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_position.c
Go to the documentation of this file.
1
5
7#include "ab_siteGP.h"
8#include "rte/utils/cast/rte_cast.h"
9
11 uint32_t nid_lrbg,
12 uint32_t d_lrbg_m,
13 rbc_q_dirlrbg_t q_dirlrbg,
14 uint32_t v_train_kmh,
15 uint32_t m_mode,
16 uint32_t m_level,
17 uint32_t cycle,
18 uint32_t timestamp_ms)
19{
20 const ab_site_balise_t *balise;
21
22 if (ctx == NULL)
23 {
24 return false;
25 }
26
27 ctx->position.nid_lrbg = nid_lrbg;
28 ctx->position.d_lrbg_m = d_lrbg_m;
29 ctx->position.q_dirlrbg = q_dirlrbg;
30 ctx->position.v_train_kmh = v_train_kmh;
31 ctx->position.m_mode = m_mode;
32 ctx->position.m_level = m_level;
33 ctx->position.last_report_cycle = cycle;
34 ctx->position.last_report_time_ms = timestamp_ms;
35 ctx->contact_timer_ms = 0U; /* Reset communication contact timer */
36
37 /* Correlate LRBG with static site topology */
38 balise = ab_site_get_balise(nid_lrbg);
39 if (balise != NULL)
40 {
41 ab_site_direction_t train_dir;
42
43 ctx->position.current_segment_id = balise->segment_id;
44 ctx->position.current_route_id = balise->route_id;
45
46 /* Determine train travel direction relative to segment.
47 * The balise direction indicates its nominal orientation on the segment:
48 * NOMINAL: increasing pos_m (pos 0 -> length)
49 * REVERSE: decreasing pos_m (length -> pos 0)
50 * Packet 0 q_dirlrbg indicates train direction relative to LRBG orientation:
51 * NOMINAL: train moves in the balise's nominal direction
52 * REVERSE: train moves in the balise's reverse direction */
53 if (balise->direction == AB_SITE_DIR_REVERSE)
54 {
55 if (q_dirlrbg == RBC_Q_DIRLRBG_REVERSE)
56 {
57 train_dir = AB_SITE_DIR_NOMINAL;
58 }
59 else
60 {
61 train_dir = AB_SITE_DIR_REVERSE;
62 }
63 }
64 else
65 {
66 if (q_dirlrbg == RBC_Q_DIRLRBG_REVERSE)
67 {
68 train_dir = AB_SITE_DIR_REVERSE;
69 }
70 else
71 {
72 train_dir = AB_SITE_DIR_NOMINAL;
73 }
74 }
75 ctx->position.direction_on_segment = train_dir;
76
77 /* Calculate train coordinate along the segment (pos_on_segment_m) */
78 if (train_dir == AB_SITE_DIR_REVERSE)
79 {
80 if (balise->pos_m >= d_lrbg_m)
81 {
82 ctx->position.pos_on_segment_m = balise->pos_m - d_lrbg_m;
83 }
84 else
85 {
86 ctx->position.pos_on_segment_m = 0U;
87 }
88 }
89 else
90 {
91 (void)rte_cast_checked_add_u32(balise->pos_m, d_lrbg_m, &ctx->position.pos_on_segment_m);
92 }
93
94 (void)rte_cast_checked_add_u32(balise->pos_m, d_lrbg_m, &ctx->position.distance_in_route_m);
95 }
96 else
97 {
99 ctx->position.current_route_id = 0U;
100 ctx->position.pos_on_segment_m = d_lrbg_m;
101 ctx->position.direction_on_segment = AB_SITE_DIR_NOMINAL;
102 ctx->position.distance_in_route_m = d_lrbg_m;
103 }
104
105 return true;
106}
107
109 uint16_t route_id)
110{
111 uint8_t i;
112
113 if (ctx == NULL || route_id == 0U)
114 {
115 return false;
116 }
117
118 if (ctx->position.current_route_id == route_id)
119 {
120 return true;
121 }
122
123 /* Also check if route_id is one of the allocated routes in active MA */
124 for (i = 0U; i < ctx->ma.route_count; i++)
125 {
126 if (ctx->ma.route_ids[i] == route_id)
127 {
128 return true;
129 }
130 }
131
132 return false;
133}
134
136{
137 if (ctx == NULL || !ctx->ma.has_active_ma)
138 {
139 return false;
140 }
141
142 if (ctx->ma.ma_length_m > 0U && ctx->position.distance_in_route_m > ctx->ma.ma_length_m)
143 {
144 return true;
145 }
146
147 return false;
148}
bool ab_gp_proc_position_has_exceeded_ma(const ab_gp_ertms_train_context_t *ctx)
Checks if the train has reached or exceeded its Limit of Authority (LOA / EOA).
bool ab_gp_proc_position_is_train_in_route(const ab_gp_ertms_train_context_t *ctx, uint16_t route_id)
Checks if the train is currently located within a specific interlocking route.
bool ab_gp_proc_position_update(ab_gp_ertms_train_context_t *ctx, uint32_t nid_lrbg, uint32_t d_lrbg_m, rbc_q_dirlrbg_t q_dirlrbg, uint32_t v_train_kmh, uint32_t m_mode, uint32_t m_level, uint32_t cycle, uint32_t timestamp_ms)
Processes an inbound Position Report (Msg 136 + Packet 0).
ERTMS Subset-026 ยง5.6 Supervised Location and Position Reporting Procedure.
rbc_q_dirlrbg_t
Balise Group Orientation (Q_DIRLRBG) Subset-026 Section 7.5.1.16: 0 = Reverse 1 = Nominal 2 = Unknown...
@ RBC_Q_DIRLRBG_REVERSE
uint16_t route_ids[RTE_EXAMPLE_MAX_ROUTES_PER_TRAIN]
ab_site_direction_t direction_on_segment
Complete ERTMS state and procedure context for one train slot.
ab_gp_ertms_position_record_t position
ab_gp_ertms_ma_record_t ma