API
telem_loopgain.hpp
Go to the documentation of this file.
1 /** \file telem_loopgain.hpp
2  * \brief The MagAO-X logger telem_loopgain log type.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_types_files
6  *
7  * History:
8  * - 2022-11-28 created by JRM
9  */
10 #ifndef logger_types_telem_loopgain_hpp
11 #define logger_types_telem_loopgain_hpp
12 
13 #include "generated/telem_loopgain_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording the build-time git state.
23 /** \ingroup logger_types
24  */
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_LOOPGAIN;
29 
30  ///The default level
32 
33  static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
34 
35  ///The type of the input message
36  struct messageT : public fbMessage
37  {
38  ///Construct from components
39  messageT( const uint8_t & state, ///< [in]
40  const float & gain, ///< [in]
41  const float & multcoef, ///< [in]
42  const float & limit ///< [in]
43  )
44  {
45  auto fp = CreateTelem_loopgain_fb(builder, state, gain, multcoef, limit);
46  builder.Finish(fp);
47  }
48 
49  };
50 
51  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
52  flatlogs::msgLenT len ///< [in] length of msgBuffer.
53  )
54  {
55  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
56  return VerifyTelem_loopgain_fbBuffer(verifier);
57  }
58 
59  ///Get the message formatte for human consumption.
60  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
61  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
62  )
63  {
64  static_cast<void>(len);
65 
66  auto fbs = GetTelem_loopgain_fb(msgBuffer);
67 
68  std::string msg = "[loopgain] ";
69 
70 
71 
72  msg += "state: ";
73  msg += std::to_string(fbs->state()) + " ";
74 
75  msg += "gain: ";
76  msg += std::to_string(fbs->gain()) + " ";
77 
78  msg += "multcoef: ";
79  msg += std::to_string(fbs->multcoef()) + " ";
80 
81  msg += "limit: ";
82  msg += std::to_string(fbs->limit());
83 
84  return msg;
85 
86  }
87 
88  static uint8_t state(void * msgBuffer)
89  {
90  auto fbs = GetTelem_loopgain_fb(msgBuffer);
91  return fbs->state();
92  }
93 
94  static float gain(void * msgBuffer)
95  {
96  auto fbs = GetTelem_loopgain_fb(msgBuffer);
97  return fbs->gain();
98  }
99 
100  static float multcoef(void * msgBuffer)
101  {
102  auto fbs = GetTelem_loopgain_fb(msgBuffer);
103  return fbs->multcoef();
104  }
105 
106  static float limit(void * msgBuffer)
107  {
108  auto fbs = GetTelem_loopgain_fb(msgBuffer);
109  return fbs->limit();
110  }
111 
112  /// Get the logMetaDetail for a member by name
113  /**
114  * \returns the a logMetaDetail filled in with the appropriate details
115  * \returns an empty logmegaDetail if member not recognized
116  */
117  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
118  {
119  if( member == "state") return logMetaDetail({"LOOP STATE", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&state)});
120  else if( member == "gain") return logMetaDetail({"LOOP GAIN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&gain)});
121  else if( member == "multcoef") return logMetaDetail({"LOOP MULTCOEF", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&multcoef)});
122  else if( member == "limit") return logMetaDetail({"LOOP LIMIT", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&limit)});
123  else
124  {
125  std::cerr << "No string member " << member << " in telem_loopgain\n";
126  return logMetaDetail();
127  }
128 
129  }
130 
131 
132 }; //telem_loopgain
133 
134 
135 
136 } //namespace logger
137 } //namespace MagAOX
138 
139 #endif //logger_types_telem_loopgain_hpp
140 
The MagAO-X logger flatbuffer log base type.
uint16_t eventCodeT
The type of an event code (16-bit unsigned int).
Definition: logDefs.hpp:40
msgLen2T msgLenT
The type used to refer to the message length, regardless of length.
Definition: logDefs.hpp:69
int8_t logPrioT
The type of the log priority code.
Definition: logDefs.hpp:21
static void * messageBuffer(bufferPtrT &logBuffer)
Get the message buffer address.
Definition: logHeader.hpp:621
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition: logHeader.hpp:58
std::ostream & cerr()
std::stringstream msg
Definition: dm.hpp:24
constexpr static logPrioT LOG_TELEM
A telemetry recording.
Definition: logPriority.hpp:58
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
The type of the input message.
messageT(const uint8_t &state, const float &gain, const float &multcoef, const float &limit)
Construct from components.
Log entry recording the build-time git state.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static float multcoef(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static const flatlogs::eventCodeT eventCode
The event code.
static float limit(void *msgBuffer)
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static const flatlogs::logPrioT defaultLevel
The default level.
static uint8_t state(void *msgBuffer)
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static float gain(void *msgBuffer)