Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
object_data_types.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <cstdint>
6#include <nlohmann/json_fwd.hpp>
7#include <string_view>
8
9// <cmath>/<math.h> — pulled in transitively by the STL headers above — defines the obsolete
10// SVID matherr macro DOMAIN on macOS/Clang and Windows/MSVC. Left in place it would expand
11// inside the ObjectDataType enum below and break the build. glibc gates the macro behind a
12// feature test that -std=c++2b disables, so only the non-Linux toolchains hit this. The
13// matherr interface is long dead; drop the macro so the ETG.1020 DOMAIN enumerator survives.
14#ifdef DOMAIN
15#undef DOMAIN
16#endif
17
18namespace mm::comm {
19
27enum class ObjectDataType : uint16_t {
28 UNSPECIFIED = 0x0000,
29
30 BOOLEAN = 0x0001,
31 BYTE = 0x001E,
32 WORD = 0x001F,
33 DWORD = 0x0020,
34
35 BIT1 = 0x0030,
36 BIT2 = 0x0031,
37 BIT3 = 0x0032,
38 BIT4 = 0x0033,
39 BIT5 = 0x0034,
40 BIT6 = 0x0035,
41 BIT7 = 0x0036,
42 BIT8 = 0x0037,
43 BIT9 = 0x0038,
44 BIT10 = 0x0039,
45 BIT11 = 0x003A,
46 BIT12 = 0x003B,
47 BIT13 = 0x003C,
48 BIT14 = 0x003D,
49 BIT15 = 0x003E,
50 BIT16 = 0x003F,
51
52 BITARR8 = 0x002D,
53 BITARR16 = 0x002E,
54 BITARR32 = 0x002F,
55
56 INTEGER8 = 0x0002,
57 INTEGER16 = 0x0003,
58 INTEGER24 = 0x0010,
59 INTEGER32 = 0x0004,
60 INTEGER40 = 0x0012,
61 INTEGER48 = 0x0013,
62 INTEGER56 = 0x0014,
63 INTEGER64 = 0x0015,
64
65 UNSIGNED8 = 0x0005,
66 UNSIGNED16 = 0x0006,
67 UNSIGNED24 = 0x0016,
68 UNSIGNED32 = 0x0007,
69 UNSIGNED40 = 0x0018,
70 UNSIGNED48 = 0x0019,
71 UNSIGNED56 = 0x001A,
72 UNSIGNED64 = 0x001B,
73
74 REAL32 = 0x0008,
75 REAL64 = 0x0011,
76
77 GUID = 0x001D,
78
79 VISIBLE_STRING = 0x0009,
80 OCTET_STRING = 0x000A,
81 // 0x000B is UNICODE_STRING per SOEM (ec_type.h) / CiA 301, which is what ecx_readOE and
82 // SOMANET drives actually report. ETG.1020 v1.6.0 instead lists 0x000B as ARRAY_OF_UINT and
83 // puts UNICODE_STRING at 0x0268 — we keep 0x000B for wire decoding and also catalogue the
84 // ETG.1020 code as WSTRING (below) so a spec-numbered device still decodes.
85 UNICODE_STRING = 0x000B,
86 WSTRING = 0x0268,
87
88 TIME_OF_DAY = 0x000C,
89 TIME_DIFFERENCE = 0x000D,
90 DOMAIN = 0x000F,
91
92 ARRAY_OF_INT = 0x0260,
93 ARRAY_OF_SINT = 0x0261,
94 ARRAY_OF_DINT = 0x0262,
95 ARRAY_OF_UDINT = 0x0263,
96 ARRAY_OF_BITARR8 = 0x0264,
97 ARRAY_OF_BITARR16 = 0x0265,
98 ARRAY_OF_BITARR32 = 0x0266,
99 ARRAY_OF_USINT = 0x0267,
100 ARRAY_OF_REAL = 0x0269,
101 ARRAY_OF_LREAL = 0x026A,
102
103 PDO_MAPPING = 0x0021,
104 IDENTITY = 0x0023,
105 COMMAND_PAR = 0x0025,
106 PDO_PARAMETER = 0x0027,
107 ENUM = 0x0028,
108 SM_SYNCHRONISATION = 0x0029,
109 RECORD = 0x002A,
110 BACKUP_PARAMETER = 0x002B,
111 MODULAR_DEVICE_PROFILE = 0x002C,
112
113 ERROR_SETTING = 0x0281,
114 DIAGNOSIS_HISTORY = 0x0282,
115 EXTERNAL_SYNC_STATUS = 0x0283,
116 EXTERNAL_SYNC_SETTINGS = 0x0284,
117 DEFTYPE_FSOEFRAME = 0x0285,
118 DEFTYPE_FSOECOMMPAR = 0x0286,
119
120 UTYPE_START = 0x0800,
121 UTYPE_END = 0x0FFF,
122};
123
126 uint16_t code = 0;
127 std::string_view name;
128 uint16_t bitSize = 0;
129};
130
135void to_json(nlohmann::json& j, const ObjectDataTypeInfo& info);
136
138inline constexpr auto kObjectDataTypes = std::to_array<ObjectDataTypeInfo>({
139 {0x0000, "UNSPECIFIED", 0},
140 {0x0001, "BOOLEAN", 1},
141 {0x0002, "INTEGER8", 8},
142 {0x0003, "INTEGER16", 16},
143 {0x0004, "INTEGER32", 32},
144 {0x0005, "UNSIGNED8", 8},
145 {0x0006, "UNSIGNED16", 16},
146 {0x0007, "UNSIGNED32", 32},
147 {0x0008, "REAL32", 32},
148 {0x0009, "VISIBLE_STRING", 0},
149 {0x000A, "OCTET_STRING", 0},
150 {0x000B, "UNICODE_STRING", 0},
151 {0x000C, "TIME_OF_DAY", 48},
152 {0x000D, "TIME_DIFFERENCE", 48},
153 {0x000F, "DOMAIN", 0},
154 {0x0010, "INTEGER24", 24},
155 {0x0011, "REAL64", 64},
156 {0x0012, "INTEGER40", 40},
157 {0x0013, "INTEGER48", 48},
158 {0x0014, "INTEGER56", 56},
159 {0x0015, "INTEGER64", 64},
160 {0x0016, "UNSIGNED24", 24},
161 {0x0018, "UNSIGNED40", 40},
162 {0x0019, "UNSIGNED48", 48},
163 {0x001A, "UNSIGNED56", 56},
164 {0x001B, "UNSIGNED64", 64},
165 {0x001D, "GUID", 128},
166 {0x001E, "BYTE", 8},
167 {0x001F, "WORD", 16},
168 {0x0020, "DWORD", 32},
169 {0x0021, "PDO_MAPPING", 0},
170 {0x0023, "IDENTITY", 0},
171 {0x0025, "COMMAND_PAR", 0},
172 {0x0027, "PDO_PARAMETER", 0},
173 {0x0028, "ENUM", 0},
174 {0x0029, "SM_SYNCHRONISATION", 0},
175 {0x002A, "RECORD", 0},
176 {0x002B, "BACKUP_PARAMETER", 0},
177 {0x002C, "MODULAR_DEVICE_PROFILE", 0},
178 {0x002D, "BITARR8", 8},
179 {0x002E, "BITARR16", 16},
180 {0x002F, "BITARR32", 32},
181 {0x0030, "BIT1", 1},
182 {0x0031, "BIT2", 2},
183 {0x0032, "BIT3", 3},
184 {0x0033, "BIT4", 4},
185 {0x0034, "BIT5", 5},
186 {0x0035, "BIT6", 6},
187 {0x0036, "BIT7", 7},
188 {0x0037, "BIT8", 8},
189 {0x0038, "BIT9", 9},
190 {0x0039, "BIT10", 10},
191 {0x003A, "BIT11", 11},
192 {0x003B, "BIT12", 12},
193 {0x003C, "BIT13", 13},
194 {0x003D, "BIT14", 14},
195 {0x003E, "BIT15", 15},
196 {0x003F, "BIT16", 16},
197 {0x0260, "ARRAY_OF_INT", 0},
198 {0x0261, "ARRAY_OF_SINT", 0},
199 {0x0262, "ARRAY_OF_DINT", 0},
200 {0x0263, "ARRAY_OF_UDINT", 0},
201 {0x0264, "ARRAY_OF_BITARR8", 0},
202 {0x0265, "ARRAY_OF_BITARR16", 0},
203 {0x0266, "ARRAY_OF_BITARR32", 0},
204 {0x0267, "ARRAY_OF_USINT", 0},
205 {0x0268, "WSTRING", 0},
206 {0x0269, "ARRAY_OF_REAL", 0},
207 {0x026A, "ARRAY_OF_LREAL", 0},
208 {0x0281, "ERROR_SETTING", 0},
209 {0x0282, "DIAGNOSIS_HISTORY", 0},
210 {0x0283, "EXTERNAL_SYNC_STATUS", 0},
211 {0x0284, "EXTERNAL_SYNC_SETTINGS", 0},
212 {0x0285, "DEFTYPE_FSOEFRAME", 0},
213 {0x0286, "DEFTYPE_FSOECOMMPAR", 0},
214});
215
217constexpr std::string_view objectDataTypeName(uint16_t code) {
218 const auto it = std::find_if(kObjectDataTypes.begin(), kObjectDataTypes.end(),
219 [code](const ObjectDataTypeInfo& e) { return e.code == code; });
220 return it != kObjectDataTypes.end() ? it->name : std::string_view{"UNKNOWN"};
221}
222
224constexpr uint16_t objectDataTypeBitSize(uint16_t code) {
225 const auto it = std::find_if(kObjectDataTypes.begin(), kObjectDataTypes.end(),
226 [code](const ObjectDataTypeInfo& e) { return e.code == code; });
227 return it != kObjectDataTypes.end() ? it->bitSize : uint16_t{0};
228}
229
230} // namespace mm::comm
Definition al_status_codes.cc:5
void to_json(nlohmann::json &j, const AlStatusCode &c)
Serialises an AlStatusCode to JSON.
Definition al_status_codes.cc:7
ObjectDataType
CoE object dictionary data type codes.
Definition object_data_types.h:27
@ UNSIGNED40
40-bit unsigned integer.
@ INTEGER16
16-bit signed integer.
@ UNICODE_STRING
UCS-2 string (SOEM/CiA numbering; see note above).
@ BACKUP_PARAMETER
Backup parameter (ETG.1020).
@ UNSPECIFIED
Undefined or unknown data type.
@ INTEGER64
64-bit signed integer.
@ ARRAY_OF_BITARR16
Sequence of BITARR16.
@ EXTERNAL_SYNC_STATUS
External sync status (ETG.1020).
@ ERROR_SETTING
Error setting (ETG.1020).
@ INTEGER32
32-bit signed integer.
@ ARRAY_OF_BITARR8
Sequence of BITARR8.
@ ARRAY_OF_INT
Sequence of INT (IEC 61131-3).
@ TIME_OF_DAY
Time of day (ETG.1020).
@ REAL32
32-bit IEEE 754 floating point.
@ UNSIGNED56
56-bit unsigned integer.
@ UNSIGNED8
8-bit unsigned integer.
@ ARRAY_OF_USINT
Sequence of USINT.
@ BITARR8
Array of 8 bits.
@ BITARR32
Array of 32 bits.
@ UNSIGNED64
64-bit unsigned integer.
@ MODULAR_DEVICE_PROFILE
Modular device profile (ETG.5001).
@ REAL64
64-bit IEEE 754 floating point.
@ DEFTYPE_FSOECOMMPAR
FSoE communication parameters (ETG.5120).
@ GUID
128-bit globally unique identifier.
@ INTEGER40
40-bit signed integer.
@ PDO_PARAMETER
PDO parameter (ETG.1020).
@ ENUM
Enumeration (ETG.1020).
@ EXTERNAL_SYNC_SETTINGS
External sync settings (ETG.1020).
@ UNSIGNED48
48-bit unsigned integer.
@ DWORD
32-bit unsigned integer.
@ UTYPE_END
End of user-defined type range.
@ ARRAY_OF_SINT
Sequence of SINT.
@ RECORD
Generic record structure.
@ UNSIGNED16
16-bit unsigned integer.
@ SM_SYNCHRONISATION
Sync manager synchronisation (ETG.1000).
@ ARRAY_OF_BITARR32
Sequence of BITARR32.
@ INTEGER48
48-bit signed integer.
@ ARRAY_OF_UDINT
Sequence of UDINT.
@ INTEGER56
56-bit signed integer.
@ DEFTYPE_FSOEFRAME
FSoE frame (ETG.5120).
@ BITARR16
Array of 16 bits.
@ VISIBLE_STRING
Null-terminated ASCII string.
@ WORD
16-bit unsigned integer.
@ ARRAY_OF_REAL
Sequence of REAL.
@ DOMAIN
Application-specific domain (ETG.1020).
@ BOOLEAN
Boolean value (true or false), transported as a byte.
@ UNSIGNED32
32-bit unsigned integer.
@ DIAGNOSIS_HISTORY
Diagnosis history (ETG.1020).
@ INTEGER24
24-bit signed integer.
@ ARRAY_OF_DINT
Sequence of DINT.
@ WSTRING
UCS-2/wide string — ETG.1020's UNICODE_STRING code (cf. 0x000B).
@ COMMAND_PAR
Command parameter (ETG.1000).
@ IDENTITY
Identity object (ETG.1000).
@ TIME_DIFFERENCE
Time difference (ETG.1020).
@ BYTE
8-bit unsigned integer.
@ PDO_MAPPING
PDO mapping (ETG.1000).
@ ARRAY_OF_LREAL
Sequence of LREAL.
@ UNSIGNED24
24-bit unsigned integer.
@ OCTET_STRING
Variable-length byte array.
@ INTEGER8
8-bit signed integer.
@ UTYPE_START
Start of user-defined type range.
constexpr uint16_t objectDataTypeBitSize(uint16_t code)
Returns the declared bit width of code, or 0 if unknown / variable-length.
Definition object_data_types.h:224
constexpr auto kObjectDataTypes
Catalogue of ETG.1020 object dictionary data types.
Definition object_data_types.h:138
constexpr std::string_view objectDataTypeName(uint16_t code)
Returns the symbolic name of code, or "UNKNOWN" if it is not in the table.
Definition object_data_types.h:217
Metadata for a single object dictionary data type.
Definition object_data_types.h:125
std::string_view name
Symbolic name (e.g. "UNSIGNED32").
Definition object_data_types.h:127
uint16_t code
ETG.1020 data type code.
Definition object_data_types.h:126
uint16_t bitSize
Bit width of one element; 0 for variable-length types.
Definition object_data_types.h:128