Motion Master
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
SoemSlave Class Reference

#include <soem_slave.h>

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

Public Member Functions

 SoemSlave (const uint16_t position)
 
 ~SoemSlave () override
 
uint16_t get_device_id () const override
 Get the ID (absolute position) of the EtherCAT slave in the EtherCAT chain. More...
 
uint16_t get_hardware_id () const override
 Get the hardware ID. More...
 
Type get_device_type () const override
 Get the device type. More...
 
std::list< VirtualParameter * > get_all_virtual_parameters () override
 Get all configuration parameters from a slave. More...
 
VirtualParameterget_virtual_parameter (uint16_t index, uint8_t subindex) override
 Get a configuration parameter by its index/subindex. More...
 
std::variant< MotionMasterError, std::list< std::string > > get_file_list () override
 Get the list of available files on the device. More...
 
std::variant< MotionMasterError, std::vector< uint8_t > > read_file (const std::string &file_name) override
 Return the raw content (bytes) of the requested file from the flash memory. More...
 
MotionMasterError write_file (const std::string &file_name, const std::vector< uint8_t > &content, std::function< void(uint8_t)> progress_callback) override
 Write raw content (bytes) into a file in the flash memory. More...
 
MotionMasterError remove_file (const std::string &file_name) override
 Remove a file from the flash memory. More...
 
bool has_firmware () override
 Check if the slave has a firmware installed. More...
 
bool is_operational () const override
 Request the current slave state. More...
 
bool is_supported ()
 
bool has_pdos () override
 Check if PDO mapping is available. More...
 
State get_state (bool force_refresh) const override
 Get the slave EtherCAT state. More...
 
bool set_state (State state, uint32_t timeout_ms=5000) override
 Change the EtherCAT state of the slave. More...
 
bool request_state_switch (State state) override
 
MotionMasterError write_sii (const std::vector< uint8_t > &content) override
 
void receive_pdos (const uint8_t *process_data) override
 
void update_outputs ()
 
void send_pdos (const uint8_t *process_data) override
 
void update_inputs ()
 
std::variant< MotionMasterError, std::vector< uint8_t > > get_file_content (const std::string &file_name)
 
int32_t set_file_content (const std::string &file_name, const std::vector< uint8_t > &content)
 
bool write_file_as_parts (const std::string &file_name, const std::vector< uint8_t > &content, std::function< void(uint8_t)> progress_callback)
 
MotionMasterError do_remove_file (const std::string &file_name)
 
- Public Member Functions inherited from EthercatSlave
 EthercatSlave ()
 
 EthercatSlave (EthercatSlave const &)
 
 ~EthercatSlave ()
 
uint16_t get_device_id () const override
 Get the ID (absolute position) of the EtherCAT slave in the EtherCAT chain. More...
 
uint16_t get_hardware_id () const override
 Get the hardware ID. More...
 
Protocol get_protocol () const override
 Get the protocol the device uses. More...
 
Type get_device_type () const override
 Get the device type. More...
 
std::list< VirtualParameter * > get_all_virtual_parameters () override
 Get all configuration parameters from a slave. More...
 
VirtualParameterget_virtual_parameter (uint16_t index, uint8_t subindex) override
 Get a configuration parameter by its index/subindex. More...
 
std::variant< MotionMasterError, std::list< std::string > > get_file_list () override
 Get the list of available files on the device. More...
 
std::variant< MotionMasterError, std::vector< uint8_t > > read_file (const std::string &file_name) override
 Return the raw content (bytes) of the requested file from the flash memory. More...
 
MotionMasterError write_file (const std::string &file_name, const std::vector< uint8_t > &content, std::function< void(uint8_t)> progress_callback) override
 Write raw content (bytes) into a file in the flash memory. More...
 
MotionMasterError remove_file (const std::string &file_name) override
 Remove a file from the flash memory. More...
 
virtual bool has_firmware ()
 Check if the slave has a firmware installed. More...
 
bool is_operational () const override
 Request the current slave state. More...
 
virtual bool has_pdos ()
 Check if PDO mapping is available. More...
 
virtual State get_state (bool force_refresh) const
 Get the slave EtherCAT state. More...
 
virtual bool set_state (State state, uint32_t timeout_ms=10000)
 Change the EtherCAT state of the slave. More...
 
virtual MotionMasterError write_sii (const std::vector< uint8_t > &content)
 Write the SII file content onto an EtherCAT slave. More...
 
virtual void update_pdo_mapping_od ()
 
virtual void receive_pdos (const uint8_t *process_data)
 
virtual void send_pdos (const uint8_t *process_data)
 
virtual bool request_state_switch (State state)
 
- Public Member Functions inherited from VirtualDevice
virtual ~VirtualDevice ()=default
 
