openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
1.2 KiB

static int elm327_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
int tx = 1;
int bus = GET_BUS(to_send);
int addr = GET_ADDR(to_send);
int len = GET_LEN(to_send);
//All ELM traffic must appear on CAN0
if (bus != 0) {
tx = 0;
}
//All ISO 15765-4 messages must be 8 bytes long
if (len != 8) {
tx = 0;
}
//Check valid 29 bit send addresses for ISO 15765-4
//Check valid 11 bit send addresses for ISO 15765-4
if ((addr != 0x18DB33F1) && ((addr & 0x1FFF00FF) != 0x18DA00F1) &&
((addr != 0x7DF) && ((addr & 0x7F8) != 0x7E0))) {
tx = 0;
}
return tx;
}
static int elm327_tx_lin_hook(int lin_num, uint8_t *data, int len) {
int tx = 1;
if (lin_num != 0) {
tx = 0; //Only operate on LIN 0, aka serial 2
}
if ((len < 5) || (len > 11)) {
tx = 0; //Valid KWP size
}
if (!(((data[0] & 0xF8U) == 0xC0U) && ((data[0] & 0x07U) != 0U) &&
(data[1] == 0x33U) && (data[2] == 0xF1U))) {
tx = 0; //Bad msg
}
return tx;
}
const safety_hooks elm327_hooks = {
.init = nooutput_init,
.rx = default_rx_hook,
.tx = elm327_tx_hook,
.tx_lin = elm327_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = default_fwd_hook,
};