|
HERMES Modem
Hermes ARQ/Broadcast modem
|
#include "arq_protocol.h"#include <string.h>#include <stdio.h>#include <stdatomic.h>#include "../modem/freedv/freedv_api.h"#include "../modem/framer.h"#include "arq.h"
Functions | |
| void | init_model (void) |
| int | arithmetic_encode (const char *msg, uint8_t *output) |
| int | arithmetic_decode (uint8_t *input, int max_len, char *output, int max_output) |
| const arq_mode_timing_t * | arq_protocol_mode_timing (int freedv_mode) |
| Look up mode timing entry for a FreeDV mode. | |
| 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. | |
| 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. | |
| uint8_t | arq_protocol_bw_token_from_hz (int bw_hz) |
| Map a configured bandwidth in Hz to an on-air BW token. | |
| int | arq_protocol_bw_hz_from_token (uint8_t bw_token) |
| Map an on-air BW token back to Hz. | |
| uint8_t | arq_protocol_encode_snr (float snr_db) |
| Encode a floating-point SNR (dB) into the snr_raw wire byte. | |
| float | arq_protocol_decode_snr (uint8_t snr_raw) |
| Decode snr_raw wire byte back to float dB. | |
| uint8_t | arq_protocol_encode_ack_delay (uint32_t delay_ms) |
| Encode ack_delay_ms to the 8-bit wire value (10ms units, max 2.55s). | |
| uint32_t | arq_protocol_decode_ack_delay (uint8_t raw) |
| Decode the 8-bit wire ack_delay to milliseconds. | |
| static int | build_ctrl (uint8_t *buf, size_t buf_len, uint8_t subtype, uint8_t session_id, uint8_t tx_seq, uint8_t rx_ack_seq, uint8_t flags, uint8_t snr_raw, uint8_t ack_delay_raw, const uint8_t *payload, size_t payload_len) |
| int | arq_protocol_build_ack (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t rx_ack_seq, uint8_t flags, uint8_t snr_raw, uint8_t ack_delay_raw) |
| ACK frame. | |
| int | arq_protocol_build_disconnect (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw) |
| DISCONNECT frame. | |
| int | arq_protocol_build_keepalive (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw) |
| KEEPALIVE frame. | |
| int | arq_protocol_build_keepalive_ack (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw) |
| KEEPALIVE_ACK frame. | |
| int | arq_protocol_build_turn_req (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t rx_ack_seq, uint8_t snr_raw) |
| TURN_REQ frame. | |
| int | arq_protocol_build_turn_ack (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw) |
| TURN_ACK frame. | |
| int | arq_protocol_build_mode_req (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw, int freedv_mode) |
| MODE_REQ frame. | |
| int | arq_protocol_build_mode_ack (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw, int freedv_mode) |
| MODE_ACK frame — accept peer's mode request. | |
| int | arq_protocol_build_data (uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t tx_seq, uint8_t rx_ack_seq, uint8_t flags, uint8_t snr_raw, uint8_t payload_valid, const uint8_t *payload, size_t payload_len) |
| DATA frame — 8-byte header + payload bytes. | |
| uint16_t | arq_protocol_callsign_crc16 (const char *callsign) |
| Compute CRC16-CCITT of an uppercase-normalised callsign. | |
| static int | encode_callsign_payload (const char *src, const char *dst, uint8_t *out, size_t out_cap) |
| static int | decode_callsign_payload (const uint8_t *in, size_t in_len, char *src_out, char *dst_out) |
| static int | encode_callsign_only_payload (const char *src, uint8_t *out, size_t out_cap) |
| static int | decode_callsign_only_payload (const uint8_t *in, size_t in_len, char *src_out) |
| static int | build_call_accept (uint8_t *buf, size_t buf_len, bool is_accept, uint8_t session_id, const char *src, const char *dst, int bw_hz) |
| int | arq_protocol_build_call (uint8_t *buf, size_t buf_len, uint8_t session_id, const char *src, const char *dst, int bw_hz) |
| Build a CALL frame. | |
| int | arq_protocol_build_accept (uint8_t *buf, size_t buf_len, uint8_t session_id, const char *src, const char *dst, int bw_hz) |
| Build an ACCEPT frame. | |
| static int | parse_call_accept (const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *src_out, char *dst_out, int *bw_hz_out) |
| int | arq_protocol_parse_call (const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *src_out, char *dst_out, int *bw_hz_out) |
| Parse a CALL frame; extract callsigns. | |
| int | arq_protocol_parse_accept (const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *src_out, char *dst_out, int *bw_hz_out) |
| Parse an ACCEPT frame; same layout as CALL. | |
| int | arq_protocol_build_cq (uint8_t *buf, size_t buf_len, const char *src, int bw_hz) |
| Build a compact DATAC13 CQ frame carrying source callsign and BW token. | |
| int | arq_protocol_parse_cq (const uint8_t *buf, size_t buf_len, char *src_out, int *bw_hz_out) |
| Parse a compact DATAC13 CQ frame. | |
Variables | |
| _Atomic int | arq_call_retry_slots = ARQ_CALL_RETRY_SLOTS_DEFAULT |
| _Atomic int | arq_accept_retry_slots = ARQ_ACCEPT_RETRY_SLOTS_DEFAULT |
| _Atomic int | arq_data_retry_slots = ARQ_DATA_RETRY_SLOTS_DEFAULT |
| _Atomic int | arq_disconnect_retry_slots = ARQ_DISCONNECT_RETRY_SLOTS_DEFAULT |
| const arq_mode_timing_t | arq_mode_table [] |
| const int | arq_mode_table_count |
|
extern |
|
extern |
| int arq_protocol_build_accept | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| const char * | src, | ||
| const char * | dst, | ||
| int | bw_hz | ||
| ) |
Build an ACCEPT frame.
| buf | Output buffer (caller-provided). |
| buf_len | Size of buf in bytes. |
| session_id | ARQ session identifier. |
| src | Local callsign. |
| dst | Remote callsign. |
| bw_hz | Accepted bandwidth in Hz. |
| int arq_protocol_build_ack | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | rx_ack_seq, | ||
| uint8_t | flags, | ||
| uint8_t | snr_raw, | ||
| uint8_t | ack_delay_raw | ||
| ) |
ACK frame.
flags = ARQ_FLAG_HAS_DATA when IRS has pending TX data.
| int arq_protocol_build_call | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| const char * | src, | ||
| const char * | dst, | ||
| int | bw_hz | ||
| ) |
Build a CALL frame.
| buf | Output buffer (caller-provided). |
| buf_len | Size of buf in bytes. |
| session_id | ARQ session identifier. |
| src | Local callsign. |
| dst | Remote callsign. |
| bw_hz | Requested bandwidth in Hz. |
| int arq_protocol_build_cq | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| const char * | src, | ||
| int | bw_hz | ||
| ) |
Build a compact DATAC13 CQ frame carrying source callsign and BW token.
| int arq_protocol_build_data | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | tx_seq, | ||
| uint8_t | rx_ack_seq, | ||
| uint8_t | flags, | ||
| uint8_t | snr_raw, | ||
| uint8_t | payload_valid, | ||
| const uint8_t * | payload, | ||
| size_t | payload_len | ||
| ) |
DATA frame — 8-byte header + payload bytes.
| buf | Output buffer (caller-provided). |
| buf_len | Size of buf in bytes. |
| session_id | ARQ session identifier. |
| tx_seq | TX sequence number. |
| rx_ack_seq | Last seq received from peer (piggybacked ACK). |
| flags | ARQ_FLAG_TURN_REQ | ARQ_FLAG_HAS_DATA (bitmask). |
| snr_raw | Local SNR encoded for wire. |
| payload_valid | Number of valid bytes in the payload slot. |
| payload | Payload bytes (must be <= buf_len - ARQ_FRAME_HDR_SIZE). |
| payload_len | Number of payload bytes. |
| int arq_protocol_build_disconnect | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | snr_raw | ||
| ) |
DISCONNECT frame.
| int arq_protocol_build_keepalive | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | snr_raw | ||
| ) |
KEEPALIVE frame.
| int arq_protocol_build_keepalive_ack | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | snr_raw | ||
| ) |
KEEPALIVE_ACK frame.
| int arq_protocol_build_mode_ack | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | snr_raw, | ||
| int | freedv_mode | ||
| ) |
MODE_ACK frame — accept peer's mode request.
| int arq_protocol_build_mode_req | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | snr_raw, | ||
| int | freedv_mode | ||
| ) |
MODE_REQ frame.
| buf | Output buffer (caller-provided). |
| buf_len | Size of buf in bytes. |
| session_id | ARQ session identifier. |
| snr_raw | Local SNR encoded for wire. |
| freedv_mode | Requested payload FreeDV mode (FREEDV_MODE_DATAC*). |
| int arq_protocol_build_turn_ack | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | snr_raw | ||
| ) |
TURN_ACK frame.
| int arq_protocol_build_turn_req | ( | uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t | session_id, | ||
| uint8_t | rx_ack_seq, | ||
| uint8_t | snr_raw | ||
| ) |
TURN_REQ frame.
| buf | Output buffer (caller-provided). |
| buf_len | Size of buf in bytes. |
| session_id | ARQ session identifier. |
| rx_ack_seq | Last seq received from current ISS (so ISS can flush pending retries). |
| snr_raw | Local SNR encoded for wire. |
| int arq_protocol_bw_hz_from_token | ( | uint8_t | bw_token | ) |
Map an on-air BW token back to Hz.
| uint8_t arq_protocol_bw_token_from_hz | ( | int | bw_hz | ) |
Map a configured bandwidth in Hz to an on-air BW token.
| uint16_t arq_protocol_callsign_crc16 | ( | const char * | callsign | ) |
Compute CRC16-CCITT of an uppercase-normalised callsign.
Used to encode/validate the DST field in CALL/ACCEPT frames.
| uint32_t arq_protocol_decode_ack_delay | ( | uint8_t | raw | ) |
Decode the 8-bit wire ack_delay to milliseconds.
| 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.
| float arq_protocol_decode_snr | ( | uint8_t | snr_raw | ) |
Decode snr_raw wire byte back to float dB.
| uint8_t arq_protocol_encode_ack_delay | ( | uint32_t | delay_ms | ) |
Encode ack_delay_ms to the 8-bit wire value (10ms units, max 2.55s).
| 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.
| uint8_t arq_protocol_encode_snr | ( | float | snr_db | ) |
Encode a floating-point SNR (dB) into the snr_raw wire byte.
| const arq_mode_timing_t * arq_protocol_mode_timing | ( | int | freedv_mode | ) |
Look up mode timing entry for a FreeDV mode.
| int arq_protocol_parse_accept | ( | const uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t * | session_id_out, | ||
| char * | src_out, | ||
| char * | dst_out, | ||
| int * | bw_hz_out | ||
| ) |
Parse an ACCEPT frame; same layout as CALL.
| int arq_protocol_parse_call | ( | const uint8_t * | buf, |
| size_t | buf_len, | ||
| uint8_t * | session_id_out, | ||
| char * | src_out, | ||
| char * | dst_out, | ||
| int * | bw_hz_out | ||
| ) |
Parse a CALL frame; extract callsigns.
| buf | Input frame buffer. |
| buf_len | Size of buf in bytes. |
| session_id_out | Receives the session_id byte. |
| src_out | Buffer for local (transmitting) callsign, CALLSIGN_MAX_SIZE bytes. |
| dst_out | Buffer for remote callsign, CALLSIGN_MAX_SIZE bytes. |
| bw_hz_out | Receives the requested bandwidth in Hz. |
| int arq_protocol_parse_cq | ( | const uint8_t * | buf, |
| size_t | buf_len, | ||
| char * | src_out, | ||
| int * | bw_hz_out | ||
| ) |
Parse a compact DATAC13 CQ frame.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
extern |
|
static |
| _Atomic int arq_accept_retry_slots = ARQ_ACCEPT_RETRY_SLOTS_DEFAULT |
| _Atomic int arq_call_retry_slots = ARQ_CALL_RETRY_SLOTS_DEFAULT |
| _Atomic int arq_data_retry_slots = ARQ_DATA_RETRY_SLOTS_DEFAULT |
| _Atomic int arq_disconnect_retry_slots = ARQ_DISCONNECT_RETRY_SLOTS_DEFAULT |
| const arq_mode_timing_t arq_mode_table[] |
| const int arq_mode_table_count |