475ae21560174e1defa1a5e4ea39e6939aa727b9
[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.
44
45 ## Diagnostic Messages
46
47 ### Requests
48
49     {"bus": 1,
50       "id": 1234,
51       "mode": 1,
52       "pid": 5,
53       "payload": "0x1234",
54       "parse_payload": true,
55       "factor": 1.0,
56       "offset": 0,
57       "frequency": 0}
58
59 **bus** - the numerical identifier of the CAN bus where this request should be
60     sent, most likely 1 or 2 (for a vehicle interface with 2 CAN controllers).
61
62 **id** - the CAN arbitration ID for the request.
63
64 **mode** - the OBD-II mode of the request - 1 through 15 (1 through 9 are the
65     standardized modes).
66
67 **pid** - (optional) the PID for the request, if applicable.
68
69 **payload** - (optional) up to 7 bytes of data for the request's payload
70     represented as a hexidecimal number in a string. Many JSON parser cannot
71     handle 64-bit integers, which is why we are not using a numerical data type.
72
73 **parse_payload** - (optional, false by default) if true, the complete payload in the
74     response message will be parsed as a number and returned in the 'value' field of
75     the response. The 'payload' field will be omitted in responses with a
76     'value'.
77
78 **factor** - (optional, 1.0 by default) if `parse_payload` is true, the value in
79     the payload will be multiplied by this factor before returning. The `factor`
80     is applied before the `offset`.
81
82 **offset** - (optional, 0 by default) if `parse_payload` is true, this offset
83     will be added to the value in the payload before returning. The `offset` is
84     applied after the `factor`.
85
86 **frequency** - (optional, defaults to 0) The frequency in Hz to send this
87     request. To send a single request, set this to 0 or leave it out.
88
89 TODO it'd be nice to have the OBD-II PIDs built in, with the proper conversion
90 functions - that may need a different output format
91
92 If you're just requesting a PID, you can use a simplified format for the
93 request:
94
95     {"bus": 1, "id": 1234, "mode": 1, "pid": 5}
96
97 ### Responses
98
99     {"bus": 1,
100       "id": 1234,
101       "mode": 1,
102       "pid": 5,
103       "success": true,
104       "negative_response_code": 17,
105       "payload": "0x1234",
106       "parsed_payload": 4660}
107
108 **bus** - the numerical identifier of the CAN bus where this response was
109     received.
110
111 **id** - the CAN arbitration ID for this response.
112
113 **mode** - the OBD-II mode of the original diagnostic request.
114
115 **pid** - (optional) the PID for the request, if applicable.
116
117 **success** -  true if the response received was a positive response. If this
118   field is false, the remote node returned an error and the
119   `negative_response_code` field should be populated.
120
121 **negative_response_code** - (optional)  If requested node returned an error,
122     `success` will be `false` and this field will contain the negative response
123     code (NRC).
124
125 Finally, the `payload` and `value` fields are mutually exclusive:
126
127 **payload** - (optional) up to 7 bytes of data returned in the response,
128     represented as a hexadecimal number in a string. Many JSON parser cannot
129     handle 64-bit integers, which is why we are not using a numerical data type.
130
131 **value** - (optional) if the response had a payload, this may be the
132     payload interpreted as an integer and transformed with a factor and offset
133     provided with the request.
134
135 The response to a simple PID request would look like this:
136
137     {"bus": 1, "id": 1234, "mode": 1, "pid": 5, "payload": "0x2"}
138
139 TODO again, it'd be nice to have the OBD-II PIDs built in, with the proper
140 conversion functions so the response here included the actual transformed value
141 of the pid and a human readable name
142
143 ## Trace File Format
144
145 An OpenXC vehicle trace file is a plaintext file that contains JSON objects,
146 separated by newlines.
147
148 The first line may be a metadata object, although this is optional:
149
150 ```
151 {"metadata": {
152     "version": "v3.0",
153     "vehicle_interface_id": "7ABF",
154     "vehicle": {
155         "make": "Ford",
156         "model": "Mustang",
157         "trim": "V6 Premium",
158         "year": 2013
159     },
160     "description": "highway drive to work",
161     "driver_name": "TJ Giuli",
162     "vehicle_id": "17N1039247929"
163 }
164 ```
165
166 The following lines are OpenXC messages with a `timestamp` field added, e.g.:
167
168     {"timestamp": 1385133351.285525, "name": "steering_wheel_angle", "value": 45}
169
170 The timestamp is in [UNIX time](http://en.wikipedia.org/wiki/Unix_time)
171 (i.e. seconds since the UNIX epoch, 00:00:00 UTC, 1/1/1970).
172
173 ## Official Signals
174
175 These signal names are a part of the OpenXC specification, although some
176 manufacturers may support custom message names.
177
178 * steering_wheel_angle
179     * numerical, -600 to +600 degrees
180     * 10Hz
181 * torque_at_transmission
182     * numerical, -500 to 1500 Nm
183     * 10Hz
184 * engine_speed
185     * numerical, 0 to 16382 RPM
186     * 10Hz
187 * vehicle_speed
188     * numerical, 0 to 655 km/h (this will be positive even if going in reverse
189       as it's not a velocity, although you can use the gear status to figure out
190       direction)
191     * 10Hz
192 * accelerator_pedal_position
193     * percentage
194     * 10Hz
195 * parking_brake_status
196     * boolean, (true == brake engaged)
197     * 1Hz, but sent immediately on change
198 * brake_pedal_status
199     * boolean (True == pedal pressed)
200     * 1Hz, but sent immediately on change
201 * transmission_gear_position
202     * states: first, second, third, fourth, fifth, sixth, seventh, eighth,
203       reverse, neutral
204     * 1Hz, but sent immediately on change
205 * gear_lever_position
206     * states: neutral, park, reverse, drive, sport, low, first, second, third,
207       fourth, fifth, sixth
208     * 1Hz, but sent immediately on change
209 * odometer
210     * Numerical, km
211         0 to 16777214.000 km, with about .2m resolution
212     * 10Hz
213 * ignition_status
214     * states: off, accessory, run, start
215     * 1Hz, but sent immediately on change
216 * fuel_level
217     * percentage
218     * 2Hz
219 * fuel_consumed_since_restart
220     * numerical, 0 - 4294967295.0 L (this goes to 0 every time the vehicle
221       restarts, like a trip meter)
222     * 10Hz
223 * door_status
224     * Value is State: driver, passenger, rear_left, rear_right.
225     * Event is boolean: true == ajar
226     * 1Hz, but sent immediately on change
227 * headlamp_status
228     * boolean, true is on
229     * 1Hz, but sent immediately on change
230 * high_beam_status
231     * boolean, true is on
232     * 1Hz, but sent immediately on change
233 * windshield_wiper_status
234     * boolean, true is on
235     * 1Hz, but sent immediately on change
236 * latitude
237     * numerical, -89.0 to 89.0 degrees with standard GPS accuracy
238     * 1Hz
239 * longitude
240     * numerical, -179.0 to 179.0 degrees with standard GPS accuracy
241     * 1Hz
242
243 License
244 =======
245
246 Copyright (c) 2012-2013 Ford Motor Company
247
248 Licensed under the BSD license.
249
250 [OpenXC]: http://openxcplatform.com