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