10#define ARQ_PROTOCOL_H_
34#define ARQ_HDR_SUBTYPE_IDX 1
35#define ARQ_HDR_FLAGS_IDX 2
36#define ARQ_HDR_SESSION_IDX 3
37#define ARQ_HDR_SEQ_IDX 4
38#define ARQ_HDR_ACK_IDX 5
39#define ARQ_HDR_SNR_IDX 6
40#define ARQ_HDR_DELAY_IDX 7
41#define ARQ_FRAME_HDR_SIZE 8
51#define ARQ_CONNECT_SESSION_IDX 1
52#define ARQ_CONNECT_PAYLOAD_IDX 2
53#define ARQ_CONNECT_SESSION_MASK 0x7F
54#define ARQ_CONNECT_ACCEPT_FLAG 0x80
55#define ARQ_CONTROL_FRAME_SIZE 14
56#define ARQ_CONNECT_META_SIZE 2
57#define ARQ_CONNECT_MAX_ENCODED (ARQ_CONTROL_FRAME_SIZE - ARQ_CONNECT_META_SIZE)
58#define ARQ_CONNECT_DST_CRC_SIZE 2
59#define ARQ_CONNECT_SRC_MAX_ENCODED (ARQ_CONNECT_MAX_ENCODED - ARQ_CONNECT_DST_CRC_SIZE)
67#define ARQ_CQ_PAYLOAD_IDX 1
68#define ARQ_CQ_SRC_MAX_ENCODED (ARQ_CONTROL_FRAME_SIZE - ARQ_CQ_PAYLOAD_IDX)
71#define ARQ_BW_TOKEN_NONE 0
72#define ARQ_BW_TOKEN_500 1
73#define ARQ_BW_TOKEN_2300 2
74#define ARQ_BW_TOKEN_2750 3
108#define ARQ_BURST_MAX 5
123#define ARQ_CONTROL_MODE FREEDV_MODE_DATAC16
128#define ARQ_CHANNEL_GUARD_MS 700
137#define ARQ_ISS_POST_ACK_GUARD_MS 900
147#define ARQ_ACCEPT_RX_WINDOW_MS 9000
158#define ARQ_LISTEN_OFF_GRACE_MS 2000
159#define ARQ_CALL_RETRY_SLOTS_DEFAULT 4
165#define ARQ_CALL_FAST_SLOTS 2
169#define ARQ_ACCEPT_RX_WINDOW_FLOOR_MS 26000
170#define ARQ_ACCEPT_RETRY_SLOTS_DEFAULT 4
171#define ARQ_DISCONNECT_RETRY_SLOTS_DEFAULT 2
182#define ARQ_CALLINT_MIN_S 4.0f
183#define ARQ_CALLINT_DEFAULT_S 0.0f
190#define ARQ_RETRY_STAGGER_MS_DEFAULT 2000
191#define ARQ_RETRY_STAGGER_MS_MAX 5000
203#define ARQ_CALL_RETRY_SLOTS atomic_load(&arq_call_retry_slots)
204#define ARQ_ACCEPT_RETRY_SLOTS atomic_load(&arq_accept_retry_slots)
205#define ARQ_DISCONNECT_RETRY_SLOTS atomic_load(&arq_disconnect_retry_slots)
212#define ARQ_ACK_DATA_GAP_MS 300
224#define ARQ_CHANNEL_SYNC_HOLD_MS 250
225#define ARQ_CHANNEL_DEFER_MS 500
226#define ARQ_CHANNEL_DEFER_MAX 20
230#define ARQ_REPLY_WINDOW_MARGIN_MS 1000
234#define ARQ_SNR_HYST_DB 5.0f
235#define ARQ_SNR_MIN_DATAC15_DB -7.0f
237#define ARQ_SNR_MIN_DATAC4_DB -6.0f
240#define ARQ_SNR_MIN_DATAC3_DB -1.0f
241#define ARQ_SNR_MIN_DATAC1_DB 3.0f
242#define ARQ_SNR_MIN_DATAC17_DB 7.0f
245#define ARQ_SNR_MIN_QAM16C2_DB 13.0f
257#define ARQ_DISCONNECT_DRAIN_TIMEOUT_S_DEFAULT 45
259#define ARQ_DISCONNECT_DRAIN_TIMEOUT_S atomic_load(&arq_disconnect_drain_timeout_s)
349 uint8_t session_id, uint8_t snr_raw);
366#define ARQ_CONNECT_VERSION 1
367#define ARQ_CONNECT_EXT_BW_MASK 0x03
368#define ARQ_CONNECT_EXT_VERSION_SHIFT 2
369#define ARQ_CONNECT_EXT_VERSION_MASK 0x0C
370#define ARQ_CONNECT_EXT_CAROUSEL 0x10
371#define ARQ_ACCEPT_CALLED_CRC_IDX 4
372#define ARQ_ACCEPT_NONCE_IDX 6
373#define ARQ_ACCEPT_LEVEL_IDX 8
374#define ARQ_ACCEPT_LEVEL_CTL_DEAF 7
380 const char *caller,
const char *called,
388 const char *called,
const char *caller,
389 int bw_hz,
int start_level, uint16_t nonce);
400 uint8_t *session_id_out,
char *caller_out,
419 const char *src,
int bw_hz);
425 char *src_out,
int *bw_hz_out);
int arq_protocol_bw_hz_from_token(uint8_t bw_token)
Map an on-air BW token back to Hz.
Definition arq_protocol.c:216
int arq_protocol_parse_cq(const uint8_t *buf, size_t buf_len, char *src_out, int *bw_hz_out)
Parse a compact DATAC16 CQ frame.
Definition arq_protocol.c:542
_Atomic int arq_disconnect_retry_slots
Definition arq_protocol.c:21
_Atomic float arq_callint_override_s
Definition arq_protocol.c:85
int arq_protocol_parse_accept(const uint8_t *buf, size_t buf_len, arq_accept_t *out)
Parse an ACCEPT.
Definition arq_protocol.c:495
_Atomic int arq_retry_stagger_ms
Definition arq_protocol.c:22
int arq_protocol_build_accept(uint8_t *buf, size_t buf_len, uint8_t session_id, const char *called, const char *caller, int bw_hz, int start_level, uint16_t nonce)
Build an ACCEPT.
Definition arq_protocol.c:451
uint16_t arq_protocol_callsign_crc16(const char *callsign)
Compute CRC16-CCITT of an uppercase-normalised callsign.
Definition arq_protocol.c:280
float arq_protocol_longest_burst_s(void)
Longest single-burst airtime across the whole mode table, in seconds.
Definition arq_protocol.c:97
_Atomic int arq_accept_retry_slots
Definition arq_protocol.c:20
const int arq_mode_table_count
Definition arq_protocol.c:74
_Atomic int arq_call_retry_slots
Definition arq_protocol.c:19
const arq_mode_timing_t * arq_protocol_mode_timing(int freedv_mode)
Look up mode timing entry for a FreeDV mode.
Definition arq_protocol.c:87
int arq_protocol_parse_call(const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *caller_out, int *bw_hz_out)
Parse a CALL: session id, the caller's callsign, the bandwidth.
Definition arq_protocol.c:478
float arq_protocol_call_interval_s(void)
Return the CALL/ACCEPT retry interval in seconds, applying any CALLINT override.
Definition arq_protocol.c:110
int arq_protocol_build_disconnect(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw)
DISCONNECT frame (PACKET_TYPE_ARQ_CONTROL).
Definition arq_protocol.c:261
int arq_protocol_build_call(uint8_t *buf, size_t buf_len, uint8_t session_id, const char *caller, const char *called, int bw_hz)
Build a CALL.
Definition arq_protocol.c:429
uint8_t arq_protocol_bw_token_from_hz(int bw_hz)
Map a configured bandwidth in Hz to an on-air BW token.
Definition arq_protocol.c:201
uint64_t arq_protocol_retry_deadline_ms(float seconds, int rank)
Definition arq_protocol.c:142
uint8_t arq_protocol_encode_snr(float snr_db)
Encode a floating-point SNR (dB) into the snr_raw wire byte.
Definition arq_protocol.c:238
int arq_protocol_retry_rank(const char *local_call, const char *remote_call)
Definition arq_protocol.c:132
_Atomic int arq_disconnect_drain_timeout_s
Definition arq_protocol.c:23
int arq_protocol_build_cq(uint8_t *buf, size_t buf_len, const char *src, int bw_hz)
Build a compact DATAC16 CQ frame carrying source callsign and BW token.
Definition arq_protocol.c:518
bool arq_protocol_connect_dst_matches(const uint8_t *buf, const char *callsign)
Is a CALL or ACCEPT addressed to callsign (bytes 2-3, all 16 bits)?
Definition arq_protocol.c:473
const arq_mode_timing_t arq_mode_table[]
Definition arq_protocol.c:57
float arq_protocol_call_interval_for_mode_s(int mode)
Definition arq_protocol.c:120
bool arq_protocol_connect_version_ok(const uint8_t *buf, size_t buf_len)
Is buf a CALL or ACCEPT of this protocol version?
Definition arq_protocol.c:414
int arq_protocol_decode_hdr(const uint8_t *buf, size_t buf_len, arq_frame_hdr_t *hdr)
Decode the ARQ header from the first bytes of buf.
Definition arq_protocol.c:184
float arq_protocol_decode_snr(uint8_t snr_raw)
Decode snr_raw wire byte back to float dB.
Definition arq_protocol.c:249
arq_subtype_t
Definition arq_protocol.h:82
@ ARQ_SUBTYPE_DISCONNECT
Definition arq_protocol.h:83
int arq_protocol_encode_hdr(uint8_t *buf, size_t buf_len, const arq_frame_hdr_t *hdr)
Encode a parsed header into the first ARQ_FRAME_HDR_SIZE bytes of buf.
Definition arq_protocol.c:168
int mode
Definition carousel.c:2330
int bw_hz
Definition carousel.c:2369
Definition arq_protocol.h:374
Definition arq_protocol.h:91
uint8_t packet_type
Definition arq_protocol.h:92
uint8_t session_id
Definition arq_protocol.h:96
uint8_t frame_ext
Definition arq_protocol.h:93
uint8_t flags
Definition arq_protocol.h:95
uint8_t tx_seq
Definition arq_protocol.h:97
uint8_t subtype
Definition arq_protocol.h:94
uint8_t ack_delay_raw
Definition arq_protocol.h:100
uint8_t snr_raw
Definition arq_protocol.h:99
uint8_t rx_ack_seq
Definition arq_protocol.h:98
Definition arq_protocol.h:111
float retry_interval_s
Definition arq_protocol.h:114
int payload_bytes
Definition arq_protocol.h:115
float frame_duration_s
Definition arq_protocol.h:113
int freedv_mode
Definition arq_protocol.h:112