diff options
m--------- | deps/isotp-c | 12 | ||||
-rw-r--r-- | src/uds/uds.c | 3 | ||||
-rw-r--r-- | src/uds/uds_types.h | 5 | ||||
-rw-r--r-- | tests/test_core.c | 68 |
4 files changed, 76 insertions, 12 deletions
diff --git a/deps/isotp-c b/deps/isotp-c -Subproject 513d8c8d7089960618a1fa00a71442dc3929458 +Subproject c01a88ba1e56d455c7187a52a5e244500a0d6b0 diff --git a/src/uds/uds.c b/src/uds/uds.c index f38c6aac..9fec9a88 100644 --- a/src/uds/uds.c +++ b/src/uds/uds.c @@ -87,6 +87,7 @@ DiagnosticRequestHandle diagnostic_request(DiagnosticShims* shims, handle.isotp_shims = isotp_init_shims(shims->log, shims->send_can_message, shims->set_timer); + handle.isotp_shims.frame_padding = !request->no_frame_padding; handle.isotp_send_handle = isotp_send(&handle.isotp_shims, request->arbitration_id, payload, @@ -121,7 +122,7 @@ DiagnosticRequestHandle diagnostic_request(DiagnosticShims* shims, // that are just called continuously from the main loop. it's a waste of a // few cpu cycles but it may be more natural than callbacks. // - // what woudl a timer callback look like...it would need to pass the handle + // what would a timer callback look like...it would need to pass the handle // and that's all. seems like a context void* would be able to capture all // of the information but arg, memory allocation. look at how it's done in // the other library again diff --git a/src/uds/uds_types.h b/src/uds/uds_types.h index 88c7ce44..10d15d62 100644 --- a/src/uds/uds_types.h +++ b/src/uds/uds_types.h @@ -42,6 +42,10 @@ typedef enum { * payload - (optional) The payload for the request, if the request requires * one. If payload_length is 0 this field is ignored. * payload_length - The length of the payload, or 0 if no payload is used. + * no_frame_padding - false if sent CAN payloads should *not* be padded out to a + * full 8 byte CAN frame. Many ECUs require this, but others require the + * size of the CAN message to only be the actual data. By default padding + * is enabled (so this struct value can default to 0). * type - the type of the request (TODO unused) */ typedef struct { @@ -52,6 +56,7 @@ typedef struct { uint8_t pid_length; uint8_t payload[MAX_UDS_PAYLOAD_LENGTH]; uint8_t payload_length; + bool no_frame_padding; DiagnosticRequestType type; } DiagnosticRequest; diff --git a/tests/test_core.c b/tests/test_core.c index 9f118fc2..815954b1 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -40,7 +40,8 @@ START_TEST (test_send_diag_request_with_payload) arbitration_id: 0x100, mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST, payload: {0x12, 0x34}, - payload_length: 2 + payload_length: 2, + no_frame_padding: true }; DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, response_received_handler); @@ -60,7 +61,8 @@ START_TEST (test_send_functional_request) { DiagnosticRequest request = { arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID, - mode: OBD2_MODE_EMISSIONS_DTC_REQUEST + mode: OBD2_MODE_EMISSIONS_DTC_REQUEST, + no_frame_padding: true }; DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, response_received_handler); @@ -91,7 +93,23 @@ START_TEST (test_send_functional_request) } END_TEST -START_TEST (test_send_diag_request) +START_TEST (test_sent_message_no_padding) +{ + DiagnosticRequest request = { + arbitration_id: 0x100, + mode: OBD2_MODE_EMISSIONS_DTC_REQUEST, + no_frame_padding: true + }; + DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, + response_received_handler); + + fail_if(handle.completed); + ck_assert_int_eq(last_can_frame_sent_arb_id, request.arbitration_id); + ck_assert_int_eq(last_can_payload_size, 2); +} +END_TEST + +START_TEST (test_sent_message_is_padded_by_default) { DiagnosticRequest request = { arbitration_id: 0x100, @@ -102,6 +120,38 @@ START_TEST (test_send_diag_request) fail_if(handle.completed); ck_assert_int_eq(last_can_frame_sent_arb_id, request.arbitration_id); + ck_assert_int_eq(last_can_payload_size, 8); +} +END_TEST + +START_TEST (test_sent_message_is_padded) +{ + DiagnosticRequest request = { + arbitration_id: 0x100, + mode: OBD2_MODE_EMISSIONS_DTC_REQUEST, + no_frame_padding: false + }; + DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, + response_received_handler); + + fail_if(handle.completed); + ck_assert_int_eq(last_can_frame_sent_arb_id, request.arbitration_id); + ck_assert_int_eq(last_can_payload_size, 8); +} +END_TEST + +START_TEST (test_send_diag_request) +{ + DiagnosticRequest request = { + arbitration_id: 0x100, + mode: OBD2_MODE_EMISSIONS_DTC_REQUEST, + no_frame_padding: true + }; + DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, + response_received_handler); + + fail_if(handle.completed); + ck_assert_int_eq(last_can_frame_sent_arb_id, request.arbitration_id); ck_assert_int_eq(last_can_payload_sent[1], request.mode); ck_assert_int_eq(last_can_payload_size, 2); @@ -131,19 +181,22 @@ START_TEST (test_autoset_pid_length) ck_assert_int_eq(last_can_frame_sent_arb_id, arb_id); ck_assert_int_eq(last_can_payload_sent[1], 0x1); ck_assert_int_eq(last_can_payload_sent[2], 0x2); - ck_assert_int_eq(last_can_payload_size, 3); + // padding is on for the diagnostic_request_pid helper function - if you + // need to turn it off, use the more manual diagnostic_request(...) + ck_assert_int_eq(last_can_payload_size, 8); DiagnosticRequest request = { arbitration_id: 0x100, mode: 0x22, has_pid: true, - pid: 2 + pid: 2, + no_frame_padding: true }; diagnostic_request(&SHIMS, &request, response_received_handler); ck_assert_int_eq(last_can_frame_sent_arb_id, request.arbitration_id); ck_assert_int_eq(last_can_payload_sent[1], request.mode); -ck_assert_int_eq(last_can_payload_size, 4); + ck_assert_int_eq(last_can_payload_size, 4); } END_TEST @@ -303,6 +356,9 @@ Suite* testSuite(void) { Suite* s = suite_create("uds"); TCase *tc_core = tcase_create("core"); tcase_add_checked_fixture(tc_core, setup, NULL); + tcase_add_test(tc_core, test_sent_message_no_padding); + tcase_add_test(tc_core, test_sent_message_is_padded); + tcase_add_test(tc_core, test_sent_message_is_padded_by_default); tcase_add_test(tc_core, test_send_diag_request); tcase_add_test(tc_core, test_send_functional_request); tcase_add_test(tc_core, test_send_diag_request_with_payload); |