1 #include <isotp/isotp.h>
2 #include <isotp/receive.h>
3 #include <bitfield/bitfield.h>
5 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT = 100;
6 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS = true;
8 /* void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms) { */
9 /* handler->timeout_ms = timeout_ms; */
12 IsoTpShims isotp_init_shims(LogShim log, SendCanMessageShim send_can_message,
13 SetTimerShim set_timer) {
16 send_can_message: send_can_message,
22 void isotp_message_to_string(const IsoTpMessage* message, char* destination,
23 size_t destination_length) {
24 snprintf(destination, destination_length, "ID: 0x%02x, Payload: 0x%02x%02x%02x%02x%02x%02x%02x%02x",
25 message->arbitration_id,
36 IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
37 IsoTpReceiveHandle* handle, const uint16_t arbitration_id,
38 const uint8_t data[], const uint8_t size) {
39 IsoTpMessage message = {
40 arbitration_id: arbitration_id,
50 if(handle->arbitration_id != arbitration_id) {
51 if(shims->log != NULL) {
52 shims->log("The arb ID 0x%x doesn't match the expected rx ID 0x%x",
53 arbitration_id, handle->arbitration_id);
58 IsoTpProtocolControlInformation pci = (IsoTpProtocolControlInformation)
59 get_nibble(data, size, 0);
61 uint8_t payload_length = get_nibble(data, size, 1);
62 uint8_t payload[payload_length];
63 if(payload_length > 0 && size > 0) {
64 memcpy(payload, &data[1], payload_length);
67 // TODO this is set up to handle rx a response with a payload, but not to
68 // handle flow control responses for multi frame messages that we're in the
73 if(payload_length > 0) {
74 memcpy(message.payload, payload, payload_length);
76 message.size = payload_length;
77 message.completed = true;
78 handle->success = true;
79 handle->completed = true;
80 isotp_handle_single_frame(handle, &message);
84 shims->log("Only single frame messages are supported");
90 bool isotp_continue_send(IsoTpShims* shims, IsoTpSendHandle* handle,
91 const uint16_t arbitration_id, const uint8_t data[],
93 // TODO this will need to be tested when we add multi-frame support,
94 // which is when it'll be necessary to pass in CAN messages to SENDING
96 if(handle->receiving_arbitration_id != arbitration_id) {
97 if(shims->log != NULL) {
98 shims->log("The arb ID 0x%x doesn't match the expected tx continuation ID 0x%x",
99 arbitration_id, handle->receiving_arbitration_id);