Safe Communication Framework 0.1.0 build feea4f9
ERTMS/ETCS safe communication (Subset-037 EuroRadio, Subset-098 RBC/RBC), CENELEC EN 50128 SIL 4 oriented
Loading...
Searching...
No Matches
config.h File Reference

File-based configuration for the Safe Communication Framework. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "safecomm/status.h"
Include dependency graph for config.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  safecomm_config_entry_t
 One parsed key/value pair. More...
struct  safecomm_config_t
 A loaded configuration file. Caller-allocated, opaque in use. More...

Macros

#define SAFECOMM_CONFIG_MAX_ENTRIES   64U
#define SAFECOMM_CONFIG_MAX_KEY_LEN   64U
#define SAFECOMM_CONFIG_MAX_VALUE_LEN   192U
#define SAFECOMM_CONFIG_MAX_LINE_LEN   320U

Functions

safecomm_status_t safecomm_config_load (const char *path, safecomm_config_t *out)
 Load path into out (fully overwrites it).
const char * safecomm_config_get_str (const safecomm_config_t *cfg, const char *key)
 Raw string value for key.
safecomm_status_t safecomm_config_get_u32 (const safecomm_config_t *cfg, const char *key, uint32_t *out)
 Unsigned-integer value for key.
safecomm_status_t safecomm_config_get_bool (const safecomm_config_t *cfg, const char *key, bool *out)
 Boolean value for key ("true"/"false"/"1"/"0", case-insensitive).

Detailed Description

File-based configuration for the Safe Communication Framework.

Every runtime parameter of the stack is read from a plain text file, never hard-coded and never passed as a long argv list — one file per node (A, B, Gateway), same "configuration lives in files" convention as the rest of the RBC_Template workspace (packaging.conf, sim config.json).

Format (deliberately minimal — MISRA-friendly, deterministic, no external parser):

comment

saf.role = responder saf.etcs_id_self = 4661 saf.etcs_id_peer = 0 # 0 = accept any (responder) saf.t_connect_ms = 10000 saf.t_supervision_ms= 20000 saf.seq_window = 8 cfm.profile = euroradio # euroradio | rbc_rbc cfm.peer_host = 10.0.0.7 cfm.peer_port = 7911 cfm.bind_port = 7911 cfm.retry_ms = 5000 keys.kmac_file = /etc/safecomm/kmac_evc.key # 48 hex chars = 24 bytes ale.listen_host = 0.0.0.0 # Gateway only ale.listen_port = 15010 ale.peer_map_file = /etc/safecomm/peers.map

Keys are flat "group.name"; there are no sections (no section-state in the parser). Unknown keys are kept verbatim and ignored by components that do not consume them. A component RANGE-CHECKS every value it reads at init and refuses to start on a bad one — the loader itself performs no semantic validation, so parsing stays non-vital.

REQ-SC-CFG-001..012 — see docs/requirements/SRS.md.

Definition in file config.h.

Macro Definition Documentation

◆ SAFECOMM_CONFIG_MAX_ENTRIES

#define SAFECOMM_CONFIG_MAX_ENTRIES   64U

Limits — fixed storage, no dynamic allocation.

Definition at line 52 of file config.h.

◆ SAFECOMM_CONFIG_MAX_KEY_LEN

#define SAFECOMM_CONFIG_MAX_KEY_LEN   64U

Definition at line 53 of file config.h.

◆ SAFECOMM_CONFIG_MAX_VALUE_LEN

#define SAFECOMM_CONFIG_MAX_VALUE_LEN   192U

Definition at line 54 of file config.h.

◆ SAFECOMM_CONFIG_MAX_LINE_LEN

#define SAFECOMM_CONFIG_MAX_LINE_LEN   320U

Definition at line 55 of file config.h.

Function Documentation

◆ safecomm_config_load()

safecomm_status_t safecomm_config_load ( const char * path,
safecomm_config_t * out )

Load path into out (fully overwrites it).

Reads at most SAFECOMM_CONFIG_MAX_ENTRIES key = value lines. Blank lines and lines whose first non-space character is '#' are skipped. Leading/trailing whitespace is trimmed from both key and value; an inline # ... comment after the value is stripped. No semantic checks.

Parameters
pathfile path (NUL-terminated). Non-NULL.
outreceives the parsed entries. Non-NULL.
Returns
SAFECOMM_STATUS_OK, SAFECOMM_STATUS_INVALID_PARAM (NULL args), SAFECOMM_STATUS_TRANSPORT (file cannot be opened / read), SAFECOMM_STATUS_BUFFER_TOO_SMALL (a line or the entry table overflows).
Note
REQ-SC-CFG-002.

Definition at line 74 of file config.c.

◆ safecomm_config_get_str()

const char * safecomm_config_get_str ( const safecomm_config_t * cfg,
const char * key )

Raw string value for key.

Returns
pointer into cfg (valid for its lifetime), or NULL if absent.
Note
REQ-SC-CFG-005.

Definition at line 141 of file config.c.

◆ safecomm_config_get_u32()

safecomm_status_t safecomm_config_get_u32 ( const safecomm_config_t * cfg,
const char * key,
uint32_t * out )

Unsigned-integer value for key.

Parameters
cfgloaded config. Non-NULL.
keyflat "group.name". Non-NULL.
outreceives the value on success. Non-NULL.
Returns
SAFECOMM_STATUS_OK, SAFECOMM_STATUS_INVALID_PARAM (absent key or not a base-10 uint32).
Note
REQ-SC-CFG-006. Callers still range-check the result.

Definition at line 159 of file config.c.

◆ safecomm_config_get_bool()

safecomm_status_t safecomm_config_get_bool ( const safecomm_config_t * cfg,
const char * key,
bool * out )

Boolean value for key ("true"/"false"/"1"/"0", case-insensitive).

Returns
SAFECOMM_STATUS_OK or SAFECOMM_STATUS_INVALID_PARAM.
Note
REQ-SC-CFG-007.

Definition at line 178 of file config.c.