|
|
|
@ -42,78 +42,84 @@ uint32_t gm_ts_last = 0; |
|
|
|
|
struct sample_t gm_torque_driver; // last few driver torques measured
|
|
|
|
|
|
|
|
|
|
static int gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { |
|
|
|
|
int bus = GET_BUS(to_push); |
|
|
|
|
int addr = GET_ADDR(to_push); |
|
|
|
|
|
|
|
|
|
if (addr == 388) { |
|
|
|
|
int torque_driver_new = ((GET_BYTE(to_push, 6) & 0x7) << 8) | GET_BYTE(to_push, 7); |
|
|
|
|
torque_driver_new = to_signed(torque_driver_new, 11); |
|
|
|
|
// update array of samples
|
|
|
|
|
update_sample(&gm_torque_driver, torque_driver_new); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// sample speed, really only care if car is moving or not
|
|
|
|
|
// rear left wheel speed
|
|
|
|
|
if (addr == 842) { |
|
|
|
|
gm_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1); |
|
|
|
|
} |
|
|
|
|
bool valid = addr_safety_check(to_push, gm_rx_checks, GM_RX_CHECK_LEN, |
|
|
|
|
NULL, NULL, NULL); |
|
|
|
|
|
|
|
|
|
// ACC steering wheel buttons
|
|
|
|
|
if (addr == 481) { |
|
|
|
|
int button = (GET_BYTE(to_push, 5) & 0x70) >> 4; |
|
|
|
|
switch (button) { |
|
|
|
|
case 2: // resume
|
|
|
|
|
case 3: // set
|
|
|
|
|
controls_allowed = 1; |
|
|
|
|
break; |
|
|
|
|
case 6: // cancel
|
|
|
|
|
controls_allowed = 0; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; // any other button is irrelevant
|
|
|
|
|
if (valid) { |
|
|
|
|
int bus = GET_BUS(to_push); |
|
|
|
|
int addr = GET_ADDR(to_push); |
|
|
|
|
|
|
|
|
|
if (addr == 388) { |
|
|
|
|
int torque_driver_new = ((GET_BYTE(to_push, 6) & 0x7) << 8) | GET_BYTE(to_push, 7); |
|
|
|
|
torque_driver_new = to_signed(torque_driver_new, 11); |
|
|
|
|
// update array of samples
|
|
|
|
|
update_sample(&gm_torque_driver, torque_driver_new); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// exit controls on rising edge of brake press or on brake press when
|
|
|
|
|
// speed > 0
|
|
|
|
|
if (addr == 241) { |
|
|
|
|
int brake = GET_BYTE(to_push, 1); |
|
|
|
|
// Brake pedal's potentiometer returns near-zero reading
|
|
|
|
|
// even when pedal is not pressed
|
|
|
|
|
if (brake < 10) { |
|
|
|
|
brake = 0; |
|
|
|
|
// sample speed, really only care if car is moving or not
|
|
|
|
|
// rear left wheel speed
|
|
|
|
|
if (addr == 842) { |
|
|
|
|
gm_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1); |
|
|
|
|
} |
|
|
|
|
if (brake && (!gm_brake_prev || gm_moving)) { |
|
|
|
|
controls_allowed = 0; |
|
|
|
|
|
|
|
|
|
// ACC steering wheel buttons
|
|
|
|
|
if (addr == 481) { |
|
|
|
|
int button = (GET_BYTE(to_push, 5) & 0x70) >> 4; |
|
|
|
|
switch (button) { |
|
|
|
|
case 2: // resume
|
|
|
|
|
case 3: // set
|
|
|
|
|
controls_allowed = 1; |
|
|
|
|
break; |
|
|
|
|
case 6: // cancel
|
|
|
|
|
controls_allowed = 0; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; // any other button is irrelevant
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
gm_brake_prev = brake; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// exit controls on rising edge of gas press
|
|
|
|
|
if (addr == 417) { |
|
|
|
|
int gas = GET_BYTE(to_push, 6); |
|
|
|
|
if (gas && !gm_gas_prev) { |
|
|
|
|
controls_allowed = 0; |
|
|
|
|
// exit controls on rising edge of brake press or on brake press when
|
|
|
|
|
// speed > 0
|
|
|
|
|
if (addr == 241) { |
|
|
|
|
int brake = GET_BYTE(to_push, 1); |
|
|
|
|
// Brake pedal's potentiometer returns near-zero reading
|
|
|
|
|
// even when pedal is not pressed
|
|
|
|
|
if (brake < 10) { |
|
|
|
|
brake = 0; |
|
|
|
|
} |
|
|
|
|
if (brake && (!gm_brake_prev || gm_moving)) { |
|
|
|
|
controls_allowed = 0; |
|
|
|
|
} |
|
|
|
|
gm_brake_prev = brake; |
|
|
|
|
} |
|
|
|
|
gm_gas_prev = gas; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// exit controls on regen paddle
|
|
|
|
|
if (addr == 189) { |
|
|
|
|
bool regen = GET_BYTE(to_push, 0) & 0x20; |
|
|
|
|
if (regen) { |
|
|
|
|
controls_allowed = 0; |
|
|
|
|
// exit controls on rising edge of gas press
|
|
|
|
|
if (addr == 417) { |
|
|
|
|
int gas = GET_BYTE(to_push, 6); |
|
|
|
|
if (gas && !gm_gas_prev) { |
|
|
|
|
controls_allowed = 0; |
|
|
|
|
} |
|
|
|
|
gm_gas_prev = gas; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if ASCM or LKA camera are online
|
|
|
|
|
// on powertrain bus.
|
|
|
|
|
// 384 = ASCMLKASteeringCmd
|
|
|
|
|
// 715 = ASCMGasRegenCmd
|
|
|
|
|
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && ((addr == 384) || (addr == 715))) { |
|
|
|
|
relay_malfunction = true; |
|
|
|
|
// exit controls on regen paddle
|
|
|
|
|
if (addr == 189) { |
|
|
|
|
bool regen = GET_BYTE(to_push, 0) & 0x20; |
|
|
|
|
if (regen) { |
|
|
|
|
controls_allowed = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if ASCM or LKA camera are online
|
|
|
|
|
// on powertrain bus.
|
|
|
|
|
// 384 = ASCMLKASteeringCmd
|
|
|
|
|
// 715 = ASCMGasRegenCmd
|
|
|
|
|
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && ((addr == 384) || (addr == 715))) { |
|
|
|
|
relay_malfunction = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 1; |
|
|
|
|
return valid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// all commands: gas/regen, friction brake and steering
|
|
|
|
|