virtual uint16_t get_device_id () const =0
 Get the device ID. More...
 
virtual uint16_t get_hardware_id () const =0
 Get the hardware ID. More...
 
virtual Protocol get_protocol () const
 Get the protocol the device uses. More...
 
virtual Type get_device_type () const
 Get the device type. More...
 
virtual std::list< VirtualParameter * > get_all_virtual_parameters ()=0
 Get all available configuration parameters on the virtual device. More...
 
virtual VirtualParameterget_virtual_parameter (uint16_t index, uint8_t subindex)=0
 Get a configuration parameter. More...
 
virtual std::variant< MotionMasterError, std::list< std::string > > get_file_list ()=0
 Get the list of available files on the device. More...
 
virtual std::variant< MotionMasterError, std::vector< uint8_t > > read_file (const std::string &file_name)=0
 Get the file content from a file from the flash memory. More...
 
virtual MotionMasterError write_file (const std::string &file_name, const std::vector< uint8_t > &content, std::function< void(uint8_t)> progress_callback)=0
 Write the file to the flash memory. More...
 
virtual MotionMasterError remove_file (const std::string &file_name)=0
 Remove the file from the flash memory. More...
 
virtual bool is_operational () const =0
 Check if the device is operational. More...
 

Additional Inherited Members

- Public Types inherited from EthercatSlave
enum class  State : uint8_t {
  kUnspecified = 0 , kInit = 1 , kPreOp = 2 , kBoot = 3 ,
  kSafeOp = 4 , kOp = 8
}
 
enum class  FoeError {
  kNotFound = 0x00008001 , kAccessDenied = 0x00008002 , kDiskFull = 0x00008003 , kIllegal = 0x00008004 ,
  kPacketNumberWrong = 0x00008005 , kAlreadyExists = 0x00008006 , kNoUser = 0x00008007 , kBootstrapOnly = 0x00008008 ,
  kNotBootstrap = 0x00008009 , kNoRights = 0x0000800a , kProgramError = 0x0000800b
}
 
- Public Types inherited from VirtualDevice
enum class  Protocol { kUnspecified = 0 , kMock , kEcat , kSerial }
 
enum class  Type { kUnspecified = 0 , kCia402Drive , kDigitalIo }
 
- Public Attributes inherited from EthercatSlave
uint16_t obytes = 0
 
uint16_t ibytes = 0
 
- Static Public Attributes inherited from EthercatSlave
static const std::map< State, std::map< State, State > > ecat_state_machine_table_
 
static const std::map< FoeError, std::string > foe_error_messages_
 
- Static Public Attributes inherited from VirtualDevice
static const std::map< std::pair< uint32_t, uint32_t >, Typedevice_type_map_
 

Constructor & Destructor Documentation

◆ SoemSlave()

SoemSlave::SoemSlave ( const uint16_t  position)
explicit

◆ ~SoemSlave()

SoemSlave::~SoemSlave ( )
inlineoverride

Member Function Documentation

◆ do_remove_file()

MotionMasterError SoemSlave::do_remove_file ( const std::string &  file_name)

◆ get_all_virtual_parameters()

std::list< VirtualParameter * > SoemSlave::get_all_virtual_parameters ( )
overridevirtual

Get all configuration parameters from a slave.

Returns
a list of configuration parameters

Reimplemented from EthercatSlave.

◆ get_device_id()

uint16_t SoemSlave::get_device_id ( ) const
overridevirtual

Get the ID (absolute position) of the EtherCAT slave in the EtherCAT chain.

Returns
device ID

Reimplemented from EthercatSlave.

◆ get_device_type()

VirtualDevice::Type SoemSlave::get_device_type ( ) const
overridevirtual

Get the device type.

Returns
Type enum

Reimplemented from EthercatSlave.

◆ get_file_content()

std::variant< MotionMasterError, std::vector< uint8_t > > SoemSlave::get_file_content ( const std::string &  file_name)

◆ get_file_list()

std::variant< MotionMasterError, std::list< std::string > > SoemSlave::get_file_list ( )
overridevirtual

Get the list of available files on the device.

Returns
the list of available files on the device
Attention
WORKAROUND: Execute fs-getlist twice in a row if the EtherCAT slave is in EtherCAT BOOT state

If the fs-getlist output is too long, and the EtherCAT slave is currently in EtherCAT BOOT state, the command will return the truncated output in the first call and the rest of the output in the second call.

Reimplemented from EthercatSlave.

◆ get_hardware_id()

uint16_t SoemSlave::get_hardware_id ( ) const
overridevirtual

Get the hardware ID.

Returns
the hardware ID

Reimplemented from EthercatSlave.

◆ get_state()

EthercatSlave::State SoemSlave::get_state ( bool  force_refresh) const
overridevirtual

