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_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
14#include "ab_gp_km114_client.h"
15
17
19
22static uint16_t s_total_len;
23static uint8_t s_frag_count;
25static uint8_t s_frags_seen_count;
26
28void ab_gp_km114_relay_on_frame(const rbc_util_frame_t *frame, const char *role_tag, rte_example_site_t site,
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;
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;
83 }
84
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;
98 }
99}
struct ab_gp_channel_context_s * ab_gp_channel_handle_t
Opaque handle over this component's own static per-process context.
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.
A/B-side Subset-114 KMC message decoder - step 2 of Platform_Protocol_KM114's "Consumption design" (s...
static uint8_t s_frag_count
static uint16_t s_total_len
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.
static uint8_t s_frags_seen_count
static uint8_t s_buf[RBC_UTIL_KM114_RELAY_FILE_MAX]
static bool s_frag_seen[RBC_UTIL_KM114_RELAY_MAX_FRAGS]
A/B-side receiver for Gateway-relayed Subset-114 off-line KMC file bytes (RBC_UTIL_TOPIC_KM114_FILE,...
Wire chunking for RBC_UTIL_TOPIC_KM114_FILE publishes: Gateway relays one opaque Subset-114 off-line ...
#define RBC_UTIL_KM114_RELAY_FILE_MAX
#define RBC_UTIL_KM114_RELAY_CHUNK_MAX
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...
#define RBC_UTIL_KM114_RELAY_MAX_FRAGS
const char * site_config_name(rte_example_site_t site)
Definition site_config.c:52
rte_example_site_t
Definition site_config.h:20
Decoded view of a util frame (payload is a pointer into the caller's buffer, NUL-terminated into payl...
char payload_z[RBC_UTIL_PAYLOAD_MAX+1U]