roo_transceivers
API Documentation for roo_transceivers
Loading...
Searching...
No Matches
simple_sensor_universe.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace roo_transceivers {
6
7/// Convenience `Universe` for identical, basic sensor-only transceivers.
8///
9/// Each device exposes exactly one sensor and no actuators.
10///
11/// Can be used e.g. for a collection of identical thermometers.
12///
13/// This class implements the full `Universe` contract. Implementations only
14/// need to provide:
15/// - `readSensor()` to return reading for a device,
16/// - `getSensorQuantity()` to define sensor quantity type.
18 public:
19 /// Synthesizes a single-sensor descriptor for `locator`.
20 ///
21 /// Returns `false` when `locator` is not recognized by this universe.
23 const DeviceLocator& locator,
24 roo_transceivers_Descriptor& descriptor) const override {
27 return false;
28 }
29 descriptor.sensors_count = 1;
30 descriptor.sensors[0].id[0] = 0;
31 descriptor.sensors[0].quantity = quantity;
32 descriptor.actuators_count = 0;
33 return true;
34 }
35
36 /// Reads the single sensor of a device.
37 ///
38 /// Only empty sensor id (`""`) is valid. Any non-empty sensor id returns an
39 /// initial/unspecified measurement.
40 Measurement read(const SensorLocator& locator) const override {
41 if (!locator.sensor_id().empty()) {
42 return Measurement();
43 }
44 return readSensor(locator.device_locator());
45 }
46
47 /// This universe is sensor-only; writes are always rejected.
48 bool write(const ActuatorLocator& locator, float value) override {
49 return false;
50 }
51
52 protected:
53 virtual Measurement readSensor(const DeviceLocator& locator) const = 0;
54
56 DeviceLocator device_locator) const = 0;
57};
58
59} // namespace roo_transceivers
Identifies actuator within a transceiver device.
Definition id.h:104
Identifies a transceiver device by schema and device id.
Definition id.h:21
Measurement of a quantity at a specific time.
Definition measurement.h:11
Identifies sensor within a transceiver device.
Definition id.h:57
const SensorId & sensor_id() const
Returns the sensor id.
Definition id.h:76
const DeviceLocator & device_locator() const
Returns the device locator.
Definition id.h:67
Convenience Universe for identical, basic sensor-only transceivers.
virtual roo_transceivers_Quantity getSensorQuantity(DeviceLocator device_locator) const =0
bool getDeviceDescriptor(const DeviceLocator &locator, roo_transceivers_Descriptor &descriptor) const override
Synthesizes a single-sensor descriptor for locator.
virtual Measurement readSensor(const DeviceLocator &locator) const =0
Measurement read(const SensorLocator &locator) const override
Reads the single sensor of a device.
bool write(const ActuatorLocator &locator, float value) override
This universe is sensor-only; writes are always rejected.
An abstract collection of transceiver devices.
Definition universe.h:19
@ roo_transceivers_Quantity_kUnspecifiedQuantity
enum _roo_transceivers_Quantity roo_transceivers_Quantity
roo_transceivers_Descriptor_Sensor sensors[16]