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