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

#include <ethernet_master.h>

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

Public Member Functions

 EthernetMaster (Notifier &notifier, const std::vector< std::string > ipAddresses)
 
 ~EthernetMaster () 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
 
- 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::vector< std::string > ipAddresses)
 

Static Public Attributes

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

Constructor & Destructor Documentation

◆ EthernetMaster()

EthernetMaster::EthernetMaster ( Notifier notifier,
const std::vector< std::string >  ipAddresses 
)
explicit

◆ ~EthernetMaster()

EthernetMaster::~EthernetMaster ( )
override

Member Function Documentation

◆ abort_all_client_requests()

void EthernetMaster::abort_all_client_requests ( )
inlineoverridevirtual

Implements EthercatMaster.

◆ disable_all_slaves()

bool EthernetMaster::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 EthernetMaster::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 * > EthernetMaster::get_slaves ( )
overridevirtual

Get all of the available slaves.

Returns
map of available slaves

Implements EthercatMaster.

◆ get_slaves_responding()

int EthernetMaster::get_slaves_responding ( )
overridevirtual

Return the number of slaves actually responding on the bus.

Returns
number of responding slaves

Implements EthercatMaster.

◆ is_running()

bool EthernetMaster::is_running ( )
overridevirtual

Check if the EtherCAT master is currently running.

Returns
true if currently running, false otherwise

Implements EthercatMaster.

◆ restart()

size_t EthernetMaster::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.

◆ start()

size_t EthernetMaster::start ( )
overridevirtual

Start the EtherCAT master.

Returns
the number of initially responding slaves

Implements EthercatMaster.

◆ stop()

void EthernetMaster::stop ( )
overridevirtual

Stop the EtherCAT master.

Implements EthercatMaster.

◆ wait_for_slaves()

void EthernetMaster::wait_for_slaves ( Notifier notifier,
const std::vector< std::string >  ipAddresses 
)
static

Member Data Documentation

◆ slaveMap

std::map< uint16_t, std::unique_ptr< EthercatSlave > > EthernetMaster::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: