Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safety: Convert message addresses from decimal to hexadecimal #1623

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,38 @@ typedef struct {

// CAN messages for Chrysler/Jeep platforms
const ChryslerAddrs CHRYSLER_ADDRS = {
.EPS_2 = 544, // EPS driver input torque
.ESP_1 = 320, // Brake pedal and vehicle speed
.ESP_8 = 284, // Brake pedal and vehicle speed
.ECM_5 = 559, // Throttle position sensor
.DAS_3 = 500, // ACC engagement states from DASM
.DAS_6 = 678, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 658, // LKAS controls from DASM
.CRUISE_BUTTONS = 571, // Cruise control buttons
.EPS_2 = 0x220, // EPS driver input torque
.ESP_1 = 0x140, // Brake pedal and vehicle speed
.ESP_8 = 0x11C, // Brake pedal and vehicle speed
.ECM_5 = 0x22F, // Throttle position sensor
.DAS_3 = 0x1F4, // ACC engagement states from DASM
.DAS_6 = 0x2A6, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 0x292, // LKAS controls from DASM
.CRUISE_BUTTONS = 0x23B, // Cruise control buttons
};

// CAN messages for the 5th gen RAM DT platform
const ChryslerAddrs CHRYSLER_RAM_DT_ADDRS = {
.EPS_2 = 49, // EPS driver input torque
.ESP_1 = 131, // Brake pedal and vehicle speed
.ESP_8 = 121, // Brake pedal and vehicle speed
.ECM_5 = 157, // Throttle position sensor
.DAS_3 = 153, // ACC engagement states from DASM
.DAS_6 = 250, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 166, // LKAS controls from DASM
.CRUISE_BUTTONS = 177, // Cruise control buttons
.EPS_2 = 0x31, // EPS driver input torque
.ESP_1 = 0x83, // Brake pedal and vehicle speed
.ESP_8 = 0x79, // Brake pedal and vehicle speed
.ECM_5 = 0x9D, // Throttle position sensor
.DAS_3 = 0x99, // ACC engagement states from DASM
.DAS_6 = 0xFA, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 0xA6, // LKAS controls from DASM
.CRUISE_BUTTONS = 0xB1, // Cruise control buttons
};

// CAN messages for the 5th gen RAM HD platform
const ChryslerAddrs CHRYSLER_RAM_HD_ADDRS = {
.EPS_2 = 544, // EPS driver input torque
.ESP_1 = 320, // Brake pedal and vehicle speed
.ESP_8 = 284, // Brake pedal and vehicle speed
.ECM_5 = 559, // Throttle position sensor
.DAS_3 = 500, // ACC engagement states from DASM
.DAS_6 = 629, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 630, // LKAS controls from DASM
.CRUISE_BUTTONS = 570, // Cruise control buttons
.EPS_2 = 0x220, // EPS driver input torque
.ESP_1 = 0x140, // Brake pedal and vehicle speed
.ESP_8 = 0x11C, // Brake pedal and vehicle speed
.ECM_5 = 0x22F, // Throttle position sensor
.DAS_3 = 0x1F4, // ACC engagement states from DASM
.DAS_6 = 0x275, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 0x276, // LKAS controls from DASM
.CRUISE_BUTTONS = 0x23A, // Cruise control buttons
};

const CanMsg CHRYSLER_TX_MSGS[] = {
Expand Down
62 changes: 31 additions & 31 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ const LongitudinalLimits *gm_long_limits;

const int GM_STANDSTILL_THRSLD = 10; // 0.311kph

const CanMsg GM_ASCM_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
const CanMsg GM_ASCM_TX_MSGS[] = {{0x180, 0, 4}, {0x409, 0, 7}, {0x40A, 0, 7}, {0x2CB, 0, 8}, {0x370, 0, 6}, // pt bus
{0xA1, 1, 7}, {0x306, 1, 8}, {0x308, 1, 7}, {0x310, 1, 2}, // obs bus
{0x315, 2, 5}, // ch bus
{0x104c006c, 3, 3}, {0x10400060, 3, 5}}; // gmlan

const CanMsg GM_CAM_TX_MSGS[] = {{384, 0, 4}, // pt bus
{481, 2, 7}, {388, 2, 8}}; // camera bus
const CanMsg GM_CAM_TX_MSGS[] = {{0x180, 0, 4}, // pt bus
{0x1E1, 2, 7}, {0x184, 2, 8}}; // camera bus

const CanMsg GM_CAM_LONG_TX_MSGS[] = {{384, 0, 4}, {789, 0, 5}, {715, 0, 8}, {880, 0, 6}, // pt bus
{388, 2, 8}}; // camera bus
const CanMsg GM_CAM_LONG_TX_MSGS[] = {{0x180, 0, 4}, {0x315, 0, 5}, {0x2CB, 0, 8}, {0x370, 0, 6}, // pt bus
{0x184, 2, 8}}; // camera bus

// TODO: do checksum and counter checks. Add correct timestep, 0.1s for now.
AddrCheckStruct gm_addr_checks[] = {
{.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 }}},
{.msg = {{190, 0, 6, .expected_timestep = 100000U}, // Volt, Silverado, Acadia Denali
{190, 0, 7, .expected_timestep = 100000U}, // Bolt EUV
{190, 0, 8, .expected_timestep = 100000U}}}, // Escalade
{.msg = {{452, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{201, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{0x184, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{0x34A, 0, 5, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{0x1E1, 0, 7, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{0xBE, 0, 6, .expected_timestep = 100000U}, // Volt, Silverado, Acadia Denali
{0xBE, 0, 7, .expected_timestep = 100000U}, // Bolt EUV
{0xBE, 0, 8, .expected_timestep = 100000U}}}, // Escalade
{.msg = {{0x1C4, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{0xC9, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#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};
Expand All @@ -73,22 +73,22 @@ static int gm_rx_hook(CANPacket_t *to_push) {
if (valid && (GET_BUS(to_push) == 0U)) {
int addr = GET_ADDR(to_push);

if (addr == 388) {
if (addr == 0x184) {
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
update_sample(&torque_driver, torque_driver_new);
}

// sample rear wheel speeds
if (addr == 842) {
if (addr == 0x34A) {
int left_rear_speed = (GET_BYTE(to_push, 0) << 8) | GET_BYTE(to_push, 1);
int right_rear_speed = (GET_BYTE(to_push, 2) << 8) | GET_BYTE(to_push, 3);
vehicle_moving = (left_rear_speed > GM_STANDSTILL_THRSLD) || (right_rear_speed > GM_STANDSTILL_THRSLD);
}

// ACC steering wheel buttons (GM_CAM is tied to the PCM)
if ((addr == 481) && !gm_pcm_cruise) {
if ((addr == 0x1E1) && !gm_pcm_cruise) {
int button = (GET_BYTE(to_push, 5) & 0x70U) >> 4;

// enter controls on falling edge of set or rising edge of resume (avoids fault)
Expand All @@ -108,15 +108,15 @@ static int gm_rx_hook(CANPacket_t *to_push) {

// Reference for brake pressed signals:
// https://github.com/commaai/openpilot/blob/master/selfdrive/car/gm/carstate.py
if ((addr == 190) && (gm_hw == GM_ASCM)) {
if ((addr == 0xBE) && (gm_hw == GM_ASCM)) {
brake_pressed = GET_BYTE(to_push, 1) >= 8U;
}

if ((addr == 201) && (gm_hw == GM_CAM)) {
if ((addr == 0xC9) && (gm_hw == GM_CAM)) {
brake_pressed = GET_BIT(to_push, 40U) != 0U;
}

if (addr == 452) {
if (addr == 0x1C4) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;

// enter controls on rising edge of ACC, exit controls when ACC off
Expand All @@ -126,14 +126,14 @@ static int gm_rx_hook(CANPacket_t *to_push) {
}
}

if (addr == 189) {
if (addr == 0xBD) {
regen_braking = (GET_BYTE(to_push, 0) >> 4) != 0U;
}

bool stock_ecu_detected = (addr == 384); // ASCMLKASteeringCmd
bool stock_ecu_detected = (addr == 0x180); // ASCMLKASteeringCmd

// Check ASCMGasRegenCmd only if we're blocking it
if (!gm_pcm_cruise && (addr == 715)) {
if (!gm_pcm_cruise && (addr == 0x2CB)) {
stock_ecu_detected = true;
}
generic_rx_checks(stock_ecu_detected);
Expand Down Expand Up @@ -163,7 +163,7 @@ static int gm_tx_hook(CANPacket_t *to_send) {
}

// BRAKE: safety check
if (addr == 789) {
if (addr == 0x315) {
int brake = ((GET_BYTE(to_send, 0) & 0xFU) << 8) + GET_BYTE(to_send, 1);
brake = (0x1000 - brake) & 0xFFF;
if (longitudinal_brake_checks(brake, *gm_long_limits)) {
Expand All @@ -172,7 +172,7 @@ static int gm_tx_hook(CANPacket_t *to_send) {
}

// LKA STEER: safety check
if (addr == 384) {
if (addr == 0x180) {
int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1);
desired_torque = to_signed(desired_torque, 11);

Expand All @@ -182,7 +182,7 @@ static int gm_tx_hook(CANPacket_t *to_send) {
}

// GAS/REGEN: safety check
if (addr == 715) {
if (addr == 0x2CB) {
bool apply = GET_BIT(to_send, 0U) != 0U;
int gas_regen = ((GET_BYTE(to_send, 2) & 0x7FU) << 5) + ((GET_BYTE(to_send, 3) & 0xF8U) >> 3);

Expand All @@ -197,7 +197,7 @@ static int gm_tx_hook(CANPacket_t *to_send) {
}

// BUTTONS: used for resume spamming and cruise cancellation with stock longitudinal
if ((addr == 481) && gm_pcm_cruise) {
if ((addr == 0x1E1) && gm_pcm_cruise) {
int button = (GET_BYTE(to_send, 5) >> 4) & 0x7U;

bool allowed_cancel = (button == 6) && cruise_engaged_prev;
Expand All @@ -217,16 +217,16 @@ static int gm_fwd_hook(int bus_num, int addr) {
if (gm_hw == GM_CAM) {
if (bus_num == 0) {
// block PSCMStatus; forwarded through openpilot to hide an alert from the camera
bool is_pscm_msg = (addr == 388);
bool is_pscm_msg = (addr == 0x184);
if (!is_pscm_msg) {
bus_fwd = 2;
}
}

if (bus_num == 2) {
// block lkas message and acc messages if gm_cam_long, forward all others
bool is_lkas_msg = (addr == 384);
bool is_acc_msg = (addr == 789) || (addr == 715) || (addr == 880);
bool is_lkas_msg = (addr == 0x180);
bool is_acc_msg = (addr == 0x315) || (addr == 0x2CB) || (addr == 0x370);
int block_msg = is_lkas_msg || (is_acc_msg && gm_cam_long);
if (!block_msg) {
bus_fwd = 0;
Expand Down
Loading
Loading