Files
trikkeSensors/main/trikke_transport.h
T

55 lines
1.5 KiB
C

#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
TRIKKE_TRANSPORT_COMPLETE = 0,
TRIKKE_TRANSPORT_RETRY,
TRIKKE_TRANSPORT_PENDING,
TRIKKE_TRANSPORT_FATAL,
} trikke_transport_status_t;
typedef trikke_transport_status_t (*trikke_transport_begin_fn)(
void *context,
const uint8_t *packet,
size_t packet_size);
typedef trikke_transport_status_t (*trikke_transport_poll_fn)(void *context);
typedef struct {
void *context;
trikke_transport_begin_fn begin;
trikke_transport_poll_fn poll;
} trikke_transport_t;
typedef struct {
bool pending;
uint32_t begin_retry_count;
} trikke_transport_sender_t;
void trikke_transport_sender_init(trikke_transport_sender_t *sender);
// Advances one bounded transport operation. The packet storage must remain valid
// and unchanged from the first PENDING result through COMPLETE. While pending,
// only poll is called: an ambiguous timeout can never duplicate a frame. RETRY
// is valid only from begin, where it guarantees that no bytes were accepted.
//
// COMPLETE is backend-specific. USB uses endpoint drain, which does not prove
// application receipt. A reliable BLE backend must reserve COMPLETE for an
// application acknowledgement covering this exact frame.
trikke_transport_status_t trikke_transport_sender_step(
trikke_transport_sender_t *sender,
const trikke_transport_t *transport,
const uint8_t *packet,
size_t packet_size);
#ifdef __cplusplus
}
#endif