API
 
Loading...
Searching...
No Matches
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
14#include "flatbuffer_log.hpp"
15
16namespace MagAOX
17{
18namespace logger
19{
20
21/// Log entry recording electronics rack temperature
22/** \ingroup logger_types
23 */
25{
26 /// The event code
28
29 /// The default level
31
32 static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
33
34 /// The type of the input message
35 struct messageT : public fbMessage
36 {
37 /// Construct from components
38 messageT( const std::vector<float> &gains, ///<[in] vector of gains
39 const std::vector<uint8_t> &gains_constant, ///<[in] vector of gains constant flags
40 const std::vector<float> &mcs, ///<[in] vector of mult. coeffs.
41 const std::vector<uint8_t> &mcs_constant, ///<[in] vector of mult. coeff constant flags
42 const std::vector<float> &lims, ///<[in] vector of limits
43 const std::vector<uint8_t> &lims_constant ///<[in] vector of limits constant flags
44 )
45 {
46 auto _gains = builder.CreateVector( gains );
47 auto _gainsc = builder.CreateVector( gains_constant );
48 auto _mcs = builder.CreateVector( mcs );
49 auto _mcsc = builder.CreateVector( mcs_constant );
50 auto _lims = builder.CreateVector( lims );
51 auto _limsc = builder.CreateVector( lims_constant );
52
53 auto fb = CreateTelem_blockgains_fb( builder, _gains, _gainsc, _mcs, _mcsc, _lims, _limsc );
54
55 builder.Finish( fb );
56 }
57 };
58
59 static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
60 flatlogs::msgLenT len ///< [in] length of msgBuffer.
61 )
62 {
63 auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
64 static_cast<size_t>( len ) );
65 return VerifyTelem_blockgains_fbBuffer( verifier );
66 }
67
68 /// Get the message formatte for human consumption.
69 static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
70 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
71 )
72 {
73 static_cast<void>( len );
74
75 auto fbs = GetTelem_blockgains_fb( msgBuffer );
76
77 std::string msg = "[gains] ";
78
79 // being very paranoid about existence and length here
80 if( fbs->gains() && fbs->gains_constant() )
81 {
82 if( fbs->gains()->size() == fbs->gains_constant()->size() )
83 {
84 for( size_t i = 0; i < fbs->gains()->size(); ++i )
85 {
86 msg += " ";
87 msg += std::to_string( fbs->gains()->Get( i ) );
88 msg += " (";
89 msg += std::to_string( fbs->gains_constant()->Get( i ) );
90 msg += ")";
91 }
92 }
93 else
94 {
95 for( size_t i = 0; i < fbs->gains()->size(); ++i )
96 {
97 msg += " ";
98 msg += std::to_string( fbs->gains()->Get( i ) );
99 msg += " (?)";
100 }
101 }
102 }
103 else if( fbs->gains() )
104 {
105 for( size_t i = 0; i < fbs->gains()->size(); ++i )
106 {
107 msg += " ";
108 msg += std::to_string( fbs->gains()->Get( i ) );
109 msg += " (?)";
110 }
111 }
112
113 msg += " [mcs] ";
114 if( fbs->mcs() && fbs->mcs_constant() )
115 {
116 if( fbs->mcs()->size() == fbs->mcs_constant()->size() )
117 {
118 for( size_t i = 0; i < fbs->mcs()->size(); ++i )
119 {
120 msg += " ";
121 msg += std::to_string( fbs->mcs()->Get( i ) );
122 msg += " (";
123 msg += std::to_string( fbs->mcs_constant()->Get( i ) );
124 msg += ")";
125 }
126 }
127 else
128 {
129 for( size_t i = 0; i < fbs->mcs()->size(); ++i )
130 {
131 msg += " ";
132 msg += std::to_string( fbs->mcs()->Get( i ) );
133 msg += " (?)";
134 }
135 }
136 }
137 else if( fbs->mcs() )
138 {
139 for( size_t i = 0; i < fbs->mcs()->size(); ++i )
140 {
141 msg += " ";
142 msg += std::to_string( fbs->mcs()->Get( i ) );
143 msg += " (?)";
144 }
145 }
146
147 msg += " [lims] ";
148
149 if( fbs->lims() && fbs->lims_constant() )
150 {
151 if( fbs->lims()->size() == fbs->lims_constant()->size() )
152 {
153 for( size_t i = 0; i < fbs->lims()->size(); ++i )
154 {
155 msg += " ";
156 msg += std::to_string( fbs->lims()->Get( i ) );
157 msg += " (";
158 msg += std::to_string( fbs->lims_constant()->Get( i ) );
159 msg += ")";
160 }
161 }
162 else
163 {
164 for( size_t i = 0; i < fbs->lims()->size(); ++i )
165 {
166 msg += " ";
167 msg += std::to_string( fbs->lims()->Get( i ) );
168 msg += " (?)";
169 }
170 }
171 }
172 else if( fbs->lims() )
173 {
174 for( size_t i = 0; i < fbs->lims()->size(); ++i )
175 {
176 msg += " ";
177 msg += std::to_string( fbs->lims()->Get( i ) );
178 msg += " (?)";
179 }
180 }
181
182 return msg;
183 }
184
185 static std::vector<float> gains( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
186 {
187 std::vector<float> p;
188
189 auto fbs = GetTelem_blockgains_fb( msgBuffer );
190
191 if( fbs->gains() != nullptr )
192 {
193 for( auto it = fbs->gains()->begin(); it != fbs->gains()->end(); ++it )
194 {
195 p.push_back( *it );
196 }
197 }
198 return p;
199 }
200
201 static std::vector<bool>
202 gains_constant( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
203 {
204 std::vector<bool> p;
205
206 auto fbs = GetTelem_blockgains_fb( msgBuffer );
207
208 if( fbs->gains_constant() != nullptr )
209 {
210 for( auto it = fbs->gains_constant()->begin(); it != fbs->gains_constant()->end(); ++it )
211 {
212 p.push_back( *it );
213 }
214 }
215 return p;
216 }
217
218 static std::vector<float> mcs( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
219 {
220 std::vector<float> p;
221
222 auto fbs = GetTelem_blockgains_fb( msgBuffer );
223
224 if( fbs->mcs() != nullptr )
225 {
226 for( auto it = fbs->mcs()->begin(); it != fbs->mcs()->end(); ++it )
227 {
228 p.push_back( *it );
229 }
230 }
231 return p;
232 }
233
234 static std::vector<bool>
235 mcs_constant( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
236 {
237 std::vector<bool> p;
238
239 auto fbs = GetTelem_blockgains_fb( msgBuffer );
240
241 if( fbs->mcs_constant() != nullptr )
242 {
243 for( auto it = fbs->mcs_constant()->begin(); it != fbs->mcs_constant()->end(); ++it )
244 {
245 p.push_back( *it );
246 }
247 }
248 return p;
249 }
250
251 static std::vector<float> lims( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
252 {
253 std::vector<float> p;
254
255 auto fbs = GetTelem_blockgains_fb( msgBuffer );
256
257 if( fbs->lims() != nullptr )
258 {
259 for( auto it = fbs->lims()->begin(); it != fbs->lims()->end(); ++it )
260 {
261 p.push_back( *it );
262 }
263 }
264 return p;
265 }
266
267 static std::vector<bool>
268 lims_constant( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
269 {
270 std::vector<bool> p;
271
272 auto fbs = GetTelem_blockgains_fb( msgBuffer );
273
274 if( fbs->lims_constant() != nullptr )
275 {
276 for( auto it = fbs->lims_constant()->begin(); it != fbs->lims_constant()->end(); ++it )
277 {
278 p.push_back( *it );
279 }
280 }
281 return p;
282 }
283
284 /// Get the logMetaDetail for a member by name
285 /**
286 * \returns the a logMetaDetail filled in with the appropriate details
287 * \returns an empty logMetaDetail if member not recognized
288 */
289 static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
290 {
291 if( member == "gains" )
292 return logMetaDetail( { "BLOCK GAINS",
293 "mode block gains",
296 reinterpret_cast<void *>( &gains ),
297 false } );
298 else if( member == "gains_constant" )
299 return logMetaDetail( { "BLOCK GAINS CONSTANT",
300 "whether or not all modes have same gain in block",
303 reinterpret_cast<void *>( &gains_constant ),
304 false } );
305 else if( member == "mcs" )
306 return logMetaDetail( { "BLOCK MULT COEFS",
307 "mode block mult. coefs.",
310 reinterpret_cast<void *>( &mcs ),
311 false } );
312 else if( member == "mcs_constant" )
313 return logMetaDetail( { "BLOCK MULT COEFS CONSTANT",
314 "whether or not all modes have same mult. coefs. in block",
317 reinterpret_cast<void *>( &mcs_constant ),
318 false } );
319 else if( member == "lims" )
320 return logMetaDetail( { "BLOCK LIMITS",
321 "mode block limits",
324 reinterpret_cast<void *>( &lims ),
325 false } );
326 else if( member == "lims_constant" )
327 return logMetaDetail( { "BLOCK LIMITS CONSTANT",
328 "whether or not all modes have same limit in block",
331 reinterpret_cast<void *>( &lims_constant ),
332 false } );
333 else
334 {
335 std::cerr << "No member " << member << " in telem_blockgains\n";
336 return logMetaDetail();
337 }
338 }
339
340}; // telem_blockgains
341
342} // namespace logger
343} // namespace MagAOX
344
345#endif // logger_types_telem_blockgains_hpp
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.
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
static constexpr flatlogs::eventCodeT TELEM_BLOCKGAINS
Definition logCodes.hpp:60
inline ::flatbuffers::Offset< Telem_blockgains_fb > CreateTelem_blockgains_fb(::flatbuffers::FlatBufferBuilder &_fbb, ::flatbuffers::Offset<::flatbuffers::Vector< float > > gains=0, ::flatbuffers::Offset<::flatbuffers::Vector< uint8_t > > gains_constant=0, ::flatbuffers::Offset<::flatbuffers::Vector< float > > mcs=0, ::flatbuffers::Offset<::flatbuffers::Vector< uint8_t > > mcs_constant=0, ::flatbuffers::Offset<::flatbuffers::Vector< float > > lims=0, ::flatbuffers::Offset<::flatbuffers::Vector< uint8_t > > lims_constant=0)
bool VerifyTelem_blockgains_fbBuffer(::flatbuffers::Verifier &verifier)
const MagAOX::logger::Telem_blockgains_fb * GetTelem_blockgains_fb(const void *buf)
Definition dm.hpp:28
static constexpr logPrioT LOG_TELEM
A telemetry recording.
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 > &mcs, const std::vector< uint8_t > &mcs_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::vector< bool > gains_constant(void *msgBuffer)
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static std::vector< float > lims(void *msgBuffer)
static std::vector< bool > mcs_constant(void *msgBuffer)
static std::vector< float > gains(void *msgBuffer)
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.
static std::vector< bool > lims_constant(void *msgBuffer)
static std::vector< float > mcs(void *msgBuffer)