From a1fd346354fe1b1e683c1ad54ea477cac233cd05 Mon Sep 17 00:00:00 2001 From: Makiv1 Date: Thu, 24 Oct 2024 22:36:24 -0600 Subject: [PATCH 1/8] Create new file --- .../startup_sequence/antenna_deploy_startup.h | 7 ++ firmware/Core/Src/main.c | 3 + .../startup_sequence/antenna_deploy_startup.c | 65 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h create mode 100644 firmware/Core/Src/startup_sequence/antenna_deploy_startup.c diff --git a/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h b/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h new file mode 100644 index 000000000..9e4e42f2b --- /dev/null +++ b/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h @@ -0,0 +1,7 @@ +#ifndef __INCLUDE_GUARD__ANTENNA_DEPLOY_STARTUP_H__ +#define __INCLUDE_GUARD__ANTENNA_DEPLOY_STARTUP_H__ +#include +uint8_t START_antenna_deploy(); + + +#endif // __INCLUDE_GUARD__ANTENNA_DEPLOY_STARTUP_H__ \ No newline at end of file diff --git a/firmware/Core/Src/main.c b/firmware/Core/Src/main.c index e8692eb45..12e04ea91 100644 --- a/firmware/Core/Src/main.c +++ b/firmware/Core/Src/main.c @@ -32,6 +32,8 @@ #include "adcs_drivers/adcs_internal_drivers.h" #include "littlefs/flash_driver.h" +#include "startup_sequence/antenna_deploy_startup.h" + /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -257,6 +259,7 @@ int main(void) // Initialise the ADCS CRC8 checksum (required for ADCS operation). ADCS_initialise_crc8_checksum(); + START_antenna_deploy(); /* USER CODE END 2 */ /* Init scheduler */ diff --git a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c new file mode 100644 index 000000000..b8480874b --- /dev/null +++ b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c @@ -0,0 +1,65 @@ +#include "startup_sequence/antenna_deploy_startup.h" +#include "littlefs/littlefs_helper.h" +#include "littlefs/lfs.h" +#include "log/log.h" +uint8_t START_antenna_deploy() { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "Starting Antenna Deploy" + ); + uint8_t LFS_unmount_on_completion = 0; + if (!LFS_is_lfs_mounted) { + lfs_mount(&LFS_filesystem, &LFS_cfg); + LFS_unmount_on_completion = 1; + } + + // Create lifecycle directory if it doesn't exist + const int32_t mkdir_result = lfs_mkdir(&LFS_filesystem, "lifecycle"); + if(mkdir_result != LFS_ERR_EXIST && mkdir_result != 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "Error %d creating lifecycle directory.", + mkdir_result + ); + //TODO: what happens if directory creation fails? + } + + lfs_file_t file; + int32_t open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + if ( open_result == LFS_ERR_NOENT) { + // Create file if it doesn't exist + open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "file did not exist, created deploy_antenna_on_boot_enabled.bool file." + ); + } + else if(open_result != 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d opening deploy_antenna_on_boot_enabled.bool file.", + open_result + ); + } + + lfs_file_rewind(&LFS_filesystem, &file); + + uint8_t deploy_antenna_on_boot_enabled; + + lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); + + lfs_file_close(&LFS_filesystem, &file); + + if(LFS_unmount_on_completion) { + lfs_unmount(&LFS_filesystem); + } + return 0; +} \ No newline at end of file From bc6718e906f4a7b7dd2fc96a7d7035c12ae059c8 Mon Sep 17 00:00:00 2001 From: Makiv1 Date: Tue, 12 Nov 2024 20:01:24 -0700 Subject: [PATCH 2/8] testing lfs functions --- .../startup_sequence/antenna_deploy_startup.c | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c index b8480874b..c255c23e8 100644 --- a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c +++ b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c @@ -28,11 +28,32 @@ uint8_t START_antenna_deploy() { //TODO: what happens if directory creation fails? } + if(mkdir_result == LFS_ERR_EXIST) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "lifecycle directory already exists. Skipping creation." + ); + } + + if(mkdir_result == 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "lifecycle directory created." + ); + } + // At this point the lifecycle directory exists or has been created + + // Create deploy_antenna_on_boot_enabled.bool file if it doesn't exist + // lfs_file_t file; int32_t open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); if ( open_result == LFS_ERR_NOENT) { // Create file if it doesn't exist - open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY | LFS_O_CREAT, &LFS_file_cfg); LOG_message( LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, @@ -45,18 +66,56 @@ uint8_t START_antenna_deploy() { LOG_SYSTEM_LFS, LOG_SEVERITY_WARNING, LOG_SINK_ALL, - "Error %d opening deploy_antenna_on_boot_enabled.bool file.", + "Error %d opening/creating deploy_antenna_on_boot_enabled.bool file.", open_result ); } + else if (open_result == 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "deploy_antenna_on_boot_enabled.bool file opened." + ); + } + // At this point the depoy_antenna_on_boot_enabled.bool file is open - lfs_file_rewind(&LFS_filesystem, &file); + uint8_t deploy_antenna_on_boot_enabled[10]; + size_t num_bytes_read = lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); + + if(num_bytes_read < 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d reading deploy_antenna_on_boot_enabled.bool file.", + num_bytes_read + ); + } + if(num_bytes_read == 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "deploy_antenna_on_boot_enabled.bool file is empty." + ); + } + if(num_bytes_read > 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_NORMAL, + LOG_SINK_ALL, + "read %d bytes from deploy_antenna_on_boot_enabled.bool. Result: %s", + num_bytes_read, + deploy_antenna_on_boot_enabled + ); + } - uint8_t deploy_antenna_on_boot_enabled; + //uint8_t deploy_antenna_on_boot_enabled; - lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); + //lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); - lfs_file_close(&LFS_filesystem, &file); + // lfs_file_close(&LFS_filesystem, &file); if(LFS_unmount_on_completion) { lfs_unmount(&LFS_filesystem); From fd9004c23845c7b2ce5d6a22e7cb9fd24f9f555c Mon Sep 17 00:00:00 2001 From: Makiv1 Date: Wed, 13 Nov 2024 16:32:29 -0700 Subject: [PATCH 3/8] Rough implementation of specifications compelete --- .../startup_sequence/antenna_deploy_startup.c | 67 +++++++++++++++---- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c index c255c23e8..36e94a157 100644 --- a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c +++ b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c @@ -2,6 +2,8 @@ #include "littlefs/littlefs_helper.h" #include "littlefs/lfs.h" #include "log/log.h" +#include "antenna_deploy_drivers/ant_commands.h" +#include "antenna_deploy_drivers/ant_internal_drivers.h" uint8_t START_antenna_deploy() { LOG_message( LOG_SYSTEM_LFS, @@ -47,20 +49,55 @@ uint8_t START_antenna_deploy() { } // At this point the lifecycle directory exists or has been created + // Create deploy_antenna_on_boot_enabled.bool file if it doesn't exist // lfs_file_t file; int32_t open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + uint8_t file_did_exist = 1; if ( open_result == LFS_ERR_NOENT) { - // Create file if it doesn't exist - open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY | LFS_O_CREAT, &LFS_file_cfg); + // file doesn't exist, create it and open for writing + file_did_exist = 0; + open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_WRONLY | LFS_O_CREAT, &LFS_file_cfg); LOG_message( LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, "file did not exist, created deploy_antenna_on_boot_enabled.bool file." ); + if (open_result == 0) + { + uint8_t buff = 1; + int32_t write_result = lfs_file_write(&LFS_filesystem, &file, &buff, sizeof(buff)); + if(write_result < 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d writing to newly created deploy_antenna_on_boot_enabled.bool file.", + write_result + ); + //TODO: what happens if write fails? + } + + int32_t close_result = lfs_file_close(&LFS_filesystem, &file); + if(close_result < 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d closing newly created deploy_antenna_on_boot_enabled.bool file.", + close_result + ); + //TODO: what happens if close fails? + } + + // the fil has been created and 1 (assuming no errors occured) has been written to it, open for reading + open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + } + } + //TODO: should this be else if? else if(open_result != 0) { LOG_message( LOG_SYSTEM_LFS, @@ -80,9 +117,8 @@ uint8_t START_antenna_deploy() { } // At this point the depoy_antenna_on_boot_enabled.bool file is open - uint8_t deploy_antenna_on_boot_enabled[10]; - size_t num_bytes_read = lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); - + uint8_t deploy_antenna_on_boot_enabled; + int32_t num_bytes_read = lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); if(num_bytes_read < 0) { LOG_message( LOG_SYSTEM_LFS, @@ -105,20 +141,23 @@ uint8_t START_antenna_deploy() { LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, - "read %d bytes from deploy_antenna_on_boot_enabled.bool. Result: %s", + "read %d bytes from deploy_antenna_on_boot_enabled.bool. Result: %d", num_bytes_read, - deploy_antenna_on_boot_enabled + deploy_antenna_on_boot_enabled[0] ); } - - //uint8_t deploy_antenna_on_boot_enabled; - - //lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); - - // lfs_file_close(&LFS_filesystem, &file); - + //reading the file is done now, unmount fs and close the file + lfs_file_close(&LFS_filesystem, &file); if(LFS_unmount_on_completion) { lfs_unmount(&LFS_filesystem); } + + if(deploy_antenna_on_boot_enabled == 1) { + //TODO: which mcu should be armed on the antenna deploy system? Error handling + ANT_CMD_arm_antenna_system(ANT_i2c_bus_mcu1); + ANT_CMD_start_automated_sequential_deployment(ANT_i2c_bus_mcu1, 7); + } + + return 0; } \ No newline at end of file From f61e69a7cb557aad88db7cf8f84c80df5ce3590f Mon Sep 17 00:00:00 2001 From: Makiv1 <81124080+Makiv1@users.noreply.github.com> Date: Sat, 16 Nov 2024 18:26:37 -0700 Subject: [PATCH 4/8] bugfix --- firmware/Core/Src/startup_sequence/antenna_deploy_startup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c index 36e94a157..fbfcba4ee 100644 --- a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c +++ b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c @@ -143,7 +143,7 @@ uint8_t START_antenna_deploy() { LOG_SINK_ALL, "read %d bytes from deploy_antenna_on_boot_enabled.bool. Result: %d", num_bytes_read, - deploy_antenna_on_boot_enabled[0] + deploy_antenna_on_boot_enabled ); } //reading the file is done now, unmount fs and close the file @@ -154,8 +154,8 @@ uint8_t START_antenna_deploy() { if(deploy_antenna_on_boot_enabled == 1) { //TODO: which mcu should be armed on the antenna deploy system? Error handling - ANT_CMD_arm_antenna_system(ANT_i2c_bus_mcu1); - ANT_CMD_start_automated_sequential_deployment(ANT_i2c_bus_mcu1, 7); + ANT_CMD_arm_antenna_system(ANT_I2C_BUS_A_MCU_A); + ANT_CMD_start_automated_sequential_deployment(ANT_I2C_BUS_A_MCU_A, 7); } From 7f7f9baaa33e9fecb040c882c74afa6a69a2be7d Mon Sep 17 00:00:00 2001 From: Makiv1 Date: Sat, 30 Nov 2024 14:42:30 -0700 Subject: [PATCH 5/8] Create bootup task which runs bootup procedure --- firmware/Core/Inc/rtos_tasks/rtos_tasks.h | 1 + firmware/Core/Src/main.c | 10 +++++++++- firmware/Core/Src/rtos_tasks/rtos_tasks.c | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/firmware/Core/Inc/rtos_tasks/rtos_tasks.h b/firmware/Core/Inc/rtos_tasks/rtos_tasks.h index 0dc6b6aa2..6b00b4739 100644 --- a/firmware/Core/Inc/rtos_tasks/rtos_tasks.h +++ b/firmware/Core/Inc/rtos_tasks/rtos_tasks.h @@ -14,5 +14,6 @@ void TASK_handle_uart_telecommands(void *argument); void TASK_execute_telecommands(void *argument); void TASK_monitor_freertos_memory(void *argument); +void TASK_bootup(void *argument); #endif // __INCLUDE_GUARD__RTOS_TASKS_H__ diff --git a/firmware/Core/Src/main.c b/firmware/Core/Src/main.c index 12e04ea91..aca3af3f6 100644 --- a/firmware/Core/Src/main.c +++ b/firmware/Core/Src/main.c @@ -123,6 +123,13 @@ const osThreadAttr_t TASK_time_sync_Attributes = { .priority = (osPriority_t) osPriorityNormal, //TODO: Figure out which priority makes sense for this task }; +osThreadId_t TASK_bootup_Handle; +const osThreadAttr_t TASK_bootup_Attributes = { + .name = "TASK_bootup", + .stack_size = 1024, //in bytes. 512 is tool small and will cause crashes when lfs_close() is called! + .priority = (osPriority_t) osPriorityNormal, //TODO: Figure out which priority makes sense for this task +}; + osThreadId_t TASK_monitor_freertos_memory_Handle; const osThreadAttr_t TASK_monitor_freertos_memory_Attributes = { .name = "TASK_monitor_freertos_memory", @@ -259,7 +266,6 @@ int main(void) // Initialise the ADCS CRC8 checksum (required for ADCS operation). ADCS_initialise_crc8_checksum(); - START_antenna_deploy(); /* USER CODE END 2 */ /* Init scheduler */ @@ -297,6 +303,8 @@ int main(void) TASK_service_eps_watchdog_Handle = osThreadNew(TASK_service_eps_watchdog, NULL, &TASK_service_eps_watchdog_Attributes); TASK_time_sync_Handle = osThreadNew(TASK_time_sync, NULL, &TASK_time_sync_Attributes); + + TASK_bootup_Handle = osThreadNew(TASK_bootup, NULL, &TASK_bootup_Attributes); /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ diff --git a/firmware/Core/Src/rtos_tasks/rtos_tasks.c b/firmware/Core/Src/rtos_tasks/rtos_tasks.c index 0e3abe8fc..11584e222 100644 --- a/firmware/Core/Src/rtos_tasks/rtos_tasks.c +++ b/firmware/Core/Src/rtos_tasks/rtos_tasks.c @@ -12,6 +12,7 @@ #include "log/log.h" #include "config/configuration.h" #include "eps_drivers/eps_commands.h" +#include "startup_sequence/antenna_deploy_startup.h" #include "cmsis_os.h" @@ -222,3 +223,22 @@ void TASK_monitor_freertos_memory(void *argument) { } /* End Task's Main Loop */ } +/// @brief Completes all tasks which are nesssary after the obc is powered on(or rebooted) +/// @param argument +void TASK_bootup(void *argument) { + TASK_HELP_start_of_task(); + + uint8_t ant_deploy_complete = 0; + //TODO: Unsure of how to properly terminate this task. Should it be a forever loop? + while (1) { + //TODO: What should the delay be here? I suspect it should be smaller. + osDelay(2000); + if (!ant_deploy_complete) { + START_antenna_deploy(); + //TODO: This should be changed to the commeted out code + if (/*START_antenna_deploy() == 0*/ 1) { + ant_deploy_complete = 1; + } + } + } /* End Task's Main Loop */ +} From ed3612a81300048486f338860202853e9c6c6d48 Mon Sep 17 00:00:00 2001 From: Makiv1 Date: Sat, 30 Nov 2024 14:44:20 -0700 Subject: [PATCH 6/8] Implement function which deternimes if the antenna should be deployed on startup. Deploys accordingly --- .../startup_sequence/antenna_deploy_startup.h | 2 +- .../startup_sequence/antenna_deploy_startup.c | 177 ++++++++++++------ 2 files changed, 124 insertions(+), 55 deletions(-) diff --git a/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h b/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h index 9e4e42f2b..c01633ade 100644 --- a/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h +++ b/firmware/Core/Inc/startup_sequence/antenna_deploy_startup.h @@ -1,7 +1,7 @@ #ifndef __INCLUDE_GUARD__ANTENNA_DEPLOY_STARTUP_H__ #define __INCLUDE_GUARD__ANTENNA_DEPLOY_STARTUP_H__ #include -uint8_t START_antenna_deploy(); +int16_t START_antenna_deploy(); #endif // __INCLUDE_GUARD__ANTENNA_DEPLOY_STARTUP_H__ \ No newline at end of file diff --git a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c index fbfcba4ee..950e09343 100644 --- a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c +++ b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c @@ -4,41 +4,50 @@ #include "log/log.h" #include "antenna_deploy_drivers/ant_commands.h" #include "antenna_deploy_drivers/ant_internal_drivers.h" -uint8_t START_antenna_deploy() { +/// @brief Attempts to read to the file "lifecycle/deploy_antenna_on_boot_enabled.bool". +/// If 1 is stored in the file then it attempts to deploy the antenna. If the file did not +/// exist: then it creates the file, stores a 1 in it, and attempts to deploy. +/// @return 0 on success, <0 on failure +int16_t START_antenna_deploy() { + //TODO: remove after validation LOG_message( LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, "Starting Antenna Deploy" ); + uint8_t LFS_unmount_on_completion = 0; if (!LFS_is_lfs_mounted) { - lfs_mount(&LFS_filesystem, &LFS_cfg); + if (lfs_mount(&LFS_filesystem, &LFS_cfg) != 0) { + return -1; + } LFS_unmount_on_completion = 1; } // Create lifecycle directory if it doesn't exist const int32_t mkdir_result = lfs_mkdir(&LFS_filesystem, "lifecycle"); - if(mkdir_result != LFS_ERR_EXIST && mkdir_result != 0) { + if(mkdir_result == LFS_ERR_EXIST) { LOG_message( LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, - "Error %d creating lifecycle directory.", - mkdir_result + "lifecycle directory already exists. Skipping creation." ); - //TODO: what happens if directory creation fails? } - if(mkdir_result == LFS_ERR_EXIST) { + if(mkdir_result != LFS_ERR_EXIST && mkdir_result != 0) { LOG_message( LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, - "lifecycle directory already exists. Skipping creation." + "Error %d creating lifecycle directory.", + mkdir_result ); + return -2; } + //TODO: remove after validation if(mkdir_result == 0) { LOG_message( LOG_SYSTEM_LFS, @@ -51,62 +60,78 @@ uint8_t START_antenna_deploy() { // Create deploy_antenna_on_boot_enabled.bool file if it doesn't exist - // lfs_file_t file; int32_t open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); - uint8_t file_did_exist = 1; if ( open_result == LFS_ERR_NOENT) { - // file doesn't exist, create it and open for writing - file_did_exist = 0; + + // if file doesn't exist, create it and open for writing and write 1 open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_WRONLY | LFS_O_CREAT, &LFS_file_cfg); + if(open_result != 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d opening/creating deploy_antenna_on_boot_enabled.bool file.", + open_result + ); + return open_result; + } + + uint8_t buff = 1; + int32_t write_result = lfs_file_write(&LFS_filesystem, &file, &buff, sizeof(buff)); + if(write_result < 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d writing to newly created deploy_antenna_on_boot_enabled.bool file.", + write_result + ); + return write_result; + } + + //TODO: remove after validation LOG_message( LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, "file did not exist, created deploy_antenna_on_boot_enabled.bool file." ); - if (open_result == 0) - { - uint8_t buff = 1; - int32_t write_result = lfs_file_write(&LFS_filesystem, &file, &buff, sizeof(buff)); - if(write_result < 0) { - LOG_message( - LOG_SYSTEM_LFS, - LOG_SEVERITY_WARNING, - LOG_SINK_ALL, - "Error %d writing to newly created deploy_antenna_on_boot_enabled.bool file.", - write_result - ); - //TODO: what happens if write fails? - } - - int32_t close_result = lfs_file_close(&LFS_filesystem, &file); - if(close_result < 0) { + + int32_t close_result = lfs_file_close(&LFS_filesystem, &file); + if(close_result != 0) { LOG_message( - LOG_SYSTEM_LFS, - LOG_SEVERITY_WARNING, - LOG_SINK_ALL, - "Error %d closing newly created deploy_antenna_on_boot_enabled.bool file.", - close_result - ); - //TODO: what happens if close fails? - } + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d closing newly created deploy_antenna_on_boot_enabled.bool file.", + close_result + ); + return close_result; + } - // the fil has been created and 1 (assuming no errors occured) has been written to it, open for reading - open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + // the file has been created and 1 has been written to it, open for reading + open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + if (open_result != 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_WARNING, + LOG_SINK_ALL, + "Error %d opening/creating deploy_antenna_on_boot_enabled.bool file.", + open_result + ); + return -5 ; } - - } - //TODO: should this be else if? - else if(open_result != 0) { LOG_message( LOG_SYSTEM_LFS, - LOG_SEVERITY_WARNING, + LOG_SEVERITY_NORMAL, LOG_SINK_ALL, - "Error %d opening/creating deploy_antenna_on_boot_enabled.bool file.", - open_result + "new file created, 1 written, opend for reading." ); } + + + //TODO: remove after validation else if (open_result == 0) { LOG_message( LOG_SYSTEM_LFS, @@ -115,8 +140,8 @@ uint8_t START_antenna_deploy() { "deploy_antenna_on_boot_enabled.bool file opened." ); } + // At this point the depoy_antenna_on_boot_enabled.bool file is open - uint8_t deploy_antenna_on_boot_enabled; int32_t num_bytes_read = lfs_file_read(&LFS_filesystem, &file, &deploy_antenna_on_boot_enabled, sizeof(deploy_antenna_on_boot_enabled)); if(num_bytes_read < 0) { @@ -127,7 +152,9 @@ uint8_t START_antenna_deploy() { "Error %d reading deploy_antenna_on_boot_enabled.bool file.", num_bytes_read ); + return num_bytes_read; } + //TODO: remove after validation if(num_bytes_read == 0) { LOG_message( LOG_SYSTEM_LFS, @@ -136,6 +163,7 @@ uint8_t START_antenna_deploy() { "deploy_antenna_on_boot_enabled.bool file is empty." ); } + //TODO: remove after validation if(num_bytes_read > 0) { LOG_message( LOG_SYSTEM_LFS, @@ -146,18 +174,59 @@ uint8_t START_antenna_deploy() { deploy_antenna_on_boot_enabled ); } - //reading the file is done now, unmount fs and close the file - lfs_file_close(&LFS_filesystem, &file); + //reading the file is done now, close the file and unmount lfs if needed + int close_status = lfs_file_close(&LFS_filesystem, &file); + if( close_status != 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_ERROR, + LOG_SINK_ALL, + "Error %d closing deploy_antenna_on_boot_enabled.bool file.", + close_status + ); + return close_status; + } + if(LFS_unmount_on_completion) { - lfs_unmount(&LFS_filesystem); + int32_t unmount_status = lfs_unmount(&LFS_filesystem); + if (unmount_status != 0) { + LOG_message( + LOG_SYSTEM_LFS, + LOG_SEVERITY_ERROR, + LOG_SINK_ALL, + "Error %d unmounting lfs.", + unmount_status + ); + return unmount_status; + } } if(deploy_antenna_on_boot_enabled == 1) { - //TODO: which mcu should be armed on the antenna deploy system? Error handling - ANT_CMD_arm_antenna_system(ANT_I2C_BUS_A_MCU_A); - ANT_CMD_start_automated_sequential_deployment(ANT_I2C_BUS_A_MCU_A, 7); - } + //TODO: which mcu should be armed on the antenna deploy system? Error handling. How long to activate? + int8_t arm_result = ANT_CMD_arm_antenna_system(ANT_I2C_BUS_A_MCU_A); + if (arm_result != 0) { + LOG_message( + LOG_SYSTEM_ANTENNA_DEPLOY, + LOG_SEVERITY_ERROR, + LOG_SINK_ALL, + "Error %d arming antenna deploy system.", + arm_result + ); + return arm_result; + } + int8_t deploy_result = ANT_CMD_start_automated_sequential_deployment(ANT_I2C_BUS_A_MCU_A, 7); + if (deploy_result != 0) { + LOG_message( + LOG_SYSTEM_ANTENNA_DEPLOY, + LOG_SEVERITY_ERROR, + LOG_SINK_ALL, + "Error %d deploying antennas.", + deploy_result + ); + return deploy_result; + } + } return 0; } \ No newline at end of file From 6d630c250adf657b45c05e38202e431ce87b3994 Mon Sep 17 00:00:00 2001 From: Makiv1 Date: Sat, 30 Nov 2024 14:59:04 -0700 Subject: [PATCH 7/8] Change task delay --- firmware/Core/Src/rtos_tasks/rtos_tasks.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/firmware/Core/Src/rtos_tasks/rtos_tasks.c b/firmware/Core/Src/rtos_tasks/rtos_tasks.c index 11584e222..3296ee963 100644 --- a/firmware/Core/Src/rtos_tasks/rtos_tasks.c +++ b/firmware/Core/Src/rtos_tasks/rtos_tasks.c @@ -229,14 +229,13 @@ void TASK_bootup(void *argument) { TASK_HELP_start_of_task(); uint8_t ant_deploy_complete = 0; - //TODO: Unsure of how to properly terminate this task. Should it be a forever loop? + uint32_t delay_ms = 100; while (1) { - //TODO: What should the delay be here? I suspect it should be smaller. - osDelay(2000); + //TODO: What should the delay be here? + osDelay(delay_ms); + delay_ms = 60000; if (!ant_deploy_complete) { - START_antenna_deploy(); - //TODO: This should be changed to the commeted out code - if (/*START_antenna_deploy() == 0*/ 1) { + if (START_antenna_deploy() == 0) { ant_deploy_complete = 1; } } From b5ac88cdf4c7698fe54438e8b74029e8b40fb0ad Mon Sep 17 00:00:00 2001 From: Makiv1 <81124080+Makiv1@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:24:00 -0700 Subject: [PATCH 8/8] fixed int types --- .../startup_sequence/antenna_deploy_startup.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c index 950e09343..58409f8d9 100644 --- a/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c +++ b/firmware/Core/Src/startup_sequence/antenna_deploy_startup.c @@ -26,7 +26,7 @@ int16_t START_antenna_deploy() { } // Create lifecycle directory if it doesn't exist - const int32_t mkdir_result = lfs_mkdir(&LFS_filesystem, "lifecycle"); + const int16_t mkdir_result = lfs_mkdir(&LFS_filesystem, "lifecycle"); if(mkdir_result == LFS_ERR_EXIST) { LOG_message( LOG_SYSTEM_LFS, @@ -61,7 +61,7 @@ int16_t START_antenna_deploy() { // Create deploy_antenna_on_boot_enabled.bool file if it doesn't exist lfs_file_t file; - int32_t open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); + int16_t open_result = lfs_file_opencfg(&LFS_filesystem, &file, "lifecycle/deploy_antenna_on_boot_enabled.bool", LFS_O_RDONLY, &LFS_file_cfg); if ( open_result == LFS_ERR_NOENT) { // if file doesn't exist, create it and open for writing and write 1 @@ -84,7 +84,7 @@ int16_t START_antenna_deploy() { LOG_SYSTEM_LFS, LOG_SEVERITY_WARNING, LOG_SINK_ALL, - "Error %d writing to newly created deploy_antenna_on_boot_enabled.bool file.", + "Error %ld writing to newly created deploy_antenna_on_boot_enabled.bool file.", write_result ); return write_result; @@ -104,7 +104,7 @@ int16_t START_antenna_deploy() { LOG_SYSTEM_LFS, LOG_SEVERITY_WARNING, LOG_SINK_ALL, - "Error %d closing newly created deploy_antenna_on_boot_enabled.bool file.", + "Error %ld closing newly created deploy_antenna_on_boot_enabled.bool file.", close_result ); return close_result; @@ -149,7 +149,7 @@ int16_t START_antenna_deploy() { LOG_SYSTEM_LFS, LOG_SEVERITY_WARNING, LOG_SINK_ALL, - "Error %d reading deploy_antenna_on_boot_enabled.bool file.", + "Error %ld reading deploy_antenna_on_boot_enabled.bool file.", num_bytes_read ); return num_bytes_read; @@ -169,13 +169,13 @@ int16_t START_antenna_deploy() { LOG_SYSTEM_LFS, LOG_SEVERITY_NORMAL, LOG_SINK_ALL, - "read %d bytes from deploy_antenna_on_boot_enabled.bool. Result: %d", + "read %ld bytes from deploy_antenna_on_boot_enabled.bool. Result: %d", num_bytes_read, deploy_antenna_on_boot_enabled ); } //reading the file is done now, close the file and unmount lfs if needed - int close_status = lfs_file_close(&LFS_filesystem, &file); + int16_t close_status = lfs_file_close(&LFS_filesystem, &file); if( close_status != 0) { LOG_message( LOG_SYSTEM_LFS, @@ -188,7 +188,7 @@ int16_t START_antenna_deploy() { } if(LFS_unmount_on_completion) { - int32_t unmount_status = lfs_unmount(&LFS_filesystem); + int16_t unmount_status = lfs_unmount(&LFS_filesystem); if (unmount_status != 0) { LOG_message( LOG_SYSTEM_LFS, @@ -203,7 +203,7 @@ int16_t START_antenna_deploy() { if(deploy_antenna_on_boot_enabled == 1) { //TODO: which mcu should be armed on the antenna deploy system? Error handling. How long to activate? - int8_t arm_result = ANT_CMD_arm_antenna_system(ANT_I2C_BUS_A_MCU_A); + uint8_t arm_result = ANT_CMD_arm_antenna_system(ANT_I2C_BUS_A_MCU_A); if (arm_result != 0) { LOG_message( LOG_SYSTEM_ANTENNA_DEPLOY, @@ -215,7 +215,7 @@ int16_t START_antenna_deploy() { return arm_result; } - int8_t deploy_result = ANT_CMD_start_automated_sequential_deployment(ANT_I2C_BUS_A_MCU_A, 7); + uint8_t deploy_result = ANT_CMD_start_automated_sequential_deployment(ANT_I2C_BUS_A_MCU_A, 7); if (deploy_result != 0) { LOG_message( LOG_SYSTEM_ANTENNA_DEPLOY,