Cadillac ignition: simplified logic
const int STEER_MAX = 150; // 1s
const int CADILLAC_IGNITION_TIMEOUT = 1000000; // 1s
-int cadillac_can_seen = 0;
+int cadillac_ign = 0;
int cadillac_cruise_engaged_last = 0;
uint32_t cadillac_ts_last = 0;
@@ -9,10 +9,10 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
int bus_number = (to_push->RDTR >> 4) & 0xFF;
uint32_t addr = to_push->RIR >> 21;
- // this message isn't all zeros when car is on
+ // this message isn't all zeros when ignition is on
if ((addr == 0x160) && (bus_number == 0) && to_push->RDLR) {
- cadillac_can_seen = 1;
- cadillac_ts_last = TIM2->CNT; // reset timer when gear msg is received
+ cadillac_ign = 1;
+ cadillac_ts_last = TIM2->CNT; // reset timer when ign is received
}
// enter controls on rising edge of ACC, exit controls on ACC off
@@ -44,17 +44,16 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
static void cadillac_init(int16_t param) {
- cadillac_can_seen = 0;
+ cadillac_ign = 0;
}
static int cadillac_ign_hook() {
uint32_t ts = TIM2->CNT;
uint32_t ts_elapsed = get_ts_elapsed(ts, cadillac_ts_last);
- if ((ts_elapsed > CADILLAC_IGNITION_TIMEOUT) || (!cadillac_can_seen)) {
- cadillac_can_seen = 0;
- return 0;
+ if (ts_elapsed > CADILLAC_IGNITION_TIMEOUT) {
+ cadillac_ign = 0;
}
- return 1;
+ return cadillac_ign;
}
// Placeholder file, actual safety is TODO.
