Skip to content

Commit

Permalink
CRIT LED Changes (#1262)
Browse files Browse the repository at this point in the history
### Changelist 
<!-- Give a list of the changes covered in this PR. This will help both
you and the reviewer keep this PR within scope. -->
- Hearbeat turns off LED
- Shutdown OK test (does not follow TSAL, should it?)

### Testing Done
<!-- Outline the testing that was done to demonstrate the changes are
solid. This could be unit tests, integration tests, testing on the car,
etc. Include relevant code snippets, screenshots, etc as needed. -->
yes

### Resolved Tickets
<!-- Link any tickets that this PR resolves. -->

---------

Co-authored-by: Gus Tahara-Edmonds <[email protected]>
  • Loading branch information
Lucien950 and gtaharaedmonds authored May 21, 2024
1 parent 9426dba commit 532d898
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions can_bus/quadruna/CRIT/CRIT_rx.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"BMS_OkStatuses",
"VC_Regen",
"VC_TorqueVectoring",
"VC_GlobalShdnNodeStatus",
"Debug_CanMode"
]
}
36 changes: 30 additions & 6 deletions firmware/quadruna/CRIT/src/app/app_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,33 @@

BoardLEDStatus board_worst_status(CanAlertBoard b)
{
bool is_missing_heartbeat;
switch (b)
{
case BMS_ALERT_BOARD:
is_missing_heartbeat = app_canAlerts_CRIT_Fault_MissingBMSHeartbeat_get();
break;
case CRIT_ALERT_BOARD:
is_missing_heartbeat = false; // lmao like
break;
case FSM_ALERT_BOARD:
is_missing_heartbeat = app_canAlerts_CRIT_Fault_MissingFSMHeartbeat_get();
break;
case RSM_ALERT_BOARD:
is_missing_heartbeat = app_canAlerts_CRIT_Fault_MissingRSMHeartbeat_get();
break;
case VC_ALERT_BOARD:
is_missing_heartbeat = app_canAlerts_CRIT_Fault_MissingVCHeartbeat_get();
break;
}

if (is_missing_heartbeat)
return BOARD_LED_STATUS_MISSING_HEARTBEAT;
if (app_canAlerts_BoardHasFault(b))
return FAULT;
return BOARD_LED_STATUS_FAULT;
if (app_canAlerts_BoardHasWarning(b))
return WARNING;
return OK;
return BOARD_LED_STATUS_WARNING;
return BOARD_LED_STATUS_OK;
}

void app_leds_update(void)
Expand All @@ -27,8 +49,10 @@ void app_leds_update(void)
const bool torquevec_light_on = app_canRx_VC_TorqueVectoringEnabled_get();
io_led_torquevec_set(torquevec_light_on);

const BoardLEDStatus shutdown_sensor = OK; // TODO implement VC last shutdown node code is in
io_led_shutdown_set(shutdown_sensor);
// or driven by BMS_drive_state???
const BoardLEDStatus shutdown_sensor_ok =
app_canRx_VC_FirstFaultNode_get() == SHDN_OK ? BOARD_LED_STATUS_OK : BOARD_LED_STATUS_FAULT;
io_led_shutdown_set(shutdown_sensor_ok);

const BoardLEDStatus bms_status = board_worst_status(BMS_ALERT_BOARD);
io_led_bms_status_set(bms_status);
Expand All @@ -46,5 +70,5 @@ void app_leds_update(void)
io_led_rsm_status_set(rsm_status);

// TODO AUX status
io_led_aux_status_set(WHITE);
io_led_aux_status_set(BOARD_LED_STATUS_NOT_IMPLEMENTED);
}
13 changes: 8 additions & 5 deletions firmware/quadruna/CRIT/src/io/io_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,27 @@ void set_led_from_board_status(const RgbLed *led, const BoardLEDStatus status)
{
switch (status)
{
case FAULT:
case BOARD_LED_STATUS_FAULT:
hw_rgbLed_enable(led, RGB_RED);
break;
case OK:
case BOARD_LED_STATUS_OK:
hw_rgbLed_enable(led, RGB_GREEN);
break;
case WARNING:
case BOARD_LED_STATUS_WARNING:
hw_rgbLed_enable(led, RGB_YELLOW);
break;
case WHITE:
case BOARD_LED_STATUS_NOT_IMPLEMENTED:
hw_rgbLed_enable(led, RGB_WHITE);
break;
case BOARD_LED_STATUS_MISSING_HEARTBEAT:
hw_rgbLed_enable(led, RGB_OFF);
break;
}
}

void io_led_shutdown_set(const BoardLEDStatus status)
{
assert(status != WHITE && status != WARNING);
assert(status != BOARD_LED_STATUS_NOT_IMPLEMENTED && status != BOARD_LED_STATUS_WARNING);
set_led_from_board_status(leds->shdn_led, status);
}

Expand Down
9 changes: 5 additions & 4 deletions firmware/quadruna/CRIT/src/io/io_leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ void io_led_torquevec_set(bool val);

typedef enum
{
OK,
WARNING,
FAULT,
WHITE
BOARD_LED_STATUS_OK,
BOARD_LED_STATUS_WARNING,
BOARD_LED_STATUS_FAULT,
BOARD_LED_STATUS_NOT_IMPLEMENTED,
BOARD_LED_STATUS_MISSING_HEARTBEAT
} BoardLEDStatus;

void io_led_shutdown_set(BoardLEDStatus status);
Expand Down
10 changes: 5 additions & 5 deletions firmware/quadruna/CRIT/test/test_ledStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ TEST_F(LedStatusTest, vc_board_status_led_control_with_critical_error)
{
can_update(true);
LetTimePass(10);
ASSERT_EQ(1, assert_func(FAULT));
ASSERT_EQ(1, assert_func(BOARD_LED_STATUS_FAULT));
}
}

Expand All @@ -114,7 +114,7 @@ TEST_F(LedStatusTest, vc_board_status_led_control_with_warning)
{
can_update(true);
LetTimePass(10);
ASSERT_EQ(1, assert_func(WARNING));
ASSERT_EQ(1, assert_func(BOARD_LED_STATUS_WARNING));
}
}

Expand All @@ -127,7 +127,7 @@ TEST_F(LedStatusTest, vc_board_status_led_control_with_no_error)
fake_io_led_fsm_status_set_callCountForArgs, fake_io_led_rsm_status_set_callCountForArgs,
fake_io_led_crit_status_set_callCountForArgs })
{
const auto out = assert_func(OK);
const auto out = assert_func(BOARD_LED_STATUS_OK);
ASSERT_EQ(1, out);
}
}
Expand All @@ -153,7 +153,7 @@ TEST_F(LedStatusTest, vc_board_status_led_control_with_multiple_errors)
fault(true);
warning(true);
LetTimePass(10);
ASSERT_EQ(1, assert_func(FAULT));
ASSERT_EQ(0, assert_func(WARNING));
ASSERT_EQ(1, assert_func(BOARD_LED_STATUS_FAULT));
ASSERT_EQ(0, assert_func(BOARD_LED_STATUS_WARNING));
}
}

0 comments on commit 532d898

Please sign in to comment.