Skip to content

Commit 7ffc916

Browse files
authored
move can ignition to opendbc (#2396)
* move can ignition to opendbc temp: point to opendbc PR * rm * pyproject * run ci * fix * move
1 parent b19b66a commit 7ffc916

2 files changed

Lines changed: 2 additions & 61 deletions

File tree

board/drivers/can_common.h

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "board/drivers/drivers.h"
2+
#include "opendbc/safety/ignition.h"
23

34
uint32_t safety_tx_blocked = 0;
45
uint32_t safety_rx_invalid = 0;
@@ -7,10 +8,6 @@ uint32_t rx_buffer_overflow = 0;
78

89
can_health_t can_health[PANDA_CAN_CNT] = {{0}, {0}, {0}};
910

10-
// Ignition detected from CAN meessages
11-
bool ignition_can = false;
12-
uint32_t ignition_can_cnt = 0U;
13-
1411
bool can_silent = true;
1512
bool can_loopback = false;
1613

@@ -155,61 +152,6 @@ void can_set_forwarding(uint8_t from, uint8_t to) {
155152
}
156153
#endif
157154

158-
void ignition_can_hook(CANPacket_t *msg) {
159-
if (msg->bus == 0U) {
160-
int len = GET_LEN(msg);
161-
162-
// GM exception
163-
if ((msg->addr == 0x1F1U) && (len == 8)) {
164-
// SystemPowerMode (2=Run, 3=Crank Request)
165-
ignition_can = (msg->data[0] & 0x2U) != 0U;
166-
ignition_can_cnt = 0U;
167-
}
168-
169-
// Rivian R1S/T GEN1 exception
170-
if ((msg->addr == 0x152U) && (len == 8)) {
171-
// 0x152 overlaps with Subaru pre-global which has this bit as the high beam
172-
int counter = msg->data[1] & 0xFU; // max is only 14
173-
174-
static int prev_counter_rivian = -1;
175-
if ((counter == ((prev_counter_rivian + 1) % 15)) && (prev_counter_rivian != -1)) {
176-
// VDM_OutputSignals->VDM_EpasPowerMode
177-
ignition_can = ((msg->data[7] >> 4U) & 0x3U) == 1U; // VDM_EpasPowerMode_Drive_On=1
178-
ignition_can_cnt = 0U;
179-
}
180-
prev_counter_rivian = counter;
181-
}
182-
183-
// Tesla Model 3/Y exception
184-
if ((msg->addr == 0x221U) && (len == 8)) {
185-
// 0x221 overlaps with Rivian which has random data on byte 0
186-
int counter = msg->data[6] >> 4;
187-
188-
static int prev_counter_tesla = -1;
189-
if ((counter == ((prev_counter_tesla + 1) % 16)) && (prev_counter_tesla != -1)) {
190-
// VCFRONT_LVPowerState->VCFRONT_vehiclePowerState
191-
int power_state = (msg->data[0] >> 5U) & 0x3U;
192-
ignition_can = power_state == 0x3; // VEHICLE_POWER_STATE_DRIVE=3
193-
ignition_can_cnt = 0U;
194-
}
195-
prev_counter_tesla = counter;
196-
}
197-
198-
// Mazda exception
199-
if ((msg->addr == 0x9EU) && (len == 8)) {
200-
ignition_can = (msg->data[0] >> 5) == 0x6U;
201-
ignition_can_cnt = 0U;
202-
}
203-
}
204-
205-
// TODO: this is too loose, Teslas have 0x222
206-
// body v2 exception
207-
// if (((msg->bus == 0U) || (msg->bus == 2U)) && (msg->addr == 0x222U)) {
208-
// ignition_can = true;
209-
// ignition_can_cnt = 0U;
210-
// }
211-
}
212-
213155
bool can_tx_check_min_slots_free(uint32_t min) {
214156
return
215157
(can_slots_empty(&can_tx1_q) >= min) &&

board/drivers/drivers.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern uint32_t rx_buffer_overflow;
4141

4242
extern can_health_t can_health[PANDA_CAN_CNT];
4343

44-
// Ignition detected from CAN meessages
44+
// Ignition detected from CAN messages
4545
extern bool ignition_can;
4646
extern uint32_t ignition_can_cnt;
4747

@@ -74,7 +74,6 @@ void can_set_orientation(bool flipped);
7474
#ifdef PANDA_JUNGLE
7575
void can_set_forwarding(uint8_t from, uint8_t to);
7676
#endif
77-
void ignition_can_hook(CANPacket_t *to_push);
7877
bool can_tx_check_min_slots_free(uint32_t min);
7978
uint8_t calculate_checksum(const uint8_t *dat, uint32_t len);
8079
void can_set_checksum(CANPacket_t *packet);

0 commit comments

Comments
 (0)