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_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
}
 

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.
 
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).
 
const char * arq_conn_state_name (arq_conn_state_t s)
 Human-readable name for a connection state (for log output).
 
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 

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_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_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_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).