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