Motorcortex Core  version: 2.7.6
ecat_xmltypes.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2016 - 2018 VECTIONEER.
4  */
5 
6 #ifndef ECAT_TYPES_H
7 #define ECAT_TYPES_H
8 
9 #include "ecat_datatype.h"
10 #include "fmt/printf.h"
11 #include "utl_log.h"
12 
13 #include <map>
14 #include <string>
15 #include <vector>
16 
17 namespace mcx::ecat {
18 
21 enum EcatAlState {
22  EC_AL_STATE_INIT = 1,
23  EC_AL_STATE_PREOP = 2,
24  EC_AL_STATE_SAFEOP = 4,
25  EC_AL_STATE_OP = 8,
26 };
27 
28 constexpr std::pair<const char*, EcatAlState> TransitionToStr[] = {{"IP", EcatAlState::EC_AL_STATE_INIT},
29  {"PS", EcatAlState::EC_AL_STATE_PREOP},
30  {"SO", EcatAlState::EC_AL_STATE_SAFEOP},
31  {0x0, EcatAlState::EC_AL_STATE_PREOP}};
32 
33 constexpr const char* transitionToStr(EcatAlState al_state) {
34  unsigned int counter = 0;
35  while (TransitionToStr[counter].first) {
36  if (TransitionToStr[counter].second == al_state) {
37  break;
38  }
39  ++counter;
40  }
41  return TransitionToStr[counter].first;
42 }
43 
48 enum EcatWatchdogMode {
49  EC_WD_DEFAULT,
50  EC_WD_ENABLE,
51  EC_WD_DISABLE,
52  EC_WD_COUNT
53 };
54 
55 constexpr std::pair<const char*, EcatWatchdogMode> EcatWdToStr[]{{"Default", EcatWatchdogMode::EC_WD_DEFAULT},
56  {"Enable", EcatWatchdogMode::EC_WD_ENABLE},
57  {"Disable", EcatWatchdogMode::EC_WD_DISABLE},
58  {0x0, EcatWatchdogMode::EC_WD_COUNT}};
59 
62 enum EcatDirection {
63  EC_DIR_INVALID,
64  EC_DIR_OUTPUT,
65  EC_DIR_INPUT,
66  EC_DIR_BOTH,
67  EC_DIR_COUNT
68 };
69 
70 using SdoDirection = EcatDirection;
71 
72 constexpr std::pair<const char*, EcatDirection> EcatDirToStr[]{{"Invalid", EcatDirection::EC_DIR_INVALID},
73  {"Output", EcatDirection::EC_DIR_OUTPUT},
74  {"Input", EcatDirection::EC_DIR_INPUT},
75  {"Both", EcatDirection::EC_DIR_BOTH},
76  {0x0, EcatDirection::EC_DIR_COUNT}};
77 
78 struct EcatSdoId {
79  unsigned int device_id;
80  unsigned int index;
81  unsigned int subindex;
82  EcatDirection dir;
83 };
84 
85 // data type to represent pdo address, for example "1600 7010:10" (HEX)
86 
87 struct EcatPdoId {
88  unsigned int pdo_index;
89  unsigned int entry_index;
90  unsigned int entry_subindex;
91 };
92 
93 enum ParameterLinkType { PL_DIR_UNKNOWN, PL_DIR_TO, PL_DIR_FROM, PL_SDO_READ, PL_SDO_WRITE };
94 
95 struct ParameterLink {
96  std::string name;
97  std::string group;
98  ParameterLinkType type;
99  std::string path;
100  unsigned int index;
101  double gain;
102  double offset;
103  bool inv_bool;
104  bool sim;
105  bool clamp;
106 };
107 
113 struct EcatPdoInfo {
114  // bool is_mapped; /**< Entry is mapped to the user configuration. */
115  bool is_visible;
116  unsigned int pos;
117  unsigned int index;
118  unsigned int subindex;
119  unsigned int byte_offset;
120  unsigned int bit_offset;
121  std::string name;
122  std::string group;
123  DataTypeDesc data_type;
124  std::vector<ParameterLink> links;
125  std::vector<EcatPdoInfo> entries;
126 };
127 
134 struct EcatSyncInfo {
135  // bool is_mapped; /**< Syn manager is mapped. */
136  unsigned int index;
139  EcatDirection dir;
140  EcatWatchdogMode watchdog_mode;
141  std::vector<EcatPdoInfo> pdo_info;
142 };
143 
149 enum SdoDownloadState {
150  EC_REQUEST_UNUSED,
151  EC_REQUEST_BUSY,
152  EC_REQUEST_SUCCESS,
153  EC_REQUEST_ERROR
154 };
155 
156 enum SdoType {
157  EC_SDO_TYPE_INVALID,
158  EC_CAN_OVER_ETHERCAT,
159  EC_SERCOS_OVER_ETHERCAT
160 };
161 
162 constexpr std::pair<const char*, SdoType> SdoTypeToStr[]{{"Invalid", SdoType::EC_SDO_TYPE_INVALID},
163  {"COE", SdoType::EC_CAN_OVER_ETHERCAT},
164  {"SOE", SdoType::EC_SERCOS_OVER_ETHERCAT}};
165 
166 // device information
167 struct EcatDcInfo {
168  unsigned int assign_activate;
169  unsigned int cycle_time_sync0;
170  unsigned int shift_time_sync0;
171  unsigned int cycle_time_sync1;
172  unsigned int shift_time_sync1;
173 };
174 
176  unsigned int vendor_id;
177  unsigned int product_code;
178  unsigned int alias;
179  unsigned int position;
180  std::string name;
181  std::string group;
182 };
183 
184 // complete description required for device configuration
185 // array of these structures is filled from etherlab xml file
186 
187 struct EcatDevice {
188  EcatDeviceInfo device_info;
189  std::vector<EcatSyncInfo> sm_info;
190  std::vector<EcatDcInfo> dc_info;
191 };
192 
193 struct EcatSdoConfig;
194 using Links = std::vector<ParameterLink>;
195 using Entries = std::vector<EcatSdoConfig>;
196 
198  // bool is_mapped;
199  SdoType type;
200  SdoDirection dir;
201  unsigned int pos;
202  unsigned int index;
203  unsigned int subindex;
204  void* data_ptr;
205  uint8_t* read_data_ptr;
206  uint8_t* write_data_ptr;
207  DataTypeDesc data_type;
208  std::string group;
209  std::string name;
210  Links links;
211  Entries entries;
212 };
213 
214 inline size_t getSdoHash(EcatSdoConfig sdo_config) {
215  return std::hash<std::string>{}(
216  fmt::format("{}:{}:{}:{}", sdo_config.pos, sdo_config.index, sdo_config.subindex, sdo_config.dir));
217 }
218 
219 struct EcatSoe {
220  EcatAlState state_transition;
221  unsigned int op_code;
222  unsigned int drive_no;
223  unsigned int idn;
224  unsigned int elements;
225  unsigned int attribute;
226  unsigned int timeout;
227  std::vector<unsigned char> data;
228  std::string comment;
229 };
230 
231 struct EcatCoe {
232  bool complete_access;
233  EcatAlState state_transition;
234  unsigned int index;
235  unsigned int subindex;
236  unsigned int timeout;
237  unsigned int ccs;
238  std::vector<unsigned char> data;
239  std::string comment;
240 };
241 
242 struct EcatMailbox {
243  std::vector<EcatSoe> soe;
244  std::vector<EcatCoe> coe;
245 };
246 
248  EcatDeviceInfo info;
249  std::vector<EcatMailbox> mailbox;
250  std::vector<EcatSyncInfo> sm;
251  std::vector<EcatSdoConfig> sdo;
252  EcatDcInfo dc;
253 };
254 
256  std::string name;
257  std::string group;
258  std::vector<EcatDeviceConfig> device;
259  double no_error_timeout_sec;
260  double error_timeout_sec;
261  bool sdo_recovery;
262 };
263 
264 } // namespace mcx::ecat
265 
266 #endif /* ECAT_TYPES_H */
mcx::ecat::EcatPdoInfo
Definition: ecat_xmltypes.h:113
mcx::ecat::EcatSyncInfo::dir
EcatDirection dir
Definition: ecat_xmltypes.h:139
mcx::ecat::EcatSyncInfo::pdo_info
std::vector< EcatPdoInfo > pdo_info
Definition: ecat_xmltypes.h:141
mcx::ecat::EcatDomainConfig
Definition: ecat_xmltypes.h:255
mcx::ecat::EcatPdoInfo::index
unsigned int index
Definition: ecat_xmltypes.h:117
mcx::ecat::EcatDeviceInfo
Definition: ecat_xmltypes.h:175
mcx::ecat::EcatMailbox
Definition: ecat_xmltypes.h:242
mcx::ecat::EcatSoe
Definition: ecat_xmltypes.h:219
mcx::ecat::EcatCoe
Definition: ecat_xmltypes.h:231
mcx::ecat::EcatSyncInfo::watchdog_mode
EcatWatchdogMode watchdog_mode
Definition: ecat_xmltypes.h:140
mcx::ecat::EcatSyncInfo
Definition: ecat_xmltypes.h:134
mcx::ecat::EcatPdoInfo::bit_offset
unsigned int bit_offset
Definition: ecat_xmltypes.h:120
mcx::ecat::EcatPdoId
Definition: ecat_xmltypes.h:87
mcx::ecat::EcatSyncInfo::index
unsigned int index
Definition: ecat_xmltypes.h:136
mcx::ecat::DataTypeDesc
Definition: ecat_datatype.h:24
mcx::ecat::EcatSdoConfig
Definition: ecat_xmltypes.h:197
mcx::ecat::EcatDcInfo
Definition: ecat_xmltypes.h:167
mcx::ecat::EcatDevice
Definition: ecat_xmltypes.h:187
mcx::ecat::EcatPdoInfo::subindex
unsigned int subindex
Definition: ecat_xmltypes.h:118
mcx::ecat::EcatPdoInfo::pos
unsigned int pos
Definition: ecat_xmltypes.h:116
mcx::ecat::EcatPdoInfo::byte_offset
unsigned int byte_offset
Definition: ecat_xmltypes.h:119
mcx::ecat::EcatDeviceConfig
Definition: ecat_xmltypes.h:247
mcx::ecat::EcatSdoId
Definition: ecat_xmltypes.h:78