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