Motion Master 6.0.0-alpha.111
Next-generation motion control software
Loading...
Searching...
No Matches
config.cc File Reference
#include "config.h"
#include <algorithm>
#include <array>
#include <string>
#include <thread>
Include dependency graph for config.cc:

Functions

std::expected< Config, std::string > parseConfig (const nlohmann::json &doc)
 Deserialises a parsed JSONC document into a Config, applying defaults for absent keys.
 
std::expected< void, std::string > validateFieldbusConfig (const FieldbusConfig &fieldbus)
 Checks the "fieldbus" block. The config file and POST /api/init share it.
 

Function Documentation

◆ parseConfig()

std::expected< Config, std::string > parseConfig ( const nlohmann::json &  doc)

Deserialises a parsed JSONC document into a Config, applying defaults for absent keys.

Pure: no file I/O, no process exit. Unknown keys are ignored (forward-compatible). nlohmann validates value types; this adds the enum and range checks it cannot (logging.level, fieldbus.driver; gameLoop.periodUs, recorder.capacity and autoTuning.port must be > 0).

Parameters
docA parsed JSON value (must be an object).
Returns
The populated Config, or an error string on a wrong top-level type, a field type mismatch (from nlohmann), or an invalid enum value.

◆ validateFieldbusConfig()

std::expected< void, std::string > validateFieldbusConfig ( const FieldbusConfig &  fieldbus)

Checks the "fieldbus" block. The config file and POST /api/init share it.

An empty driver passes, because it means "do not init". For "spoe" it needs at least one address, a known mode, a watchdogMs of at least 50 and a nonzero port.