API
 
Loading...
Searching...
No Matches
telem_stdcam.hpp
Go to the documentation of this file.
1/** \file telem_stdcam.hpp
2 * \brief The MagAO-X logger telem_stdcam log type.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_types_files
6 *
7 * History:
8 * - 2018-09-06 created by JRM
9 */
10#ifndef logger_types_telem_stdcam_hpp
11#define logger_types_telem_stdcam_hpp
12
14#include "flatbuffer_log.hpp"
15
16namespace MagAOX
17{
18namespace logger
19{
20
21/// Log entry recording stdcam stage specific status.
22/** \ingroup logger_types
23 */
25{
26 /// The event code
28
29 /// The default level
31
32 static timespec
33 lastRecord; ///< The timestamp 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::string &mode, ///<[in]
40 const float &xcen, ///<[in]
41 const float &ycen, ///<[in]
42 const int &width, ///<[in]
43 const int &height, ///<[in]
44 const int &xbin, ///<[in]
45 const int &ybin, ///<[in]
46 const float &exptime, ///<[in]
47 const float &fps, ///<[in]
48 const float &emGain, ///<[in]
49 const float &adcSpeed, ///<[in]
50 const float &temp, ///<[in]
51 const float &setpt, ///<[in]
52 const uint8_t &status, ///<[in]
53 const uint8_t &ontarget, ///<[in]
54 const std::string &statusStr, ///<[in]
55 const std::string &shutterStatusSr, ///<[in]
56 const int8_t &shutterState, ///<[in]
57 const uint8_t &synchro, ///<[in]
58 const float &vshift, ///<[in]
59 const uint8_t &cropMode, ///<[in]
60 const std::string &fan_speed, ///<[in]
61 const std::string &readout_speed, ///<[in]
62 const std::string &analog_gain, ///<[in]
63 const int8_t &led ///<[in]
64 )
65 {
66 auto _mode = builder.CreateString( mode );
67 auto _roi = CreateROI( builder, xcen, ycen, width, height, xbin, ybin );
68
69 auto _statusStr = builder.CreateString( statusStr );
70 auto _tempCtrl = CreateTempCtrl( builder, temp, setpt, status, ontarget, _statusStr );
71
72 auto _shutterStatusStr = builder.CreateString( shutterStatusSr );
73 auto _shutter = CreateShutter( builder, _shutterStatusStr, shutterState );
74
75 auto _fanSpeed = builder.CreateString( fan_speed );
76 auto _readoutSpeed = builder.CreateString( readout_speed );
77 auto _analogGain = builder.CreateString( analog_gain );
78
80 _mode,
81 _roi,
82 exptime,
83 fps,
84 emGain,
86 _tempCtrl,
87 _shutter,
88 synchro,
89 vshift,
91 _fanSpeed,
92 _readoutSpeed,
93 _analogGain,
94 led );
95 builder.Finish( fp );
96 }
97 };
98
99 static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
100 flatlogs::msgLenT len ///< [in] length of msgBuffer.
101 )
102 {
103 auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
104 static_cast<size_t>( len ) );
105 return VerifyTelem_stdcam_fbBuffer( verifier );
106 }
107
108 /// Get the message formatted for human consumption.
109 static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
110 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
111 )
112 {
113 static_cast<void>( len );
114
115 auto fbs = GetTelem_stdcam_fb( msgBuffer );
116
117 std::string msg = "[stdcam] ";
118
119 if( fbs->mode() != nullptr )
120 {
121 msg += "mode: ";
122 msg += fbs->mode()->c_str();
123 msg += " ";
124 }
125
126 if( fbs->roi() != nullptr )
127 {
128 msg += "ROI-x: ";
129 msg += std::to_string( fbs->roi()->xcen() );
130 msg += " y: ";
131 msg += std::to_string( fbs->roi()->ycen() );
132 msg += " w: ";
133 msg += std::to_string( fbs->roi()->w() );
134 msg += " h: ";
135 msg += std::to_string( fbs->roi()->h() );
136 msg += " xbin: ";
137 msg += std::to_string( fbs->roi()->xbin() );
138 msg += " ybin: ";
139 msg += std::to_string( fbs->roi()->ybin() );
140 msg += " ";
141 }
142
143 msg += "expt: ";
144 msg += std::to_string( fbs->exptime() );
145 msg += " fps: ";
146 msg += std::to_string( fbs->fps() );
147 msg += " emG: ";
148 msg += std::to_string( fbs->emGain() );
149 msg += " adc: ";
150 msg += std::to_string( fbs->adcSpeed() );
151
152 if( fbs->tempCtrl() != nullptr )
153 {
154 msg += " temp: ";
155 msg += std::to_string( fbs->tempCtrl()->temp() );
156 msg += " setpt: ";
157 msg += std::to_string( fbs->tempCtrl()->setpt() );
158 msg += " tempctr-stat: ";
159 msg += std::to_string( fbs->tempCtrl()->status() );
160 msg += " tempctr-ontgt: ";
161 msg += std::to_string( fbs->tempCtrl()->ontarget() );
162
163 if( fbs->tempCtrl()->statusStr() )
164 {
165 msg += " tempctr-statstr: ";
166 msg += fbs->tempCtrl()->statusStr()->c_str();
167 }
168 }
169
170 if( fbs->shutter() != nullptr )
171 {
172 if( fbs->shutter()->statusStr() )
173 {
174 msg += " shutter-statstr: ";
175 msg += fbs->shutter()->statusStr()->c_str();
176 }
177 msg += " shutter: ";
178 if( fbs->shutter()->state() == -1 )
179 {
180 msg += "UNKN";
181 }
182 else if( fbs->shutter()->state() == 0 )
183 {
184 msg += "SHUT";
185 }
186 else if( fbs->shutter()->state() == 1 )
187 {
188 msg += "OPEN";
189 }
190 }
191
192 msg += " Sync: ";
193 if( fbs->synchro() )
194 msg += "ON";
195 else
196 msg += "OFF";
197
198 msg += " vshift: ";
199 if( fbs->vshift() == 0 )
200 msg += "---";
201 else
202 msg += std::to_string( fbs->vshift() );
203
204 msg += " crop: ";
205 if( fbs->cropMode() == -1 )
206 msg += "---";
207 else if( fbs->cropMode() == 1 )
208 msg += "ON";
209 else
210 msg += "OFF";
211
212 if( fbs->readout_speed() != nullptr )
213 {
214 if( fbs->readout_speed()->size() > 0 )
215 {
216 msg += " rospd: ";
217 msg += fbs->readout_speed()->c_str();
218 }
219 }
220
221 if( fbs->fan_speed() != nullptr )
222 {
223 if( fbs->fan_speed()->size() > 0 )
224 {
225 msg += " fan: ";
226 msg += fbs->fan_speed()->c_str();
227 }
228 }
229
230 if( fbs->analog_gain() != nullptr )
231 {
232 if( fbs->analog_gain()->size() > 0 )
233 {
234 msg += " again: ";
235 msg += fbs->analog_gain()->c_str();
236 }
237 }
238
239 msg += " led: ";
240 if( fbs->led() == -1 )
241 msg += "---";
242 else if( fbs->led() == 1 )
243 msg += "ON";
244 else
245 msg += "OFF";
246
247 return msg;
248 }
249
250 static std::string mode( void *msgBuffer )
251 {
252 auto fbs = GetTelem_stdcam_fb( msgBuffer );
253 if( fbs->mode() != nullptr )
254 {
255 return std::string( fbs->mode()->c_str() );
256 }
257 else
258 return "";
259 }
260
261 static float xcen( void *msgBuffer )
262 {
263 auto fbs = GetTelem_stdcam_fb( msgBuffer );
264 if( fbs->roi() != nullptr )
265 return fbs->roi()->xcen();
266 else
267 return -1;
268 }
269
270 static float ycen( void *msgBuffer )
271 {
272 auto fbs = GetTelem_stdcam_fb( msgBuffer );
273 if( fbs->roi() != nullptr )
274 return fbs->roi()->ycen();
275 else
276 return -1;
277 }
278
279 static int width( void *msgBuffer )
280 {
281 auto fbs = GetTelem_stdcam_fb( msgBuffer );
282 if( fbs->roi() != nullptr )
283 return fbs->roi()->w();
284 else
285 return -1;
286 }
287
288 static int height( void *msgBuffer )
289 {
290 auto fbs = GetTelem_stdcam_fb( msgBuffer );
291 if( fbs->roi() != nullptr )
292 return fbs->roi()->h();
293 else
294 return -1;
295 }
296
297 static int xbin( void *msgBuffer )
298 {
299 auto fbs = GetTelem_stdcam_fb( msgBuffer );
300 if( fbs->roi() != nullptr )
301 return fbs->roi()->xbin();
302 else
303 return -1;
304 }
305
306 static int ybin( void *msgBuffer )
307 {
308 auto fbs = GetTelem_stdcam_fb( msgBuffer );
309 if( fbs->roi() != nullptr )
310 return fbs->roi()->ybin();
311 else
312 return -1;
313 }
314
315 static float exptime( void *msgBuffer )
316 {
317 auto fbs = GetTelem_stdcam_fb( msgBuffer );
318 return fbs->exptime();
319 }
320
321 static float fps( void *msgBuffer )
322 {
323 auto fbs = GetTelem_stdcam_fb( msgBuffer );
324 return fbs->fps();
325 }
326
327 static float emGain( void *msgBuffer )
328 {
329 auto fbs = GetTelem_stdcam_fb( msgBuffer );
330 return fbs->emGain();
331 }
332
333 static float adcSpeed( void *msgBuffer )
334 {
335 auto fbs = GetTelem_stdcam_fb( msgBuffer );
336 return fbs->adcSpeed();
337 }
338
339 static float temp( void *msgBuffer )
340 {
341 auto fbs = GetTelem_stdcam_fb( msgBuffer );
342 if( fbs->tempCtrl() != nullptr )
343 return fbs->tempCtrl()->temp();
344 else
345 return -9999;
346 }
347
348 static float tempSetpt( void *msgBuffer )
349 {
350 auto fbs = GetTelem_stdcam_fb( msgBuffer );
351 if( fbs->tempCtrl() != nullptr )
352 return fbs->tempCtrl()->setpt();
353 else
354 return -9999;
355 }
356
357 static int tempStatus( void *msgBuffer )
358 {
359 auto fbs = GetTelem_stdcam_fb( msgBuffer );
360 if( fbs->tempCtrl() != nullptr )
361 return fbs->tempCtrl()->status();
362 else
363 return -9999;
364 }
365
366 static int tempOnTarget( void *msgBuffer )
367 {
368 auto fbs = GetTelem_stdcam_fb( msgBuffer );
369 if( fbs->tempCtrl() != nullptr )
370 return fbs->tempCtrl()->ontarget();
371 else
372 return -9999;
373 }
374
375 static std::string tempStatusStr( void *msgBuffer )
376 {
377 auto fbs = GetTelem_stdcam_fb( msgBuffer );
378 if( fbs->tempCtrl() != nullptr )
379 {
380 if( fbs->tempCtrl()->statusStr() )
381 return fbs->tempCtrl()->statusStr()->c_str();
382 else
383 return "";
384 }
385 else
386 return "";
387 }
388
389 static std::string shutterStatusStr( void *msgBuffer )
390 {
391 auto fbs = GetTelem_stdcam_fb( msgBuffer );
392 if( fbs->shutter() != nullptr )
393 {
394 if( fbs->shutter()->statusStr() )
395 return fbs->shutter()->statusStr()->c_str();
396 else
397 return "";
398 }
399 else
400 return "";
401 }
402
403 static std::string shutterState( void *msgBuffer )
404 {
405 auto fbs = GetTelem_stdcam_fb( msgBuffer );
406 if( fbs->shutter() != nullptr )
407 {
408 if( fbs->shutter()->state() == -1 )
409 return "UNKNOWN";
410 else if( fbs->shutter()->state() == 0 )
411 return "SHUT";
412 else if( fbs->shutter()->state() == 1 )
413 return "OPEN";
414 else
415 return "INVALID";
416 }
417 else
418 return "INVALID";
419 }
420
421 static bool synchro( void *msgBuffer )
422 {
423 auto fbs = GetTelem_stdcam_fb( msgBuffer );
424 return fbs->synchro();
425 }
426
427 static float vshift( void *msgBuffer )
428 {
429 auto fbs = GetTelem_stdcam_fb( msgBuffer );
430 return fbs->vshift();
431 }
432
433 static bool cropMode( void *msgBuffer )
434 {
435 auto fbs = GetTelem_stdcam_fb( msgBuffer );
436
437 // slightly different because define a default to indicated not-used.
438 if( fbs->cropMode() == 1 )
439 return true;
440 else
441 return false;
442 }
443
444 static std::string readout_speed( void *msgBuffer )
445 {
446 auto fbs = GetTelem_stdcam_fb( msgBuffer );
447 if( fbs->readout_speed() != nullptr )
448 {
449 return std::string( fbs->readout_speed()->c_str() );
450 }
451 else
452 return "";
453 }
454
455 static std::string fan_speed( void *msgBuffer )
456 {
457 auto fbs = GetTelem_stdcam_fb( msgBuffer );
458 if( fbs->fan_speed() != nullptr )
459 {
460 return std::string( fbs->fan_speed()->c_str() );
461 }
462 else
463 return "";
464 }
465
466 static std::string analog_gain( void *msgBuffer )
467 {
468 auto fbs = GetTelem_stdcam_fb( msgBuffer );
469 if( fbs->analog_gain() != nullptr )
470 {
471 return std::string( fbs->analog_gain()->c_str() );
472 }
473 else
474 return "";
475 }
476
477 static bool led( void *msgBuffer )
478 {
479 auto fbs = GetTelem_stdcam_fb( msgBuffer );
480
481 if( fbs->led() == 1 )
482 return true;
483 else
484 return false;
485 }
486
487 /// Get the logMetaDetail for a member by name
488 /**
489 * \returns the a logMetaDetail filled in with the appropriate details
490 * \returns an empty logMetaDetail if member not recognized
491 */
492 static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
493 {
494 if( member == "mode" )
495 return logMetaDetail(
496 { "MODE", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void *>( &mode ) } );
497 else if( member == "xcen" )
498 return logMetaDetail( { "ROI XCEN",
501 reinterpret_cast<void *>( &xcen ) } );
502 else if( member == "ycen" )
503 return logMetaDetail( { "ROI YCEN",
506 reinterpret_cast<void *>( &ycen ) } );
507 else if( member == "width" )
508 return logMetaDetail( { "ROI WIDTH",
511 reinterpret_cast<void *>( &width ) } );
512 else if( member == "height" )
513 return logMetaDetail( { "ROI HEIGHT",
516 reinterpret_cast<void *>( &height ) } );
517 else if( member == "xbin" )
518 return logMetaDetail(
519 { "ROI XBIN", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void *>( &xbin ) } );
520 else if( member == "ybin" )
521 return logMetaDetail(
522 { "ROI YBIN", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void *>( &ybin ) } );
523 else if( member == "exptime" )
524 return logMetaDetail( { "EXPTIME",
527 reinterpret_cast<void *>( &exptime ) } );
528 else if( member == "fps" )
529 return logMetaDetail(
530 { "FPS", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void *>( &fps ) } );
531 else if( member == "emGain" )
532 return logMetaDetail( { "EMGAIN",
535 reinterpret_cast<void *>( &emGain ) } );
536 else if( member == "adcSpeed" )
537 return logMetaDetail( { "ADC SPEED",
540 reinterpret_cast<void *>( &adcSpeed ) } );
541 else if( member == "temp" )
542 return logMetaDetail( { "TEMP",
545 reinterpret_cast<void *>( &temp ) } );
546 else if( member == "tempSetpt" )
547 return logMetaDetail( { "TEMP SETPT",
550 reinterpret_cast<void *>( &tempSetpt ) } );
551 else if( member == "tempStatus" )
552 return logMetaDetail( { "TEMP STATUS",
555 reinterpret_cast<void *>( &tempStatus ) } );
556 else if( member == "tempOnTarget" )
557 return logMetaDetail( { "TEMP ONTGT",
560 reinterpret_cast<void *>( &tempOnTarget ) } );
561 else if( member == "tempStatusStr" )
562 return logMetaDetail( { "TEMP STATUSSTR",
565 reinterpret_cast<void *>( &tempStatusStr ) } );
566 else if( member == "shutterStatusStr" )
567 return logMetaDetail( { "SHUTTER STATUS",
570 reinterpret_cast<void *>( &shutterStatusStr ) } );
571 else if( member == "shutterState" )
572 return logMetaDetail( { "SHUTTER",
575 reinterpret_cast<void *>( &shutterState ) } );
576 else if( member == "synchro" )
577 return logMetaDetail( { "SYNCHRO",
580 reinterpret_cast<void *>( &synchro ) } );
581 else if( member == "vshift" )
582 return logMetaDetail( { "VERT SHIFT SPEED",
585 reinterpret_cast<void *>( &vshift ) } );
586 else if( member == "cropMode" )
587 return logMetaDetail( { "CROP MODE",
590 reinterpret_cast<void *>( &cropMode ) } );
591 else if( member == "readout_speed" )
592 return logMetaDetail( { "READOUT SPEED",
595 reinterpret_cast<void *>( &readout_speed ) } );
596 else if( member == "fan_speed" )
597 return logMetaDetail( { "FAN SPEED",
600 reinterpret_cast<void *>( &fan_speed ) } );
601 else if( member == "analog_gain" )
602 return logMetaDetail( { "ANALOG GAIN",
605 reinterpret_cast<void *>( &analog_gain ) } );
606 else if( member == "led" )
607 return logMetaDetail(
608 { "LED", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void *>( &led ) } );
609 else
610 {
611 std::cerr << "No member " << member << " in telem_stdcam\n";
612 return logMetaDetail();
613 }
614 }
615
616}; // telem_stdcam
617
618} // namespace logger
619} // namespace MagAOX
620
621#endif // logger_types_telem_stdcam_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_STDCAM
Definition logCodes.hpp:53
const MagAOX::logger::Telem_stdcam_fb * GetTelem_stdcam_fb(const void *buf)
inline ::flatbuffers::Offset< Telem_stdcam_fb > CreateTelem_stdcam_fb(::flatbuffers::FlatBufferBuilder &_fbb, ::flatbuffers::Offset<::flatbuffers::String > mode=0, ::flatbuffers::Offset< MagAOX::logger::ROI > roi=0, float exptime=0.0f, float fps=0.0f, float emGain=0.0f, float adcSpeed=0.0f, ::flatbuffers::Offset< MagAOX::logger::TempCtrl > tempCtrl=0, ::flatbuffers::Offset< MagAOX::logger::Shutter > shutter=0, uint8_t synchro=0, float vshift=0.0f, int8_t cropMode=-1, ::flatbuffers::Offset<::flatbuffers::String > fan_speed=0, ::flatbuffers::Offset<::flatbuffers::String > readout_speed=0, ::flatbuffers::Offset<::flatbuffers::String > analog_gain=0, int8_t led=-1)
inline ::flatbuffers::Offset< ROI > CreateROI(::flatbuffers::FlatBufferBuilder &_fbb, float xcen=0.0f, float ycen=0.0f, int32_t w=0, int32_t h=0, int32_t xbin=0, int32_t ybin=0)
bool VerifyTelem_stdcam_fbBuffer(::flatbuffers::Verifier &verifier)
inline ::flatbuffers::Offset< TempCtrl > CreateTempCtrl(::flatbuffers::FlatBufferBuilder &_fbb, float temp=0.0f, float setpt=0.0f, bool status=false, bool ontarget=false, ::flatbuffers::Offset<::flatbuffers::String > statusStr=0)
inline ::flatbuffers::Offset< Shutter > CreateShutter(::flatbuffers::FlatBufferBuilder &_fbb, ::flatbuffers::Offset<::flatbuffers::String > statusStr=0, int32_t state=0)
Definition dm.hpp:19
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.
The type of the input message.
messageT(const std::string &mode, const float &xcen, const float &ycen, const int &width, const int &height, const int &xbin, const int &ybin, const float &exptime, const float &fps, const float &emGain, const float &adcSpeed, const float &temp, const float &setpt, const uint8_t &status, const uint8_t &ontarget, const std::string &statusStr, const std::string &shutterStatusSr, const int8_t &shutterState, const uint8_t &synchro, const float &vshift, const uint8_t &cropMode, const std::string &fan_speed, const std::string &readout_speed, const std::string &analog_gain, const int8_t &led)
Construct from components.
Log entry recording stdcam stage specific status.
static float temp(void *msgBuffer)
static bool synchro(void *msgBuffer)
static std::string shutterStatusStr(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static bool cropMode(void *msgBuffer)
static float vshift(void *msgBuffer)
static std::string shutterState(void *msgBuffer)
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
static float tempSetpt(void *msgBuffer)
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static std::string fan_speed(void *msgBuffer)
static int tempStatus(void *msgBuffer)
static const flatlogs::logPrioT defaultLevel
The default level.
static float adcSpeed(void *msgBuffer)
static int tempOnTarget(void *msgBuffer)
static std::string tempStatusStr(void *msgBuffer)
static float ycen(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static int height(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatted for human consumption.
static float fps(void *msgBuffer)
static float emGain(void *msgBuffer)
static std::string mode(void *msgBuffer)
static bool led(void *msgBuffer)
static std::string readout_speed(void *msgBuffer)
static std::string analog_gain(void *msgBuffer)
static int xbin(void *msgBuffer)
static float xcen(void *msgBuffer)
static int ybin(void *msgBuffer)
static float exptime(void *msgBuffer)
static int width(void *msgBuffer)