Motion Master
Loading...
Searching...
No Matches
soem_slave.h
Go to the documentation of this file.
1#include <ethercat.h>
2
3#include <chrono>
4#include <map>
5#include <mutex>
6
7#include "ethercat_slave.h"
9#include "soem_od_entry.h"
10
11#define OTYPE_VAR 0x0007
12#define OTYPE_ARRAY 0x0008
13#define OTYPE_RECORD 0x0009
14
16
17class SoemSlave : public EthercatSlave {
18 uint16_t position_;
19 Type type_;
20 uint16_t hardware_id_;
21 std::map<uint32_t, SoemOdEntry> od_entry_map_;
22
23 class Pdo {
24 public:
25 explicit Pdo(SoemOdEntry *od_entry, uint32_t offset)
26 : od_entry_{od_entry}, offset_{offset} {}
27
28 explicit Pdo(VirtualParameter *virtual_parameter, uint32_t offset) {
29 SoemOdEntry *od_entry = dynamic_cast<SoemOdEntry *>(virtual_parameter);
30 if (!od_entry) {
31 throw std::invalid_argument(
32 "Invalid argument provided for Pdo object construction.");
33 }
34 *this = Pdo(od_entry, offset);
35 }
36
37 SoemOdEntry *od_entry_ = nullptr;
38 uint32_t offset_ = 0;
39 };
40
41 std::list<Pdo> rx_pdos_;
42 std::list<Pdo> tx_pdos_;
43
44 int setup_od_entries();
45
46 void config_detected_smm();
47
48 void init_hardware_id();
49 void init_type();
50
51 void update_pdo_mapping_od() override;
52
53 public:
54 explicit SoemSlave(const uint16_t position);
55
56 ~SoemSlave() override {};
57
58 [[nodiscard]] uint16_t get_device_id() const override;
59
60 [[nodiscard]] uint16_t get_hardware_id() const override;
61
62 [[nodiscard]] Type get_device_type() const override;
63
64 [[nodiscard]] std::list<VirtualParameter *> get_all_virtual_parameters()
65 override;
66
68 uint16_t index, uint8_t subindex) override;
69
70 [[nodiscard]] std::variant<MotionMasterError, std::list<std::string>>
71 get_file_list() override;
72
73 [[nodiscard]] std::variant<MotionMasterError, std::vector<uint8_t>> read_file(
74 const std::string &file_name) override;
75
77 const std::string &file_name, const std::vector<uint8_t> &content,
78 std::function<void(uint8_t)> progress_callback) override;
79
80 MotionMasterError remove_file(const std::string &file_name) override;
81
82 bool has_firmware() override;
83
84 [[nodiscard]] bool is_operational() const override;
85
86 bool is_supported();
87
88 [[nodiscard]] bool has_pdos() override;
89
90 [[nodiscard]] State get_state(bool force_refresh) const override;
91
92 bool set_state(State state, uint32_t timeout_ms = 5000) override;
93
94 bool request_state_switch(State state) override;
95
96 MotionMasterError write_sii(const std::vector<uint8_t> &content) override;
97
98 [[maybe_unused]] void receive_pdos(const uint8_t *process_data) override;
99
100 void update_outputs();
101
102 [[maybe_unused]] void send_pdos(const uint8_t *process_data) override;
103
104 void update_inputs();
105
106 [[nodiscard]] std::variant<MotionMasterError, std::vector<uint8_t>>
107 get_file_content(const std::string &file_name);
108 [[nodiscard]] int32_t set_file_content(const std::string &file_name,
109 const std::vector<uint8_t> &content);
110 bool write_file_as_parts(const std::string &file_name,
111 const std::vector<uint8_t> &content,
112 std::function<void(uint8_t)> progress_callback);
113 MotionMasterError do_remove_file(const std::string &file_name);
114};
115
116const std::map<uint16_t, std::vector<uint32_t>> rxpdos_static_map = {
117 {0x1600,
118 {
119 0x60400010,
120 0x60600008,
121 0x60710010,
122 0x607a0020,
123 0x60ff0020,
124 0x60b20010,
125 0x27010020,
126 }},
127 {0x1601,
128 {
129 0x60fe0120,
130 0x60fe0220,
131 }},
132 {0x1602,
133 {
134 0x27030020,
135 0x60b10020,
136 }}};
137
138const std::map<uint16_t, std::vector<uint32_t>> txpdos_static_map = {
139 {0x1A00,
140 {
141 0x60410010,
142 0x60610008,
143 0x60640020,
144 0x606c0020,
145 0x60770010,
146 0x60F40020,
147 }},
148 {0x1A01,
149 {
150 0x24010010,
151 0x24020010,
152 0x24030010,
153 0x24040010,
154 0x27020020,
155 }},
156 {0x1A02, {0x60fd0020}},
157 {0x1A03,
158 {
159 0x27040020,
160 0x20f00020,
161 0x60fc0020,
162 0x606b0020,
163 0x60740010,
164 }}};
Definition: ethercat_slave.h:11
State
Definition: ethercat_slave.h:19
Definition: motion_master_error.h:6
Definition: soem_od_entry.h:5
Definition: soem_slave.h:17
uint16_t get_device_id() const override
Get the ID (absolute position) of the EtherCAT slave in the EtherCAT chain.
Definition: soem_slave.cc:174
void send_pdos(const uint8_t *process_data) override
Definition: soem_slave.cc:1026
bool is_operational() const override
Request the current slave state.
Definition: soem_slave.cc:892
bool has_pdos() override
Check if PDO mapping is available.
Definition: soem_slave.cc:907
std::variant< MotionMasterError, std::list< std::string > > get_file_list() override
Get the list of available files on the device.
Definition: soem_slave.cc:458
std::variant< MotionMasterError, std::vector< uint8_t > > get_file_content(const std::string &file_name)
Definition: soem_slave.cc:1042
MotionMasterError do_remove_file(const std::string &file_name)
Definition: soem_slave.cc:1181
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: soem_slave.cc:505
State get_state(bool force_refresh) const override
Get the slave EtherCAT state.
Definition: soem_slave.cc:909
uint16_t get_hardware_id() const override
Get the hardware ID.
Definition: soem_slave.cc:176
MotionMasterError write_sii(const std::vector< uint8_t > &content) override
Definition: soem_slave.cc:987
bool set_state(State state, uint32_t timeout_ms=5000) override
Change the EtherCAT state of the slave.
Definition: soem_slave.cc:921
void receive_pdos(const uint8_t *process_data) override
Definition: soem_slave.cc:1007
bool is_supported()
Definition: soem_slave.cc:896
bool write_file_as_parts(const std::string &file_name, const std::vector< uint8_t > &content, std::function< void(uint8_t)> progress_callback)
Definition: soem_slave.cc:1137
int32_t set_file_content(const std::string &file_name, const std::vector< uint8_t > &content)
Definition: soem_slave.cc:1106
~SoemSlave() override
Definition: soem_slave.h:56
std::list< VirtualParameter * > get_all_virtual_parameters() override
Get all configuration parameters from a slave.
Definition: soem_slave.cc:438
void update_outputs()
Definition: soem_slave.cc:1009
MotionMasterError remove_file(const std::string &file_name) override
Remove a file from the flash memory.
Definition: soem_slave.cc:739
VirtualParameter * get_virtual_parameter(uint16_t index, uint8_t subindex) override
Get a configuration parameter by its index/subindex.
Definition: soem_slave.cc:446
bool has_firmware() override
Check if the slave has a firmware installed.
Definition: soem_slave.cc:890
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: soem_slave.cc:605
void update_inputs()
Definition: soem_slave.cc:1028
Type get_device_type() const override
Get the device type.
Definition: soem_slave.cc:436
bool request_state_switch(State state) override
Definition: soem_slave.cc:979
Type
Definition: virtual_device.h:24
Definition: virtual_parameter.h:9
uint16_t index
Definition: co_dictionary.h:0
const std::map< uint16_t, std::vector< uint32_t > > txpdos_static_map
Definition: soem_slave.h:138
const std::map< uint16_t, std::vector< uint32_t > > rxpdos_static_map
Definition: soem_slave.h:116