Refactor diagnostic fields for decoding payload.
[apps/agl-service-can-low-level.git] / README.md
1 # OpenXC Message Format Specification
2
3 This specification is a part of the [OpenXC platform][OpenXC].
4
5 An OpenXC vehicle interface sends generic vehicle data over one or more output
6 interfaces (e.g. USB or Bluetooth) as JSON objects, separated by newlines.
7
8 There are two valid message types - single valued and evented.
9
10 There may not be a 1:1 relationship between input and output signals - i.e. raw
11 engine timing CAN signals may be summarized in an "engine performance" metric on
12 the abstract side of the interface.
13
14 ## Single Valued
15
16 The expected format of a single valued message is:
17
18     {"name": "steering_wheel_angle", "value": 45}
19
20 ## Evented
21
22 The expected format of an event message is:
23
24     {"name": "button_event", "value": "up", "event": "pressed"}
25
26 This format is good for something like a button event, where there are two
27 discrete pieces of information in the measurement.
28
29 ## Raw CAN Message format
30
31 An OpenXC vehicle interface may also output raw CAN messages. Each CAN message
32 is sent as a JSON object, separated by newlines. The format of each object is:
33
34     {"bus": 1, "id": 1234, "value": "0x12345678"}
35
36 **bus** - the numerical identifier of the CAN bus where this message originated,
37   most likely 1 or 2 (for a vehicle interface with 2 CAN controllers).
38
39 **id** - the CAN message ID
40
41 **data** - up to 8 bytes of data from the CAN message's payload, represented as
42   a hexidecimal number in a string. Many JSON parser cannot handle 64-bit
43   integers, which is why we are not using a numerical data type. Each byte in
44   the string *must* be represented with 2 characters, e.g. `0x1` is `0x01` - the
45   complete string must have an even number of characters.
46
47 ## Diagnostic Messages
48
49 ### Requests
50
51 A request to add or update a diagnostic request is sent to a vehicle interface
52 with this command format:
53
54     { "command": "diagnostic_request",
55       "request": {
56           "bus": 1,
57           "id": 1234,
58           "mode": 1,
59           "pid": 5,
60           "payload": "0x1234",
61           "multiple_responses": false,
62           "factor": 1.0,
63           "offset": 0,
64           "frequency": 1,
65           "name": "my_pid"
66         }
67       }
68     }
69
70 **bus** - the numerical identifier of the CAN bus where this request should be
71     sent, most likely 1 or 2 (for a vehicle interface with 2 CAN controllers).
72
73 **id** - the CAN arbitration ID for the request.
74
75 **mode** - the OBD-II mode of the request - 1 through 15 (1 through 9 are the
76     standardized modes).
77
78 **pid** - (optional) the PID for the request, if applicable.
79
80 **payload** - (optional) up to 7 bytes of data for the request's payload
81     represented as a hexidecimal number in a string. Many JSON parser cannot
82     handle 64-bit integers, which is why we are not using a numerical data type.
83     Each byte in the string *must* be represented with 2 characters, e.g. `0x1`
84     is `0x01` - the complete string must have an even number of characters.
85
86 **name** - (optional, defaults to nothing) A human readable, string name for
87   this request. If provided, the response will have a `name` field (much like a
88   normal translated message) with this value in place of `bus`, `id`, `mode` and
89   `pid`.
90
91 **multiple_responses** - (optional, false by default) if true, request will stay
92   active for a full 100ms, even after receiving a diagnostic response message.
93   This is useful for requests to the functional broadcast arbitration ID
94   (`0x7df`) when you need to get responses from multiple modules. It's possible
95   to set this to `true` for non-broadcast requests, but in practice you won't
96   see any additional responses after the first and it will just take up memory
97   in the VI for longer.
98
99 **frequency** - (optional, defaults to 0) The frequency in Hz to send this
100     request. To send a single request, set this to 0 or leave it out.
101
102 **decoded_type** - (optional, defaults to "obd2" if the request is a recognized
103 OBD-II mode 1 request, otherwise "none") If specified, the valid values are
104 `"none"` and `"obd2"`. If `obd2`, the payload will be decoded according to the
105 OBD-II specification and returned in the `value` field. Set this to `none` to
106 manually override the OBD-II decoding feature for a known PID.
107
108 The `bus+id+mode+pid` key is unique, so if you send a create request with that
109 key twice, it'll overwrite the existing one (i.e. it will change the frequency,
110 the only other parameter). To cancel a recurring request, send this command with
111 the frequency set to 0.
112
113 If you're just requesting a PID, you can use this minimal field set for the
114 `request` object:
115
116     {"bus": 1, "id": 1234, "mode": 1, "pid": 5}
117
118 ### Responses
119
120 The response to a successful request:
121
122     {"bus": 1,
123       "id": 1234,
124       "mode": 1,
125       "pid": 5,
126       "success": true,
127       "payload": "0x1234",
128       "value": 4660}
129
130 and to an unsuccessful request, with the `negative_response_code` and no `pid`
131 echo:
132
133     {"bus": 1,
134       "id": 1234,
135       "mode": 1,
136       "success": false,
137       "negative_response_code": 17}
138
139 **bus** - the numerical identifier of the CAN bus where this response was
140     received.
141
142 **id** - the CAN arbitration ID for this response.
143
144 **mode** - the OBD-II mode of the original diagnostic request.
145
146 **pid** - (optional) the PID for the request, if applicable.
147
148 **success** -  true if the response received was a positive response. If this
149   field is false, the remote node returned an error and the
150   `negative_response_code` field should be populated.
151
152 **negative_response_code** - (optional)  If requested node returned an error,
153     `success` will be `false` and this field will contain the negative response
154     code (NRC).
155
156 Finally, the `payload` and `value` fields are mutually exclusive:
157
158 **payload** - (optional) up to 7 bytes of data returned in the response,
159     represented as a hexadecimal number in a string. Many JSON parser cannot
160     handle 64-bit integers, which is why we are not using a numerical data type.
161
162 **value** - (optional) if the response had a payload, this may be the
163     payload interpreted as an integer.
164
165 The response to a simple PID request would look like this:
166
167     {"success": true, "bus": 1, "id": 1234, "mode": 1, "pid": 5, "payload": "0x2"}
168
169 ## Commands
170
171 ### Version Query
172
173 The `version` command triggers the VI to inject a firmware version identifier
174 response into the outgoing data stream.
175
176 **Request**
177
178     { "command": "version"}
179
180 **Response**
181
182     { "command_response": "version", "message": "v6.0-dev (default)"}
183
184 ### Device ID Query
185
186 The `device_id` command triggers the VI to inject a unique device ID (e.g. the
187 MAC address of an included Bluetooth module) into into the outgoing data stream.
188
189 **Request**
190
191     { "command": "device_id"}
192
193 **Response**
194
195     { "command_response": "device_id", "message": "0012345678"}
196
197 ## Trace File Format
198
199 An OpenXC vehicle trace file is a plaintext file that contains JSON objects,
200 separated by newlines.
201
202 The first line may be a metadata object, although this is optional:
203
204 ```
205 {"metadata": {
206     "version": "v3.0",
207     "vehicle_interface_id": "7ABF",
208     "vehicle": {
209         "make": "Ford",
210         "model": "Mustang",
211         "trim": "V6 Premium",
212         "year": 2013
213     },
214     "description": "highway drive to work",
215     "driver_name": "TJ Giuli",
216     "vehicle_id": "17N1039247929"
217 }
218 ```
219
220 The following lines are OpenXC messages with a `timestamp` field added, e.g.:
221
222     {"timestamp": 1385133351.285525, "name": "steering_wheel_angle", "value": 45}
223
224 The timestamp is in [UNIX time](http://en.wikipedia.org/wiki/Unix_time)
225 (i.e. seconds since the UNIX epoch, 00:00:00 UTC, 1/1/1970).
226
227 ## Official Signals
228
229 These signal names are a part of the OpenXC specification, although some
230 manufacturers may support custom message names.
231
232 * steering_wheel_angle
233     * numerical, -600 to +600 degrees
234     * 10Hz
235 * torque_at_transmission
236     * numerical, -500 to 1500 Nm
237     * 10Hz
238 * engine_speed
239     * numerical, 0 to 16382 RPM
240     * 10Hz
241 * vehicle_speed
242     * numerical, 0 to 655 km/h (this will be positive even if going in reverse
243       as it's not a velocity, although you can use the gear status to figure out
244       direction)
245     * 10Hz
246 * accelerator_pedal_position
247     * percentage
248     * 10Hz
249 * parking_brake_status
250     * boolean, (true == brake engaged)
251     * 1Hz, but sent immediately on change
252 * brake_pedal_status
253     * boolean (True == pedal pressed)
254     * 1Hz, but sent immediately on change
255 * transmission_gear_position
256     * states: first, second, third, fourth, fifth, sixth, seventh, eighth,
257       reverse, neutral
258     * 1Hz, but sent immediately on change
259 * gear_lever_position
260     * states: neutral, park, reverse, drive, sport, low, first, second, third,
261       fourth, fifth, sixth
262     * 1Hz, but sent immediately on change
263 * odometer
264     * Numerical, km
265         0 to 16777214.000 km, with about .2m resolution
266     * 10Hz
267 * ignition_status
268     * states: off, accessory, run, start
269     * 1Hz, but sent immediately on change
270 * fuel_level
271     * percentage
272     * 2Hz
273 * fuel_consumed_since_restart
274     * numerical, 0 - 4294967295.0 L (this goes to 0 every time the vehicle
275       restarts, like a trip meter)
276     * 10Hz
277 * door_status
278     * Value is State: driver, passenger, rear_left, rear_right.
279     * Event is boolean: true == ajar
280     * 1Hz, but sent immediately on change
281 * headlamp_status
282     * boolean, true is on
283     * 1Hz, but sent immediately on change
284 * high_beam_status
285     * boolean, true is on
286     * 1Hz, but sent immediately on change
287 * windshield_wiper_status
288     * boolean, true is on
289     * 1Hz, but sent immediately on change
290 * latitude
291     * numerical, -89.0 to 89.0 degrees with standard GPS accuracy
292     * 1Hz
293 * longitude
294     * numerical, -179.0 to 179.0 degrees with standard GPS accuracy
295     * 1Hz
296
297 License
298 =======
299
300 Copyright (c) 2012-2013 Ford Motor Company
301
302 Licensed under the BSD license.
303
304 [OpenXC]: http://openxcplatform.com