EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
SensorRingFactory.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <string>
13#include <unordered_map>
14#include <variant>
15#include <vector>
16
21#include "sensorring/device/hardware/htpa32/HTPA32_Params.hpp"
22#include "sensorring/device/hardware/vl53l8cx/VL53L8CX_Params.hpp"
23#include "sensorring/device/hardware/ws2812b/WS2812b_Params.hpp"
25#include "sensorring/platform/SensorringExport.hpp"
26
27namespace eduart {
28
29namespace ring {
30
43
68class SENSORRING_EXPORT SensorRingFactory {
69public:
71 using DeviceParamsVariant = std::variant<device::VL53L8CX_Params, device::HTPA32_Params, device::WS2812b_Params>;
72
74 using EnumerationMap = std::unordered_map<com::ComInterfaceID, std::vector<device::EnumerationInformation> >;
75
77 static constexpr Version MIN_FIRMWARE_VERSION = { 0, 8, 0 };
78
86
95
103 void expectBoard(device::SensorBoardParams params, std::vector<DeviceParamsVariant> device_params);
104
112
121 std::unique_ptr<SensorRing> build(ValidationMode mode = ValidationMode::Strict);
122
133
139
144 std::string printTopology() const;
145
149 void reset();
150
151private:
152 struct BoardExpectation {
154 std::vector<DeviceParamsVariant> device_params;
155 bool has_explicit_devices = false;
156 };
157
158 struct InterfaceConfig {
159 com::ComInterfaceID interface;
160 std::vector<BoardExpectation> expected_boards;
161 bool has_expectations = false;
162 };
163
164 static device::DeviceType deviceTypeFromVariant(const DeviceParamsVariant& v);
165
167 std::unordered_map<device::DeviceType, DeviceParamsVariant> buildDefaultParamsMap(const std::vector<device::DeviceType>& devices) const;
168
169 std::vector<InterfaceConfig> _interfaces;
170 std::unordered_map<device::DeviceType, DeviceParamsVariant> _default_device_params;
171 EnumerationMap _enumeration_results;
172};
173
174} // namespace ring
175
176} // namespace eduart
Interface type definition.
Enumeration of supported device hardware types.
DeviceType
Supported device hardware types used for device registration and grouping.
Definition DeviceType.hpp:25
Version, commit hash, and board enumeration info reported by hardware.
Parameter structure of a sensor board.
ValidationMode
Controls how build() handles mismatches between expectations and discovered hardware.
Definition SensorRingFactory.hpp:35
@ Strict
All expectations must match exactly by index; build() returns nullptr on any mismatch.
Definition SensorRingFactory.hpp:37
@ Relaxed
Definition SensorRingFactory.hpp:41
Top-level container managing multiple sensor buses.
Factory for creating a SensorRing.
Definition SensorRingFactory.hpp:68
void expectBoard(device::SensorBoardParams params)
Declare an expected board on the current interface.
static constexpr Version MIN_FIRMWARE_VERSION
Minimum sensor board firmware version required by this library version.
Definition SensorRingFactory.hpp:77
std::unordered_map< com::ComInterfaceID, std::vector< device::EnumerationInformation > > EnumerationMap
Per-interface enumeration results, keyed by interface ID.
Definition SensorRingFactory.hpp:74
std::string printTopology() const
Format the latest enumeration results as a human-readable topology string.
std::variant< device::VL53L8CX_Params, device::HTPA32_Params, device::WS2812b_Params > DeviceParamsVariant
Currently supported devices for explicit configuration in expectBoard().
Definition SensorRingFactory.hpp:71
void addInterface(com::ComInterfaceID interface)
Add a communication interface (bus) to scan during build().
const EnumerationMap & getLatestEnumerationResult() const
Return the enumeration results from the last enumerate() or build() call.
EnumerationMap enumerate()
Enumerate hardware on all added interfaces without building a SensorRing.
std::unique_ptr< SensorRing > build(ValidationMode mode=ValidationMode::Strict)
Enumerate hardware on all added interfaces, validate against expectations, and construct the SensorRi...
void expectBoard(device::SensorBoardParams params, std::vector< DeviceParamsVariant > device_params)
Declare an expected board together with explicit per-device params.
void setDefaultDeviceParams(DeviceParamsVariant params)
Set default params applied to every device of the given type that has no explicit params from expectB...
void reset()
Reset the factory to its initial state. Enumeration results are preserved.
Semantic version (major, minor, patch) for firmware or board.
Definition EnumerationInformation.hpp:27
Definition ComInterfaceID.hpp:32
Parameter structure of a sensor board. A sensor board is one circuit board.
Definition SensorBoardParams.hpp:22