Mark request handle and response completed even if an error ocurred.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Mon, 6 Jan 2014 23:22:06 +0000 (18:22 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Mon, 6 Jan 2014 23:24:17 +0000 (18:24 -0500)
Add extra logging and a few notes.

src/obd2/obd2.c
tests/test_core.c

index 3dad886..c780fd8 100644 (file)
@@ -147,6 +147,8 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle,
             } else {
                 response->pid = message->payload[PID_BYTE_INDEX];
             }
+            // TODO we're not currently throwing an error or anything if the PID
+            // doesn't match - it may be OK to leave that up to the user.
         }
 
         uint8_t payload_index = 1 + handle->request.pid_length;
@@ -197,13 +199,23 @@ DiagnosticResponse diagnostic_receive_can_frame(DiagnosticShims* shims,
                             response.mode - MODE_RESPONSE_OFFSET,
                             handle->request.mode);
                 }
+            } else {
+                shims->log("Received an empty response on arb ID 0x%x",
+                        response.arbitration_id);
             }
+            // TODO For now even if we got an empty repsonse or something for
+            // the wrong mode, we're marking this as completed - I'm not sure
+            // those other cases could or will ever happen in practice.
+            // Alternatively, we could re-init handle->isotp_receive_handle if
+            // the current one completed without a valid response to this
+            // diagnostic request.
+            response.completed = true;
+            handle->completed = true;
 
             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);
index cf8673a..51dff33 100644 (file)
@@ -140,8 +140,11 @@ START_TEST (test_wrong_mode_response)
     const uint8_t can_data[] = {0x4, 0x1 + 0x40, 0x0, 0x2, 0x45};
     diagnostic_receive_can_frame(&SHIMS, &handle, arb_id + 0x8, can_data,
             sizeof(can_data));
-    fail_if(last_response_was_received);
-    fail_if(handle.completed);
+    // TODO change this if we even re-request a message receipt on a mode or PID
+    // mismatch
+    fail_unless(last_response_was_received);
+    fail_unless(handle.completed);
+    fail_if(last_response_received.success);
 }
 END_TEST