|
Motion Master 6.0.0-alpha.86
Next-generation motion control software
|
A single object dictionary entry held by a Device.
More...
#include <device_parameter.h>
Public Member Functions | |
| uint32_t | key () const |
Returns the packed (index, subindex) key used in the parameter map. | |
| uint64_t | loadBits () const |
| Loads the scalar cell. Lock-free, non-allocating — safe from the RT loop. | |
| void | storeBits (uint64_t v) const |
| Stores the scalar cell. Lock-free, non-allocating, relaxed — safe from the RT loop. | |
| DeviceParameterValue | currentValue () const |
Returns the current value as a DeviceParameterValue, built on the spot. | |
| template<typename T > | |
| std::optional< T > | scalar () const |
Reads the value as T straight out of the cell. Lock-free, non-allocating. | |
| std::vector< uint8_t > | rawValueBytes () const |
| Returns the value's raw wire bytes at the object's declared width. | |
| void | setRawValue (std::span< const uint8_t > bytes) |
Replaces the stored value with bytes, its raw little-endian wire encoding. | |
| template<typename T > | |
| std::expected< T, std::string > | getValue () const |
Returns the value as the requested type T. | |
| std::expected< double, std::string > | numeric () const |
Returns the value coerced to a double, for any numeric parameter. | |
| std::expected< void, std::string > | setValue (const DeviceParameterValue &v) |
Sets value, coercing v into the parameter's declared data type. | |
| template<typename T > | |
| std::expected< void, std::string > | setValue (const T &v) |
Strongly-typed setValue overload; wraps v and coerces as above. | |
| bool | isReadable () const |
| Whether the object is readable in any state (ETG.1000.6 ObjAccess read bits 0-2). | |
| bool | inRange (const DeviceParameterValue &v) const |
Whether v lies within [minValue, maxValue]. | |
| DeviceParameterValue | clampToRange (const DeviceParameterValue &v) const |
Returns v clamped to [minValue, maxValue]. | |
Public Attributes | |
| uint16_t | index {} |
| CoE object index. | |
| uint8_t | subindex {} |
| CoE object subindex. | |
| std::string | name |
Textual description from ecx_readOE. | |
| uint16_t | objectCode {} |
| OTYPE_VAR / OTYPE_ARRAY / OTYPE_RECORD (ETG.1000.6 §5). | |
| uint16_t | dataType {} |
| ETG.1020 data type code (e.g. 0x0007 = UNSIGNED32). | |
| uint16_t | bitLength {} |
| Bit length of the value. | |
| uint16_t | access {} |
| ObjAccess bitfield (read/write per-state flags). | |
| ParameterOrigin | origin {ParameterOrigin::ObjectDictionary} |
| Where this definition came from. | |
| ScalarCell | cell {} |
| Scalar value, LSB-aligned little-endian, zero-extended. | |
| std::vector< uint8_t > | rawValue {} |
| Non-scalar value (string / byte array) as wire bytes. | |
| SyncState | syncState {SyncState::Unknown} |
| Freshness of the value relative to the device. | |
| std::optional< uint32_t > | unit |
| ETG.1004 unit code, when reported. | |
| std::optional< DeviceParameterValue > | defaultValue |
| Slave-reported default, when available. | |
| std::optional< DeviceParameterValue > | minValue |
| Slave-reported minimum, when available. | |
| std::optional< DeviceParameterValue > | maxValue |
| Slave-reported maximum, when available. | |
A single object dictionary entry held by a Device.
Combines immutable schema (index, subindex, name, data type, bit length, access flags, object code) with a value that is overwritten by SDO upload or PDO exchange. value is initialised to the type-appropriate zero so callers can std::visit it directly without checking for a read.
| DeviceParameterValue mm::node::DeviceParameter::clampToRange | ( | const DeviceParameterValue & | v | ) | const |
Returns v clamped to [minValue, maxValue].
Clamps numerically and returns a value of the same alternative as v. Returns v unchanged when it is non-numeric or no numeric bounds apply.
| DeviceParameterValue mm::node::DeviceParameter::currentValue | ( | ) | const |
Returns the current value as a DeviceParameterValue, built on the spot.
The value is stored as wire bytes, so the variant is reconstructed here rather than held: one switch on the immutable dataType turns the bytes into the right alternative — the same mapping defaultValueForDataType has always used to choose it. That is what keeps a value in exactly one home, so the HTTP view and a cyclic task's view can never disagree.
Off-RT only, by cost rather than by safety: it may allocate (a string or byte-array parameter). A cyclic task reads loadBits instead.
|
inline |
Returns the value as the requested type T.
Type-exact: T must be the alternative dataType maps to (e.g. uint32_t for an UNSIGNED32 parameter — booleans are stored as uint8_t, see defaultValueForDataType). Use numeric() when you only need a number and do not care about the exact width.
T is not the parameter's alternative. | bool mm::node::DeviceParameter::inRange | ( | const DeviceParameterValue & | v | ) | const |
Whether v lies within [minValue, maxValue].
Bounds are compared via numeric coercion. Returns true when v is non-numeric or when a bound is unset/non-numeric (i.e. no constraint to violate).
|
inline |
Whether the object is readable in any state (ETG.1000.6 ObjAccess read bits 0-2).
Write-only objects (e.g. a command/trigger sub-object) report no read bits; an SDO upload of one aborts, so a bulk value refresh should skip them rather than log a spurious failure.
|
inline |
Returns the packed (index, subindex) key used in the parameter map.
|
inline |
Loads the scalar cell. Lock-free, non-allocating — safe from the RT loop.
See ScalarCell for why relaxed ordering is the whole requirement here.
| std::expected< double, std::string > mm::node::DeviceParameter::numeric | ( | ) | const |
Returns the value coerced to a double, for any numeric parameter.
The "don't worry about the type" accessor — handy because most parameters are numbers of varying width.
value is a string / raw bytes. | std::vector< uint8_t > mm::node::DeviceParameter::rawValueBytes | ( | ) | const |
Returns the value's raw wire bytes at the object's declared width.
The storage-level getter, and the inverse of setRawValue: a scalar is unpacked from the cell, a non-scalar returned as stored. Prefer it over encodeSdoBytes(dataType,
currentValue()) — storage is already bytes, so that route decodes and re-encodes for nothing.
One difference worth knowing for strings: this returns what the slave actually sent, padding included, where currentValue() strips the trailing NUL/space padding ETG.1000.6 allows.
|
inline |
Reads the value as T straight out of the cell. Lock-free, non-allocating.
The RT-callable read: one relaxed atomic load and a copy, with no lookup, no decode into a variant and no error string to build. T must be the alternative dataType maps to — int32_t for an INTEGER32 object, uint8_t for a BOOLEAN — and a mismatch, or a non-scalar parameter, reads as nullopt rather than as a wrong number.
A parameter never written reads as zero, not nullopt: syncState is where "never read" is recorded, and a control loop wants a number it can act on.
| void mm::node::DeviceParameter::setRawValue | ( | std::span< const uint8_t > | bytes | ) |
Replaces the stored value with bytes, its raw little-endian wire encoding.
The storage-level setter: no coercion, no decoding, no syncState change — it takes the bytes an SDO upload or the process image already produced and puts them where isScalarDataType says they belong. setValue is the typed counterpart.
| std::expected< void, std::string > mm::node::DeviceParameter::setValue | ( | const DeviceParameterValue & | v | ) |
Sets value, coercing v into the parameter's declared data type.
Numeric inputs are static_cast into the alternative matching dataType, so setValue(5) works regardless of whether the parameter is UNSIGNED8 or UNSIGNED32 — unlike a bare variant assignment, which would store the wrong alternative. Does not touch syncState; the caller decides that.
v cannot be coerced (e.g. a string into a numeric parameter, or a number into a string parameter).
|
inline |
Strongly-typed setValue overload; wraps v and coerces as above.
|
inline |
Stores the scalar cell. Lock-free, non-allocating, relaxed — safe from the RT loop.
| uint16_t mm::node::DeviceParameter::access {} |
ObjAccess bitfield (read/write per-state flags).
| uint16_t mm::node::DeviceParameter::bitLength {} |
Bit length of the value.
| ScalarCell mm::node::DeviceParameter::cell {} |
Scalar value, LSB-aligned little-endian, zero-extended.
| uint16_t mm::node::DeviceParameter::dataType {} |
ETG.1020 data type code (e.g. 0x0007 = UNSIGNED32).
| std::optional<DeviceParameterValue> mm::node::DeviceParameter::defaultValue |
Slave-reported default, when available.
| uint16_t mm::node::DeviceParameter::index {} |
CoE object index.
| std::optional<DeviceParameterValue> mm::node::DeviceParameter::maxValue |
Slave-reported maximum, when available.
| std::optional<DeviceParameterValue> mm::node::DeviceParameter::minValue |
Slave-reported minimum, when available.
| std::string mm::node::DeviceParameter::name |
Textual description from ecx_readOE.
| uint16_t mm::node::DeviceParameter::objectCode {} |
OTYPE_VAR / OTYPE_ARRAY / OTYPE_RECORD (ETG.1000.6 §5).
| ParameterOrigin mm::node::DeviceParameter::origin {ParameterOrigin::ObjectDictionary} |
Where this definition came from.
| std::vector<uint8_t> mm::node::DeviceParameter::rawValue {} |
Non-scalar value (string / byte array) as wire bytes.
| uint8_t mm::node::DeviceParameter::subindex {} |
CoE object subindex.
| SyncState mm::node::DeviceParameter::syncState {SyncState::Unknown} |
Freshness of the value relative to the device.
| std::optional<uint32_t> mm::node::DeviceParameter::unit |
ETG.1004 unit code, when reported.