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 RX 0
27#define TX 1
28
29#define HEADER_SIZE 1
30
31#define PACKET_ARQ_CONTROL 0x00
32#define PACKET_ARQ_DATA 0x01
33#define PACKET_ARQ_CALL 0x02
34#define PACKET_BROADCAST_CONTROL 0x03
35#define PACKET_BROADCAST_PAYLOAD 0x04
36
37#include <stdbool.h>
38#include <stddef.h>
39#include <stdint.h>
40
41#include "fsm.h"
42#include "arq_events.h"
43
45typedef struct
46{
47 int TRX; // RX (0) or TX (1)
48 char my_call_sign[CALLSIGN_MAX_SIZE];
49 char src_addr[CALLSIGN_MAX_SIZE], dst_addr[CALLSIGN_MAX_SIZE];
52 bool listen;
53 int bw; // in Hz
54 size_t frame_size;
55 int mode;
56} arq_info;
57
66
68typedef struct
69{
71 int mode;
72 size_t frame_size;
74
76typedef struct
77{
80 int trx;
83 int payload_mode; /* my TX mode (ISS direction) */
84 int peer_tx_mode; /* RX decoder mode = peer's TX mode (IRS direction) */
89
90extern arq_info arq_conn;
91extern fsm_handle arq_fsm;
92
99int arq_init(size_t frame_size, int mode);
100
104void arq_shutdown();
105
109void arq_tick_1hz(void);
110
115void arq_post_event(int event);
116
121bool arq_is_link_connected(void);
122
129int arq_queue_data(const uint8_t *data, size_t len);
130
136
141int arq_get_speed_level(void);
142
147int arq_get_payload_mode(void);
148
153int arq_get_control_mode(void);
154
160
166
172void arq_set_active_modem_mode(int mode, size_t frame_size);
173
180bool arq_handle_incoming_connect_frame(uint8_t *data, size_t frame_size);
181
188void arq_handle_incoming_frame(uint8_t *data, size_t frame_size, float rx_snr);
189
197void arq_update_link_metrics(int sync, float snr, int rx_status, bool frame_decoded);
198
205
212bool arq_wait_dequeue_action(arq_action_t *action, int timeout_ms);
213
220
226int arq_submit_tcp_cmd(const arq_cmd_msg_t *cmd);
227
234int arq_submit_tcp_payload(const uint8_t *data, size_t len);
235
240
246
250void call_remote();
251
256
257#endif
#define CALLSIGN_MAX_SIZE
Definition arq.h:24
int arq_submit_tcp_cmd(const arq_cmd_msg_t *cmd)
Submit parsed control command from TCP bridge to ARQ.
Definition arq.c:695
arq_info arq_conn
Definition arq.c:41
int arq_init(size_t frame_size, int mode)
Initialize ARQ subsystem.
Definition arq.c:508
int arq_submit_tcp_payload(const uint8_t *data, size_t len)
Submit payload bytes from TCP bridge to ARQ.
Definition arq.c:701
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:655
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:409
int arq_get_speed_level(void)
Get current ARQ speed level (gear).
Definition arq.c:638
bool arq_get_runtime_snapshot(arq_runtime_snapshot_t *snapshot)
Copy ARQ runtime snapshot.
Definition arq.c:679
void clear_connection_data()
Clear legacy ARQ connection state and buffers.
Definition arq.c:707
void arq_post_event(int event)
Post an FSM event to ARQ.
Definition arq.c:616
bool arq_wait_dequeue_action(arq_action_t *action, int timeout_ms)
Wait for next modem action.
Definition arq.c:673
arq_action_type_t
Action types emitted by ARQ for modem worker execution.
Definition arq.h:60
@ ARQ_ACTION_TX_PAYLOAD
Definition arq.h:63
@ ARQ_ACTION_TX_CONTROL
Definition arq.h:62
@ ARQ_ACTION_NONE
Definition arq.h:61
@ ARQ_ACTION_MODE_SWITCH
Definition arq.h:64
int arq_get_preferred_rx_mode(void)
Get ARQ-preferred receive mode for modem.
Definition arq.c:641
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:644
bool arq_handle_incoming_connect_frame(uint8_t *data, size_t frame_size)
Handle incoming compressed CALL/ACCEPT frame.
Definition arq.c:381
bool arq_try_dequeue_action(arq_action_t *action)
Try to dequeue next modem action without blocking.
Definition arq.c:667
void reset_arq_info(arq_info *arq_conn)
Reset external arq_info structure.
Definition arq.c:717
void callee_accept_connection()
Trigger callee-side accept flow in compatibility path.
Definition arq.c:732
void call_remote()
Trigger outgoing call attempt using current ARQ addresses.
Definition arq.c:731
fsm_handle arq_fsm
Definition arq.c:42
void arq_shutdown()
Shut down ARQ workers and release ARQ resources.
Definition arq.c:585
int arq_get_payload_mode(void)
Get active ARQ payload mode.
Definition arq.c:639
void arq_tick_1hz(void)
Execute 1 Hz ARQ maintenance tick.
Definition arq.c:614
bool arq_is_link_connected(void)
Check whether ARQ link is connected.
Definition arq.c:618
int arq_get_tx_backlog_bytes(void)
Get pending outbound payload backlog.
Definition arq.c:637
int arq_queue_data(const uint8_t *data, size_t len)
Queue outbound payload bytes for ARQ transmission.
Definition arq.c:623
int arq_get_preferred_tx_mode(void)
Get ARQ-preferred transmit mode for modem.
Definition arq.c:642
int arq_get_control_mode(void)
Get active ARQ control mode.
Definition arq.c:640
Single modem action item popped by modem TX worker.
Definition arq.h:69
size_t frame_size
Definition arq.h:72
int mode
Definition arq.h:71
arq_action_type_t type
Definition arq.h:70
Definition arq_events.h:50
Runtime ARQ connection and mode state shared across modules.
Definition arq.h:46
int bw
Definition arq.h:53
bool encryption
Definition arq.h:50
size_t frame_size
Definition arq.h:54
bool listen
Definition arq.h:52
int mode
Definition arq.h:55
int TRX
Definition arq.h:47
int call_burst_size
Definition arq.h:51
Snapshot of current ARQ runtime state for telemetry/decision making.
Definition arq.h:77
int tx_backlog_bytes
Definition arq.h:81
bool initialized
Definition arq.h:78
int speed_level
Definition arq.h:82
int trx
Definition arq.h:80
int peer_tx_mode
Definition arq.h:84
int preferred_rx_mode
Definition arq.h:86
int payload_mode
Definition arq.h:83
int control_mode
Definition arq.h:85
int preferred_tx_mode
Definition arq.h:87
bool connected
Definition arq.h:79
Thread-safe finite-state machine wrapper.
Definition fsm.h:59