extern "C" {
#endif
+// TODO This isn't true for multi frame messages - we may need to dynamically
+// allocate this in the future
#define MAX_OBD2_PAYLOAD_LENGTH 7
#define VIN_LENGTH 17
+typedef enum {
+ DIAGNOSTIC_REQUEST_TYPE_PID,
+ DIAGNOSTIC_REQUEST_TYPE_DTC,
+ DIAGNOSTIC_REQUEST_TYPE_MIL_STATUS,
+ DIAGNOSTIC_REQUEST_TYPE_VIN
+} DiagnosticRequestType;
+
typedef struct {
+ DiagnosticRequestType type;
uint16_t arbitration_id;
uint8_t mode;
uint16_t pid;
uint8_t payload_length;
} DiagnosticRequest;
-// TODO I don't like this, it's hard coding isotp library stuff here
-typedef bool (*SendIsoTpMessageShim)(IsoTpHandler* handler,
- const uint8_t* payload, uint16_t payload_size);
-
// Thanks to
// http://www.canbushack.com/blog/index.php?title=scanning-for-diagnostic-data&more=1&c=1&tb=1&pb=1
// for the list of NRCs
typedef struct {
uint16_t arbitration_id;
uint8_t mode;
+ bool completed;
bool success;
- // if mode is one with a PID, read the correct numbers of PID bytes (1 or 2)
- // into this field, then store the remainder of the payload in the payload
- // field
uint16_t pid;
DiagnosticNegativeResponseCode negative_response_code;
- // if response mode is a negative response, read first byte of payload into
- // NRC and store remainder of payload in payload field
uint8_t payload[MAX_OBD2_PAYLOAD_LENGTH];
uint8_t payload_length;
} DiagnosticResponse;
float max_value;
} DiagnosticParameter;
-typedef enum {
- DIAGNOSTIC_REQUEST_TYPE_PID,
- DIAGNOSTIC_REQUEST_TYPE_DTC,
- DIAGNOSTIC_REQUEST_TYPE_MIL_STATUS,
- DIAGNOSTIC_REQUEST_TYPE_VIN
-} DiagnosticRequestType;
-
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
+ DiagnosticRequest request;
+ bool success;
+ bool completed;
- DiagnosticRequestType type;
+ IsoTpShims isotp_shims;
+ IsoTpSendHandle isotp_send_handle;
+ IsoTpReceiveHandle isotp_receive_handle;
DiagnosticResponseReceived callback;
DiagnosticMilStatusReceived mil_status_callback;
DiagnosticVinReceived vin_callback;
- bool status;
} DiagnosticRequestHandle;
typedef enum {
} DiagnosticPidRequestType;
typedef struct {
- SetTimerShim set_timer;
- SendCanMessageShim send_can_message;
LogShim log;
+ SendCanMessageShim send_can_message;
+ SetTimerShim set_timer;
} DiagnosticShims;
DiagnosticShims diagnostic_init_shims(LogShim log,
// decide mode 0x1 / 0x22 based on pid type
DiagnosticRequestHandle diagnostic_request_pid(DiagnosticShims* shims,
- DiagnosticPidRequestType pid_request_type, uint16_t pid,
- DiagnosticResponseReceived callback);
+ DiagnosticPidRequestType pid_request_type, uint16_t arbitration_id,
+ uint16_t pid, DiagnosticResponseReceived callback);
DiagnosticRequestHandle diagnostic_request_malfunction_indicator_status(
DiagnosticShims* shims,
DiagnosticRequestHandle diagnostic_enumerate_pids(DiagnosticShims* shims,
DiagnosticRequest* request, DiagnosticPidEnumerationReceived callback);
-// TODO
-// void diagnostic_receive_isotp_message(DiagnosticRequestHandle* handle,
- // const IsoTpMessage* message);
-void diagnostic_receive_isotp_message(const IsoTpMessage* message);
-
-void diagnostic_receive_can_frame(DiagnosticRequestHandle* handle,
+DiagnosticResponse diagnostic_receive_can_frame(DiagnosticShims* shims,
+ DiagnosticRequestHandle* handle,
const uint16_t arbitration_id, const uint8_t data[],
const uint8_t size);