MIP_SDK  v3.0.0-208-gdb90bae
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  template<>
12  {
13  using type = CmdResult;
14 
15  static constexpr inline EnumInfo::Entry entries[] = {
16  {
17  /* .value = */ CmdResult::ACK_OK,
18  /* .name = */ "OK",
19  /* .docs = */ "Command completed successfully",
20  },
21  {
22  /* .value = */ CmdResult::NACK_COMMAND_UNKNOWN,
23  /* .name = */ "Unknown Command",
24  /* .docs = */ "The device did not recognize the command",
25  },
26  {
27  /* .value = */ CmdResult::NACK_INVALID_CHECKSUM,
28  /* .name = */ "Invalid Checksum",
29  /* .docs = */ "An packet with an invalid checksum was received by the device",
30  },
31  {
32  /* .value = */ CmdResult::NACK_INVALID_PARAM,
33  /* .name = */ "Invalid Parameter",
34  /* .docs = */ "One or more parameters to the command were not valid",
35  },
36  {
37  /* .value = */ CmdResult::NACK_COMMAND_FAILED,
38  /* .name = */ "Command Failed",
39  /* .docs = */ "The device could not complete the command",
40  },
41  {
42  /* .value = */ CmdResult::NACK_COMMAND_TIMEOUT,
43  /* .name = */ "Device Timeout",
44  /* .docs = */ "The device reported a timeout condition",
45  },
46  // Status codes not represented here as they don't come from the device.
47  };
48 
49  static constexpr inline EnumInfo value = {
50  /* .name = */ "CmdResult",
51  /* .docs = */ "Acknowledgement/reply code from the device after a command is issued",
52  /* .type = */ Type::U8,
53  /* .entries = */ entries,
54  };
55  };
56 
57  struct ReplyField
58  {
59  static constexpr inline uint8_t FIELD_DESCRIPTOR = 0xF1;
60  static constexpr inline CompositeDescriptor DESCRIPTOR = {INVALID_DESCRIPTOR_SET, FIELD_DESCRIPTOR};
61 
62  uint8_t cmd_field_desc;
64 
65  size_t insert(Serializer& buffer) const { return buffer.insert(cmd_field_desc, result.value); }
66  size_t extract(Serializer& buffer) { return buffer.extract(cmd_field_desc, result.value); }
67  };
68 
69  template<>
71  {
72  using type = ReplyField;
73 
74  static constexpr inline ParameterInfo parameters[] = {
75  {
76  /* .name = */ "cmd_field_desc",
77  /* .docs = */ "The field descriptor of the command this field acknowledges.",
78  /* .type = */ {Type::U8},
79  /* .accessor = */ nullptr, //utils::access<type, uint8_t, &type::cmd_field_desc>,
80  /* .attributes = */ NO_FUNCTIONS,
81  /* .count = */ 1,
82  /* .condition = */ {},
83  },
84  {
85  /* .name = */ "result",
86  /* .docs = */ "Result of the command.",
87  /* .type = */ {Type::ENUM, &MetadataFor<CmdResult>::value},
88  /* .accessor = */ nullptr, //utils::access<type, CmdResult, &type::result>,
89  /* .attributes = */ NO_FUNCTIONS,
90  /* .count = */ 1,
91  /* .condition = */ {},
92  },
93  };
94 
95  static constexpr inline FieldInfo value = {{
96  /* .name = */ "ReplyField",
97  /* .title = */ "Command Reply",
98  /* .docs = */ "Sent by the device to indicate the result of a command.",
99  /* .parameters = */ parameters,
100  },
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 } // namespace mip::metadata
mip::metadata::ReplyField::insert
size_t insert(Serializer &buffer) const
Definition: common.hpp:65
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: common.hpp:8
mip::metadata::ReplyField
Definition: common.hpp:57
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:66
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:13
mip::metadata::ReplyField::cmd_field_desc
uint8_t cmd_field_desc
Definition: common.hpp:62
mip::metadata::ParameterInfo
Definition: mip_structures.hpp:158
microstrain::Serializer::extract
bool extract(Ts &... values)
Deserializes one or more values.
Definition: serializer.hpp:949
mip::metadata::EnumInfo::Entry
Definition: mip_structures.hpp:65
mip::metadata::ReplyField::DESCRIPTOR
static constexpr CompositeDescriptor DESCRIPTOR
Definition: common.hpp:60
mip::metadata::utils::ParamType
Definition: mip_meta_utils.hpp:10
mip::metadata::ReplyField::FIELD_DESCRIPTOR
static constexpr uint8_t FIELD_DESCRIPTOR
Definition: common.hpp:59
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:63
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:212
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:63
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:201
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