Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
mm::node::MonitoringManager Class Reference

Owns the active monitorings and turns each into a lossless stream of recorded rows. More...

#include <monitoring_manager.h>

Public Types

using PublishFn = std::function< void(std::string topic, std::string json)>
 Publishes one batch: json (a {"type":"monitoring","topic",...} envelope) under topic. Wired in the composition root to the WebSocket server's topic publish.
 

Public Member Functions

 MonitoringManager (DeviceManager &deviceManager)
 Constructs the manager over deviceManager. Does not start sampling — call start().
 
 ~MonitoringManager ()
 Stops the owned refresher (and, once added, the sampler thread).
 
 MonitoringManager (const MonitoringManager &)=delete
 
MonitoringManageroperator= (const MonitoringManager &)=delete
 
void setPublish (PublishFn publish)
 Sets the batch publish callback. Call before start().
 
std::expected< Monitoring, std::string > create (Monitoring config)
 Validates config, classifies its parameters, registers SDO ones with the refresher, and registers the monitoring.
 
bool remove (const std::string &topic)
 Removes a monitoring, releasing its SDO parameters from the refresher.
 
std::optional< nlohmann::json > get (const std::string &topic) const
 Returns the monitoring resource as JSON (config + per-parameter source + buffer fill), or nullopt if topic is unknown.
 
nlohmann::json list () const
 Returns all monitoring resources as a JSON array, in topic order.
 
void start ()
 Starts the owned refresher (and, once added, the sampler thread). Idempotent.
 
void stop ()
 Stops the owned refresher (and, once added, the sampler thread). Idempotent.
 
void sampleAll ()
 Flushes every monitoring once: delivers each one's recorded cycles since its last flush. The deterministic core the scheduler thread drives; exposed for tests.
 
std::size_t monitoringCount () const
 Number of registered monitorings. For tests / status.
 
std::size_t polledSdoCount () const
 Number of distinct SDO objects currently polled by the refresher. For tests / status.
 

Detailed Description

Owns the active monitorings and turns each into a lossless stream of recorded rows.

A client creates a Monitoring (topic, interval, parameters); the manager validates it, classifies every parameter by how its value is sourced, and on each flush ships every process-data cycle recorded since the last flush. The stream is lossless: each monitoring holds a read cursor into the recorder ring and, each time it is due, decodes and publishes every cycle-row in [cursor, recorderHead()) as one batch, then advances the cursor. interval is the flush cadence, not a sample rate — a longer interval means a bigger batch, never dropped cycles. A cursor that falls more than a whole ring behind (a stalled client) is logged and resynced to the oldest available cycle; the gap is never silent.

Sourcing (decided once at create, against the published process image):

  • PDO — the object is mapped in the live image; its value is decoded for each recorded cycle from that cycle's ring record (no bus access, all values in a row from the same cycle). The decode spec is captured up front and re-captured on a re-map.
  • SDO — the object is not PDO-mapped; it is registered with the owned ParameterRefresher which polls it in the background, and the sampler reads the cached value.

Monitoring is live-only: a parameter whose owning device is not exchanging (SAFE-OP/OP) samples null. Topics are unique.

Thread-safe. Owns a private ParameterRefresher (the sampler is its sole client). The App wires only this manager (with a DeviceManager& and a publish callback).

Member Typedef Documentation

◆ PublishFn

using mm::node::MonitoringManager::PublishFn = std::function<void(std::string topic, std::string json)>

Publishes one batch: json (a {"type":"monitoring","topic",...} envelope) under topic. Wired in the composition root to the WebSocket server's topic publish.

Constructor & Destructor Documentation

◆ MonitoringManager() [1/2]

mm::node::MonitoringManager::MonitoringManager ( DeviceManager deviceManager)
explicit

Constructs the manager over deviceManager. Does not start sampling — call start().

◆ ~MonitoringManager()

mm::node::MonitoringManager::~MonitoringManager ( )

Stops the owned refresher (and, once added, the sampler thread).

◆ MonitoringManager() [2/2]

mm::node::MonitoringManager::MonitoringManager ( const MonitoringManager )
delete

Member Function Documentation

◆ create()

std::expected< Monitoring, std::string > mm::node::MonitoringManager::create ( Monitoring  config)

Validates config, classifies its parameters, registers SDO ones with the refresher, and registers the monitoring.

Validation: topic URL-safe; not already registered; interval between 5 ms and 2000 ms (the flush cadence); parameters non-empty; and every parameter is either PDO-mapped or present in its device's object dictionary (otherwise it cannot be sourced).

Returns
The created configuration on success, or an error string describing the first validation failure.

◆ get()

std::optional< nlohmann::json > mm::node::MonitoringManager::get ( const std::string &  topic) const

Returns the monitoring resource as JSON (config + per-parameter source + buffer fill), or nullopt if topic is unknown.

◆ list()

nlohmann::json mm::node::MonitoringManager::list ( ) const

Returns all monitoring resources as a JSON array, in topic order.

◆ monitoringCount()

std::size_t mm::node::MonitoringManager::monitoringCount ( ) const

Number of registered monitorings. For tests / status.

◆ operator=()

MonitoringManager & mm::node::MonitoringManager::operator= ( const MonitoringManager )
delete

◆ polledSdoCount()

std::size_t mm::node::MonitoringManager::polledSdoCount ( ) const

Number of distinct SDO objects currently polled by the refresher. For tests / status.

◆ remove()

bool mm::node::MonitoringManager::remove ( const std::string &  topic)

Removes a monitoring, releasing its SDO parameters from the refresher.

Returns
true if a monitoring with topic existed, false otherwise.

◆ sampleAll()

void mm::node::MonitoringManager::sampleAll ( )

Flushes every monitoring once: delivers each one's recorded cycles since its last flush. The deterministic core the scheduler thread drives; exposed for tests.

◆ setPublish()

void mm::node::MonitoringManager::setPublish ( PublishFn  publish)

Sets the batch publish callback. Call before start().

◆ start()

void mm::node::MonitoringManager::start ( )

Starts the owned refresher (and, once added, the sampler thread). Idempotent.

◆ stop()

void mm::node::MonitoringManager::stop ( )

Stops the owned refresher (and, once added, the sampler thread). Idempotent.


The documentation for this class was generated from the following files: