#define MAX_ISO_TP_MESSAGE_SIZE 4096
// TODO we want to avoid malloc, and we can't be allocated 4K on the stack for
// each IsoTpMessage, so for now we're setting an artificial max message size
-// here - since we only handle single frame messages, 8 bytes is plenty.
-#define OUR_MAX_ISO_TP_MESSAGE_SIZE 8
+// here - for most multi-frame use cases, 256 bytes is plenty.
+#define OUR_MAX_ISO_TP_MESSAGE_SIZE 256
+
+/* Private: IsoTp nibble specifics for PCI and Payload.
+ */
+#define PCI_NIBBLE_INDEX 0
+#define PAYLOAD_LENGTH_NIBBLE_INDEX 1
+#define PAYLOAD_BYTE_INDEX 1
/* Private: The default timeout to use when waiting for a response during a
* multi-frame send or receive.
* completed - An IsoTpMessage is the return value from a few functions - this
* attribute will be true if the message is actually completely received.
* If the function returns but is only partially through receiving the
- * message, this will be false and you should not consider the other data
- * to be valid.
+ * message, this will be false, the multi_frame attribute will be true,
+ * and you should not consider the other data to be valid.
+ * multi_frame - Designates the message is being built with multi-frame.
* arbitration_id - The arbitration ID of the message.
* payload - The optional payload of the message - don't forget to check the
* size!
* size - The size of the payload. The size will be 0 if there is no payload.
*/
typedef struct {
- const uint16_t arbitration_id;
+ const uint32_t arbitration_id;
uint8_t payload[OUR_MAX_ISO_TP_MESSAGE_SIZE];
uint16_t size;
bool completed;
+ bool multi_frame;
} IsoTpMessage;
/* Public: The type signature for an optional logging function, if the user
*
* Returns true if the CAN message was sent successfully.
*/
-typedef bool (*SendCanMessageShim)(const uint16_t arbitration_id,
+typedef bool (*SendCanMessageShim)(const uint32_t arbitration_id,
const uint8_t* data, const uint8_t size);
/* Public: The type signature for a... TODO, not used yet.
* with the wider system.
*
* Use the isotp_init_shims(...) function to create an instance of this struct.
+ *
+ * By default, all CAN frames sent from this device in the process of an ISO-TP
+ * message are padded out to a complete 8 byte frame. This is often required by
+ * ECUs. To disable this feature, change the 'frame_padding' field to false on
+ * the IsoTpShims object returned from isotp_init_shims(...).
+ *
+ * frame_padding - true if outgoing CAN frames should be padded to a full 8
+ * bytes.
*/
typedef struct {
LogShim log;
SendCanMessageShim send_can_message;
SetTimerShim set_timer;
+ bool frame_padding;
} IsoTpShims;
/* Private: PCI types, for identifying each frame of an ISO-TP message.