Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
mm::node::ProfileDevice Class Reference

Root of the drive-profile view hierarchy — a concrete, instantiable, borrowed view over a Device that exposes the generic CANopen device area (CiA301). More...

#include <profile_device.h>

Inheritance diagram for mm::node::ProfileDevice:
[legend]
Collaboration diagram for mm::node::ProfileDevice:
[legend]

Public Member Functions

 ProfileDevice (Device &device)
 Binds an (unchecked) view to device. Prefer createProfileDevice.
 
Devicedevice ()
 The underlying generic device this view operates on.
 
const Devicedevice () const
 
std::expected< uint32_t, std::string > deviceType () const
 Reads the device type (0x1000, UNSIGNED32) — the device profile the object dictionary implements (low word = profile number, e.g. 402; high word = profile-specific info).
 
std::expected< uint8_t, std::string > errorRegister () const
 Reads the error register (0x1001, UNSIGNED8) — the active error class bit field (bit 0 = generic error). Read-only but volatile, so every call re-reads the device.
 
std::expected< int32_t, std::string > cobIdSync () const
 Reads the COB-ID of the SYNC message (0x1005, INTEGER32). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setCobIdSync (int32_t value)
 Writes the COB-ID of the SYNC message (0x1005, INTEGER32).
 
std::expected< int32_t, std::string > communicationCyclePeriod () const
 Reads the communication cycle period (0x1006, INTEGER32, µs). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setCommunicationCyclePeriod (int32_t value)
 Writes the communication cycle period (0x1006, INTEGER32, µs).
 
std::expected< std::string, std::string > manufacturerDeviceName () const
 Reads the manufacturer device name (0x1008, VISIBLE_STRING).
 
std::expected< std::string, std::string > manufacturerSoftwareVersion () const
 Reads the manufacturer software version (0x100A, VISIBLE_STRING) — the firmware version.
 
std::expected< uint16_t, std::string > guardTime () const
 Reads the node guarding guard time (0x100C, UNSIGNED16, ms). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setGuardTime (uint16_t value)
 Writes the node guarding guard time (0x100C, UNSIGNED16, ms).
 
std::expected< uint8_t, std::string > lifeTimeFactor () const
 Reads the node guarding life time factor (0x100D, UNSIGNED8). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setLifeTimeFactor (uint8_t value)
 Writes the node guarding life time factor (0x100D, UNSIGNED8).
 
std::expected< uint32_t, std::string > storeParameters () const
 Reads "save all parameters" (0x1010:01, UNSIGNED32) — the save capability (bit 0 = device saves on command); writing the "save" signature to it triggers the store. Writable, so every call re-reads the device.
 
std::expected< void, std::string > setStoreParameters (uint32_t signature)
 Writes "save all parameters" (0x1010:01, UNSIGNED32). Writing the ASCII "save" signature (0x65766173) commands the device to store its parameters to non-volatile memory; the device aborts any other value.
 
std::expected< void, std::string > runStoreParameters (const StoreParametersConfig &config={})
 Commands a parameter store (0x1010) and waits for the device to confirm it completed.
 
std::expected< RestoreDefaultParameters, std::string > restoreDefaultParameters () const
 Reads the restore-default-parameters object (0x1011) — the restore capability of all four groups. Writable (the "load" signature triggers a restore), so every call re-reads the device. Fails if any sub-entry read fails.
 
std::expected< void, std::string > setRestoreAllDefaultParameters (uint32_t signature)
 Writes "restore all default parameters" (0x1011:01, UNSIGNED32). Writing the ASCII "load" signature (0x64616F6C) commands the restore; the device aborts any other value.
 
std::expected< void, std::string > setRestoreCommunicationDefaultParameters (uint32_t signature)
 Writes "restore communication default parameters" (0x1011:02, UNSIGNED32) — the ASCII "load" signature (0x64616F6C) commands the restore.
 
std::expected< void, std::string > setRestoreApplicationDefaultParameters (uint32_t signature)
 Writes "restore application default parameters" (0x1011:03, UNSIGNED32) — the ASCII "load" signature (0x64616F6C) commands the restore.
 
