1 #include <isotp/isotp.h>
2 #include <isotp/receive.h>
3 #include <bitfield/bitfield.h>
5 const uint16_t MAX_ISO_TP_MESSAGE_SIZE = 4096;
6 const uint16_t MAX_CAN_FRAME_SIZE = 8;
7 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT = 100;
8 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS = true;
11 void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms) {
12 handler->timeout_ms = timeout_ms;
15 IsoTpShims isotp_init_shims(LogShim log, SendCanMessageShim send_can_message,
16 SetTimerShim set_timer) {
19 send_can_message: send_can_message,
25 IsoTpHandler isotp_init(IsoTpShims* shims, uint16_t arbitration_id,
26 IsoTpMessageReceivedHandler message_received_callback,
27 IsoTpMessageSentHandler message_sent_callback,
28 IsoTpCanFrameSentHandler can_frame_sent_callback) {
29 IsoTpHandler handler = {
31 arbitration_id: arbitration_id,
32 message_received_callback: message_received_callback,
33 message_sent_callback: message_sent_callback,
34 can_frame_sent_callback: can_frame_sent_callback,
35 timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT,
36 frame_padding: ISO_TP_DEFAULT_FRAME_PADDING_STATUS,
42 void isotp_message_to_string(const IsoTpMessage* message, char* destination,
43 size_t destination_length) {
44 snprintf(destination, destination_length,"ID: 0x%02x, Payload: 0x%llx",
45 // TODO the payload may be backwards here
46 message->arbitration_id, message->payload);