Mercury Modem
Mercury ARQ/Broadcast modem
Loading...
Searching...
No Matches
carousel.h
Go to the documentation of this file.
1/* datalink_arq/carousel.h -- the carousel data plane: erasure-coded rounds
2 *
3 * One connected session moves data both ways. Per direction the RECEIVER
4 * chooses: what each block still needs, and the next round's mode and size
5 * ("send me up to N frames in mode M"). The receiver chooses the mode because
6 * it is the side whose payload decoder must be bound to it in advance, and the
7 * side that sees what arrives.
8 *
9 * Who keys, and when (docs/CAROUSEL-TURNS.md, proved in specs/turns): the
10 * caller is the session's only timing master (M). It alone keys on timers of
11 * its own, and only where the callee (S) cannot be on the air. S keys only in
12 * slots anchored to the end of an M keydown it decoded. M carries both
13 * directions: it sends its own rounds, which S answers with its poll; and it
14 * polls S for S's rounds, which S sends in its slots.
15 *
16 * Data is cut into blocks of up to CAR_MAX_K pieces of CAR_PIECE bytes,
17 * Reed-Solomon coded (rs_erasure.h): any K pieces rebuild a block, so a poll
18 * says how many pieces a block needs, never which. Pieces fit every mode, so
19 * a block is never re-encoded when the mode changes.
20 *
21 * At the MFSK floor the control mode no longer gets through, so a round is
22 * answered with a pattern instead (car_io_t.pattern): ACK "keep going", BREAK
23 * "the block you are on is delivered". There silence also means "keep going":
24 * M continues once S's slot is over, S in its continuation slots.
25 *
26 * This module is the protocol only: no threads, no clock of its own, no I/O
27 * but the callbacks. tests/sim/carousel_bench.c runs two of them on the sim
28 * channel; the ARQ runtime runs one against the modem.
29 *
30 * Copyright (C) 2026 Rhizomatica
31 * SPDX-License-Identifier: GPL-3.0-or-later
32 */
33#ifndef CAROUSEL_H
34#define CAROUSEL_H
35
36#include <stdbool.h>
37#include <stddef.h>
38#include <stdint.h>
39
40#include "rs_erasure.h"
41
42#define CAR_PIECE 24 /* bytes per piece: fits DATAC15 with the headers */
43/* ...and in a session that starts on the floor: an MFSK frame (98 bytes,
44 * 6 of headers) holds 4 of 23 where it held 3 of 24 -- 92 bytes, not 72.
45 * A whole session uses one size (car_piece_for_start), so blocks
46 * stay uniform; the DATAC rungs carry 4 % less at 23, so only a session
47 * expected to live at the floor takes it. */
48#define CAR_PIECE_FLOOR 23
49#define CAR_MAX_K 96 /* data pieces per block (see carousel.c) */
50#define CAR_WIN 8 /* open blocks at once */
51#define CAR_NLEVELS 7 /* the payload mode ladder (3 bits on the wire) */
52#define CAR_FRAME_MAX 1280 /* largest payload-mode frame, bytes */
53#define CAR_POLL_BYTES 14 /* a poll fills one control-mode (DATAC16) frame */
54#define CAR_KEYDOWN_MAX 16 /* frames in one keydown (a round) */
55#define CAR_MLOG 16 /* M's keydowns whose slots may still be open */
56
57/* One frame of a keydown, as the modem sends it. */
58typedef struct {
59 int mode; /* FREEDV_MODE_* */
60 size_t len;
61 uint8_t bytes[CAR_FRAME_MAX];
62 uint32_t gap_ms; /* silence before this frame (not the first) */
64
65/* What says the peer is on the air (car_io_t.peer_keyed); 0: nothing. */
66enum {
67 CAR_KEYED_SYNC = 1, /* a decoder is in sync on a frame */
68 CAR_KEYED_PREAMBLE, /* a frame's preamble was caught: its airtime */
69 CAR_KEYED_NAV, /* the peer's NAV header: its keydown */
70 CAR_KEYED_BUSY, /* the energy busy detector (off by default) */
71};
72
73typedef struct {
74 /* Key the radio for these frames, back to back with their gaps. The
75 * frames are only valid during the call. The runtime calls
76 * car_on_tx_done() when the keydown has ended. */
77 void (*keydown)(void *ctx, const car_frame_t *frames, int n);
78 /* Bind the payload decoder to this mode (the control decoder always runs). */
79 void (*bind_rx)(void *ctx, int mode);
80 /* Is the peer on the air, and by what sign (CAR_KEYED_*, 0: no)? A
81 * decoder in sync, held for the sync-loss latency after it ends. */
82 int (*peer_keyed)(void *ctx);
83 /* The application's queue: take up to max bytes; how many are waiting. */
84 size_t (*tx_read)(void *ctx, uint8_t *buf, size_t max);
85 size_t (*tx_pending)(void *ctx);
86 /* Bytes for the application, in order. */
87 void (*deliver)(void *ctx, const uint8_t *buf, size_t len);
88 /* This many of our bytes have reached the peer. */
89 void (*tx_confirmed)(void *ctx, size_t len);
90 /* Key a pattern: CAR_PATTERN_ACK or CAR_PATTERN_BREAK. Optional: without
91 * it the floor polls in the control mode like every other rung. The
92 * runtime calls car_on_tx_done() when it has ended. */
93 void (*pattern)(void *ctx, int kind);
94 /* The callee ending the session (car_request_end): key the session's
95 * DISCONNECT now, in the slot the carousel was given. */
96 void (*end)(void *ctx);
97 /* One line on each decision (optional): what the receiver measured and
98 * chose, what the sender was told. For debug logs. */
99 void (*trace)(void *ctx, const char *line);
100 void *ctx;
101 /* Keys each block's check (the session's CRC seed): a block rebuilt from
102 * another session's pieces fails it. */
103 uint32_t block_key;
104 /* The longest keydown this end keys, ms (arq:max_keydown_s, #445); 0:
105 * the station's (car_set_max_keydown_ms). Per end, so the sim can set
106 * one. */
108} car_io_t;
109
111
112enum { CAR_T_M, CAR_T_S, CAR_T_F, CAR_T_W, CAR_NTIMERS }; /* M's next decision or keydown; S's next slot;
113 * S's fallback to the floor, and its watch
114 * for the round it asked for (listening only) */
115
116typedef struct {
117 uint8_t id;
118 int K, len, next, need; /* next: the next piece index to send */
119 int app_len; /* of len, the application's bytes (the rest: the check) */
120 int resend; /* data piece the receiver waits on, -1 */
121 int sent; /* distinct pieces sent so far (capped) */
122 int round_sent; /* fresh pieces of it in my last round */
123 bool stopped; /* a floor BREAK said it is in; a poll retires it */
124 uint8_t data[CAR_MAX_K][CAR_PIECE];
126
127typedef struct {
128 bool known, done;
129 uint8_t id;
130 int K, len, have; /* len: with the check */
131 int delivered; /* bytes already handed to the application */
132 bool got[RS_MAX_PIECES];
133 uint8_t piece[RS_MAX_PIECES][CAR_PIECE];
135
136typedef struct {
137 uint64_t e; /* when it ended (exact: my own keydown) */
138 uint32_t r, d; /* the longest S keydown it allows; S's lateness */
139 uint32_t p; /* the period of its continuation slots */
140 uint32_t tg; /* when its response slot opens, after it */
141 uint8_t k; /* continuation slots after the response slot */
142 uint8_t done; /* slots I heard S's keydown in, end to end */
143 uint8_t mk; /* its id */
144 bool pat; /* a pattern: S's answers name no id */
145} car_mlog_t;
146
147typedef struct {
149 bool master; /* the caller: the session's only timing master */
150 bool idle; /* nothing in flight either way */
151 int rx_level; /* what the payload decoder is bound to */
152 int snr_level; /* where the SNR measured here starts the peer */
153 int max_level; /* the highest rung the session's bandwidth
154 * allows (car_set_max_level) */
155 int floor_mode; /* rung 0's mode (car_set_floor_mode) */
156 uint8_t ctl_deaf; /* I hear the peer below the control mode
157 * (CAR_DEAF_*): its control must reach me
158 * on MFSK (reported) */
159 uint8_t peer_ctl_deaf; /* ...and the peer, of me, as it reports
160 * (or CAR_DEAF_MFSK_TX) */
161 float snr_ema; /* SNR of what the peer sends us, smoothed */
162 float snr_last; /* ...and its latest reading */
163 uint64_t snr_ms; /* ...and when it came */
165 uint64_t deadline[CAR_NTIMERS]; /* 0 = disarmed */
166 uint64_t last_carrier_ms; /* the peer was last heard on the air */
167 uint64_t heard_ms; /* ...last decoded: a frame or a pattern */
168 bool tx_busy; /* our keydown is on the air */
169 uint8_t held; /* why the planned keydown waits (HELD_*):
170 * logged once per hold */
171 uint64_t held_since; /* ...since when, for a busy channel */
172
173 /* M: the turn */
174 int phase; /* sending my data, polling the peer's, or idle */
175 uint64_t phase_start;
176 uint8_t mk; /* id of my next keydown, mod 16 */
178 int nmlog;
179 bool m_keyed; /* M: keyed at all this session */
180 bool m_heard_ever; /* M: heard S at all this session */
181 int m_kind; /* my keydown on the air, */
182 car_mlog_t m_kd; /* ...its id and the slots it opens, as its log
183 * entry will hold them (e, done, tg, pat: then) */
184 int m_state; /* waiting for S's answer, or for a free time */
185 int plan, plan_lv, plan_n; /* the keydown decided */
186 bool m_heard; /* S keyed since my last keydown, and I heard it end */
187 bool s_answered; /* ...with a poll or a pattern for my round */
188 bool offered; /* M: my round offered S its turn as well (offer_both) */
189 uint64_t kd_allowed; /* M: the length my keydown was checked against FreeFor at */
190 int overruns; /* M: keydowns longer than that (a bug: see keydown()) */
191 int piece; /* the session's piece size (0: CAR_PIECE) */
192 uint32_t deliver_seq; /* deliveries to my application so far */
193 uint32_t seq_at_ask; /* ...when I last asked or answered */
194 uint64_t plan_not_before; /* M: an ack-only DONE waits for my application till then */
195 int last_lv, last_nf; /* my last round, for a REQ */
196 uint8_t last_mk;
197 bool idle_poll; /* my poll on the air only asks whether S has data */
199 bool traffic; /* data moved since I was last idle */
200 int reqs; /* REQs in a row unanswered */
201
202 /* S: the slots */
203 struct {
204 bool on;
205 uint8_t mk; /* the M keydown (its id; patterns carry none) */
206 int kind;
207 uint64_t eh; /* its end, as I learned it */
208 uint32_t p; /* slot period */
209 uint8_t k, i; /* continuation slots; the next slot */
210 bool sent_round; /* I sent a round in this anchor's slots */
211 uint32_t d; /* its lateness allowance: my start may be this late */
212 bool waited; /* its slot 0 already waited for my application */
213 } anc;
214 uint8_t end_req; /* S: CAR_END_WISH, my application has hung up and my
215 * polls say so (M_END); CAR_END_SLOT, my next slot
216 * carries the session's DISCONNECT.
217 * M: CAR_END_WISH, a poll of S's said S's application
218 * has hung up (M_END), whatever S still holds
219 * (car_peer_ending); never CAR_END_SLOT */
220 int req_lv, req_n; /* a REQ: M's round I may not have heard */
221 uint8_t req_mk;
222 uint8_t rx_mk; /* the M round whose frames I am counting */
223 uint64_t s_tx_end; /* when my last keydown ended */
224 bool rx_late; /* the frame being handled was decoded too late to answer */
225 int s_prev_lv; /* the rung M's rounds last came on (-1: none) */
226 bool s_asked_new; /* my poll on the air asks M for another rung */
227 int ok_lv; /* the rung of my last round the peer answered (-1: none) */
228 uint64_t peer_data_ms; /* when a frame of the peer's data last came */
229 bool fell_back; /* M: my last round went back to it */
230
231 /* as sender */
233 int nsb;
234 uint8_t next_blk_id;
235 int tx_level, tx_n; /* as the last poll directed (-1: never polled) */
236 uint8_t tx_poll_id; /* the poll my rounds answer (its keydown id) */
237 int tx_slot; /* ...in this slot (S) */
238 bool tx_pat_anchor; /* ...anchored on a pattern (S) */
239 double tx_loss; /* the receiver's loss estimate, for the margin */
240 bool floor_waiting; /* my floor round is out: a pattern may come */
241 bool pat_waiting; /* my round above the floor is out: a pattern
242 * ("it came whole, the same again") may come */
243 int floor_silent; /* floor rounds in a row with no answer */
244 uint8_t floor_blk; /* the block my last floor round carried */
245 int peer_snr_level; /* where the SNR the peer measures starts me */
246 bool peer_level_known; /* ...as the peer reported it (ACCEPT, poll) */
247 float peer_snr_db; /* how the peer hears me, as its last control
248 * frame said (dB) */
249 uint64_t peer_snr_ms; /* ...and when (0: never) */
250 float peer_snr_mine; /* ...and how I heard the peer then (NAN: unknown) */
251 int rx_data_lv; /* the rung of the last data frame I took; -1 none */
252 bool peer_has_data; /* the peer said it has data for me */
253
254 /* as receiver: the peer's direction, measured here, per rung */
255 struct {
256 double sent, lost; /* frames, decayed (measure_level) */
257 int rounds, dead_run;
258 int probe_fails; /* its rounds in a row that lost half */
259 double p_ok; /* the delivery it showed when it last delivered */
260 uint32_t round_at; /* polls, when last measured */
261 uint64_t probe_at, backoff_ms;
262 } rung[CAR_NLEVELS];
263 uint32_t polls;
264 double loss_est;
265 double polled_loss; /* the loss my last poll told the sender */
266 uint8_t poll_id; /* my last poll's keydown id (M), or the one I answer (S) */
267 int poll_level, poll_n; /* what I asked the peer for */
268 int round_seen, round_frames;
269 int round_lv; /* the rung the frames came on */
270 bool rx_tail; /* ...and its last frame among them */
272 int silent_polls; /* bit 0: asked again this round; above it, 2 per scored
273 * round in a row with nothing of the peer heard */
275 bool peer_short; /* the peer speaks the backlog hint (car_set_short_rung) */
276 uint8_t peer_backlog; /* ...and what it last said it holds (BL_*) */
277 int name_lv; /* S: the rung my next ack says I listen on (0: none) */
278 size_t rx_run; /* bytes delivered since the peer's direction last completed */
279 size_t peer_last_msg; /* ...and that size, the last time it did */
280 uint8_t peer_hi;
281 uint8_t polled_base; /* the window base my last poll reported */
282 bool round_fresh; /* this round carried a block I do not have yet */
283 int stale_rounds; /* floor rounds in a row that carried nothing new */
284 const char *failed; /* car_failed() */
287 uint8_t rbase;
289 bool rx_break; /* the last round delivered the block it carried */
290 int floor_patterns; /* patterns since my last poll */
291 bool floor_streaming; /* a floor round came since my last poll */
293} car_t;
294
295/* Start a connected session. rx_level: the rung the SNR measured here gives
296 * the peer's direction; tx_level: the rung the peer gave ours (-1: unknown,
297 * then rx_level until the peer's frames say). car_start_sender() on the
298 * caller, the session's timing master; car_start_receiver() on the callee. */
299void car_init(car_t *c, const car_io_t *io, int rx_level, int tx_level);
300/* Cap both directions at rung lv: a BW500 session stays below the wideband
301 * modes (DATAC1, DATAC17, QAM16C2). Both ends set the same cap, from the
302 * bandwidth the connect negotiated, after car_init and before starting. */
303void car_set_max_level(car_t *c, int lv);
304/* The highest rung a session bandwidth (Hz, VARA's BW500/BW2300/BW2750)
305 * allows. */
307/* The session's floor, rung 0 (arq_floor_mode of its bandwidth): the 1 kHz
308 * MFSK unless set. Both ends set the same, after car_init. */
309void car_set_floor_mode(car_t *c, int mode);
310/* car_t.ctl_deaf: deaf by the SNR reading, or HARD -- deaf though the reading
311 * says the control mode works (the connect got through on MFSK only). A
312 * reading on an MFSK frame does not clear HARD: MFSK copes with what may be
313 * killing the control mode, a Doppler spread or a multipath the SNR does not
314 * show. Only a frame of the peer's on an OFDM mode does. MFSK_TX is deaf
315 * for good: the station transmits only MFSK (arq:mfsk_tx_only, an FSK-only
316 * radio; the connect's TX-MFSK-only bit). Its peer holds it in ctl_deaf,
317 * the station itself in peer_ctl_deaf; nothing the session hears clears it. */
319/* Seed, from the connect exchange, whether each end hears the other below the
320 * control mode (CAR_DEAF_*; see ctl_on_floor in carousel.c). Frames keep
321 * both current, all but MFSK_TX. */
322void car_seed_ctl_deaf(car_t *c, uint8_t mine, uint8_t peers);
323/* The connect's SNRs (0: unknown): mine, the reading of the peer's connect
324 * frame -- the carousel's first, so its first control frame reports one --
325 * and the peer's of mine (the caller has it from the ACCEPT). */
326void car_seed_snr(car_t *c, float mine, float peers);
327/* The peer hears us below the control mode, as it last reported: our control
328 * frames go on MFSK. The session's own control frames follow the same rule. */
329bool car_peer_ctl_deaf(const car_t *c);
330void car_start_sender(car_t *c, uint64_t now);
331void car_start_receiver(car_t *c, uint64_t now);
332
333/* A frame came in. control: the control decoder (DATAC16) produced it;
334 * otherwise mode is the payload decoder's. snr_db: the decoder's estimate
335 * for it, 0 when unknown. age_ms: how long ago the frame ended (0 when the
336 * decode was immediate); one older than its mode's decode bound is data,
337 * never a time to answer at. */
338bool car_on_frame(car_t *c, uint64_t now, const uint8_t *bytes, size_t len, int mode, bool control,
339 float snr_db, uint32_t age_ms); /* true: the caller heard an M_END */
340void car_on_tx_done(car_t *c, uint64_t now);
341/* A pattern was heard: CAR_PATTERN_ACK or CAR_PATTERN_BREAK. */
342void car_on_pattern(car_t *c, uint64_t now, int kind);
343/* Whether a pattern can arrive now (the runtime runs its detector only then). */
344bool car_expect_pattern(const car_t *c);
345/* The application queued data. */
346void car_on_app_data(car_t *c, uint64_t now);
347
348/* The earliest armed deadline (UINT64_MAX: none), and firing what is due. */
349uint64_t car_next_deadline(const car_t *c);
350void car_on_time(car_t *c, uint64_t now);
351
352/* The ladder rung for an SNR, mapped the way trunk enters a mode from DATAC15. */
353int car_start_level(float snr_db);
354int car_level_mode(int level); /* on the 1 kHz floor's ladder */
355int car_session_level_mode(const car_t *c, int level);
356/* The session's piece size, from the rung the callee's ACCEPT starts the
357 * caller's rounds on (both ends know it; the FSM also folds it into the
358 * session seed, so ends that disagree hear none of each other's frames). */
359int car_piece_for_start(int caller_start_level);
360/* The piece size this session cuts its blocks into (tests). */
361int car_piece(const car_t *c);
362/* For the UI: the mode of my last data round, of the last data frame I took,
363 * and of the rung the peer last reported hearing me on. -1: none yet. */
364int car_ui_tx_mode(const car_t *c);
365int car_ui_rx_mode(const car_t *c);
366int car_ui_peer_mode(const car_t *c);
367bool car_is_idle(const car_t *c);
368bool car_is_drained(const car_t *c); /* delivered both ways (a DISCONNECT may go) */
369bool car_rx_verified(const car_t *c); /* every block heard of has passed its check */
370/* The session can no longer be trusted: a block failed its check, or did not
371 * decode. What it carried may already be partly delivered (the stream runs
372 * ahead of the check), so the session must end -- never carry on. NULL: fine. */
373const char *car_failed(const car_t *c);
374/* Keydowns of M's longer than the slot check allowed them: always 0 (tests). */
375int car_overruns(const car_t *c);
376/* For tests, the turn rules checked from outside: does M's log hold a slot,
377 * not yet over, for a keydown of S's on the air over [start, end)? M keys
378 * clear of every such slot, so S inside one cannot meet M. */
379bool car_slot_reserved(const car_t *m, uint64_t start, uint64_t end);
380/* Every keydown of mine opens with a NAV header this long (0: none), where
381 * car_wants_nav() says the peer may not sense it otherwise (car_set_nav_below_db). */
382void car_set_nav_ms(uint32_t ms);
383void car_set_short_rung(bool on); /* small backlogs on the shortest rung (default on) */
384/* The longest keydown this station keys, in ms (0: the protocol's 30 s
385 * round); rounds it accepts stay at 30 s (arq:max_keydown_s, #445). A
386 * session takes it at car_init unless its car_io_t sets one. */
387void car_set_max_keydown_ms(uint32_t ms);
388void car_set_nav_below_db(float db);
389void car_set_nav_loss(double loss); /* ...or at this loss estimate (default 0.3) */
390bool car_wants_nav(const car_t *c);
391/* A rung's geometry (bytes of data per frame, frames per full keydown, its
392 * airtime, a round's fixed overhead): for computing bounds. */
393void car_rung_geometry(int lv, bool floor_patterns, int *bytes_per_frame, int *frames,
394 uint64_t *round_air_ms, uint64_t *overhead_ms);
395/* The smoothed SNR below which the SNR alone keeps a rung out (level_gated,
396 * before its delivery exception): for the sims' probe checks. */
397float car_rung_gate_db(int lv);
398
399/* The session's own control keydowns (its DISCONNECT) follow the turn rules
400 * too. The caller: car_free_at() is the earliest time from now a keydown of
401 * len ms misses every slot the callee could be using; once one has gone out,
402 * car_log_ctl() keeps the callee's reply (tg ms after it) clear of the next.
403 * The callee: car_request_end() makes its next slot call io.end instead of
404 * answering -- it never keys a DISCONNECT on a timer of its own. */
405bool car_is_master(const car_t *c);
406uint64_t car_free_at(const car_t *c, uint64_t now, uint64_t len);
407void car_log_ctl(car_t *c, uint64_t end, uint32_t tg);
408void car_request_end(car_t *c);
409/* The callee whose application has hung up while its DISCONNECT waits for
410 * its data to be acknowledged: car_wish_end() makes its polls say so (type
411 * 3, M_END) once it has all of the caller's. The caller, with all of the
412 * callee's, then ends the session itself (car_on_frame returns true). */
414void car_wish_end(car_t *c);
415/* The callee has delivered data of the caller's that no answer of its own
416 * has acknowledged yet: a DISCONNECT keyed now would take that answer's
417 * slot, and the caller would never hear that its last bytes arrived. */
418bool car_owes_ack(const car_t *c);
419
420/* How long delivering what is left may take on the rung the session is on:
421 * a few exchanges -- my round, the peer's control answer -- there. Seconds
422 * on a fast rung; minutes at the MFSK floor. */
423uint64_t car_drain_budget_ms(const car_t *c);
424/* The caller has heard the callee say its application has hung up (M_END),
425 * whether or not everything of the callee's has arrived since. */
426bool car_peer_ending(const car_t *c);
427/* Bytes taken from the application that the peer has not confirmed yet. */
428size_t car_tx_inflight(const car_t *c);
429
430#endif
static void bind_rx(car_t *c, int lv)
Definition carousel.c:690
int mode
Definition carousel.c:2916
int bw_hz
Definition carousel.c:2962
static int peer_keyed(car_t *c, uint64_t now)
Definition carousel.c:610
static void keydown(car_t *c, car_frame_t *fr, int n)
Definition carousel.c:670
@ CAR_T_M
Definition carousel.h:112
@ CAR_T_F
Definition carousel.h:112
@ CAR_T_S
Definition carousel.h:112
@ CAR_T_W
Definition carousel.h:112
@ CAR_NTIMERS
Definition carousel.h:112
void car_start_receiver(car_t *c, uint64_t now)
Definition carousel.c:3026
void car_wish_end(car_t *c)
Definition carousel.c:3352
int car_session_level_mode(const car_t *c, int level)
Definition carousel.c:197
@ CAR_DEAF_HARD
Definition carousel.h:318
@ CAR_DEAF_MFSK_TX
Definition carousel.h:318
@ CAR_DEAF_SNR
Definition carousel.h:318
void car_set_nav_loss(double loss)
Definition carousel.c:115
bool car_slot_reserved(const car_t *m, uint64_t start, uint64_t end)
Definition carousel.c:236
void car_init(car_t *c, const car_io_t *io, int rx_level, int tx_level)
Definition carousel.c:2935
bool car_is_master(const car_t *c)
Definition carousel.c:3334
void car_set_max_level(car_t *c, int lv)
Definition carousel.c:2976
void car_log_ctl(car_t *c, uint64_t end, uint32_t tg)
Definition carousel.c:3344
#define CAR_PIECE
Definition carousel.h:42
int car_max_level_for_bw(int bw_hz)
Definition carousel.c:2968
void car_set_floor_mode(car_t *c, int mode)
Definition carousel.c:2951
void car_on_tx_done(car_t *c, uint64_t now)
Definition carousel.c:3166
#define CAR_MAX_K
Definition carousel.h:49
void car_on_time(car_t *c, uint64_t now)
Definition carousel.c:3287
void car_set_max_keydown_ms(uint32_t ms)
Definition carousel.c:90
int car_ui_tx_mode(const car_t *c)
Definition carousel.c:3001
bool car_on_frame(car_t *c, uint64_t now, const uint8_t *bytes, size_t len, int mode, bool control, float snr_db, uint32_t age_ms)
Definition carousel.c:3088
bool car_rx_verified(const car_t *c)
Definition carousel.c:226
void car_rung_geometry(int lv, bool floor_patterns, int *bytes_per_frame, int *frames, uint64_t *round_air_ms, uint64_t *overhead_ms)
Definition carousel.c:1135
void car_on_app_data(car_t *c, uint64_t now)
Definition carousel.c:3271
void car_seed_ctl_deaf(car_t *c, uint8_t mine, uint8_t peers)
Definition carousel.c:3057
#define CAR_NLEVELS
Definition carousel.h:51
int car_piece(const car_t *c)
Definition carousel.c:2999
size_t car_tx_inflight(const car_t *c)
Definition carousel.c:215
int car_level_mode(int level)
Definition carousel.c:196
#define CAR_WIN
Definition carousel.h:50
uint64_t car_drain_budget_ms(const car_t *c)
Definition carousel.c:3325
bool car_peer_ctl_deaf(const car_t *c)
Definition carousel.c:3055
#define CAR_MLOG
Definition carousel.h:55
bool car_is_drained(const car_t *c)
Definition carousel.c:210
int car_overruns(const car_t *c)
Definition carousel.c:232
bool car_expect_pattern(const car_t *c)
Definition carousel.c:3253
int car_start_level(float snr_db)
Definition carousel.c:2927
int car_piece_for_start(int caller_start_level)
Definition carousel.c:2994
bool car_peer_ending(const car_t *c)
Definition carousel.c:3335
int car_ui_peer_mode(const car_t *c)
Definition carousel.c:3003
void car_start_sender(car_t *c, uint64_t now)
Definition carousel.c:3011
bool car_wants_nav(const car_t *c)
Definition carousel.c:116
const char * car_failed(const car_t *c)
Definition carousel.c:222
bool car_is_idle(const car_t *c)
Definition carousel.c:202
void car_on_pattern(car_t *c, uint64_t now, int kind)
Definition carousel.c:3227
void car_set_short_rung(bool on)
Definition carousel.c:108
@ CAR_END_NONE
Definition carousel.h:413
@ CAR_END_SLOT
Definition carousel.h:413
@ CAR_END_WISH
Definition carousel.h:413
@ CAR_KEYED_NAV
Definition carousel.h:69
@ CAR_KEYED_BUSY
Definition carousel.h:70
@ CAR_KEYED_SYNC
Definition carousel.h:67
@ CAR_KEYED_PREAMBLE
Definition carousel.h:68
void car_seed_snr(car_t *c, float mine, float peers)
Definition carousel.c:3071
@ CAR_PATTERN_BREAK
Definition carousel.h:110
@ CAR_PATTERN_ACK
Definition carousel.h:110
bool car_owes_ack(const car_t *c)
Definition carousel.c:3359
void car_set_nav_below_db(float db)
Definition carousel.c:114
#define CAR_KEYDOWN_MAX
Definition carousel.h:54
void car_set_nav_ms(uint32_t ms)
Definition carousel.c:97
#define CAR_FRAME_MAX
Definition carousel.h:52
uint64_t car_next_deadline(const car_t *c)
Definition carousel.c:602
void car_request_end(car_t *c)
Definition carousel.c:3364
float car_rung_gate_db(int lv)
Definition carousel.c:1078
uint64_t car_free_at(const car_t *c, uint64_t now, uint64_t len)
Definition carousel.c:3337
int car_ui_rx_mode(const car_t *c)
Definition carousel.c:3002
#define RS_MAX_PIECES
Definition rs_erasure.h:20
Definition carousel.h:58
int mode
Definition carousel.h:59
uint32_t gap_ms
Definition carousel.h:62
size_t len
Definition carousel.h:60
Definition carousel.h:73
void * ctx
Definition carousel.h:100
uint32_t block_key
Definition carousel.h:103
uint32_t max_keydown_ms
Definition carousel.h:107
Definition carousel.h:136
uint8_t k
Definition carousel.h:141
uint64_t e
Definition carousel.h:137
uint8_t mk
Definition carousel.h:143
bool pat
Definition carousel.h:144
uint32_t d
Definition carousel.h:138
uint32_t tg
Definition carousel.h:140
uint32_t p
Definition carousel.h:139
uint8_t done
Definition carousel.h:142
Definition carousel.h:127
bool done
Definition carousel.h:128
uint8_t id
Definition carousel.h:129
int delivered
Definition carousel.h:131
int have
Definition carousel.h:130
Definition carousel.h:116
int sent
Definition carousel.h:121
int round_sent
Definition carousel.h:122
int app_len
Definition carousel.h:119
bool stopped
Definition carousel.h:123
int K
Definition carousel.h:118
uint8_t id
Definition carousel.h:117
int resend
Definition carousel.h:120
Definition carousel.h:147
int floor_silent
Definition carousel.h:243
car_mlog_t m_kd
Definition carousel.h:182
int rx_level
Definition carousel.h:151
uint64_t eh
Definition carousel.h:207
int poll_level
Definition carousel.h:267
double tx_loss
Definition carousel.h:239
uint8_t ctl_deaf
Definition carousel.h:156
bool peer_hi_known
Definition carousel.h:285
bool m_heard_ever
Definition carousel.h:180
bool m_heard
Definition carousel.h:186
uint8_t last_mk
Definition carousel.h:196
uint8_t held
Definition carousel.h:169
uint64_t peer_snr_ms
Definition carousel.h:249
uint64_t peer_data_ms
Definition carousel.h:228
uint64_t backoff_ms
Definition carousel.h:261
float peer_snr_db
Definition carousel.h:247
bool traffic
Definition carousel.h:199
int probe_fails
Definition carousel.h:258
uint8_t tx_poll_id
Definition carousel.h:236
int dead_run
Definition carousel.h:257
int round_frames
Definition carousel.h:268
size_t rx_run
Definition carousel.h:278
int reqs
Definition carousel.h:200
float peer_snr_mine
Definition carousel.h:250
uint32_t d
Definition carousel.h:211
int req_lv
Definition carousel.h:220
int name_lv
Definition carousel.h:277
int m_kind
Definition carousel.h:181
int floor_mode
Definition carousel.h:155
bool floor_waiting
Definition carousel.h:240
bool peer_unopened
Definition carousel.h:274
bool tx_pat_anchor
Definition carousel.h:238
bool m_keyed
Definition carousel.h:179
uint8_t peer_backlog
Definition carousel.h:276
bool master
Definition carousel.h:149
uint32_t round_at
Definition carousel.h:260
uint64_t phase_start
Definition carousel.h:175
int kind
Definition carousel.h:206
uint8_t i
Definition carousel.h:209
int round_lv
Definition carousel.h:269
int tx_slot
Definition carousel.h:237
bool on
Definition carousel.h:204
uint64_t snr_ms
Definition carousel.h:163
int stale_rounds
Definition carousel.h:283
int done_in_round
Definition carousel.h:288
uint8_t polled_base
Definition carousel.h:281
uint8_t next_blk_id
Definition carousel.h:234
bool idle
Definition carousel.h:150
uint32_t idle_backoff_ms
Definition carousel.h:198
size_t peer_last_msg
Definition carousel.h:279
bool waited
Definition carousel.h:212
double loss_est
Definition carousel.h:264
int s_prev_lv
Definition carousel.h:225
float snr_ema
Definition carousel.h:161
uint8_t rbase
Definition carousel.h:287
uint8_t mk
Definition carousel.h:176
bool peer_short
Definition carousel.h:275
uint32_t polls
Definition carousel.h:263
const char * failed
Definition carousel.h:284
bool peer_level_known
Definition carousel.h:246
uint32_t deliver_seq
Definition carousel.h:192
double polled_loss
Definition carousel.h:265
bool round_fresh
Definition carousel.h:282
bool tx_busy
Definition carousel.h:168
bool idle_poll
Definition carousel.h:197
float snr_last
Definition carousel.h:162
int ok_lv
Definition carousel.h:227
double lost
Definition carousel.h:256
uint64_t heard_ms
Definition carousel.h:167
int nsb
Definition carousel.h:233
bool fell_back
Definition carousel.h:229
int snr_level
Definition carousel.h:152
uint8_t peer_ctl_deaf
Definition carousel.h:159
int overruns
Definition carousel.h:190
bool rx_late
Definition carousel.h:224
int max_level
Definition carousel.h:153
uint8_t req_mk
Definition carousel.h:221
bool sent_round
Definition carousel.h:210
bool rx_tail
Definition carousel.h:270
bool pat_waiting
Definition carousel.h:241
uint64_t s_tx_end
Definition carousel.h:223
int phase
Definition carousel.h:174
bool rx_break
Definition carousel.h:289
bool snr_valid
Definition carousel.h:164
uint8_t floor_blk
Definition carousel.h:244
uint64_t plan_not_before
Definition carousel.h:194
int rx_data_lv
Definition carousel.h:251
int nmlog
Definition carousel.h:178
int plan
Definition carousel.h:185
uint8_t poll_id
Definition carousel.h:266
int piece
Definition carousel.h:191
bool offered
Definition carousel.h:188
uint8_t end_req
Definition carousel.h:214
uint64_t held_since
Definition carousel.h:171
car_io_t io
Definition carousel.h:148
double p_ok
Definition carousel.h:259
bool peer_has_data
Definition carousel.h:252
uint32_t seq_at_ask
Definition carousel.h:193
uint8_t peer_hi
Definition carousel.h:280
bool s_asked_new
Definition carousel.h:226
uint64_t last_carrier_ms
Definition carousel.h:166
int last_lv
Definition carousel.h:195
uint32_t p
Definition carousel.h:208
uint8_t rx_mk
Definition carousel.h:222
int peer_snr_level
Definition carousel.h:245
bool floor_streaming
Definition carousel.h:291
int m_state
Definition carousel.h:184
int tx_level
Definition carousel.h:235
uint64_t kd_allowed
Definition carousel.h:189
bool status_seen
Definition carousel.h:271
int floor_patterns
Definition carousel.h:290
bool s_answered
Definition carousel.h:187
int silent_polls
Definition carousel.h:272