1 #ifndef __ISOTP_TYPES__
2 #define __ISOTP_TYPES__
8 #define CAN_MESSAGE_BYTE_SIZE 8
9 #define MAX_ISO_TP_MESSAGE_SIZE 4096
10 // TODO we want to avoid malloc, and we can't be allocated 4K on the stack for
11 // each IsoTpMessage, so for now we're setting an artificial max message size
12 // here - since we only handle single frame messages, 8 bytes is plenty.
13 #define OUR_MAX_ISO_TP_MESSAGE_SIZE 8
15 /* Private: The default timeout to use when waiting for a response during a
16 * multi-frame send or receive.
18 #define ISO_TP_DEFAULT_RESPONSE_TIMEOUT 100
20 /* Private: Determines if by default, padding is added to ISO-TP message frames.
22 #define ISO_TP_DEFAULT_FRAME_PADDING_STATUS true
28 /* Public: A container for a sent or received ISO-TP message.
30 * completed - An IsoTpMessage is the return value from a few functions - this
31 * attribute will be true if the message is actually completely received.
32 * If the function returns but is only partially through receiving the
33 * message, this will be false and you should not consider the other data
35 * arbitration_id - The arbitration ID of the message.
36 * payload - The optional payload of the message - don't forget to check the
38 * size - The size of the payload. The size will be 0 if there is no payload.
41 const uint16_t arbitration_id;
42 uint8_t payload[OUR_MAX_ISO_TP_MESSAGE_SIZE];
47 /* Public: The type signature for an optional logging function, if the user
48 * wishes to provide one. It should print, store or otherwise display the
51 * message - A format string to log using the given parameters.
52 * ... (vargs) - the parameters for the format string.
54 typedef void (*LogShim)(const char* message, ...);
55 /* Public: The type signature for a function to send a single CAN message.
57 * arbitration_id - The arbitration ID of the message.
58 * data - The data payload for the message. NULL is valid if size is also 0.
59 * size - The size of the data payload, in bytes.
61 * Returns true if the CAN message was sent successfully.
63 typedef bool (*SendCanMessageShim)(const uint16_t arbitration_id,
64 const uint8_t* data, const uint8_t size);
66 /* Public: The type signature for a... TODO, not used yet.
68 typedef bool (*SetTimerShim)(uint16_t time_ms, void (*callback));
70 /* Public: The signature for a function to be called when an ISO-TP message has
71 * been completely received.
73 * message - The received message.
75 typedef void (*IsoTpMessageReceivedHandler)(const IsoTpMessage* message);
77 /* Public: the signature for a function to be called when an ISO-TP message has
78 * been completely sent, or had a fatal error during sending.
80 * message - The sent message.
81 * success - True if the message was sent successfully.
83 typedef void (*IsoTpMessageSentHandler)(const IsoTpMessage* message,
86 /* Public: The signature for a function to be called when a CAN frame has been
87 * sent as as part of sending or receive an ISO-TP message.
89 * This is really only useful for debugging the library itself.
91 * message - The ISO-TP message that generated this CAN frame.
93 typedef void (*IsoTpCanFrameSentHandler)(const IsoTpMessage* message);
95 /* Public: A container for the 3 shim functions used by the library to interact
96 * with the wider system.
98 * Use the isotp_init_shims(...) function to create an instance of this struct.
102 SendCanMessageShim send_can_message;
103 SetTimerShim set_timer;
106 /* Private: PCI types, for identifying each frame of an ISO-TP message.
110 PCI_FIRST_FRAME = 0x1,
111 PCI_CONSECUTIVE_FRAME = 0x2,
112 PCI_FLOW_CONTROL_FRAME = 0x3
113 } IsoTpProtocolControlInformation;
115 /* Private: PCI flow control identifiers.
118 PCI_FLOW_STATUS_CONTINUE = 0x0,
119 PCI_FLOW_STATUS_WAIT = 0x1,
120 PCI_FLOW_STATUS_OVERFLOW = 0x2
127 #endif // __ISOTP_TYPES__