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_startup_timestamp.c
Go to the documentation of this file.
1
5
#include "
ab_gp_startup_timestamp.h
"
6
7
rte_timestamp_ms_t
ab_gp_startup_timestamp_agree
(rte_timestamp_ms_t own_now_ms, rte_timestamp_ms_t sibling_ts_ms,
8
bool
have_sibling)
9
{
10
rte_timestamp_ms_t agreed = own_now_ms;
11
12
if
(have_sibling && (sibling_ts_ms <= own_now_ms) &&
13
((own_now_ms - sibling_ts_ms) < (rte_timestamp_ms_t)
AB_GP_STARTUP_TS_FRESH_MS
))
14
{
15
agreed = sibling_ts_ms;
16
}
17
return
agreed;
18
}
19
20
void
ab_gp_startup_timestamp_encode
(uint8_t *buf,
bool
is_reply, rte_timestamp_ms_t ts_ms)
21
{
22
if
(buf != NULL)
23
{
24
uint32_t i;
25
26
buf[0] = is_reply ? 1U : 0U;
27
for
(i = 0U; i < 8U; i++)
28
{
29
const
uint32_t shift = 8U * i;
30
31
buf[1U + i] = (uint8_t)((ts_ms >> shift) & 0xFFU);
32
}
33
}
34
}
35
36
bool
ab_gp_startup_timestamp_decode
(
const
uint8_t *buf,
size_t
size,
bool
*is_reply, rte_timestamp_ms_t *ts_ms)
37
{
38
bool
ok =
false
;
39
40
if
((buf != NULL) && (is_reply != NULL) && (ts_ms != NULL) && (size >= (
size_t
)
AB_GP_STARTUP_TS_PAYLOAD_SIZE
) &&
41
(buf[0] <= 1U))
42
{
43
rte_timestamp_ms_t value = 0U;
44
uint32_t i;
45
46
for
(i = 0U; i < 8U; i++)
47
{
48
const
uint32_t shift = 8U * i;
49
50
value |= ((rte_timestamp_ms_t)buf[1U + i]) << shift;
51
}
52
*is_reply = (buf[0] == 1U);
53
*ts_ms = value;
54
ok =
true
;
55
}
56
return
ok;
57
}
ab_gp_startup_timestamp_agree
rte_timestamp_ms_t ab_gp_startup_timestamp_agree(rte_timestamp_ms_t own_now_ms, rte_timestamp_ms_t sibling_ts_ms, bool have_sibling)
The site startup timestamp this channel uses given its own clock and the sibling's value.
Definition
ab_gp_startup_timestamp.c:7
ab_gp_startup_timestamp_decode
bool ab_gp_startup_timestamp_decode(const uint8_t *buf, size_t size, bool *is_reply, rte_timestamp_ms_t *ts_ms)
Decodes a STARTUP_TS payload.
Definition
ab_gp_startup_timestamp.c:36
ab_gp_startup_timestamp_encode
void ab_gp_startup_timestamp_encode(uint8_t *buf, bool is_reply, rte_timestamp_ms_t ts_ms)
Encodes a STARTUP_TS payload.
Definition
ab_gp_startup_timestamp.c:20
ab_gp_startup_timestamp.h
The site startup timestamp A and B agree over the A/B peer link (ADR-040 step 5a): the agreement rule...
AB_GP_STARTUP_TS_PAYLOAD_SIZE
#define AB_GP_STARTUP_TS_PAYLOAD_SIZE
Definition
ab_gp_startup_timestamp.h:38
AB_GP_STARTUP_TS_FRESH_MS
#define AB_GP_STARTUP_TS_FRESH_MS
Definition
ab_gp_startup_timestamp.h:24
src
application
AB
GP
com
ab_gp_startup_timestamp.c
Generated by
1.18.0