aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-15 16:49:22 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-15 16:49:22 -0500
commit1b5a2116bc558ebef5d59c2c37c02c7375bf8712 (patch)
tree3fff0cefe2fd0ecee12d00b65c28fda947a9d09e /src
parent6e08c6f35254273aa9750600be0effe6e7cf276e (diff)
Accept functional broadcast responses to a range of arb IDs.
Diffstat (limited to 'src')
-rw-r--r--src/obd2/obd2.c84
-rw-r--r--src/obd2/obd2.h2
-rw-r--r--src/obd2/obd2_types.h4
3 files changed, 54 insertions, 36 deletions
diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c
index 25b00e7c..513c7d71 100644
--- a/src/obd2/obd2.c
+++ b/src/obd2/obd2.c
@@ -30,9 +30,20 @@ DiagnosticShims diagnostic_init_shims(LogShim log,
}
static void setup_receive_handle(DiagnosticRequestHandle* handle) {
- handle->isotp_receive_handle = isotp_receive(&handle->isotp_shims,
- handle->request.arbitration_id + ARBITRATION_ID_OFFSET,
- NULL);
+ if(handle->request.arbitration_id == OBD2_FUNCTIONAL_BROADCAST_ID) {
+ for(uint16_t response_id = 0;
+ response_id < OBD2_FUNCTIONAL_RESPONSE_COUNT; ++response_id) {
+ handle->isotp_receive_handles[response_id] = isotp_receive(
+ &handle->isotp_shims, OBD2_FUNCTIONAL_RESPONSE_START + response_id,
+ NULL);
+ }
+ handle->isotp_receive_handle_count = OBD2_FUNCTIONAL_RESPONSE_COUNT;
+ } else {
+ handle->isotp_receive_handle_count = 1;
+ handle->isotp_receive_handles[0] = isotp_receive(&handle->isotp_shims,
+ handle->request.arbitration_id + ARBITRATION_ID_OFFSET,
+ NULL);
+ }
}
@@ -185,43 +196,46 @@ DiagnosticResponse diagnostic_receive_can_frame(DiagnosticShims* shims,
if(!handle->isotp_send_handle.completed) {
isotp_continue_send(&handle->isotp_shims,
&handle->isotp_send_handle, arbitration_id, data, size);
- } else if(!handle->isotp_receive_handle.completed) {
- IsoTpMessage message = isotp_continue_receive(&handle->isotp_shims,
- &handle->isotp_receive_handle, arbitration_id, data, size);
-
- if(message.completed) {
- if(message.size > 0) {
- response.mode = message.payload[0];
- if(handle_negative_response(&message, &response, shims)) {
- shims->log("Received a negative response to mode %d on arb ID 0x%x",
- response.mode, response.arbitration_id);
- handle->success = true;
- handle->completed = true;
- } else if(handle_positive_response(handle, &message, &response,
- shims)) {
- shims->log("Received a positive mode %d response on arb ID 0x%x",
- response.mode, response.arbitration_id);
- handle->success = true;
- handle->completed = true;
+ } else {
+ for(uint8_t i = 0; i < handle->isotp_receive_handle_count; ++i) {
+ IsoTpMessage message = isotp_continue_receive(&handle->isotp_shims,
+ &handle->isotp_receive_handles[i], arbitration_id, data, size);
+
+ // TODO as of now we're completing the handle as soon as one
+ // broadcast response is received....need to hang on for 100ms
+ if(message.completed) {
+ if(message.size > 0) {
+ response.mode = message.payload[0];
+ if(handle_negative_response(&message, &response, shims)) {
+ shims->log("Received a negative response to mode %d on arb ID 0x%x",
+ response.mode, response.arbitration_id);
+ handle->success = true;
+ handle->completed = true;
+ } else if(handle_positive_response(handle, &message, &response,
+ shims)) {
+ shims->log("Received a positive mode %d response on arb ID 0x%x",
+ response.mode, response.arbitration_id);
+ handle->success = true;
+ handle->completed = true;
+ } else {
+ shims->log("Response was for a mode 0x%x request (pid 0x%x), not our mode 0x%x request (pid 0x%x)",
+ MAX(0, response.mode - MODE_RESPONSE_OFFSET),
+ response.pid, handle->request.mode,
+ handle->request.pid);
+ // TODO just leave handles open until the user decides
+ // to be done with it - keep a count of valid responses
+ // received.
+ }
} else {
- shims->log("Response was for a mode 0x%x request (pid 0x%x), not our mode 0x%x request (pid 0x%x)",
- MAX(0, response.mode - MODE_RESPONSE_OFFSET),
- response.pid, handle->request.mode,
- handle->request.pid);
- setup_receive_handle(handle);
+ shims->log("Received an empty response on arb ID 0x%x",
+ response.arbitration_id);
}
- } else {
- shims->log("Received an empty response on arb ID 0x%x",
- response.arbitration_id);
- }
- if(handle->completed && handle->callback != NULL) {
- handle->callback(&response);
+ if(handle->completed && handle->callback != NULL) {
+ handle->callback(&response);
+ }
}
}
- } else {
- shims->log("Mode %d request to arb ID 0x%x is already completed",
- handle->request.mode, handle->request.arbitration_id);
}
return response;
}
diff --git a/src/obd2/obd2.h b/src/obd2/obd2.h
index b301138c..bcd6e76b 100644
--- a/src/obd2/obd2.h
+++ b/src/obd2/obd2.h
@@ -6,6 +6,8 @@
#include <stdbool.h>
#define OBD2_FUNCTIONAL_BROADCAST_ID 0x7df
+#define OBD2_FUNCTIONAL_RESPONSE_START 0x7e8
+#define OBD2_FUNCTIONAL_RESPONSE_COUNT 8
#ifdef __cplusplus
extern "C" {
diff --git a/src/obd2/obd2_types.h b/src/obd2/obd2_types.h
index 5260fa8e..0699fc4b 100644
--- a/src/obd2/obd2_types.h
+++ b/src/obd2/obd2_types.h
@@ -12,6 +12,7 @@ extern "C" {
// 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 MAX_RESPONDING_ECU_COUNT 8
#define VIN_LENGTH 17
/* Private: The four main types of diagnositc requests that determine how the
@@ -149,7 +150,8 @@ typedef struct {
// Private
IsoTpShims isotp_shims;
IsoTpSendHandle isotp_send_handle;
- IsoTpReceiveHandle isotp_receive_handle;
+ IsoTpReceiveHandle isotp_receive_handles[MAX_RESPONDING_ECU_COUNT];
+ uint8_t isotp_receive_handle_count;
DiagnosticResponseReceived callback;
// DiagnosticMilStatusReceived mil_status_callback;
// DiagnosticVinReceived vin_callback;