From: Christopher Peplin Date: Wed, 8 Jan 2014 22:19:05 +0000 (-0500) Subject: Reject a response that should have had PID but did not. X-Git-Tag: 5.0.2~273^2~35 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=fe38d0d4925be0e0182ec5b511b8f7fe715ffee5;p=apps%2Fagl-service-can-low-level.git Reject a response that should have had PID but did not. --- diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c index 1c3d7bc3..c000aa3e 100644 --- a/src/obd2/obd2.c +++ b/src/obd2/obd2.c @@ -161,7 +161,8 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle, response->payload_length); } - if(!has_pid || response->pid == handle->request.pid) { + if((handle->request.pid_length == 0 && !has_pid) + || response->pid == handle->request.pid) { response->success = true; response->completed = true; } else { diff --git a/tests/test_core.c b/tests/test_core.c index 9f979232..be4d1412 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -144,6 +144,21 @@ START_TEST (test_wrong_mode_response) } END_TEST +START_TEST (test_missing_pid) +{ + uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID; + DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS, + DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler); + + fail_if(last_response_was_received); + const uint8_t can_data[] = {0x1, 0x22 + 0x40}; + diagnostic_receive_can_frame(&SHIMS, &handle, arb_id + 0x8, can_data, + sizeof(can_data)); + fail_if(last_response_was_received); + fail_if(handle.completed); +} +END_TEST + START_TEST (test_wrong_pid_response) { uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID; @@ -253,6 +268,7 @@ Suite* testSuite(void) { tcase_add_test(tc_core, test_request_pid_enhanced); tcase_add_test(tc_core, test_wrong_mode_response); tcase_add_test(tc_core, test_wrong_pid_response); + tcase_add_test(tc_core, test_missing_pid); tcase_add_test(tc_core, test_wrong_pid_then_right_completes); tcase_add_test(tc_core, test_handle_completed); tcase_add_test(tc_core, test_negative_response);