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_km114_relay.c
Go to the documentation of this file.
1
5
#include "
ab_gp_km114_relay.h
"
6
7
#include <stdbool.h>
8
#include <stdio.h>
9
#include <string.h>
10
11
#include "rte/oal/log/rte_log.h"
12
13
#include "
../../common/rbc_util_km114_relay.h
"
14
#include "
ab_gp_km114_client.h
"
15
17
19
21
static
uint8_t
s_buf
[
RBC_UTIL_KM114_RELAY_FILE_MAX
];
22
static
uint16_t
s_total_len
;
23
static
uint8_t
s_frag_count
;
24
static
bool
s_frag_seen
[
RBC_UTIL_KM114_RELAY_MAX_FRAGS
];
25
static
uint8_t
s_frags_seen_count
;
26
28
void
ab_gp_km114_relay_on_frame
(
const
rbc_util_frame_t
*frame,
const
char
*role_tag,
rte_example_site_t
site,
29
ab_gp_channel_handle_t
handle)
30
{
31
uint16_t total_len;
32
uint8_t frag_index;
33
uint8_t frag_count;
34
const
uint8_t *chunk;
35
uint8_t chunk_len;
36
size_t
offset;
37
38
if
(frame == NULL)
39
{
40
return
;
41
}
42
if
(!
rbc_util_km114_relay_decode_chunk
((
const
uint8_t *)frame->
payload_z
, frame->
payload_len
, &total_len,
43
&frag_index, &frag_count, &chunk, &chunk_len))
44
{
45
return
;
46
}
47
if
((frag_count == 0U) || (frag_count > (uint8_t)
RBC_UTIL_KM114_RELAY_MAX_FRAGS
) ||
48
(frag_index >= frag_count) || (total_len > (uint16_t)
RBC_UTIL_KM114_RELAY_FILE_MAX
))
49
{
50
rte_log_write_event(RTE_LOG_LEVEL_WARNING,
site_config_name
(site), 0U, role_tag,
"-"
,
"KM114_RELAY"
,
51
"malformed chunk header"
, NULL);
52
return
;
53
}
54
55
/* A frag_count that differs from an in-progress transfer's own means a NEW transfer
56
* started (the off-line KMC drop is one-file-at-a-time in this workspace's design, so
57
* overlapping transfers are not expected) - reset and start over rather than mix bytes
58
* from two different files. */
59
if
((
s_frag_count
!= frag_count) || (
s_total_len
!= total_len))
60
{
61
s_total_len
= total_len;
62
s_frag_count
= frag_count;
63
s_frags_seen_count
= 0U;
64
for
(offset = 0U; offset < (size_t)
RBC_UTIL_KM114_RELAY_MAX_FRAGS
; offset++)
65
{
66
s_frag_seen
[offset] =
false
;
67
}
68
}
69
70
offset = (size_t)frag_index * (
size_t
)
RBC_UTIL_KM114_RELAY_CHUNK_MAX
;
71
if
((offset + (
size_t
)chunk_len) > (
size_t
)
RBC_UTIL_KM114_RELAY_FILE_MAX
)
72
{
73
return
;
/* Defensive - cannot happen given the range checks above. */
74
}
75
if
(chunk_len > 0U)
76
{
77
(void)memcpy(&
s_buf
[offset], chunk, chunk_len);
78
}
79
if
(!
s_frag_seen
[frag_index])
80
{
81
s_frag_seen
[frag_index] =
true
;
82
s_frags_seen_count
++;
83
}
84
85
if
(
s_frags_seen_count
==
s_frag_count
)
86
{
87
char
msg[64];
88
89
(void)snprintf(msg,
sizeof
(msg),
"bytes=%u frags=%u"
, (
unsigned
int
)
s_total_len
,
90
(
unsigned
int
)
s_frag_count
);
91
rte_log_write_event(RTE_LOG_LEVEL_INFO,
site_config_name
(site), 0U, role_tag,
"-"
,
"KM114_RELAY"
,
92
"file reassembled"
, msg);
93
/* Hand off to the actual decoder - see ab_gp_km114_client.h. Gateway (which sent these
94
* bytes) never does this itself; only A/B, each independently. */
95
ab_gp_km114_client_on_message
(
s_buf
, (
size_t
)
s_total_len
, role_tag, site, handle);
96
s_frag_count
= 0U;
97
s_frags_seen_count
= 0U;
98
}
99
}
ab_gp_channel_handle_t
struct ab_gp_channel_context_s * ab_gp_channel_handle_t
Opaque handle over this component's own static per-process context.
Definition
ab_gp_channel.h:18
ab_gp_km114_client_on_message
void ab_gp_km114_client_on_message(const uint8_t *bytes, size_t len, const char *role_tag, rte_example_site_t site, ab_gp_channel_handle_t handle)
Processes one complete, reassembled Subset-114 message.
Definition
ab_gp_km114_client.c:50
ab_gp_km114_client.h
A/B-side Subset-114 KMC message decoder - step 2 of Platform_Protocol_KM114's "Consumption design" (s...
s_frag_count
static uint8_t s_frag_count
Definition
ab_gp_km114_relay.c:23
s_total_len
static uint16_t s_total_len
Definition
ab_gp_km114_relay.c:22
ab_gp_km114_relay_on_frame
void ab_gp_km114_relay_on_frame(const rbc_util_frame_t *frame, const char *role_tag, rte_example_site_t site, ab_gp_channel_handle_t handle)
Feeds one decoded RBC_UTIL_TOPIC_KM114_FILE publish frame into the reassembler.
Definition
ab_gp_km114_relay.c:28
s_frags_seen_count
static uint8_t s_frags_seen_count
Definition
ab_gp_km114_relay.c:25
s_buf
static uint8_t s_buf[RBC_UTIL_KM114_RELAY_FILE_MAX]
Definition
ab_gp_km114_relay.c:21
s_frag_seen
static bool s_frag_seen[RBC_UTIL_KM114_RELAY_MAX_FRAGS]
Definition
ab_gp_km114_relay.c:24
ab_gp_km114_relay.h
A/B-side receiver for Gateway-relayed Subset-114 off-line KMC file bytes (RBC_UTIL_TOPIC_KM114_FILE,...
rbc_util_km114_relay.h
Wire chunking for RBC_UTIL_TOPIC_KM114_FILE publishes: Gateway relays one opaque Subset-114 off-line ...
RBC_UTIL_KM114_RELAY_FILE_MAX
#define RBC_UTIL_KM114_RELAY_FILE_MAX
Definition
rbc_util_km114_relay.h:41
RBC_UTIL_KM114_RELAY_CHUNK_MAX
#define RBC_UTIL_KM114_RELAY_CHUNK_MAX
Definition
rbc_util_km114_relay.h:39
rbc_util_km114_relay_decode_chunk
static bool rbc_util_km114_relay_decode_chunk(const uint8_t *payload, uint8_t payload_len, uint16_t *out_total_len, uint8_t *out_frag_index, uint8_t *out_frag_count, const uint8_t **out_chunk, uint8_t *out_chunk_len)
Decodes one chunk's header out of a received RBC_UTIL_TOPIC_KM114_FILE publish payload (payload_len b...
Definition
rbc_util_km114_relay.h:80
RBC_UTIL_KM114_RELAY_MAX_FRAGS
#define RBC_UTIL_KM114_RELAY_MAX_FRAGS
Definition
rbc_util_km114_relay.h:40
site_config_name
const char * site_config_name(rte_example_site_t site)
Definition
site_config.c:52
rte_example_site_t
rte_example_site_t
Definition
site_config.h:20
rbc_util_frame_t
Decoded view of a util frame (payload is a pointer into the caller's buffer, NUL-terminated into payl...
Definition
rbc_util_frame.h:92
rbc_util_frame_t::payload_len
uint8_t payload_len
Definition
rbc_util_frame.h:97
rbc_util_frame_t::payload_z
char payload_z[RBC_UTIL_PAYLOAD_MAX+1U]
Definition
rbc_util_frame.h:98
src
application
AB
GP
com
ab_gp_km114_relay.c
Generated by
1.18.0