|
HERMES Modem
Hermes ARQ/Broadcast modem
|
#include "arq.h"#include "arq_fsm.h"#include "arq_protocol.h"#include "arq_timing.h"#include "arq_modem.h"#include "arq_channels.h"#include "fsm.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include <pthread.h>#include <stdlib.h>#include <time.h>#include <errno.h>#include <limits.h>#include <stdatomic.h>#include "../common/hermes_log.h"#include "../common/defines_modem.h"#include "../common/ring_buffer_posix.h"#include "../data_interfaces/tcp_interfaces.h"#include "../modem/framer.h"#include "../modem/freedv/freedv_api.h"
Macros | |
| #define | LOG_COMP "arq" |
| #define | APP_TX_BUF_SIZE (64 * 1024) |
| #define | ARQ_EV_QUEUE_CAP 64 |
Functions | |
| void | tnc_send_pending (void) |
| void | tnc_send_cancelpending (void) |
| void | tnc_send_connected (void) |
| void | tnc_send_cqframe (const char *source_call, int bw_hz) |
| void | tnc_send_disconnected (void) |
| void | tnc_send_buffer (uint32_t bytes) |
| void | init_model (void) |
| static void | evq_push (const arq_event_t *ev) |
| static bool | evq_pop_locked (arq_event_t *ev) |
| static void | ptt_event_inject (int mode, bool ptt_on) |
| static void | cb_send_tx_frame (int packet_type, int mode, size_t frame_size, const uint8_t *frame) |
| static void | cb_notify_connected (const char *remote_call) |
| static void | cb_notify_pending (const char *remote_call) |
| static void | cb_notify_cancelpending (void) |
| static void | cb_notify_disconnected (bool to_no_client) |
| static void | cb_deliver_rx_data (const uint8_t *data, size_t len) |
| static int | cb_tx_backlog (void) |
| static int | cb_tx_read (uint8_t *buf, size_t len) |
| static void | cb_send_buffer_status (int backlog_bytes) |
| static int | normalize_bandwidth_hz (int bw_hz) |
| static int | active_session_bandwidth_hz (void) |
| int | arq_effective_bandwidth_hz (void) |
| Get the effective ARQ bandwidth cap in Hz used for mode gating. | |
| int | arq_reported_bandwidth_hz (void) |
| Get the configured ARQ bandwidth token to report to VARA clients. | |
| bool | arq_bandwidth_allows_mode (int mode) |
| Check whether the current ARQ bandwidth cap allows a modem mode. | |
| static void | handle_cmd (const arq_cmd_msg_t *msg) |
| static void * | arq_cmd_bridge_worker (void *arg) |
| static void * | arq_payload_bridge_worker (void *arg) |
| static void * | arq_event_loop_worker (void *arg) |
| bool | arq_handle_incoming_connect_frame (uint8_t *data, size_t frame_size) |
| Handle incoming compressed CALL/ACCEPT frame. | |
| bool | arq_handle_incoming_cq_frame (uint8_t *data, size_t frame_size) |
| Handle incoming compact CQ frame and emit host-side CQFRAME notification. | |
| void | arq_notify_cq_tx_started (void) |
| Emit VARA-style async status for an outgoing CQFRAME transmission. | |
| void | arq_notify_cq_tx_complete (void) |
| void | arq_handle_incoming_frame (uint8_t *data, size_t frame_size, float rx_snr) |
| Handle incoming regular ARQ control/data frame. | |
| int | arq_init (size_t frame_size, int mode) |
| Initialize ARQ subsystem. | |
| void | arq_shutdown (void) |
| Shut down ARQ workers and release ARQ resources. | |
| void | arq_tick_1hz (void) |
| Execute 1 Hz ARQ maintenance tick. | |
| void | arq_post_event (int event) |
| Post an FSM event to ARQ. | |
| bool | arq_is_link_connected (void) |
| Check whether ARQ link is connected. | |
| int | arq_queue_data (const uint8_t *data, size_t len) |
| Queue outbound payload bytes for ARQ transmission. | |
| int | arq_get_tx_backlog_bytes (void) |
| Get pending outbound payload backlog. | |
| int | arq_get_speed_level (void) |
| Get current ARQ speed level (gear). | |
| int | arq_get_payload_mode (void) |
| Get active ARQ payload mode. | |
| int | arq_get_control_mode (void) |
| Get active ARQ control mode. | |
| int | arq_get_preferred_rx_mode (void) |
| Get ARQ-preferred receive mode for modem. | |
| int | arq_get_preferred_tx_mode (void) |
| Get ARQ-preferred transmit mode for modem. | |
| void | arq_set_active_modem_mode (int mode, size_t frame_size) |
| Inform ARQ of modem mode/frame size actually active in modem. | |
| void | arq_update_link_metrics (int sync, float snr, int rx_status, bool frame_decoded) |
| Feed decoder/link metrics into ARQ adaptation. | |
| bool | arq_try_dequeue_action (arq_action_t *action) |
| Try to dequeue next modem action without blocking. | |
| bool | arq_wait_dequeue_action (arq_action_t *action, int timeout_ms) |
| Wait for next modem action. | |
| bool | arq_get_runtime_snapshot (arq_runtime_snapshot_t *snapshot) |
| Copy ARQ runtime snapshot. | |
| int | arq_submit_tcp_cmd (const arq_cmd_msg_t *cmd) |
| Submit parsed control command from TCP bridge to ARQ. | |
| int | arq_submit_tcp_payload (const uint8_t *data, size_t len) |
| Submit payload bytes from TCP bridge to ARQ. | |
| void | clear_connection_data (void) |
| Clear legacy ARQ connection state and buffers. | |
| void | arq_set_retry_slots (int slots) |
| Set runtime retry slot counts. | |
| void | reset_arq_info (arq_info *conn) |
| Reset external arq_info structure. | |
| void | call_remote (void) |
| Trigger outgoing call attempt using current ARQ addresses. | |
| void | callee_accept_connection (void) |
| Trigger callee-side accept flow in compatibility path. | |
Variables | |
| arq_info | arq_conn |
| fsm_handle | arq_fsm |
| cbuf_handle_t | data_tx_buffer_arq |
| cbuf_handle_t | data_tx_buffer_arq_control |
| cbuf_handle_t | data_rx_buffer_arq |
| static arq_session_t | g_sess |
| static arq_timing_ctx_t | g_timing |
| static uint8_t | g_app_tx_storage [APP_TX_BUF_SIZE] |
| static cbuf_handle_t | g_app_tx_buf |
| static pthread_mutex_t | g_app_tx_mtx = PTHREAD_MUTEX_INITIALIZER |
| static arq_event_t | g_evq [ARQ_EV_QUEUE_CAP] |
| static size_t | g_evq_head |
| static size_t | g_evq_tail |
| static size_t | g_evq_count |
| static pthread_mutex_t | g_evq_lock = PTHREAD_MUTEX_INITIALIZER |
| static pthread_cond_t | g_evq_cond = PTHREAD_COND_INITIALIZER |
| static arq_channel_bus_t | g_bus |
| static pthread_t | g_loop_tid |
| static pthread_t | g_cmd_tid |
| static pthread_t | g_payload_tid |
| static volatile bool | g_running |
| static volatile bool | g_initialized |
| #define APP_TX_BUF_SIZE (64 * 1024) |
| #define ARQ_EV_QUEUE_CAP 64 |
| #define LOG_COMP "arq" |
|
static |
| bool arq_bandwidth_allows_mode | ( | int | mode | ) |
Check whether the current ARQ bandwidth cap allows a modem mode.
| mode | FreeDV mode value. |
|
static |
| int arq_effective_bandwidth_hz | ( | void | ) |
Get the effective ARQ bandwidth cap in Hz used for mode gating.
|
static |
| int arq_get_control_mode | ( | void | ) |
Get active ARQ control mode.
| int arq_get_payload_mode | ( | void | ) |
Get active ARQ payload mode.
| int arq_get_preferred_rx_mode | ( | void | ) |
Get ARQ-preferred receive mode for modem.
| int arq_get_preferred_tx_mode | ( | void | ) |
Get ARQ-preferred transmit mode for modem.
| bool arq_get_runtime_snapshot | ( | arq_runtime_snapshot_t * | snapshot | ) |
Copy ARQ runtime snapshot.
| snapshot | Output snapshot pointer. |
| int arq_get_speed_level | ( | void | ) |
Get current ARQ speed level (gear).
| int arq_get_tx_backlog_bytes | ( | void | ) |
Get pending outbound payload backlog.
| bool arq_handle_incoming_connect_frame | ( | uint8_t * | data, |
| size_t | frame_size | ||
| ) |
Handle incoming compressed CALL/ACCEPT frame.
| data | Frame bytes. |
| frame_size | Frame length in bytes. |
| bool arq_handle_incoming_cq_frame | ( | uint8_t * | data, |
| size_t | frame_size | ||
| ) |
Handle incoming compact CQ frame and emit host-side CQFRAME notification.
| data | Incoming frame bytes. |
| frame_size | Frame length in bytes. |
| void arq_handle_incoming_frame | ( | uint8_t * | data, |
| size_t | frame_size, | ||
| float | rx_snr | ||
| ) |
Handle incoming regular ARQ control/data frame.
| data | Frame bytes. |
| frame_size | Frame length in bytes. |
| rx_snr | Local receive SNR at decode time (dB); 0.0 = unknown. |
| int arq_init | ( | size_t | frame_size, |
| int | mode | ||
| ) |
Initialize ARQ subsystem.
| frame_size | Active modem frame size in bytes. |
| mode | Initial modem mode. |
| bool arq_is_link_connected | ( | void | ) |
Check whether ARQ link is connected.
| void arq_notify_cq_tx_complete | ( | void | ) |
| void arq_notify_cq_tx_started | ( | void | ) |
Emit VARA-style async status for an outgoing CQFRAME transmission.
VARA clients such as varim treat CQFRAME as a pending operation and expect PENDING/CANCELPENDING around the actual send lifecycle.
|
static |
| void arq_post_event | ( | int | event | ) |
Post an FSM event to ARQ.
| event | Event identifier from fsm.h. |
| int arq_queue_data | ( | const uint8_t * | data, |
| size_t | len | ||
| ) |
Queue outbound payload bytes for ARQ transmission.
| data | Pointer to payload bytes. |
| len | Number of bytes to queue. |
| int arq_reported_bandwidth_hz | ( | void | ) |
Get the configured ARQ bandwidth token to report to VARA clients.
| void arq_set_active_modem_mode | ( | int | mode, |
| size_t | frame_size | ||
| ) |
Inform ARQ of modem mode/frame size actually active in modem.
| mode | Active FreeDV mode. |
| frame_size | Active frame size in bytes. |
| void arq_set_retry_slots | ( | int | slots | ) |
Set runtime retry slot counts.
Updates CALL, ACCEPT, and DATA retry counters used by the ARQ FSM. DISCONNECT retries are left at the compiled default. Pass 0 to restore all counters to compiled defaults.
| slots | Number of retry slots, or 0 to restore defaults. |
| void arq_shutdown | ( | void | ) |
Shut down ARQ workers and release ARQ resources.
| int arq_submit_tcp_cmd | ( | const arq_cmd_msg_t * | cmd | ) |
Submit parsed control command from TCP bridge to ARQ.
| cmd | Command message. |
| int arq_submit_tcp_payload | ( | const uint8_t * | data, |
| size_t | len | ||
| ) |
Submit payload bytes from TCP bridge to ARQ.
| data | Payload bytes. |
| len | Payload length in bytes. |
| void arq_tick_1hz | ( | void | ) |
Execute 1 Hz ARQ maintenance tick.
| bool arq_try_dequeue_action | ( | arq_action_t * | action | ) |
Try to dequeue next modem action without blocking.
| action | Output action item. |
| void arq_update_link_metrics | ( | int | sync, |
| float | snr, | ||
| int | rx_status, | ||
| bool | frame_decoded | ||
| ) |
Feed decoder/link metrics into ARQ adaptation.
| sync | Decoder sync flag. |
| snr | Estimated SNR. |
| rx_status | Decoder RX status flags. |
| frame_decoded | True when a frame decoded this cycle. |
| bool arq_wait_dequeue_action | ( | arq_action_t * | action, |
| int | timeout_ms | ||
| ) |
Wait for next modem action.
| action | Output action item. |
| timeout_ms | Wait timeout in milliseconds. |
| void call_remote | ( | void | ) |
Trigger outgoing call attempt using current ARQ addresses.
| void callee_accept_connection | ( | void | ) |
Trigger callee-side accept flow in compatibility path.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| void clear_connection_data | ( | void | ) |
Clear legacy ARQ connection state and buffers.
|
static |
|
static |
|
static |
|
extern |
|
static |
|
static |
| void reset_arq_info | ( | arq_info * | arq_conn | ) |
Reset external arq_info structure.
| arq_conn | Pointer to structure to reset. |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
| arq_info arq_conn |
| fsm_handle arq_fsm |
|
extern |
|
extern |
|
extern |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |