Add skeleton of the API and data structures.
[apps/low-level-can-service.git] / README.mkd
1 OBD-II Support Library in C
2 =============================
3
4 TODO isotp needs to accept responses on an ID other that the request's arb id -
5 or maybe we have 2 isotp instances, for rx and tx.
6
7 * Response's arb id is assigned ID plus 0x8
8 * Functional daignostic request (Broadcast), 0x7df arb id
9 * Standard ECU requests to 0x7e0 - 0x7e7
10
11 * Some requests don't need PIDs - e.g. mode 3
12     * some responses don't have PIDs, just payload - e.g. mode 3
13
14 * Service ID + 0x40 == positive response
15 * Response includes PID echo - use this to match up request/response
16 * Response ID, ISO-TP PCI, ISO-TP length, service response ID, PID echo, data
17
18 I send the request and give a callback
19 when the response arrives for the matchin service and PID - on any arb id, since
20 this may be a broadcast - call my callback.
21
22
23 TODO do you want to provide the callback to the Handler, or to each
24 individual send?o
25 ok, what are the use cases here.
26
27 you're going to request a few PIDs over and over again at some frequency
28 you're going to request DTCs once and read the response
29 you're going to clear DTCs once
30
31 i'd rather use the same diagnostic handler to send all of the differet messages
32 rather than create one for each use. that way ai can
33
34 but that does complicate the memory management because it'll need to create
35 some internal data structures.
36
37 at the simplest, what does this handler have to do?
38
39 * store the request arb id, mode, pid, and payload locally
40 * send a can message
41 * get all new can messages passed to it
42 * Check the incoming can message to see if it matches one of the standard ECU
43   response IDs, or our arb ID + 0x8
44 * if it matches, parse the diagnostic response and call the callback
45
46 that seems pretty simple and not worth greatly increasing the internal state to
47 handle multiple requests
48
49 what we need is another layer on top of that to handle the repeated requests.
50
51 ## API
52
53     void my_callback(const DiagnosticResponse* response) {
54     }
55
56     DiagnosticRequestHandler handler = diagnostic_init(my_callback);
57     DiagnosticRequest request = {
58         arbitratin_id: 0x7df,
59         mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST,
60         pid: 3
61     };
62
63     diagnostic_send(&handler, &request);
64     while(true) {
65         diagnostic_handle_can_frame(&handler, 42, data, 8);
66     }
67
68     diagnostic_request_pid(&handler, DIAGNOSTIC_STANDARD_PID, 42
69
70     diagnostic_destroy(&handler);
71
72 ## Testing
73
74 The library includes a test suite that uses the `check` C unit test library.
75
76     $ make test
77
78 ## Authors
79
80 Chris Peplin cpeplin@ford.com
81
82 ## License
83
84 Copyright (c) 2013 Ford Motor Company
85
86 Licensed under the BSD license.