diff options
-rw-r--r-- | src/isotp/isotp.c | 3 | ||||
-rw-r--r-- | src/isotp/isotp_types.h | 9 | ||||
-rw-r--r-- | src/isotp/receive.h | 2 | ||||
-rw-r--r-- | src/isotp/send.c | 2 | ||||
-rw-r--r-- | tests/test_core.c | 78 | ||||
-rw-r--r-- | tests/test_send.c | 2 |
6 files changed, 92 insertions, 4 deletions
diff --git a/src/isotp/isotp.c b/src/isotp/isotp.c index f115810e..ad693416 100644 --- a/src/isotp/isotp.c +++ b/src/isotp/isotp.c @@ -10,7 +10,8 @@ IsoTpShims isotp_init_shims(LogShim log, SendCanMessageShim send_can_message, IsoTpShims shims = { log: log, send_can_message: send_can_message, - set_timer: set_timer + set_timer: set_timer, + frame_padding: ISO_TP_DEFAULT_FRAME_PADDING_STATUS }; return shims; } diff --git a/src/isotp/isotp_types.h b/src/isotp/isotp_types.h index d9fe4601..5a40733f 100644 --- a/src/isotp/isotp_types.h +++ b/src/isotp/isotp_types.h @@ -96,11 +96,20 @@ typedef void (*IsoTpCanFrameSentHandler)(const IsoTpMessage* message); * with the wider system. * * Use the isotp_init_shims(...) function to create an instance of this struct. + * + * By default, all CAN frames sent from this device in the process of an ISO-TP + * message are padded out to a complete 8 byte frame. This is often required by + * ECUs. To disable this feature, change the 'frame_padding' field to false on + * the IsoTpShims object returned from isotp_init_shims(...). + * + * frame_padding - true if outgoing CAN frames should be padded to a full 8 + * bytes. */ typedef struct { LogShim log; SendCanMessageShim send_can_message; SetTimerShim set_timer; + bool frame_padding; } IsoTpShims; /* Private: PCI types, for identifying each frame of an ISO-TP message. diff --git a/src/isotp/receive.h b/src/isotp/receive.h index e7e56d61..1dfd6f6d 100644 --- a/src/isotp/receive.h +++ b/src/isotp/receive.h @@ -29,8 +29,6 @@ typedef struct { IsoTpMessageReceivedHandler message_received_callback; uint16_t timeout_ms; // timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT, - bool frame_padding; - // frame_padding: ISO_TP_DEFAULT_FRAME_PADDING_STATUS, uint8_t* receive_buffer; uint16_t received_buffer_size; uint16_t incoming_message_size; diff --git a/src/isotp/send.c b/src/isotp/send.c index 798fab83..e849bb2c 100644 --- a/src/isotp/send.c +++ b/src/isotp/send.c @@ -37,7 +37,7 @@ IsoTpSendHandle isotp_send_single_frame(IsoTpShims* shims, IsoTpMessage* message } shims->send_can_message(message->arbitration_id, can_data, - 1 + message->size); + shims->frame_padding ? 8 : 1 + message->size); handle.success = true; isotp_complete_send(shims, message, true, callback); return handle; diff --git a/tests/test_core.c b/tests/test_core.c new file mode 100644 index 00000000..78e13e8d --- /dev/null +++ b/tests/test_core.c @@ -0,0 +1,78 @@ +#include <isotp/receive.h> +#include <check.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +extern IsoTpShims SHIMS; + +extern void message_sent(const IsoTpMessage* message, const bool success); + +extern uint16_t last_can_frame_sent_arb_id; +extern uint8_t last_can_payload_sent[8]; +extern uint8_t last_can_payload_size; +extern bool can_frame_was_sent; + +extern bool message_was_received; +extern uint16_t last_message_received_arb_id; +extern uint8_t last_message_received_payload[]; +extern uint8_t last_message_received_payload_size; + +extern uint16_t last_message_sent_arb_id; +extern bool last_message_sent_status; +extern uint8_t last_message_sent_payload[]; +extern uint8_t last_message_sent_payload_size; + +extern void setup(); + +START_TEST (test_default_frame_padding_on) +{ + ck_assert(SHIMS.frame_padding); + const uint8_t payload[] = {0x12, 0x34}; + uint16_t arbitration_id = 0x2a; + isotp_send(&SHIMS, arbitration_id, payload, sizeof(payload), message_sent); + ck_assert_int_eq(last_message_sent_arb_id, arbitration_id); + fail_unless(last_message_sent_status); + ck_assert_int_eq(last_message_sent_payload_size, 2); + ck_assert_int_eq(last_can_payload_size, 8); + +} +END_TEST + +START_TEST (test_disabled_frame_padding) +{ + SHIMS.frame_padding = false; + const uint8_t payload[] = {0x12, 0x34}; + uint16_t arbitration_id = 0x2a; + isotp_send(&SHIMS, arbitration_id, payload, sizeof(payload), message_sent); + ck_assert_int_eq(last_message_sent_arb_id, arbitration_id); + fail_unless(last_message_sent_status); + ck_assert_int_eq(last_message_sent_payload_size, 2); + ck_assert_int_eq(last_can_payload_size, 3); + +} +END_TEST + +Suite* testSuite(void) { + Suite* s = suite_create("iso15765"); + TCase *tc_core = tcase_create("core"); + tcase_add_checked_fixture(tc_core, setup, NULL); + tcase_add_test(tc_core, test_default_frame_padding_on); + tcase_add_test(tc_core, test_disabled_frame_padding); + suite_add_tcase(s, tc_core); + + return s; +} + +int main(void) { + int numberFailed; + Suite* s = testSuite(); + SRunner *sr = srunner_create(s); + // Don't fork so we can actually use gdb + srunner_set_fork_status(sr, CK_NOFORK); + srunner_run_all(sr, CK_NORMAL); + numberFailed = srunner_ntests_failed(sr); + srunner_free(sr); + return (numberFailed == 0) ? 0 : 1; +} diff --git a/tests/test_send.c b/tests/test_send.c index 3a18ff30..29cf5dec 100644 --- a/tests/test_send.c +++ b/tests/test_send.c @@ -28,6 +28,7 @@ extern void setup(); START_TEST (test_send_empty_payload) { + SHIMS.frame_padding = false; uint16_t arbitration_id = 0x2a; IsoTpSendHandle handle = isotp_send(&SHIMS, arbitration_id, NULL, 0, message_sent); fail_unless(handle.success); @@ -46,6 +47,7 @@ END_TEST START_TEST (test_send_single_frame) { + SHIMS.frame_padding = false; const uint8_t payload[] = {0x12, 0x34}; uint16_t arbitration_id = 0x2a; isotp_send(&SHIMS, arbitration_id, payload, sizeof(payload), message_sent); |