16 volatile uint32_t
h, t;
31static uint8_t
s_acc[4 + 255 + 2];
61 for (uint32_t k = 0; k <
n; ++k) {
87 if (
s_acc[j] == 0xA5u && (j + 1u >=
s_na ||
s_acc[j + 1u] == 0x5Au))
break;
97 if (
s_na < 4u)
return 0;
98 const uint32_t len =
s_acc[3];
99 if (
s_na < len + 6u)
return 0;
112 const uint32_t len =
s_acc[3];
113 const uint8_t type =
s_acc[2];
127 if (
s_na == 0u &&
b != 0xA5u)
continue;
128 if (
s_na == 1u &&
b != 0x5Au) {
s_na = (
b == 0xA5u) ? 1u : 0u;
continue; }
147 const uint32_t h = r->
h;
148 for (uint32_t k = 0; k <
n; ++k) r->
b[(h + k) %
USBL_TX_SIZE] = f[k];
154int usbl_send_src(uint8_t src, uint8_t type,
const void *payload, uint8_t len)
156 uint8_t f[4 + 255 + 2];
157 const size_t n =
pv2_frame(type, payload, len, f,
sizeof f);
181 for (uint32_t k = 0; k <
n; ++k) buf[k] = r->
b[(r->
t + k) %
USBL_TX_SIZE];
static void cmd(uint8_t port, const uint8_t *c, uint32_t n, uint8_t armed, uint32_t now)
size_t pv2_frame(uint8_t type, const void *payload, uint8_t len, uint8_t *out, size_t cap)
ACwing Pilot app protocol v2: identifiers and frame layouts.
#define PV2_FT_CMD
PC -> drone: payload = op, seq, args (as a BLE CMD write)
Lock-free single-producer single-consumer queue of fixed-size items.
uint16_t tlm_crc16(const uint8_t *data, size_t len)
Telemetry packet format (shared with 02 - Tools/00 - Matlab/Telemetry/parseTelemetry....
uint32_t usbl_poll(uint8_t *cmd, uint32_t cap, uint32_t now)
next CMD frame payload; returns its length (>= 2), 0 if none.
static int rx_byte(uint8_t *b)
uint8_t usbl_open(uint32_t now)
a program has the port open: host and (DTR or a command in the last USBL_OPEN_MS)
static volatile uint32_t s_rx_h
static int frame_ready(void)
void usbl_tx_consume(uint32_t n)
static uint8_t s_acc[4+255+2]
static volatile uint32_t s_cmd_ms
static volatile uint8_t s_dtr
void usbl_rx_isr(const uint8_t *p, uint32_t n)
bytes that do not fit are dropped
void usbl_set_dtr(uint8_t on)
static uint32_t s_cur_left
static volatile uint32_t s_rx_t
int usbl_put_frame(uint8_t src, const uint8_t *f, uint32_t n)
a frame already encoded; 0 = queued whole
void usbl_tx_flush(void)
nobody listening: empties every ring
uint32_t usbl_tx_dropped(uint8_t src)
frames that did not fit
void usbl_set_configured(uint8_t on)
host state: configured by a host, DTR set (any context, single writer each)
int usbl_send_src(uint8_t src, uint8_t type, const void *payload, uint8_t len)
a whole v2 frame built from type and payload; 0 = queued whole
uint32_t usbl_rx_errors(void)
frames with a bad CRC
static volatile uint8_t s_ever
static volatile uint8_t s_cfgd
uint32_t usbl_tx_free_src(uint8_t src)
static ring_t s_tx[USBL_SRC_COUNT]
static uint8_t s_rx[USBL_RX_SIZE]
uint32_t usbl_tx_peek(uint8_t *buf, uint32_t cap)
uint8_t usbl_host(void)
a USB host has configured the device (cable to a PC): ARM is refused
Byte-stream link over USB CDC: protocol v2 frames in both directions (A5 5A | TYPE | LEN | PAYLOAD | ...
#define USBL_TX_SIZE
per producer
#define USBL_OPEN_MS
without DTR, the link stays open this long after a command