Get the slave EtherCAT state.

Returns
the slave EtherCAT state

Reimplemented from EthercatSlave.

◆ get_virtual_parameter()

VirtualParameter * SoemSlave::get_virtual_parameter ( uint16_t  index,
uint8_t  subindex 
)
overridevirtual

Get a configuration parameter by its index/subindex.

Parameters
index
subindex
Returns
the pointer to the virtual parameter if available, or nullptr if not

Reimplemented from EthercatSlave.

◆ has_firmware()

bool SoemSlave::has_firmware ( )
overridevirtual

Check if the slave has a firmware installed.

Returns
true if the slave has a firmware installed, false otherwise

Reimplemented from EthercatSlave.

◆ has_pdos()

bool SoemSlave::has_pdos ( )
overridevirtual

Check if PDO mapping is available.

Try to fetch all of the OD entries that define the PDO mapping

Returns
true if PDO mapping is available, false otherwise

Reimplemented from EthercatSlave.

◆ is_operational()

bool SoemSlave::is_operational ( ) const
overridevirtual

Request the current slave state.

Parameters
force_refreshforce refresh the state of the slave first
Returns
the current state of the slave

Reimplemented from EthercatSlave.

◆ is_supported()

bool SoemSlave::is_supported ( )

◆ read_file()

std::variant< MotionMasterError, std::vector< uint8_t > > SoemSlave::read_file ( const std::string &  file_name)
overridevirtual

Return the raw content (bytes) of the requested file from the flash memory.

Parameters
file_name
Returns
MotionMasterError or file content

Reimplemented from EthercatSlave.

◆ receive_pdos()

void SoemSlave::receive_pdos ( const uint8_t *  process_data)
overridevirtual
Note
Use the roundtrip() function within the SoemMaster class.

Reimplemented from EthercatSlave.

◆ remove_file()

MotionMasterError SoemSlave::remove_file ( const std::string &  file_name)
overridevirtual

Remove a file from the flash memory.

Parameters
file_name
Returns
error if any
Attention
Clear the files_to_delete list

The files_to_delete list should be empty at this point, but clear it anyway just because of possible future changes to the code which could result in some files still being in the list.

Try removing files outside of the file list - SAFETY SWEEP

Attention
There are no error codes for removing files, so there is no way to know if the file ever existed in the first place before it was removed, or if there was an error during file removal. To work around this, all of the files are being read first and then deleted (the reading provides the information whether the file is present).

If no additional (hidden) files are found, check if any non-hidden files were removed in the first removal phase and return the result of that.

Reimplemented from EthercatSlave.

◆ request_state_switch()

bool SoemSlave::request_state_switch ( State  state)
overridevirtual

NOTE: This function is called only when using the IgH EtherCAT Master.

Reimplemented from EthercatSlave.

◆ send_pdos()

void SoemSlave::send_pdos ( const uint8_t *  process_data)
overridevirtual
Note
Use the roundtrip() function within the SoemMaster class.

Reimplemented from EthercatSlave.

◆ set_file_content()

int32_t SoemSlave::set_file_content ( const std::string &  file_name,
const std::vector< uint8_t > &  content 
)

◆ set_state()

bool SoemSlave::set_state ( State  state,
uint32_t  timeout_ms = 5000 
)
overridevirtual

Change the EtherCAT state of the slave.

Attention
This is a blocking function, which actually waits until the state has been changed
Parameters
stateEtherCAT state to switch the slave to
timeout_msTimeout in ms, or how long to poll the state, default value is 10000
Returns
true if successful, false otherwise

Reimplemented from EthercatSlave.

◆ update_inputs()

void SoemSlave::update_inputs ( )

◆ update_outputs()

void SoemSlave::update_outputs ( )

◆ write_file()

MotionMasterError SoemSlave::write_file ( const std::string &  file_name,
const std::vector< uint8_t > &  content,
std::function< void(uint8_t)>  progress_callback 
)
overridevirtual

Write raw content (bytes) into a file in the flash memory.

Parameters
file_name
contentvector of bytes
progress_callbackfunction to call for progress changes
Returns
error if any

Reimplemented from EthercatSlave.

◆ write_file_as_parts()

bool SoemSlave::write_file_as_parts ( const std::string &  file_name,
const std::vector< uint8_t > &  content,
std::function< void(uint8_t)>  progress_callback 
)

◆ write_sii()

MotionMasterError SoemSlave::write_sii ( const std::vector< uint8_t > &  content)
overridevirtual

According to the EtherCAT specification (ETG.2000), the SII starts at EEPROM address 0x0000. However, this is not a strict requirement, and the actual starting address may differ based on the slave device's implementation.

Reimplemented from EthercatSlave.


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