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_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 */
15
void
ab_gp_proc_tsr_init
(
ab_gp_ertms_train_context_t
*ctx)
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 */
35
bool
ab_gp_proc_tsr_add
(
ab_gp_ertms_train_context_t
*ctx,
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 */
81
bool
ab_gp_proc_tsr_remove
(
ab_gp_ertms_train_context_t
*ctx, uint8_t nid_tsr)
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 */
107
bool
ab_gp_proc_tsr_generate_packet_65
(
const
ab_gp_ertms_train_context_t
*ctx,
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
}
129
out_p65->
q_front
=
RBC_Q_FRONT_TRAIN_LENGTH_DELAY
;
130
return
true
;
131
}
132
}
133
134
return
false
;
135
}
136
137
/* REQ-ID: RBC_ERTMS_TSR_005 - Packet 66 Generation */
138
bool
ab_gp_proc_tsr_generate_packet_66
(uint8_t nid_tsr,
139
rbc_packet_66_tsr_revoke_t
*out_p66)
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 */
151
uint8_t
ab_gp_proc_tsr_get_active_count
(
const
ab_gp_ertms_train_context_t
*ctx)
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
RBC_MAX_TSR_ITEMS
#define RBC_MAX_TSR_ITEMS
Definition
ab_gp_ertms_train_packets.h:22
ab_gp_proc_tsr_remove
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.
Definition
ab_gp_proc_tsr.c:81
ab_gp_proc_tsr_generate_packet_65
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.
Definition
ab_gp_proc_tsr.c:107
ab_gp_proc_tsr_add
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.
Definition
ab_gp_proc_tsr.c:35
ab_gp_proc_tsr_init
void ab_gp_proc_tsr_init(ab_gp_ertms_train_context_t *ctx)
Initializes the TSR records for a train context.
Definition
ab_gp_proc_tsr.c:15
ab_gp_proc_tsr_get_active_count
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.
Definition
ab_gp_proc_tsr.c:151
ab_gp_proc_tsr_generate_packet_66
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.
Definition
ab_gp_proc_tsr.c:138
ab_gp_proc_tsr.h
ERTMS Subset-026 ยง5.10 Temporary Speed Restriction (TSR) Procedure.
RBC_Q_FRONT_TRAIN_LENGTH_DELAY
@ RBC_Q_FRONT_TRAIN_LENGTH_DELAY
Definition
ab_gp_ertms_types.h:198
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::tsrs
ab_gp_ertms_tsr_record_t tsrs[RBC_MAX_TSR_ITEMS]
Definition
ab_gp_ertms_types.h:246
ab_gp_ertms_tsr_record_t::nid_tsr
uint8_t nid_tsr
Definition
ab_gp_ertms_types.h:175
ab_gp_ertms_tsr_record_t::v_tsr_kmh
uint32_t v_tsr_kmh
Definition
ab_gp_ertms_types.h:176
ab_gp_ertms_tsr_record_t::is_active
bool is_active
Definition
ab_gp_ertms_types.h:174
ab_gp_ertms_tsr_record_t::d_tsr_end_m
uint32_t d_tsr_end_m
Definition
ab_gp_ertms_types.h:178
ab_gp_ertms_tsr_record_t::d_tsr_start_m
uint32_t d_tsr_start_m
Definition
ab_gp_ertms_types.h:177
rbc_packet_65_tsr_t
Definition
ab_gp_ertms_train_packets.h:200
rbc_packet_65_tsr_t::d_tsr
rbc_distance_m_t d_tsr
Definition
ab_gp_ertms_train_packets.h:202
rbc_packet_65_tsr_t::l_tsr
rbc_distance_m_t l_tsr
Definition
ab_gp_ertms_train_packets.h:203
rbc_packet_65_tsr_t::q_front
rbc_q_front_t q_front
Definition
ab_gp_ertms_train_packets.h:205
rbc_packet_65_tsr_t::nid_tsr
rbc_nid_tsr_t nid_tsr
Definition
ab_gp_ertms_train_packets.h:201
rbc_packet_65_tsr_t::v_tsr
rbc_speed_kmh_t v_tsr
Definition
ab_gp_ertms_train_packets.h:204
rbc_packet_66_tsr_revoke_t
Definition
ab_gp_ertms_train_packets.h:213
rbc_packet_66_tsr_revoke_t::nid_tsr
rbc_nid_tsr_t nid_tsr
Definition
ab_gp_ertms_train_packets.h:214
src
application
AB
GP
ertms_procedures
ab_gp_proc_tsr.c
Generated by
1.18.0