6#include <nlohmann/json_fwd.hpp>
21 std::variant<int8_t, int16_t, int32_t, int64_t,
22 uint8_t, uint16_t, uint32_t, uint64_t,
24 std::string, std::vector<uint8_t>>;
30 return (
static_cast<uint32_t
>(index) << 8) |
static_cast<uint32_t
>(subindex);
76 std::optional<uint32_t>
unit;
93 std::expected<T, std::string>
getValue()
const {
94 if (
const auto* p = std::get_if<T>(&
value)) {
97 return std::unexpected(
98 std::format(
"parameter 0x{:04X}:{:02X} holds a different type",
index,
subindex));
107 std::expected<double, std::string>
numeric()
const;
121 template <
typename T>
122 std::expected<void, std::string>
setValue(
const T& v) {
151std::expected<DeviceParameterValue, std::string>
decodeSdoBytes(uint16_t dataType,
152 std::span<const uint8_t> bytes);
167std::expected<std::vector<uint8_t>, std::string>
encodeSdoBytes(uint16_t dataType,
174void to_json(nlohmann::json& j,
const DeviceParameter& p);
Definition http_server.h:16
std::string_view syncStateName(SyncState state)
Returns the lowercase string form of state ("unknown" etc.).
Definition device_parameter.cc:200
std::expected< std::vector< uint8_t >, std::string > encodeSdoBytes(uint16_t dataType, const DeviceParameterValue &value)
Serialises a DeviceParameterValue to raw SDO bytes — the inverse of decodeSdoBytes.
Definition device_parameter.cc:138
std::variant< int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, float, double, std::string, std::vector< uint8_t > > DeviceParameterValue
Decoded value of a single device parameter (CoE object dictionary entry).
Definition device_parameter.h:24
DeviceParameterValue defaultValueForDataType(uint16_t dataType)
Returns a zero-equivalent value for the given ETG.1020 dataType.
Definition device_parameter.cc:56
void to_json(nlohmann::json &j, const Device &d)
Serialises a Device to JSON.
Definition device.cc:924
std::expected< DeviceParameterValue, std::string > decodeSdoBytes(uint16_t dataType, std::span< const uint8_t > bytes)
Decodes a raw SDO byte sequence according to an ETG.1020 data type code.
Definition device_parameter.cc:92
std::optional< double > numericValue(const DeviceParameterValue &value)
Coerces a DeviceParameterValue to a double, when it holds a number.
Definition device_parameter.cc:187
SyncState
Tracks how a cached parameter value relates to the device.
Definition device_parameter.h:51
@ Pending
value was set locally while offline / after a failed write.
@ Synced
value matches the device (last successful read or write).
@ Unknown
Never read; value is the type-appropriate default.
constexpr uint32_t makeParameterKey(uint16_t index, uint8_t subindex)
Packs an object dictionary index and subindex into a single 32-bit key.
Definition device_parameter.h:29
A single object dictionary entry held by a Device.
Definition device_parameter.h:66
uint16_t access
ObjAccess bitfield (read/write per-state flags).
Definition device_parameter.h:73
bool inRange(const DeviceParameterValue &v) const
Whether v lies within [minValue, maxValue].
Definition device_parameter.cc:260
SyncState syncState
Freshness of value relative to the device.
Definition device_parameter.h:75
std::optional< DeviceParameterValue > defaultValue
Slave-reported default, when available.
Definition device_parameter.h:77
std::expected< void, std::string > setValue(const DeviceParameterValue &v)
Sets value, coercing v into the parameter's declared data type.
Definition device_parameter.cc:220
uint16_t objectCode
OTYPE_VAR / OTYPE_ARRAY / OTYPE_RECORD (ETG.1000.6 §5).
Definition device_parameter.h:70
std::optional< uint32_t > unit
ETG.1004 unit code, when reported.
Definition device_parameter.h:76
std::string name
Textual description from ecx_readOE.
Definition device_parameter.h:69
uint16_t bitLength
Bit length of the value.
Definition device_parameter.h:72
uint16_t index
CoE object index.
Definition device_parameter.h:67
DeviceParameterValue value
Last-known value; type-appropriate zero before first read.
Definition device_parameter.h:74
std::optional< DeviceParameterValue > maxValue
Slave-reported maximum, when available.
Definition device_parameter.h:79
std::expected< void, std::string > setValue(const T &v)
Strongly-typed setValue overload; wraps v and coerces as above.
Definition device_parameter.h:122
DeviceParameterValue clampToRange(const DeviceParameterValue &v) const
Returns v clamped to [minValue, maxValue].
Definition device_parameter.cc:278
uint8_t subindex
CoE object subindex.
Definition device_parameter.h:68
uint16_t dataType
ETG.1020 data type code (e.g. 0x0007 = UNSIGNED32).
Definition device_parameter.h:71
std::expected< T, std::string > getValue() const
Returns value as the requested type T.
Definition device_parameter.h:93
bool isReadable() const
Whether the object is readable in any state (ETG.1000.6 ObjAccess read bits 0-2).
Definition device_parameter.h:130
std::optional< DeviceParameterValue > minValue
Slave-reported minimum, when available.
Definition device_parameter.h:78
uint32_t key() const
Returns the packed (index, subindex) key used in the parameter map.
Definition device_parameter.h:82
std::expected< double, std::string > numeric() const
Returns value coerced to a double, for any numeric parameter.
Definition device_parameter.cc:212