From 769405e689da736e326e9b8d5588c85705109a46 Mon Sep 17 00:00:00 2001 From: Justin Chow Date: Sat, 26 Oct 2024 16:38:22 -0400 Subject: [PATCH] fixes part 2 --- lm75bd/lm75bd.c | 12 +++--------- services/thermal_mgr/thermal_mgr.c | 12 +++++++----- sys/logging/logging.h | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lm75bd/lm75bd.c b/lm75bd/lm75bd.c index 09ae7d9a..05c03bed 100644 --- a/lm75bd/lm75bd.c +++ b/lm75bd/lm75bd.c @@ -35,19 +35,13 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { uint8_t tempPointer = 0x0; //temp pointer reg is set to 0 to specify temperature reading to the device - error_code_t res = i2cSendTo(devAddr, &tempPointer, sizeof(tempPointer)); // write pointer byte 0x0 to the device address for temperature reading + error_code_t errCode = 0; - if (res != ERR_CODE_SUCCESS){ - RETURN_IF_ERROR_CODE(res); - } + RETURN_IF_ERROR_CODE(i2cSendTo(devAddr, &tempPointer, sizeof(tempPointer)));// write pointer byte 0x0 to the device address for temperature reading uint8_t buff[2] = {0, 0}; //0 is MSB, 1 is LSB - res = i2cReceiveFrom(devAddr, buff, sizeof(buff)); //get actual temperature reading - - if (res != ERR_CODE_SUCCESS){ - RETURN_IF_ERROR_CODE(res); - } + RETURN_IF_ERROR_CODE(i2cReceiveFrom(devAddr, buff, sizeof(buff))); //get actual temperature reading int16_t val = ((int16_t)(buff[0] << 8 | buff[1]) >> 5); diff --git a/services/thermal_mgr/thermal_mgr.c b/services/thermal_mgr/thermal_mgr.c index 4738d12b..2039f293 100644 --- a/services/thermal_mgr/thermal_mgr.c +++ b/services/thermal_mgr/thermal_mgr.c @@ -71,7 +71,6 @@ static void thermalMgr(void *pvParameters) { thermal_mgr_event_t buffer = {0}; - while (1) { if (xQueueReceive(thermalMgrQueueHandle, &buffer, (TickType_t) portMAX_DELAY) != pdPASS){ continue; @@ -81,18 +80,21 @@ static void thermalMgr(void *pvParameters) { if (buffer.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD){ //temperature reading event //read temperature float tempC = 0; - if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC) != ERR_CODE_SUCCESS){ - LOG_ERROR("Failed to read temperature sensor\n"); + error_code_t res = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC); + if (res != ERR_CODE_SUCCESS){ + LOG_ERROR_CODE(res); continue; //some error occurred } + addTemperatureTelemetry(tempC); //add to temperature telemetry } else if (buffer.type == THERMAL_MGR_EVENT_OS_INTERRUPT){ float tempC = 0; //OS interrupt occurred => T_{th} was reached; Make sure temperature is below T_{hys}! - if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC) != ERR_CODE_SUCCESS){ - LOG_ERROR("Failed to read temperature sensor\n"); + error_code_t res = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC); + if (res != ERR_CODE_SUCCESS){ + LOG_ERROR_CODE(res); continue; //some error occurred } diff --git a/sys/logging/logging.h b/sys/logging/logging.h index 619d2c1b..a7d5298d 100644 --- a/sys/logging/logging.h +++ b/sys/logging/logging.h @@ -28,7 +28,7 @@ typedef enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL, L #define RETURN_IF_ERROR_CODE(_ret) \ do { \ - error_code_t errCode = _ret; \ + errCode = _ret; \ if (errCode != ERR_CODE_SUCCESS) { \ LOG_ERROR_CODE(errCode); \ return errCode; \