4#include <condition_variable>
11#include <nlohmann/json_fwd.hpp>
66 using PublishFn = std::function<void(std::string topic, std::string json)>;
94 bool remove(
const std::string& topic);
98 std::optional<nlohmann::json>
get(
const std::string& topic)
const;
101 nlohmann::json
list()
const;
132 std::chrono::milliseconds period);
149 enum class Source { Pdo, Sdo };
154 uint16_t devicePosition = 0;
157 Source source = Source::Pdo;
158 std::optional<DeviceManager::PdoSampleSpec> pdoSpec;
165 int64_t timestampUs = 0;
166 std::vector<std::optional<DeviceParameterValue>> values;
172 std::vector<ParamPlan> plans;
175 bool cursorPrimed =
false;
176 uint64_t imageGeneration = 0;
177 std::chrono::steady_clock::time_point nextDue{};
192 std::chrono::milliseconds interval{};
193 std::vector<ParamPlan> plans;
195 bool cursorPrimed =
false;
196 uint64_t imageGeneration = 0;
201 std::vector<FlushState> takeDue(std::chrono::steady_clock::time_point now,
bool forceAll);
205 void flushDetached(FlushState& state,
const PublishFn& publish);
209 void commitFlush(
const FlushState& state);
213 void flushDue(std::unique_lock<std::mutex>& lock, std::chrono::steady_clock::time_point now,
218 void recaptureIfRemapped(FlushState& state);
220 static nlohmann::json resourceJson(
const Entry& entry);
226 DeviceManager& deviceManager_;
227 ParameterRefresher refresher_;
228 mutable std::mutex mutex_;
229 std::condition_variable cv_;
230 std::map<std::string, Entry> entries_;
231 uint64_t nextEpoch_ = 1;
233 bool running_ =
false;
Owns the fieldbus driver and node collection, and drives PDO exchange.
Definition device_manager.h:287
Owns the active monitorings and turns each into a lossless stream of recorded rows.
Definition monitoring_manager.h:62
std::size_t polledSdoCount() const
Number of distinct SDO objects currently polled by the refresher. For tests / status.
Definition monitoring_manager.cc:289
std::expected< Monitoring, std::string > create(Monitoring config)
Validates config, classifies its parameters, registers SDO ones with the refresher,...
Definition monitoring_manager.cc:49
void setPublish(PublishFn publish)
Sets the batch publish callback. Call before start().
Definition monitoring_manager.cc:44
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:154
bool remove(const std::string &topic)
Removes a monitoring, releasing its SDO parameters from the refresher.
Definition monitoring_manager.cc:138
MonitoringManager & operator=(const MonitoringManager &)=delete
void stopKeepingFresh(uint16_t devicePosition, uint16_t index, uint8_t subindex)
Drops a reference taken by keepFresh. Polling stops when the last one is released.
Definition monitoring_manager.cc:223
void keepFresh(uint16_t devicePosition, uint16_t index, uint8_t subindex, std::chrono::milliseconds period)
Keeps an SDO-only object's value fresh in the background, for a cyclic task to read.
Definition monitoring_manager.cc:215
void sampleAll()
Flushes every monitoring once: delivers each one's recorded cycles since its last flush....
Definition monitoring_manager.cc:228
void start()
Starts the owned refresher (and, once added, the sampler thread). Idempotent.
Definition monitoring_manager.cc:172
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:66
~MonitoringManager()
Stops the owned refresher (and, once added, the sampler thread).
Definition monitoring_manager.cc:42
nlohmann::json list() const
Returns all monitoring resources as a JSON array, in topic order.
Definition monitoring_manager.cc:163
void stop()
Stops the owned refresher (and, once added, the sampler thread). Idempotent.
Definition monitoring_manager.cc:183
std::size_t monitoringCount() const
Number of registered monitorings. For tests / status.
Definition monitoring_manager.cc:284
uint8_t subindex
Definition esi_entry.cc:283
Definition bus_health_source.h:7
A client-defined recording of a set of parameters streamed over time.
Definition monitoring.h:28