RTE RBC 2oo2 Reference Application
0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Toggle main menu visibility
Loading...
Searching...
No Matches
ab_gp_proc_session.c
Go to the documentation of this file.
1
7
8
#include "
ab_gp_proc_session.h
"
9
#include "
../state_machines/ab_gp_dispatch.h
"
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
16
void
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;
25
ctx->
session_state
=
AB_GP_ERTMS_SESSION_IDLE
;
26
}
27
28
bool
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
35
if
(
ab_gp_dispatch
(ctx,
AB_GP_SESSION_EVENT_SESSION_INITIATION_REQUESTED
))
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
50
bool
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
57
if
(!
ab_gp_dispatch
(ctx,
AB_GP_SESSION_EVENT_SESSION_ESTABLISHED_CONFIRMED
))
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. */
68
if
(ctx->
session_state
!=
AB_GP_ERTMS_SESSION_IDLE
)
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
83
bool
ab_gp_proc_session_handle_termination
(
ab_gp_ertms_train_context_t
*ctx,
ab_gp_db_t
*db)
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
{
98
(void)
ab_gp_db_route_disconnect_train
(db, ctx->
ma
.
route_ids
[i]);
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. */
123
(void)
ab_gp_dispatch
(ctx,
AB_GP_SESSION_EVENT_SESSION_TERMINATED
);
124
ctx->
contact_timer_ms
= 0U;
125
126
return
true
;
127
}
128
129
bool
ab_gp_proc_session_check_timeout
(
ab_gp_ertms_train_context_t
*ctx, uint32_t elapsed_ms,
130
uint32_t timeout_limit_ms,
ab_gp_db_t
*db)
131
{
132
if
(ctx == NULL)
133
{
134
return
false
;
135
}
136
137
if
(ctx->
session_state
==
AB_GP_ERTMS_SESSION_IDLE
)
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 */
147
(void)
ab_gp_proc_session_handle_termination
(ctx, db);
148
return
false
;
149
}
150
151
return
true
;
152
}
ab_gp_db_route_disconnect_train
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
ab_gp_dispatch
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,...
Definition
ab_gp_dispatch.c:140
ab_gp_dispatch.h
Synchronous, statically-wired event dispatch for GP's per-entity procedure state machines (state_mach...
AB_GP_SESSION_EVENT_SESSION_TERMINATED
@ AB_GP_SESSION_EVENT_SESSION_TERMINATED
Definition
ab_gp_event.h:66
AB_GP_SESSION_EVENT_SESSION_INITIATION_REQUESTED
@ AB_GP_SESSION_EVENT_SESSION_INITIATION_REQUESTED
Definition
ab_gp_event.h:55
AB_GP_SESSION_EVENT_SESSION_ESTABLISHED_CONFIRMED
@ AB_GP_SESSION_EVENT_SESSION_ESTABLISHED_CONFIRMED
Definition
ab_gp_event.h:56
ab_gp_proc_session_handle_initiation
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).
Definition
ab_gp_proc_session.c:28
ab_gp_proc_session_check_timeout
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).
Definition
ab_gp_proc_session.c:129
ab_gp_proc_session_handle_termination
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).
Definition
ab_gp_proc_session.c:83
ab_gp_proc_session_handle_established
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).
Definition
ab_gp_proc_session.c:50
ab_gp_proc_session_init
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.
Definition
ab_gp_proc_session.c:16
ab_gp_proc_session.h
ERTMS Subset-026 ยง5.3 Communication Session Management Procedure.
AB_GP_ERTMS_SESSION_IDLE
@ AB_GP_ERTMS_SESSION_IDLE
Definition
ab_gp_ertms_types.h:44
AB_GP_TRAIN_DATA_NONE
@ AB_GP_TRAIN_DATA_NONE
Definition
ab_gp_ertms_types.h:70
ab_gp_db_t
Definition
ab_gp_db.h:133
ab_gp_ertms_emergency_stop_t::active
bool active
Definition
ab_gp_ertms_types.h:156
ab_gp_ertms_ma_record_t::route_count
uint8_t route_count
Definition
ab_gp_ertms_types.h:115
ab_gp_ertms_ma_record_t::has_active_ma
bool has_active_ma
Definition
ab_gp_ertms_types.h:108
ab_gp_ertms_ma_record_t::route_ids
uint16_t route_ids[RTE_EXAMPLE_MAX_ROUTES_PER_TRAIN]
Definition
ab_gp_ertms_types.h:116
ab_gp_ertms_ma_record_t::ma_length_m
uint32_t ma_length_m
Definition
ab_gp_ertms_types.h:110
ab_gp_ertms_position_record_t::last_report_time_ms
uint32_t last_report_time_ms
Definition
ab_gp_ertms_types.h:144
ab_gp_ertms_position_record_t::last_report_cycle
uint32_t last_report_cycle
Definition
ab_gp_ertms_types.h:143
ab_gp_ertms_train_context_t
Complete ERTMS state and procedure context for one train slot.
Definition
ab_gp_ertms_types.h:235
ab_gp_ertms_train_context_t::shunting_requested
bool shunting_requested
Definition
ab_gp_ertms_types.h:244
ab_gp_ertms_train_context_t::session_state
ab_gp_ertms_session_state_t session_state
Definition
ab_gp_ertms_types.h:238
ab_gp_ertms_train_context_t::shunting_authorized
bool shunting_authorized
Definition
ab_gp_ertms_types.h:245
ab_gp_ertms_train_context_t::position
ab_gp_ertms_position_record_t position
Definition
ab_gp_ertms_types.h:242
ab_gp_ertms_train_context_t::contact_timer_ms
uint32_t contact_timer_ms
Definition
ab_gp_ertms_types.h:239
ab_gp_ertms_train_context_t::nid_engine
uint32_t nid_engine
Definition
ab_gp_ertms_types.h:237
ab_gp_ertms_train_context_t::emergency_stop
ab_gp_ertms_emergency_stop_t emergency_stop
Definition
ab_gp_ertms_types.h:243
ab_gp_ertms_train_context_t::train_id
uint8_t train_id
Definition
ab_gp_ertms_types.h:236
ab_gp_ertms_train_context_t::train_data
ab_gp_ertms_train_data_t train_data
Definition
ab_gp_ertms_types.h:240
ab_gp_ertms_train_context_t::ma
ab_gp_ertms_ma_record_t ma
Definition
ab_gp_ertms_types.h:241
ab_gp_ertms_train_data_t::config_sent
bool config_sent
Definition
ab_gp_ertms_types.h:90
ab_gp_ertms_train_data_t::valid
bool valid
Definition
ab_gp_ertms_types.h:82
ab_gp_ertms_train_data_t::state
ab_gp_train_data_state_t state
Definition
ab_gp_ertms_types.h:81
src
application
AB
GP
ertms_procedures
ab_gp_proc_session.c
Generated by
1.18.0