MIP_SDK  v3.0.0
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 <tuple>
9 #include <type_traits>
10 #include <functional>
11 
12 
13 namespace mip
14 {
18 
23 {
24  uint8_t descriptorSet;
25  uint8_t fieldDescriptor;
26 
27  constexpr CompositeDescriptor(uint8_t descSet, uint8_t fieldDesc) : descriptorSet(descSet), fieldDescriptor(fieldDesc) {}
28  constexpr CompositeDescriptor(uint16_t combo) : descriptorSet(combo >> 8), fieldDescriptor(combo & 0xFF) {}
29 
30  CompositeDescriptor& operator=(uint16_t combo) { return *this = CompositeDescriptor(combo); }
31 
32  constexpr uint16_t as_u16() const { return (uint16_t(descriptorSet) << 8) | fieldDescriptor; }
33 
34 // operator uint16_t() const { return as_u16(); }
35 
36  constexpr bool operator==(const CompositeDescriptor& other) const { return other.descriptorSet == descriptorSet && other.fieldDescriptor == fieldDescriptor; }
37  constexpr bool operator<(const CompositeDescriptor& other) const { return as_u16() < other.as_u16(); }
38 
39 };
40 
41 
42 // All MIP command/data fields should inherit this struct.
44 {
45  //static_assert(std::is_base_of<FieldStruct<T>, T>::value, "T must inherit from FieldStruct<T>");
46 
47 private:
48  // No direct instantiation,
49  // this class must be inherited.
50  FieldStruct() = default;
51 };
52 
53 template<class T>
54 using isField = std::is_base_of<FieldStruct, T>;
55 
56 template<class T>
57 using EnableForFieldTypes = std::enable_if<isField<T>::value, T>;
58 
59 
62 template<typename DerivedT> struct Bitfield {};
63 
64 template<class Derived> size_t insert (Serializer& serializer, const Bitfield<Derived>& bitfield) { return insert(serializer, static_cast<const Derived&>(bitfield).value); }
65 template<class Derived> size_t extract(Serializer& serializer, Bitfield<Derived>& bitfield) { return extract(serializer, static_cast<Derived&>(bitfield).value); }
66 
67 
68 enum class FunctionSelector : uint8_t
69 {
75 };
76 
77 static constexpr uint8_t INVALID_FIELD_DESCRIPTOR = C::MIP_INVALID_FIELD_DESCRIPTOR;
78 static constexpr uint8_t INVALID_DESCRIPTOR_SET = C::MIP_INVALID_DESCRIPTOR_SET;
79 
80 inline bool isValidDescriptorSet (uint8_t descriptorSet) { return C::mip_is_valid_descriptor_set(descriptorSet); }
81 inline bool isDataDescriptorSet (uint8_t descriptorSet) { return C::mip_is_data_descriptor_set(descriptorSet); }
82 inline bool isCommandDescriptorSet (uint8_t descriptorSet) { return C::mip_is_cmd_descriptor_set(descriptorSet); }
83 inline bool isReservedDescriptorSet(uint8_t descriptorSet) { return C::mip_is_reserved_descriptor_set(descriptorSet); }
84 inline bool isGnssDataDescriptorSet(uint8_t descriptorSet) { return C::mip_is_gnss_data_descriptor_set(descriptorSet); }
85 
86 inline bool isValidFieldDescriptor (uint8_t fieldDescriptor) { return C::mip_is_valid_field_descriptor(fieldDescriptor); }
87 inline bool isCommandFieldDescriptor (uint8_t fieldDescriptor) { return C::mip_is_cmd_field_descriptor(fieldDescriptor); }
88 inline bool isReplyFieldDescriptor (uint8_t fieldDescriptor) { return C::mip_is_reply_field_descriptor(fieldDescriptor); }
89 inline bool isResponseFieldDescriptor(uint8_t fieldDescriptor) { return C::mip_is_response_field_descriptor(fieldDescriptor); }
90 inline bool isReservedFieldDescriptor(uint8_t fieldDescriptor) { return C::mip_is_reserved_cmd_field_descriptor(fieldDescriptor); }
91 inline bool isSharedDataFieldDescriptor(uint8_t fieldDescriptor) { return C::mip_is_shared_data_field_descriptor(fieldDescriptor); }
92 
93 
99 template<class MipCmd>
100 struct TypedResult : public CmdResult
101 {
102  using Cmd = MipCmd;
103 
104  // Same constructor as CmdResult.
105  using CmdResult::CmdResult;
106 
109  static constexpr CompositeDescriptor DESCRIPTOR = MipCmd::DESCRIPTOR;
110 
113  constexpr CompositeDescriptor descriptor() const { return DESCRIPTOR; }
114 };
115 
118 } // namespace mip
119 
mip::FunctionSelector::READ
@ READ
mip::isCommandDescriptorSet
bool isCommandDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:82
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:24
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:30
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:28
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:91
mip::CompositeDescriptor::operator<
constexpr bool operator<(const CompositeDescriptor &other) const
Definition: mip_descriptors.hpp:37
mip::isGnssDataDescriptorSet
bool isGnssDataDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:84
mip::FunctionSelector::SAVE
@ SAVE
mip::isCommandFieldDescriptor
bool isCommandFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:87
mip::TypedResult::DESCRIPTOR
static constexpr CompositeDescriptor DESCRIPTOR
The command descriptor.
Definition: mip_descriptors.hpp:109
mip::EnableForFieldTypes
std::enable_if< isField< T >::value, T > EnableForFieldTypes
Definition: mip_descriptors.hpp:57
mip::isDataDescriptorSet
bool isDataDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:81
mip::isValidFieldDescriptor
bool isValidFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:86
mip::FunctionSelector::LOAD
@ LOAD
mip::CompositeDescriptor::operator==
constexpr bool operator==(const CompositeDescriptor &other) const
Definition: mip_descriptors.hpp:36
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:68
mip::CmdResult
Represents the status of a MIP command.
Definition: mip_result.hpp:24
mip::FieldStruct
Definition: mip_descriptors.hpp:43
mip::isResponseFieldDescriptor
bool isResponseFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:89
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:102
mip::isValidDescriptorSet
bool isValidDescriptorSet(uint8_t descriptorSet)
Definition: mip_descriptors.hpp:80
mip::C::MIP_FUNCTION_LOAD
@ MIP_FUNCTION_LOAD
Definition: mip_descriptors.h:47
mip::isReplyFieldDescriptor
bool isReplyFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:88
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:27
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:32
mip::CompositeDescriptor::fieldDescriptor
uint8_t fieldDescriptor
MIP field descriptor.
Definition: mip_descriptors.hpp:25
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:22
mip::isReservedFieldDescriptor
bool isReservedFieldDescriptor(uint8_t fieldDescriptor)
Definition: mip_descriptors.hpp:90
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:83
mip::isField
std::is_base_of< FieldStruct, T > isField
Definition: mip_descriptors.hpp:54
mip::Bitfield
A dummy struct which is used to mark bitfield objects.
Definition: mip_descriptors.hpp:62
mip::CmdResult::CmdResult
constexpr CmdResult()
Definition: mip_result.hpp:47
mip::TypedResult
A CmdResult that knows the corresponding command type.
Definition: mip_descriptors.hpp:100
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