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_dispatch.c
Go to the documentation of this file.
1
5
6#include "ab_gp_dispatch.h"
7
10#include "ma/ab_gp_ma_fsm.h"
14#include "eom/ab_gp_eom_fsm.h"
16#include "tsr/ab_gp_tsr_fsm.h"
18
19#include "rte/oal/log/rte_log.h"
20#include "rte/utils/string/rte_string.h"
21
37static const struct
38{
41} s_subscriptions[] = {
42 /* Session lifecycle - ab_gp_session_fsm.c is the sole subscriber for
43 * all of these (so ab_gp_dispatch()'s bool == this FSM's result). */
56
57 /* Validated Train Data - ab_gp_train_data_fsm.c. It ALSO subscribes to
58 * the shared _TRAIN_DATA_VALIDATED event above (the "accepted" case),
59 * so that event has two rows: session FSM first, then this one. */
63
64 /* ---- STUB per-entity FSMs (ab_gp_fsm_stub.h) ------------------- */
65 /* The wiring is complete - each event below reaches its FSM - but
66 * these handlers only log "not implemented yet" and return false
67 * (changed=0), so they never affect ab_gp_dispatch()'s bool. Where
68 * an event also has a real subscriber above (MA_GRANTED etc.), that
69 * one still runs first and still decides the return. */
70
71 /* Movement Authority. */
76
77 /* Shunting. */
80
81 /* Emergency stop. */
86
87 /* Supervised position. */
89
90 /* End of Mission. */
92
93 /* RBC handover (no raise site yet). */
96
97 /* Temporary Speed Restriction (no raise site yet). */
100
101 /* Driver text message (no raise site yet). */
105
106#define AB_GP_DISPATCH_SUBSCRIPTION_COUNT \
107 (sizeof(s_subscriptions) / sizeof(s_subscriptions[0]))
108
115 uint32_t reached, uint32_t changed)
116{
117 char storage[96];
118 rte_string_t line;
119 const char *out_cstr = NULL;
120
121 if (rte_string_init(&line, storage, sizeof(storage)) != RTE_STATUS_OK)
122 {
123 return;
124 }
125 (void)rte_string_copy(&line, "train=");
126 (void)rte_string_append_u32(&line, (uint32_t)ctx->train_id);
127 (void)rte_string_concat(&line, " event=");
128 (void)rte_string_append_u32(&line, (uint32_t)event);
129 (void)rte_string_concat(&line, " reached=");
130 (void)rte_string_append_u32(&line, reached);
131 (void)rte_string_concat(&line, " changed=");
132 (void)rte_string_append_u32(&line, changed);
133
134 if (rte_string_c_str(&line, &out_cstr) == RTE_STATUS_OK)
135 {
136 rte_log_write(RTE_LOG_LEVEL_DEBUG, "GP_DISPATCH", out_cstr);
137 }
138}
139
141{
142 uint32_t i;
143 uint32_t reached = 0U;
144 uint32_t changed = 0U;
145
146 if (ctx == NULL)
147 {
148 return false;
149 }
150 if ((uint32_t)event >= (uint32_t)AB_GP_EVENT_COUNT)
151 {
152 return false;
153 }
154
155 for (i = 0U; i < (uint32_t)AB_GP_DISPATCH_SUBSCRIPTION_COUNT; i++)
156 {
157 if (s_subscriptions[i].event == event)
158 {
159 reached++;
160 if (s_subscriptions[i].handler(ctx, event))
161 {
162 changed++;
163 }
164 }
165 }
166
167 log_dispatch(ctx, event, reached, changed);
168 return (changed > 0U);
169}
static const struct @227266333067155012122310032006107002200036350304 s_subscriptions[]
static void log_dispatch(const ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event, uint32_t reached, uint32_t changed)
#define AB_GP_DISPATCH_SUBSCRIPTION_COUNT
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...
bool(*) ab_gp_fsm_handler_fn(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
One FSM's event entry point. Every per-entity FSM under state_machines/ exposes exactly this signatur...
bool ab_gp_emergency_stop_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the EMERGENCY_STOP procedure.
bool ab_gp_eom_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the EOM procedure.
ab_gp_event_t
Every event any GP procedure state machine reacts to. One per distinct real trigger in ertms_procedur...
Definition ab_gp_event.h:53
@ AB_GP_SESSION_EVENT_EMERGENCY_STOP_ISSUED
Definition ab_gp_event.h:62
@ AB_GP_EVENT_TEXT_MESSAGE_ACKNOWLEDGED
@ 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_EVENT_MA_REQUESTED
Definition ab_gp_event.h:85
@ AB_GP_SESSION_EVENT_EMERGENCY_STOP_REVOKED_TO_ESTABLISHED
Definition ab_gp_event.h:65
@ AB_GP_SESSION_EVENT_EMERGENCY_STOP_REVOKED_TO_STANDBY
Definition ab_gp_event.h:64
@ AB_GP_SESSION_EVENT_SHUNTING_AUTHORIZED
Definition ab_gp_event.h:60
@ AB_GP_EVENT_TRAIN_DATA_REJECTED
Definition ab_gp_event.h:73
@ AB_GP_EVENT_COUNT
@ AB_GP_SESSION_EVENT_MA_REVOKED
Definition ab_gp_event.h:59
@ AB_GP_SESSION_EVENT_SESSION_ESTABLISHED_CONFIRMED
Definition ab_gp_event.h:56
@ AB_GP_EVENT_TEXT_MESSAGE_SENT
@ AB_GP_EVENT_HANDOVER_CONFIRMED
Definition ab_gp_event.h:97
@ AB_GP_SESSION_EVENT_MA_GRANTED
Definition ab_gp_event.h:58
@ AB_GP_EVENT_MA_ACKNOWLEDGED
Definition ab_gp_event.h:86
@ AB_GP_EVENT_HANDOVER_ANNOUNCED
Definition ab_gp_event.h:96
@ AB_GP_SESSION_EVENT_EMERGENCY_STOP_REVOKED_TO_FS
Definition ab_gp_event.h:63
@ AB_GP_EVENT_TSR_IMPOSED
@ AB_GP_EVENT_POSITION_REPORTED
Definition ab_gp_event.h:89
@ AB_GP_SESSION_EVENT_TRAIN_DATA_VALIDATED
Definition ab_gp_event.h:57
@ AB_GP_EVENT_TRAIN_DATA_RECEIVED
Definition ab_gp_event.h:72
@ AB_GP_EVENT_END_OF_MISSION
Definition ab_gp_event.h:92
@ AB_GP_EVENT_TSR_REVOKED
@ AB_GP_SESSION_EVENT_SHUNTING_DEAUTHORIZED
Definition ab_gp_event.h:61
bool ab_gp_handover_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the HANDOVER procedure.
bool ab_gp_ma_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the MA procedure.
bool ab_gp_position_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the POSITION procedure.
bool ab_gp_session_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_session_event_t event)
Applies event to ctx->session_state.
Event-driven legal-transition table for ab_gp_ertms_session_state_t (Subset-026 Chapter 5's various p...
bool ab_gp_shunting_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the SHUNTING procedure.
bool ab_gp_text_message_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the TEXT_MESSAGE procedure.
bool ab_gp_train_data_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
Applies event to ctx->train_data.state, and keeps ctx->train_data.valid in sync (true iff the new sta...
(state, event) -> state table for ab_gp_train_data_state_t (Subset-026 ยง5.4 Validated Train Data acce...
bool ab_gp_tsr_fsm_handle_event(ab_gp_ertms_train_context_t *ctx, ab_gp_event_t event)
STUB handler - logs "not implemented yet" and returns false (no state change). Signature matches ab_g...
STUB per-entity state machine for the TSR procedure.
ab_gp_fsm_handler_fn handler
Complete ERTMS state and procedure context for one train slot.