#include <soem_master.h>
|
| | SoemMaster (Notifier ¬ifier, const std::string &ifname) |
| | Initializes the SOEM EtherCAT master and brings all discovered slaves to OPERATIONAL state.
|
| | ~SoemMaster () override |
| size_t | start () override |
| | Start the EtherCAT master.
|
| void | stop () override |
| | Stop the EtherCAT master.
|
| size_t | restart () override |
| | Returns the number of EtherCAT slaves during a restart.
|
| int32_t | execute (uint64_t pending_signals) override |
| | Main EtherCAT master loop function to be executed at one millisecond interval.
|
| bool | is_running () override |
| | Check if the EtherCAT master is currently running.
|
| int | get_slaves_responding () override |
| | Return the number of slaves actually responding on the bus.
|
| std::list< VirtualDevice * > | get_slaves () override |
| | Get all of the available slaves.
|
| bool | disable_all_slaves () override |
| | Switch all slaves to PREOP.
|
| int | roundtrip () |
| void | checkstate () |
| virtual | ~EthercatMaster ()=default |
|
| static std::map< uint16_t, std::unique_ptr< EthercatSlave > > | slaveMap {} |
| | Static map of EtherCAT slave instances.
|
◆ SoemMaster()
| SoemMaster::SoemMaster |
( |
Notifier & | notifier, |
|
|
const std::string & | ifname ) |
|
explicit |
Initializes the SOEM EtherCAT master and brings all discovered slaves to OPERATIONAL state.
Performs the full EtherCAT startup sequence:
- Manual state change — Sets ecx_context.manualstatechange = TRUE so that ecx_config_map_group does not automatically advance slaves to SAFE-OP. Without this, SOMANET devices without firmware that reach SAFE-OP become stuck and require a power cycle to recover.
- Slave discovery — Calls g_soem_update_slavecount() and creates a SoemSlave for every responding slave. Only supported devices are added to slaveMap; others are silently skipped.
- Parallel PRE-OP transition — All slaves in slaveMap are transitioned to PRE-OPERATIONAL concurrently (10 retries, 500 ms timeout per attempt).
- Sequential slave initialization — Each slave in slaveMap is initialized one at a time to avoid SDO mailbox contention. Third-party devices (neither Synapticon nor Sensodrive vendor ID) are skipped entirely. For each Synapticon/Sensodrive slave:
- If still in INIT after the PRE-OP attempt (likely missing firmware), it is first re-set to INIT (Integro workaround) and then transitioned to BOOT so firmware can be uploaded via FoE.
- SoemSlave::initialize() is called for all states; it reads state internally and performs full init for PRE-OP or hardware ID only for BOOT.
- OD entry values are refreshed only for slaves that reached PRE-OP.
- Early-exit guard — Rechecks the slave count. If all slaves have disappeared (e.g. powered off during initialization), the constructor returns early to avoid hanging inside ecx_config_map_group.
- PDO mapping — ecx_config_map_group configures and maps all Process Data Objects.
- Parallel SAFE-OP transition — Each slave's current state is read; only those confirmed to be in PRE-OP are transitioned to SAFE-OP.
- PDO roundtrip — A single roundtrip() call primes slave outputs before the final state transition.
- Parallel OP transition — Each slave's current state is read; only those confirmed to be in SAFE-OP are transitioned to OPERATIONAL.
- Parameters
-
| notifier | Reference to the notification bus used to publish EtherCAT events to the rest of the system. |
| ifname | Network interface name for the EtherCAT master port (e.g. "eth0"). |
◆ ~SoemMaster()
| SoemMaster::~SoemMaster |
( |
| ) |
|
|
override |
◆ checkstate()
| void SoemMaster::checkstate |
( |
| ) |
|
◆ disable_all_slaves()
| bool SoemMaster::disable_all_slaves |
( |
| ) |
|
|
overridevirtual |
Switch all slaves to PREOP.
- Attention
- Must be implemented as non-blocking!
- Returns
- true on success, false otherwise
Implements EthercatMaster.
◆ execute()
| int32_t SoemMaster::execute |
( |
uint64_t | pending_signals | ) |
|
|
overridevirtual |
Main EtherCAT master loop function to be executed at one millisecond interval.
- Returns
- error if any
Implements EthercatMaster.
◆ get_slaves()
Get all of the available slaves.
- Returns
- map of available slaves
Implements EthercatMaster.
◆ get_slaves_responding()
| int SoemMaster::get_slaves_responding |
( |
| ) |
|
|
overridevirtual |
Return the number of slaves actually responding on the bus.
- Returns
- number of responding slaves
Implements EthercatMaster.
◆ is_running()
| bool SoemMaster::is_running |
( |
| ) |
|
|
overridevirtual |
Check if the EtherCAT master is currently running.
- Returns
- true if currently running, false otherwise
Implements EthercatMaster.
◆ restart()
| size_t SoemMaster::restart |
( |
| ) |
|
|
overridevirtual |
Returns the number of EtherCAT slaves during a restart.
A restart is triggered when transitioning from PRE-OP to OP, typically due to updated PDO mappings on a device.
- Returns
- Current EtherCAT slave count.
Implements EthercatMaster.
◆ roundtrip()
| int SoemMaster::roundtrip |
( |
| ) |
|
◆ start()
| size_t SoemMaster::start |
( |
| ) |
|
|
overridevirtual |
Start the EtherCAT master.
- Returns
- the number of initially responding slaves
Implements EthercatMaster.
◆ stop()
| void SoemMaster::stop |
( |
| ) |
|
|
overridevirtual |
◆ wait_for_slaves()
| void SoemMaster::wait_for_slaves |
( |
Notifier & | notifier, |
|
|
const std::string & | ifname ) |
|
static |
◆ slaveMap
| std::map< uint16_t, std::unique_ptr< EthercatSlave > > SoemMaster::slaveMap {} |
|
static |
Static map of EtherCAT slave instances.
The slaveMap is declared static because other components of the system, such as ParameterValueRefresher, may hold raw pointers to instances of EthercatSlave (retrieved via SoemMaster::get_slaves()).
If slaveMap were a non-static member of SoemMaster, it would be destroyed when the SoemMaster instance goes out of scope. Since slaveMap holds std::unique_ptrs, this would also delete the associated slave objects and their Object Dictionary (OD) entries. Consequently, any component still holding raw pointers to those objects would be left with dangling references, leading to undefined behavior.
Declaring slaveMap as static ensures that these instances persist beyond the lifetime of a single SoemMaster instance, preventing invalid memory access.
The documentation for this class was generated from the following files: