Motion Master
Loading...
Searching...
No Matches
igh_ethercat_slave.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef LINUX_BUILD
4
5#include <list>
6#include <map>
7#include <variant>
8
9#include "ethercat_slave.h"
10#include "igh_dynamic.h"
11#include "igh_od_entry.h"
12#include "util.h"
13
14class IghEthercatMaster;
16
17class IghEthercatSlave : public EthercatSlave {
18 public:
19 friend class IghEthercatMaster;
20
21 explicit IghEthercatSlave(IghEthercatMaster &master);
22
23 ~IghEthercatSlave() override {};
24
31 [[nodiscard]] uint16_t get_device_id() const override;
32
38 [[nodiscard]] uint16_t get_hardware_id() const override;
39
45 [[nodiscard]] Type get_device_type() const override;
46
47 /******************************* PARAMETERS *******************************/
53 [[nodiscard]] std::list<VirtualParameter *> get_all_virtual_parameters()
54 override;
55
66 uint16_t index, uint8_t subindex) override;
67
68 /**************************** FILE OPERATIONS ****************************/
74 [[nodiscard]] std::variant<MotionMasterError, std::list<std::string>>
75 get_file_list() override;
76
85 [[nodiscard]] std::variant<MotionMasterError, std::vector<uint8_t>> read_file(
86 const std::string &file_name) override;
87
98 const std::string &file_name, const std::vector<uint8_t> &content,
99 std::function<void(uint8_t)> progress_callback) override;
100
108 MotionMasterError remove_file(const std::string &file_name) override;
109
110 /********************************* OTHER *********************************/
116 bool has_firmware() override;
117
125 [[nodiscard]] bool is_operational() const override;
126
134 [[nodiscard]] bool has_pdos() override;
135
141 [[nodiscard]] State get_state(bool force_refresh) const override;
142
154 bool set_state(State state, uint32_t timeout_ms = 1000) override;
155
166 bool request_state_switch(State state) override;
167
175 MotionMasterError write_sii(const std::vector<uint8_t> &content) override;
176
182 void receive_pdos(const uint8_t *process_data) override;
183
189 void send_pdos(const uint8_t *process_data) override;
190
191 private:
192 class Pdo {
193 public:
194 explicit Pdo(IghOdEntry *od_entry, ec_direction_t dir)
195 : od_entry_(od_entry), dir_(dir) {}
196
197 [[nodiscard]] bool is_valid() const {
198 return od_entry_ && dir_ != EC_DIR_INVALID;
199 }
200
201 IghOdEntry *od_entry_ = nullptr;
202 ec_direction_t dir_ = EC_DIR_INVALID;
203 unsigned int offset_ = 0;
204 unsigned int bit_offset_ = 0;
205 };
206
207 // Reference to the master interface this slave is connected to
208 IghEthercatMaster &master_;
209
210 // Keeps the last active alias, since it is different than in
211 // ec_slave_info_t
212 uint16_t reference_alias_ = 0;
213
214 // Position relative to the last defined alias in the chain
215 uint16_t relative_position_ = 0;
216
217 // The type is determined by the vendor/product numbers
218 Type type_ = Type::kUnspecified;
219
220 // Initialized via init_hardware_id() in IghEthercatMaster
221 uint16_t hardware_id_ = 0;
222
223 // Information structures from libethercat
224 ec_slave_info_t slave_info_{};
225 ec_slave_config_t *slave_config_ = nullptr;
226
227 std::map<uint16_t, std::vector<ec_pdo_entry_info_t>> rx_pdo_map_;
228 std::vector<ec_pdo_info_t> rx_pdos_;
229 std::map<uint16_t, std::vector<ec_pdo_entry_info_t>> tx_pdo_map_;
230 std::vector<ec_pdo_info_t> tx_pdos_;
231 std::vector<ec_sync_info_t> syncs_;
232
233 // Read with ecrt_slave_config_state()
234 ec_slave_config_state_t slave_config_state_{};
235
236 std::list<Pdo> pdos_;
237
238 std::map<uint32_t, IghOdEntry> od_entry_map_; // Object dictionary
239
240 static inline std::vector<std::string> files_to_cache_ = {
242
243 // This map will be empty if the caching has never been done
244 std::map<std::string, std::vector<uint8_t>> cached_files_;
245
252 void update_pdo_mapping_od() override;
253};
254
255#endif
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
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
virtual State get_state(bool force_refresh) const
Get the slave EtherCAT state.
Definition: ethercat_slave.h:237
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
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
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
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
uint16_t get_hardware_id() const override
Get the hardware ID.
Definition: ethercat_slave.h:111
Definition: motion_master_error.h:6
Definition: virtual_parameter.h:9
uint16_t index
Definition: co_dictionary.h:0
const char *const HARDWARE_DESCRIPTION_FILENAME
Definition: util.h:25
const char *const STACK_INFO_FILENAME
Definition: util.h:26