summaryrefslogtreecommitdiffstats
path: root/src/obd2
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-30 21:06:57 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-30 21:06:57 -0500
commit84bc68873aa53e295853b461b6793b5019d1dacb (patch)
tree933981a79b25c05185f7b55d5f8e6a96d5decc72 /src/obd2
parent0bd237bae324740d6b6b22e3c63ac426267d5bf1 (diff)
Spray a bunch of notes and code into the implementation file.
Diffstat (limited to 'src/obd2')
-rw-r--r--src/obd2/obd2.c62
-rw-r--r--src/obd2/obd2.h3
2 files changed, 53 insertions, 12 deletions
diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c
index 9b4ea92d..3d501d6a 100644
--- a/src/obd2/obd2.c
+++ b/src/obd2/obd2.c
@@ -3,23 +3,68 @@
DiagnosticShims diagnostic_init_shims(LogShim log,
SendCanMessageShim send_can_message,
SetTimerShim set_timer) {
+ DiagnosticShims shims = {
+ isotp_shims: {
+ log: log,
+ send_can_message: send_can_message,
+ set_timer: set_timer
+ },
+ log: log
+ };
+ return shims;
}
DiagnosticRequestHandle diagnostic_request(DiagnosticShims* shims,
DiagnosticRequest* request, DiagnosticResponseReceived callback) {
+ // TODO hmm, where is message_received coming from? we would need 2 layers
+ // of callbacks. if we do it in the obd2 library, we have to have some
+ // context passed to that message_received handler so we can then retreive
+ // the obd2 callback. there was an option question of if we should pass a
+ // context with that callback, and maybe this answers it.
+ //
+ // alternatively, what if don't hide isotp and allow that to also be
+ // injected. the user has the iso_tp message_received callback, and in that
+ // they call a message_received handler from obd2.
+ //
+ // in fact that makes more sense - all the diagnostic_can_frame_received
+ // function is going to be able to do is call the equivalent function in the
+ // isotp library. it may or may not have a complete ISO-TP message. huh.
+ DiagnosticRequestHandle handle = {
+ // TODO why are teh shims stored as a reference in the isotp handler?
+ // it's just 3 pointers
+ isotp_handler: isotp_init(&shims->isotp_shims, request->arbitration_id,
+ NULL, // TODO need a callback here!
+ NULL, NULL),
+ type: 0 //DIAGNOSTIC_.... // TODO how would we know the type?
+ //does it matter? we were going to have a different callback
+ };
}
-// decide mode 0x1 / 0x22 based on pid type
DiagnosticRequestHandle diagnostic_request_pid(DiagnosticShims* shims,
DiagnosticPidRequestType pid_request_type, uint16_t pid,
DiagnosticResponseReceived callback) {
+ // decide mode 0x1 / 0x22 based on pid type
+ DiagnosticRequest request = {
+ mode: pid_request_type == DIAGNOSTIC_STANDARD_PID ? 0x1 : 0x22,
+ pid: pid
+ };
+
+ return diagnostic_request(shims, &request, callback);
+}
+
+void diagnostic_receive_can_frame(DiagnosticRequestHandle* handler,
+ const uint16_t arbitration_id, const uint8_t data[],
+ const uint8_t size) {
+ isotp_receive_can_frame(handler->isotp_handler, arbitration_id, data, size);
}
-// TODO request malfunction indicator light (MIL) status - request mode 1 pid 1,
-// parse first bit
+// TODO everything below here is for future work...not critical for now.
+
DiagnosticRequestHandle diagnostic_request_malfunction_indicator_status(
DiagnosticShims* shims,
DiagnosticMilStatusReceived callback) {
+ // TODO request malfunction indicator light (MIL) status - request mode 1
+ // pid 1, parse first bit
}
DiagnosticRequestHandle diagnostic_request_vin(DiagnosticShims* shims,
@@ -34,14 +79,9 @@ DiagnosticRequestHandle diagnostic_request_dtc(DiagnosticShims* shims,
bool diagnostic_clear_dtc(DiagnosticShims* shims) {
}
-// before calling the callback, split up the received bytes into 1 or 2 byte
-// chunks depending on the mode so the final pid list is actual 1 or 2 byte PIDs
-// TODO request supported PIDs - request PID 0 and parse 4 bytes in response
DiagnosticRequestHandle diagnostic_enumerate_pids(DiagnosticShims* shims,
DiagnosticRequest* request, DiagnosticPidEnumerationReceived callback) {
-}
-
-void diagnostic_receive_can_frame(DiagnosticRequestHandle* handler,
- const uint16_t arbitration_id, const uint8_t data[],
- const uint8_t size) {
+ // before calling the callback, split up the received bytes into 1 or 2 byte
+ // chunks depending on the mode so the final pid list is actual 1 or 2 byte PIDs
+ // TODO request supported PIDs - request PID 0 and parse 4 bytes in response
}
diff --git a/src/obd2/obd2.h b/src/obd2/obd2.h
index 74459520..e4ffc7ab 100644
--- a/src/obd2/obd2.h
+++ b/src/obd2/obd2.h
@@ -114,6 +114,8 @@ typedef struct {
IsoTpHandler isotp_handler;
// TODO the Handle may need to keep the original request, otherwise we can't
// compare an incoming CAN message to see if it matches the service / PID!
+ // TODO i'm not sure this type/callback in here is too useful - see the
+ // comments in obd2.c:diagnostic_request
DiagnosticRequestType type;
DiagnosticResponseReceived callback;
DiagnosticMilStatusReceived mil_status_callback;
@@ -129,7 +131,6 @@ typedef enum {
typedef struct {
IsoTpShims isotp_shims;
LogShim log;
- SendCanMessageShim send_can_message;
} DiagnosticShims;
DiagnosticShims diagnostic_init_shims(LogShim log,