3 DiagnosticShims diagnostic_init_shims(LogShim log,
4 SendCanMessageShim send_can_message,
5 SetTimerShim set_timer) {
6 DiagnosticShims shims = {
9 send_can_message: send_can_message,
17 DiagnosticRequestHandle diagnostic_request(DiagnosticShims* shims,
18 DiagnosticRequest* request, DiagnosticResponseReceived callback) {
19 // TODO hmm, where is message_received coming from? we would need 2 layers
20 // of callbacks. if we do it in the obd2 library, we have to have some
21 // context passed to that message_received handler so we can then retreive
22 // the obd2 callback. there was an option question of if we should pass a
23 // context with that callback, and maybe this answers it.
25 // alternatively, what if don't hide isotp and allow that to also be
26 // injected. the user has the iso_tp message_received callback, and in that
27 // they call a message_received handler from obd2.
29 // in fact that makes more sense - all the diagnostic_can_frame_received
30 // function is going to be able to do is call the equivalent function in the
31 // isotp library. it may or may not have a complete ISO-TP message. huh.
32 DiagnosticRequestHandle handle = {
33 // TODO why are teh shims stored as a reference in the isotp handler?
34 // it's just 3 pointers
35 isotp_handler: isotp_init(&shims->isotp_shims, request->arbitration_id,
36 NULL, // TODO need a callback here!
38 type: 0 //DIAGNOSTIC_.... // TODO how would we know the type?
39 //does it matter? we were going to have a different callback
43 DiagnosticRequestHandle diagnostic_request_pid(DiagnosticShims* shims,
44 DiagnosticPidRequestType pid_request_type, uint16_t pid,
45 DiagnosticResponseReceived callback) {
46 // decide mode 0x1 / 0x22 based on pid type
47 DiagnosticRequest request = {
48 mode: pid_request_type == DIAGNOSTIC_STANDARD_PID ? 0x1 : 0x22,
52 return diagnostic_request(shims, &request, callback);
55 void diagnostic_receive_can_frame(DiagnosticRequestHandle* handler,
56 const uint16_t arbitration_id, const uint8_t data[],
58 isotp_receive_can_frame(handler->isotp_handler, arbitration_id, data, size);
61 // TODO everything below here is for future work...not critical for now.
63 DiagnosticRequestHandle diagnostic_request_malfunction_indicator_status(
64 DiagnosticShims* shims,
65 DiagnosticMilStatusReceived callback) {
66 // TODO request malfunction indicator light (MIL) status - request mode 1
67 // pid 1, parse first bit
70 DiagnosticRequestHandle diagnostic_request_vin(DiagnosticShims* shims,
71 DiagnosticVinReceived callback) {
74 DiagnosticRequestHandle diagnostic_request_dtc(DiagnosticShims* shims,
75 DiagnosticTroubleCodeType dtc_type,
76 DiagnosticTroubleCodesReceived callback) {
79 bool diagnostic_clear_dtc(DiagnosticShims* shims) {
82 DiagnosticRequestHandle diagnostic_enumerate_pids(DiagnosticShims* shims,
83 DiagnosticRequest* request, DiagnosticPidEnumerationReceived callback) {
84 // before calling the callback, split up the received bytes into 1 or 2 byte
85 // chunks depending on the mode so the final pid list is actual 1 or 2 byte PIDs
86 // TODO request supported PIDs - request PID 0 and parse 4 bytes in response