Mercury Modem
Mercury ARQ/Broadcast modem
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
arq_fsm.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "arq.h"
#include "arq_timing.h"
#include "arq_protocol.h"
#include "carousel.h"
Include dependency graph for arq_fsm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  arq_event_t
 ARQ event with all possible payload fields. More...
 
struct  arq_session_t
 
struct  arq_fsm_callbacks_t
 

Enumerations

enum  arq_conn_state_t {
  ARQ_CONN_DISCONNECTED = 0 , ARQ_CONN_LISTENING = 1 , ARQ_CONN_CALLING = 2 , ARQ_CONN_ACCEPTING = 3 ,
  ARQ_CONN_CONNECTED = 4 , ARQ_CONN_DISCONNECTING = 5 , ARQ_CONN__COUNT
}
 
enum  arq_teardown_t {
  ARQ_TD_NONE = 0 , ARQ_TD_LISTEN_OFF , ARQ_TD_DRAINING , ARQ_TD_SENT ,
  ARQ_TD_REPLYING , ARQ_TD_NOTIFYING
}
 
enum  arq_event_id_t {
  ARQ_EV_APP_LISTEN = 0 , ARQ_EV_APP_STOP_LISTEN , ARQ_EV_APP_CONNECT , ARQ_EV_APP_DISCONNECT ,
  ARQ_EV_APP_DATA_READY , ARQ_EV_RX_CALL , ARQ_EV_RX_ACCEPT , ARQ_EV_RX_DISCONNECT ,
  ARQ_EV_TIMER_RETRY , ARQ_EV_TIMER_ACK , ARQ_EV_TX_STARTED , ARQ_EV_TX_COMPLETE ,
  ARQ_EV_RX_CAROUSEL , ARQ_EV_TIMER_CAROUSEL , ARQ_EV_RX_PATTERN , ARQ_EV__COUNT
}
 
enum  arq_listen_end_t { ARQ_LISTEN_GOES_ON = 0 , ARQ_LISTEN_ENDS_IN_SESSION , ARQ_LISTEN_ENDS_RELEASED }
 

Functions

void arq_fsm_set_callbacks (const arq_fsm_callbacks_t *cbs)
 Register FSM action callbacks (call once before first dispatch).
 
void arq_fsm_set_timing (arq_timing_ctx_t *timing)
 Register timing context for recording (call once at init).
 
void arq_fsm_init (arq_session_t *sess)
 Initialise a session structure to DISCONNECTED state.
 
void arq_fsm_release (arq_session_t *sess)
 
void arq_fsm_dispatch (arq_session_t *sess, const arq_event_t *event)
 Dispatch an event through both FSM levels.
 
arq_listen_end_t arq_fsm_dispatch_ends_listening (arq_session_t *sess, const arq_event_t *event)
 arq_fsm_dispatch(), and whether that one event ended a spell of listening for calls (LISTENING or ACCEPTING, to any other state), and how.
 
int arq_fsm_timeout_ms (const arq_session_t *sess, uint64_t now)
 Return milliseconds until the next deadline, or INT_MAX if idle.
 
int arq_call_carrier (const arq_session_t *sess)
 The carrier the next CALL goes out on: the control mode for the first ARQ_CALL_FAST_SLOTS, then MFSK and the control mode alternately.
 