std::expected< void, std::string > setRestoreManufacturerDefaultParameters (uint32_t signature)
 Writes "restore manufacturer-defined default parameters" (0x1011:04, UNSIGNED32) — the ASCII "load" signature (0x64616F6C) commands the restore.
 
std::expected< void, std::string > runRestoreDefaultParameters (RestoreGroup group, const RestoreDefaultParametersConfig &config={})
 Commands a restore of default parameters (0x1011) and waits for the device to confirm.
 
std::expected< uint32_t, std::string > consumerHeartbeatTime () const
 Reads the consumer heartbeat time (0x1016:01, UNSIGNED32, ms — node ID in bits 16-23). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setConsumerHeartbeatTime (uint32_t value)
 Writes the consumer heartbeat time (0x1016:01, UNSIGNED32, ms — node ID in bits 16-23).
 
std::expected< uint16_t, std::string > producerHeartbeatTime () const
 Reads the producer heartbeat time (0x1017, UNSIGNED16, ms). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setProducerHeartbeatTime (uint16_t value)
 Writes the producer heartbeat time (0x1017, UNSIGNED16, ms).
 
std::expected< Identity, std::string > identity () const
 Reads the identity object (0x1018) — vendor ID, product code, revision, serial.
 
std::expected< uint8_t, std::string > synchronousCounterOverflowValue () const
 Reads the synchronous counter overflow value (0x1019, UNSIGNED8). Writable, so every call re-reads the device.
 
std::expected< void, std::string > setSynchronousCounterOverflowValue (uint8_t value)
 Writes the synchronous counter overflow value (0x1019, UNSIGNED8).
 
std::expected< std::vector< uint8_t >, std::string > osCommand () const
 Reads back the OS command bytes (0x1023:01, 8 bytes). Writable (this is the command the caller last issued), so every call re-reads the device.
 
std::expected< void, std::string > setOsCommand (const std::vector< uint8_t > &command)
 Writes the OS command bytes (0x1023:01, 8 bytes) — issues an OS command; poll osCommandStatus / osCommandResponse for the result.
 
std::expected< uint8_t, std::string > osCommandStatus () const
 Reads the OS command status (0x1023:02, UNSIGNED8). Read-only but volatile (it tracks the last issued command), so every call re-reads the device.
 
std::expected< std::vector< uint8_t >, std::string > osCommandResponse () const
 Reads the OS command response bytes (0x1023:03, 8 bytes). Read-only but volatile (it tracks the last issued command), so every call re-reads the device.
 
std::expected< void, std::string > setOsCommandMode (uint8_t mode)
 Writes the OS command mode (0x1024, UNSIGNED8). Write-only on the device — there is no matching getter.
 

Protected Attributes

Devicedevice_
 The borrowed device — the only data member permitted in the whole view chain.
 

Detailed Description

Root of the drive-profile view hierarchy — a concrete, instantiable, borrowed view over a Device that exposes the generic CANopen device area (CiA301).

This is not an abstract interface: it is directly usable on its own. Every CoE device — not just CiA402 drives — carries the generic device-profile objects (manufacturer device name and software version, identity, store/restore, error register, ...), so those accessors live here, on the root, and any device with an enumerated object dictionary can be viewed as a ProfileDevice. Cia402Drive refines it with the drive state machine; SomanetDrive refines that with the vendor object range.

