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 - for most multi-frame use cases, 256 bytes is plenty.
13 #define OUR_MAX_ISO_TP_MESSAGE_SIZE 127
15 /* Private: IsoTp nibble specifics for PCI and Payload.
17 #define PCI_NIBBLE_INDEX 0
18 #define PAYLOAD_LENGTH_NIBBLE_INDEX 1
19 #define PAYLOAD_BYTE_INDEX 1
21 /* Private: The default timeout to use when waiting for a response during a
22 * multi-frame send or receive.
24 #define ISO_TP_DEFAULT_RESPONSE_TIMEOUT 100
26 /* Private: Determines if by default, padding is added to ISO-TP message frames.
28 #define ISO_TP_DEFAULT_FRAME_PADDING_STATUS true
34 /* Public: A container for a sent or received ISO-TP message.
36 * completed - An IsoTpMessage is the return value from a few functions - this
37 * attribute will be true if the message is actually completely received.
38 * If the function returns but is only partially through receiving the
39 * message, this will be false, the multi_frame attribute will be true,
40 * and you should not consider the other data to be valid.
41 * multi_frame - Designates the message is being built with multi-frame.
42 * arbitration_id - The arbitration ID of the message.
43 * payload - The optional payload of the message - don't forget to check the
45 * size - The size of the payload. The size will be 0 if there is no payload.
48 const uint32_t arbitration_id;
49 uint8_t payload[OUR_MAX_ISO_TP_MESSAGE_SIZE];
55 /* Public: The type signature for an optional logging function, if the user
56 * wishes to provide one. It should print, store or otherwise display the
59 * message - A format string to log using the given parameters.
60 * ... (vargs) - the parameters for the format string.
62 typedef void (*LogShim)(const char* message, ...);
63 /* Public: The type signature for a function to send a single CAN message.
65 * arbitration_id - The arbitration ID of the message.
66 * data - The data payload for the message. NULL is valid if size is also 0.
67 * size - The size of the data payload, in bytes.
69 * Returns true if the CAN message was sent successfully.
71 typedef bool (*SendCanMessageShim)(const uint32_t arbitration_id,
72 const uint8_t* data, const uint8_t size);
74 /* Public: The type signature for a... TODO, not used yet.
76 typedef bool (*SetTimerShim)(uint16_t time_ms, void (*callback));
78 /* Public: The signature for a function to be called when an ISO-TP message has
79 * been completely received.
81 * message - The received message.
83 typedef void (*IsoTpMessageReceivedHandler)(const IsoTpMessage* message);
85 /* Public: the signature for a function to be called when an ISO-TP message has
86 * been completely sent, or had a fatal error during sending.
88 * message - The sent message.
89 * success - True if the message was sent successfully.
91 typedef void (*IsoTpMessageSentHandler)(const IsoTpMessage* message,
94 /* Public: The signature for a function to be called when a CAN frame has been
95 * sent as as part of sending or receive an ISO-TP message.
97 * This is really only useful for debugging the library itself.
99 * message - The ISO-TP message that generated this CAN frame.
101 typedef void (*IsoTpCanFrameSentHandler)(const IsoTpMessage* message);
103 /* Public: A container for the 3 shim functions used by the library to interact
104 * with the wider system.
106 * Use the isotp_init_shims(...) function to create an instance of this struct.
108 * By default, all CAN frames sent from this device in the process of an ISO-TP
109 * message are padded out to a complete 8 byte frame. This is often required by
110 * ECUs. To disable this feature, change the 'frame_padding' field to false on
111 * the IsoTpShims object returned from isotp_init_shims(...).
113 * frame_padding - true if outgoing CAN frames should be padded to a full 8
118 SendCanMessageShim send_can_message;
119 SetTimerShim set_timer;
123 /* Private: PCI types, for identifying each frame of an ISO-TP message.
127 PCI_FIRST_FRAME = 0x1,
128 PCI_CONSECUTIVE_FRAME = 0x2,
129 PCI_FLOW_CONTROL_FRAME = 0x3
130 } IsoTpProtocolControlInformation;
132 /* Private: PCI flow control identifiers.
135 PCI_FLOW_STATUS_CONTINUE = 0x0,
136 PCI_FLOW_STATUS_WAIT = 0x1,
137 PCI_FLOW_STATUS_OVERFLOW = 0x2
144 #endif // __ISOTP_TYPES__