MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
mip_descriptors.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_result.hpp"
4 #include "mip_serialization.hpp"
5 
6 #include <mip/mip_descriptors.h>
7 
8 #include <functional>
9 #include <tuple>
10 #include <type_traits>
11 
12 namespace mip
13 {
17 
22  {
23  uint8_t descriptorSet;
24  uint8_t fieldDescriptor;
25 
26  constexpr CompositeDescriptor(uint8_t descSet, uint8_t fieldDesc) : descriptorSet(descSet), fieldDescriptor(fieldDesc) {}
27  constexpr CompositeDescriptor(uint16_t combo) : descriptorSet(combo >> 8), fieldDescriptor(combo & 0xFF) {}
28 
29  CompositeDescriptor& operator=(uint16_t combo) { return *this = CompositeDescriptor(combo); }
30 
31  constexpr uint16_t as_u16() const { return (uint16_t(descriptorSet) << 8) | fieldDescriptor; }
32 
33  // operator uint16_t() const { return as_u16(); }
34 
35  constexpr bool operator==(const CompositeDescriptor& other) const { return other.descriptorSet == descriptorSet && other.fieldDescriptor == fieldDescriptor; }
36  constexpr bool operator<(const CompositeDescriptor& other) const { return as_u16() < other.as_u16(); }
37 
38  };
39 
40 
41  // All MIP command/data fields should inherit this struct.
42  struct FieldStruct
43  {
44  // static_assert(std::is_base_of<FieldStruct<T>, T>::value, "T must inherit from FieldStruct<T>");
45 
46  private:
47  // No direct instantiation,
48  // this class must be inherited.
49  FieldStruct() = default;
50  };
51 
52  template<class T>
53  using isField = std::is_base_of<FieldStruct, T>;
54 
55  template<class T>
56  using EnableForFieldTypes = std::enable_if<isField<T>::value, T>;
57 
61  template<typename DerivedT> struct Bitfield {};
62 
63  template<class Derived> size_t insert (Serializer& serializer, const Bitfield<Derived>& bitfield) { return insert(serializer, static_cast<const Derived&>(bitfield).value); }
64  template<class Derived> size_t extract(Serializer& serializer, Bitfield<Derived>& bitfield) { return extract(serializer, static_cast<Derived&>(bitfield).value); }
65 
66  enum class FunctionSelector : uint8_t
67  {
73  };
74 
75  static constexpr uint8_t INVALID_FIELD_DESCRIPTOR = C::MIP_INVALID_FIELD_DESCRIPTOR;
76  static constexpr uint8_t INVALID_DESCRIPTOR_SET = C::MIP_INVALID_DESCRIPTOR_SET;
77 
78  inline bool isValidDescriptorSet (uint8_t descriptorSet) { return C::mip_is_valid_descriptor_set(descriptorSet); }
79  inline bool isDataDescriptorSet (uint8_t descriptorSet) { return C::mip_is_data_descriptor_set(descriptorSet); }
80  inline bool isCommandDescriptorSet (uint8_t descriptorSet) { return C::mip_is_cmd_descriptor_set(descriptorSet); }
81  inline bool isReservedDescriptorSet(uint8_t descriptorSet) { return C::mip_is_reserved_descriptor_set(descriptorSet); }
82  inline bool isGnssDataDescriptorSet(uint8_t descriptorSet) { return C::mip_is_gnss_data_descriptor_set(descriptorSet); }
83 
84  inline bool isValidFieldDescriptor (uint8_t fieldDescriptor) { return C::mip_is_valid_field_descriptor(fieldDescriptor); }
85  inline bool isCommandFieldDescriptor (uint8_t fieldDescriptor) { return C::mip_is_cmd_field_descriptor(fieldDescriptor); }
86  inline bool isReplyFieldDescriptor (uint8_t fieldDescriptor) { return C::mip_is_reply_field_descriptor(fieldDescriptor); }
87  inline bool isResponseFieldDescriptor(uint8_t fieldDescriptor) { return C::mip_is_response_field_descriptor(fieldDescriptor); }
88  inline bool isReservedFieldDescriptor(uint8_t fieldDescriptor) { return C::mip_is_reserved_cmd_field_descriptor(fieldDescriptor); }
89  inline bool isSharedDataFieldDescriptor(uint8_t fieldDescriptor) { return C::mip_is_shared_data_field_descriptor(fieldDescriptor); }
90 
96  template<class MipCmd>
97  struct TypedResult : public CmdResult
98  {
99  using Cmd = MipCmd;
100 
101  // Same constructor as CmdResult.
102  using CmdResult::CmdResult;
103  TypedResult(CmdResult existing) : CmdResult(existing) {}
104 
108  static constexpr CompositeDescriptor DESCRIPTOR = MipCmd::DESCRIPTOR;
109 
113  constexpr CompositeDescriptor descriptor() const { return DESCRIPTOR; }
114  };
115 
118 } // namespace mip
mip::FunctionSelector::READ
@ READ
mip::isCommandDescriptorSet
bool isCommandDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:80
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::CompositeDescriptor::descriptorSet
uint8_t descriptorSet
MIP descriptor set.
Definition: mip_descriptors.hpp:23
mip::C::MIP_FUNCTION_READ
@ MIP_FUNCTION_READ
Definition: mip_descriptors.h:45
mip::C::mip_is_gnss_data_descriptor_set
bool mip_is_gnss_data_descriptor_set(uint8_t descriptor_set)
Determines if the descriptor set represents some kind of GNSS data.
Definition: mip_descriptors.c:70
mip::CompositeDescriptor::operator=
CompositeDescriptor & operator=(uint16_t combo)
Definition: mip_descriptors.hpp:29
microstrain::Serializer
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:125
mip::CompositeDescriptor::CompositeDescriptor
constexpr CompositeDescriptor(uint16_t combo)
Definition: mip_descriptors.hpp:27
mip::C::mip_is_data_descriptor_set
bool mip_is_data_descriptor_set(uint8_t descriptor_set)
Determines if the descriptor set represents some kind of data.
Definition: mip_descriptors.c:34
mip::FunctionSelector::RESET
@ RESET
mip::isSharedDataFieldDescriptor
bool isSharedDataFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:89
mip::CompositeDescriptor::operator<
constexpr bool operator<(const CompositeDescriptor &other) const
Definition: mip_descriptors.hpp:36
mip::isGnssDataDescriptorSet
bool isGnssDataDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:82
mip::FunctionSelector::SAVE
@ SAVE
mip::isCommandFieldDescriptor
bool isCommandFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:85
mip::TypedResult::DESCRIPTOR
static constexpr CompositeDescriptor DESCRIPTOR
The command descriptor.
Definition: mip_descriptors.hpp:108
mip::EnableForFieldTypes
std::enable_if< isField< T >::value, T > EnableForFieldTypes
Definition: mip_descriptors.hpp:56
mip::isDataDescriptorSet
bool isDataDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:79
mip::isValidFieldDescriptor
bool isValidFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:84
mip::FunctionSelector::LOAD
@ LOAD
mip::CompositeDescriptor::operator==
constexpr bool operator==(const CompositeDescriptor &other) const
Definition: mip_descriptors.hpp:35
mip::TypedResult::descriptor
constexpr CompositeDescriptor descriptor() const
Returns the composite descriptor of the command.
Definition: mip_descriptors.hpp:113
mip::insert
size_t insert(Serializer &serializer, const Vector< T, N > &v)
Definition: common.hpp:130
mip::C::MIP_FUNCTION_RESET
@ MIP_FUNCTION_RESET
Definition: mip_descriptors.h:48
mip::FunctionSelector
FunctionSelector
Definition: mip_descriptors.hpp:66
mip::CmdResult
Represents the status of a MIP command.
Definition: mip_result.hpp:24
mip::FieldStruct
Definition: mip_descriptors.hpp:42
mip::TypedResult::TypedResult
TypedResult(CmdResult existing)
Definition: mip_descriptors.hpp:103
mip::isResponseFieldDescriptor
bool isResponseFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:87
mip::C::mip_is_reserved_cmd_field_descriptor
bool mip_is_reserved_cmd_field_descriptor(uint8_t field_descriptor)
Determines if the field descriptor is reserved.
Definition: mip_descriptors.c:137
mip::TypedResult::Cmd
MipCmd Cmd
Definition: mip_descriptors.hpp:99
mip::isValidDescriptorSet
bool isValidDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:78
mip::C::MIP_FUNCTION_LOAD
@ MIP_FUNCTION_LOAD
Definition: mip_descriptors.h:47
mip::isReplyFieldDescriptor
bool isReplyFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:86
mip::C::mip_is_reply_field_descriptor
bool mip_is_reply_field_descriptor(uint8_t field_descriptor)
Determines if the field descriptor is for an ack/nack reply.
Definition: mip_descriptors.c:108
mip::C::MIP_INVALID_FIELD_DESCRIPTOR
@ MIP_INVALID_FIELD_DESCRIPTOR
Definition: mip_descriptors.h:21
mip::C::MIP_INVALID_DESCRIPTOR_SET
@ MIP_INVALID_DESCRIPTOR_SET
Definition: mip_descriptors.h:17
mip::FunctionSelector::WRITE
@ WRITE
mip::C::MIP_FUNCTION_SAVE
@ MIP_FUNCTION_SAVE
Definition: mip_descriptors.h:46
mip::C::MIP_FUNCTION_WRITE
@ MIP_FUNCTION_WRITE
Definition: mip_descriptors.h:44
mip::C::mip_is_reserved_descriptor_set
bool mip_is_reserved_descriptor_set(uint8_t descriptor_set)
Determines if the descriptor is reserved for special purposes.
Definition: mip_descriptors.c:58
mip_descriptors.h
mip::C::mip_is_valid_field_descriptor
bool mip_is_valid_field_descriptor(uint8_t field_descriptor)
Determines if the field descriptor is valid.
Definition: mip_descriptors.c:84
mip::CompositeDescriptor::CompositeDescriptor
constexpr CompositeDescriptor(uint8_t descSet, uint8_t fieldDesc)
Definition: mip_descriptors.hpp:26
mip::C::mip_is_valid_descriptor_set
bool mip_is_valid_descriptor_set(uint8_t descriptor_set)
Determines if the descriptor set is valid.
Definition: mip_descriptors.c:22
mip::CompositeDescriptor::as_u16
constexpr uint16_t as_u16() const
Definition: mip_descriptors.hpp:31
mip::CompositeDescriptor::fieldDescriptor
uint8_t fieldDescriptor
MIP field descriptor.
Definition: mip_descriptors.hpp:24
mip::C::mip_is_response_field_descriptor
bool mip_is_response_field_descriptor(uint8_t field_descriptor)
Determines if the field descriptor contains response data from a command.
Definition: mip_descriptors.c:123
mip::CompositeDescriptor
Convenience struct holding both descriptor set and field descriptor.
Definition: mip_descriptors.hpp:21
mip::isReservedFieldDescriptor
bool isReservedFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:88
mip_serialization.hpp
mip::C::mip_is_shared_data_field_descriptor
bool mip_is_shared_data_field_descriptor(uint8_t field_descriptor)
Determines if the field descriptor is from the shared data set.
Definition: mip_descriptors.c:151
mip::isReservedDescriptorSet
bool isReservedDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:81
mip::isField
std::is_base_of< FieldStruct, T > isField
Definition: mip_descriptors.hpp:53
mip::Bitfield
A dummy struct which is used to mark bitfield objects.
Definition: mip_descriptors.hpp:61
mip::CmdResult::CmdResult
constexpr CmdResult()
Definition: mip_result.hpp:47
mip::TypedResult
A CmdResult that knows the corresponding command type.
Definition: mip_descriptors.hpp:97
mip::C::mip_is_cmd_descriptor_set
bool mip_is_cmd_descriptor_set(uint8_t descriptor_set)
Determines if the descriptor set contains commands.
Definition: mip_descriptors.c:46
mip::C::mip_is_cmd_field_descriptor
bool mip_is_cmd_field_descriptor(uint8_t field_descriptor)
Determines if the field descriptor is a command.
Definition: mip_descriptors.c:96
mip_result.hpp
mip::extract
size_t extract(Serializer &serializer, Vector< T, N > &v)
Definition: common.hpp:133