A profile is not what a device is in storage — every device is a Device, value-stored in DeviceManager. A profile is what you do with a device, using knowledge of its object-dictionary layout. So profile types do not derive from Device nor are they owned by it; they borrow a Device& and are constructed on demand for a single operation (a stack local in an HTTP handler, or a member of a cyclic task scoped to that task's lifetime).

Because these views are never stored base-typed (no vector<ProfileDevice>, no polymorphic container), the inheritance chain SomanetDriveCia402DriveProfileDevice is a genuine is-a relationship with no slicing or downcasting hazard — the objection that makes inheritance on Device wrong does not apply to a borrowed view.

Invariant: a profile view holds no state beyond this reference. A CiA402 drive's state lives in its statusword on the wire, not in the view; multi-cycle procedure state lives in a cyclic task, not here. The methods here are pure behaviour — thin typed reads/writes over device() — so the day a view needs a persistent data member is the day this borrowed-view model needs rethinking.

Warning
The borrowed Device& must outlive the view. Construct a view, use it, and drop it within a single operation; never cache one across a bus rescan (which rebuilds DeviceManager's device vector and would dangle the reference). A cyclic task re-resolves its Device via DeviceManager::findDevice every cycle for exactly this reason.

Constructor & Destructor Documentation

◆ ProfileDevice()

mm::node::ProfileDevice::ProfileDevice ( Device device)
inlineexplicit

Binds an (unchecked) view to device. Prefer createProfileDevice.

Member Function Documentation

◆ cobIdSync()

std::expected< int32_t, std::string > mm::node::ProfileDevice::cobIdSync ( ) const

Reads the COB-ID of the SYNC message (0x1005, INTEGER32). Writable, so every call re-reads the device.

◆ communicationCyclePeriod()

std::expected< int32_t, std::string > mm::node::ProfileDevice::communicationCyclePeriod ( ) const

Reads the communication cycle period (0x1006, INTEGER32, µs). Writable, so every call re-reads the device.

◆ consumerHeartbeatTime()

std::expected< uint32_t, std::string > mm::node::ProfileDevice::consumerHeartbeatTime ( ) const

Reads the consumer heartbeat time (0x1016:01, UNSIGNED32, ms — node ID in bits 16-23). Writable, so every call re-reads the device.

◆ device() [1/2]

Device & mm::node::ProfileDevice::device ( )
inline

The underlying generic device this view operates on.

◆ device() [2/2]

const Device & mm::node::ProfileDevice::device ( ) const
inline

◆ deviceType()

std::expected< uint32_t, std::string > mm::node::ProfileDevice::deviceType ( ) const

Reads the device type (0x1000, UNSIGNED32) — the device profile the object dictionary implements (low word = profile number, e.g. 402; high word = profile-specific info).

◆ errorRegister()

std::expected< uint8_t, std::string > mm::node::ProfileDevice::errorRegister ( ) const

Reads the error register (0x1001, UNSIGNED8) — the active error class bit field (bit 0 = generic error). Read-only but volatile, so every call re-reads the device.

◆ guardTime()

std::expected< uint16_t, std::string > mm::node::ProfileDevice::guardTime ( ) const

Reads the node guarding guard time (0x100C, UNSIGNED16, ms). Writable, so every call re-reads the device.

◆ identity()

std::expected< Identity, std::string > mm::node::ProfileDevice::identity ( ) const

Reads the identity object (0x1018) — vendor ID, product code, revision, serial.

A live re-read over the wire of all four sub-entries, distinct from the same values cached on Device at scan (Device::vendorId() etc.). Fails if any sub-entry read fails.

◆ lifeTimeFactor()

std::expected< uint8_t, std::string > mm::node::ProfileDevice::lifeTimeFactor ( ) const

Reads the node guarding life time factor (0x100D, UNSIGNED8). Writable, so every call re-reads the device.

◆ manufacturerDeviceName()

std::expected< std::string, std::string > mm::node::ProfileDevice::manufacturerDeviceName ( ) const

Reads the manufacturer device name (0x1008, VISIBLE_STRING).

A live re-read over the wire, distinct from Device::name() (the EtherCAT slave name cached at scan): this is the CoE object the firmware reports for itself.

◆ manufacturerSoftwareVersion()

std::expected< std::string, std::string > mm::node::ProfileDevice::manufacturerSoftwareVersion ( ) const

Reads the manufacturer software version (0x100A, VISIBLE_STRING) — the firmware version.

◆ osCommand()

std::expected< std::vector< uint8_t >, std::string > mm::node::ProfileDevice::osCommand ( ) const

Reads back the OS command bytes (0x1023:01, 8 bytes). Writable (this is the command the caller last issued), so every call re-reads the device.

◆ osCommandResponse()

std::expected< std::vector< uint8_t >, std::string > mm::node::ProfileDevice::osCommandResponse ( ) const

Reads the OS command response bytes (0x1023:03, 8 bytes). Read-only but volatile (it tracks the last issued command), so every call re-reads the device.

◆ osCommandStatus()

std::expected< uint8_t, std::string > mm::node::ProfileDevice::osCommandStatus ( ) const

Reads the OS command status (0x1023:02, UNSIGNED8). Read-only but volatile (it tracks the last issued command), so every call re-reads the device.

◆ producerHeartbeatTime()

std::expected< uint16_t, std::string > mm::node::ProfileDevice::producerHeartbeatTime ( ) const

Reads the producer heartbeat time (0x1017, UNSIGNED16, ms). Writable, so every call re-reads the device.

◆ restoreDefaultParameters()

std::expected< RestoreDefaultParameters, std::string > mm::node::ProfileDevice::restoreDefaultParameters ( ) const

Reads the restore-default-parameters object (0x1011) — the restore capability of all four groups. Writable (the "load" signature triggers a restore), so every call re-reads the device. Fails if any sub-entry read fails.

◆ runRestoreDefaultParameters()

std::expected< void, std::string > mm::node::ProfileDevice::runRestoreDefaultParameters ( RestoreGroup  group,
const RestoreDefaultParametersConfig config = {} 
)

Commands a restore of default parameters (0x1011) and waits for the device to confirm.

The restore counterpart of runStoreParameters: writes the ASCII "load" signature (0x64616F6C) to the 0x1011 sub-entry selected by group, waits config.settle, then polls that sub-entry until it reads back 1 — the CiA301 "restore completed" value — retrying a poll that does not yet confirm (a value mismatch or a transient mailbox read error) up to config.retries more times, config.interval apart.

Destructive: this overwrites the selected group's parameter values in the device's volatile memory with the device's defaults, replacing the current live values (not the persisted store). Which values it touches, and whether the change takes effect immediately or after the next reset, is device-specific. Blocks the calling thread and takes the driver's control-plane lock only per transaction, exactly like runStoreParameters; requires the mailbox to be active (PRE-OP/SAFE-OP/OP).

Parameters
groupWhich group of defaults to restore (maps to the 0x1011 sub-entry).
configRetry/timing configuration (see RestoreDefaultParametersConfig).
Returns
Void once the sub-entry reads 1, or an error string if the restore command write fails (e.g. the device does not support group) or it is not confirmed within the budget.

◆ runStoreParameters()

std::expected< void, std::string > mm::node::ProfileDevice::runStoreParameters ( const StoreParametersConfig config = {})

Commands a parameter store (0x1010) and waits for the device to confirm it completed.

The command-and-wait procedure built on the two raw accessors above: writes the ASCII "save" signature (setStoreParameters), waits config.settle for the device to begin the non-volatile write, then polls storeParameters (0x1010:01) until it reads back 1 — the CiA301 "save completed" value. A store can take a second or more (the drive persists its config to flash), and while it is in progress the mailbox may briefly refuse the read, so each poll that does not yet confirm — a value mismatch or a read error alike — is retried up to config.retries more times, config.interval apart, before the call gives up.

Blocks the calling thread for up to settle plus retries × interval. Intended to run on the control-plane (HTTP) thread: it sleeps between polls but each poll's bus access takes the driver's control-plane lock only per transaction, so it never blocks the RT loop or the WebSocket. Requires the device's mailbox to be active (PRE-OP/SAFE-OP/OP).

Parameters
configRetry/timing configuration (see StoreParametersConfig); the defaults suit a normal store.
Returns
Void once 0x1010:01 reads 1, or an error string if the store command write fails or the device does not confirm within the retry budget.

◆ setCobIdSync()

std::expected< void, std::string > mm::node::ProfileDevice::setCobIdSync ( int32_t  value)

Writes the COB-ID of the SYNC message (0x1005, INTEGER32).

◆ setCommunicationCyclePeriod()

std::expected< void, std::string > mm::node::ProfileDevice::setCommunicationCyclePeriod ( int32_t  value)

Writes the communication cycle period (0x1006, INTEGER32, µs).

◆ setConsumerHeartbeatTime()

std::expected< void, std::string > mm::node::ProfileDevice::setConsumerHeartbeatTime ( uint32_t  value)

Writes the consumer heartbeat time (0x1016:01, UNSIGNED32, ms — node ID in bits 16-23).

◆ setGuardTime()

std::expected< void, std::string > mm::node::ProfileDevice::setGuardTime ( uint16_t  value)

Writes the node guarding guard time (0x100C, UNSIGNED16, ms).

◆ setLifeTimeFactor()

std::expected< void, std::string > mm::node::ProfileDevice::setLifeTimeFactor ( uint8_t  value)

Writes the node guarding life time factor (0x100D, UNSIGNED8).

◆ setOsCommand()

std::expected< void, std::string > mm::node::ProfileDevice::setOsCommand ( const std::vector< uint8_t > &  command)

Writes the OS command bytes (0x1023:01, 8 bytes) — issues an OS command; poll osCommandStatus / osCommandResponse for the result.

◆ setOsCommandMode()

std::expected< void, std::string > mm::node::ProfileDevice::setOsCommandMode ( uint8_t  mode)

Writes the OS command mode (0x1024, UNSIGNED8). Write-only on the device — there is no matching getter.

◆ setProducerHeartbeatTime()

std::expected< void, std::string > mm::node::ProfileDevice::setProducerHeartbeatTime ( uint16_t  value)

Writes the producer heartbeat time (0x1017, UNSIGNED16, ms).

◆ setRestoreAllDefaultParameters()

std::expected< void, std::string > mm::node::ProfileDevice::setRestoreAllDefaultParameters ( uint32_t  signature)

Writes "restore all default parameters" (0x1011:01, UNSIGNED32). Writing the ASCII "load" signature (0x64616F6C) commands the restore; the device aborts any other value.

◆ setRestoreApplicationDefaultParameters()

std::expected< void, std::string > mm::node::ProfileDevice::setRestoreApplicationDefaultParameters ( uint32_t  signature)

Writes "restore application default parameters" (0x1011:03, UNSIGNED32) — the ASCII "load" signature (0x64616F6C) commands the restore.

◆ setRestoreCommunicationDefaultParameters()

std::expected< void, std::string > mm::node::ProfileDevice::setRestoreCommunicationDefaultParameters ( uint32_t  signature)

Writes "restore communication default parameters" (0x1011:02, UNSIGNED32) — the ASCII "load" signature (0x64616F6C) commands the restore.

◆ setRestoreManufacturerDefaultParameters()

std::expected< void, std::string > mm::node::ProfileDevice::setRestoreManufacturerDefaultParameters ( uint32_t  signature)

Writes "restore manufacturer-defined default parameters" (0x1011:04, UNSIGNED32) — the ASCII "load" signature (0x64616F6C) commands the restore.

◆ setStoreParameters()

std::expected< void, std::string > mm::node::ProfileDevice::setStoreParameters ( uint32_t  signature)

Writes "save all parameters" (0x1010:01, UNSIGNED32). Writing the ASCII "save" signature (0x65766173) commands the device to store its parameters to non-volatile memory; the device aborts any other value.

◆ setSynchronousCounterOverflowValue()

std::expected< void, std::string > mm::node::ProfileDevice::setSynchronousCounterOverflowValue ( uint8_t  value)

Writes the synchronous counter overflow value (0x1019, UNSIGNED8).

◆ storeParameters()

std::expected< uint32_t, std::string > mm::node::ProfileDevice::storeParameters ( ) const

Reads "save all parameters" (0x1010:01, UNSIGNED32) — the save capability (bit 0 = device saves on command); writing the "save" signature to it triggers the store. Writable, so every call re-reads the device.

◆ synchronousCounterOverflowValue()

std::expected< uint8_t, std::string > mm::node::ProfileDevice::synchronousCounterOverflowValue ( ) const

Reads the synchronous counter overflow value (0x1019, UNSIGNED8). Writable, so every call re-reads the device.

Member Data Documentation

◆ device_

Device& mm::node::ProfileDevice::device_
protected

The borrowed device — the only data member permitted in the whole view chain.


The documentation for this class was generated from the following files: