Skip to content
Closed
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
8 changes: 8 additions & 0 deletions opendbc/safety/tests/libsafety/libsafety_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class CANPacket:
void set_honda_alt_brake_msg(bool c);
void set_honda_bosch_long(bool c);
int get_honda_hw(void);

uint8_t TEST_get_counter(CANPacket_t *msg);
uint32_t TEST_get_checksum(CANPacket_t *msg);
uint32_t TEST_compute_checksum(CANPacket_t *msg);
bool TEST_get_quality_flag_valid(CANPacket_t *msg);

void TEST_rx_hook(CANPacket_t *msg);
bool TEST_tx_hook(CANPacket_t *msg);
""")

class LibSafety:
Expand Down
26 changes: 26 additions & 0 deletions opendbc/safety/tests/libsafety/safety.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,29 @@ void init_tests(void){
// assumes autopark on safety mode init to avoid a fault. get rid of that for testing
tesla_autopark = false;
}

uint8_t TEST_get_counter(const CANPacket_t *msg) {
return current_hooks->get_counter ? current_hooks->get_counter(msg) : 0;
}
uint32_t TEST_get_checksum(const CANPacket_t *msg) {
return current_hooks->get_checksum ? current_hooks->get_checksum(msg) : 0;
}
uint32_t TEST_compute_checksum(const CANPacket_t *msg) {
return current_hooks->compute_checksum ? current_hooks->compute_checksum(msg) : 0;
}
bool TEST_get_quality_flag_valid(const CANPacket_t *msg) {
return current_hooks->get_quality_flag_valid ? current_hooks->get_quality_flag_valid(msg) : true;
}

void TEST_rx_hook(const CANPacket_t *msg) {
if (current_hooks->rx) {
current_hooks->rx(msg);
}
}

bool TEST_tx_hook(const CANPacket_t *msg) {
if (current_hooks->tx) {
return current_hooks->tx(msg);
}
return false;
}