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_logic.c File Reference

Route<->train connect logic (GP) + its own GA callback registries - see ab_gp_logic.h. More...

#include "ab_gp_logic.h"
#include "rte/utils/lifecycle/rte_lifecycle.h"
#include "rte/utils/notify/rte_notify.h"
#include "rte/oal/log/rte_log.h"
#include "../../common/common_config.h"
#include "ab_siteGP.h"
#include "../train/ab_gp_train.h"
Include dependency graph for ab_gp_logic.c:

Go to the source code of this file.

Functions

 RTE_DECLARE_CALLBACK_LIST (ab_gp_logic_route_validator_list_t, ab_gp_logic_route_validator_fn, AB_GP_LOGIC_MAX_ROUTE_VALIDATORS)
 RTE_DECLARE_CALLBACK_LIST (ab_gp_logic_shunting_validator_list_t, ab_gp_logic_shunting_validator_fn, AB_GP_LOGIC_MAX_SHUNTING_VALIDATORS)
static bool route_validators_all_agree (uint16_t route_id, uint8_t train_id)
rte_status_t ab_gp_ga_register_init (ab_gp_logic_route_validator_fn fn, void *context)
rte_status_t ab_gp_ga_register_shunting_validator (ab_gp_logic_shunting_validator_fn fn, void *context)
bool ab_gp_logic_shunting_allowed (uint8_t train_id)
 Asks every registered shunting validator about train_id.
bool ab_gp_logic_connect_route_for_train (ab_gp_db_t *db, uint8_t train_id)
 Connects one train's own currently-reported route to it: looks up which route the balise at db->trains[train_id-1].last_nid_lrbg (ab_gp_train_get_last_position(), AB/GP/train/ab_gp_train.h) is placed in (site/'s own static balise table, ab_site.h), asks every registered GA validator whether connecting it to train_id is OK (ab_gp_ga_register_init() above - il/'s own validator is also where a not-yet-tracked route gets added, see that function's own doc), and if approved, connects it (AB/GP/db/ab_gp_db.h's own ab_gp_db_route_connect_train(), which fires its OWN registered-subscriber notification on success - this module itself does not notify GA, see this file's own module doc for why). Idempotent: calling this again with the same still-current position is a safe no-op, not a re-connect (already-connected is detected before any validator call, so it does not fire again for an unchanged position).
void ab_gp_logic_connect_routes_and_trains (ab_gp_db_t *db)
 THE cyclic sweep: calls ab_gp_logic_connect_route_for_train() for every currently-connected train (ab_gp_train_is_connected(), AB/GP/train/ab_gp_train.h). Safe to call every cycle unconditionally, whether or not any train reported a new position this cycle - see this function's own idempotence doc above.

Variables

static ab_gp_logic_route_validator_list_t g_validators
static ab_gp_logic_shunting_validator_list_t g_shunting_validators

Detailed Description

Route<->train connect logic (GP) + its own GA callback registries - see ab_gp_logic.h.

Definition in file ab_gp_logic.c.

Function Documentation

◆ RTE_DECLARE_CALLBACK_LIST() [1/2]

RTE_DECLARE_CALLBACK_LIST ( ab_gp_logic_route_validator_list_t ,
ab_gp_logic_route_validator_fn ,
AB_GP_LOGIC_MAX_ROUTE_VALIDATORS  )

Local makros Local types declarations

◆ RTE_DECLARE_CALLBACK_LIST() [2/2]

RTE_DECLARE_CALLBACK_LIST ( ab_gp_logic_shunting_validator_list_t ,
ab_gp_logic_shunting_validator_fn ,
AB_GP_LOGIC_MAX_SHUNTING_VALIDATORS  )

◆ route_validators_all_agree()

bool route_validators_all_agree ( uint16_t route_id,
uint8_t train_id )
static

Global variables declarations Local function declarations

Returns
true only if EVERY registered validator approves, AND at least one is registered - fail-safe default-deny, see ab_gp_ga_register_init()'s own doc.

Definition at line 237 of file ab_gp_logic.c.

◆ ab_gp_ga_register_init()

rte_status_t ab_gp_ga_register_init ( ab_gp_logic_route_validator_fn fn,
void * context )

Global functions

Definition at line 46 of file ab_gp_logic.c.

◆ ab_gp_ga_register_shunting_validator()

rte_status_t ab_gp_ga_register_shunting_validator ( ab_gp_logic_shunting_validator_fn fn,
void * context )

Definition at line 69 of file ab_gp_logic.c.

◆ ab_gp_logic_shunting_allowed()

bool ab_gp_logic_shunting_allowed ( uint8_t train_id)

Asks every registered shunting validator about train_id.

Returns
true only if at least one validator is registered and all approve.

Definition at line 92 of file ab_gp_logic.c.

◆ ab_gp_logic_connect_route_for_train()

bool ab_gp_logic_connect_route_for_train ( ab_gp_db_t * db,
uint8_t train_id )

Connects one train's own currently-reported route to it: looks up which route the balise at db->trains[train_id-1].last_nid_lrbg (ab_gp_train_get_last_position(), AB/GP/train/ab_gp_train.h) is placed in (site/'s own static balise table, ab_site.h), asks every registered GA validator whether connecting it to train_id is OK (ab_gp_ga_register_init() above - il/'s own validator is also where a not-yet-tracked route gets added, see that function's own doc), and if approved, connects it (AB/GP/db/ab_gp_db.h's own ab_gp_db_route_connect_train(), which fires its OWN registered-subscriber notification on success - this module itself does not notify GA, see this file's own module doc for why). Idempotent: calling this again with the same still-current position is a safe no-op, not a re-connect (already-connected is detected before any validator call, so it does not fire again for an unchanged position).

Returns
false if train_id is not a currently-connected train, it has not reported a position yet (last_nid_lrbg == 0), the reported NID_LRBG is not a balise this site's own layout knows about, no GA validator approved the connection (this includes the route already being assigned to a DIFFERENT train - never silently reassigned), or the actual connect itself failed. true if the route is now connected to this train (whether this call just did that, or it already was).

Definition at line 120 of file ab_gp_logic.c.

◆ ab_gp_logic_connect_routes_and_trains()

void ab_gp_logic_connect_routes_and_trains ( ab_gp_db_t * db)

THE cyclic sweep: calls ab_gp_logic_connect_route_for_train() for every currently-connected train (ab_gp_train_is_connected(), AB/GP/train/ab_gp_train.h). Safe to call every cycle unconditionally, whether or not any train reported a new position this cycle - see this function's own idempotence doc above.

Definition at line 219 of file ab_gp_logic.c.

Variable Documentation

◆ g_validators

ab_gp_logic_route_validator_list_t g_validators
static

Local variables declarations

Definition at line 33 of file ab_gp_logic.c.

◆ g_shunting_validators

ab_gp_logic_shunting_validator_list_t g_shunting_validators
static

Definition at line 34 of file ab_gp_logic.c.