EduArt Sensor Ring Library 4.0.0
Loading...
Searching...
No Matches
Sensor.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <future>
13#include <mutex>
14#include <optional>
15
18#include "sensorring/platform/SensorringExport.hpp"
19
20namespace eduart {
21
22namespace sensorring {
23
24namespace device {
25
33class SENSORRING_EXPORT Sensor : public Device {
34public:
41 Sensor(DeviceID id, com::ComInterface* interface, com::ComEndpoint target);
42
43 ~Sensor() override;
44
45 // -- state / measurement synchronisation --
46 std::future<bool> measure(std::uint8_t sequence_number);
47 std::future<bool> fetch();
48
53 std::future<bool> beginMeasurementWait();
54
59 void setMeasurementReady(bool success);
60
65 std::future<bool> beginDataAvailableWait();
66
71 void setDataAvailableReady(bool success);
72
75
78
79protected:
80 virtual bool sendMeasurementRequest(std::uint8_t sequence_number) = 0;
81 virtual bool sendMeasurementTransmissionRequest() = 0;
82
83 virtual void onResetSensorState() {}
84 virtual void onClearDataFlag() {}
85
86 DeviceState _state;
87 mutable std::mutex _state_mutex;
88
89 std::mutex _promise_mutex;
90 std::optional<std::promise<bool> > _data_available_promise;
91 std::optional<std::promise<bool> > _measurement_promise;
92};
93
94} // namespace device
95
96} // namespace sensorring
97
98} // namespace eduart
Unified device state enum covering lifecycle and runtime health.
Base class for all concrete sensor/actuator devices.
Device(DeviceID id, com::ComInterface *interface, com::ComEndpoint target)
Construct the device with identity and communication link.
std::future< bool > beginMeasurementWait()
Begin an asynchronous wait for the next measurement trigger.
void resetSensorState()
Reset the device to its initialised state, clearing all error flags.
std::future< bool > beginDataAvailableWait()
Begin an asynchronous wait for new data to become available.
void setDataAvailableReady(bool success)
Satisfy the pending data-available-wait future.
void clearDataFlag()
Clear the data-available flag so the device can accept the next measurement cycle.
Sensor(DeviceID id, com::ComInterface *interface, com::ComEndpoint target)
Construct the sensor with identity and communication link.
void setMeasurementReady(bool success)
Satisfy the pending measurement-wait future.
Uniquely identifies a communication endpoint as a (Direction, BoardAddress, DeviceId) tuple.
Definition ComEndpoint.hpp:37
Identifier for a device: type, human-readable name, and index.
Definition DeviceID.hpp:27