RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
ab_gp_proc_ma.c File Reference

Implementation of ERTMS Subset-026 §5.5 Movement Authority (MA) Management. More...

#include "ab_gp_proc_ma.h"
#include "../state_machines/ab_gp_dispatch.h"
#include "../state_machines/session/ab_gp_session_fsm.h"
#include "rte/oal/memory/rte_mem_util.h"
#include "rte/utils/cast/rte_cast.h"
Include dependency graph for ab_gp_proc_ma.c:

Go to the source code of this file.

Functions

static bool distance_from_lrbg_to_route_end (const ab_site_ga_route_layout_t *route, uint32_t nid_lrbg, uint32_t *out_dist_m)
 Distance, in meters, from nid_lrbg's own balise to route's END signal, measured along the route's direction of travel from the absolute chainage of the two objects (ab_site_balise_t.chainage_m and ab_site_signal_t.chainage_m, both generated from the railML netElement sapi:chainage origins).
uint32_t ab_gp_proc_ma_remaining_length_m (const ab_site_ga_route_layout_t *route, uint32_t nid_lrbg, uint32_t d_lrbg_m)
 Computes the Movement Authority length actually REMAINING from a train's own last-KNOWN balise to route's end signal - a direct point-to-point distance along route's own segment chain from that balise's (nid_lrbg) own physical position to the end signal's own physical position, NOT "route->length_m minus however far the balise sits from the route's own START signal" - the two are NOT interchangeable (found live: an earlier version of this function computed the latter and got a real, confirmed-wrong answer - see the .c file's own implementation doc for the concrete counter-example). Measured from the balise, NOT from nid_lrbg plus d_lrbg_m's own distance past it - on direct instruction: MA length is anchored to the train's last KNOWN, site-data-backed reference point, not a continuously self-reported odometer offset past it (d_lrbg_m is accepted for a possible future use but not used in this computation today - see the .c file's own doc). A train connecting to (or being extended into) a route it is already partway through must NOT be granted the route's own full length regardless - found live: both this function's own caller below and the flat scheme's ab_ga_il_on_route_context_changed() (safeAPIRBC2oo2GA) were granting route->length_m unconditionally, regardless of the train's own reported position - a real overrun-risk shape (the train is told it has more track ahead of it than physically remains).
bool ab_gp_proc_ma_compute (ab_gp_ertms_train_context_t *ctx, const ab_site_ga_route_layout_t *route, uint32_t ma_seq)
 Computes and grants a new Movement Authority based on site track layout.
bool ab_gp_proc_ma_extend (ab_gp_ertms_train_context_t *ctx, const ab_site_ga_route_layout_t *additional_route)
 Extends an existing Movement Authority with an additional connected route.
bool ab_gp_proc_ma_shorten (ab_gp_ertms_train_context_t *ctx, uint32_t new_ma_length_m)
 Shortens an existing Movement Authority (Subset-026 §5.5.4 / Msg 9).
bool ab_gp_proc_ma_handle_ack (ab_gp_ertms_train_context_t *ctx, uint32_t ma_seq)
 Handles Movement Authority Acknowledgement (Msg 146).
void ab_gp_proc_ma_revoke (ab_gp_ertms_train_context_t *ctx)
 Revokes active Movement Authority (e.g. during emergency or termination).

Detailed Description

Implementation of ERTMS Subset-026 §5.5 Movement Authority (MA) Management.

Definition in file ab_gp_proc_ma.c.

Function Documentation

◆ distance_from_lrbg_to_route_end()

bool distance_from_lrbg_to_route_end ( const ab_site_ga_route_layout_t * route,
uint32_t nid_lrbg,
uint32_t * out_dist_m )
static

Distance, in meters, from nid_lrbg's own balise to route's END signal, measured along the route's direction of travel from the absolute chainage of the two objects (ab_site_balise_t.chainage_m and ab_site_signal_t.chainage_m, both generated from the railML netElement sapi:chainage origins).

This is the Movement Authority rule (Subset-026): the MA length is measured from the LRBG, so it is distance(LRBG -> end signal) - overlap, whatever the route's authoring:

  • a balise BEFORE the route's start signal counts the gap to the start signal (the train has not entered the route yet; the MA covers the gap and the route);
  • a balise inside the route counts only what is left;
  • the result does not depend on how netElements were split at switches, on a route's trigger-balise entry, or on the authored lengthM (which need not equal the chainage span). Replaces three different rules (a trigger-balise shortcut, a segment-chain walk and a fall back to the authored length) that gave different results for identical geometry - see safety_quality/MA_LENGTH_ANALYSIS_2026-09-21.md.
Returns
true and sets *out_dist_m (0 if the balise is at or past the end signal); false if nid_lrbg is not a known balise or the route's end signal is not a known signal.

Definition at line 31 of file ab_gp_proc_ma.c.

◆ ab_gp_proc_ma_remaining_length_m()

uint32_t ab_gp_proc_ma_remaining_length_m ( const ab_site_ga_route_layout_t * route,
uint32_t nid_lrbg,
uint32_t d_lrbg_m )

