Repository navigation
RaftSysManager
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.
- 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
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
The API provided by this module includes:
-
/reset: Restarts the firmware. -
/v: Retrieves system version information. -
/caps: Lists device capabilities (the names of all registered REST API endpoints) so clients can feature-detect firmware support rather than probing.caps/<name>returns the method and description for one endpoint. See Raft Core API. -
/sysmodinfo: Retrieves information about a SysMod -
/sysmoddebug: Retrieves debug information from a SysMod.sysmoddebug/SysMangives the main loop timing stats and the slow SysMod totals;sysmoddebug/RestAPIgives the deferred response counters. -
/friendlyname: Gets or sets the system's friendly name. -
/serialno: Gets or sets the system's serial number. -
/hwrevno: Retrieves hardware revision information. -
/datetime: Gets or sets the system UTC time. AcceptsUTC(ISO 8601) orepoch(Unix seconds) parameters. The RaftJS library sends this automatically on connect, so devices have correct time even without NTP.
For full a list of Raft APIs with parameters and examples, see Raft API List
SysManager::loop() runs on the main task and calls every SysMod's loop() in turn, so one slow loop() (or REST API handler, which also runs on the main task) holds up everything else - device polling, publishing, the comms links. Aim to keep each pass of the main loop short (around 10 ms), and put slow work elsewhere:
- do it a step at a time from
loop(), or in a task of your own; - do file system work on the shared file system worker - file uploads and downloads,
FileManager's file operations and the web server's static files already use it; - for a REST request that can't be answered at once, defer the response.
When reportSlowSysMod is on (the default, needs supervisorEnable), SysManager times each SysMod's loop() and reports one that takes longer than slowSysModMs (default 50 ms):
- The first slow loop of a SysMod is logged at once, as a warning:
loop sysMod <name> SLOW took <N>ms, with(slow file system write)added if a file system write took over 10 ms during that loop (a flash erase or write stalls all code running from flash, so a SysMod can be slow because of a write somewhere else). - Further slow loops of that SysMod are counted and summarised after 10 seconds:
loop sysMod <name> SLOW <count> more times in <s>s max <N>ms, with the number of slow file system writes in that time. - Totals since startup are returned by
sysmoddebug/SysMan, after the loop timing stats, as"slow":{"n":...,"maxMs":...,"maxMod":"...","fsSlowWrites":...,"fsSlowWriteMs":...}- the number of slow loops, the longest and the SysMod it was in, and the number and total duration of slow file system writes.
See SysManager Settings for the settings.
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);-
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.
This function is called before the main setup. It configures the system name, version, friendly name, and settings like reboot intervals.
This function is responsible for the final setup of the SysManager and SysMods. It creates modules, initializes REST API endpoints, and registers system diagnostics.
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.
Adds a new system module to the manager.
Registers a callback for status changes in a system module.
Retrieves the status of a system module in JSON format.
Get a "named value" (double) from the specified SysMod along with a validity indicator.
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 |
Getting Started
- Quick Start
- Architecture at a Glance
- Writing Your First SysMod
- Adding a Comms Channel
- Adding an I2C Device Type
Scaffolding & Building
- Raft CLI
- Web Apps (Device Types, Flasher)
- SysTypes
- Top-Level SysType
- Build Process
- WebUI Build Pipeline
- File System
- Partitions & Flash
- Local Dev Libraries
- Library Developer Guide
Architecture
Built-in SysMods
- NetworkManager
- WiFi Troubleshooting
- BLEManager
- WebServer
- MQTTManager
- SerialConsole
- CommandSerial
- CommandSocket
- CommandFile
- FileManager
- LogManager
- ESPOTAUpdate
- StatePublisher
- Remote Logging
- Data Source Registration
Comms & Protocols
- Stack Overview
- Comms Channels
- ProtocolExchange
- RICREST Protocol
- Real-Time Streams
- Adding REST Endpoints
- Built-in REST Endpoints
- File Download (OKTO)
- OTA Update Flow
Devices & Buses
- DeviceManager
- Device Manager REST API
- Device Factory & Classes
- Device Type Records
- Adding an I2C Device Type
- Device Data Publishing
- Data Logger
- I2C Bus
- I2C Device Scanning
- I2C ID & Polling
- MotorControl Overview
- MotorControl Config
- MotorControl Commands
- Camera
ROS 2
Helpers
Reference