diff --git a/board/safety.h b/board/safety.h index 08e0da71d48024..282f53d198b767 100644 --- a/board/safety.h +++ b/board/safety.h @@ -78,11 +78,10 @@ const safety_hook_config safety_hook_registry[] = { {SAFETY_ELM327, &elm327_hooks}, }; -#define HOOK_CONFIG_COUNT (sizeof(safety_hook_registry)/sizeof(safety_hook_config)) - int safety_set_mode(uint16_t mode, int16_t param) { int set_status = -1; // not set - for (int i = 0; i < HOOK_CONFIG_COUNT; i++) { + int hook_config_count = sizeof(safety_hook_registry) / sizeof(safety_hook_config); + for (int i = 0; i < hook_config_count; i++) { if (safety_hook_registry[i].id == mode) { current_hooks = safety_hook_registry[i].hooks; set_status = 0; // set @@ -112,7 +111,8 @@ int to_signed(int d, int bits) { // given a new sample, update the smaple_t struct void update_sample(struct sample_t *sample, int sample_new) { - for (int i = sizeof(sample->values)/sizeof(sample->values[0]) - 1; i > 0; i--) { + int sample_size = sizeof(sample->values) / sizeof(sample->values[0]); + for (int i = sample_size - 1; i > 0; i--) { sample->values[i] = sample->values[i-1]; } sample->values[0] = sample_new; @@ -120,7 +120,7 @@ void update_sample(struct sample_t *sample, int sample_new) { // get the minimum and maximum measured samples sample->min = sample->values[0]; sample->max = sample->values[0]; - for (int i = 1; i < sizeof(sample->values) / sizeof(sample->values[0]); i++) { + for (int i = 1; i < sample_size; i++) { if (sample->values[i] < sample->min) { sample->min = sample->values[i]; } diff --git a/board/safety/safety_cadillac.h b/board/safety/safety_cadillac.h index 991dea533be0a3..87646ab0d2168e 100644 --- a/board/safety/safety_cadillac.h +++ b/board/safety/safety_cadillac.h @@ -4,7 +4,7 @@ const int CADILLAC_MAX_STEER = 150; // 1s // real time torque limit to prevent controls spamming // the real time limit is 1500/sec const int CADILLAC_MAX_RT_DELTA = 75; // max delta torque allowed for real time checks -const int32_t CADILLAC_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t CADILLAC_RT_INTERVAL = 250000; // 250ms between real time checks const int CADILLAC_MAX_RATE_UP = 2; const int CADILLAC_MAX_RATE_DOWN = 5; const int CADILLAC_DRIVER_TORQUE_ALLOWANCE = 50; @@ -20,14 +20,14 @@ int cadillac_supercruise_on = 0; struct sample_t cadillac_torque_driver; // last few driver torques measured int cadillac_get_torque_idx(uint32_t addr, int array_size) { - return min(max(addr - 0x151, 0), array_size); // 0x151 is id 0, 0x152 is id 1 and so on... + return min(max(addr - 0x151U, 0), array_size); // 0x151 is id 0, 0x152 is id 1 and so on... } static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int bus_number = (to_push->RDTR >> 4) & 0xFF; uint32_t addr = to_push->RIR >> 21; - if (addr == 356) { + if (addr == 356U) { int torque_driver_new = ((to_push->RDLR & 0x7) << 8) | ((to_push->RDLR >> 8) & 0xFF); torque_driver_new = to_signed(torque_driver_new, 11); // update array of samples @@ -35,12 +35,12 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // this message isn't all zeros when ignition is on - if ((addr == 0x160) && (bus_number == 0)) { + if ((addr == 0x160U) && (bus_number == 0)) { cadillac_ign = to_push->RDLR > 0; } // enter controls on rising edge of ACC, exit controls on ACC off - if ((addr == 0x370) && (bus_number == 0)) { + if ((addr == 0x370U) && (bus_number == 0)) { int cruise_engaged = to_push->RDLR & 0x800000; // bit 23 if (cruise_engaged && !cadillac_cruise_engaged_last) { controls_allowed = 1; @@ -51,7 +51,7 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // know supercruise mode and block openpilot msgs if on - if ((addr == 0x152) || (addr == 0x154)) { + if ((addr == 0x152U) || (addr == 0x154U)) { cadillac_supercruise_on = (to_push->RDHR>>4) & 0x1; } } @@ -61,7 +61,7 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { uint32_t addr = to_send->RIR >> 21; // steer cmd checks - if ((addr == 0x151) || (addr == 0x152) || (addr == 0x153) || (addr == 0x154)) { + if ((addr == 0x151U) || (addr == 0x152U) || (addr == 0x153U) || (addr == 0x154U)) { int desired_torque = ((to_send->RDLR & 0x3f) << 8) + ((to_send->RDLR & 0xff00) >> 8); int violation = 0; uint32_t ts = TIM2->CNT; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 797d2e446c185d..6e36f423cc883d 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -1,6 +1,6 @@ const int CHRYSLER_MAX_STEER = 261; const int CHRYSLER_MAX_RT_DELTA = 112; // max delta torque allowed for real time checks -const int32_t CHRYSLER_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t CHRYSLER_RT_INTERVAL = 250000; // 250ms between real time checks const int CHRYSLER_MAX_RATE_UP = 3; const int CHRYSLER_MAX_RATE_DOWN = 3; const int CHRYSLER_MAX_TORQUE_ERROR = 80; // max torque cmd in excess of torque motor @@ -26,7 +26,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // Measured eps torque - if (addr == 544) { + if (addr == 544U) { int rdhr = to_push->RDHR; int torque_meas_new = ((rdhr & 0x7) << 8) + ((rdhr & 0xFF00) >> 8) - 1024; @@ -35,7 +35,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // enter controls on rising edge of ACC, exit controls on ACC off - if (addr == 0x1f4) { + if (addr == 0x1F4U) { int cruise_engaged = ((to_push->RDLR & 0x380000) >> 19) == 7; if (cruise_engaged && !chrysler_cruise_engaged_last) { controls_allowed = 1; @@ -46,7 +46,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // check if stock camera ECU is still online - if ((bus == 0) && (addr == 0x292)) { + if ((bus == 0) && (addr == 0x292U)) { chrysler_camera_detected = 1; controls_allowed = 0; } @@ -72,7 +72,7 @@ static int chrysler_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // LKA STEER - if (addr == 0x292) { + if (addr == 0x292U) { int rdlr = to_send->RDLR; int desired_torque = ((rdlr & 0x7) << 8) + ((rdlr & 0xFF00) >> 8) - 1024; uint32_t ts = TIM2->CNT; diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index b6f5e4f0bc79d5..ea57766db0b7e7 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -15,13 +15,13 @@ static int elm327_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { if ((to_send->RIR & 4) != 0) { uint32_t addr = to_send->RIR >> 3; //Check valid 29 bit send addresses for ISO 15765-4 - if (!((addr == 0x18DB33F1) || ((addr & 0x1FFF00FF) == 0x18DA00F1))) { + if (!((addr == 0x18DB33F1U) || ((addr & 0x1FFF00FFU) == 0x18DA00F1U))) { tx = 0; } } else { uint32_t addr = to_send->RIR >> 21; //Check valid 11 bit send addresses for ISO 15765-4 - if (!((addr == 0x7DF) || ((addr & 0x7F8) == 0x7E0))) { + if (!((addr == 0x7DFU) || ((addr & 0x7F8U) == 0x7E0U))) { tx = 0; } } @@ -36,8 +36,8 @@ static int elm327_tx_lin_hook(int lin_num, uint8_t *data, int len) { if ((len < 5) || (len > 11)) { tx = 0; //Valid KWP size } - if (!(((data[0] & 0xF8) == 0xC0) && ((data[0] & 0x07) > 0) && - (data[1] == 0x33) && (data[2] == 0xF1))) { + if (!(((data[0] & 0xF8U) == 0xC0U) && ((data[0] & 0x07U) != 0U) && + (data[1] == 0x33U) && (data[2] == 0xF1U))) { tx = 0; //Bad msg } return tx; diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index bbcdd8568bf2d9..8b4b490e3b6ac6 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -10,7 +10,7 @@ const int GM_MAX_STEER = 300; const int GM_MAX_RT_DELTA = 128; // max delta torque allowed for real time checks -const int32_t GM_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t GM_RT_INTERVAL = 250000; // 250ms between real time checks const int GM_MAX_RATE_UP = 7; const int GM_MAX_RATE_DOWN = 17; const int GM_DRIVER_TORQUE_ALLOWANCE = 50; @@ -43,23 +43,23 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { addr = to_push->RIR >> 21; } - if (addr == 388) { + if (addr == 388U) { int torque_driver_new = (((to_push->RDHR >> 16) & 0x7) << 8) | ((to_push->RDHR >> 24) & 0xFF); torque_driver_new = to_signed(torque_driver_new, 11); // update array of samples update_sample(&gm_torque_driver, torque_driver_new); } - if ((addr == 0x1f1) && (bus_number == 0)) { + if ((addr == 0x1F1U) && (bus_number == 0)) { //Bit 5 should be ignition "on" //Backup plan is Bit 2 (accessory power) - uint32_t ign = (to_push->RDLR) & 0x20; - gm_ignition_started = ign > 0; + bool ign = ((to_push->RDLR) & 0x20) != 0; + gm_ignition_started = ign; } // sample speed, really only care if car is moving or not // rear left wheel speed - if (addr == 842) { + if (addr == 842U) { gm_speed = to_push->RDLR & 0xFFFF; } @@ -67,13 +67,13 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // on powertrain bus. // 384 = ASCMLKASteeringCmd // 715 = ASCMGasRegenCmd - if ((bus_number == 0) && ((addr == 384) || (addr == 715))) { + if ((bus_number == 0) && ((addr == 384U) || (addr == 715U))) { gm_ascm_detected = 1; controls_allowed = 0; } // ACC steering wheel buttons - if (addr == 481) { + if (addr == 481U) { int buttons = (to_push->RDHR >> 12) & 0x7; // res/set - enable, cancel button - disable if ((buttons == 2) || (buttons == 3)) { @@ -85,7 +85,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of brake press or on brake press when // speed > 0 - if (addr == 241) { + if (addr == 241U) { int brake = (to_push->RDLR & 0xFF00) >> 8; // Brake pedal's potentiometer returns near-zero reading // even when pedal is not pressed @@ -99,7 +99,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // exit controls on rising edge of gas press - if (addr == 417) { + if (addr == 417U) { int gas = to_push->RDHR & 0xFF0000; if (gas && !gm_gas_prev && long_controls_allowed) { controls_allowed = 0; @@ -108,7 +108,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // exit controls on regen paddle - if (addr == 189) { + if (addr == 189U) { bool regen = to_push->RDLR & 0x20; if (regen) { controls_allowed = 0; @@ -146,7 +146,7 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { } // BRAKE: safety check - if (addr == 789) { + if (addr == 789U) { int rdlr = to_send->RDLR; int brake = ((rdlr & 0xF) << 8) + ((rdlr & 0xFF00) >> 8); brake = (0x1000 - brake) & 0xFFF; @@ -162,7 +162,7 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { } // LKA STEER: safety check - if (addr == 384) { + if (addr == 384U) { int rdlr = to_send->RDLR; int desired_torque = ((rdlr & 0x7) << 8) + ((rdlr & 0xFF00) >> 8); uint32_t ts = TIM2->CNT; @@ -211,15 +211,15 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { } // PARK ASSIST STEER: unlimited torque, no thanks - if (addr == 823) { + if (addr == 823U) { tx = 0; } // GAS/REGEN: safety check - if (addr == 715) { - int rdlr = to_send->RDLR; - int gas_regen = ((rdlr & 0x7F0000) >> 11) + ((rdlr & 0xF8000000) >> 27); - int apply = rdlr & 1; + if (addr == 715U) { + uint32_t rdlr = to_send->RDLR; + int gas_regen = ((rdlr & 0x7F0000U) >> 11) + ((rdlr & 0xF8000000U) >> 27); + bool apply = (rdlr & 1U) != 0U; if (current_controls_allowed && long_controls_allowed) { if (gas_regen > GM_MAX_GAS) { tx = 0; diff --git a/board/safety/safety_gm_ascm.h b/board/safety/safety_gm_ascm.h index 5dbaccd8ec886f..e2b526befc0bbd 100644 --- a/board/safety/safety_gm_ascm.h +++ b/board/safety/safety_gm_ascm.h @@ -12,16 +12,16 @@ static int gm_ascm_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { // block 0x152 and 0x154, which are the lkas command from ASCM1 and ASCM2 // block 0x315 and 0x2cb, which are the brake and accel commands from ASCM1 //if ((addr == 0x152) || (addr == 0x154) || (addr == 0x315) || (addr == 0x2cb)) { - if ((addr == 0x152) || (addr == 0x154)) { + if ((addr == 0x152U) || (addr == 0x154U)) { int supercruise_on = (to_fwd->RDHR>>4) & 0x1; // bit 36 if (!supercruise_on) { bus_fwd = -1; } - } else if ((addr == 0x151) || (addr == 0x153) || (addr == 0x314)) { + } else if ((addr == 0x151U) || (addr == 0x153U) || (addr == 0x314U)) { // on the chassis bus, the OBDII port is on the module side, so we need to read // the lkas messages sent by openpilot (put on unused 0x151 ane 0x153 addrs) and send it to // the actuator as 0x152 and 0x154 - to_fwd->RIR = ((addr + 1) << 21) | (to_fwd->RIR & 0x1fffff); + to_fwd->RIR = ((addr + 1U) << 21) | (to_fwd->RIR & 0x1fffff); } } diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 6c5a93886dc3e6..bbd7e48e018178 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -1,6 +1,6 @@ const int HYUNDAI_MAX_STEER = 255; // like stock const int HYUNDAI_MAX_RT_DELTA = 112; // max delta torque allowed for real time checks -const int32_t HYUNDAI_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t HYUNDAI_RT_INTERVAL = 250000; // 250ms between real time checks const int HYUNDAI_MAX_RATE_UP = 3; const int HYUNDAI_MAX_RATE_DOWN = 7; const int HYUNDAI_DRIVER_TORQUE_ALLOWANCE = 50; @@ -28,25 +28,25 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { addr = to_push->RIR >> 21; } - if (addr == 897) { + if (addr == 897U) { int torque_driver_new = ((to_push->RDLR >> 11) & 0xfff) - 2048; // update array of samples update_sample(&hyundai_torque_driver, torque_driver_new); } // check if stock camera ECU is still online - if ((bus == 0) && (addr == 832)) { + if ((bus == 0) && (addr == 832U)) { hyundai_camera_detected = 1; controls_allowed = 0; } // Find out which bus the camera is on - if (addr == 832) { + if (addr == 832U) { hyundai_camera_bus = bus; } // enter controls on rising edge of ACC, exit controls on ACC off - if (addr == 1057) { + if (addr == 1057U) { // 2 bits: 13-14 int cruise_engaged = (to_push->RDLR >> 13) & 0x3; if (cruise_engaged && !hyundai_cruise_engaged_last) { @@ -58,7 +58,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // 832 is lkas cmd. If it is on camera bus, then giraffe switch 2 is high - if ((addr == 832) && (bus == hyundai_camera_bus) && (hyundai_camera_bus != 0)) { + if ((addr == 832U) && (bus == hyundai_camera_bus) && (hyundai_camera_bus != 0)) { hyundai_giraffe_switch_2 = 1; } } @@ -82,7 +82,7 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { } // LKA STEER: safety check - if (addr == 832) { + if (addr == 832U) { int desired_torque = ((to_send->RDLR >> 16) & 0x7ff) - 1024; uint32_t ts = TIM2->CNT; bool violation = 0; diff --git a/board/safety/safety_subaru.h b/board/safety/safety_subaru.h index 0f92631f83184c..eca95acc958e30 100644 --- a/board/safety/safety_subaru.h +++ b/board/safety/safety_subaru.h @@ -2,7 +2,7 @@ const int SUBARU_MAX_STEER = 2047; // 1s // real time torque limit to prevent controls spamming // the real time limit is 1500/sec const int SUBARU_MAX_RT_DELTA = 940; // max delta torque allowed for real time checks -const int32_t SUBARU_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t SUBARU_RT_INTERVAL = 250000; // 250ms between real time checks const int SUBARU_MAX_RATE_UP = 50; const int SUBARU_MAX_RATE_DOWN = 70; const int SUBARU_DRIVER_TORQUE_ALLOWANCE = 60; @@ -19,7 +19,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int bus_number = (to_push->RDTR >> 4) & 0xFF; uint32_t addr = to_push->RIR >> 21; - if ((addr == 0x119) && (bus_number == 0)){ + if ((addr == 0x119U) && (bus_number == 0)){ int torque_driver_new = ((to_push->RDLR >> 16) & 0x7FF); torque_driver_new = to_signed(torque_driver_new, 11); // update array of samples @@ -27,7 +27,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // enter controls on rising edge of ACC, exit controls on ACC off - if ((addr == 0x240) && (bus_number == 0)) { + if ((addr == 0x240U) && (bus_number == 0)) { int cruise_engaged = (to_push->RDHR >> 9) & 1; if (cruise_engaged && !subaru_cruise_engaged_last) { controls_allowed = 1; @@ -43,7 +43,7 @@ static int subaru_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { uint32_t addr = to_send->RIR >> 21; // steer cmd checks - if (addr == 0x122) { + if (addr == 0x122U) { int desired_torque = ((to_send->RDLR >> 16) & 0x1FFF); bool violation = 0; uint32_t ts = TIM2->CNT; diff --git a/board/safety/safety_tesla.h b/board/safety/safety_tesla.h index 750dab256efb5c..543baa15ebd1ed 100644 --- a/board/safety/safety_tesla.h +++ b/board/safety/safety_tesla.h @@ -25,7 +25,7 @@ const struct lookup_t TESLA_LOOKUP_MAX_ANGLE = { {2., 29., 38.}, {410., 92., 36.}}; -const int TESLA_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t TESLA_RT_INTERVAL = 250000; // 250ms between real time checks // state of angle limits float tesla_desired_angle_last = 0; // last desired steer angle @@ -63,7 +63,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { addr = to_push->RIR >> 21; } - if (addr == 0x45) { + if (addr == 0x45U) { // 6 bits starting at position 0 int lever_position = (to_push->RDLR & 0x3F); if (lever_position == 2) { // pull forward @@ -76,7 +76,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } // Detect drive rail on (ignition) (start recording) - if (addr == 0x348) { + if (addr == 0x348U) { // GTW_status int drive_rail_on = (to_push->RDLR & 0x0001); tesla_ignition_started = drive_rail_on == 1; @@ -84,7 +84,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on brake press // DI_torque2::DI_brakePedal 0x118 - if (addr == 0x118) { + if (addr == 0x118U) { // 1 bit at position 16 if ((((to_push->RDLR & 0x8000)) >> 15) == 1) { // disable break cancel by commenting line below @@ -99,18 +99,18 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on EPAS error // EPAS_sysStatus::EPAS_eacStatus 0x370 - if (addr == 0x370) { + if (addr == 0x370U) { // if EPAS_eacStatus is not 1 or 2, disable control eac_status = ((to_push->RDHR >> 21)) & 0x7; // For human steering override we must not disable controls when eac_status == 0 // Additional safety: we could only allow eac_status == 0 when we have human steering allowed - if ((controls_allowed == 1) && (eac_status != 0) && (eac_status != 1) && (eac_status != 2)) { + if (controls_allowed && (eac_status != 0) && (eac_status != 1) && (eac_status != 2)) { controls_allowed = 0; //puts("EPAS error! \n"); } } //get latest steering wheel angle - if (addr == 0x00E) { + if (addr == 0x00EU) { float angle_meas_now = (int)(((((to_push->RDLR & 0x3F) << 8) + ((to_push->RDLR >> 8) & 0xFF)) * 0.1) - 819.2); uint32_t ts = TIM2->CNT; uint32_t ts_elapsed = get_ts_elapsed(ts, tesla_ts_angle_last); @@ -119,8 +119,8 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // add 1 to not false trigger the violation and multiply by 25 since the check is done every 250 ms and steer angle is updated at 100Hz float rt_delta_angle_up = (interpolate(TESLA_LOOKUP_ANGLE_RATE_UP, tesla_speed) * 25.) + 1.; float rt_delta_angle_down = (interpolate(TESLA_LOOKUP_ANGLE_RATE_DOWN, tesla_speed) * 25.) + 1.; - float highest_rt_angle = tesla_rt_angle_last + ((tesla_rt_angle_last > 0) ? rt_delta_angle_up : rt_delta_angle_down); - float lowest_rt_angle = tesla_rt_angle_last - ((tesla_rt_angle_last > 0) ? rt_delta_angle_down : rt_delta_angle_up); + float highest_rt_angle = tesla_rt_angle_last + ((tesla_rt_angle_last > 0.) ? rt_delta_angle_up : rt_delta_angle_down); + float lowest_rt_angle = tesla_rt_angle_last - ((tesla_rt_angle_last > 0.) ? rt_delta_angle_down : rt_delta_angle_up); if ((ts_elapsed > TESLA_RT_INTERVAL) || (controls_allowed && !tesla_controls_allowed_last)) { tesla_rt_angle_last = angle_meas_now; @@ -158,7 +158,7 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // do not transmit CAN message if steering angle too high // DAS_steeringControl::DAS_steeringAngleRequest - if (addr == 0x488) { + if (addr == 0x488U) { angle_raw = ((to_send->RDLR & 0x7F) << 8) + ((to_send->RDLR & 0xFF00) >> 8); desired_angle = (angle_raw * 0.1) - 1638.35; bool violation = 0; @@ -171,8 +171,8 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // add 1 to not false trigger the violation float delta_angle_up = interpolate(TESLA_LOOKUP_ANGLE_RATE_UP, tesla_speed) + 1.; float delta_angle_down = interpolate(TESLA_LOOKUP_ANGLE_RATE_DOWN, tesla_speed) + 1.; - float highest_desired_angle = tesla_desired_angle_last + ((tesla_desired_angle_last > 0) ? delta_angle_up : delta_angle_down); - float lowest_desired_angle = tesla_desired_angle_last - ((tesla_desired_angle_last > 0) ? delta_angle_down : delta_angle_up); + float highest_desired_angle = tesla_desired_angle_last + ((tesla_desired_angle_last > 0.) ? delta_angle_up : delta_angle_down); + float lowest_desired_angle = tesla_desired_angle_last - ((tesla_desired_angle_last > 0.) ? delta_angle_down : delta_angle_up); float TESLA_MAX_ANGLE = interpolate(TESLA_LOOKUP_MAX_ANGLE, tesla_speed) + 1.; //check for max angles diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index 30214128b39366..10b303092a076b 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -10,7 +10,7 @@ const int TOYOTA_MAX_TORQUE_ERROR = 350; // max torque cmd in excess of torque // real time torque limit to prevent controls spamming // the real time limit is 1500/sec const int TOYOTA_MAX_RT_DELTA = 375; // max delta torque allowed for real time checks -const int TOYOTA_RT_INTERVAL = 250000; // 250ms between real time checks +const uint32_t TOYOTA_RT_INTERVAL = 250000; // 250ms between real time checks // longitudinal limits const int TOYOTA_MAX_ACCEL = 1500; // 1.5 m/s2