MIP_SDK  latest-2-g34f3e39
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[] = {
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 
187  static constexpr inline StructInfo values_f[3] = {
188  {
189  /*.name =*/ "Vector2f",
190  /*.title =*/ "Vector2f",
191  /*.docs =*/ "2-dimensional vector of floats",
192  /*.parameters =*/ {parameters, 2}
193  },
194  {
195  /*.name =*/ "Vector3f",
196  /*.title =*/ "Vector3f",
197  /*.docs =*/ "3-dimensional vector of floats",
198  /*.parameters =*/ {parameters, 3}
199  },
200  {
201  /*.name =*/ "Vector4f",
202  /*.title =*/ "Vector4f",
203  /*.docs =*/ "4-dimensional vector of floats",
204  /*.parameters =*/ {parameters, 4}
205  },
206  };
207  static constexpr inline StructInfo values_d[3] = {
208  {
209  /*.name =*/ "Vector2d",
210  /*.title =*/ "Vector2d",
211  /*.docs =*/ "2-dimensional vector of doubles",
212  /*.parameters =*/ {parameters, 2}
213  },
214  {
215  /*.name =*/ "Vector3d",
216  /*.title =*/ "Vector3d",
217  /*.docs =*/ "3-dimensional vector of doubles",
218  /*.parameters =*/ {parameters, 3}
219  },
220  {
221  /*.name =*/ "Vector4d",
222  /*.title =*/ "Vector4d",
223  /*.docs =*/ "4-dimensional vector of doubles",
224  /*.parameters =*/ {parameters, 4}
225  },
226  };
227 
228  static_assert(std::is_floating_point<T>::value, "Expected either float or double");
229  static_assert(N >= 2 && N <= 4, "N should be in the range [2,4].");
230 
231  static constexpr inline const StructInfo& value = std::is_same<T,double>::value ? values_d[N-2] : values_f[N-2];
232 };
233 
234 
235 template<>
237 {
238  using type = Matrix3f;
239 
240  static constexpr inline ParameterInfo parameters[] = {
241  {
242  /*.name =*/ "m",
243  /*.docs =*/ "Matrix data",
244  /*.type =*/ {Type::FLOAT},
245  /*.accessor =*/ nullptr,
246  /*.attributes =*/ NO_FUNCTIONS,
247  /*.count =*/ 3,
248  /*.condition =*/ {},
249  },
250  };
251 
252  static constexpr inline StructInfo value = {
253  /*.name =*/ "Matrix3f",
254  /*.title =*/ "3x3 Float Matrix",
255  /*.docs =*/ "Represents a 3D matrix of floats.",
256  /*.parameters =*/ parameters,
257  };
258 };
259 
260 template<>
262 {
263  using type = Matrix3d;
264 
265  static constexpr inline ParameterInfo parameters[] = {
266  {
267  /*.name =*/ "m",
268  /*.docs =*/ "Matrix data",
269  /*.type =*/ {Type::DOUBLE},
270  /*.accessor =*/ nullptr,
271  /*.attributes =*/ NO_FUNCTIONS,
272  /*.count =*/ 3,
273  /*.condition =*/ {},
274  },
275  };
276 
277  static constexpr inline StructInfo value = {
278  /*.name =*/ "Matrix3f",
279  /*.title =*/ "3x3 Double Matrix",
280  /*.docs =*/ "Represents a 3D matrix of doubles.",
281  /*.parameters =*/ parameters,
282  };
283 };
284 
285 } // 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::Type::DOUBLE
@ DOUBLE
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::Type::FLOAT
@ FLOAT
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::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: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
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