11 const uint16_t MAX_ISO_TP_MESSAGE_SIZE;
12 const uint16_t MAX_CAN_FRAME_SIZE;
13 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT;
14 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS;
16 typedef void (*LogShim)(const char* message);
17 typedef bool (*SendCanMessageShim)(const uint16_t arbitration_id, const uint8_t* data,
19 typedef bool (*SetTimerShim)(uint16_t time_ms, void (*callback));
21 typedef void (*IsoTpMessageReceivedHandler)(const uint16_t arbitration_id,
22 const uint8_t* payload, const uint16_t size);
23 typedef void (*IsoTpMessageSentHandler)(const bool success,
24 const uint16_t arbitration_id, const uint8_t* payload,
26 typedef void (*IsoTpCanFrameSentHandler)(const uint16_t arbitration_id,
27 const uint8_t* payload, const uint8_t size);
29 // TODO this is really necessary and it would leak this library into the user's
32 // const uint16_t arbitration_id;
33 // const uint8_t* payload;
34 // const uint16_t size;
39 SendCanMessageShim send_can_message;
40 SetTimerShim set_timer;
45 uint16_t arbitration_id;
46 IsoTpMessageReceivedHandler message_received_callback;
47 IsoTpMessageSentHandler message_sent_callback;
48 IsoTpCanFrameSentHandler can_frame_sent_callback;
53 uint8_t* receive_buffer;
54 uint16_t received_buffer_size;
55 uint16_t incoming_message_size;
57 // TODO timer callback
62 PCI_FIRST_FRAME = 0x1,
63 PCI_CONSECUTIVE_FRAME = 0x2,
64 PCI_FLOW_CONTROL_FRAME = 0x3
65 } IsoTpProtocolControlInformation;
68 PCI_FLOW_STATUS_CONTINUE = 0x0,
69 PCI_FLOW_STATUS_WAIT = 0x1,
70 PCI_FLOW_STATUS_OVERFLOW = 0x2
73 IsoTpShims isotp_init_shims(LogShim log,
74 SendCanMessageShim send_can_message,
75 SetTimerShim set_timer);
77 IsoTpHandler isotp_init(IsoTpShims* shims,
78 uint16_t arbitration_id,
79 IsoTpMessageReceivedHandler message_received_callback,
80 IsoTpMessageSentHandler message_sent_callback,
81 IsoTpCanFrameSentHandler can_frame_sent_callback);
83 /* Public: Change the timeout for waiting on an ISO-TP response frame.
85 * If this function is not used, the conventional 100ms is used by default.
87 * handler - the ISO-TP handler to modify.
88 * timeout - the new timeout in milliseconds.
90 void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms);
92 // TODO we have to make sure to copy the payload internall if it's more than 1
93 // frame, the soure could go out of scope
94 bool isotp_send(const uint8_t* payload, uint16_t payload_size);
96 void isotp_receive_can_frame(IsoTpHandler* handler,
97 const uint16_t arbitration_id, const uint8_t* data,
98 const uint8_t length);
100 void isotp_destroy(IsoTpHandler* handler);
102 void log_isotp_message(const uint16_t arbitration_id, const uint8_t* payload,
103 const uint16_t size);
110 #endif // __ISOTP_H__