Motion Master
Loading...
Searching...
No Matches
ethercat_slave.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
6#include "virtual_device.h"
7
8#define MAX_FILE_LIST_LENGTH 30
9
11 public:
13
15
17
18 enum class State : uint8_t {
20 kInit = 1,
21 kPreOp = 2,
22 kBoot = 3,
24 kOp = 8
25 };
26
27 uint16_t obytes = 0;
28 uint16_t ibytes = 0;
29
38 inline static const std::map<State, std::map<State, State>>
69
70 enum class FoeError {
71 kNotFound = 0x00008001,
72 kAccessDenied = 0x00008002,
73 kDiskFull = 0x00008003,
74 kIllegal = 0x00008004,
75 kPacketNumberWrong = 0x00008005,
76 kAlreadyExists = 0x00008006,
77 kNoUser = 0x00008007,
78 kBootstrapOnly = 0x00008008,
79 kNotBootstrap = 0x00008009,
80 kNoRights = 0x0000800a,
81 kProgramError = 0x0000800b
82 };
83
84 static inline const std::map<FoeError, std::string> foe_error_messages_ = {
85 {FoeError::kNotFound, "Not found"},
86 {FoeError::kAccessDenied, "Access denied"},
87 {FoeError::kDiskFull, "Disk full"},
88 {FoeError::kIllegal, "Illegal operation"},
89 {FoeError::kPacketNumberWrong, "Packet number wrong"},
90 {FoeError::kAlreadyExists, "Already exists"},
91 {FoeError::kNoUser, "No user"},
92 {FoeError::kBootstrapOnly, "Bootstrap only"},
93 {FoeError::kNotBootstrap, "Not Bootstrap"},
94 {FoeError::kNoRights, "No rights"},
95 {FoeError::kProgramError, "Program Error"}};
96
103 [[nodiscard]] uint16_t get_device_id() const override { return 0; };
104
110 [[nodiscard]] uint16_t get_hardware_id() const override { return 0; };
111
117 [[nodiscard]] Protocol get_protocol() const override {
118 return Protocol::kEcat;
119 }
120
126 [[nodiscard]] Type get_device_type() const override {
127 return Type::kUnspecified;
128 };
129
130 /******************************* PARAMETERS *******************************/
136 [[nodiscard]] std::list<VirtualParameter*> get_all_virtual_parameters()
137 override {
138 return {};
139 };
140
151 uint16_t index, uint8_t subindex) override {
152 return nullptr;
153 };
154
155 /**************************** FILE OPERATIONS ****************************/
161 [[nodiscard]] std::variant<MotionMasterError, std::list<std::string>>
162 get_file_list() override {
163 return {};
164 };
165
174 [[nodiscard]] std::variant<MotionMasterError, std::vector<uint8_t>> read_file(
175 const std::string& file_name) override {
176 return {};
177 };
178
189 const std::string& file_name, const std::vector<uint8_t>& content,
190 std::function<void(uint8_t)> progress_callback) override {
191 return MotionMasterError();
192 };
193
201 MotionMasterError remove_file(const std::string& file_name) override {
202 return MotionMasterError();
203 };
204
205 /********************************* OTHER *********************************/
211 virtual bool has_firmware() { return false; }
212
220 [[nodiscard]] bool is_operational() const override { return false; }
221
229 [[nodiscard]] virtual bool has_pdos() { return false; }
230
236 [[nodiscard]] virtual State get_state(bool force_refresh) const {
237 return State();
238 }
239
252 virtual bool set_state(State state, uint32_t timeout_ms = 10000) {
253 return false;
254 }
255
263 virtual MotionMasterError write_sii(const std::vector<uint8_t>& content) {
264 return MotionMasterError(MotionMasterError::Error::kNone);
265 }
266
267 virtual void update_pdo_mapping_od() {}
268 virtual void receive_pdos(const uint8_t* process_data) {}
269 virtual void send_pdos(const uint8_t* process_data) {}
270 virtual bool request_state_switch(State state) { return false; }
271};
virtual bool has_pdos()
Check if PDO mapping is available.
Definition ethercat_slave.h:229
std::variant< MotionMasterError, std::list< std::string > > get_file_list() override
Get the list of available files on the device.
Definition ethercat_slave.h:162
EthercatSlave(EthercatSlave const &)
Definition ethercat_slave.h:14
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.
Definition ethercat_slave.h:188
VirtualParameter * get_virtual_parameter(uint16_t index, uint8_t subindex) override
Get a configuration parameter by its index/subindex.
Definition ethercat_slave.h:150
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.
Definition ethercat_slave.h:174
static const std::map< FoeError, std::string > foe_error_messages_
Definition ethercat_slave.h:84
virtual State get_state(bool force_refresh) const
Get the slave EtherCAT state.
Definition ethercat_slave.h:236
Protocol get_protocol() const override
Get the protocol the device uses.
Definition ethercat_slave.h:117
static const std::map< State, std::map< State, State > > ecat_state_machine_table_
Definition ethercat_slave.h:39
State
Definition ethercat_slave.h:18
@ kSafeOp
Definition ethercat_slave.h:23
@ kPreOp
Definition ethercat_slave.h:21
@ kOp
Definition ethercat_slave.h:24
@ kUnspecified
Definition ethercat_slave.h:19
@ kBoot
Definition ethercat_slave.h:22
@ kInit
Definition ethercat_slave.h:20
uint16_t obytes
Definition ethercat_slave.h:27
virtual void send_pdos(const uint8_t *process_data)
Definition ethercat_slave.h:269
std::list< VirtualParameter * > get_all_virtual_parameters() override
Get all configuration parameters from a slave.
Definition ethercat_slave.h:136
virtual void update_pdo_mapping_od()
Definition ethercat_slave.h:267
virtual MotionMasterError write_sii(const std::vector< uint8_t > &content)
Write the SII file content onto an EtherCAT slave.
Definition ethercat_slave.h:263
FoeError
Definition ethercat_slave.h:70
@ kAccessDenied
Definition ethercat_slave.h:72
@ kNotBootstrap
Definition ethercat_slave.h:79
@ kProgramError
Definition ethercat_slave.h:81
@ kBootstrapOnly
Definition ethercat_slave.h:78
@ kNoRights
Definition ethercat_slave.h:80
@ kIllegal
Definition ethercat_slave.h:74
@ kAlreadyExists
Definition ethercat_slave.h:76
@ kNotFound
Definition ethercat_slave.h:71
@ kPacketNumberWrong
Definition ethercat_slave.h:75
@ kNoUser
Definition ethercat_slave.h:77
@ kDiskFull
Definition ethercat_slave.h:73
MotionMasterError remove_file(const std::string &file_name) override
Remove a file from the flash memory.
Definition ethercat_slave.h:201
virtual void receive_pdos(const uint8_t *process_data)
Definition ethercat_slave.h:268
~EthercatSlave()
Definition ethercat_slave.h:16
virtual bool request_state_switch(State state)
Definition ethercat_slave.h:270
uint16_t get_device_id() const override
Get the ID (absolute position) of the EtherCAT slave in the EtherCAT chain.
Definition ethercat_slave.h:103
virtual bool has_firmware()
Check if the slave has a firmware installed.
Definition ethercat_slave.h:211
uint16_t ibytes
Definition ethercat_slave.h:28
virtual bool set_state(State state, uint32_t timeout_ms=10000)
Change the EtherCAT state of the slave.
Definition ethercat_slave.h:252
bool is_operational() const override
Request the current slave state.
Definition ethercat_slave.h:220
Type get_device_type() const override
Get the device type.
Definition ethercat_slave.h:126
EthercatSlave()
Definition ethercat_slave.h:12
uint16_t get_hardware_id() const override
Get the hardware ID.
Definition ethercat_slave.h:110
Definition motion_master_error.h:6
Definition virtual_device.h:22
Protocol
Definition virtual_device.h:24
@ kEcat
Definition virtual_device.h:24
Type
Definition virtual_device.h:26
@ kUnspecified
Definition virtual_device.h:26
Definition virtual_parameter.h:9
uint16_t index
Definition co_dictionary.h:0