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/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 85422e7f5..747f739cf 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_enabled_channels_json( + 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/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 e53b86ff6..d11da8d01 100644 --- a/firmware/Core/Src/telecommands/eps_telecommands.c +++ b/firmware/Core/Src/telecommands/eps_telecommands.c @@ -520,3 +520,52 @@ uint8_t TCMDEXEC_eps_get_piu_housekeeping_data_run_avg_json( return 0; } +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_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; + } + + 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, "\"}"); + + // 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 diff --git a/firmware/Core/Src/telecommands/telecommand_definitions.c b/firmware/Core/Src/telecommands/telecommand_definitions.c index 347c799a2..2160ee7c3 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_enabled_channels_json", + .tcmd_func = TCMDEXEC_eps_get_enabled_channels_json, + .number_of_args = 0, + .readiness_level = TCMD_READINESS_LEVEL_FOR_OPERATION, }, /* *************************** END EPS Section ************************************** */