01ca5f3984b88ae66428f413d7bd79b1237bfe9a
[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           "parse_payload": true,
62           "multiple_response": 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 in the
88     response message will be parsed as a number and returned in the 'value' field of
89     the response. The 'payload' field will be omitted in responses with a
90     'value'.
91
92 **multiple_response** - (optional, false by default) if true, request will stay
93   active for a full 100ms, even after receiving a diagnostic response message.
94   This is useful for requests to the functional broadcast arbitration ID
95   (`0x7df`) when you need to get responses from multiple modules. It's possible
96   to set this to `true` for non-broadcast requests, but in practice you won't
97   see any additional responses after the first and it will just take up memory
98   in the VI for longer.
99
100 **factor** - (optional, 1.0 by default) if `parse_payload` is true, the value in
101     the payload will be multiplied by this factor before returning. The `factor`
102     is applied before the `offset`.
103
104 **offset** - (optional, 0 by default) if `parse_payload` is true, this offset
105     will be added to the value in the payload before returning. The `offset` is
106     applied after the `factor`.
107
108 **frequency** - (optional, defaults to 0) The frequency in Hz to send this
109     request. To send a single request, set this to 0 or leave it out.
110
111 **name** - (optional, defaults to nothing) A human readable, string name for
112     this request. If provided, the response will have a `name` field (much like a
113     normal translated message) in place of the request details (i.e. the bus,
114     id, mode and pid).  TODO elaborate on this.
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 TODO it'd be nice to have the OBD-II PIDs built in, with the proper conversion
122 functions - that may need a different output format
123
124 If you're just requesting a PID, you can use this minimal field set for the
125 `request` object:
126
127     {"bus": 1, "id": 1234, "mode": 1, "pid": 5}
128
129 ### Responses
130
131     {"bus": 1,
132       "id": 1234,
133       "mode": 1,
134       "pid": 5,
135       "success": true,
136       "negative_response_code": 17,
137       "payload": "0x1234",
138       "parsed_payload": 4660}
139
140 **bus** - the numerical identifier of the CAN bus where this response was
141     received.
142
143 **id** - the CAN arbitration ID for this response.
144
145 **mode** - the OBD-II mode of the original diagnostic request.
146
147 **pid** - (optional) the PID for the request, if applicable.
148
149 **success** -  true if the response received was a positive response. If this
150   field is false, the remote node returned an error and the
151   `negative_response_code` field should be populated.
152
153 **negative_response_code** - (optional)  If requested node returned an error,
154     `success` will be `false` and this field will contain the negative response
155     code (NRC).
156
157 Finally, the `payload` and `value` fields are mutually exclusive:
158
159 **payload** - (optional) up to 7 bytes of data returned in the response,
160     represented as a hexadecimal number in a string. Many JSON parser cannot
161     handle 64-bit integers, which is why we are not using a numerical data type.
162
163 **value** - (optional) if the response had a payload, this may be the
164     payload interpreted as an integer and transformed with a factor and offset
165     provided with the request.
166
167 The response to a simple PID request would look like this:
168
169     {"bus": 1, "id": 1234, "mode": 1, "pid": 5, "payload": "0x2"}
170
171 TODO again, it'd be nice to have the OBD-II PIDs built in, with the proper
172 conversion functions so the response here included the actual transformed value
173 of the pid and a human readable name
174
175 ## Trace File Format
176
177 An OpenXC vehicle trace file is a plaintext file that contains JSON objects,
178 separated by newlines.
179
180 The first line may be a metadata object, although this is optional:
181
182 ```
183 {"metadata": {
184     "version": "v3.0",
185     "vehicle_interface_id": "7ABF",
186     "vehicle": {
187         "make": "Ford",
188         "model": "Mustang",
189         "trim": "V6 Premium",
190         "year": 2013
191     },
192     "description": "highway drive to work",
193     "driver_name": "TJ Giuli",
194     "vehicle_id": "17N1039247929"
195 }
196 ```
197
198 The following lines are OpenXC messages with a `timestamp` field added, e.g.:
199
200     {"timestamp": 1385133351.285525, "name": "steering_wheel_angle", "value": 45}
201
202 The timestamp is in [UNIX time](http://en.wikipedia.org/wiki/Unix_time)
203 (i.e. seconds since the UNIX epoch, 00:00:00 UTC, 1/1/1970).
204
205 ## Official Signals
206
207 These signal names are a part of the OpenXC specification, although some
208 manufacturers may support custom message names.
209
210 * steering_wheel_angle
211     * numerical, -600 to +600 degrees
212     * 10Hz
213 * torque_at_transmission
214     * numerical, -500 to 1500 Nm
215     * 10Hz
216 * engine_speed
217     * numerical, 0 to 16382 RPM
218     * 10Hz
219 * vehicle_speed
220     * numerical, 0 to 655 km/h (this will be positive even if going in reverse
221       as it's not a velocity, although you can use the gear status to figure out
222       direction)
223     * 10Hz
224 * accelerator_pedal_position
225     * percentage
226     * 10Hz
227 * parking_brake_status
228     * boolean, (true == brake engaged)
229     * 1Hz, but sent immediately on change
230 * brake_pedal_status
231     * boolean (True == pedal pressed)
232     * 1Hz, but sent immediately on change
233 * transmission_gear_position
234     * states: first, second, third, fourth, fifth, sixth, seventh, eighth,
235       reverse, neutral
236     * 1Hz, but sent immediately on change
237 * gear_lever_position
238     * states: neutral, park, reverse, drive, sport, low, first, second, third,
239       fourth, fifth, sixth
240     * 1Hz, but sent immediately on change
241 * odometer
242     * Numerical, km
243         0 to 16777214.000 km, with about .2m resolution
244     * 10Hz
245 * ignition_status
246     * states: off, accessory, run, start
247     * 1Hz, but sent immediately on change
248 * fuel_level
249     * percentage
250     * 2Hz
251 * fuel_consumed_since_restart
252     * numerical, 0 - 4294967295.0 L (this goes to 0 every time the vehicle
253       restarts, like a trip meter)
254     * 10Hz
255 * door_status
256     * Value is State: driver, passenger, rear_left, rear_right.
257     * Event is boolean: true == ajar
258     * 1Hz, but sent immediately on change
259 * headlamp_status
260     * boolean, true is on
261     * 1Hz, but sent immediately on change
262 * high_beam_status
263     * boolean, true is on
264     * 1Hz, but sent immediately on change
265 * windshield_wiper_status
266     * boolean, true is on
267     * 1Hz, but sent immediately on change
268 * latitude
269     * numerical, -89.0 to 89.0 degrees with standard GPS accuracy
270     * 1Hz
271 * longitude
272     * numerical, -179.0 to 179.0 degrees with standard GPS accuracy
273     * 1Hz
274
275 License
276 =======
277
278 Copyright (c) 2012-2013 Ford Motor Company
279
280 Licensed under the BSD license.
281
282 [OpenXC]: http://openxcplatform.com