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 uint32_t arbitration_id;
29 IsoTpMessageReceivedHandler message_received_callback;
31 // timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT,
32 uint8_t* receive_buffer;
33 uint16_t received_buffer_size;
34 uint16_t incoming_message_size;
35 // TODO timer callback for multi frame
38 /* Public: Initiate receiving a single ISO-TP message on a particular
41 * Note that no actual CAN data has been received at this point - this just sets
42 * up a handle to be used when new CAN messages to arrive, so they can be parsed
43 * as potential single or multi-frame ISO-TP messages.
45 * shims - Low-level shims required to send and receive CAN messages, etc.
46 * arbitration_id - The arbitration ID to receive the message on.
47 * callback - an optional function to be called when the message is completely
48 * received (use NULL if no callback required).
50 * Returns a handle to be used with isotp_continue_receive when a new CAN frame
51 * arrives. The 'completed' field in the returned IsoTpReceiveHandle will be true
52 * when the message is completely sent.
54 IsoTpReceiveHandle isotp_receive(IsoTpShims* shims,
55 const uint32_t arbitration_id, IsoTpMessageReceivedHandler callback);
57 /* Public: Continue to receive a an ISO-TP message, based on a freshly
58 * received CAN message.
60 * For a multi-frame ISO-TP message, this function must be called
61 * repeatedly whenever a new CAN message is received in order to complete
64 * TODO does this API work for if we wanted to receive an ISO-TP message and
65 * send our own flow control messages back?
67 * shims - Low-level shims required to send and receive CAN messages, etc.
68 * handle - An IsoTpReceiveHandle previously returned by isotp_receive(...).
69 * arbitration_id - The arbitration_id of the received CAN message.
70 * data - The data of the received CAN message.
71 * size - The size of the data in the received CAN message.
73 * Returns an IsoTpMessage with the 'completed' field set to true if a message
74 * was completely received. If 'completed' is false, more CAN frames are
75 * required to complete the messages, or the arbitration ID didn't match this
76 * handle. Keep passing the same handle to this function when CAN frames arrive.
78 IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
79 IsoTpReceiveHandle* handle, const uint32_t arbitration_id,
80 const uint8_t data[], const uint8_t size);
86 #endif // __ISOTP_RECEIVE_H__