X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fisotp%2Fsend.h;h=1af326688783a376538f2c7e7427d4743a6fc847;hb=ee24440b7c123ab1b0317e57be33e837a1cb51f1;hp=8f707b29f4de82996c95ae781418b2f277f23800;hpb=482c7eafcb35a4031ab6f2241b14ac495735b7cd;p=apps%2Flow-level-can-service.git diff --git a/src/isotp/send.h b/src/isotp/send.h index 8f707b2..1af3266 100644 --- a/src/isotp/send.h +++ b/src/isotp/send.h @@ -9,6 +9,75 @@ extern "C" { #endif +/* Public: A handle for beginning and continuing sending a single ISO-TP + * message - both single and multi-frame. + * + * Since an ISO-TP message may contain multiple frames, we need to keep a handle + * around while waiting for flow control messages from the receiver. + * This struct encapsulates the local state required. + * + * completed - True if the message was completely sent, or the send was + * otherwise cancelled. + * success - True if the message send request was successful. The value if this + * field isn't valid if 'completed' isn't true. + */ +typedef struct { + bool completed; + bool success; + + // Private + uint16_t sending_arbitration_id; + uint16_t receiving_arbitration_id; + IsoTpMessageSentHandler message_sent_callback; + IsoTpCanFrameSentHandler can_frame_sent_callback; + // TODO going to need some state here for multi frame messages +} IsoTpSendHandle; + +/* Public: Initiate sending a single ISO-TP message. + * + * If the message fits in a single ISO-TP frame (i.e. the payload isn't more + * than 7 bytes) it will be sent immediately and the returned IsoTpSendHandle's + * 'completed' flag will be true. + * + * For multi-frame messages, see isotp_continue_send(...). + * + * shims - Low-level shims required to send CAN messages, etc. + * arbitration_id - The arbitration ID to send the message on. + * payload - The payload for the message. If no payload, NULL is valid is size + * is also 0. + * size - The size of the payload, or 0 if no payload. + * callback - an optional function to be called when the message is completely + * sent (use NULL if no callback required). + * + * Returns a handle to be used with isotp_continue_send to continue sending + * multi-frame messages. The 'completed' field in the returned IsoTpSendHandle + * will be true when the message is completely sent. + */ +IsoTpSendHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id, + const uint8_t payload[], uint16_t size, + IsoTpMessageSentHandler callback); + +/* Public: Continue to send a multi-frame ISO-TP message, based on a freshly + * received CAN message (potentially from the receiver about flow control). + * + * For a multi-frame ISO-TP message, this function must be called + * repeatedly whenever a new CAN message is received in order to complete the + * send. The sender can't just blast everything onto the bus at once - it must + * wait for some response from the receiver to know how much to send at once. + * + * shims - Low-level shims required to send CAN messages, etc. + * handle - An IsoTpSendHandle previously returned by isotp_send(...). + * arbitration_id - The arbitration_id of the received CAN message. + * data - The data of the received CAN message. + * size - The size of the data in the received CAN message. + * + * Returns true if the message was completely sent, or the send was + * otherwise cancelled. Check the 'success' field of the handle to see if + * it was successful. + */ +bool isotp_continue_send(IsoTpShims* shims, IsoTpSendHandle* handle, + const uint16_t arbitration_id, const uint8_t data[], + const uint8_t size); #ifdef __cplusplus }