4 #include <uds/uds_types.h>
8 #define OBD2_FUNCTIONAL_BROADCAST_ID 0x7df
9 #define OBD2_FUNCTIONAL_RESPONSE_START 0x7e8
10 #define OBD2_FUNCTIONAL_RESPONSE_COUNT 8
16 /* Public: Initialize an DiagnosticShims with the given callback functions.
18 * If any callbacks are not to be used, set them to NULL. For documentation of
19 * the function type signatures, see higher up in this header file. This struct
20 * is a handy encapsulation used to pass the shims around to the various
21 * diagnostic_* functions.
23 * Returns a struct with the fields initailized to the callbacks.
25 DiagnosticShims diagnostic_init_shims(LogShim log,
26 SendCanMessageShim send_can_message,
27 SetTimerShim set_timer);
29 /* Public: Initiate a diagnostic request and return a handle, ready to completly
30 * send the request and process the response via
31 * diagnostic_receive_can_frame(...).
33 * shims - Low-level shims required to send CAN messages, etc.
35 * callback - an optional function to be called when the response is receved
36 * (use NULL if no callback is required).
38 * Returns a handle to be used with diagnostic_receive_can_frame to complete
39 * sending the request and receive the response. The 'completed' field in the
40 * returned DiagnosticRequestHandle will be true when the message is completely
43 DiagnosticRequestHandle diagnostic_request(DiagnosticShims* shims,
44 DiagnosticRequest* request, DiagnosticResponseReceived callback);
46 /* Public: Request a PID from the given arbitration ID, determining the mode
47 * automatically based on the PID type.
49 * shims - Low-level shims required to send CAN messages, etc.
50 * pid_request_type - either DIAGNOSTIC_STANDARD_PID (will use mode 0x1 and 1
51 * byte PIDs) or DIAGNOSTIC_ENHANCED_PID (will use mode 0x22 and 2 byte
53 * arbitration_id - The arbitration ID to send the request to.
54 * pid - The PID to request from the other node.
55 * callback - an optional function to be called when the response is receved
56 * (use NULL if no callback is required).
58 * Returns a handle to be used with diagnostic_receive_can_frame to complete
59 * sending the request and receive the response. The 'completed' field in the
60 * returned DiagnosticRequestHandle will be true when the message is completely
63 DiagnosticRequestHandle diagnostic_request_pid(DiagnosticShims* shims,
64 DiagnosticPidRequestType pid_request_type, uint16_t arbitration_id,
65 uint16_t pid, DiagnosticResponseReceived callback);
67 /* Public: Continue to send and receive a single diagnostic request, based on a
68 * freshly received CAN message.
70 * shims - Low-level shims required to send CAN messages, etc.
71 * handle - A DiagnosticRequestHandle previously returned by one of the
72 * diagnostic_request*(..) functions.
73 * arbitration_id - The arbitration_id of the received CAN message.
74 * data - The data of the received CAN message.
75 * size - The size of the data in the received CAN message.
77 * Returns true if the request was completed and response received, or the
78 * request was otherwise cancelled. Check the 'success' field of the handle to
79 * see if it was successful.
81 DiagnosticResponse diagnostic_receive_can_frame(DiagnosticShims* shims,
82 DiagnosticRequestHandle* handle,
83 const uint16_t arbitration_id, const uint8_t data[],
86 /* Public: Render a DiagnosticResponse as a string into the given buffer.
90 * message - the response to convert to a string, for debug logging.
91 * destination - the target string buffer.
92 * destination_length - the size of the destination buffer, i.e. the max size
93 * for the rendered string.
95 // void diagnostic_response_to_string(const DiagnosticResponse* response,
96 // char* destination, size_t destination_length);