Skip to content

Commit 4e9bb4b

Browse files
committed
Remove duplicate logic in message prioritization
There's no need to check which sensors are enabled, since if they're not enabled then messages won't be queued, and the get_num_msgs_enqueued call will return 0.
1 parent 4a7a7fb commit 4e9bb4b

1 file changed

Lines changed: 9 additions & 46 deletions

File tree

microSWIFT_V2.2/Core/Src/threadx_support.c

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -435,56 +435,19 @@ uint32_t get_next_telemetry_message ( uint8_t **msg_buffer, microSWIFT_configura
435435

436436
}
437437

438-
// First case, both light and turbidity sensors are enabled
439-
if ( config->turbidity_enabled && config->light_enabled )
438+
439+
// First priority is light telemetry as it contains the most elements
440+
if ( (num_light_msgs >= num_waves_msgs) && (num_light_msgs >= num_turbidity_msgs) )
440441
{
441-
// First priority is light telemetry as it contains the most elements
442-
if ( (num_light_msgs >= num_waves_msgs) && (num_light_msgs >= num_turbidity_msgs) )
443-
{
444-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (LIGHT_TELEMETRY);
445-
msg_type = LIGHT_TELEMETRY;
446-
}
447-
// Second priority is turbidity as there are fewer per message than light and more than waves
448-
else if ( (num_turbidity_msgs >= num_waves_msgs) )
449-
{
450-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (TURBIDITY_TELEMETRY);
451-
msg_type = TURBIDITY_TELEMETRY;
452-
}
453-
else
454-
{
455-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (WAVES_TELEMETRY);
456-
msg_type = WAVES_TELEMETRY;
457-
}
442+
*msg_buffer = persistent_ram_get_prioritized_unsent_message (LIGHT_TELEMETRY);
443+
msg_type = LIGHT_TELEMETRY;
458444
}
459-
// Only turbidity enabled
460-
else if ( config->turbidity_enabled )
445+
// Second priority is turbidity as there are fewer per message than light and more than waves
446+
else if ( (num_turbidity_msgs >= num_waves_msgs) )
461447
{
462-
if ( (num_turbidity_msgs >= num_waves_msgs) )
463-
{
464-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (TURBIDITY_TELEMETRY);
465-
msg_type = TURBIDITY_TELEMETRY;
466-
}
467-
else
468-
{
469-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (WAVES_TELEMETRY);
470-
msg_type = WAVES_TELEMETRY;
471-
}
472-
}
473-
// Only light enabled
474-
else if ( config->light_enabled )
475-
{
476-
if ( (num_light_msgs >= num_waves_msgs) )
477-
{
478-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (LIGHT_TELEMETRY);
479-
msg_type = LIGHT_TELEMETRY;
480-
}
481-
else
482-
{
483-
*msg_buffer = persistent_ram_get_prioritized_unsent_message (WAVES_TELEMETRY);
484-
msg_type = WAVES_TELEMETRY;
485-
}
448+
*msg_buffer = persistent_ram_get_prioritized_unsent_message (TURBIDITY_TELEMETRY);
449+
msg_type = TURBIDITY_TELEMETRY;
486450
}
487-
// Neither turbidity nor light sensors are enabled
488451
else
489452
{
490453
*msg_buffer = persistent_ram_get_prioritized_unsent_message (WAVES_TELEMETRY);

0 commit comments

Comments
 (0)