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_config.c File Reference

Zero-dependency, statically-allocated configuration parser for Role A/B. More...

#include "ab_gp_config.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rte/oal/memory/rte_mem_util.h"
#include "../../common/common_config.h"
Include dependency graph for ab_gp_config.c:

Go to the source code of this file.

Macros

#define MAX_LINE_LEN   256U

Functions

static void trim_whitespace (char *str)
static ab_gp_config_channel_t * get_or_create_channel (ab_gp_config_t *cfg, const char *name)
rte_status_t ab_gp_config_init_defaults (rte_example_site_t site, bool is_role_a, ab_gp_config_t *out_cfg)
 Initializes default configuration in memory based on site and role.
static void apply_timer_setting (ab_gp_config_timers_t *timers, const char *key, const char *val)
static void apply_channel_setting (ab_gp_config_channel_t *ch, const char *key, const char *val)
static void apply_global_setting (ab_gp_config_t *cfg, const char *key, const char *val)
rte_status_t ab_gp_config_load_file (const char *filepath, ab_gp_config_t *out_cfg)
 Parses an INI-style configuration file into the static ab_gp_config_t structure.
rte_status_t ab_gp_config_find_channel (const ab_gp_config_t *cfg, const char *channel_name, rte_netlink_config_t *out_netlink_cfg)
 Resolves netlink configuration for a named channel from the parsed config.
rte_status_t ab_gp_config_find_channel_by_id (const ab_gp_config_t *cfg, uint32_t channel_id, rte_netlink_config_t *out_netlink_cfg)
 Resolves netlink configuration for a channel by numeric ID from the parsed config.

Detailed Description

Zero-dependency, statically-allocated configuration parser for Role A/B.

Compliant with CENELEC EN 50128 SIL 4 and MISRA C:2012. Strictly no dynamic memory allocation.

Definition in file ab_gp_config.c.

Macro Definition Documentation

◆ MAX_LINE_LEN

#define MAX_LINE_LEN   256U

Definition at line 19 of file ab_gp_config.c.

Function Documentation

◆ trim_whitespace()

void trim_whitespace ( char * str)
static

Definition at line 21 of file ab_gp_config.c.

◆ get_or_create_channel()

ab_gp_config_channel_t * get_or_create_channel ( ab_gp_config_t * cfg,
const char * name )
static

Definition at line 54 of file ab_gp_config.c.

◆ ab_gp_config_init_defaults()

rte_status_t ab_gp_config_init_defaults ( rte_example_site_t site,
bool is_role_a,
ab_gp_config_t * out_cfg )

Initializes default configuration in memory based on site and role.

Definition at line 79 of file ab_gp_config.c.

◆ apply_timer_setting()

void apply_timer_setting ( ab_gp_config_timers_t * timers,
const char * key,
const char * val )
static

Definition at line 109 of file ab_gp_config.c.

◆ apply_channel_setting()

void apply_channel_setting ( ab_gp_config_channel_t * ch,
const char * key,
const char * val )
static

Definition at line 170 of file ab_gp_config.c.

◆ apply_global_setting()

void apply_global_setting ( ab_gp_config_t * cfg,
const char * key,
const char * val )
static

Definition at line 212 of file ab_gp_config.c.

◆ ab_gp_config_load_file()

rte_status_t ab_gp_config_load_file ( const char * filepath,
ab_gp_config_t * out_cfg )

Parses an INI-style configuration file into the static ab_gp_config_t structure.

Parameters
filepathPath to the configuration file.
out_cfgTarget configuration struct.
Returns
RTE_STATUS_OK on success, or error status code on failure.

Definition at line 228 of file ab_gp_config.c.

◆ ab_gp_config_find_channel()

rte_status_t ab_gp_config_find_channel ( const ab_gp_config_t * cfg,
const char * channel_name,
rte_netlink_config_t * out_netlink_cfg )

Resolves netlink configuration for a named channel from the parsed config.

Parameters
cfgParsed configuration.
channel_nameChannel identifier string (e.g. "ab-peer", "ab-relay-train-0").
out_netlink_cfgReceives resolved netlink configuration.
Returns
RTE_STATUS_OK if found, RTE_STATUS_NOT_FOUND otherwise.

Definition at line 316 of file ab_gp_config.c.

◆ ab_gp_config_find_channel_by_id()

rte_status_t ab_gp_config_find_channel_by_id ( const ab_gp_config_t * cfg,
uint32_t channel_id,
rte_netlink_config_t * out_netlink_cfg )

Resolves netlink configuration for a channel by numeric ID from the parsed config.

Parameters
cfgParsed configuration.
channel_idChannel numeric ID (e.g. 1 for ab-peer).
out_netlink_cfgReceives resolved netlink configuration.
Returns
RTE_STATUS_OK if found, RTE_STATUS_NOT_FOUND otherwise.

Definition at line 345 of file ab_gp_config.c.