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