From af46bc2df9ae044d63a16638216aeac4b030306a Mon Sep 17 00:00:00 2001 From: kev9268 Date: Thu, 24 Oct 2024 20:16:47 -0600 Subject: [PATCH 1/4] Added TCMDEXEC_eps_get_list_of_enabled_channels --- .../Core/Inc/telecommands/eps_telecommands.h | 4 +++ .../Core/Src/telecommands/eps_telecommands.c | 34 +++++++++++++++++++ .../telecommands/telecommand_definitions.c | 6 ++++ 3 files changed, 44 insertions(+) diff --git a/firmware/Core/Inc/telecommands/eps_telecommands.h b/firmware/Core/Inc/telecommands/eps_telecommands.h index 85422e7f5..f93bcac08 100644 --- a/firmware/Core/Inc/telecommands/eps_telecommands.h +++ b/firmware/Core/Inc/telecommands/eps_telecommands.h @@ -91,6 +91,10 @@ uint8_t TCMDEXEC_eps_get_piu_housekeeping_data_run_avg_json( char *response_output_buf, uint16_t response_output_buf_len ); +uint8_t TCMDEXEC_eps_get_list_of_enabled_channels( + const char *args_str, TCMD_TelecommandChannel_enum_t tcmd_channel, + char *response_output_buf, uint16_t response_output_buf_len +); #endif /* INCLUDE_GUARD__EPS_TELECOMMANDS_H__ */ diff --git a/firmware/Core/Src/telecommands/eps_telecommands.c b/firmware/Core/Src/telecommands/eps_telecommands.c index e53b86ff6..20a5110f8 100644 --- a/firmware/Core/Src/telecommands/eps_telecommands.c +++ b/firmware/Core/Src/telecommands/eps_telecommands.c @@ -520,3 +520,37 @@ uint8_t TCMDEXEC_eps_get_piu_housekeeping_data_run_avg_json( return 0; } +uint8_t TCMDEXEC_eps_get_list_of_enabled_channels( + const char *args_str, TCMD_TelecommandChannel_enum_t tcmd_channel, + char *response_output_buf, uint16_t response_output_buf_len +) { + + EPS_struct_piu_housekeeping_data_eng_t status; + const uint8_t result = EPS_CMD_get_piu_housekeeping_data_eng(&status); + if (result != 0) { + snprintf(response_output_buf, response_output_buf_len, + "EPS_CMD_get_piu_housekeeping_data_run_avg (err %d)", result); + return 1; + } + + uint16_t status_bitfield = status.stat_ch_on_bitfield; + uint8_t list_of_enabled_channels[16]; + for (int i =0; i> i) & 1; // bit shift right and then check bit status + + if (bit_status == 1) { + list_of_enabled_channels[i] = 1; + } else { + list_of_enabled_channels[i] = 0; + } + } + + // sprintf(buffer, "%d ", i); // Format the index into a buffer + // strcat(result, buffer); // Concatenate the index to result + + snprintf(response_output_buf, response_output_buf_len, + "EPS_CHANNEL_VBATT_STACK: %d, EPS_CHANNEL_5V_STACK: %d, EPS_CHANNEL_5V_CH2_UNUSED: %d " + ,list_of_enabled_channels[0],list_of_enabled_channels[1],list_of_enabled_channels[2]); + + return 0; +} \ No newline at end of file diff --git a/firmware/Core/Src/telecommands/telecommand_definitions.c b/firmware/Core/Src/telecommands/telecommand_definitions.c index 347c799a2..87cfbaf0a 100644 --- a/firmware/Core/Src/telecommands/telecommand_definitions.c +++ b/firmware/Core/Src/telecommands/telecommand_definitions.c @@ -841,6 +841,12 @@ const TCMD_TelecommandDefinition_t TCMD_telecommand_definitions[] = { .tcmd_func = TCMDEXEC_eps_get_piu_housekeeping_data_run_avg_json, .number_of_args = 0, .readiness_level = TCMD_READINESS_LEVEL_FOR_OPERATION, + }, + { + .tcmd_name = "eps_get_list_of_enabled_channels", + .tcmd_func = TCMDEXEC_eps_get_list_of_enabled_channels, + .number_of_args = 0, + .readiness_level = TCMD_READINESS_LEVEL_FOR_OPERATION, }, /* *************************** END EPS Section ************************************** */ From 45d60ff701b22ef519784a30f5bf496337cc9357 Mon Sep 17 00:00:00 2001 From: kev9268 Date: Thu, 7 Nov 2024 19:16:25 -0700 Subject: [PATCH 2/4] Added output for eps_get_list_of_enabled_channels --- README.md | 1 + .../Core/Src/telecommands/eps_telecommands.c | 71 +++++++++++++++---- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b9e47b701..ac73e831d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Please add your name to the list below in your first Pull Request! * Marko V. * Vaibhav K. * Muhammad Ali +* Kevin Hoang ## License and Libraries diff --git a/firmware/Core/Src/telecommands/eps_telecommands.c b/firmware/Core/Src/telecommands/eps_telecommands.c index 20a5110f8..ea100f63d 100644 --- a/firmware/Core/Src/telecommands/eps_telecommands.c +++ b/firmware/Core/Src/telecommands/eps_telecommands.c @@ -534,23 +534,68 @@ uint8_t TCMDEXEC_eps_get_list_of_enabled_channels( } uint16_t status_bitfield = status.stat_ch_on_bitfield; - uint8_t list_of_enabled_channels[16]; - for (int i =0; i> i) & 1; // bit shift right and then check bit status - if (bit_status == 1) { - list_of_enabled_channels[i] = 1; - } else { - list_of_enabled_channels[i] = 0; + switch (i) { + case EPS_CHANNEL_VBATT_STACK: + strcat(response_output_buf,"VBATT_STACK, "); + break; + case EPS_CHANNEL_5V_STACK: + strcat(response_output_buf,"5V_STACK, "); + break; + case EPS_CHANNEL_5V_CH2_UNUSED: + strcat(response_output_buf,"5V_CH2_UNUSED, "); + break; + case EPS_CHANNEL_5V_CH3_UNUSED: + strcat(response_output_buf,"5V_CH3_UNUSED, "); + break; + case EPS_CHANNEL_5V_MPI: + strcat(response_output_buf,"5V_MPI, "); + break; + case EPS_CHANNEL_3V3_STACK: + strcat(response_output_buf,"3V3_STACK, "); + break; + case EPS_CHANNEL_3V3_CAMERA: + strcat(response_output_buf,"3V3_CAMERA, "); + break; + case EPS_CHANNEL_3V3_UHF_ANTENNA_DEPLOY: + strcat(response_output_buf,"3V3_UHF_ANTENNA_DEPLOY, "); + break; + case EPS_CHANNEL_3V3_LORA_MODULE: + strcat(response_output_buf,"3V3_LORA_MODULE, "); + break; + case EPS_CHANNEL_VBATT_CH9_UNUSED: + strcat(response_output_buf,"VBATT_CH9_UNUSED, "); + break; + case EPS_CHANNEL_VBATT_CH10_UNUSED: + strcat(response_output_buf,"VBATT_CH10_UNUSED, "); + break; + case EPS_CHANNEL_VBATT_CH11_UNUSED: + strcat(response_output_buf,"VBATT_CH11_UNUSED, "); + break; + case EPS_CHANNEL_12V_MPI: + strcat(response_output_buf,"12V_MPI, "); + break; + case EPS_CHANNEL_12V_BOOM: + strcat(response_output_buf,"12V_BOOM, "); + break; + case EPS_CHANNEL_3V3_CH14_UNUSED: + strcat(response_output_buf,"3V3_CH14_UNUSED, "); + break; + case EPS_CHANNEL_3V3_CH15_UNUSED: + strcat(response_output_buf,"3V3_CH15_UNUSED, "); + break; + default: + break; + } + } + if ((status_oc_bitfield & 1)==1){ // checking status of ch16 because the info is on a different bitfield that the inital 0-15 channels + strcat(response_output_buf,"28V6_CH16_UNUSED, "); } } - // sprintf(buffer, "%d ", i); // Format the index into a buffer - // strcat(result, buffer); // Concatenate the index to result - - snprintf(response_output_buf, response_output_buf_len, - "EPS_CHANNEL_VBATT_STACK: %d, EPS_CHANNEL_5V_STACK: %d, EPS_CHANNEL_5V_CH2_UNUSED: %d " - ,list_of_enabled_channels[0],list_of_enabled_channels[1],list_of_enabled_channels[2]); - return 0; } \ No newline at end of file From 3dc3a25f0c003070ae95ade8d86439973a18bfec Mon Sep 17 00:00:00 2001 From: kev9268 Date: Tue, 26 Nov 2024 02:41:39 -0700 Subject: [PATCH 3/4] convert eps status bitfield to str function --- .../Inc/eps_drivers/eps_channel_control.h | 2 + .../Core/Inc/telecommands/eps_telecommands.h | 2 +- .../Src/eps_drivers/eps_channel_control.c | 26 +++++++ .../Core/Src/telecommands/eps_telecommands.c | 75 +++---------------- .../telecommands/telecommand_definitions.c | 4 +- 5 files changed, 40 insertions(+), 69 deletions(-) diff --git a/firmware/Core/Inc/eps_drivers/eps_channel_control.h b/firmware/Core/Inc/eps_drivers/eps_channel_control.h index 9c3097e3b..170250d76 100644 --- a/firmware/Core/Inc/eps_drivers/eps_channel_control.h +++ b/firmware/Core/Inc/eps_drivers/eps_channel_control.h @@ -8,4 +8,6 @@ EPS_CHANNEL_enum_t EPS_channel_from_str(const char channel_name[]); uint8_t EPS_set_channel_enabled(EPS_CHANNEL_enum_t channel, uint8_t enabled); +void EPS_convert_stat_bit_to_string(char *response_output_buf, uint16_t stat_bit_1 , uint16_t stat_bit_2); + #endif // INCLUDE_GUARD__EPS_CHANNEL_CONTROL_H diff --git a/firmware/Core/Inc/telecommands/eps_telecommands.h b/firmware/Core/Inc/telecommands/eps_telecommands.h index f93bcac08..747f739cf 100644 --- a/firmware/Core/Inc/telecommands/eps_telecommands.h +++ b/firmware/Core/Inc/telecommands/eps_telecommands.h @@ -91,7 +91,7 @@ uint8_t TCMDEXEC_eps_get_piu_housekeeping_data_run_avg_json( char *response_output_buf, uint16_t response_output_buf_len ); -uint8_t TCMDEXEC_eps_get_list_of_enabled_channels( +uint8_t TCMDEXEC_eps_get_enabled_channels_json( const char *args_str, TCMD_TelecommandChannel_enum_t tcmd_channel, char *response_output_buf, uint16_t response_output_buf_len ); diff --git a/firmware/Core/Src/eps_drivers/eps_channel_control.c b/firmware/Core/Src/eps_drivers/eps_channel_control.c index 3d7fbedb6..cdf90b654 100644 --- a/firmware/Core/Src/eps_drivers/eps_channel_control.c +++ b/firmware/Core/Src/eps_drivers/eps_channel_control.c @@ -62,3 +62,29 @@ uint8_t EPS_set_channel_enabled(EPS_CHANNEL_enum_t channel, uint8_t enabled) { } return 100; // Unreachable } + +/// @brief Uses the status bitfield from eps and converts it to a list-of-string of available channels. +/// @param response_output_buf The buffer to output the list-of-string of available channels +/// @param status_bitfield_1 The status bitfield of channels 0-15. +/// @param status_bitfield_2 The status bitfield of channels 16-31. +void EPS_convert_stat_bit_to_string(char *response_output_buf, uint16_t status_bitfield_1 , uint16_t status_bitfield_2){ + + if ((status_bitfield_1 & 1) == 1) {strcat(response_output_buf, "VBATT_STACK, ");} + if (((status_bitfield_1 >> 1) & 1) == 1) {strcat(response_output_buf,"5V_STACK, ");} + if (((status_bitfield_1 >> 2) & 1) == 1) {strcat(response_output_buf,"5V_CH2_UNUSED, ");} + if (((status_bitfield_1 >> 3) & 1) == 1) {strcat(response_output_buf,"5V_CH3_UNUSED, ");} + if (((status_bitfield_1 >> 4) & 1) == 1) {strcat(response_output_buf,"5V_MPI, ");} + if (((status_bitfield_1 >> 5) & 1) == 1) {strcat(response_output_buf,"3V3_STACK, ");} + if (((status_bitfield_1 >> 6) & 1) == 1) {strcat(response_output_buf,"3V3_CAMERA, ");} + if (((status_bitfield_1 >> 7) & 1) == 1) {strcat(response_output_buf,"3V3_UHF_ANTENNA_DEPLOY, ");} + if (((status_bitfield_1 >> 8) & 1) == 1) {strcat(response_output_buf,"3V3_LORA_MODULE, ");} + if (((status_bitfield_1 >> 9) & 1) == 1) {strcat(response_output_buf,"VBATT_CH9_UNUSED, ");} + if (((status_bitfield_1 >> 10) & 1) == 1) {strcat(response_output_buf,"VBATT_CH10_UNUSED, ");} + if (((status_bitfield_1 >> 11) & 1) == 1) {strcat(response_output_buf,"VBATT_CH11_UNUSED, ");} + if (((status_bitfield_1 >> 12) & 1) == 1) {strcat(response_output_buf,"12V_MPI, ");} + if (((status_bitfield_1 >> 13) & 1) == 1) {strcat(response_output_buf,"12V_BOOM, ");} + if (((status_bitfield_1 >> 14) & 1) == 1) {strcat(response_output_buf,"3V3_CH14_UNUSED, ");} + if (((status_bitfield_1 >> 15) & 1) == 1) {strcat(response_output_buf,"3V3_CH15_UNUSED, ");} + if ((status_bitfield_2 & 1) == 1) {strcat(response_output_buf,"28V6_CH16_UNUSED, ");} + +} \ No newline at end of file diff --git a/firmware/Core/Src/telecommands/eps_telecommands.c b/firmware/Core/Src/telecommands/eps_telecommands.c index ea100f63d..e5f437f70 100644 --- a/firmware/Core/Src/telecommands/eps_telecommands.c +++ b/firmware/Core/Src/telecommands/eps_telecommands.c @@ -520,82 +520,25 @@ uint8_t TCMDEXEC_eps_get_piu_housekeeping_data_run_avg_json( return 0; } -uint8_t TCMDEXEC_eps_get_list_of_enabled_channels( +uint8_t TCMDEXEC_eps_get_enabled_channels_json( const char *args_str, TCMD_TelecommandChannel_enum_t tcmd_channel, char *response_output_buf, uint16_t response_output_buf_len ) { - EPS_struct_piu_housekeeping_data_eng_t status; - const uint8_t result = EPS_CMD_get_piu_housekeeping_data_eng(&status); + EPS_struct_pdu_housekeeping_data_eng_t status; + const uint8_t result = EPS_CMD_get_pdu_housekeeping_data_eng(&status); + if (result != 0) { snprintf(response_output_buf, response_output_buf_len, "EPS_CMD_get_piu_housekeeping_data_run_avg (err %d)", result); return 1; } - uint16_t status_bitfield = status.stat_ch_on_bitfield; - uint16_t status_oc_bitfield = status.stat_ch_overcurrent_fault_bitfield; - strcat(response_output_buf, "Current Channels Enabled: "); - for (int i =0; i<16; i++){ // check bit field for channels 0-15 - uint8_t bit_status = (status_bitfield >> i) & 1; // bit shift right and then check bit status - if (bit_status == 1) { - switch (i) { - case EPS_CHANNEL_VBATT_STACK: - strcat(response_output_buf,"VBATT_STACK, "); - break; - case EPS_CHANNEL_5V_STACK: - strcat(response_output_buf,"5V_STACK, "); - break; - case EPS_CHANNEL_5V_CH2_UNUSED: - strcat(response_output_buf,"5V_CH2_UNUSED, "); - break; - case EPS_CHANNEL_5V_CH3_UNUSED: - strcat(response_output_buf,"5V_CH3_UNUSED, "); - break; - case EPS_CHANNEL_5V_MPI: - strcat(response_output_buf,"5V_MPI, "); - break; - case EPS_CHANNEL_3V3_STACK: - strcat(response_output_buf,"3V3_STACK, "); - break; - case EPS_CHANNEL_3V3_CAMERA: - strcat(response_output_buf,"3V3_CAMERA, "); - break; - case EPS_CHANNEL_3V3_UHF_ANTENNA_DEPLOY: - strcat(response_output_buf,"3V3_UHF_ANTENNA_DEPLOY, "); - break; - case EPS_CHANNEL_3V3_LORA_MODULE: - strcat(response_output_buf,"3V3_LORA_MODULE, "); - break; - case EPS_CHANNEL_VBATT_CH9_UNUSED: - strcat(response_output_buf,"VBATT_CH9_UNUSED, "); - break; - case EPS_CHANNEL_VBATT_CH10_UNUSED: - strcat(response_output_buf,"VBATT_CH10_UNUSED, "); - break; - case EPS_CHANNEL_VBATT_CH11_UNUSED: - strcat(response_output_buf,"VBATT_CH11_UNUSED, "); - break; - case EPS_CHANNEL_12V_MPI: - strcat(response_output_buf,"12V_MPI, "); - break; - case EPS_CHANNEL_12V_BOOM: - strcat(response_output_buf,"12V_BOOM, "); - break; - case EPS_CHANNEL_3V3_CH14_UNUSED: - strcat(response_output_buf,"3V3_CH14_UNUSED, "); - break; - case EPS_CHANNEL_3V3_CH15_UNUSED: - strcat(response_output_buf,"3V3_CH15_UNUSED, "); - break; - default: - break; - } - } - if ((status_oc_bitfield & 1)==1){ // checking status of ch16 because the info is on a different bitfield that the inital 0-15 channels - strcat(response_output_buf,"28V6_CH16_UNUSED, "); - } - } + const uint16_t status_bitfield = status.stat_ch_on_bitfield; + const uint16_t status_ch_ext_bitfield = status.stat_ch_ext_on_bitfield; + strcat(response_output_buf, "{\"EPS_Channels_Enabled\": \""); + EPS_convert_stat_bit_to_string(response_output_buf, status_bitfield, status_ch_ext_bitfield); + strcat(response_output_buf, "\"}"); return 0; } \ No newline at end of file diff --git a/firmware/Core/Src/telecommands/telecommand_definitions.c b/firmware/Core/Src/telecommands/telecommand_definitions.c index 87cfbaf0a..2160ee7c3 100644 --- a/firmware/Core/Src/telecommands/telecommand_definitions.c +++ b/firmware/Core/Src/telecommands/telecommand_definitions.c @@ -843,8 +843,8 @@ const TCMD_TelecommandDefinition_t TCMD_telecommand_definitions[] = { .readiness_level = TCMD_READINESS_LEVEL_FOR_OPERATION, }, { - .tcmd_name = "eps_get_list_of_enabled_channels", - .tcmd_func = TCMDEXEC_eps_get_list_of_enabled_channels, + .tcmd_name = "eps_get_enabled_channels_json", + .tcmd_func = TCMDEXEC_eps_get_enabled_channels_json, .number_of_args = 0, .readiness_level = TCMD_READINESS_LEVEL_FOR_OPERATION, }, From c0e5677a199085b7356e0df09383f04ef67495d8 Mon Sep 17 00:00:00 2001 From: kev9268 Date: Thu, 28 Nov 2024 19:55:09 -0700 Subject: [PATCH 4/4] Adding test plan in comments --- .../Core/Src/telecommands/eps_telecommands.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/firmware/Core/Src/telecommands/eps_telecommands.c b/firmware/Core/Src/telecommands/eps_telecommands.c index e5f437f70..d11da8d01 100644 --- a/firmware/Core/Src/telecommands/eps_telecommands.c +++ b/firmware/Core/Src/telecommands/eps_telecommands.c @@ -540,5 +540,32 @@ uint8_t TCMDEXEC_eps_get_enabled_channels_json( EPS_convert_stat_bit_to_string(response_output_buf, status_bitfield, status_ch_ext_bitfield); strcat(response_output_buf, "\"}"); + // Test plan: + + // Use eps_get_pdu_housekeeping_data_eng_json to output bitfield of channels enabled + // CTS1+eps_get_pdu_housekeeping_data_eng_json()! + // read bitfield from preexisting housekeping_json file to create expectations of string output + // Ex. bitfield = "0011000111110011" = 12787 + // expected response ("VBATT_STACK, 5V_STACK, 5V_MPI, 3V3_STACK, 3V3_CAMERA, 3V3_UHF_ANTENNA_DEPLOY, 3V3_LORA_MODULE, 12V_MPI, 12V_BOOM") + // 9 channels enabled (0,1,4,5,6,7,8,12,13) + + // Call function CTS1+eps_get_enabled_channels_json()! + // Ex. if bitfield = "0011000111110011" = 12787 + // expected response {"EPS_Channels_Enabled": "VBATT_STACK, 5V_STACK, 5V_MPI, 3V3_STACK, 3V3_CAMERA, 3V3_UHF_ANTENNA_DEPLOY, 3V3_LORA_MODULE, 12V_MPI, 12V_BOOM, "} + + // enable/disable some channels and then recalling testing function CTS1+eps_get_enabled_channels_json()! + + // Ex. if first call had bitfield=12787 + // then applying the commands + + // CTS1+eps_set_channel_enabled("stack_5v,off")! (channel 1) + // CTS1+eps_set_channel_enabled("vbatt_stack,off")! (channel 0) + // CTS1+eps_set_channel_enabled("2,on")! (channel 2) + // CTS1+eps_set_channel_enabled("16,on")! (channel 16) + + // CTS1+eps_get_enabled_channels_json()! + + // expected response: {"EPS_Channels_Enabled": "5V_CH2_UNUSED, 5V_MPI, 3V3_STACK, 3V3_CAMERA, 3V3_UHF_ANTENNA_DEPLOY, 3V3_LORA_MODULE, 12V_MPI, 12V_BOOM, 28V6_CH16_UNUSED, "} + return 0; } \ No newline at end of file