MIP_SDK  v3.0.0-187-g93c7302
MicroStrain Communications Library for embedded systems
common.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
7 
8 namespace mip::metadata
9 {
10 
11 template<>
13 {
14  using type = CmdResult;
15 
16  static constexpr inline EnumInfo::Entry entries[] = {
17  {
18  /*.value =*/ CmdResult::ACK_OK,
19  /*.name =*/ "OK",
20  /*.docs =*/ "Command completed successfully",
21  },
22  {
24  /*.name =*/ "Unknown Command",
25  /*.docs =*/ "The device did not recognize the command",
26  },
27  {
29  /*.name =*/ "Invalid Checksum",
30  /*.docs =*/ "An packet with an invalid checksum was received by the device",
31  },
32  {
33  /*.value =*/ CmdResult::NACK_INVALID_PARAM,
34  /*.name =*/ "Invalid Parameter",
35  /*.docs =*/ "One or more parameters to the command were not valid",
36  },
37  {
38  /*.value =*/ CmdResult::NACK_COMMAND_FAILED,
39  /*.name =*/ "Command Failed",
40  /*.docs =*/ "The device could not complete the command",
41  },
42  {
44  /*.name =*/ "Device Timeout",
45  /*.docs =*/ "The device reported a timeout condition",
46  },
47  // Status codes not represented here as they don't come from the device.
48  };
49 
50  static constexpr inline EnumInfo value = {
51  /*.name =*/ "CmdResult",
52  /*.docs =*/ "Acknowledgement/reply code from the device after a command is issued",
53  /*.type =*/ Type::U8,
54  /*.entries =*/ entries,
55  };
56 };
57 
58 struct ReplyField
59 {
60  static constexpr inline uint8_t FIELD_DESCRIPTOR = 0xF1;
61  static constexpr inline CompositeDescriptor DESCRIPTOR = {INVALID_DESCRIPTOR_SET, FIELD_DESCRIPTOR};
62 
63  uint8_t cmd_field_desc;
65 
66  size_t insert(Serializer& buffer) const { return buffer.insert(cmd_field_desc, result.value); }
67  size_t extract(Serializer& buffer) { return buffer.extract(cmd_field_desc, result.value); }
68 };
69 
70 template<>
72 {
73  using type = ReplyField;
74 
75  static constexpr inline ParameterInfo parameters[] = {
76  {
77  /*.name =*/ "cmd_field_desc",
78  /*.docs =*/ "The field descriptor of the command this field acknowledges.",
79  /*.type =*/ {Type::U8},
80  /*.accessor =*/ nullptr, //utils::access<type, uint8_t, &type::cmd_field_desc>,
81  /*.attributes =*/ NO_FUNCTIONS,
82  /*.count =*/ 1,
83  /*.condition =*/ {},
84  },
85  {
86  /*.name =*/ "result",
87  /*.docs =*/ "Result of the command.",
89  /*.accessor =*/ nullptr, //utils::access<type, CmdResult, &type::result>,
90  /*.attributes =*/ NO_FUNCTIONS,
91  /*.count =*/ 1,
92  /*.condition =*/ {},
93  },
94  };
95 
96  static constexpr inline FieldInfo value = {
97  /*.name = */ "ReplyField",
98  /* .title = */ "Command Reply",
99  /* .docs = */ "Sent by the device to indicate the result of a command.",
100  /* .parameters = */ parameters,
101  /* .descriptor = */ type::DESCRIPTOR,
102  /* .functions = */ NO_FUNCTIONS,
103  /* .response = */ nullptr,
104  };
105 };
106 
107 template<>
109 {
111 
112  static constexpr inline ParameterInfo parameters[] = {
113  {
114  /*.name =*/ "descriptor",
115  /*.docs =*/ "MIP data descriptor",
116  /*.type =*/ {Type::U8},
117  /*.accessor =*/ nullptr, //utils::access<type, uint8_t, &type::descriptor>,
118  /*.attributes =*/ NO_FUNCTIONS,
119  /*.count =*/ 1,
120  /*.condition =*/ {},
121  },
122  {
123  /*.name =*/ "decimation",
124  /*.docs =*/ "Decimation from the base rate",
125  /*.type =*/ {Type::U16},
126  /*.accessor =*/ nullptr, //utils::access<type, uint16_t, &type::decimation>,
127  /*.attributes =*/ NO_FUNCTIONS,
128  /*.count =*/ 1,
129  /*.condition =*/ {},
130  },
131  };
132 
133  static constexpr inline StructInfo value = {
134  /*.name =*/ "DescriptorRate",
135  /*.title =*/ "Descriptor Rate",
136  /*.docs =*/ "Descriptor rate information",
137  /*.parameters =*/ parameters,
138  };
139 };
140 
141 
142 template<typename T, size_t N>
143 struct MetadataFor<Vector<T,N>>
144 {
145  using type = Vector<T,N>;
146 
147  static constexpr inline ParameterInfo parameters_v[] = {
148  {
149  /*.name =*/ "x",
150  /*.docs =*/ "X axis",
151  /*.type =*/ {utils::ParamType<T>::value},
152  /*.accessor =*/ nullptr,
153  /*.attributes =*/ NO_FUNCTIONS,
154  /*.count =*/ 1,
155  /*.condition =*/ {},
156  },
157  {
158  /*.name =*/ "y",
159  /*.docs =*/ "Y axis",
160  /*.type =*/ {utils::ParamType<T>::value},
161  /*.accessor =*/ nullptr,
162  /*.attributes =*/ NO_FUNCTIONS,
163  /*.count =*/ 1,
164  /*.condition =*/ {},
165  },
166  {
167  /*.name =*/ "z",
168  /*.docs =*/ "Z axis",
169  /*.type =*/ {utils::ParamType<T>::value},
170  /*.accessor =*/ nullptr,
171  /*.attributes =*/ NO_FUNCTIONS,
172  /*.count =*/ 1,
173  /*.condition =*/ {},
174  },
175  {
176  /*.name =*/ "w",
177  /*.docs =*/ "W axis",
178  /*.type =*/ {utils::ParamType<T>::value},
179  /*.accessor =*/ nullptr,
180  /*.attributes =*/ NO_FUNCTIONS,
181  /*.count =*/ 1,
182  /*.condition =*/ {},
183  },
184  };
185 
186  static constexpr inline StructInfo vector_f[3] = {
187  {
188  /*.name =*/ "Vector2f",
189  /*.title =*/ "Vector2f",
190  /*.docs =*/ "2-dimensional vector of floats",
191  /*.parameters =*/ {parameters_v, 2}
192  },
193  {
194  /*.name =*/ "Vector3f",
195  /*.title =*/ "Vector3f",
196  /*.docs =*/ "3-dimensional vector of floats",
197  /*.parameters =*/ {parameters_v, 3}
198  },
199  {
200  /*.name =*/ "Vector4f",
201  /*.title =*/ "Vector4f",
202  /*.docs =*/ "4-dimensional vector of floats",
203  /*.parameters =*/ {parameters_v, 4}
204  },
205  };
206 
207  static constexpr inline StructInfo vector_d[3] = {
208  {
209  /*.name =*/ "Vector2d",
210  /*.title =*/ "Vector2d",
211  /*.docs =*/ "2-dimensional vector of doubles",
212  /*.parameters =*/ {parameters_v, 2}
213  },
214  {
215  /*.name =*/ "Vector3d",
216  /*.title =*/ "Vector3d",
217  /*.docs =*/ "3-dimensional vector of doubles",
218  /*.parameters =*/ {parameters_v, 3}
219  },
220  {
221  /*.name =*/ "Vector4d",
222  /*.title =*/ "Vector4d",
223  /*.docs =*/ "4-dimensional vector of doubles",
224  /*.parameters =*/ {parameters_v, 4}
225  },
226  };
227 
228  static constexpr inline ParameterInfo parameters_m[] = {
229  {
230  /*.name =*/ "m[0]",
231  /*.docs =*/ "Matrix data",
232  /*.type =*/ {utils::ParamType<T>::value},
233  /*.accessor =*/ nullptr,
234  /*.attributes =*/ NO_FUNCTIONS,
235  /*.count =*/ 1,
236  /*.condition =*/ {},
237  },
238  {
239  /*.name =*/ "m[1]",
240  /*.docs =*/ "Matrix data",
241  /*.type =*/ {utils::ParamType<T>::value},
242  /*.accessor =*/ nullptr,
243  /*.attributes =*/ NO_FUNCTIONS,
244  /*.count =*/ 1,
245  /*.condition =*/ {},
246  },
247  {
248  /*.name =*/ "m[2]",
249  /*.docs =*/ "Matrix data",
250  /*.type =*/ {utils::ParamType<T>::value},
251  /*.accessor =*/ nullptr,
252  /*.attributes =*/ NO_FUNCTIONS,
253  /*.count =*/ 1,
254  /*.condition =*/ {},
255  },
256  {
257  /*.name =*/ "m[3]",
258  /*.docs =*/ "Matrix data",
259  /*.type =*/ {utils::ParamType<T>::value},
260  /*.accessor =*/ nullptr,
261  /*.attributes =*/ NO_FUNCTIONS,
262  /*.count =*/ 1,
263  /*.condition =*/ {},
264  },
265  {
266  /*.name =*/ "m[4]",
267  /*.docs =*/ "Matrix data",
268  /*.type =*/ {utils::ParamType<T>::value},
269  /*.accessor =*/ nullptr,
270  /*.attributes =*/ NO_FUNCTIONS,
271  /*.count =*/ 1,
272  /*.condition =*/ {},
273  },
274  {
275  /*.name =*/ "m[5]",
276  /*.docs =*/ "Matrix data",
277  /*.type =*/ {utils::ParamType<T>::value},
278  /*.accessor =*/ nullptr,
279  /*.attributes =*/ NO_FUNCTIONS,
280  /*.count =*/ 1,
281  /*.condition =*/ {},
282  },
283  {
284  /*.name =*/ "m[6]",
285  /*.docs =*/ "Matrix data",
286  /*.type =*/ {utils::ParamType<T>::value},
287  /*.accessor =*/ nullptr,
288  /*.attributes =*/ NO_FUNCTIONS,
289  /*.count =*/ 1,
290  /*.condition =*/ {},
291  },
292  {
293  /*.name =*/ "m[7]",
294  /*.docs =*/ "Matrix data",
295  /*.type =*/ {utils::ParamType<T>::value},
296  /*.accessor =*/ nullptr,
297  /*.attributes =*/ NO_FUNCTIONS,
298  /*.count =*/ 1,
299  /*.condition =*/ {},
300  },
301  {
302  /*.name =*/ "m[8]",
303  /*.docs =*/ "Matrix data",
304  /*.type =*/ {utils::ParamType<T>::value},
305  /*.accessor =*/ nullptr,
306  /*.attributes =*/ NO_FUNCTIONS,
307  /*.count =*/ 1,
308  /*.condition =*/ {},
309  },
310  };
311 
312  static constexpr inline StructInfo matrix_f = {
313  /*.name =*/ "Matrix3d",
314  /*.title =*/ "3x3 Double Matrix",
315  /*.docs =*/ "Represents a 3D matrix of doubles.",
316  /*.parameters =*/ parameters_m,
317  };
318 
319  static constexpr inline StructInfo matrix_d = {
320  /*.name =*/ "Matrix3f",
321  /*.title =*/ "3x3 Float Matrix",
322  /*.docs =*/ "Represents a 3D matrix of floats.",
323  /*.parameters =*/ parameters_m,
324  };
325 
326  static_assert(std::is_floating_point<T>::value, "Expected either float or double");
327  static_assert(N == 9 || (N >= 2 && N <= 4), "N should be in the range [2,4] or exactly 9.");
328 
329  static constexpr inline const StructInfo& value =
330  N == 9 ? (std::is_same<T,double>::value ? matrix_d : matrix_f) :
331  (std::is_same<T,double>::value ? vector_d[N - 2] : vector_f[N - 2]);
332 };
333 
334 } // namespace mip::metadata
mip::metadata::ReplyField::insert
size_t insert(Serializer &buffer) const
Definition: common.hpp:66
mip::metadata::Type::ENUM
@ ENUM
microstrain::Serializer
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:125
mip::CmdResult::NACK_INVALID_CHECKSUM
static constexpr C::mip_cmd_result NACK_INVALID_CHECKSUM
Reserved.
Definition: mip_result.hpp:36
mip::metadata
Definition: commands_3dm.hpp:10
mip::metadata::ReplyField
Definition: common.hpp:58
mip::CmdResult::NACK_INVALID_PARAM
static constexpr C::mip_cmd_result NACK_INVALID_PARAM
A parameter was not a supported value.
Definition: mip_result.hpp:37
mip::metadata::ReplyField::extract
size_t extract(Serializer &buffer)
Definition: common.hpp:67
mip::Vector
Vector is a wrapper around an array of some type T, usually float or double.
Definition: common.hpp:42
mip::metadata::Type::U16
@ U16
mip::metadata::MetadataFor
Definition: mip_metadata.hpp:15
mip::metadata::ReplyField::cmd_field_desc
uint8_t cmd_field_desc
Definition: common.hpp:63
mip::metadata::ParameterInfo
Definition: mip_structures.hpp:161
microstrain::Serializer::extract
bool extract(Ts &... values)
Deserializes one or more values.
Definition: serializer.hpp:949
mip::metadata::EnumInfo::Entry
Definition: mip_structures.hpp:67
mip::metadata::ReplyField::DESCRIPTOR
static constexpr CompositeDescriptor DESCRIPTOR
Definition: common.hpp:61
mip::metadata::utils::ParamType
Definition: mip_meta_utils.hpp:12
mip::metadata::ReplyField::FIELD_DESCRIPTOR
static constexpr uint8_t FIELD_DESCRIPTOR
Definition: common.hpp:60
mip_metadata.hpp
mip::CmdResult
Represents the status of a MIP command.
Definition: mip_result.hpp:24
mip::metadata::ReplyField::result
CmdResult result
Definition: common.hpp:64
mip::CmdResult::NACK_COMMAND_UNKNOWN
static constexpr C::mip_cmd_result NACK_COMMAND_UNKNOWN
Command not supported.
Definition: mip_result.hpp:35
mip::DescriptorRate
Definition: common.hpp:25
mip::metadata::FieldInfo
Definition: mip_structures.hpp:216
mip::metadata::Type::U8
@ U8
mip::CmdResult::ACK_OK
static constexpr C::mip_cmd_result ACK_OK
Command completed successfully.
Definition: mip_result.hpp:34
mip_meta_utils.hpp
mip::metadata::EnumInfo
Definition: mip_structures.hpp:65
mip::CmdResult::value
C::mip_cmd_result value
Definition: mip_result.hpp:45
mip::CompositeDescriptor
Convenience struct holding both descriptor set and field descriptor.
Definition: mip_descriptors.hpp:21
mip::CmdResult::NACK_COMMAND_TIMEOUT
static constexpr C::mip_cmd_result NACK_COMMAND_TIMEOUT
Internal device timeout. Use MIP_STATUS_TIMEDOUT for command timeouts.
Definition: mip_result.hpp:39
mip::metadata::StructInfo
Definition: mip_structures.hpp:205
microstrain::Serializer::insert
bool insert(const Ts &... values)
Serializes one or more values.
Definition: serializer.hpp:923
common.hpp
mip::CmdResult::NACK_COMMAND_FAILED
static constexpr C::mip_cmd_result NACK_COMMAND_FAILED
The device could not complete the command.
Definition: mip_result.hpp:38