Skip to content

RaftSysManager

Rob Dobson edited this page Oct 29, 2024 · 3 revisions

Raft SysManager

The SysManager module is responsible for managing system modules (RaftSysMod) in a consistent way. It is a singleton object. Each SysMod derives from the RaftSysMod base class. These modules can be dynamically creted, enabled, disabled, or reconfigured by the SysManager.

Features

  • SysMod Creation: Classes defining SysMods can define a "create" function which is used by a factory-model to construct SysMods. During the setup process the SysManager uses the information in the SysTypes (JSON) to determine which SysMods to construct. Subsequently the application code can create additional SysMods as required.
  • SysMod Configuration: SysMods are configured using JSON via its setup() function. SysMods which are constructed during the SysManager initialization process are provided with the JSON settings that are specified in the SysTypes file. Subsequently created SysMods must be provided with JSON settings information by the application code.
  • SysMod Management: Manages all SysMods (which are derived from RaftSysMod).
  • Interaction by Name: Modules can be accessed by name for more complex interaction such as getting their status, sending JSON "commands", or accessing named-values provided by the SysMod.
  • Looping Mechanism: Each constructed SysMod's loop() function is called iteratively.
  • Supervisory Monitoring: Detects and logs performance issues such as long execution times in system modules.
  • API: This module provides part of the overall API of the app, see Raft API List

SysManager Settings

When constructed normally (in RaftCoreApp for instance) the SysManager is configured using the contents of the SysTypes key SysManager. The settings available to configure SysManager are described in SysManagerSettings

SysManager API

The API provided by this module includes:

  • /reset: Restarts the firmware.
  • /v: Retrieves system version information.
  • /sysmodinfo: Retrieves information about a SysMod
  • /friendlyname: Gets or sets the system's friendly name.
  • /serialno: Gets or sets the system's serial number.
  • /hwrevno: Retrieves hardware revision information.

For full a list of Raft APIs with parameters and examples, see Raft API List

Constructor

The constructor initializes the SysManager with essential parameters such as module names, system configuration, and serial information.

SysManager::SysManager(const char* pModuleName,
                RaftJsonIF& systemConfig,
                const String sysManagerNVSNamespace,
                SysTypeManager& sysTypeManager,
                const char* pSystemName,
                const char* pDefaultFriendlyName,
                uint32_t serialLengthBytes, 
                const char* pSerialMagicStr);

Parameters

  • pModuleName: The name of the system manager (this must match the name used in the SysTypes JSON configuration for the SysManager object)
  • systemConfig: Configuration information (JSON) - this is generally the entire SysTypes JSON.
  • sysManagerNVSNamespace: Namespace for NVS storage area to be used the system manager.
  • sysTypeManager: The manager SysTypes (which allows overriding SysType settings using an API).
  • pSystemName: Name of the system (used as a default if not specified in the SysType).
  • pDefaultFriendlyName: A friendly name for the system (used as a default, can be overriden by the user using the API).
  • serialLengthBytes: Length of the system's serial number.
  • pSerialMagicStr: A magic string for validating serial numbers.

Key Functions

void preSetup()

This function is called before the main setup. It configures the system name, version, friendly name, and settings like reboot intervals.

void postSetup()

This function is responsible for the final setup of the SysManager and SysMods. It creates modules, initializes REST API endpoints, and registers system diagnostics.

void loop()

The main loop of the SysManager where all registered modules are iterated over and their respective loop() functions are called. It also manages timing, monitors system performance, and handles system restarts if necessary.

void addManagedSysMod(RaftSysMod* pSysMod)

Adds a new system module to the manager.

void setStatusChangeCB(const char* sysModName, SysMod_statusChangeCB statusChangeCB)

Registers a callback for status changes in a system module.

String getStatusJSON(const char* sysModName) const

Retrieves the status of a system module in JSON format.

double getNamedValue(const char* sysModName, const char* valueName, bool& isValid)

Get a "named value" (double) from the specified SysMod along with a validity indicator.

void setModuleLogLevel(const char* pModuleName, const String& logLevel)

Set the logging level for a SysMod. Valid logLevel strings:

logLevel Meaning
N No logging
E Error
W Warning
I Info
D Debug
V Verbose

Clone this wiki locally