Line data Source code
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 : /// Log entry recording electronics rack temperature
22 : /** \ingroup logger_types
23 : */
24 : struct telem_blockgains : public flatbuffer_log
25 : {
26 : /// The event code
27 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_BLOCKGAINS;
28 :
29 : /// The default level
30 : static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
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 1 : 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 1 : {
46 1 : auto _gains = builder.CreateVector( gains );
47 1 : auto _gainsc = builder.CreateVector( gains_constant );
48 1 : auto _mcs = builder.CreateVector( mcs );
49 1 : auto _mcsc = builder.CreateVector( mcs_constant );
50 1 : auto _lims = builder.CreateVector( lims );
51 1 : auto _limsc = builder.CreateVector( lims_constant );
52 :
53 1 : auto fb = CreateTelem_blockgains_fb( builder, _gains, _gainsc, _mcs, _mcsc, _lims, _limsc );
54 :
55 1 : builder.Finish( fb );
56 1 : }
57 : };
58 :
59 1 : static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
60 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
61 : )
62 : {
63 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
64 1 : static_cast<size_t>( len ) );
65 2 : return VerifyTelem_blockgains_fbBuffer( verifier );
66 : }
67 :
68 : /// Get the message formatte for human consumption.
69 0 : 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 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
76 :
77 0 : std::string msg = "[gains] ";
78 :
79 : // being very paranoid about existence and length here
80 0 : if( fbs->gains() && fbs->gains_constant() )
81 : {
82 0 : if( fbs->gains()->size() == fbs->gains_constant()->size() )
83 : {
84 0 : for( size_t i = 0; i < fbs->gains()->size(); ++i )
85 : {
86 0 : msg += " ";
87 0 : msg += std::to_string( fbs->gains()->Get( i ) );
88 0 : msg += " (";
89 0 : msg += std::to_string( fbs->gains_constant()->Get( i ) );
90 0 : msg += ")";
91 : }
92 : }
93 : else
94 : {
95 0 : for( size_t i = 0; i < fbs->gains()->size(); ++i )
96 : {
97 0 : msg += " ";
98 0 : msg += std::to_string( fbs->gains()->Get( i ) );
99 0 : msg += " (?)";
100 : }
101 : }
102 : }
103 0 : else if( fbs->gains() )
104 : {
105 0 : for( size_t i = 0; i < fbs->gains()->size(); ++i )
106 : {
107 0 : msg += " ";
108 0 : msg += std::to_string( fbs->gains()->Get( i ) );
109 0 : msg += " (?)";
110 : }
111 : }
112 :
113 0 : msg += " [mcs] ";
114 0 : if( fbs->mcs() && fbs->mcs_constant() )
115 : {
116 0 : if( fbs->mcs()->size() == fbs->mcs_constant()->size() )
117 : {
118 0 : for( size_t i = 0; i < fbs->mcs()->size(); ++i )
119 : {
120 0 : msg += " ";
121 0 : msg += std::to_string( fbs->mcs()->Get( i ) );
122 0 : msg += " (";
123 0 : msg += std::to_string( fbs->mcs_constant()->Get( i ) );
124 0 : msg += ")";
125 : }
126 : }
127 : else
128 : {
129 0 : for( size_t i = 0; i < fbs->mcs()->size(); ++i )
130 : {
131 0 : msg += " ";
132 0 : msg += std::to_string( fbs->mcs()->Get( i ) );
133 0 : msg += " (?)";
134 : }
135 : }
136 : }
137 0 : else if( fbs->mcs() )
138 : {
139 0 : for( size_t i = 0; i < fbs->mcs()->size(); ++i )
140 : {
141 0 : msg += " ";
142 0 : msg += std::to_string( fbs->mcs()->Get( i ) );
143 0 : msg += " (?)";
144 : }
145 : }
146 :
147 0 : msg += " [lims] ";
148 :
149 0 : if( fbs->lims() && fbs->lims_constant() )
150 : {
151 0 : if( fbs->lims()->size() == fbs->lims_constant()->size() )
152 : {
153 0 : for( size_t i = 0; i < fbs->lims()->size(); ++i )
154 : {
155 0 : msg += " ";
156 0 : msg += std::to_string( fbs->lims()->Get( i ) );
157 0 : msg += " (";
158 0 : msg += std::to_string( fbs->lims_constant()->Get( i ) );
159 0 : msg += ")";
160 : }
161 : }
162 : else
163 : {
164 0 : for( size_t i = 0; i < fbs->lims()->size(); ++i )
165 : {
166 0 : msg += " ";
167 0 : msg += std::to_string( fbs->lims()->Get( i ) );
168 0 : msg += " (?)";
169 : }
170 : }
171 : }
172 0 : else if( fbs->lims() )
173 : {
174 0 : for( size_t i = 0; i < fbs->lims()->size(); ++i )
175 : {
176 0 : msg += " ";
177 0 : msg += std::to_string( fbs->lims()->Get( i ) );
178 0 : msg += " (?)";
179 : }
180 : }
181 :
182 0 : return msg;
183 0 : }
184 :
185 0 : static std::vector<float> gains( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
186 : {
187 0 : std::vector<float> p;
188 :
189 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
190 :
191 0 : if( fbs->gains() != nullptr )
192 : {
193 0 : for( auto it = fbs->gains()->begin(); it != fbs->gains()->end(); ++it )
194 : {
195 0 : p.push_back( *it );
196 : }
197 : }
198 0 : return p;
199 0 : }
200 :
201 : static std::vector<bool>
202 0 : gains_constant( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
203 : {
204 0 : std::vector<bool> p;
205 :
206 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
207 :
208 0 : if( fbs->gains_constant() != nullptr )
209 : {
210 0 : for( auto it = fbs->gains_constant()->begin(); it != fbs->gains_constant()->end(); ++it )
211 : {
212 0 : p.push_back( *it );
213 : }
214 : }
215 0 : return p;
216 0 : }
217 :
218 0 : static std::vector<float> mcs( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
219 : {
220 0 : std::vector<float> p;
221 :
222 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
223 :
224 0 : if( fbs->mcs() != nullptr )
225 : {
226 0 : for( auto it = fbs->mcs()->begin(); it != fbs->mcs()->end(); ++it )
227 : {
228 0 : p.push_back( *it );
229 : }
230 : }
231 0 : return p;
232 0 : }
233 :
234 : static std::vector<bool>
235 0 : mcs_constant( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
236 : {
237 0 : std::vector<bool> p;
238 :
239 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
240 :
241 0 : if( fbs->mcs_constant() != nullptr )
242 : {
243 0 : for( auto it = fbs->mcs_constant()->begin(); it != fbs->mcs_constant()->end(); ++it )
244 : {
245 0 : p.push_back( *it );
246 : }
247 : }
248 0 : return p;
249 0 : }
250 :
251 0 : static std::vector<float> lims( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
252 : {
253 0 : std::vector<float> p;
254 :
255 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
256 :
257 0 : if( fbs->lims() != nullptr )
258 : {
259 0 : for( auto it = fbs->lims()->begin(); it != fbs->lims()->end(); ++it )
260 : {
261 0 : p.push_back( *it );
262 : }
263 : }
264 0 : return p;
265 0 : }
266 :
267 : static std::vector<bool>
268 0 : lims_constant( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
269 : {
270 0 : std::vector<bool> p;
271 :
272 0 : auto fbs = GetTelem_blockgains_fb( msgBuffer );
273 :
274 0 : if( fbs->lims_constant() != nullptr )
275 : {
276 0 : for( auto it = fbs->lims_constant()->begin(); it != fbs->lims_constant()->end(); ++it )
277 : {
278 0 : p.push_back( *it );
279 : }
280 : }
281 0 : return p;
282 0 : }
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 1 : static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
290 : {
291 1 : if( member == "gains" )
292 : return logMetaDetail( { "BLOCK GAINS",
293 : "mode block gains",
294 : logMeta::valTypes::Vector_Float,
295 : logMeta::metaTypes::State,
296 : reinterpret_cast<void *>( &gains ),
297 0 : true } );
298 1 : else if( member == "gains_constant" )
299 : return logMetaDetail( { "BLOCK GAINS CONSTANT",
300 : "whether or not all modes have same gain in block",
301 : logMeta::valTypes::Vector_Bool,
302 : logMeta::metaTypes::State,
303 : reinterpret_cast<void *>( &gains_constant ),
304 0 : true } );
305 1 : else if( member == "mcs" )
306 : return logMetaDetail( { "BLOCK MULT COEFS",
307 : "mode block mult. coefs.",
308 : logMeta::valTypes::Vector_Float,
309 : logMeta::metaTypes::State,
310 : reinterpret_cast<void *>( &mcs ),
311 0 : true } );
312 :
313 1 : else if( member == "mcs_constant" )
314 : return logMetaDetail( { "BLOCK MULT COEFS CONSTANT",
315 : "whether or not all modes have same mult. coefs. in block",
316 : logMeta::valTypes::Vector_Bool,
317 : logMeta::metaTypes::State,
318 : reinterpret_cast<void *>( &mcs_constant ),
319 0 : true } );
320 :
321 1 : else if( member == "lims" )
322 : return logMetaDetail( { "BLOCK LIMITS",
323 : "mode block limits",
324 : logMeta::valTypes::Vector_Float,
325 : logMeta::metaTypes::State,
326 : reinterpret_cast<void *>( &lims ),
327 0 : true } );
328 :
329 1 : else if( member == "lims_constant" )
330 : return logMetaDetail( { "BLOCK LIMITS CONSTANT",
331 : "whether or not all modes have same limit in block",
332 : logMeta::valTypes::Vector_Bool,
333 : logMeta::metaTypes::State,
334 : reinterpret_cast<void *>( &lims_constant ),
335 0 : true } );
336 : else
337 : {
338 1 : std::cerr << "No member " << member << " in telem_blockgains\n";
339 1 : return logMetaDetail();
340 : }
341 : }
342 :
343 : }; // telem_blockgains
344 :
345 : } // namespace logger
346 : } // namespace MagAOX
347 :
348 : #endif // logger_types_telem_blockgains_hpp
|