Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Onboarding Challenge #103

Closed
wants to merge 13 commits into from
Closed
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your integration test run looks wrong

3 changes: 3 additions & 0 deletions Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Start testing: Dec 18 23:32 EST
----------------------------------------------------------
End testing: Dec 18 23:32 EST
16 changes: 15 additions & 1 deletion lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,22 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {
}

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */
// declare error code variable
error_code_t errCode;

// set pointer register to 'temperature sensor'
uint8_t writeBuf[1] = {0};
RETURN_IF_ERROR_CODE(i2cSendTo(devAddr, writeBuf, 1));

// read temperature from sensor
uint8_t readBuf[2] = {0};
RETURN_IF_ERROR_CODE(i2cReceiveFrom(devAddr, readBuf, 2));

// convert temperature reading to celsius
int16_t tempC = (readBuf[0] << 8) | readBuf[1];
tempC >>= 5;
*temp = tempC * 0.125;

return ERR_CODE_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion lm75bd/lm75bd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>

/* LM75BD I2C Device Address */
#define LM75BD_OBC_I2C_ADDR /* Define the address here */
#define LM75BD_OBC_I2C_ADDR 0x4F

/* LM75BD Configuration Values */
#define LM75BD_DEV_OP_MODE_NORMAL 0x00U
Expand Down
43 changes: 37 additions & 6 deletions services/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "errors.h"
#include "lm75bd.h"
#include "console.h"

#include "logging.h"
#include <FreeRTOS.h>
#include <os_task.h>
#include <os_queue.h>
Expand Down Expand Up @@ -42,19 +42,50 @@ void initThermalSystemManager(lm75bd_config_t *config) {
}

error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) {
/* Send an event to the thermal manager queue */

if (&thermalMgrQueueHandle == NULL)
return ERR_CODE_INVALID_STATE;

if (event == NULL)
return ERR_CODE_INVALID_ARG;

if (xQueueSend(thermalMgrQueueHandle, (void *) event, (TickType_t) 0) != pdPASS)
return ERR_CODE_QUEUE_FULL;

return ERR_CODE_SUCCESS;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that when your doing multiple errror checks like this it's a lot cleaner to just use multiple if statements with early returns rather than a bunch of nested if statements. For example something like ```

if(errCodeCondition){
return ERR_CODE
}
if(otherPossibleError){
return OTHER_ERROR
}
// continue with the rest of the function knowing everything before was success without need an else statement


void osHandlerLM75BD(void) {
/* Implement this function */
thermal_mgr_event_t event;
event.type = THERMAL_MGR_EVENT_INTERRUPT_CMD;
thermalMgrSendEvent(&event);
}

static void thermalMgr(void *pvParameters) {
/* Implement this task */
while (1) {

thermal_mgr_event_t eventBuf;

float temp;

if (xQueueReceive(thermalMgrQueueHandle, &eventBuf, 10) == pdPASS) {
if (eventBuf.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) {
error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
if (errCode == ERR_CODE_SUCCESS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to log the error if it was no successful

addTemperatureTelemetry(temp);
else
LOG_ERROR_CODE(errCode);
}
else if (eventBuf.type == THERMAL_MGR_EVENT_INTERRUPT_CMD) {
error_code_t errCode = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if the function call was successful or not

if (errCode == ERR_CODE_SUCCESS) {
if (temp > 75)
overTemperatureDetected();
else
safeOperatingConditions();
}
else
LOG_ERROR_CODE(errCode);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion services/thermal_mgr/thermal_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

typedef enum {
THERMAL_MGR_EVENT_MEASURE_TEMP_CMD,

THERMAL_MGR_EVENT_INTERRUPT_CMD,
} thermal_mgr_event_type_t;

typedef struct {
Expand Down