-
Notifications
You must be signed in to change notification settings - Fork 31
Added new Thermal Manager with more temperature telemetry (besides lm75bd) #657
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
base: main
Are you sure you want to change the base?
Changes from all commits
14c0ae0
1799f4f
a9b70c7
7595058
932bc71
52d9aa2
c7ceed5
a87b930
307e879
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ | |
| /* Comms Manager event queue config */ | ||
| #define COMMS_MANAGER_QUEUE_LENGTH 10U | ||
| #define COMMS_MANAGER_QUEUE_ITEM_SIZE sizeof(comms_event_t) | ||
| #define COMMS_MANAGER_QUEUE_RX_WAIT_PERIOD pdMS_TO_TICKS(10) | ||
| #define COMMS_MANAGER_QUEUE_RX_WAIT_PERIOD pdMS_TO_TICKS(1000) | ||
| #define COMMS_MANAGER_QUEUE_TX_WAIT_PERIOD pdMS_TO_TICKS(10) | ||
|
|
||
| static QueueHandle_t commsQueueHandle = NULL; | ||
|
|
@@ -61,6 +61,13 @@ static uint8_t cc1120TransmitQueueStack[CC1120_TRANSMIT_QUEUE_LENGTH * CC1120_TR | |
| static const uint8_t TEMP_STATIC_KEY[AES_KEY_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; | ||
|
|
||
| #define CC1120_TEMP_QUEUE_LENGTH 1 | ||
| #define CC1120_TEMP_QUEUE_ITEM_SIZE sizeof(uint32_t) | ||
|
|
||
| QueueHandle_t cc1120TempQueueHandle = NULL; | ||
| static StaticQueue_t cc1120TempQueue; | ||
| static uint8_t cc1120TempQueueStack[COMMS_MANAGER_QUEUE_LENGTH * CC1120_TEMP_QUEUE_ITEM_SIZE]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using the queue length of the comms manager here? |
||
|
|
||
| /** | ||
| * @brief determines what the next Comms Manager state should be and sets it to | ||
| * that state | ||
|
|
@@ -96,6 +103,13 @@ static obc_error_code_t handleEnterEmergencyState(void); | |
| static obc_error_code_t handleEmergUplinkState(void); | ||
| /* COMMS STATE HANDLER FUNCTIONS END */ | ||
|
|
||
| /** | ||
| * @brief Reading the temperature using driver functions and adding that temperature to | ||
| * the mailbox temperature queue | ||
| * @return error code | ||
| */ | ||
| static obc_error_code_t postCommsManagerTempQueue(); | ||
|
|
||
| typedef obc_error_code_t (*comms_state_func_t)(void); | ||
|
|
||
| static const comms_state_func_t commsStateFns[] = { | ||
|
|
@@ -126,6 +140,12 @@ void obcTaskInitCommsMgr(void) { | |
| cc1120TransmitQueueStack, &cc1120TransmitQueue); | ||
| } | ||
|
|
||
| ASSERT((cc1120TempQueueStack != NULL) && (&cc1120TempQueue != NULL)); | ||
| if (cc1120TempQueueHandle == NULL) { | ||
| cc1120TempQueueHandle = xQueueCreateStatic(CC1120_TEMP_QUEUE_LENGTH, CC1120_TEMP_QUEUE_ITEM_SIZE, | ||
| cc1120TempQueueStack, &cc1120TempQueue); | ||
| } | ||
|
|
||
| // TODO: Implement a key exchange algorithm instead of using Pre-Shared/static | ||
| // key | ||
| initializeAesCtx(TEMP_STATIC_KEY); | ||
|
|
@@ -299,6 +319,21 @@ obc_error_code_t sendToFrontCommsManagerQueue(comms_event_t *event) { | |
| return OBC_ERR_CODE_QUEUE_FULL; | ||
| } | ||
|
|
||
| static obc_error_code_t postCommsManagerTempQueue() { | ||
| float value = 0.0f; // dummy value, replace with actual temp reading function | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Label this as a TODO: and add it to outstanding changes |
||
| if (xQueueOverwrite(cc1120TempQueueHandle, &value) != pdPASS) { | ||
| return OBC_ERR_CODE_UNKNOWN; | ||
| } | ||
| return OBC_ERR_CODE_SUCCESS; | ||
| } | ||
|
|
||
| obc_error_code_t readCC1120Temp(float *temp) { | ||
| if (xQueuePeek(cc1120TempQueueHandle, temp, pdMS_TO_TICKS(1000)) != pdPASS) { | ||
| return OBC_ERR_CODE_QUEUE_EMPTY; | ||
| } | ||
| return OBC_ERR_CODE_SUCCESS; | ||
| } | ||
|
|
||
| // NOTE: This is created on startup | ||
| void obcTaskFunctionCommsMgr(void *pvParameters) { | ||
| obc_error_code_t errCode; | ||
|
|
@@ -311,6 +346,7 @@ void obcTaskFunctionCommsMgr(void *pvParameters) { | |
| comms_event_t queueMsg; | ||
|
|
||
| if (xQueueReceive(commsQueueHandle, &queueMsg, COMMS_MANAGER_QUEUE_RX_WAIT_PERIOD) != pdPASS) { | ||
| postCommsManagerTempQueue(); | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |
| #define U_FRAME_COMMS_RECV_SIZE 30 | ||
| #define I_FRAME_COMMS_RECV_SIZE 300 | ||
|
|
||
| extern QueueHandle_t cc1120TempQueueHandle; | ||
|
|
||
| /** | ||
| * @enum comms_event_id_t | ||
| * @brief comms event ID enum. | ||
|
|
@@ -76,6 +78,13 @@ typedef enum { | |
| */ | ||
| obc_error_code_t sendToCommsManagerQueue(comms_event_t *event); | ||
|
|
||
| /** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recognize that this declaration is commented out due to what is mentioned in the PR description, but you also have the same declaration written below, uncommented |
||
| * @brief Get the temperature from the mailbox temperature queue of the CC1120 | ||
| * @param temp The memory address that stores the temperature in the mailbox queue | ||
| * @return The error code | ||
| */ | ||
| // obc_error_code_t readCC1120Temp(float* temp); | ||
|
|
||
| /** | ||
| * @brief Send an event to the front of the Comms Manager queue | ||
| * | ||
|
|
@@ -92,3 +101,11 @@ obc_error_code_t sendToFrontCommsManagerQueue(comms_event_t *event); | |
| * @return obc_error_code_t OBC_ERR_CODE_SUCCESS if the packet was sent to the queue | ||
| */ | ||
| obc_error_code_t sendToCC1120TransmitQueue(transmit_event_t *event); | ||
|
|
||
| /** | ||
| * @brief Reads temperature from the CC1120 Temperature Queue | ||
| * | ||
| * @param temp - Pointer to the variable that will store the temperature. | ||
| * @return obc_error_code_t OBC_ERR_CODE_SUCCESS if data was retrieved from queue successfully. | ||
| */ | ||
| obc_error_code_t readCC1120Temp(float *temp); | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #include "thermal_mgr.h" | ||
| #include "lm75bd.h" | ||
| #include "obc_time.h" | ||
| #include "telemetry_manager.h" | ||
| #include "obc_errors.h" | ||
| #include "obc_logging.h" | ||
| #include "obc_scheduler_config.h" | ||
| #include "comms_manager.h" | ||
| #include "timekeeper.h" | ||
|
|
||
| #include <FreeRTOS.h> | ||
| #include <os_task.h> | ||
| #include <sys_common.h> | ||
|
|
||
| #define HEALTH_COLLECTION_PERIOD_MS 60000UL | ||
|
|
||
| static obc_error_code_t collectThermalData(void); | ||
|
|
||
| void obcTaskInitThermalMgr(void) {} | ||
|
|
||
| void obcTaskFunctionThermalMgr(void* pvParameters) { | ||
| obc_error_code_t errCode; | ||
|
|
||
| while (1) { | ||
| LOG_IF_ERROR_CODE(collectThermalData()); | ||
| vTaskDelay(pdMS_TO_TICKS(HEALTH_COLLECTION_PERIOD_MS)); | ||
| } | ||
| } | ||
|
|
||
| static obc_error_code_t collectThermalData(void) { | ||
| obc_error_code_t errCode; | ||
|
|
||
| float lm75bdTemp = 0.0f; | ||
| RETURN_IF_ERROR_CODE(readTempLM75BD(LM75BD_OBC_I2C_ADDR, &lm75bdTemp)); | ||
| telemetry_data_t lm75bdTempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do all three temp structs have the same id?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You call |
||
| RETURN_IF_ERROR_CODE(addTelemetryData(&lm75bdTempVal)); | ||
|
|
||
| /* Uncomment this if comms manager task being suspened issue is fixed. | ||
| float cc1120Temp = 0.0f; | ||
| RETURN_IF_ERROR_CODE(readCC1120Temp(&cc1120Temp)); | ||
| telemetry_data_t cc1120TempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is commented out, but this should not be |
||
| RETURN_IF_ERROR_CODE(addTelemetryData(&cc1120TempVal)); | ||
| */ | ||
| float rtcTemp = 0.0f; | ||
| RETURN_IF_ERROR_CODE(readRTCTemp(&rtcTemp)); | ||
| telemetry_data_t rtcTempVal = {.obcTemp = lm75bdTemp, .id = TELEM_OBC_TEMP, .timestamp = getCurrentUnixTime()}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not be |
||
| RETURN_IF_ERROR_CODE(addTelemetryData(&rtcTempVal)); | ||
|
|
||
| return OBC_ERR_CODE_SUCCESS; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,48 @@ | |
| #include <os_task.h> | ||
| #include <os_timer.h> | ||
| #include <sys_common.h> | ||
| #include <stdint.h> | ||
|
|
||
| #define LOCAL_TIME_SYNC_PERIOD_S 60UL | ||
|
|
||
| void obcTaskInitTimekeeper(void) {} | ||
| #define RTC_TEMP_QUEUE_LENGTH 1 | ||
| #define RTC_TEMP_QUEUE_ITEM_SIZE sizeof(uint32_t) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though we can assume floats on our architecture are 32 bit, a type mismatch like this is unideal and not portable. We should define the size as being the same as the type of data we store in the queue. |
||
|
|
||
| QueueHandle_t rtcTempQueueHandle = NULL; | ||
| static StaticQueue_t rtcTempQueue; | ||
| static uint8_t rtcTempQueueStack[RTC_TEMP_QUEUE_LENGTH * RTC_TEMP_QUEUE_ITEM_SIZE]; | ||
|
|
||
| /** | ||
| * @brief Reading the temperature using driver functions and adding that temperature to | ||
| * the mailbox temperature queue | ||
| * @return error code | ||
| */ | ||
| static obc_error_code_t postRtcTempQueue(); | ||
|
|
||
| void obcTaskInitTimekeeper(void) { | ||
| ASSERT((rtcTempQueueStack != NULL) && (&rtcTempQueue != NULL)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking the address of a static variable like rtcTempQueue will never result in NULL |
||
| if (rtcTempQueueHandle == NULL) { | ||
| rtcTempQueueHandle = | ||
| xQueueCreateStatic(RTC_TEMP_QUEUE_LENGTH, RTC_TEMP_QUEUE_ITEM_SIZE, rtcTempQueueStack, &rtcTempQueue); | ||
| } | ||
| } | ||
|
|
||
| static obc_error_code_t postRtcTempQueue() { | ||
| obc_error_code_t errCode; | ||
| float temp; | ||
| RETURN_IF_ERROR_CODE(getTemperatureRTC(&temp)); | ||
| if (xQueueOverwrite(rtcTempQueueHandle, &temp) != pdPASS) { | ||
| return OBC_ERR_CODE_UNKNOWN; | ||
| } | ||
| return OBC_ERR_CODE_SUCCESS; | ||
| } | ||
|
|
||
| obc_error_code_t readRTCTemp(float *data) { | ||
| if (xQueuePeek(rtcTempQueueHandle, data, 0) != pdPASS) { | ||
| return OBC_ERR_CODE_QUEUE_EMPTY; | ||
| } | ||
| return OBC_ERR_CODE_SUCCESS; | ||
| } | ||
|
|
||
| void obcTaskFunctionTimekeeper(void *pvParameters) { | ||
| /* | ||
|
|
@@ -46,7 +84,11 @@ void obcTaskFunctionTimekeeper(void *pvParameters) { | |
| vPortExitCritical(); | ||
| } | ||
|
|
||
| // Send Unix time to fram | ||
| // Post temperature into mailbox queue | ||
|
|
||
| postRtcTempQueue(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignoring the return value of this function, which is an error code? |
||
|
|
||
| // Send Unix time to frame | ||
| unixTime.unixTime = getCurrentUnixTime(); | ||
| LOG_IF_ERROR_CODE( | ||
| setPersistentData(OBC_PERSIST_SECTION_ID_OBC_TIME, (uint8_t *)&unixTime, sizeof(obc_time_persist_data_t))); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,14 @@ | ||
| #pragma once | ||
|
|
||
| #include <FreeRTOS.h> | ||
| #include <os_queue.h> | ||
| #include "obc_errors.h" | ||
|
|
||
| extern QueueHandle_t rtcTempQueueHandle; | ||
|
|
||
| /** | ||
| * @brief Get the temperature from the mailbox temperature queue of the ds3232 | ||
| * @param temp The memory address that stores the temperature in the mailbox queue | ||
| * @return The error code | ||
| */ | ||
| obc_error_code_t readRTCTemp(float* data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same type mismatch as mentioned in the other comment