4#include <condition_variable>
11#include <nlohmann/json_fwd.hpp>
50 using PublishFn = std::function<void(std::string topic, std::string json)>;
78 bool remove(
const std::string& topic);
82 std::optional<nlohmann::json>
get(
const std::string& topic)
const;
85 nlohmann::json
list()
const;
105 enum class Source { Pdo, Sdo };
110 uint16_t devicePosition = 0;
112 uint8_t subindex = 0;
113 Source source = Source::Pdo;
114 std::optional<DeviceManager::PdoSampleSpec> pdoSpec;
121 int64_t timestampUs = 0;
122 std::vector<std::optional<DeviceParameterValue>> values;
128 std::vector<ParamPlan> plans;
130 bool cursorPrimed =
false;
131 uint64_t imageGeneration = 0;
132 std::chrono::steady_clock::time_point nextDue{};
135 void flushEntry(Entry& entry);
136 void recaptureIfRemapped(
138 static nlohmann::json resourceJson(
const Entry& entry);
144 DeviceManager& deviceManager_;
145 ParameterRefresher refresher_;
146 mutable std::mutex mutex_;
147 std::condition_variable cv_;
148 std::map<std::string, Entry> entries_;
150 bool running_ =
false;
Owns the fieldbus driver and node collection, and drives PDO exchange.
Definition device_manager.h:181
Owns the active monitorings and turns each into a lossless stream of recorded rows.
Definition monitoring_manager.h:46
std::size_t polledSdoCount() const
Number of distinct SDO objects currently polled by the refresher. For tests / status.
Definition monitoring_manager.cc:222
std::expected< Monitoring, std::string > create(Monitoring config)
Validates config, classifies its parameters, registers SDO ones with the refresher,...
Definition monitoring_manager.cc:48
void setPublish(PublishFn publish)
Sets the batch publish callback. Call before start().
Definition monitoring_manager.cc:43
MonitoringManager(const MonitoringManager &)=delete
std::optional< nlohmann::json > get(const std::string &topic) const
Returns the monitoring resource as JSON (config + per-parameter source + buffer fill),...
Definition monitoring_manager.cc:144
bool remove(const std::string &topic)
Removes a monitoring, releasing its SDO parameters from the refresher.
Definition monitoring_manager.cc:128
MonitoringManager & operator=(const MonitoringManager &)=delete
void sampleAll()
Flushes every monitoring once: delivers each one's recorded cycles since its last flush....
Definition monitoring_manager.cc:210
void start()
Starts the owned refresher (and, once added, the sampler thread). Idempotent.
Definition monitoring_manager.cc:162
std::function< void(std::string topic, std::string json)> PublishFn
Publishes one batch: json (a {"type":"monitoring","topic",...} envelope) under topic....
Definition monitoring_manager.h:50
~MonitoringManager()
Stops the owned refresher (and, once added, the sampler thread).
Definition monitoring_manager.cc:41
nlohmann::json list() const
Returns all monitoring resources as a JSON array, in topic order.
Definition monitoring_manager.cc:153
void stop()
Stops the owned refresher (and, once added, the sampler thread). Idempotent.
Definition monitoring_manager.cc:173
std::size_t monitoringCount() const
Number of registered monitorings. For tests / status.
Definition monitoring_manager.cc:217
Definition http_server.h:16
A client-defined recording of a set of parameters streamed over time.
Definition monitoring.h:28