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
rbc_util_jru_payload.h
Go to the documentation of this file.
1#ifndef RTE_EXAMPLE_RBC_UTIL_JRU_PAYLOAD_H
2#define RTE_EXAMPLE_RBC_UTIL_JRU_PAYLOAD_H
3
20
21#include <stdbool.h>
22#include <stdio.h>
23#include <string.h>
24
25#include "rte/oal/log/rte_log.h"
26
27#include "rbc_util_frame.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
41static inline void rbc_util_jru_payload_encode(char *out, size_t out_size, rte_log_level_t level,
42 const char *tag, const char *message)
43{
44 (void)snprintf(out, out_size, "%d|%s|%s", (int)level,
45 ((tag != NULL) && (tag[0] != '\0')) ? tag : "-",
46 (message != NULL) ? message : "-");
47}
48
61static inline bool rbc_util_jru_payload_decode(const char *payload, rte_log_level_t *out_level,
62 char *tag_out, size_t tag_out_size, char *msg_out,
63 size_t msg_out_size)
64{
65 const char *p1;
66 const char *p2;
67 size_t tag_len;
68 int lvl;
69
70 tag_out[0] = '\0';
71 msg_out[0] = '\0';
72 *out_level = RTE_LOG_LEVEL_INFO;
73
74 if (payload == NULL)
75 {
76 return false;
77 }
78 p1 = strchr(payload, '|');
79 if (p1 == NULL)
80 {
81 return false;
82 }
83 p2 = strchr(p1 + 1, '|');
84 if (p2 == NULL)
85 {
86 return false;
87 }
88
89 lvl = 0;
90 (void)sscanf(payload, "%d", &lvl);
91 if ((lvl >= (int)RTE_LOG_LEVEL_DEBUG) && (lvl <= (int)RTE_LOG_LEVEL_ERROR))
92 {
93 *out_level = (rte_log_level_t)lvl;
94 }
95
96 tag_len = (size_t)(p2 - (p1 + 1));
97 if (tag_len >= tag_out_size)
98 {
99 tag_len = tag_out_size - 1U;
100 }
101 (void)memcpy(tag_out, p1 + 1, tag_len);
102 tag_out[tag_len] = '\0';
103
104 (void)strncpy(msg_out, p2 + 1, msg_out_size - 1U);
105 msg_out[msg_out_size - 1U] = '\0';
106
107 return true;
108}
109
110#ifdef __cplusplus
111} /* extern "C" */
112#endif
113
114#endif /* RTE_EXAMPLE_RBC_UTIL_JRU_PAYLOAD_H */
ADR-038: the wire frame for the A/B<->C util side channel (RTE_EXAMPLE_RELAY_KIND_UTIL) and the C-sid...
static bool rbc_util_jru_payload_decode(const char *payload, rte_log_level_t *out_level, char *tag_out, size_t tag_out_size, char *msg_out, size_t msg_out_size)
Decodes a JRU_LOG publish payload back into its fields.
static void rbc_util_jru_payload_encode(char *out, size_t out_size, rte_log_level_t level, const char *tag, const char *message)
Encodes one forwarded log event into a JRU_LOG publish payload.