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