Skip to content

Commit

Permalink
sci init
Browse files Browse the repository at this point in the history
  • Loading branch information
eFiniLan committed Sep 15, 2023
1 parent ec3fd44 commit b11547c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const CanMsg TOYOTA_TX_MSGS[] = {{0x283, 0, 7}, {0x2E6, 0, 8}, {0x2E7, 0, 8}, {0
{0x128, 1, 6}, {0x141, 1, 4}, {0x160, 1, 8}, {0x161, 1, 7}, {0x470, 1, 4}, // DSU bus 1
{0x2E4, 0, 5}, {0x191, 0, 8}, {0x411, 0, 8}, {0x412, 0, 8}, {0x343, 0, 8}, {0x1D2, 0, 8}, // LKAS + ACC
{0x750, 0, 8}, // dp - white list 0x750 for Enhanced Diagnostic Request
{0x2fd, 0, 8}, // rick - for SCI
{0x200, 0, 6}}; // interceptor

AddrCheckStruct toyota_addr_checks[] = {
Expand All @@ -50,11 +51,13 @@ const uint32_t TOYOTA_EPS_FACTOR = (1U << TOYOTA_PARAM_OFFSET) - 1U;
const uint32_t TOYOTA_PARAM_ALT_BRAKE = 1U << TOYOTA_PARAM_OFFSET;
const uint32_t TOYOTA_PARAM_STOCK_LONGITUDINAL = 2U << TOYOTA_PARAM_OFFSET;
const uint32_t TOYOTA_PARAM_LTA = 4U << TOYOTA_PARAM_OFFSET;
const uint32_t TOYOTA_PARAM_SCI = 8U << TOYOTA_PARAM_OFFSET;

bool toyota_alt_brake = false;
bool toyota_stock_longitudinal = false;
bool toyota_lta = false;
int toyota_dbc_eps_torque_factor = 100; // conversion factor for STEER_TORQUE_EPS in %: see dbc file
bool toyota_sci = false;

static uint32_t toyota_compute_checksum(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);
Expand Down Expand Up @@ -209,6 +212,21 @@ static int toyota_tx_hook(CANPacket_t *to_send) {
}
}

// rick - sci, use lta rules
if (addr == 0x2fd) {
// check the STEER_REQUEST, STEER_REQUEST_2, SETME_X64 STEER_ANGLE_CMD signals
bool lta_request = GET_BIT(to_send, 0U) != 0U;
bool lta_request2 = GET_BIT(to_send, 25U) != 0U;
int setme_x64 = GET_BYTE(to_send, 5);
int lta_angle = (GET_BYTE(to_send, 1) << 8) | GET_BYTE(to_send, 2);
lta_angle = to_signed(lta_angle, 16);

// block LTA msgs with actuation requests
if (lta_request || lta_request2 || (lta_angle != 0) || (setme_x64 != 0)) {
tx = 0;
}
}

// STEER: safety check on bytes 2-3
if (addr == 0x2E4) {
int desired_torque = (GET_BYTE(to_send, 1) << 8) | GET_BYTE(to_send, 2);
Expand All @@ -232,6 +250,7 @@ static const addr_checks* toyota_init(uint16_t param) {
toyota_alt_brake = GET_FLAG(param, TOYOTA_PARAM_ALT_BRAKE);
toyota_stock_longitudinal = GET_FLAG(param, TOYOTA_PARAM_STOCK_LONGITUDINAL);
toyota_dbc_eps_torque_factor = param & TOYOTA_EPS_FACTOR;
toyota_sci = GET_FLAG(param, TOYOTA_SCI);

#ifdef ALLOW_DEBUG
toyota_lta = GET_FLAG(param, TOYOTA_PARAM_LTA);
Expand Down
1 change: 1 addition & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class Panda:
FLAG_TOYOTA_ALT_BRAKE = (1 << 8)
FLAG_TOYOTA_STOCK_LONGITUDINAL = (2 << 8)
FLAG_TOYOTA_LTA = (4 << 8)
FLAG_TOYOTA_SCI = (8 << 8)

FLAG_HONDA_ALT_BRAKE = 1
FLAG_HONDA_BOSCH_LONG = 2
Expand Down

0 comments on commit b11547c

Please sign in to comment.