1 #ifndef __ISOTP_RECEIVE_H__
2 #define __ISOTP_RECEIVE_H__
4 #include <isotp/isotp.h>
12 /* Public: A handle for beginning and continuing receiving 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 subsequent CAN messages to complete the message.
17 * This struct encapsulates the local state required.
19 * completed - True if the received message request is completely finished.
20 * success - True if the message request was successful. The value if this field
21 * isn't valid if 'completed' isn't true.
28 uint16_t arbitration_id;
29 IsoTpMessageReceivedHandler message_received_callback;
31 // timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT,
33 // frame_padding: ISO_TP_DEFAULT_FRAME_PADDING_STATUS,
34 uint8_t* receive_buffer;
35 uint16_t received_buffer_size;
36 uint16_t incoming_message_size;
37 // TODO timer callback for multi frame
40 /* Public: Initiate receiving a single ISO-TP message on a particular
43 * Note that no actual CAN data has been received at this point - this just sets
44 * up a handle to be used when new CAN messages to arrive, so they can be parsed
45 * as potential single or multi-frame ISO-TP messages.
47 * shims - Low-level shims required to send and receive CAN messages, etc.
48 * arbitration_id - The arbitration ID to receive the message on.
49 * callback - an optional function to be called when the message is completely
50 * received (use NULL if no callback required).
52 * Returns a handle to be used with isotp_continue_receive when a new CAN frame
53 * arrives. The 'completed' field in the returned IsoTpReceiveHandle will be true
54 * when the message is completely sent.
56 IsoTpReceiveHandle isotp_receive(IsoTpShims* shims,
57 const uint16_t arbitration_id, IsoTpMessageReceivedHandler callback);
59 /* Public: Continue to receive a an ISO-TP message, based on a freshly
60 * received CAN message.
62 * For a multi-frame ISO-TP message, this function must be called
63 * repeatedly whenever a new CAN message is received in order to complete
66 * TODO does this API work for if we wanted to receive an ISO-TP message and
67 * send our own flow control messages back?
69 * shims - Low-level shims required to send and receive CAN messages, etc.
70 * handle - An IsoTpReceiveHandle previously returned by isotp_receive(...).
71 * arbitration_id - The arbitration_id of the received CAN message.
72 * data - The data of the received CAN message.
73 * size - The size of the data in the received CAN message.
75 * Returns an IsoTpMessage with the 'completed' field set to true if a message
76 * was completely received. If 'completed' is false, more CAN frames are
77 * required to complete the messages, or the arbitration ID didn't match this
78 * handle. Keep passing the same handle to this function when CAN frames arrive.
80 IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
81 IsoTpReceiveHandle* handle, const uint16_t arbitration_id,
82 const uint8_t data[], const uint8_t size);
88 #endif // __ISOTP_RECEIVE_H__