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_session.c
Go to the documentation of this file.
1
7
10#include "rte/oal/memory/rte_mem_util.h"
11
12/* Supported ETCS Baselines: Baseline 2 (0x10) and Baseline 3 (0x20) */
13#define RBC_SUPPORTED_ETCS_BASELINE_2 0x10U
14#define RBC_SUPPORTED_ETCS_BASELINE_3 0x20U
15
16void ab_gp_proc_session_init(ab_gp_ertms_train_context_t *ctx, uint8_t train_id, uint32_t nid_engine)
17{
18 if (ctx == NULL)
19 {
20 return;
21 }
22 rte_mem_set(ctx, 0, sizeof(*ctx));
23 ctx->train_id = train_id;
24 ctx->nid_engine = nid_engine;
26}
27
28bool ab_gp_proc_session_handle_initiation(ab_gp_ertms_train_context_t *ctx, uint32_t cycle, uint32_t timestamp_ms)
29{
30 if (ctx == NULL)
31 {
32 return false;
33 }
34
36 {
37 ctx->contact_timer_ms = 0U;
38 ctx->position.last_report_cycle = cycle;
39 ctx->position.last_report_time_ms = timestamp_ms;
40 return true;
41 }
42
43 /* This event has no outcome from the current state (ab_gp_session_fsm.c's
44 * own table - only IDLE/TERMINATING produce INITIATED) - the session is
45 * already initiated or active: refresh contact timer, no state change. */
46 ctx->contact_timer_ms = 0U;
47 return true;
48}
49
50bool ab_gp_proc_session_handle_established(ab_gp_ertms_train_context_t *ctx, uint8_t m_version, uint32_t timestamp_ms)
51{
52 if (ctx == NULL)
53 {
54 return false;
55 }
56
58 {
59 /* This event has no outcome from the current state
60 * (ab_gp_session_fsm.c's own table). Two distinct cases collapse
61 * into this branch:
62 * - already active (anything other than INITIATED): allow
63 * re-establishment, existing behaviour, unchanged.
64 * - IDLE: real, deliberate tightening - Msg 159 (session
65 * established) arriving with no prior Msg 155/INITIATED used
66 * to be silently accepted (the old guard's inverted condition
67 * let IDLE through); it is now correctly rejected instead. */
69 {
70 ctx->contact_timer_ms = 0U;
71 return true;
72 }
73 return false;
74 }
75
76 /* Validate ETCS baseline compatibility (lenient for 0 / baseline 2 / baseline 3) */
77 (void)m_version;
78 ctx->contact_timer_ms = 0U;
79 ctx->position.last_report_time_ms = timestamp_ms;
80 return true;
81}
82
84{
85 if (ctx == NULL)
86 {
87 return false;
88 }
89
90 if (db != NULL)
91 {
92 uint8_t i;
93 /* Disconnect all routes allocated to this train */
94 for (i = 0U; i < ctx->ma.route_count; i++)
95 {
96 if (ctx->ma.route_ids[i] != 0U)
97 {
99 ctx->ma.route_ids[i] = 0U;
100 }
101 }
102 }
103
104 ctx->ma.has_active_ma = false;
105 ctx->ma.route_count = 0U;
106 ctx->ma.ma_length_m = 0U;
107 ctx->train_data.state = AB_GP_TRAIN_DATA_NONE; /* co-located with the .valid reset
108 * below - a fresh session re-runs
109 * the train-data FSM from NONE.
110 * (An alternative is subscribing
111 * the train-data FSM to
112 * SESSION_TERMINATED; kept as an
113 * explicit reset here for now,
114 * next to its siblings.) */
115 ctx->train_data.valid = false;
116 ctx->train_data.config_sent = false;
117 ctx->emergency_stop.active = false;
118 ctx->shunting_requested = false;
119 ctx->shunting_authorized = false;
120 /* SESSION_TERMINATED is handled from every state (ab_gp_session_fsm.c's
121 * own table) - termination must always be possible - so this can only
122 * fail on ctx == NULL, already excluded above. */
124 ctx->contact_timer_ms = 0U;
125
126 return true;
127}
128
130 uint32_t timeout_limit_ms, ab_gp_db_t *db)
131{
132 if (ctx == NULL)
133 {
134 return false;
135 }
136
138 {
139 return true;
140 }
141
142 ctx->contact_timer_ms += elapsed_ms;
143
144 if (timeout_limit_ms > 0U && ctx->contact_timer_ms >= timeout_limit_ms)
145 {
146 /* T_NVCONTACT timeout exceeded: terminate session */
148 return false;
149 }
150
151 return true;
152}
bool ab_gp_db_route_disconnect_train(ab_gp_db_t *db, uint16_t route_id)
Reverses ab_gp_db_route_connect_train(): clears the route's own used_in_ma/train_id and removes it fr...
Definition ab_gp_db.c:197
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_SESSION_EVENT_SESSION_TERMINATED
Definition ab_gp_event.h:66
@ AB_GP_SESSION_EVENT_SESSION_INITIATION_REQUESTED
Definition ab_gp_event.h:55
@ AB_GP_SESSION_EVENT_SESSION_ESTABLISHED_CONFIRMED
Definition ab_gp_event.h:56
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_check_timeout(ab_gp_ertms_train_context_t *ctx, uint32_t elapsed_ms, uint32_t timeout_limit_ms, ab_gp_db_t *db)
Supervises the communication contact timer (T_NVCONTACT).
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).
void ab_gp_proc_session_init(ab_gp_ertms_train_context_t *ctx, uint8_t train_id, uint32_t nid_engine)
Initializes the ERTMS procedure context for a train slot.
ERTMS Subset-026 ยง5.3 Communication Session Management Procedure.
@ AB_GP_ERTMS_SESSION_IDLE
@ AB_GP_TRAIN_DATA_NONE
uint16_t route_ids[RTE_EXAMPLE_MAX_ROUTES_PER_TRAIN]
Complete ERTMS state and procedure context for one train slot.
ab_gp_ertms_session_state_t session_state
ab_gp_ertms_position_record_t position
ab_gp_ertms_emergency_stop_t emergency_stop
ab_gp_ertms_train_data_t train_data
ab_gp_ertms_ma_record_t ma
ab_gp_train_data_state_t state