Mark whether a PID is present in response.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Fri, 17 Jan 2014 20:56:34 +0000 (15:56 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Fri, 17 Jan 2014 20:56:34 +0000 (15:56 -0500)
src/obd2/obd2.c
src/obd2/obd2_types.h
tests/test_core.c

index 5b282f1..5061dd6 100644 (file)
@@ -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;
index 0699fc4..15552e8 100644 (file)
@@ -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];
index 182f268..1ab9409 100644 (file)
@@ -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]);