Skip to content
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

TCMD output into list of strings, EPS channels currently enabled #232

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions firmware/Core/Inc/eps_drivers/eps_channel_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions firmware/Core/Inc/telecommands/eps_telecommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
Expand Down
26 changes: 26 additions & 0 deletions firmware/Core/Src/eps_drivers/eps_channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ");}

}
49 changes: 49 additions & 0 deletions firmware/Core/Src/telecommands/eps_telecommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions firmware/Core/Src/telecommands/telecommand_definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ************************************** */
Expand Down