MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
mip_metadata.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_structures.hpp"
4 #include "mip_meta_utils.hpp"
5 
8 
9 
10 namespace mip::metadata
11 {
12 
13 // Type trait class to be specialized for each field/struct/etc.
14 template<class FieldType>
15 struct MetadataFor;
16 
17 
18 template<>
20 {
22 
23  static constexpr EnumInfo::Entry entries[] = {
24  { (uint8_t)FunctionSelector::WRITE, "WRITE", "Applies a new setting." },
25  { (uint8_t)FunctionSelector::READ, "READ", "Reads the current setting." },
26  { (uint8_t)FunctionSelector::SAVE, "SAVE", "Saves the current setting as power-on setting." },
27  { (uint8_t)FunctionSelector::LOAD, "LOAD", "Loads the power-on setting." },
28  { (uint8_t)FunctionSelector::RESET, "DEFAULT", "Resets to the factory default setting." },
29  };
30 
31  static constexpr inline EnumInfo value = {
32  /*.name =*/ "FunctionSelector",
33  /*.docs =*/ "",
34  /*.type =*/ Type::U8,
35  /*.entries =*/ entries,
36  };
37 };
38 
39 inline void* accessFunctionSelector(void* p) { return static_cast<FunctionSelector*>(p); }
40 
41 static constexpr inline ParameterInfo FUNCTION_SELECTOR_PARAM = {
42  /* .name = */ "function",
43  /* .docs = */ "Standard MIP function selector",
45  /* .accessor = */ accessFunctionSelector,
46  /* .functions = */ {true,true,true,true,true},
47  /* .count = */ 1,
48  /* .condition = */ {},
49 };
50 
51 
52 
53 // template<ParameterInfo::Type ParamType> struct ParamEnum;
54 // template<> struct ParamEnum<ParameterInfo::Type::U8> :
55 
56 
66 template<size_t I, class FieldType>
68 {
69  constexpr ParameterInfo& paramInfo = MetadataFor<FieldType>::PARAMETERS[I].type;
70  using T = typename utils::ParamEnum<paramInfo.type.type>::type;
71  return *static_cast<T*>(paramInfo.accessor(&field));
72 }
73 
74 
75 //template<class FieldType, size_t ParamIndex, class ParamType>
76 //ParamType get(FieldType& field)
77 //{
78 //}
79 //
80 //template<size_t ParameterIndex, class FieldType>
81 //auto get(FieldType& field)
82 //{
83 // const ParameterInfo& paramInfo = MetadataFor<FieldType>::PARAMETERS[ParameterIndex];
84 //
85 //
86 //}
87 
88 
89 //class Analyzer
90 //{
91 //public:
92 // Analyzer(microstrain::Serializer serializer) : m_serializer(serializer) {}
93 //
94 // bool analyze(const StructInfo& info)
95 // {
96 // size_t nextOffsetEntry = 0;
97 //
98 // for(const ParameterInfo& param : info.parameters)
99 // {
100 // if(param.count.paramIdx.isValid(info.parameters.size()))
101 // {
102 //
103 // }
104 // }
105 // }
106 //private:
107 // size_t getOffsetForParameter(const ParameterInfo* parameters, size_t index) const
108 // {
109 // for(size_t i=0; i<index; i++)
110 // {
111 // const ParameterInfo& param = parameters[i];
112 // size_t size = sizeForBasicType(param.type);
113 // if(size == 0)
114 // {
115 //
116 // }
117 // }
118 // for(const auto& param : parameters)
119 // }
120 //
121 //private:
122 // struct Offset
123 // {
124 // microstrain::Index parameterId = {};
125 // size_t offset = 0;
126 // };
127 //
128 //private:
129 // // Maximum number of parameters in a struct that can reference other parameters,
130 // // i.e. counters for arrays or union discriminators.
131 // static constexpr inline size_t MAX_PARAM_REFS = 5;
132 //
133 // microstrain::Serializer m_sserializer;
134 // std::array<Offset, MAX_PARAM_REFS> m_offsets;
135 //};
136 //
137 //
138 //
139 //constexpr size_t getParameterOffset(microstrain::Serializer serializer, microstrain::Index parameterId)
140 //{
141 // const auto& parameters = MetadataFor<FieldType>::parameters;
142 // if(parameterId.isValid(parameters.size()))
143 // return -1;
144 //
145 // size_t offset = 0;
146 //
147 // for(auto i=microstrain::Index(0); i<parameterId; i++)
148 // {
149 // const ParameterInfo& parameter = parameters[i.index()];
150 //
151 // size_t size = sizeForBasicType(parameter.type);
152 // if(size == 0)
153 // {
154 // if(parameter.type.type == Type::STRUCT)
155 // {
156 // // TODO
157 // }
158 // }
159 //
160 // if(parameter.count.isFixed())
161 // offset += size;
162 // else
163 // {
164 // assert(parameter.count.paramIdx.isValid(parameters.size()));
165 //
166 // uint8_t count = readCount(serializer, parameters, parameter.count.paramIdx);
167 //
168 // }
169 // }
170 //
171 // return offset;
172 //}
173 
174 } // namespace mip
mip::FunctionSelector::READ
@ READ
mip_descriptors.hpp
mip::metadata::utils::ParamEnum
Definition: mip_meta_utils.hpp:37
mip::metadata::Type::ENUM
@ ENUM
mip::metadata
Definition: commands_3dm.hpp:9
mip::FunctionSelector::RESET
@ RESET
mip::metadata::MetadataFor< FunctionSelector >::value
static constexpr EnumInfo value
Definition: mip_metadata.hpp:31
mip::FunctionSelector::SAVE
@ SAVE
mip::EnableForFieldTypes
std::enable_if< isField< T >::value, T > EnableForFieldTypes
Definition: mip_descriptors.hpp:57
mip::metadata::MetadataFor
Definition: mip_metadata.hpp:15
mip::metadata::utils::ParamEnum::type
void type
Definition: mip_meta_utils.hpp:37
mip::metadata::ParameterInfo
Definition: mip_structures.hpp:127
mip::metadata::EnumInfo::Entry
Definition: mip_structures.hpp:67
mip::FunctionSelector::LOAD
@ LOAD
mip::FunctionSelector
FunctionSelector
Definition: mip_descriptors.hpp:68
mip::metadata::accessFunctionSelector
void * accessFunctionSelector(void *p)
Definition: mip_metadata.hpp:39
mip::metadata::get
auto & get(typename EnableForFieldTypes< FieldType >::type &field)
Gets a reference to parameter 'I' in the struct for the given field.
Definition: mip_metadata.hpp:67
mip::FunctionSelector::WRITE
@ WRITE
mip::metadata::Type::U8
@ U8
mip_structures.hpp
mip_meta_utils.hpp
mip::metadata::EnumInfo
Definition: mip_structures.hpp:65
mip_serialization.hpp