EtherCATDataTypes.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 <bitset>
12#include <cstdint>
13#include <variant>
14#include <vector>
15
17{
18 /**
19 * @enum EtherCATDataTypeEnum
20 * @ingroup Namespace-datatypes
21 *
22 * \brief Holds all the types we support via EtherCAT in a type-agnostic enum.
23 *
24 * The enum values correspond to the values defined in the standard.
25 * We use these to identify which types different DataObjects have.
26 */
57
58 /*!
59 * \brief Holds all the types we support via EtherCAT as their C++ equivalents
60 * along with some tools to handle them.
61 *
62 * We use the types defined here to actually move the data around,
63 * and the templates to perform type-agnostic operations.
64 */
66 {
67 using BOOLEAN = bool;
68 using INTEGER8 = int8_t;
69 using INTEGER16 = int16_t;
70 using INTEGER32 = int32_t;
71 using UNSIGNED8 = uint8_t;
72 using UNSIGNED16 = uint16_t;
73 using UNSIGNED32 = uint32_t;
74 using REAL32 = float;
75 using VISIBLE_STRING = std::string;
76 using OCTET_STRING = std::vector<uint8_t>;
77 using UNICODE_STRING = std::string;
78 using TIME_OF_DAY = std::bitset<48>; // NOLINT
79 using TIME_DIFFERENCE = uint64_t;
80 using INTEGER24 = std::bitset<24>; // NOLINT
81 using REAL64 = double;
82 using INTEGER64 = int64_t;
83 using UNSIGNED24 = std::bitset<24>; // NOLINT
84 using UNSIGNED64 = uint64_t;
85 using BYTE = uint8_t;
86 using BIT1 = std::bitset<1>;
87 using BIT2 = std::bitset<2>;
88 using BIT3 = std::bitset<3>;
89 using BIT4 = std::bitset<4>;
90 using BIT5 = std::bitset<5>; // NOLINT
91 using BIT6 = std::bitset<6>; // NOLINT
92 using BIT7 = std::bitset<7>; // NOLINT
93 using BIT8 = std::bitset<8>; // NOLINT
94
95 /*!
96 * \brief Defines the length of the various EtherCATDataTypes in bits.
97 *
98 * If a type does not have a well-defined length, `bitLength<T> == -1`.
99 *
100 * Note that `bitLength<T> != sizeof(T) * 8` in general.
101 * \tparam T the EtherCATDataType to get the length of
102 */
103 template <typename T>
104 constexpr int bitLength = -1;
105 template <>
106 inline constexpr int bitLength<BOOLEAN> = 8;
107 template <>
108 inline constexpr int bitLength<INTEGER8> = 8;
109 template <>
110 inline constexpr int bitLength<INTEGER16> = 16;
111 template <>
112 inline constexpr int bitLength<INTEGER32> = 32;
113 template <>
114 inline constexpr int bitLength<UNSIGNED8> = 8;
115 template <>
116 inline constexpr int bitLength<UNSIGNED16> = 16;
117 template <>
118 inline constexpr int bitLength<UNSIGNED32> = 32;
119 template <>
120 inline constexpr int bitLength<REAL32> = 32;
121 template <>
122 inline constexpr int bitLength<VISIBLE_STRING> = -1;
123 template <>
124 inline constexpr int bitLength<OCTET_STRING> = -1;
125 template <>
126 inline constexpr int bitLength<TIME_OF_DAY> = 48;
127 template <>
128 inline constexpr int bitLength<INTEGER24> = 24; // NOLINT
129 template <>
130 inline constexpr int bitLength<REAL64> = 64;
131 template <>
132 inline constexpr int bitLength<INTEGER64> = 64;
133 template <>
134 inline constexpr int bitLength<UNSIGNED64> = 64;
135 template <>
136 inline constexpr int bitLength<BIT1> = 1;
137 template <>
138 inline constexpr int bitLength<BIT2> = 2;
139 template <>
140 inline constexpr int bitLength<BIT3> = 3;
141 template <>
142 inline constexpr int bitLength<BIT4> = 4;
143 template <>
144 inline constexpr int bitLength<BIT5> = 5; // NOLINT
145 template <>
146 inline constexpr int bitLength<BIT6> = 6; // NOLINT
147 template <>
148 inline constexpr int bitLength<BIT7> = 7; // NOLINT
149 template <>
150 inline constexpr int bitLength<BIT8> = 8; // NOLINT
151 } // namespace EtherCATDataType
152
153 /*!
154 * \brief Maps from EtherCATDataTypeEnum to EtherCATDataType.
155 * \tparam E the EtherCATDataTypeEnum to translate to an EtherCATDataType
156 */
157 template <EtherCATDataTypeEnum E>
158 struct TypeMap
159 {
160 };
161
162 // clang-format off
163 template<>
165 template<>
167 template<>
169 template<>
171 template<>
173 template<>
175 template<>
177 template<>
179 template<>
181 template<>
183 template<>
185 template<>
187 template<>
189 template<>
191 template<>
193 template<>
195 template<>
197 template<>
199 template<>
201 template<>
203 template<>
205 template<>
207 template<>
209 template<>
211 template<>
213 template<>
215 template<>
217
218 // clang-format on
219} // namespace armarx::control::ethercat::datatypes
#define float
Definition 16_Level.h:22
EtherCATDataTypeEnum
Holds all the types we support via EtherCAT in a type-agnostic enum.
Holds all the types we support via EtherCAT as their C++ equivalents along with some tools to handle ...
constexpr int bitLength
Defines the length of the various EtherCATDataTypes in bits.
Maps from EtherCATDataTypeEnum to EtherCATDataType.