diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9d2dfc9c3ad..5788e16b2c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,6 @@ repos: additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites', 'types-pycurl'] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.14 + rev: v0.2.1 hooks: - id: ruff diff --git a/board/boards/black.h b/board/boards/black.h index d3d0f8619dc..d72ab39aa12 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -1,6 +1,6 @@ -// ///////////////////// // -// Black Panda + Harness // -// ///////////////////// // +// /////////////////////////////// // +// Black Panda (STM32F4) + Harness // +// /////////////////////////////// // void black_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ @@ -136,7 +136,7 @@ void black_init(void) { // Set normal CAN mode black_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -165,7 +165,6 @@ const harness_configuration black_harness_config = { const board board_black = { .set_bootkick = unused_set_bootkick, .harness_config = &black_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = false, .has_canfd = false, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index ee7103b06ac..06382ceb76e 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -21,7 +21,6 @@ typedef bool (*board_read_som_gpio)(void); struct board { const harness_configuration *harness_config; - const bool has_hw_gmlan; const bool has_obd; const bool has_spi; const bool has_canfd; diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 4eb4bcc283e..ed120bb052f 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -1,3 +1,7 @@ +// ////////////////////////// // +// Cuatro (STM32H7) + Harness // +// ////////////////////////// // + void cuatro_set_led(uint8_t color, bool enabled) { switch (color) { case LED_RED: @@ -14,9 +18,52 @@ void cuatro_set_led(uint8_t color, bool enabled) { } } +void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) { + switch (transceiver) { + case 1U: + set_gpio_output(GPIOB, 7, !enabled); + break; + case 2U: + set_gpio_output(GPIOB, 10, !enabled); + break; + case 3U: + set_gpio_output(GPIOD, 8, !enabled); + break; + case 4U: + set_gpio_output(GPIOB, 11, !enabled); + break; + default: + break; + } +} + +void cuatro_enable_can_transceivers(bool enabled) { + uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U; + for (uint8_t i=1U; i<=4U; i++) { + // Leave main CAN always on for CAN-based ignition detection + if (i == main_bus) { + cuatro_enable_can_transceiver(i, true); + } else { + cuatro_enable_can_transceiver(i, enabled); + } + } +} + void cuatro_init(void) { red_chiplet_init(); + // CAN transceiver enables + set_gpio_pullup(GPIOB, 7, PULL_NONE); + set_gpio_mode(GPIOB, 7, MODE_OUTPUT); + set_gpio_pullup(GPIOD, 8, PULL_NONE); + set_gpio_mode(GPIOD, 8, MODE_OUTPUT); + + // FDCAN3, different pins on this package than the rest of the reds + set_gpio_pullup(GPIOD, 12, PULL_NONE); + set_gpio_alternate(GPIOD, 12, GPIO_AF5_FDCAN3); + set_gpio_pullup(GPIOD, 13, PULL_NONE); + set_gpio_alternate(GPIOD, 13, GPIO_AF5_FDCAN3); + // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); @@ -46,7 +93,6 @@ void cuatro_init(void) { const board board_cuatro = { .harness_config = &red_chiplet_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = true, .has_canfd = true, @@ -57,8 +103,8 @@ const board board_cuatro = { .fan_enable_cooldown_time = 3U, .init = cuatro_init, .init_bootloader = unused_init_bootloader, - .enable_can_transceiver = red_chiplet_enable_can_transceiver, - .enable_can_transceivers = red_chiplet_enable_can_transceivers, + .enable_can_transceiver = cuatro_enable_can_transceiver, + .enable_can_transceivers = cuatro_enable_can_transceivers, .set_led = cuatro_set_led, .set_can_mode = red_chiplet_set_can_mode, .check_ignition = red_check_ignition, diff --git a/board/boards/dos.h b/board/boards/dos.h index b76f8993fff..e93c0159113 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -1,6 +1,6 @@ -// ///////////// // -// Dos + Harness // -// ///////////// // +// /////////////////////// // +// Dos (STM32F4) + Harness // +// /////////////////////// // void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ @@ -168,7 +168,7 @@ void dos_init(void) { // Set normal CAN mode dos_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -193,7 +193,6 @@ const harness_configuration dos_harness_config = { const board board_dos = { .harness_config = &dos_harness_config, - .has_hw_gmlan = false, .has_obd = true, #ifdef ENABLE_SPI .has_spi = true, diff --git a/board/boards/grey.h b/board/boards/grey.h index 6065c3d227a..e8f90e263d9 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -1,13 +1,12 @@ -// ////////// // -// Grey Panda // -// ////////// // +// //////////////////// // +// Grey Panda (STM32F4) // +// //////////////////// // // Most hardware functionality is similar to white panda const board board_grey = { .set_bootkick = unused_set_bootkick, .harness_config = &white_harness_config, - .has_hw_gmlan = true, .has_obd = false, .has_spi = false, .has_canfd = false, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index 1909b2a5311..2b653e9ed1a 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -1,6 +1,6 @@ -// ///// // -// Pedal // -// ///// // +// ///////////// // +// Pedal STM32F2 // +// ///////////// // void pedal_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ @@ -69,7 +69,6 @@ const harness_configuration pedal_harness_config = { const board board_pedal = { .set_bootkick = unused_set_bootkick, .harness_config = &pedal_harness_config, - .has_hw_gmlan = false, .has_obd = false, .has_spi = false, .has_canfd = false, diff --git a/board/boards/red.h b/board/boards/red.h index 709d44df50d..58410894bc4 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -1,6 +1,6 @@ -// ///////////////////// // -// Red Panda + Harness // -// ///////////////////// // +// ///////////////////////////// // +// Red Panda (STM32H7) + Harness // +// ///////////////////////////// // void red_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver) { @@ -150,7 +150,7 @@ void red_init(void) { // Set normal CAN mode red_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -173,7 +173,6 @@ const harness_configuration red_harness_config = { const board board_red = { .set_bootkick = unused_set_bootkick, .harness_config = &red_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = false, .has_canfd = true, diff --git a/board/boards/red_chiplet.h b/board/boards/red_chiplet.h index 1301cd3e54f..eec3d95cdf5 100644 --- a/board/boards/red_chiplet.h +++ b/board/boards/red_chiplet.h @@ -1,6 +1,6 @@ -// ///////////////////// // -// Red Panda chiplet + Harness // -// ///////////////////// // +// ///////////////////////////////////// // +// Red Panda chiplet (STM32H7) + Harness // +// ///////////////////////////////////// // // Most hardware functionality is similar to red panda @@ -133,7 +133,7 @@ void red_chiplet_init(void) { // Set normal CAN mode red_chiplet_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } diff --git a/board/boards/tres.h b/board/boards/tres.h index d4faa9c0a33..4e8564b20d0 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -1,6 +1,6 @@ -// ///////////////// -// Tres + Harness // -// ///////////////// +// /////////////////////////// +// Tres (STM32H7) + Harness // +// /////////////////////////// bool tres_ir_enabled; bool tres_fan_enabled; @@ -72,7 +72,6 @@ void tres_init(void) { const board board_tres = { .harness_config = &red_chiplet_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = true, .has_canfd = true, diff --git a/board/boards/uno.h b/board/boards/uno.h index 15759b85809..5f8af593dc3 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -1,6 +1,6 @@ -// ///////////// // -// Uno + Harness // -// ///////////// // +// /////////////////////// // +// Uno (STM32F4) + Harness // +// /////////////////////// // void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ @@ -161,7 +161,7 @@ void uno_init(void) { // Set normal CAN mode uno_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -200,7 +200,6 @@ const harness_configuration uno_harness_config = { const board board_uno = { .harness_config = &uno_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = false, .has_canfd = false, diff --git a/board/boards/white.h b/board/boards/white.h index c8b8606bcf4..5048c0779d8 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -1,6 +1,6 @@ -// /////////// // -// White Panda // -// /////////// // +// ///////////////////// // +// White Panda (STM32F4) // +// ///////////////////// // void white_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ @@ -224,7 +224,6 @@ const harness_configuration white_harness_config = { const board board_white = { .set_bootkick = unused_set_bootkick, .harness_config = &white_harness_config, - .has_hw_gmlan = true, .has_obd = false, .has_spi = false, .has_canfd = false, diff --git a/board/drivers/bxcan.h b/board/drivers/bxcan.h index 080c9f4a9d4..ea2705d9d06 100644 --- a/board/drivers/bxcan.h +++ b/board/drivers/bxcan.h @@ -23,56 +23,6 @@ bool can_set_speed(uint8_t can_number) { return ret; } -// TODO: Cleanup with new abstraction -void can_set_gmlan(uint8_t bus) { - if(current_board->has_hw_gmlan){ - // first, disable GMLAN on prev bus - uint8_t prev_bus = bus_config[3].can_num_lookup; - if (bus != prev_bus) { - switch (prev_bus) { - case 1: - case 2: - print("Disable GMLAN on CAN"); - puth(prev_bus + 1U); - print("\n"); - current_board->set_can_mode(CAN_MODE_NORMAL); - bus_config[prev_bus].bus_lookup = prev_bus; - bus_config[prev_bus].can_num_lookup = prev_bus; - bus_config[3].can_num_lookup = -1; - bool ret = can_init(prev_bus); - UNUSED(ret); - break; - default: - // GMLAN was not set on either BUS 1 or 2 - break; - } - } - - // now enable GMLAN on the new bus - switch (bus) { - case 1: - case 2: - print("Enable GMLAN on CAN"); - puth(bus + 1U); - print("\n"); - current_board->set_can_mode((bus == 1U) ? CAN_MODE_GMLAN_CAN2 : CAN_MODE_GMLAN_CAN3); - bus_config[bus].bus_lookup = 3; - bus_config[bus].can_num_lookup = -1; - bus_config[3].can_num_lookup = bus; - bool ret = can_init(bus); - UNUSED(ret); - break; - case 0xFF: //-1 unsigned - break; - default: - print("GMLAN can only be set on CAN2 or CAN3\n"); - break; - } - } else { - print("GMLAN not available on black panda\n"); - } -} - void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) { CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number); uint32_t esr_reg = CANx->ESR; diff --git a/board/drivers/fdcan.h b/board/drivers/fdcan.h index 4343d5c97f6..bc4c2a532e3 100644 --- a/board/drivers/fdcan.h +++ b/board/drivers/fdcan.h @@ -35,11 +35,6 @@ bool can_set_speed(uint8_t can_number) { return ret; } -void can_set_gmlan(uint8_t bus) { - UNUSED(bus); - print("GMLAN not available on red panda\n"); -} - void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) { FDCAN_GlobalTypeDef *FDCANx = CANIF_FROM_CAN_NUM(can_number); uint32_t psr_reg = FDCANx->PSR; diff --git a/board/jungle/boards/board_declarations.h b/board/jungle/boards/board_declarations.h index 1288b5354df..925918921f8 100644 --- a/board/jungle/boards/board_declarations.h +++ b/board/jungle/boards/board_declarations.h @@ -35,7 +35,6 @@ struct board { // TODO: shouldn't need these bool has_spi; - bool has_hw_gmlan; }; // ******************* Definitions ******************** diff --git a/board/jungle/boards/board_v1.h b/board/jungle/boards/board_v1.h index 29c23d6df7a..9581686e2a3 100644 --- a/board/jungle/boards/board_v1.h +++ b/board/jungle/boards/board_v1.h @@ -1,3 +1,6 @@ +// ///////////////////////// // +// Jungle board v1 (STM32F4) // +// ///////////////////////// // void board_v1_set_led(uint8_t color, bool enabled) { switch (color) { diff --git a/board/jungle/boards/board_v2.h b/board/jungle/boards/board_v2.h index 7bce61ebb30..095114825b8 100644 --- a/board/jungle/boards/board_v2.h +++ b/board/jungle/boards/board_v2.h @@ -1,3 +1,6 @@ +// ///////////////////////// // +// Jungle board v2 (STM32H7) // +// ///////////////////////// // const gpio_t power_pins[] = { {.bank = GPIOA, .pin = 0}, diff --git a/board/main_comms.h b/board/main_comms.h index 4adfc8d744a..116f95d0ede 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -274,19 +274,6 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { // Disable OBD CAN current_board->set_can_mode(CAN_MODE_NORMAL); } - } else { - if (req->param1 == 1U) { - // GMLAN ON - if (req->param2 == 1U) { - can_set_gmlan(1); - } else if (req->param2 == 2U) { - can_set_gmlan(2); - } else { - print("Invalid bus num for GMLAN CAN set\n"); - } - } else { - can_set_gmlan(-1); - } } break; @@ -324,7 +311,8 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { } // read - while ((resp_len < MIN(req->length, USBPACKET_MAX_SIZE)) && + uint16_t req_length = MIN(req->length, USBPACKET_MAX_SIZE); + while ((resp_len < req_length) && get_char(ur, (char*)&resp[resp_len])) { ++resp_len; } diff --git a/board/power_saving.h b/board/power_saving.h index dcd64dc58d2..61541cae9ee 100644 --- a/board/power_saving.h +++ b/board/power_saving.h @@ -36,12 +36,6 @@ void set_power_save_state(int state) { current_board->enable_can_transceivers(enable); - if(current_board->has_hw_gmlan){ - // turn on GMLAN - set_gpio_output(GPIOB, 14, enable); - set_gpio_output(GPIOB, 15, enable); - } - // Switch off IR when in power saving if(!enable){ current_board->set_ir_power(0U); diff --git a/board/safety.h b/board/safety.h index e48a75502e8..50669e3bfb4 100644 --- a/board/safety.h +++ b/board/safety.h @@ -390,7 +390,8 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { // convert a trimmed integer to signed 32 bit int int to_signed(int d, int bits) { int d_signed = d; - if (d >= (1 << MAX((bits - 1), 0))) { + int max_value = (1 << MAX((bits - 1), 0)); + if (d >= max_value) { d_signed = d - (1 << MAX(bits, 0)); } return d_signed; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 71bd19d3003..1e11871286f 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -264,7 +264,9 @@ static int chrysler_fwd_hook(int bus_num, int addr) { static safety_config chrysler_init(uint16_t param) { safety_config ret; - if (GET_FLAG(param, CHRYSLER_PARAM_RAM_DT)) { + + bool enable_ram_dt = GET_FLAG(param, CHRYSLER_PARAM_RAM_DT); + if (enable_ram_dt) { chrysler_platform = CHRYSLER_RAM_DT; chrysler_addrs = &CHRYSLER_RAM_DT_ADDRS; ret = BUILD_SAFETY_CFG(chrysler_ram_dt_rx_checks, CHRYSLER_RAM_DT_TX_MSGS); diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index 5c4fd221661..954efca8d59 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -1,3 +1,5 @@ +const int GM_CAMERA_DIAG_ADDR = 0x24B; + static bool elm327_tx_hook(const CANPacket_t *to_send) { bool tx = true; int addr = GET_ADDR(to_send); @@ -11,9 +13,18 @@ static bool elm327_tx_hook(const CANPacket_t *to_send) { // Check valid 29 bit send addresses for ISO 15765-4 // Check valid 11 bit send addresses for ISO 15765-4 if ((addr != 0x18DB33F1) && ((addr & 0x1FFF00FF) != 0x18DA00F1) && - ((addr & 0x1FFFFF00) != 0x600) && ((addr & 0x1FFFFF00) != 0x700)) { + ((addr & 0x1FFFFF00) != 0x600) && ((addr & 0x1FFFFF00) != 0x700) && + (addr != GM_CAMERA_DIAG_ADDR)) { tx = false; } + + // GM camera uses non-standard diagnostic address, this has no control message address collisions + if ((addr == GM_CAMERA_DIAG_ADDR) && (len == 8)) { + // Only allow known frame types for ISO 15765-2 + if ((GET_BYTE(to_send, 0) & 0xF0U) > 0x30U) { + tx = false; + } + } return tx; } diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 6ab123be69b..0424b9d09c7 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -222,7 +222,8 @@ static void ford_rx_hook(const CANPacket_t *to_push) { // Disable controls if speeds from ABS and PCM ECUs are too far apart. // Signal: Veh_V_ActlEng float filtered_pcm_speed = ((GET_BYTE(to_push, 6) << 8) | GET_BYTE(to_push, 7)) * 0.01 / 3.6; - if (ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA) { + bool is_invalid_speed = ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA; + if (is_invalid_speed) { controls_allowed = false; } } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 413f36c8072..590954d2ec5 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -383,7 +383,9 @@ static safety_config honda_nidec_init(uint16_t param) { enable_gas_interceptor = GET_FLAG(param, HONDA_PARAM_GAS_INTERCEPTOR); safety_config ret; - if (GET_FLAG(param, HONDA_PARAM_NIDEC_ALT)) { + + bool enable_nidec_alt = GET_FLAG(param, HONDA_PARAM_NIDEC_ALT); + if (enable_nidec_alt) { enable_gas_interceptor ? SET_RX_CHECKS(honda_nidec_alt_interceptor_rx_checks, ret) : \ SET_RX_CHECKS(honda_nidec_alt_rx_checks, ret); } else { diff --git a/tests/misra/install.sh b/tests/misra/install.sh index 58ae77d443b..21396264501 100755 --- a/tests/misra/install.sh +++ b/tests/misra/install.sh @@ -10,7 +10,7 @@ fi cd $CPPCHECK_DIR VERS="2.13.0" -git fetch origin $VERS +git fetch --tags origin $VERS git checkout $VERS -make clean +#make clean make MATCHCOMPILTER=yes CXXFLAGS="-O2" -j8 diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt index 57db05a5fb6..2c91f868ab4 100644 --- a/tests/misra/suppressions.txt +++ b/tests/misra/suppressions.txt @@ -25,5 +25,4 @@ misra-c2012-8.7 misra-c2012-8.4 misra-c2012-10.6 misra-c2012-10.3 -misra-c2012-17.3 misra-c2012-21.15 diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index 28249a3d8ab..5504e3cd8c1 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -10,7 +10,7 @@ NC='\033[0m' : "${CPPCHECK_DIR:=$DIR/cppcheck/}" # install cppcheck if missing -if [ ! -d $CPPCHECK_DIR ]; then +if [ -z "${SKIP_BUILD}" ]; then $DIR/install.sh fi @@ -37,7 +37,7 @@ cppcheck() { -I $gcc_inc "$(arm-none-eabi-gcc -print-file-name=include)" \ --suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \ --suppress=*:*include/* --error-exitcode=2 --addon=misra \ - --cppcheck-build-dir=$build_dir \ + --check-level=exhaustive --cppcheck-build-dir=$build_dir \ "$@" } diff --git a/tests/safety/test.sh b/tests/safety/test.sh index 36f3c971563..d01c5009c2e 100755 --- a/tests/safety/test.sh +++ b/tests/safety/test.sh @@ -7,5 +7,5 @@ cd $DIR HW_TYPES=( 6 9 ) for hw_type in "${HW_TYPES[@]}"; do echo "Testing HW_TYPE: $hw_type" - HW_TYPE=$hw_type pytest -n auto --dist loadfile test_*.py -k 'not Base' + HW_TYPE=$hw_type pytest -n auto test_*.py -k 'not Base' done diff --git a/tests/safety/test_elm327.py b/tests/safety/test_elm327.py index 31cd74e9d6c..f133b2ead9c 100755 --- a/tests/safety/test_elm327.py +++ b/tests/safety/test_elm327.py @@ -7,9 +7,11 @@ from panda.tests.libpanda import libpanda_py from panda.tests.safety.test_defaults import TestDefaultRxHookBase +GM_CAMERA_DIAG_ADDR = 0x24B + class TestElm327(TestDefaultRxHookBase): - TX_MSGS = [[addr, bus] for addr in [*range(0x600, 0x800), + TX_MSGS = [[addr, bus] for addr in [GM_CAMERA_DIAG_ADDR, *range(0x600, 0x800), *range(0x18DA00F1, 0x18DB00F1, 0x100), # 29-bit UDS physical addressing *[0x18DB33F1], # 29-bit UDS functional address ] for bus in range(4)] @@ -31,6 +33,12 @@ def test_tx_hook(self): should_tx = msg_len == 8 self.assertEqual(should_tx, self._tx(common.make_msg(0, 0x700, msg_len))) + # TODO: perform this check for all addresses + # 4 to 15 are reserved ISO-TP frame types (https://en.wikipedia.org/wiki/ISO_15765-2) + for byte in range(0xff): + should_tx = (byte >> 4) <= 3 + self.assertEqual(should_tx, self._tx(common.make_msg(0, GM_CAMERA_DIAG_ADDR, dat=bytes([byte] * 8)))) + def test_tx_hook_on_wrong_safety_mode(self): # No point, since we allow many diagnostic addresses pass