SlaveRegisters.h
Go to the documentation of this file.
1#pragma once
2
3/*!
4 * Copied from https://gitlab.com/h2t/student-projects/pse-ws2021/etherkitten/-/tree/master/reader/src/etherkitten/reader
5 *
6 * !!!
7 * Needs correct license message!!!!
8 * !!!
9 */
10
11#include <map>
12#include <string>
13#include <unordered_map>
14
15#include "EtherCATDataTypes.h"
16
17/**
18 * @defgroup Namespace-datatypes datatypes
19 * @ingroup Library-ethercat
20 * @brief Brief description of Namespace datatypes.
21 */
23{
24 /*!
25 * @enum RegisterEnum
26 * @ingroup Namespace-datatypes
27 *
28 * \brief The RegisterEnum enum encodes the slave registers that every slave offers.
29 *
30 * Not all registers are in this enum; a subset has been selected based on the registers' value
31 * in debugging.
32 *
33 * The low 16 bits of a register's value in this enum corresponds to its address in a slave's
34 * memory. If multiple registers are located in the same byte, the next 3 bits encode the
35 * register's offset in the byte.
36 */
37 enum class RegisterEnum
38 {
39 TYPE = 0x0,
40 REVISION = 0x1,
41 BUILD = 0x2,
42 RAM_SIZE = 0x6,
49 DC_SUPPORTED = 0x20008,
50 DC_RANGE = 0x30008,
51 LOW_JITTER_EBUS = 0x40008,
71 DLS_USER_R2 = 0x121,
72 STATUS = 0x130,
73 DLS_USER_R4 = 0x131,
74 DLS_USER_R5 = 0x132,
75 DLS_USER_R6 = 0x134,
76 DLS_USER_R7 = 0x140,
77 DLS_USER_R8 = 0x150,
78 DLS_USER_R9 = 0x141,
104 SII_BUSY = 0x70503,
105 SYSTEM_TIME = 0x910,
106 };
107
108 inline std::uint32_t
110 {
111 static constexpr std::uint32_t addressMask = 0xFFFF;
112 return static_cast<std::uint32_t>(e) & addressMask;
113 }
114
115 inline std::uint8_t
117 {
118 static constexpr std::uint32_t subaddressMask = 0x70000;
119 return static_cast<std::uint8_t>((static_cast<std::uint32_t>(e) & subaddressMask) >> 16);
120 }
121
122 // Comparison Operator for RegisterEnum
123 inline bool
125 {
126 std::uint32_t a_address = getRegisterAddress(a);
127 std::uint32_t b_address = getRegisterAddress(b);
128 std::uint8_t a_subaddress = getRegisterSubAddress(a);
129 std::uint8_t b_subaddress = getRegisterSubAddress(b);
130
131 if (a_address < b_address)
132 {
133 return true;
134 }
135 else if (a_address > b_address)
136 {
137 return false;
138 }
139 else
140 {
141 if (a_subaddress < b_subaddress)
142 {
143 return true;
144 }
145 else
146 {
147 return false;
148 }
149 }
150 }
151
160
161 /*!
162 * \brief The RegisterInfo struct holds additional information on one register.
163 */
165 {
166 std::string name;
168 std::size_t bitLength;
169 };
170
171 template <EtherCATDataTypeEnum E>
173 makeInfo(const std::string& name)
174 {
176 }
177
178 /*!
179 * \brief Holds additional information on all defined registers.
180 */
181 const std::unordered_map<RegisterEnum, RegisterInfo> registerMap = {
191 makeInfo<EtherCATDataTypeEnum::BIT1>("FMMU bit operation not supported")},
193 makeInfo<EtherCATDataTypeEnum::BIT1>("No support for reserved register")},
198 makeInfo<EtherCATDataTypeEnum::BIT1>("Enhanced link detection EBUS")},
200 makeInfo<EtherCATDataTypeEnum::BIT1>("Enhanced link detection MII")},
202 makeInfo<EtherCATDataTypeEnum::BIT1>("Separate fcs error handling")},
204 makeInfo<EtherCATDataTypeEnum::UNSIGNED16>("Configured station address")},
206 makeInfo<EtherCATDataTypeEnum::UNSIGNED16>("Configured station alias")},
208 makeInfo<EtherCATDataTypeEnum::BIT1>("DLS user operational")},
210 makeInfo<EtherCATDataTypeEnum::BIT1>("Link status port 0")},
212 makeInfo<EtherCATDataTypeEnum::BIT1>("Link status port 1")},
214 makeInfo<EtherCATDataTypeEnum::BIT1>("Link status port 2")},
216 makeInfo<EtherCATDataTypeEnum::BIT1>("Link status port 3")},
218 makeInfo<EtherCATDataTypeEnum::BIT1>("Loop status port 0")},
220 makeInfo<EtherCATDataTypeEnum::BIT1>("Signal detection port 0")},
222 makeInfo<EtherCATDataTypeEnum::BIT1>("Loop status port 1")},
224 makeInfo<EtherCATDataTypeEnum::BIT1>("Signal detection port 1")},
226 makeInfo<EtherCATDataTypeEnum::BIT1>("Loop status port 2")},
228 makeInfo<EtherCATDataTypeEnum::BIT1>("Signal detection port 2")},
230 makeInfo<EtherCATDataTypeEnum::BIT1>("Loop status port 3")},
232 makeInfo<EtherCATDataTypeEnum::BIT1>("Signal detection port 3")},
243 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Frame error counter port 0")},
245 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Physical error counter port 0")},
247 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Frame error counter port 1")},
249 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Physical error counter port 1")},
251 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Frame error counter port 2")},
253 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Physical error counter port 2")},
255 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Frame error counter port 3")},
257 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Physical error counter port 3")},
259 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Previous error counter port 0")},
261 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Previous error counter port 1")},
263 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Previous error counter port 2")},
265 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Previous error counter port 3")},
267 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Malformat frame counter")},
269 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Local problem counter")},
271 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Lost link counter port 0")},
273 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Lost link counter port 1")},
275 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Lost link counter port 2")},
277 makeInfo<EtherCATDataTypeEnum::UNSIGNED8>("Lost link counter port 3")},
279 makeInfo<EtherCATDataTypeEnum::BIT1>("SII read operation")},
281 makeInfo<EtherCATDataTypeEnum::BIT1>("SII write operation")},
283 makeInfo<EtherCATDataTypeEnum::BIT1>("SII reload operation")},
285 makeInfo<EtherCATDataTypeEnum::BIT1>("SII checksum error")},
287 makeInfo<EtherCATDataTypeEnum::BIT1>("SII device info error")},
289 makeInfo<EtherCATDataTypeEnum::BIT1>("SII command error")},
293 };
294
295} // namespace armarx::control::ethercat::datatypes
296
298{
299 /*!
300 * \brief Get the length of a register in bytes, rounded up.
301 * \param reg the register to get the length of
302 * \return the length of the register
303 */
305
306 /**
307 * @struct RegisterDataList
308 * @ingroup Library-ethercat
309 * @brief Brief description of struct RegisterDataList.
310 *
311 * Detailed description of struct RegisterDataList.
312 */
314 {
315 std::uint16_t slaveIndex;
316 std::map<datatypes::RegisterEnum, datatypes::RegisterEnumTypeContainer> registerData;
317 };
318} // namespace armarx::control::ethercat
EtherCATDataTypeEnum
Holds all the types we support via EtherCAT in a type-agnostic enum.
RegisterEnum
The RegisterEnum enum encodes the slave registers that every slave offers.
constexpr int bitLength
Defines the length of the various EtherCATDataTypes in bits.
std::uint32_t getRegisterAddress(RegisterEnum e)
std::variant< EtherCATDataType::INTEGER8, EtherCATDataType::INTEGER16, EtherCATDataType::INTEGER32, EtherCATDataType::INTEGER64, EtherCATDataType::UNSIGNED8, EtherCATDataType::UNSIGNED16, EtherCATDataType::UNSIGNED32, EtherCATDataType::UNSIGNED64 > RegisterEnumTypeContainer
RegisterInfo makeInfo(const std::string &name)
std::uint8_t getRegisterSubAddress(RegisterEnum e)
const std::unordered_map< RegisterEnum, RegisterInfo > registerMap
Holds additional information on all defined registers.
bool operator<(RegisterEnum a, RegisterEnum b)
std::size_t getRegisterByteLength(datatypes::RegisterEnum reg)
Get the length of a register in bytes, rounded up.
Brief description of struct RegisterDataList.
std::map< datatypes::RegisterEnum, datatypes::RegisterEnumTypeContainer > registerData
The RegisterInfo struct holds additional information on one register.