1 #ifndef __ISOTP_SEND_H__
2 #define __ISOTP_SEND_H__
4 #include <isotp/isotp.h>
12 /* Public: A handle for beginning and continuing sending a single ISO-TP
13 * message - both single and multi-frame.
15 * Since an ISO-TP message may contain multiple frames, we need to keep a handle
16 * around while waiting for flow control messages from the receiver.
17 * This struct encapsulates the local state required.
19 * completed - True if the message was completely sent, or the send was
20 * otherwise cancelled.
21 * success - True if the message send request was successful. The value if this
22 * field isn't valid if 'completed' isn't true.
29 uint16_t sending_arbitration_id;
30 uint16_t receiving_arbitration_id;
31 IsoTpMessageSentHandler message_sent_callback;
32 IsoTpCanFrameSentHandler can_frame_sent_callback;
33 // TODO going to need some state here for multi frame messages
36 /* Public: Initiate sending a single ISO-TP message.
38 * If the message fits in a single ISO-TP frame (i.e. the payload isn't more
39 * than 7 bytes) it will be sent immediately and the returned IsoTpSendHandle's
40 * 'completed' flag will be true.
42 * For multi-frame messages, see isotp_continue_send(...).
44 * shims - Low-level shims required to send CAN messages, etc.
45 * arbitration_id - The arbitration ID to send the message on.
46 * payload - The payload for the message. If no payload, NULL is valid is size
48 * size - The size of the payload, or 0 if no payload.
49 * callback - an optional function to be called when the message is completely
50 * sent (use NULL if no callback required).
52 * Returns a handle to be used with isotp_continue_send to continue sending
53 * multi-frame messages. The 'completed' field in the returned IsoTpSendHandle
54 * will be true when the message is completely sent.
56 IsoTpSendHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id,
57 const uint8_t payload[], uint16_t size,
58 IsoTpMessageSentHandler callback);
60 /* Public: Continue to send a multi-frame ISO-TP message, based on a freshly
61 * received CAN message (potentially from the receiver about flow control).
63 * For a multi-frame ISO-TP message, this function must be called
64 * repeatedly whenever a new CAN message is received in order to complete the
65 * send. The sender can't just blast everything onto the bus at once - it must
66 * wait for some response from the receiver to know how much to send at once.
68 * shims - Low-level shims required to send CAN messages, etc.
69 * handle - An IsoTpSendHandle previously returned by isotp_send(...).
70 * arbitration_id - The arbitration_id of the received CAN message.
71 * data - The data of the received CAN message.
72 * size - The size of the data in the received CAN message.
74 * Returns true if the message was completely sent, or the send was
75 * otherwise cancelled. Check the 'success' field of the handle to see if
78 bool isotp_continue_send(IsoTpShims* shims, IsoTpSendHandle* handle,
79 const uint16_t arbitration_id, const uint8_t data[],
86 #endif // __ISOTP_SEND_H__