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_tsr.c
Go to the documentation of this file.
1
9
10#include "ab_gp_proc_tsr.h"
11#include "rte/oal/memory/rte_mem_util.h"
12#include "rte/utils/cast/rte_cast.h"
13
14/* REQ-ID: RBC_ERTMS_TSR_001 - Static TSR Table Initialization */
16{
17 uint8_t i;
18
19 if (ctx == NULL)
20 {
21 return;
22 }
23
24 for (i = 0U; i < (uint8_t)RBC_MAX_TSR_ITEMS; i++)
25 {
26 ctx->tsrs[i].is_active = false;
27 ctx->tsrs[i].nid_tsr = 0U;
28 ctx->tsrs[i].v_tsr_kmh = 0U;
29 ctx->tsrs[i].d_tsr_start_m = 0U;
30 ctx->tsrs[i].d_tsr_end_m = 0U;
31 }
32}
33
34/* REQ-ID: RBC_ERTMS_TSR_002 - Add TSR to Supervised Path */
36 uint8_t nid_tsr,
37 uint32_t v_tsr_kmh,
38 uint32_t d_start_m,
39 uint32_t d_end_m)
40{
41 uint8_t i;
42 int32_t free_slot = -1;
43
44 if ((ctx == NULL) || (nid_tsr == 0U) || (d_end_m <= d_start_m))
45 {
46 return false;
47 }
48
49 /* Check if already present to update, or find free slot */
50 for (i = 0U; i < (uint8_t)RBC_MAX_TSR_ITEMS; i++)
51 {
52 if (ctx->tsrs[i].is_active && (ctx->tsrs[i].nid_tsr == nid_tsr))
53 {
54 /* Update existing TSR */
55 ctx->tsrs[i].v_tsr_kmh = v_tsr_kmh;
56 ctx->tsrs[i].d_tsr_start_m = d_start_m;
57 ctx->tsrs[i].d_tsr_end_m = d_end_m;
58 return true;
59 }
60 if (!ctx->tsrs[i].is_active && (free_slot < 0))
61 {
62 free_slot = (int32_t)i;
63 }
64 }
65
66 if (free_slot < 0)
67 {
68 return false; /* TSR table full */
69 }
70
71 ctx->tsrs[(uint32_t)free_slot].is_active = true;
72 ctx->tsrs[(uint32_t)free_slot].nid_tsr = nid_tsr;
73 ctx->tsrs[(uint32_t)free_slot].v_tsr_kmh = v_tsr_kmh;
74 ctx->tsrs[(uint32_t)free_slot].d_tsr_start_m = d_start_m;
75 ctx->tsrs[(uint32_t)free_slot].d_tsr_end_m = d_end_m;
76
77 return true;
78}
79
80/* REQ-ID: RBC_ERTMS_TSR_003 - Revoke TSR from Path */
82{
83 uint8_t i;
84
85 if ((ctx == NULL) || (nid_tsr == 0U))
86 {
87 return false;
88 }
89
90 for (i = 0U; i < (uint8_t)RBC_MAX_TSR_ITEMS; i++)
91 {
92 if (ctx->tsrs[i].is_active && (ctx->tsrs[i].nid_tsr == nid_tsr))
93 {
94 ctx->tsrs[i].is_active = false;
95 ctx->tsrs[i].nid_tsr = 0U;
96 ctx->tsrs[i].v_tsr_kmh = 0U;
97 ctx->tsrs[i].d_tsr_start_m = 0U;
98 ctx->tsrs[i].d_tsr_end_m = 0U;
99 return true;
100 }
101 }
102
103 return false;
104}
105
106/* REQ-ID: RBC_ERTMS_TSR_004 - Packet 65 Generation */
108 uint8_t nid_tsr,
109 rbc_packet_65_tsr_t *out_p65)
110{
111 uint8_t i;
112
113 if ((ctx == NULL) || (out_p65 == NULL) || (nid_tsr == 0U))
114 {
115 return false;
116 }
117
118 for (i = 0U; i < (uint8_t)RBC_MAX_TSR_ITEMS; i++)
119 {
120 if (ctx->tsrs[i].is_active && (ctx->tsrs[i].nid_tsr == nid_tsr))
121 {
122 out_p65->nid_tsr = nid_tsr;
123 out_p65->d_tsr = ctx->tsrs[i].d_tsr_start_m;
124 (void)rte_cast_checked_sub_u32(ctx->tsrs[i].d_tsr_end_m, ctx->tsrs[i].d_tsr_start_m, &out_p65->l_tsr);
125 if (rte_cast_u32_to_u16(ctx->tsrs[i].v_tsr_kmh, &out_p65->v_tsr) != RTE_STATUS_OK)
126 {
127 return false; /* speed does not fit the 16-bit wire field */
128 }
130 return true;
131 }
132 }
133
134 return false;
135}
136
137/* REQ-ID: RBC_ERTMS_TSR_005 - Packet 66 Generation */
140{
141 if ((out_p66 == NULL) || (nid_tsr == 0U))
142 {
143 return false;
144 }
145
146 out_p66->nid_tsr = nid_tsr;
147 return true;
148}
149
150/* REQ-ID: RBC_ERTMS_TSR_006 - Active Count Query */
152{
153 uint8_t i;
154 uint8_t count = 0U;
155
156 if (ctx == NULL)
157 {
158 return 0U;
159 }
160
161 for (i = 0U; i < (uint8_t)RBC_MAX_TSR_ITEMS; i++)
162 {
163 if (ctx->tsrs[i].is_active)
164 {
165 count++;
166 }
167 }
168
169 return count;
170}
171
#define RBC_MAX_TSR_ITEMS
bool ab_gp_proc_tsr_remove(ab_gp_ertms_train_context_t *ctx, uint8_t nid_tsr)
Removes an active Temporary Speed Restriction from the train's path.
bool ab_gp_proc_tsr_generate_packet_65(const ab_gp_ertms_train_context_t *ctx, uint8_t nid_tsr, rbc_packet_65_tsr_t *out_p65)
Generates an ERTMS Packet 65 (TSR) payload for transmission in Msg 3 / Msg 24.
bool ab_gp_proc_tsr_add(ab_gp_ertms_train_context_t *ctx, uint8_t nid_tsr, uint32_t v_tsr_kmh, uint32_t d_start_m, uint32_t d_end_m)
Adds a new Temporary Speed Restriction to the train's supervised path.
void ab_gp_proc_tsr_init(ab_gp_ertms_train_context_t *ctx)
Initializes the TSR records for a train context.
uint8_t ab_gp_proc_tsr_get_active_count(const ab_gp_ertms_train_context_t *ctx)
Returns the number of currently active TSRs for this train.
bool ab_gp_proc_tsr_generate_packet_66(uint8_t nid_tsr, rbc_packet_66_tsr_revoke_t *out_p66)
Generates an ERTMS Packet 66 (TSR Revocation) payload.
ERTMS Subset-026 ยง5.10 Temporary Speed Restriction (TSR) Procedure.
@ RBC_Q_FRONT_TRAIN_LENGTH_DELAY
Complete ERTMS state and procedure context for one train slot.
ab_gp_ertms_tsr_record_t tsrs[RBC_MAX_TSR_ITEMS]