Repository navigation
CAN
The V-Link application can display information from your car like boost pressure, intake temp, etc by requesting or intercepting data from the CAN bus. This page shows how to configure V-Link to request and display the CAN information in the app.
There are two ways to get the V-Link app to display CAN information. The first and easiest method is using diagnostic CAN messages. We can send a diagnostic CAN message, and the car will reply with the requested information. To read more about diagnostic CAN messages, go to this repository.
The second method is by using internal CAN messages. These are CAN messages that the car uses internally to make the car function. For example, to display the engine RPM in the gauge cluster, the car's ECM (Engine Control Module) sends out the current RPM value, and the gauge cluster receives this value and will display the RPM value using the RPM needle accordingly. V-link can listen in on the CAN-bus and intercept the CAN-message that contains the RPM value. We simply look at the RPM value, and display it in V-Link. This method is arguably faster than by requesting the information using a diagnostic message, but it's more difficult to retrieve the internal CAN IDs and match them to their intended function.
Cars like P1 Volvo's generally have 2 CAN networks, a High Speed (HS) and a Low Speed (LS) network. The High Speed bus is connected to the Engine Control Unit (ECU), steering module, brake module and other engine-related modules. The Low Speed bus is connected to the radio, door modules, instrument cluster, and other associated (less important) accessories. In P1 Volvo's, CAN HS runs at 500kbps and CAN LS runs at 125kbps.
CAN uses differential signals, using a 2-pair twisted cable and termination resistors at each end. The two wires are called CAN high (CANH) and CAN low (CANL). Pay close attention to this naming convention, as it's easy to get confused between CAN HighSpeed and CAN High (wire).
The CAN buses show up in the Raspberry Pi as CAN0 and CAN1.
In short; there are two CAN networks: CAN High Speed and Can Low Speed, both containing two wires (CAN High and CAN Low).
You can configure the CAN-bus integration in V-Link using the file /v-link/backend/can.json. This JSON file is made up out of 3 parts: interfaces, sensors and controls, they are shown separately below to explain the functions, but in the end these 3 parts are all visible in the can.json file.
Here you define the interfaces that are connected to the Raspberry Pi.
The configuration file follows a structured JSON format. Below is an example:
"interfaces": [
{
"enabled": true,
"bustype": "socketcan",
"channel": "can0",
"bitrate": 500000
},
{
"enabled": false,
"bustype": "socketcan",
"channel": "can1",
"bitrate": 125000
}
],enabled
- Enable/disable the CAN bus interface. If you disable an interface, any associated sensors are not requested/intercepted.
bustype
- Type of the CAN bus.
channel
- The name of the CAN channel, can0, can1, etc.
bitrate
- The speed of the CAN bus.
Here you can define the engine parameters you want the app to retrieve/intercept from the CAN bus. As mentioned in the introduction, there are two ways to get the value for a given engine parameter. You can either set the sensor to "type": "diagnostic" or to "type": "internal". If you set it to diagnostic. V-Link will send a request to the associated CAN-bus and update the value in V-Link using the response. For internal messages, V-Link only listens on the CAN bus and updates app-values accordingly.
You can add as many sensors as you like by filling in the sensor information using the message format shown at the top of this page.
The configuration file follows a structured JSON format. Below is an example:
"sensors": {
"rpm": {
"interface": "can0",
"enabled": false,
"type": "diagnostic",
"parameter": [
"0x10",
"0x1D"
],
"app_id": "rpm",
"req_id": "0x000FFFFE",
"rep_id": "0x00400021",
"action": "0xA6",
"target": "0x7A",
"is_16bit": false,
"refresh_rate": 0.02,
"scale": "(value * 40)",
"label": "RPM",
"unit": "rpm",
"min_value": 0,
"max_value": 8000,
"limit_start":7000
},
}If you want to control V-Link using the steering wheel buttons, you can configure the steering wheel controls integration here.
You will need to find the CAN reply ID of the module responsible for the steering wheel controls (usually the SWM) and sniff the CAN-messages to find which buttons correspond to what CAN ID.
The configuration file follows a structured JSON format. Below is an example:
"controls": {
"enabled": true,
"interface": "can0",
"rep_id": "0x0131726C",
"zero_message": ["0x00", "0x00", "0x3F"],
"control_byte_count": 2,
"button": {
"BTN_BACK": [
["0x10", "0x3F"],
["0x80", "0x3F"],
],
"BTN_ENTER": ["0x20", "0x3F"],
},
"joystick": {
"BTN_UP": ["0x08", "0x3F"],
},
"click_timeout": 300,
"long_press_duration": 1500
}rep_id
- The Reply ID of the CAN module.
zero_message
- The (partial) message that's used to indicate no buttons are currently being pressed.
control_byte_count
- The amount of significant bytes that need to be matched to associate a CAN bus message with a given message. This needs to be the same as the amount of bytes in the button and joystick.
- Example
BTN_ENTER: Internal CAN message `0131726C#808C37D26000203F, bold is matched.
button
- Key-value pairs of button names and associated CAN IDs. You can either enter a single CAN message (see
BTN_UP) or multiple CAN messages (BTN_BACK) if multiple CAN IDs match to the same button.
joystick
- Same as buttons
click_timeout
- The amount of time (in milliseconds) before a click is registered
long_press_duration
- The amount of time (in milliseconds) before a second action is performed