bool arq_fsm_expect_pattern (const arq_session_t *sess, uint64_t now)
 Whether a pattern can arrive now (the modem's detector runs only then).
 
int arq_fsm_channel_keyed (const arq_session_t *sess)
 Why the channel is busy now (a CAR_KEYED_* sign), 0 when clear: the listen-before-talk test the FSM keys by.
 
const char * arq_conn_state_name (arq_conn_state_t s)
 Human-readable name for a connection state (for log output).
 
bool arq_conn_state_has_peer (arq_conn_state_t s)
 The link to the peer exists: CONNECTED, or DISCONNECTING (the teardown is still an exchange with that peer).
 
const char * arq_event_name (arq_event_id_t ev)
 Human-readable name for an event (for log output).
 

Enumeration Type Documentation

◆ arq_conn_state_t

Enumerator
ARQ_CONN_DISCONNECTED 
ARQ_CONN_LISTENING 
ARQ_CONN_CALLING 
ARQ_CONN_ACCEPTING 
ARQ_CONN_CONNECTED 
ARQ_CONN_DISCONNECTING 
ARQ_CONN__COUNT 

◆ arq_event_id_t

Enumerator
ARQ_EV_APP_LISTEN 
ARQ_EV_APP_STOP_LISTEN 
ARQ_EV_APP_CONNECT 
ARQ_EV_APP_DISCONNECT 
ARQ_EV_APP_DATA_READY 
ARQ_EV_RX_CALL 
ARQ_EV_RX_ACCEPT 
ARQ_EV_RX_DISCONNECT 
ARQ_EV_TIMER_RETRY 
ARQ_EV_TIMER_ACK 
ARQ_EV_TX_STARTED 
ARQ_EV_TX_COMPLETE 
ARQ_EV_RX_CAROUSEL 
ARQ_EV_TIMER_CAROUSEL 
ARQ_EV_RX_PATTERN 
ARQ_EV__COUNT 

◆ arq_listen_end_t

Enumerator
ARQ_LISTEN_GOES_ON 
ARQ_LISTEN_ENDS_IN_SESSION 
ARQ_LISTEN_ENDS_RELEASED 

◆ arq_teardown_t

Enumerator
ARQ_TD_NONE 
ARQ_TD_LISTEN_OFF 
ARQ_TD_DRAINING 
ARQ_TD_SENT 
ARQ_TD_REPLYING 
ARQ_TD_NOTIFYING 

Function Documentation

◆ arq_call_carrier()

int arq_call_carrier ( const arq_session_t *  sess)

The carrier the next CALL goes out on: the control mode for the first ARQ_CALL_FAST_SLOTS, then MFSK and the control mode alternately.

◆ arq_conn_state_has_peer()

bool arq_conn_state_has_peer ( arq_conn_state_t  s)

The link to the peer exists: CONNECTED, or DISCONNECTING (the teardown is still an exchange with that peer).

Energy on the channel in these states is the peer, not occupancy (the busy detector's mute, modem.c).

◆ arq_conn_state_name()

const char * arq_conn_state_name ( arq_conn_state_t  s)

Human-readable name for a connection state (for log output).

◆ arq_event_name()

const char * arq_event_name ( arq_event_id_t  ev)

Human-readable name for an event (for log output).

◆ arq_fsm_channel_keyed()

int arq_fsm_channel_keyed ( const arq_session_t *  sess)

Why the channel is busy now (a CAR_KEYED_* sign), 0 when clear: the listen-before-talk test the FSM keys by.

◆ arq_fsm_dispatch()

void arq_fsm_dispatch ( arq_session_t *  sess,
const arq_event_t *  event 
)

Dispatch an event through both FSM levels.

Runs transition logic, calls action callbacks, and updates deadlines. Must be called from the single ARQ event-loop thread (no locking inside).

Parameters
sessActive session.
eventEvent to process.

◆ arq_fsm_dispatch_ends_listening()

arq_listen_end_t arq_fsm_dispatch_ends_listening ( arq_session_t *  sess,
const arq_event_t *  event 
)

arq_fsm_dispatch(), and whether that one event ended a spell of listening for calls (LISTENING or ACCEPTING, to any other state), and how.

The MFSK call listeners must drop what they hold when such a spell ends – above all at a scanning host's LISTEN OFF, whose LISTEN ON follows within a millisecond, often in the same batch of events, and usually on another channel. Checked per event, so a spell that ends and restarts at once is still seen (arq.c counts them for the modem).

ARQ_LISTEN_ENDS_RELEASED is the hop itself: no session goes on, so the control and payload decoders can drop what they hold as well. In a session they cannot: the control decoder is carrying it.

◆ arq_fsm_expect_pattern()

bool arq_fsm_expect_pattern ( const arq_session_t *  sess,
uint64_t  now 
)

Whether a pattern can arrive now (the modem's detector runs only then).

◆ arq_fsm_init()

void arq_fsm_init ( arq_session_t *  sess)

Initialise a session structure to DISCONNECTED state.

Parameters
sessSession to initialise.

◆ arq_fsm_release()

void arq_fsm_release ( arq_session_t *  sess)

◆ arq_fsm_set_callbacks()

void arq_fsm_set_callbacks ( const arq_fsm_callbacks_t *  cbs)

Register FSM action callbacks (call once before first dispatch).

◆ arq_fsm_set_timing()

void arq_fsm_set_timing ( arq_timing_ctx_t *  timing)

Register timing context for recording (call once at init).

Parameters
timingPointer to the arq_timing_ctx_t to record into.

◆ arq_fsm_timeout_ms()

int arq_fsm_timeout_ms ( const arq_session_t *  sess,
uint64_t  now 
)

Return milliseconds until the next deadline, or INT_MAX if idle.

Used by the event loop's blocking wait to set a poll timeout.

Parameters
sessActive session.
nowCurrent monotonic time in milliseconds.
Returns
Milliseconds to wait (0 = fire immediately, INT_MAX = no deadline).