nopenpilot/panda/board/safety/safety_gm.h

229 lines
6.7 KiB
C
Raw Normal View History

// board enforces
// in-state
// accel set/resume
// out-state
// cancel button
// regen paddle
// accel rising edge
// brake rising edge
// brake > 0mph
const int GM_MAX_STEER = 300;
const int GM_MAX_RT_DELTA = 128; // max delta torque allowed for 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;
const int GM_DRIVER_TORQUE_FACTOR = 4;
const int GM_MAX_GAS = 3072;
const int GM_MAX_REGEN = 1404;
const int GM_MAX_BRAKE = 350;
Squashed 'panda/' changes from 869f12321..49ffbe99f 49ffbe99f disable non-universal checks in hyundai safety 3a85f4c25 use whole route when running safety replay from CLI 098f47a5b Fix leaf brake rx check (#547) b8267341a Add pre commit checks + CI (#545) 339976c3c document tx message addresses better (#543) a618e64d1 fix typing errors 9bece64e8 use mazda init 08db086d5 mazda cleanup 89658d0bd Mazda: safety tests add missing safety checks (#525) bdec1398e Fix length of 0x20b in NISSAN_TX_MSGS, wasn't cancelling ACC (#544) b48c74c2e Adding UNO to automated tests (#538) a5802cdd1 Hyundai: remove unused message from RX checks 9ebde2535 Reset state on safety mode init (#542) d4f3f15c3 Refactor addr check (#541) 5210e51b8 remove unused files 065706459 Hyundai checksum (#540) 07e668eca Fast CI (#539) 5307bf727 Fix multi message iso tp requests 0610ed1e2 Hyundai wheel speed counter is actually 4 bits spread over two signals 0d581aa5f dockerfile optimization eaefa2f6c fix docker file path 243a65f30 pull base image 0dd9470af only push to dockerhub from master 55b79b472 GitHub Actions (#535) b2c720bf4 Dos (#533) 01bf74024 remove 0x1BE checksum test 0bd06c9e0 remove 0x1BE check (breaks some vehicles) c31b899a5 honda bosch longitudinal safety 66250c41d Disable docker layer caching (#534) 6b19fa496 include nissan safety in release build db31886ad gate mazda safety behind debug flag e4558c073 Safety: message length check on RX and TX (#529) git-subtree-dir: panda git-subtree-split: 49ffbe99f65e64d23d27d9d3e37f68bc2368dccd
2020-05-31 14:22:43 -06:00
const CanMsg GM_TX_MSGS[] = {{384, 0, 4}, {1033, 0, 7}, {1034, 0, 7}, {715, 0, 8}, {880, 0, 6}, // pt bus
{161, 1, 7}, {774, 1, 8}, {776, 1, 7}, {784, 1, 2}, // obs bus
{789, 2, 5}, // ch bus
{0x104c006c, 3, 3}, {0x10400060, 3, 5}}; // gmlan
// TODO: do checksum and counter checks. Add correct timestep, 0.1s for now.
2021-09-07 19:58:54 -06:00
AddrCheckStruct gm_addr_checks[] = {
2021-07-14 18:34:36 -06:00
{.msg = {{388, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{842, 0, 5, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{481, 0, 7, .expected_timestep = 100000U}, { 0 }, { 0 }}},
2022-02-14 16:25:21 -07:00
{.msg = {{201, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{452, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
2021-09-07 19:58:54 -06:00
#define GM_RX_CHECK_LEN (sizeof(gm_addr_checks) / sizeof(gm_addr_checks[0]))
addr_checks gm_rx_checks = {gm_addr_checks, GM_RX_CHECK_LEN};
2022-03-25 19:06:15 -06:00
enum {
GM_BTN_UNPRESS = 1,
GM_BTN_RESUME = 2,
GM_BTN_SET = 3,
GM_BTN_CANCEL = 6,
};
2021-11-19 16:24:51 -07:00
static int gm_rx_hook(CANPacket_t *to_push) {
2021-09-07 19:58:54 -06:00
bool valid = addr_safety_check(to_push, &gm_rx_checks, NULL, NULL, NULL);
2021-12-13 21:51:54 -07:00
if (valid && (GET_BUS(to_push) == 0U)) {
int addr = GET_ADDR(to_push);
if (addr == 388) {
2021-12-13 21:51:54 -07:00
int torque_driver_new = ((GET_BYTE(to_push, 6) & 0x7U) << 8) | GET_BYTE(to_push, 7);
torque_driver_new = to_signed(torque_driver_new, 11);
// update array of samples
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
update_sample(&torque_driver, torque_driver_new);
}
// sample speed, really only care if car is moving or not
// rear left wheel speed
if (addr == 842) {
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
vehicle_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1);
}
// ACC steering wheel buttons
if (addr == 481) {
2021-12-13 21:51:54 -07:00
int button = (GET_BYTE(to_push, 5) & 0x70U) >> 4;
2022-03-25 19:06:15 -06:00
// exit controls on cancel press
if (button == GM_BTN_CANCEL) {
controls_allowed = 0;
}
// enter controls on falling edge of set or resume
bool set = (button == GM_BTN_UNPRESS) && (cruise_button_prev == GM_BTN_SET);
bool res = (button == GM_BTN_UNPRESS) && (cruise_button_prev == GM_BTN_RESUME);
if (set || res) {
controls_allowed = 1;
}
2022-03-25 19:06:15 -06:00
cruise_button_prev = button;
}
2022-02-14 16:25:21 -07:00
if (addr == 201) {
brake_pressed = GET_BIT(to_push, 40U) != 0U;
}
2022-02-14 16:25:21 -07:00
if (addr == 452) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;
}
// exit controls on regen paddle
if (addr == 189) {
2021-12-13 21:51:54 -07:00
bool regen = GET_BYTE(to_push, 0) & 0x20U;
if (regen) {
controls_allowed = 0;
}
}
// Check if ASCM or LKA camera are online
// on powertrain bus.
// 384 = ASCMLKASteeringCmd
// 715 = ASCMGasRegenCmd
2020-07-14 15:26:01 -06:00
generic_rx_checks(((addr == 384) || (addr == 715)));
}
return valid;
}
// all commands: gas/regen, friction brake and steering
// if controls_allowed and no pedals pressed
// allow all commands up to limit
// else
// block all commands that produce actuation
2021-11-19 16:24:51 -07:00
static int gm_tx_hook(CANPacket_t *to_send) {
int tx = 1;
int addr = GET_ADDR(to_send);
Squashed 'panda/' changes from 869f12321..49ffbe99f 49ffbe99f disable non-universal checks in hyundai safety 3a85f4c25 use whole route when running safety replay from CLI 098f47a5b Fix leaf brake rx check (#547) b8267341a Add pre commit checks + CI (#545) 339976c3c document tx message addresses better (#543) a618e64d1 fix typing errors 9bece64e8 use mazda init 08db086d5 mazda cleanup 89658d0bd Mazda: safety tests add missing safety checks (#525) bdec1398e Fix length of 0x20b in NISSAN_TX_MSGS, wasn't cancelling ACC (#544) b48c74c2e Adding UNO to automated tests (#538) a5802cdd1 Hyundai: remove unused message from RX checks 9ebde2535 Reset state on safety mode init (#542) d4f3f15c3 Refactor addr check (#541) 5210e51b8 remove unused files 065706459 Hyundai checksum (#540) 07e668eca Fast CI (#539) 5307bf727 Fix multi message iso tp requests 0610ed1e2 Hyundai wheel speed counter is actually 4 bits spread over two signals 0d581aa5f dockerfile optimization eaefa2f6c fix docker file path 243a65f30 pull base image 0dd9470af only push to dockerhub from master 55b79b472 GitHub Actions (#535) b2c720bf4 Dos (#533) 01bf74024 remove 0x1BE checksum test 0bd06c9e0 remove 0x1BE check (breaks some vehicles) c31b899a5 honda bosch longitudinal safety 66250c41d Disable docker layer caching (#534) 6b19fa496 include nissan safety in release build db31886ad gate mazda safety behind debug flag e4558c073 Safety: message length check on RX and TX (#529) git-subtree-dir: panda git-subtree-split: 49ffbe99f65e64d23d27d9d3e37f68bc2368dccd
2020-05-31 14:22:43 -06:00
if (!msg_allowed(to_send, GM_TX_MSGS, sizeof(GM_TX_MSGS)/sizeof(GM_TX_MSGS[0]))) {
tx = 0;
}
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
// and the the latching controls_allowed flag is True
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
int pedal_pressed = brake_pressed_prev && vehicle_moving;
2022-03-25 19:06:15 -06:00
bool alt_exp_allow_gas = alternative_experience & ALT_EXP_DISABLE_DISENGAGE_ON_GAS;
if (!alt_exp_allow_gas) {
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
pedal_pressed = pedal_pressed || gas_pressed_prev;
}
bool current_controls_allowed = controls_allowed && !pedal_pressed;
// BRAKE: safety check
if (addr == 789) {
int brake = ((GET_BYTE(to_send, 0) & 0xFU) << 8) + GET_BYTE(to_send, 1);
brake = (0x1000 - brake) & 0xFFF;
if (!current_controls_allowed) {
if (brake != 0) {
tx = 0;
}
}
if (brake > GM_MAX_BRAKE) {
tx = 0;
}
}
// LKA STEER: safety check
if (addr == 384) {
int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1);
2021-07-14 18:34:36 -06:00
uint32_t ts = microsecond_timer_get();
bool violation = 0;
desired_torque = to_signed(desired_torque, 11);
if (current_controls_allowed) {
// *** global torque limit check ***
violation |= max_limit_check(desired_torque, GM_MAX_STEER, -GM_MAX_STEER);
// *** torque rate limit check ***
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
violation |= driver_limit_check(desired_torque, desired_torque_last, &torque_driver,
GM_MAX_STEER, GM_MAX_RATE_UP, GM_MAX_RATE_DOWN,
GM_DRIVER_TORQUE_ALLOWANCE, GM_DRIVER_TORQUE_FACTOR);
// used next time
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
desired_torque_last = desired_torque;
// *** torque real time rate limit check ***
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
violation |= rt_rate_limit_check(desired_torque, rt_torque_last, GM_MAX_RT_DELTA);
// every RT_INTERVAL set the new limits
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
uint32_t ts_elapsed = get_ts_elapsed(ts, ts_last);
if (ts_elapsed > GM_RT_INTERVAL) {
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
rt_torque_last = desired_torque;
ts_last = ts;
}
}
// no torque if controls is not allowed
if (!current_controls_allowed && (desired_torque != 0)) {
violation = 1;
}
// reset to 0 if either controls is not allowed or there's a violation
if (violation || !current_controls_allowed) {
Squashed 'panda/' changes from 0696730c1..869f12321 869f12321 Hyundai: counter check (#530) a4390713e gitignore for route logs ac1b64e62 Fix CAN Ignition for Black Panda and Uno (#526) 273e3882f When initializing all the CAN busses, make sure the are also cleared (#527) c2bea78f6 Fix python library on Windows (#523) 0a123b181 that too ba6355d4c unused lines c9102c00e Chrysler: use can packer in safety tests (#522) 9874e7335 Abstract steering safety tests for Toyota and Chrysler (#520) 2299ecffc Block 0xe5 (Honda Bosch) at the panda/uno. Only allow static values. (#515) 351730611 Subaru: fix steer torque scaling (#501) 0bc864b3d Make torque-based steering state global (#518) d9355c414 Make cruise_engaged_prev a global + test case for it (#519) 211537641 Abstract sample speed test (#516) 11dc9054f remove unused function e5a586eea Abstract gas interceptor tests (#517) 1dbed65e3 Safety Test Refactor: Honda (#495) 0632710ac base class for different panda safety tests bd98fe603 safety tests: use shorter function name ba59ada0e No ESP in non-white (#514) c3336180b Fix the CAN init fix (#513) 884afa0ef Safety Test Refactor: Chrysler and Volkswagen PQ (#508) d77b72d16 Safety Test Refactor: Nissan (#510) 4c7755c47 Match Panda DFU entry fix in "make recover" process (#509) 0336f625d Pedal gas pressed safety limits (#507) 715b1a169 Hyundai-Kia-Genesis (HKG) (#503) 6f105e827 Safety Test Refactor: Subaru (#502) 57cc954f2 Safety Test Refactor: GM (#504) dd01c3b9c Safety Test Refactor: Hyundai (#505) 592c2c864 add support to can_unique.py for Cabana CSV format. (#506) ccf13b7af No more infinite while loops in CAN init (#499) 6c442b4c3 Safety Test Refactor: Volkswagen MQB (#493) f07a6ee7c panda recover should go through bootstub first (#498) 8cc3a3570 remove cadillac (#496) 62e4d3c36 Chrysler: fix missing button signal on TX (#490) abce8f32b Safety Test Refactor: Toyota + support code (#491) 500370aec Make sure relay faults make it to the health packet (#492) bc90b60f9 toyota: use universal gas pressed bit (#488) 74d10ccd3 Fixed possible race condition (#487) a05361ebc cleanup safety_replay dockerfile (#486) fe73dcc91 Openpilot-tools is deprecated (#484) da8e00f11 TX message guaranteed delivery (#421) d8f618492 Add ISO number for longitudinal limits flag comment 6a60b7811 touch ups 2ce65361d comments on unsafe flags d88013450 remove from there as well 055ea07ee remove that unsafe flag since it isn't implemented and it's unclear how to 4e98bbe8c Apply unsafe allow gas mode to all cars. (#480) 0c2c14949 Fixing libusb busy error (#174) 753c42cf5 Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea395 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d58 Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55d6 Support code for unsafe mode unit tests (#478) 5325b62bb current_safety_mode 7908b7224 update updating unsafe mode 98503e866 disable stock honda AEB in unsafe mode (#477) 01b2ccbed one more 9a30265a8 weak steering while not engaged 577f10b1a added options for unsafe mode 83cf7bf4c update comment 4556e7494 enable unsafe mode, toggle for use by forks that so choose de89fcdc4 Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 869f1232186f440eb388df82b85b88d346899199
2020-05-09 14:01:28 -06:00
desired_torque_last = 0;
rt_torque_last = 0;
ts_last = ts;
}
if (violation) {
tx = 0;
}
}
// GAS/REGEN: safety check
if (addr == 715) {
int gas_regen = ((GET_BYTE(to_send, 2) & 0x7FU) << 5) + ((GET_BYTE(to_send, 3) & 0xF8U) >> 3);
// Disabled message is !engaged with gas
// value that corresponds to max regen.
if (!current_controls_allowed) {
bool apply = GET_BYTE(to_send, 0) & 1U;
if (apply || (gas_regen != GM_MAX_REGEN)) {
tx = 0;
}
}
if (gas_regen > GM_MAX_GAS) {
tx = 0;
}
}
// 1 allows the message through
return tx;
}
2021-09-07 19:58:54 -06:00
static const addr_checks* gm_init(int16_t param) {
UNUSED(param);
controls_allowed = false;
relay_malfunction_reset();
return &gm_rx_checks;
}
const safety_hooks gm_hooks = {
2021-09-07 19:58:54 -06:00
.init = gm_init,
.rx = gm_rx_hook,
.tx = gm_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.fwd = default_fwd_hook,
};