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