diff options
author | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2014-01-17 15:56:34 -0500 |
---|---|---|
committer | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2014-01-17 15:56:34 -0500 |
commit | 6ebad2aac3ba2f0d7ff5e37c5db4e5b9549247e2 (patch) | |
tree | fcec8eae39587e50054fb627eee3662acb7809b3 | |
parent | 648c2f77afd1dadce1c01de3f1dc42b54da656d0 (diff) |
Mark whether a PID is present in response.
-rw-r--r-- | src/obd2/obd2.c | 6 | ||||
-rw-r--r-- | src/obd2/obd2_types.h | 6 | ||||
-rw-r--r-- | tests/test_core.c | 6 |
3 files changed, 12 insertions, 6 deletions
diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c index 5b282f16..5061dd6b 100644 --- a/src/obd2/obd2.c +++ b/src/obd2/obd2.c @@ -154,9 +154,9 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle, // hide the "response" version of the mode from the user // if it matched response->mode = handle->request.mode; - bool has_pid = false; + response->has_pid = false; if(handle->request.pid_length > 0 && message->size > 1) { - has_pid = true; + response->has_pid = true; if(handle->request.pid_length == 2) { response->pid = get_bitfield(message->payload, message->size, PID_BYTE_INDEX * CHAR_BIT, sizeof(uint16_t) * CHAR_BIT); @@ -173,7 +173,7 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle, response->payload_length); } - if((handle->request.pid_length == 0 && !has_pid) + if((handle->request.pid_length == 0 && !response->has_pid) || response->pid == handle->request.pid) { response->success = true; response->completed = true; diff --git a/src/obd2/obd2_types.h b/src/obd2/obd2_types.h index 0699fc4b..15552e88 100644 --- a/src/obd2/obd2_types.h +++ b/src/obd2/obd2_types.h @@ -83,7 +83,10 @@ typedef enum { * the negative_response_code field for the reason. * arbitration_id - The arbitration ID the response was received on. * mode - The OBD-II mode for the original request. - * pid - If the request was for a PID, this is the PID echo. + * has_pid - If this is a response to a PID request, this will be true and the + * 'pid' field will be valid. + * pid - If the request was for a PID, this is the PID echo. Only valid if + * 'has_pid' is true. * negative_response_code - If the request was not successful, 'success' will be * false and this will be set to a DiagnosticNegativeResponseCode returned * by the other node. @@ -95,6 +98,7 @@ typedef struct { bool success; uint16_t arbitration_id; uint8_t mode; + bool has_pid; uint16_t pid; DiagnosticNegativeResponseCode negative_response_code; uint8_t payload[MAX_OBD2_PAYLOAD_LENGTH]; diff --git a/tests/test_core.c b/tests/test_core.c index 182f268b..1ab94094 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -84,7 +84,7 @@ START_TEST (test_send_functional_request) ck_assert_int_eq(last_response_received.arbitration_id, filter); ck_assert_int_eq(last_response_received.mode, request.mode); - ck_assert_int_eq(last_response_received.pid, 0); + fail_if(last_response_received.has_pid); ck_assert_int_eq(last_response_received.payload_length, 1); ck_assert_int_eq(last_response_received.payload[0], can_data[2]); } @@ -116,7 +116,7 @@ START_TEST (test_send_diag_request) ck_assert_int_eq(last_response_received.arbitration_id, request.arbitration_id + 0x8); ck_assert_int_eq(last_response_received.mode, request.mode); - ck_assert_int_eq(last_response_received.pid, 0); + fail_if(last_response_received.has_pid); ck_assert_int_eq(last_response_received.payload_length, 1); ck_assert_int_eq(last_response_received.payload[0], can_data[2]); } @@ -137,6 +137,7 @@ START_TEST (test_request_pid_standard) ck_assert_int_eq(last_response_received.arbitration_id, arb_id + 0x8); ck_assert_int_eq(last_response_received.mode, 0x1); + fail_unless(last_response_received.has_pid); ck_assert_int_eq(last_response_received.pid, 0x2); ck_assert_int_eq(last_response_received.payload_length, 1); ck_assert_int_eq(last_response_received.payload[0], can_data[3]); @@ -158,6 +159,7 @@ START_TEST (test_request_pid_enhanced) ck_assert_int_eq(last_response_received.arbitration_id, arb_id + 0x8); ck_assert_int_eq(last_response_received.mode, 0x22); + fail_unless(last_response_received.has_pid); ck_assert_int_eq(last_response_received.pid, 0x2); ck_assert_int_eq(last_response_received.payload_length, 1); ck_assert_int_eq(last_response_received.payload[0], can_data[4]); |