API
telem_blockgains.hpp
Go to the documentation of this file.
1 /** \file telem_blockgains.hpp
2  * \brief The MagAO-X logger telem_blockgains log type.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_types_files
6  *
7  * History:
8  * - 2022-11-27 created by JRM
9  */
10 #ifndef logger_types_telem_blockgains_hpp
11 #define logger_types_telem_blockgains_hpp
12 
13 #include "generated/telem_blockgains_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording electronics rack temperature
23 /** \ingroup logger_types
24  */
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_BLOCKGAINS;
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 std::vector<float> & gains, ///<[in] vector of gains
40  const std::vector<uint8_t> & gains_constant, ///<[in] vector of gains constant flags
41  const std::vector<float> & multcs, ///<[in] vector of mult. coeffs.
42  const std::vector<uint8_t> & multcs_constant, ///<[in] vector of mult. coeff constant flags
43  const std::vector<float> & lims, ///<[in] vector of limits
44  const std::vector<uint8_t> & lims_constant ///<[in] vector of limits constant flags
45  )
46  {
47  auto _gains = builder.CreateVector(gains);
48  auto _gainsc = builder.CreateVector(gains_constant);
49  auto _mcs = builder.CreateVector(multcs);
50  auto _mcsc = builder.CreateVector(multcs_constant);
51  auto _lims = builder.CreateVector(lims);
52  auto _limsc = builder.CreateVector(lims_constant);
53 
54  auto fb = CreateTelem_blockgains_fb(builder, _gains, _gainsc, _mcs, _mcsc, _lims, _limsc);
55 
56  builder.Finish(fb);
57  }
58 
59  };
60 
61  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
62  flatlogs::msgLenT len ///< [in] length of msgBuffer.
63  )
64  {
65  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
66  return VerifyTelem_blockgains_fbBuffer(verifier);
67  }
68 
69  ///Get the message formatte for human consumption.
70  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
71  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
72  )
73  {
74  static_cast<void>(len);
75 
76  auto fbs = GetTelem_blockgains_fb(msgBuffer);
77 
78  std::string msg = "[gains] ";
79 
80  // being very paranoid about existence and length here
81  if( fbs->gains() && fbs->gains_constant() )
82  {
83  if(fbs->gains()->size() == fbs->gains_constant()->size())
84  {
85  for(size_t i=0; i< fbs->gains()->size(); ++i)
86  {
87  msg += " ";
88  msg += std::to_string(fbs->gains()->Get(i));
89  msg += " (";
90  msg += std::to_string(fbs->gains_constant()->Get(i));
91  msg += ")";
92  }
93  }
94  else
95  {
96  for(size_t i=0; i< fbs->gains()->size(); ++i)
97  {
98  msg += " ";
99  msg += std::to_string(fbs->gains()->Get(i));
100  msg += " (?)";
101  }
102  }
103  }
104  else if (fbs->gains())
105  {
106  for(size_t i=0; i< fbs->gains()->size(); ++i)
107  {
108  msg += " ";
109  msg += std::to_string(fbs->gains()->Get(i));
110  msg += " (?)";
111  }
112  }
113 
114  msg += " [mcs] ";
115  if( fbs->mcs() && fbs->mcs_constant() )
116  {
117  if(fbs->mcs()->size() == fbs->mcs_constant()->size())
118  {
119  for(size_t i=0; i< fbs->mcs()->size(); ++i)
120  {
121  msg += " ";
122  msg += std::to_string(fbs->mcs()->Get(i));
123  msg += " (";
124  msg += std::to_string(fbs->mcs_constant()->Get(i));
125  msg += ")";
126  }
127  }
128  else
129  {
130  for(size_t i=0; i< fbs->mcs()->size(); ++i)
131  {
132  msg += " ";
133  msg += std::to_string(fbs->mcs()->Get(i));
134  msg += " (?)";
135  }
136  }
137  }
138  else if (fbs->mcs())
139  {
140  for(size_t i=0; i< fbs->mcs()->size(); ++i)
141  {
142  msg += " ";
143  msg += std::to_string(fbs->mcs()->Get(i));
144  msg += " (?)";
145  }
146  }
147 
148  msg += " [lims] ";
149 
150  if( fbs->lims() && fbs->lims_constant() )
151  {
152  if(fbs->lims()->size() == fbs->lims_constant()->size())
153  {
154  for(size_t i=0; i< fbs->lims()->size(); ++i)
155  {
156  msg += " ";
157  msg += std::to_string(fbs->lims()->Get(i));
158  msg += " (";
159  msg += std::to_string(fbs->lims_constant()->Get(i));
160  msg += ")";
161  }
162  }
163  else
164  {
165  for(size_t i=0; i< fbs->lims()->size(); ++i)
166  {
167  msg += " ";
168  msg += std::to_string(fbs->lims()->Get(i));
169  msg += " (?)";
170  }
171  }
172  }
173  else if (fbs->lims())
174  {
175  for(size_t i=0; i< fbs->lims()->size(); ++i)
176  {
177  msg += " ";
178  msg += std::to_string(fbs->lims()->Get(i));
179  msg += " (?)";
180  }
181  }
182 
183  return msg;
184 
185  }
186 
187 }; //telem_blockgains
188 
189 
190 
191 } //namespace logger
192 } //namespace MagAOX
193 
194 #endif //logger_types_telem_blockgains_hpp
195 
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::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.
messageT(const std::vector< float > &gains, const std::vector< uint8_t > &gains_constant, const std::vector< float > &multcs, const std::vector< uint8_t > &multcs_constant, const std::vector< float > &lims, const std::vector< uint8_t > &lims_constant)
Construct from components.
Log entry recording electronics rack temperature.
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static const flatlogs::logPrioT defaultLevel
The default level.
static const flatlogs::eventCodeT eventCode
The event code.