2022-07-26 11:24:44 +08:00
|
|
|
const CanMsg BODY_TX_MSGS[] = {{0x250, 0, 8}, {0x250, 0, 6}, {0x251, 0, 5}, // body
|
2023-11-20 16:15:46 +08:00
|
|
|
{0x350, 0, 8}, {0x350, 0, 6}, {0x351, 0, 5}, // knee
|
|
|
|
{0x1, 0, 8}}; // CAN flasher
|
2022-07-23 13:57:20 +08:00
|
|
|
|
2023-11-20 14:44:13 +08:00
|
|
|
RxCheck body_rx_checks[] = {
|
2023-12-01 11:20:08 +08:00
|
|
|
{.msg = {{0x201, 0, 8, .check_checksum = false, .max_counter = 0U, .frequency = 100U}, { 0 }, { 0 }}},
|
2022-04-01 06:58:54 +08:00
|
|
|
};
|
|
|
|
|
2023-11-20 12:03:35 +08:00
|
|
|
static void body_rx_hook(CANPacket_t *to_push) {
|
2023-08-18 06:51:42 +08:00
|
|
|
// body is never at standstill
|
|
|
|
vehicle_moving = true;
|
|
|
|
|
2023-11-20 12:03:35 +08:00
|
|
|
if (GET_ADDR(to_push) == 0x201U) {
|
2023-11-11 11:02:32 +08:00
|
|
|
controls_allowed = true;
|
|
|
|
}
|
2022-04-01 06:58:54 +08:00
|
|
|
}
|
|
|
|
|
2023-11-20 08:47:09 +08:00
|
|
|
static bool body_tx_hook(CANPacket_t *to_send) {
|
2023-11-24 08:48:08 +08:00
|
|
|
bool tx = true;
|
2022-04-01 03:02:19 +08:00
|
|
|
int addr = GET_ADDR(to_send);
|
2023-11-11 11:02:32 +08:00
|
|
|
int len = GET_LEN(to_send);
|
2022-04-01 03:02:19 +08:00
|
|
|
|
2023-11-20 16:15:46 +08:00
|
|
|
if (!controls_allowed && (addr != 0x1)) {
|
2023-11-24 08:48:08 +08:00
|
|
|
tx = false;
|
2022-04-01 03:02:19 +08:00
|
|
|
}
|
2022-12-01 14:09:13 +08:00
|
|
|
|
2023-11-11 11:02:32 +08:00
|
|
|
// Allow going into CAN flashing mode for base & knee even if controls are not allowed
|
|
|
|
bool flash_msg = ((addr == 0x250) || (addr == 0x350)) && (len == 8);
|
|
|
|
if (!controls_allowed && (GET_BYTES(to_send, 0, 4) == 0xdeadfaceU) && (GET_BYTES(to_send, 4, 4) == 0x0ab00b1eU) && flash_msg) {
|
2023-11-24 08:48:08 +08:00
|
|
|
tx = true;
|
2022-07-27 13:34:34 +08:00
|
|
|
}
|
2022-04-01 03:02:19 +08:00
|
|
|
|
|
|
|
return tx;
|
|
|
|
}
|
|
|
|
|
2023-11-20 14:44:13 +08:00
|
|
|
static safety_config body_init(uint16_t param) {
|
2022-04-01 06:58:54 +08:00
|
|
|
UNUSED(param);
|
2023-11-20 16:15:46 +08:00
|
|
|
return BUILD_SAFETY_CFG(body_rx_checks, BODY_TX_MSGS);
|
2022-04-01 06:58:54 +08:00
|
|
|
}
|
|
|
|
|
2022-04-01 03:02:19 +08:00
|
|
|
const safety_hooks body_hooks = {
|
2022-04-01 06:58:54 +08:00
|
|
|
.init = body_init,
|
|
|
|
.rx = body_rx_hook,
|
2022-04-01 03:02:19 +08:00
|
|
|
.tx = body_tx_hook,
|
|
|
|
.fwd = default_fwd_hook,
|
|
|
|
};
|