Computes the Movement Authority length actually REMAINING from a train's own last-KNOWN balise to route's end signal - a direct point-to-point distance along route's own segment chain from that balise's (nid_lrbg) own physical position to the end signal's own physical position, NOT "route->length_m minus however far the balise sits from the route's own START signal" - the two are NOT interchangeable (found live: an earlier version of this function computed the latter and got a real, confirmed-wrong answer - see the .c file's own implementation doc for the concrete counter-example). Measured from the balise, NOT from nid_lrbg plus d_lrbg_m's own distance past it - on direct instruction: MA length is anchored to the train's last KNOWN, site-data-backed reference point, not a continuously self-reported odometer offset past it (d_lrbg_m is accepted for a possible future use but not used in this computation today - see the .c file's own doc). A train connecting to (or being extended into) a route it is already partway through must NOT be granted the route's own full length regardless - found live: both this function's own caller below and the flat scheme's ab_ga_il_on_route_context_changed() (safeAPIRBC2oo2GA) were granting route->length_m unconditionally, regardless of the train's own reported position - a real overrun-risk shape (the train is told it has more track ahead of it than physically remains).

Falls back to the FULL route->length_m (the previously unconditional behavior) if nid_lrbg cannot be resolved to a balise on route's own segment chain at all (e.g. no position report yet, or the reported balise belongs to a different route/segment entirely) - never guesses past what site data can actually support; this is also the correct fallback for a genuine forward extension (the additional route's own balises legitimately do not include the train's current one yet).

Implemented once, here, since only GP has direct access to the physical segment/balise tables (ab_siteGP.h, ab_site_get_segment()/ab_site_get_balise()) this computation needs - GA's own ab_site_ga_route_layout_t alone (length_m, opaque segment_ids[]) cannot do it. Exposed to GA via ga_interface.h for the flat scheme's own identical use.

Parameters
routeThe route being granted/extended - GA's own ab_site_ga_route_layout_t.
nid_lrbgTrain's own last-reported NID_LRBG (M136/flat scheme position report alike) - the balise this computation is anchored to.
d_lrbg_mTrain's own last-reported D_LRBG (distance past nid_lrbg, meters) - accepted but NOT used in this computation, see this function's own doc above.
Returns
Remaining MA length in meters - never more than route->length_m, never negative (clamped to 0 if the train's own reported position is already past the route's own end).

Definition at line 53 of file ab_gp_proc_ma.c.

◆ ab_gp_proc_ma_compute()

bool ab_gp_proc_ma_compute ( ab_gp_ertms_train_context_t * ctx,
const ab_site_ga_route_layout_t * route,
uint32_t ma_seq )

Computes and grants a new Movement Authority based on site track layout.

Parameters
[in,out]ctxTrain ERTMS context.
[in]routeSite route layout defining signals, segments, and balises (GA's own ab_site_ga_route_layout_t - GP no longer owns route topology, see ab_siteGA.h's own doc).
[in]ma_seqMonotonic MA sequence counter.
Returns
true if MA successfully computed and granted, false otherwise.

Definition at line 83 of file ab_gp_proc_ma.c.

◆ ab_gp_proc_ma_extend()

bool ab_gp_proc_ma_extend ( ab_gp_ertms_train_context_t * ctx,
const ab_site_ga_route_layout_t * additional_route )

Extends an existing Movement Authority with an additional connected route.

Parameters
[in,out]ctxTrain ERTMS context.
[in]additional_routeSubsequent route layout to append.
Returns
true if MA successfully extended, false otherwise.

Definition at line 214 of file ab_gp_proc_ma.c.

◆ ab_gp_proc_ma_shorten()

bool ab_gp_proc_ma_shorten ( ab_gp_ertms_train_context_t * ctx,
uint32_t new_ma_length_m )

Shortens an existing Movement Authority (Subset-026 §5.5.4 / Msg 9).

Parameters
[in,out]ctxTrain ERTMS context.
[in]new_ma_length_mNew reduced Limit of Authority in meters.
Returns
true if MA successfully shortened, false otherwise.

Definition at line 248 of file ab_gp_proc_ma.c.

◆ ab_gp_proc_ma_handle_ack()

bool ab_gp_proc_ma_handle_ack ( ab_gp_ertms_train_context_t * ctx,
uint32_t ma_seq )

Handles Movement Authority Acknowledgement (Msg 146).

Parameters
[in,out]ctxTrain ERTMS context.
[in]ma_seqSequence counter echoed in Msg 146.
Returns
true if sequence matches active MA, false otherwise.

Definition at line 266 of file ab_gp_proc_ma.c.

◆ ab_gp_proc_ma_revoke()

void ab_gp_proc_ma_revoke ( ab_gp_ertms_train_context_t * ctx)

Revokes active Movement Authority (e.g. during emergency or termination).

Parameters
[in,out]ctxTrain ERTMS context.

Definition at line 276 of file ab_gp_proc_ma.c.