HERMES Modem
Hermes ARQ/Broadcast modem
Loading...
Searching...
No Matches
arq.h
Go to the documentation of this file.
1/* HERMES Modem
2 *
3 * Copyright (C) 2025 Rhizomatica
4 * Author: Rafael Diniz <rafael@riseup.net>
5 *
6 * This is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef ARQ_H_
22#define ARQ_H_
23
24#define CALLSIGN_MAX_SIZE 16
25
26#define ARQ_BANDWIDTH_NARROW_HZ 500
27#define ARQ_BANDWIDTH_FULL_HZ 2300
28#define ARQ_BANDWIDTH_TACTICAL_HZ 2750
29
30#define RX 0
31#define TX 1
32
33#define HEADER_SIZE 1
34
35#define PACKET_ARQ_CONTROL 0x00
36#define PACKET_ARQ_DATA 0x01
37#define PACKET_ARQ_CALL 0x02
38#define PACKET_BROADCAST_CONTROL 0x03
39#define PACKET_BROADCAST_PAYLOAD 0x04
40
41#include <stdbool.h>
42#include <stddef.h>
43#include <stdint.h>
44
45#include "fsm.h"
46#include "arq_events.h"
47
49typedef struct
50{
51 int TRX; // RX (0) or TX (1)
52 char my_call_sign[CALLSIGN_MAX_SIZE];
53 char src_addr[CALLSIGN_MAX_SIZE], dst_addr[CALLSIGN_MAX_SIZE];
56 bool listen;
57 int bw; // configured local bandwidth in Hz
58 int session_bw; // negotiated session bandwidth in Hz (0 = not negotiated)
59 int retry_slots; // 0 = use compiled default
60 size_t frame_size;
61 int mode;
62} arq_info;
63
72
74typedef struct
75{
77 int mode;
78 size_t frame_size;
80
82typedef struct
83{
86 int trx;
89 int payload_mode; /* my TX mode (ISS direction) */
90 int peer_tx_mode; /* RX decoder mode = peer's TX mode (IRS direction) */
94 uint64_t tx_bytes;
95 uint64_t rx_bytes;
97
98extern arq_info arq_conn;
99extern fsm_handle arq_fsm;
100
107int arq_init(size_t frame_size, int mode);
108
112void arq_shutdown();
113
117void arq_tick_1hz(void);
118
123void arq_post_event(int event);
124
129bool arq_is_link_connected(void);
130
136
142
148bool arq_bandwidth_allows_mode(int mode);
149
156int arq_queue_data(const uint8_t *data, size_t len);
157
163
168int arq_get_speed_level(void);
169
174int arq_get_payload_mode(void);
175
180int arq_get_control_mode(void);
181
187
193
199void arq_set_active_modem_mode(int mode, size_t frame_size);
200
207bool arq_handle_incoming_connect_frame(uint8_t *data, size_t frame_size);
208
215bool arq_handle_incoming_cq_frame(uint8_t *data, size_t frame_size);
216
223void arq_notify_cq_tx_started(void);
225
232void arq_handle_incoming_frame(uint8_t *data, size_t frame_size, float rx_snr);
233
241void arq_update_link_metrics(int sync, float snr, int rx_status, bool frame_decoded);
242
249
256bool arq_wait_dequeue_action(arq_action_t *action, int timeout_ms);
257
264
270int arq_submit_tcp_cmd(const arq_cmd_msg_t *cmd);
271
278int arq_submit_tcp_payload(const uint8_t *data, size_t len);
279
284
290
300void arq_set_retry_slots(int slots);
301
305void call_remote();
306
311
312#endif
#define CALLSIGN_MAX_SIZE
Definition arq.h:24
void arq_set_retry_slots(int slots)
Set runtime retry slot counts.
Definition arq.c:860
int arq_effective_bandwidth_hz(void)
Get the effective ARQ bandwidth cap in Hz used for mode gating.
Definition arq.c:274
int arq_submit_tcp_cmd(const arq_cmd_msg_t *cmd)
Submit parsed control command from TCP bridge to ARQ.
Definition arq.c:838
bool arq_handle_incoming_cq_frame(uint8_t *data, size_t frame_size)
Handle incoming compact CQ frame and emit host-side CQFRAME notification.
Definition arq.c:515
arq_info arq_conn
Definition arq.c:42
int arq_init(size_t frame_size, int mode)
Initialize ARQ subsystem.
Definition arq.c:645
int arq_submit_tcp_payload(const uint8_t *data, size_t len)
Submit payload bytes from TCP bridge to ARQ.
Definition arq.c:844
void arq_update_link_metrics(int sync, float snr, int rx_status, bool frame_decoded)
Feed decoder/link metrics into ARQ adaptation.
Definition arq.c:796
void arq_handle_incoming_frame(uint8_t *data, size_t frame_size, float rx_snr)
Handle incoming regular ARQ control/data frame.
Definition arq.c:546
int arq_get_speed_level(void)
Get current ARQ speed level (gear).
Definition arq.c:779
bool arq_get_runtime_snapshot(arq_runtime_snapshot_t *snapshot)
Copy ARQ runtime snapshot.
Definition arq.c:820
void clear_connection_data()
Clear legacy ARQ connection state and buffers.
Definition arq.c:850
void arq_post_event(int event)
Post an FSM event to ARQ.
Definition arq.c:757
bool arq_wait_dequeue_action(arq_action_t *action, int timeout_ms)
Wait for next modem action.
Definition arq.c:814
arq_action_type_t
Action types emitted by ARQ for modem worker execution.
Definition arq.h:66
@ ARQ_ACTION_TX_PAYLOAD
Definition arq.h:69
@ ARQ_ACTION_TX_CONTROL
Definition arq.h:68
@ ARQ_ACTION_NONE
Definition arq.h:67
@ ARQ_ACTION_MODE_SWITCH
Definition arq.h:70
void arq_notify_cq_tx_started(void)
Emit VARA-style async status for an outgoing CQFRAME transmission.
Definition arq.c:534
int arq_get_preferred_rx_mode(void)
Get ARQ-preferred receive mode for modem.
Definition arq.c:782
void arq_set_active_modem_mode(int mode, size_t frame_size)
Inform ARQ of modem mode/frame size actually active in modem.
Definition arq.c:785
bool arq_handle_incoming_connect_frame(uint8_t *data, size_t frame_size)
Handle incoming compressed CALL/ACCEPT frame.
Definition arq.c:469
void arq_notify_cq_tx_complete(void)
Definition arq.c:540
bool arq_try_dequeue_action(arq_action_t *action)
Try to dequeue next modem action without blocking.
Definition arq.c:808
void reset_arq_info(arq_info *arq_conn)
Reset external arq_info structure.
Definition arq.c:882
void callee_accept_connection()
Trigger callee-side accept flow in compatibility path.
Definition arq.c:897
void call_remote()
Trigger outgoing call attempt using current ARQ addresses.
Definition arq.c:896
fsm_handle arq_fsm
Definition arq.c:43
void arq_shutdown()
Shut down ARQ workers and release ARQ resources.
Definition arq.c:726
int arq_get_payload_mode(void)
Get active ARQ payload mode.
Definition arq.c:780
void arq_tick_1hz(void)
Execute 1 Hz ARQ maintenance tick.
Definition arq.c:755
bool arq_is_link_connected(void)
Check whether ARQ link is connected.
Definition arq.c:759
int arq_get_tx_backlog_bytes(void)
Get pending outbound payload backlog.
Definition arq.c:778
int arq_queue_data(const uint8_t *data, size_t len)
Queue outbound payload bytes for ARQ transmission.
Definition arq.c:764
int arq_reported_bandwidth_hz(void)
Get the configured ARQ bandwidth token to report to VARA clients.
Definition arq.c:282
int arq_get_preferred_tx_mode(void)
Get ARQ-preferred transmit mode for modem.
Definition arq.c:783
bool arq_bandwidth_allows_mode(int mode)
Check whether the current ARQ bandwidth cap allows a modem mode.
Definition arq.c:287
int arq_get_control_mode(void)
Get active ARQ control mode.
Definition arq.c:781
Single modem action item popped by modem TX worker.
Definition arq.h:75
size_t frame_size
Definition arq.h:78
int mode
Definition arq.h:77
arq_action_type_t type
Definition arq.h:76
Definition arq_events.h:60
Runtime ARQ connection and mode state shared across modules.
Definition arq.h:50
int bw
Definition arq.h:57
bool encryption
Definition arq.h:54
int session_bw
Definition arq.h:58
size_t frame_size
Definition arq.h:60
int retry_slots
Definition arq.h:59
bool listen
Definition arq.h:56
int mode
Definition arq.h:61
int TRX
Definition arq.h:51
int call_burst_size
Definition arq.h:55
Snapshot of current ARQ runtime state for telemetry/decision making.
Definition arq.h:83
int tx_backlog_bytes
Definition arq.h:87
bool initialized
Definition arq.h:84
int speed_level
Definition arq.h:88
int trx
Definition arq.h:86
int peer_tx_mode
Definition arq.h:90
int preferred_rx_mode
Definition arq.h:92
int payload_mode
Definition arq.h:89
int control_mode
Definition arq.h:91
int preferred_tx_mode
Definition arq.h:93
uint64_t tx_bytes
Definition arq.h:94
uint64_t rx_bytes
Definition arq.h:95
bool connected
Definition arq.h:85
Thread-safe finite-state machine wrapper.
Definition fsm.h:59