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