forked from commaai/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request commaai#34 from diamondman/feature/ELM327_support
Feature/elm327 support
- Loading branch information
Showing
12 changed files
with
2,797 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
static void elm327_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {} | ||
|
||
static int elm327_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { | ||
//All ELM traffic must appear on CAN0 | ||
if(((to_send->RDTR >> 4) & 0xf) != 0) return 0; | ||
//All ISO 15765-4 messages must be 8 bytes long | ||
if((to_send->RDTR & 0xf) != 8) return 0; | ||
|
||
if(to_send->RIR & 4){ | ||
uint32_t addr = to_send->RIR >> 3; | ||
//Check valid 29 bit send addresses for ISO 15765-4 | ||
if(!(addr == 0x18DB33F1 || (addr & 0x1FFF00FF) == 0x18DA00F1)) return 0; | ||
} else { | ||
uint32_t addr = to_send->RIR >> 21; | ||
//Check valid 11 bit send addresses for ISO 15765-4 | ||
if(!(addr == 0x7DF || (addr & 0x7F8) == 0x7E0)) return 0; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
static int elm327_tx_lin_hook(int lin_num, uint8_t *data, int len) { | ||
if(lin_num != 0) return false; //Only operate on LIN 0, aka serial 2 | ||
if(len < 5 || len > 11) return false; //Valid KWP size | ||
if(!((data[0] & 0xF8) == 0xC0 && (data[0] & 0x07) > 0 && | ||
data[1] == 0x33 && data[2] == 0xF1)) return false; //Bad msg | ||
return true; | ||
} | ||
|
||
const safety_hooks elm327_hooks = { | ||
.init = NULL, | ||
.rx = elm327_rx_hook, | ||
.tx = elm327_tx_hook, | ||
.tx_lin = elm327_tx_lin_hook, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
ELM327 support for panda | ||
====== | ||
The panda now has basic ELM327 support. | ||
|
||
### What is ELM327? | ||
|
||
ELM327 is a command protocol for interfacing with cars using an OBD-II | ||
port to read [list](standard vehicle diagnostic codes). ELM327 | ||
originally referred to a line of programmable microcontrollers that | ||
implemented the ELM327 command protocol, and are still being | ||
developed. | ||
|
||
ELM327 devices present a shell and commands are sent via a UART. The | ||
official ELM327 chips only support raw UART communication, but most | ||
devices built with the ELM327 devices (official or clones) expose the | ||
UART in a more modern way (Wifi, USB, etc). | ||
|
||
Mechanics use ELM to diagnose vehicles, and reset fault codes in the | ||
car's computer after fixing the issue (turning off the dreaded check | ||
engine light). Car owners can use ELM devices to perform the same | ||
diagnostics in their garage using either a raw terminal to send | ||
commands to the ELM device directly, or using a GUI (like one of | ||
several popular smart phone apps) to translate the OBD error codes | ||
into readable messages. These GUIs also often allow monitoring of the | ||
performance of the car's speed, engine rpm, etc. | ||
|
||
The panda natively supports sending all the important OBD diagnostic | ||
messages, but ELM327 support removes the need for the user to manually | ||
craft CAN or LIN packets using the native panda API, and grants | ||
compatibility with many existing tools. | ||
|
||
[Wikipedia](https://en.wikipedia.org/wiki/ELM327) can provide | ||
additional information. | ||
|
||
### OBD Protocols? | ||
|
||
While the commands that the OBD standard describe are in fact | ||
standard, there are several different protocols that those messages | ||
can be sent and received with. All cars after 1991 support one of | ||
these protocols. Which one depends on the car's year and country, as | ||
legal requirements change over the years. | ||
|
||
The panda supports the most popular/modern of these protocols, and all | ||
but two can be added as needed. Below is a chart of the OBD-II | ||
protocols supported by the panda. | ||
|
||
| Protocol | Support Status | | ||
| --- | --- | | ||
| SAE J1850 PWM (41.6 kbit/s) | Never/Obsolete | | ||
| SAE J1850 VPW (10.4 kbit/s) | Never/Obsolete | | ||
| ISO 9141-2 (5 baud init, 10.4 kbit/s) | Unsupported | | ||
| ISO 14230-4 KWP (5 baud init, 10.4 kbit/s) | Unsupported | | ||
| ISO 14230-4 KWP (fast init, 10.4 kbit/s) | Supported | | ||
| ISO 15765-4 CAN (11 bit ID, 500 kbit/s) | Supported | | ||
| ISO 15765-4 CAN (29 bit ID, 500 kbit/s) | Supported | | ||
| ISO 15765-4 CAN (11 bit ID, 250 kbit/s) | Supported | | ||
| ISO 15765-4 CAN (29 bit ID, 250 kbit/s) | Supported | | ||
| SAE J1939 (250kbps) | Unsupported | | ||
|
||
### The Implementation | ||
|
||
The panda ELM327 implementation is not a full implementation of all | ||
the features of the official ELM327 microcontroller. Like most ELM327 | ||
clones, the panda reports its ELM version as the unreleased version | ||
1.5, despite only implementing commands from protocol version 1.0. | ||
|
||
|
||
### Testing | ||
|
||
These tests require two pandas. One to be tested, and the second to | ||
simulate the vehicle. | ||
|
||
The panda used to simulate the vehicle must be plugged into a USB port | ||
of the testing computer. | ||
|
||
The computer running the tests must be connected to the panda being | ||
tested's wifi network. | ||
|
||
The following command will run the tests (nosetest should work fine | ||
instead of pytest if you still prefer using that). The CANSIMSERIAL | ||
environment variable will force the car simulator to use the correct | ||
panda as the simulator if multiple pandas are attached via usb to the | ||
host computer. | ||
|
||
``` | ||
CANSIMSERIAL=car_sim_panda_serial pytest tests/automated/elm_wifi.py | ||
``` | ||
|
||
A single test can be run by putting the test name after the file name | ||
and two colons, like so: | ||
|
||
``` | ||
CANSIMSERIAL=car_sim_panda_serial pytest tests/automated/elm_wifi.py::test_important_thing | ||
``` | ||
|
||
For more detail, provide the -s (show output) and the -vv (very | ||
verbose) flags. | ||
|
||
``` | ||
CANSIMSERIAL=car_sim_panda_serial pytest -s -vv tests/automated/elm_wifi.py | ||
``` |
Oops, something went wrong.