Motion Master
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SoemMaster Class Reference

#include <soem_master.h>

Inheritance diagram for SoemMaster:
Inheritance graph
[legend]
Collaboration diagram for SoemMaster:
Collaboration graph
[legend]

Public Member Functions

 SoemMaster (Notifier &notifier, const std::string &ifname)
 
 ~SoemMaster () override
 
size_t start () override
 Start the EtherCAT master. More...
 
void stop () override
 Stop the EtherCAT master. More...
 
size_t restart () override
 Returns the number of EtherCAT slaves during a restart. More...
 
int32_t execute (uint64_t pending_signals) override
 Main EtherCAT master loop function to be executed at one millisecond interval. More...
 
bool is_running () override
 Check if the EtherCAT master is currently running. More...
 
int get_slaves_responding () override
 Return the number of slaves actually responding on the bus. More...
 
std::list< VirtualDevice * > get_slaves () override
 Get all of the available slaves. More...
 
bool disable_all_slaves () override
 Switch all slaves to PREOP. More...
 
void abort_all_client_requests () override
 
int roundtrip ()
 
void checkstate ()
 
- Public Member Functions inherited from EthercatMaster
virtual ~EthercatMaster ()=default
 
virtual size_t start ()=0
 Start the EtherCAT master. More...
 
virtual void stop ()=0
 Stop the EtherCAT master. More...
 
virtual size_t restart ()=0
 Restart the EtherCAT master. More...
 
virtual int32_t execute (uint64_t pending_signals)=0
 Main EtherCAT master loop function to be executed at one millisecond interval. More...
 
virtual bool is_running ()=0
 Check if the EtherCAT master is currently running. More...
 
virtual int get_slaves_responding ()=0
 Return the number of slaves actually responding on the bus. More...
 
virtual std::list< VirtualDevice * > get_slaves ()=0
 Get all of the available slaves. More...
 
virtual bool disable_all_slaves ()=0
 Switch all slaves to PREOP. More...
 
virtual void abort_all_client_requests ()=0
 

Static Public Member Functions

static void wait_for_slaves (Notifier &notifier, const std::string &ifname)
 

Static Public Attributes

static std::map< uint16_t, std::unique_ptr< EthercatSlave > > slaveMap {}
 Static map of EtherCAT slave instances. More...
 

Constructor & Destructor Documentation

◆ SoemMaster()

SoemMaster::SoemMaster ( Notifier notifier,
const std::string &  ifname 
)
explicit

◆ ~SoemMaster()

SoemMaster::~SoemMaster ( )
override

Member Function Documentation

◆ abort_all_client_requests()

void SoemMaster::abort_all_client_requests ( )
inlineoverridevirtual

Implements EthercatMaster.

◆ 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()

std::list< VirtualDevice * > SoemMaster::get_slaves ( )
overridevirtual

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

Stop the EtherCAT master.

Implements EthercatMaster.

◆ wait_for_slaves()

void SoemMaster::wait_for_slaves ( Notifier notifier,
const std::string &  ifname 
)
static

Member Data Documentation

◆ 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: