1 # OpenXC Message Format Specification
5 This specification is a part of the [OpenXC platform][OpenXC].
7 An OpenXC vehicle interface sends generic vehicle data over one or more output
8 interfaces (e.g. USB or Bluetooth) as JSON or Protocol Buffers (protobuf).
10 ## Binary (Protocol Buffers)
12 The binary format is encoded using [Google Protocol
13 Buffers](https://code.google.com/p/protobuf/). The format is specified in the
14 file `openxc.proto`. Those are published using the standard length-delimited
15 method (any protobuf library should support this).
17 The binary format is best if you need to maximize the amount of data that can be
18 sent from the VI, trading off flexibility for efficiency.
22 This document describes the JSON format and includes a high level description of
23 each type and field. Each JSON message published by a VI is delimited with a
26 The JSON format is best for most developers, as it is fairly efficient and very
31 Any of the following JSON objects may optionally include an `extras`
32 field. The value may be any valid JSON object or array. The client libraries
33 will do their best to parse this information into a generic format and pass it
34 to your application. For example:
36 {"name": "steering_wheel_angle",
45 There may not be a 1:1 relationship between input and output signals - i.e. raw
46 engine timing CAN signals may be summarized in an "engine performance" metric on
47 the abstract side of the interface.
49 The expected format of a single valued message is:
51 {"name": "steering_wheel_angle", "value": 45}
55 The expected format of an event message is:
57 {"name": "button_event", "value": "up", "event": "pressed"}
59 This format is good for something like a button event, where there are two
60 discrete pieces of information in the measurement.
62 ### Raw CAN Message format
64 The format for a raw CAN message:
66 {"bus": 1, "id": 1234, "data": "0x12345678"}
68 **bus** - the numerical identifier of the CAN bus where this message originated,
69 most likely 1 or 2 (for a vehicle interface with 2 CAN controllers).
71 **id** - the CAN message ID
73 **data** - up to 8 bytes of data from the CAN message's payload, represented as
74 a hexidecimal number in a string. Many JSON parser cannot handle 64-bit
75 integers, which is why we are not using a numerical data type. Each byte in
76 the string *must* be represented with 2 characters, e.g. `0x1` is `0x01` - the
77 complete string must have an even number of characters. The `0x` prefix is
80 ### Diagnostic Messages
84 A diagnostic request is added or cancelled with a JSON object like this example:
86 { "command": "diagnostic_request",
94 "multiple_responses": false,
101 * The `command` must be `diagnostic_request.`
102 * The `action` must be included, and must be one of:
103 * `add` - create a new one-off or recurring diagnostic request.
104 * `cancel` - cancel an existing request.
105 * The details of the request must be included in the `request` field, using
106 the sub-fields defined below.
108 A diagnostic request's `bus`, `id`, `mode` and `pid` (or lack of a `pid`)
109 combine to create a unique key to identify a request. These four fields will be
110 referred to as the key of the diagnostic request. For example, to create a
111 simple one-time diagnostic request:
113 { "command": "diagnostic_request",
124 Requests are completed after any responses are received (unless
125 `multiple_responses` is set), or the request has timed out after a certain
126 number of seconds. After a request is completed, you can re-`create` the same
127 key to make another request.
129 Requests with a `frequency` are added as *recurring* requests, e.g. to add the
130 previous example as a recurring request at 1Hz:
132 { "command": "diagnostic_request",
144 To cancel a recurring request, send a `cancel` action with the same key, e.g.:
146 { "command": "diagnostic_request",
157 Simultaneous recurring requests for the same key at different rates (e.g. 1Hz
158 *and* 2Hz) is not supported. However, non-recurring ("one-off") requests may
159 exist in parallel with a recurring request for the same key.
161 **bus** - the numerical identifier of the CAN bus where this request should be
162 sent, most likely 1 or 2 (for a vehicle interface with 2 CAN controllers).
164 **id** - the CAN arbitration ID for the request.
166 **mode** - the OBD-II mode of the request - 0x1 through 0xff (1 through 9 are the
167 standardized modes and 0x22 is a common proprietary mode).
169 **pid** - (optional) the PID for the request, if applicable.
171 **payload** - (optional) up to 7 bytes of data for the request's payload
172 represented as a hexadecimal number in a string. Many JSON parser cannot
173 handle 64-bit integers, which is why we are not using a numerical data type.
174 Each byte in the string *must* be represented with 2 characters, e.g. `0x1`
175 is `0x01` - the complete string must have an even number of characters. The
176 `0x` prefix is optional.
178 **name** - (optional, defaults to nothing) A human readable, string name for
179 this request. If provided, the response will have a `name` field (much like a
180 normal translated message) with this value in place of `bus`, `id`, `mode` and
183 **multiple_responses** - (optional, false by default) if true, request will stay
184 active for a full 100ms, even after receiving a diagnostic response message.
185 This is useful for requests to the functional broadcast arbitration ID
186 (`0x7df`) when you need to get responses from multiple modules. It's possible
187 to set this to `true` for non-broadcast requests, but in practice you won't
188 see any additional responses after the first and it will just take up memory
189 in the VI for longer.
191 **frequency** - (optional) Make this request a recurring request, at a this
192 frequency in Hz. To send a single non-recurring request, leave this field out.
194 **decoded_type** - (optional, defaults to "obd2" if the request is a recognized
195 OBD-II mode 1 request, otherwise "none") If specified, the valid values are
196 `"none"` and `"obd2"`. If `obd2`, the payload will be decoded according to the
197 OBD-II specification and returned in the `value` field. Set this to `none` to
198 manually override the OBD-II decoding feature for a known PID.
202 The response to a successful request:
212 and to an unsuccessful request, with the `negative_response_code` and no `pid`
219 "negative_response_code": 17}
221 **bus** - the numerical identifier of the CAN bus where this response was
224 **id** - the CAN arbitration ID for this response.
226 **mode** - the OBD-II mode of the original diagnostic request.
228 **pid** - (optional) the PID for the request, if applicable.
230 **success** - true if the response received was a positive response. If this
231 field is false, the remote node returned an error and the
232 `negative_response_code` field should be populated.
234 **negative_response_code** - (optional) If requested node returned an error,
235 `success` will be `false` and this field will contain the negative response
238 Finally, the `payload` and `value` fields are mutually exclusive:
240 **payload** - (optional) up to 7 bytes of data returned in the response,
241 represented as a hexadecimal number in a string. Many JSON parser cannot
242 handle 64-bit integers, which is why we are not using a numerical data type.
244 **value** - (optional) if the response had a payload, this may be the
245 payload interpreted as an integer.
247 The response to a simple PID request would look like this:
249 {"success": true, "bus": 1, "id": 1234, "mode": 1, "pid": 5, "payload": "0x2"}
253 In addition to the `diagnostic_request` command described earlier, there are
254 other possible values for the `command` field.
258 The `version` command triggers the VI to inject a firmware version identifier
259 response into the outgoing data stream.
263 { "command": "version"}
267 { "command_response": "version", "message": "v6.0-dev (default)"}
271 The `device_id` command triggers the VI to inject a unique device ID (e.g. the
272 MAC address of an included Bluetooth module) into into the outgoing data stream.
276 { "command": "device_id"}
280 { "command_response": "device_id", "message": "0012345678"}
282 ### Trace File Format
284 An OpenXC vehicle trace file is a plaintext file that contains JSON objects,
285 separated by newlines (which may be either `\r\n` or `\n`, depending on the
286 platform the trace file was recorded).
288 The first line may be a metadata object, although this is optional:
293 "vehicle_interface_id": "7ABF",
297 "trim": "V6 Premium",
300 "description": "highway drive to work",
301 "driver_name": "TJ Giuli",
302 "vehicle_id": "17N1039247929"
306 The following lines are OpenXC messages with a `timestamp` field added, e.g.:
308 {"timestamp": 1385133351.285525, "name": "steering_wheel_angle", "value": 45}
310 The timestamp is in [UNIX time](http://en.wikipedia.org/wiki/Unix_time)
311 (i.e. seconds since the UNIX epoch, 00:00:00 UTC, 1/1/1970).
315 These signal names are a part of the OpenXC specification, although some
316 manufacturers may support custom message names.
318 * steering_wheel_angle
319 * numerical, -600 to +600 degrees
321 * torque_at_transmission
322 * numerical, -500 to 1500 Nm
325 * numerical, 0 to 16382 RPM
328 * numerical, 0 to 655 km/h (this will be positive even if going in reverse
329 as it's not a velocity, although you can use the gear status to figure out
332 * accelerator_pedal_position
335 * parking_brake_status
336 * boolean, (true == brake engaged)
337 * 1Hz, but sent immediately on change
339 * boolean (True == pedal pressed)
340 * 1Hz, but sent immediately on change
341 * transmission_gear_position
342 * states: first, second, third, fourth, fifth, sixth, seventh, eighth,
343 ninth, tenth, reverse, neutral
344 * 1Hz, but sent immediately on change
345 * gear_lever_position
346 * states: neutral, park, reverse, drive, sport, low, first, second, third,
347 fourth, fifth, sixth, seventh, eighth, ninth, tenth
348 * 1Hz, but sent immediately on change
351 0 to 16777214.000 km, with about .2m resolution
354 * states: off, accessory, run, start
355 * 1Hz, but sent immediately on change
359 * fuel_consumed_since_restart
360 * numerical, 0 - 4294967295.0 L (this goes to 0 every time the vehicle
361 restarts, like a trip meter)
364 * Value is State: driver, passenger, rear_left, rear_right.
365 * Event is boolean: true == ajar
366 * 1Hz, but sent immediately on change
368 * boolean, true is on
369 * 1Hz, but sent immediately on change
371 * boolean, true is on
372 * 1Hz, but sent immediately on change
373 * windshield_wiper_status
374 * boolean, true is on
375 * 1Hz, but sent immediately on change
377 * numerical, -89.0 to 89.0 degrees with standard GPS accuracy
380 * numerical, -179.0 to 179.0 degrees with standard GPS accuracy
383 ### Signals from Diagnostics Messages
385 This set of signals is often retreived from OBD-II requests. The units can be
386 found in the [OBD-II standard](http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01).
389 * engine_coolant_temperature
390 * barometric_pressure
391 * commanded_throttle_position
394 * intake_air_temperature
395 * intake_manifold_pressure
399 * accelerator_pedal_position
400 * ethanol_fuel_percentage
401 * engine_oil_temperature
407 Copyright (c) 2012-2014 Ford Motor Company
409 Licensed under the BSD license.
411 [OpenXC]: http://openxcplatform.com