18#include "rte/oal/memory/rte_mem_util.h"
19#include "rte/oal/log/rte_log.h"
61 size_t codec_bytes = 0U;
65 rte_mem_set(frame, 0,
sizeof(frame));
75 if ((saf != NULL) && saf->
enabled)
82 if (!
ab_gp_saf_train_wrap(saf, train_id, &frame[2], codec_bytes, saf_frame,
sizeof(saf_frame), &saf_len) ||
90 return (status == RTE_STATUS_OK);
103 rte_mem_set(m24, 0,
sizeof(*m24));
150 rte_mem_set(session, 0,
sizeof(*session));
166 rte_mem_set(&reply, 0,
sizeof(reply));
178 uint8_t train_id, uint32_t timestamp_ms)
198 (uint32_t)pos->
m_level, cycle, timestamp_ms);
201 RTE_EXAMPLE_LOG(
"cycle %u: ERTMS Msg 130 train %u: SH %s\n", cycle, (
unsigned int)train_id,
207 RTE_EXAMPLE_LOG(
"cycle %u: ERTMS Msg %u to train %u could not be staged\n", cycle,
208 (
unsigned int)reply.
nid_message, (
unsigned int)train_id);
230 (uint32_t)pos->
m_level, cycle, timestamp_ms);
232 if (!is_idle_heartbeat)
238 rte_mem_set(session, 0,
sizeof(*session));
264 rte_mem_set(&reply, 0,
sizeof(reply));
290 uint8_t held_count = 0U;
291 uint16_t route_id = 0U;
307 for (i = 0U; (i < held_count) && !found; i++)
309 bool already_in_ma =
false;
314 already_in_ma =
true;
320 route_id = held_routes[i];
374 rte_mem_set(&reply, 0,
sizeof(reply));
393 const uint8_t *payload,
size_t payload_len,
394 uint32_t cycle, uint32_t timestamp_ms)
420 if (sessions != NULL)
422 session = &sessions[train_id - 1U];
470 bool db_removed =
true;
490 "cycle %u: ERTMS EoM for train %u could not remove db train slot "
491 "(routes still held) - leaving session in_use to avoid session/db drift\n",
492 cycle, (
unsigned int)train_id);
495 if ((session != NULL) && db_removed)
ab_gp_saf_train_t * ab_gp_channel_saf_train(ab_gp_channel_handle_t handle)
This channel's train-link SaF termination (ab_gp_saf_train.h), or NULL for a NULL handle.
struct ab_gp_channel_context_s * ab_gp_channel_handle_t
Opaque handle over this component's own static per-process context.
rte_status_t ab_gp_channel_stage_relay(ab_gp_channel_handle_t handle, rte_example_relay_kind_t kind, uint8_t index, const uint8_t *bytes, size_t size)
Queues a relay-link send for this cycle - does not transmit yet.
Stage-then-commit output queue for this cycle's own DECISION output (ADR-034): the peer AB_SAMPLE and...
bool ab_gp_db_train_get_routes(const ab_gp_db_t *db, uint8_t train_id, uint16_t out_routes[RTE_EXAMPLE_MAX_ROUTES_PER_TRAIN], uint8_t *out_count)
Retrieves routes currently allocated to a train.
bool ab_gp_dispatch(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
Raises event to every state machine subscribed to it, in subscription-table order,...
Synchronous, statically-wired event dispatch for GP's per-entity procedure state machines (state_mach...
ab_gp_ertms_train_context_t * ab_gp_ertms_engine_get_train_context(uint8_t train_id)
Retrieves the ERTMS procedure context for a given train slot.
bool ab_gp_ertms_calc_ma_for_route(uint8_t train_id, uint16_t route_id, uint32_t ma_seq)
Computes a Movement Authority for a train on a given route.
bool ab_gp_ertms_update_train_position(uint8_t train_id, uint32_t nid_lrbg, uint32_t d_lrbg_m, rbc_q_dirlrbg_t q_dirlrbg, uint32_t v_train_kmh, uint32_t m_mode, uint32_t m_level, uint32_t cycle, uint32_t timestamp_ms)
Updates train position and evaluates segment/route occupancy.
bool ab_gp_ertms_validate_train_data(uint8_t train_id, uint32_t l_train_m, uint32_t v_maxtrain_kmh, uint8_t m_axleload, uint8_t m_loadinggauge, bool m_airtight, uint32_t timestamp_ms)
Validates train characteristics against site route topology.
bool ab_gp_ertms_extend_ma_for_route(uint8_t train_id, uint16_t route_id)
Extends an existing Movement Authority with an additional route.
Unified ERTMS Subset-026 Chapter 5 Operational Procedure Orchestrator.
bool rbc_train_codec_decode_train_to_track(const uint8_t *in_buffer, size_t buffer_size, rbc_train_inbound_msg_t *out_msg)
Decodes an inbound Train-to-Track message (Msg 129, 130, 132, 136, 146, 147, 150, 155,...
bool rbc_train_codec_encode_track_to_train(const rbc_train_outbound_msg_t *msg, uint8_t *out_buffer, size_t buffer_size, size_t *out_bytes_written)
Encodes an outbound Track-to-Train message (Msg 2, 3, 6, 8, 9, 15, 16, 18, 24, 33,...
#define RBC_MSG_TRAIN_TO_TRACK_POSITION_REPORT
#define RBC_MSG_TRAIN_TO_TRACK_INIT_SESSION
#define RBC_MSG_TRAIN_TO_TRACK_REQUEST_FOR_SHUNTING
#define RBC_MSG_TRAIN_TO_TRACK_END_OF_MISSION
#define RBC_MSG_TRAIN_TO_TRACK_VALIDATED_TRAIN_DATA
#define RBC_MSG_TRACK_TO_TRAIN_MOVEMENT_AUTHORITY
#define RBC_MSG_TRACK_TO_TRAIN_GENERAL_MESSAGE
#define RBC_MSG_TRAIN_TO_TRACK_ACK_EMERGENCY_STOP
#define RBC_MSG_TRAIN_TO_TRACK_MA_REQUEST
#define RBC_MSG_TRAIN_TO_TRACK_TERMINATE_SESSION
#define RBC_MSG_TRAIN_TO_TRACK_ACKNOWLEDGEMENT
#define RBC_MSG_TRAIN_TO_TRACK_SESSION_ESTABLISHED
@ AB_GP_EVENT_MA_REQUESTED
@ AB_GP_EVENT_MA_ACKNOWLEDGED
@ AB_GP_EVENT_POSITION_REPORTED
@ AB_GP_EVENT_END_OF_MISSION
static void handle_msg_129(const rbc_msg_129_validated_train_data_t *m129, ab_gp_ertms_train_context_t *ctx, uint8_t train_id, uint32_t timestamp_ms)
static rbc_timestamp_ms_t inbound_t_train(const rbc_train_inbound_msg_t *in)
static void build_config_msg_24(rbc_msg_24_general_message_t *m24, rbc_nid_engine_t nid_engine)
The one-time (per session) Msg 24 reply to Msg 155/136's own "confirm train data, inject config" step...
static rbc_timestamp_ms_t s_reply_t_train
static void handle_msg_155(ab_gp_channel_handle_t channel, ab_gp_train_session_t *session, ab_gp_db_t *db, uint8_t train_id, ab_gp_ertms_train_context_t *ctx, const rbc_msg_155_init_session_t *m155, uint32_t cycle, uint32_t timestamp_ms)
static void handle_msg_132(ab_gp_channel_handle_t channel, ab_gp_train_session_t *session, ab_gp_db_t *db, uint8_t train_id, ab_gp_ertms_train_context_t *ctx)
static void handle_msg_136(ab_gp_channel_handle_t channel, ab_gp_train_session_t *session, ab_gp_db_t *db, uint8_t train_id, ab_gp_ertms_train_context_t *ctx, const rbc_msg_136_position_report_t *m136, uint32_t cycle, uint32_t timestamp_ms)
static void handle_msg_130(ab_gp_channel_handle_t channel, uint8_t train_id, ab_gp_ertms_train_context_t *ctx, const rbc_msg_130_request_for_shunting_t *m130, uint32_t cycle, uint32_t timestamp_ms)
Msg 130 Request for Shunting (Subset-026 5.6): position update, decision (ab_gp_proc_shunting_handle_...
static bool build_and_stage_reply(ab_gp_channel_handle_t channel, uint8_t train_id, const rbc_train_outbound_msg_t *out_msg)
Builds the RBC_MSG_ERTMS_ENVELOPE wire frame (2-byte kind+train_id prefix + the codec's own encoded b...
bool ab_gp_proc_dispatch_train_inbound(ab_gp_channel_handle_t channel, ab_gp_train_session_t sessions[], ab_gp_db_t *db, uint8_t train_id, const uint8_t *payload, size_t payload_len, uint32_t cycle, uint32_t timestamp_ms)
Decodes one RBC_MSG_ERTMS_ENVELOPE payload and dispatches it into the ertms_procedures/ engine,...
Glue between RBC_MSG_ERTMS_ENVELOPE wire frames and the real Subset-026 procedure engine (ab_gp_ertms...
bool ab_gp_proc_ma_handle_ack(ab_gp_ertms_train_context_t *ctx, uint32_t ma_seq)
Handles Movement Authority Acknowledgement (Msg 146).
bool ab_gp_proc_session_handle_initiation(ab_gp_ertms_train_context_t *ctx, uint32_t cycle, uint32_t timestamp_ms)
Handles session initiation request (Msg 155 / P0).
bool ab_gp_proc_session_handle_termination(ab_gp_ertms_train_context_t *ctx, ab_gp_db_t *db)
Handles session termination (Msg 156 / Msg 41).
bool ab_gp_proc_session_handle_established(ab_gp_ertms_train_context_t *ctx, uint8_t m_version, uint32_t timestamp_ms)
Handles session established confirmation (Msg 159).
const char * ab_gp_proc_shunting_decision_name(ab_gp_shunting_decision_t decision)
bool ab_gp_proc_shunting_build_reply(ab_gp_shunting_decision_t decision, rbc_timestamp_ms_t t_train_reply, rbc_timestamp_ms_t t_train_request, rbc_nid_lrbg_t nid_lrbg, rbc_train_outbound_msg_t *out)
Builds the answer to a Msg 130: Msg 28 SH Authorised or Msg 27 SH Refused.
ab_gp_shunting_decision_t ab_gp_proc_shunting_handle_request(ab_gp_ertms_train_context_t *ctx, uint8_t train_id, uint32_t v_train_kmh)
Decides one Msg 130 Request for Shunting and applies the outcome.
ab_gp_shunting_decision_t
bool ab_gp_saf_envelope_encode(uint8_t train_id, const uint8_t *frame, size_t frame_len, uint8_t out[RBC_TRAIN_ENVELOPE_WIRE_SIZE])
Builds an RBC_MSG_SAF_ENVELOPE relay frame (RBC_TRAIN_ENVELOPE_WIRE_SIZE bytes).
bool ab_gp_saf_train_wrap(ab_gp_saf_train_t *s, uint8_t train_id, const uint8_t *pdu, size_t pdu_len, uint8_t *out_frame, size_t out_cap, size_t *out_len)
Protects one outbound application PDU for train slot train_id (only in DATA).
Train link safe communication (Subset-037 SaF) terminated inside A and B - REQ-SC-001,...
#define AB_GP_SAF_FRAME_MAX
Largest SaF frame one Train relay envelope carries.
bool ab_gp_train_handle_connect(ab_gp_db_t *db, uint8_t train_id)
Handles an inbound P0 (connect handshake) - wraps ab_gp_train_add() with the same env->train_id-as-ni...
bool ab_gp_train_remove(ab_gp_db_t *db, uint8_t train_id)
Removes a train on disconnect: resets db->trains[train_id-1] back to its all-zero/disconnected state.
bool ab_gp_train_handle_position_report(ab_gp_db_t *db, uint8_t train_id, uint32_t nid_lrbg)
Handles an inbound M136 (Position Report) - adds the train first (ab_gp_train_handle_connect()) if th...
#define RTE_EXAMPLE_LOG(...)
#define RTE_EXAMPLE_MAX_ROUTES_PER_TRAIN
#define RBC_TRAIN_ENVELOPE_WIRE_SIZE
#define RTE_EXAMPLE_MAX_TRAINS
uint64_t rbc_timestamp_ms_t
Timestamp in milliseconds (POSIX or ETCS T_TRAIN / T_RBC scale).
uint32_t rbc_nid_engine_t
ETCS On-board Engine Identifier / Train ID (24 bits in ETCS).
@ AB_GP_ERTMS_SESSION_IDLE
The RBC Train/IL/CTC scenario's shared wire envelope (ADR-029) - one fixed-size struct/frame reused f...
West/East site identity and the per-site config derived from it (ports, container host lookup) - see ...
@ RTE_EXAMPLE_RELAY_KIND_TRAIN
rbc_packet_21_gradient_profile_t p21
uint16_t route_ids[RTE_EXAMPLE_MAX_ROUTES_PER_TRAIN]
rbc_packet_5_linking_t p5
Complete ERTMS state and procedure context for one train slot.
ab_gp_ertms_session_state_t session_state
ab_gp_ertms_train_data_t train_data
ab_gp_ertms_ma_record_t ma
ab_gp_train_data_state_t state
One channel's train-link SaF termination.
bool ctc_ma_notify_pending
Msg 129: Validated Train Data.
rbc_speed_kmh_t v_maxtrain
Msg 130: Request for Shunting (Subset-026 8.6.2) - header plus a position report, same bare (no leadi...
rbc_packet_0_position_report_t position_report
rbc_train_to_track_header_t header
Msg 136: Train Position Report - carries Packet 0 OR Packet 1 (Subset-026 8.6.4: "Packet 0 or 1"),...
rbc_packet_0_position_report_t position_report
rbc_train_to_track_header_t header
Msg 155: Initiation of a Communication Session.
rbc_train_to_track_header_t header
Msg 24: General Message (National Values, TSRs, Text, Parameters).
rbc_track_to_train_header_t header
rbc_packet_3_national_values_t national_values
bool has_ma_request_params
rbc_packet_57_ma_request_params_t ma_request_params
rbc_packet_58_pr_params_t pr_params
rbc_q_dirlrbg_t q_dirlrbg
rbc_distance_m_t ma_length
rbc_speed_kmh_t v_nvshunt
rbc_speed_kmh_t v_nvunfit
rbc_distance_m_t d_cycloc_m
union rbc_train_inbound_msg_t::@156151041174124231025067150227167311270040326010 payload
union rbc_train_outbound_msg_t::@072257326371153356142277360163235337000010176256 payload