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