LCOV - code coverage report
Current view: top level - libMagAOX/logger/types - telem_stdcam.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 20.0 % 200 40
Test Date: 2026-01-03 21:03:39 Functions: 11.5 % 26 3

            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              : 
      22              : /// Log entry recording stdcam stage specific status.
      23              : /** \ingroup logger_types
      24              :   */
      25              : struct telem_stdcam : public flatbuffer_log
      26              : {
      27              :    ///The event code
      28              :    static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_STDCAM;
      29              : 
      30              :    ///The default level
      31              :    static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
      32              : 
      33              :    static timespec 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            1 :       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 & readout_speed     ///<[in]
      61              :               )
      62            1 :       {
      63            1 :          auto _mode = builder.CreateString(mode);
      64            1 :          auto _roi = CreateROI(builder,xcen, ycen, width, height, xbin, ybin);
      65              : 
      66            1 :          auto _statusStr = builder.CreateString(statusStr);
      67            1 :          auto _tempCtrl = CreateTempCtrl(builder, temp, setpt, status, ontarget, _statusStr);
      68              : 
      69            1 :          auto _shutterStatusStr = builder.CreateString(shutterStatusSr);
      70            1 :          auto _shutter = CreateShutter(builder, _shutterStatusStr, shutterState);
      71              : 
      72            1 :          auto _readoutSpeed = builder.CreateString(readout_speed);
      73              : 
      74            1 :          auto fp = CreateTelem_stdcam_fb(builder, _mode, _roi, exptime, fps, emGain, adcSpeed, _tempCtrl, _shutter, synchro, vshift, cropMode, _readoutSpeed);
      75            1 :          builder.Finish(fp);
      76            1 :       }
      77              : 
      78              :    };
      79              : 
      80            1 :    static bool verify( flatlogs::bufferPtrT & logBuff,  ///< [in] Buffer containing the flatbuffer serialized message.
      81              :                        flatlogs::msgLenT len            ///< [in] length of msgBuffer.
      82              :                      )
      83              :    {
      84            1 :       auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
      85            2 :       return VerifyTelem_stdcam_fbBuffer(verifier);
      86              :    }
      87              : 
      88              :    ///Get the message formatted for human consumption.
      89            0 :    static std::string msgString( void * msgBuffer,  /**< [in] Buffer containing the flatbuffer serialized message.*/
      90              :                                  flatlogs::msgLenT len  /**< [in] [unused] length of msgBuffer.*/
      91              :                                )
      92              :    {
      93              :       static_cast<void>(len);
      94              : 
      95            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
      96              : 
      97            0 :       std::string msg = "[stdcam] ";
      98              : 
      99            0 :       if(fbs->mode() != nullptr)
     100              :       {
     101            0 :          msg+= "mode: ";
     102            0 :          msg += fbs->mode()->c_str();
     103            0 :          msg += " ";
     104              :       }
     105              : 
     106            0 :       if(fbs->roi() != nullptr)
     107              :       {
     108            0 :          msg += "ROI-x: ";
     109            0 :          msg += std::to_string(fbs->roi()->xcen());
     110            0 :          msg += " y: ";
     111            0 :          msg += std::to_string(fbs->roi()->ycen());
     112            0 :          msg += " w: ";
     113            0 :          msg += std::to_string(fbs->roi()->w());
     114            0 :          msg += " h: ";
     115            0 :          msg += std::to_string(fbs->roi()->h());
     116            0 :          msg += " xbin: ";
     117            0 :          msg += std::to_string(fbs->roi()->xbin());
     118            0 :          msg += " ybin: ";
     119            0 :          msg += std::to_string(fbs->roi()->ybin());
     120            0 :          msg += " ";
     121              :       }
     122              : 
     123            0 :       msg += "expt: ";
     124            0 :       msg += std::to_string(fbs->exptime());
     125            0 :       msg += " fps: ";
     126            0 :       msg += std::to_string(fbs->fps());
     127            0 :       msg += " emG: ";
     128            0 :       msg += std::to_string(fbs->emGain());
     129            0 :       msg += " adc: ";
     130            0 :       msg += std::to_string(fbs->adcSpeed());
     131              : 
     132            0 :       if(fbs->tempCtrl() != nullptr)
     133              :       {
     134            0 :          msg += " temp: ";
     135            0 :          msg += std::to_string(fbs->tempCtrl()->temp());
     136            0 :          msg += " setpt: ";
     137            0 :          msg += std::to_string(fbs->tempCtrl()->setpt());
     138            0 :          msg += " tempctr-stat: ";
     139            0 :          msg += std::to_string(fbs->tempCtrl()->status());
     140            0 :          msg += " tempctr-ontgt: ";
     141            0 :          msg += std::to_string(fbs->tempCtrl()->ontarget());
     142              : 
     143            0 :          if(fbs->tempCtrl()->statusStr())
     144              :          {
     145            0 :             msg += " tempctr-statstr: ";
     146            0 :             msg += fbs->tempCtrl()->statusStr()->c_str();
     147              :          }
     148              :       }
     149              : 
     150            0 :       if(fbs->shutter() != nullptr)
     151              :       {
     152            0 :          if(fbs->shutter()->statusStr())
     153              :          {
     154            0 :             msg += " shutter-statstr: ";
     155            0 :             msg += fbs->shutter()->statusStr()->c_str();
     156              :          }
     157            0 :          msg+= " shutter: ";
     158            0 :          if( fbs->shutter()->state() == -1)
     159              :          {
     160            0 :             msg += "UNKN";
     161              :          }
     162            0 :          else if( fbs->shutter()->state() == 0)
     163              :          {
     164            0 :             msg += "SHUT";
     165              :          }
     166            0 :          else if( fbs->shutter()->state() == 1)
     167              :          {
     168            0 :             msg += "OPEN";
     169              :          }
     170              :       }
     171              : 
     172            0 :       msg += " Sync: ";
     173            0 :       if(fbs->synchro()) msg += "ON";
     174            0 :       else msg += "OFF";
     175              : 
     176            0 :       msg += " vshift: ";
     177            0 :       if(fbs->vshift() == 0) msg += "---";
     178            0 :       else msg += std::to_string(fbs->vshift());
     179              : 
     180            0 :       msg += " crop: ";
     181            0 :       if(fbs->cropMode()==-1) msg += "---";
     182            0 :       else if(fbs->cropMode()==1) msg += "ON";
     183            0 :       else msg += "OFF";
     184              : 
     185            0 :       if(fbs->readout_speed() != nullptr)
     186              :       {
     187            0 :          if(fbs->readout_speed()->size() > 0)
     188              :          {
     189            0 :             msg += " rospd: ";
     190            0 :             msg += fbs->readout_speed()->c_str();
     191              :          }
     192              :       }
     193              : 
     194            0 :       return msg;
     195              : 
     196            0 :    }
     197              : 
     198            0 :    static std::string mode( void * msgBuffer )
     199              :    {
     200            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     201            0 :       if(fbs->mode() != nullptr)
     202              :       {
     203            0 :          return std::string(fbs->mode()->c_str());
     204              :       }
     205            0 :       else return "";
     206              :    }
     207              : 
     208            0 :    static float xcen( void * msgBuffer )
     209              :    {
     210            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     211            0 :       if(fbs->roi() != nullptr) return fbs->roi()->xcen();
     212            0 :       else return -1;
     213              :    }
     214              : 
     215            0 :    static float ycen( void * msgBuffer )
     216              :    {
     217            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     218            0 :       if(fbs->roi() != nullptr) return fbs->roi()->ycen();
     219            0 :       else return -1;
     220              :    }
     221              : 
     222            0 :    static int width( void * msgBuffer )
     223              :    {
     224            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     225            0 :       if(fbs->roi() != nullptr) return fbs->roi()->w();
     226            0 :       else return -1;
     227              :    }
     228              : 
     229            0 :    static int height( void * msgBuffer )
     230              :    {
     231            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     232            0 :       if(fbs->roi() != nullptr) return fbs->roi()->h();
     233            0 :       else return -1;
     234              :    }
     235              : 
     236            0 :    static int xbin( void * msgBuffer )
     237              :    {
     238            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     239            0 :       if(fbs->roi() != nullptr) return fbs->roi()->xbin();
     240            0 :       else return -1;
     241              :    }
     242              : 
     243            0 :    static int ybin( void * msgBuffer )
     244              :    {
     245            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     246            0 :       if(fbs->roi() != nullptr) return fbs->roi()->ybin();
     247            0 :       else return -1;
     248              :    }
     249              : 
     250            0 :    static float exptime( void * msgBuffer )
     251              :    {
     252            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     253            0 :       return fbs->exptime();
     254              :    }
     255              : 
     256            0 :    static float fps( void * msgBuffer )
     257              :    {
     258            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     259            0 :       return fbs->fps();
     260              :    }
     261              : 
     262            0 :    static float emGain( void * msgBuffer )
     263              :    {
     264            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     265            0 :       return fbs->emGain();
     266              :    }
     267              : 
     268            0 :    static float adcSpeed( void * msgBuffer )
     269              :    {
     270            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     271            0 :       return fbs->adcSpeed();
     272              :    }
     273              : 
     274            0 :    static float temp( void * msgBuffer )
     275              :    {
     276            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     277            0 :       if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->temp();
     278            0 :       else return -9999;
     279              :    }
     280              : 
     281            0 :    static float tempSetpt( void * msgBuffer )
     282              :    {
     283            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     284            0 :       if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->setpt();
     285            0 :       else return -9999;
     286              :    }
     287              : 
     288            0 :    static int tempStatus( void * msgBuffer )
     289              :    {
     290            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     291            0 :       if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->status();
     292            0 :       else return -9999;
     293              :    }
     294              : 
     295            0 :    static int tempOnTarget( void * msgBuffer )
     296              :    {
     297            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     298            0 :       if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->ontarget();
     299            0 :       else return -9999;
     300              :    }
     301              : 
     302            0 :    static std::string tempStatusStr( void * msgBuffer )
     303              :    {
     304            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     305            0 :       if(fbs->tempCtrl() != nullptr)
     306              :       {
     307            0 :          if(fbs->tempCtrl()->statusStr()) return fbs->tempCtrl()->statusStr()->c_str();
     308            0 :          else return "";
     309              :       }
     310            0 :       else return "";
     311              :    }
     312              : 
     313            0 :    static std::string shutterStatusStr( void * msgBuffer)
     314              :    {
     315            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     316            0 :       if(fbs->shutter() != nullptr)
     317              :       {
     318            0 :          if(fbs->shutter()->statusStr()) return fbs->shutter()->statusStr()->c_str();
     319            0 :          else return "";
     320              :       }
     321            0 :       else return "";
     322              :    }
     323              : 
     324            0 :    static std::string shutterState( void * msgBuffer )
     325              :    {
     326            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     327            0 :       if(fbs->shutter() != nullptr)
     328              :       {
     329            0 :          if( fbs->shutter()->state() == -1) return "UNKNOWN";
     330            0 :          else if( fbs->shutter()->state() == 0) return "SHUT";
     331            0 :          else if( fbs->shutter()->state() == 1) return "OPEN";
     332            0 :          else return "INVALID";
     333              :       }
     334            0 :       else return "INVALID";
     335              :    }
     336              : 
     337            0 :    static bool synchro( void * msgBuffer )
     338              :    {
     339            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     340            0 :       return fbs->synchro();
     341              :    }
     342              : 
     343            0 :    static float vshift( void * msgBuffer )
     344              :    {
     345            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     346            0 :       return fbs->vshift();
     347              :    }
     348              : 
     349            0 :    static bool cropMode( void * msgBuffer )
     350              :    {
     351            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     352              : 
     353              :       //slightly different because define a default to indicated not-used.
     354            0 :       if(fbs->cropMode() == 1) return true;
     355            0 :       else return false;
     356              :    }
     357              : 
     358            0 :    static std::string readout_speed( void * msgBuffer )
     359              :    {
     360            0 :       auto fbs = GetTelem_stdcam_fb(msgBuffer);
     361            0 :       if(fbs->readout_speed() != nullptr)
     362              :       {
     363            0 :          return std::string(fbs->readout_speed()->c_str());
     364              :       }
     365            0 :       else return "";
     366              :    }
     367              : 
     368              :    /// Get the logMetaDetail for a member by name
     369              :    /**
     370              :      * \returns the a logMetaDetail filled in with the appropriate details
     371              :      * \returns an empty logMetaDetail if member not recognized
     372              :      */
     373            1 :    static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
     374              :    {
     375            1 :       if(member == "mode") return logMetaDetail({"MODE", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&mode)});
     376            1 :       else if(member == "xcen") return logMetaDetail({"ROI XCEN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&xcen)});
     377            1 :       else if(member == "ycen") return logMetaDetail({"ROI YCEN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&ycen)});
     378            1 :       else if(member == "width") return logMetaDetail({"ROI WIDTH", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&width)});
     379            1 :       else if(member == "height") return logMetaDetail({"ROI HEIGHT", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&height)});
     380            1 :       else if(member == "xbin") return logMetaDetail({"ROI XBIN", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&xbin)});
     381            1 :       else if(member == "ybin") return logMetaDetail({"ROI YBIN", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&ybin)});
     382            1 :       else if(member == "exptime") return logMetaDetail({"EXPTIME", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&exptime)});
     383            1 :       else if(member == "fps") return logMetaDetail({"FPS", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&fps)});
     384            1 :       else if(member == "emGain") return logMetaDetail({"EMGAIN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&emGain)});
     385            1 :       else if(member == "adcSpeed") return logMetaDetail({"ADC SPEED", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&adcSpeed)});
     386            1 :       else if(member == "temp") return logMetaDetail({"TEMP", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&temp)});
     387            1 :       else if(member == "tempSetpt") return logMetaDetail({"TEMP SETPT", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&tempSetpt)});
     388            1 :       else if(member == "tempStatus") return logMetaDetail({"TEMP STATUS", logMeta::valTypes::Int, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&tempStatus)});
     389            1 :       else if(member == "tempOnTarget") return logMetaDetail({"TEMP ONTGT", logMeta::valTypes::Int, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&tempOnTarget)});
     390            1 :       else if(member == "tempStatusStr") return logMetaDetail({"TEMP STATUSSTR", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&tempStatusStr)});
     391            1 :       else if(member == "shutterStatusStr") return logMetaDetail({"SHUTTER STATUS", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&shutterStatusStr)});
     392            1 :       else if(member == "shutterState") return logMetaDetail({"SHUTTER", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&shutterState)});
     393            1 :       else if(member == "synchro") return logMetaDetail({"SYNCHRO", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&synchro)});
     394            1 :       else if(member == "vshift") return logMetaDetail({"VERT SHIFT SPEED", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&vshift)});
     395            1 :       else if(member == "cropMode") return logMetaDetail({"CROP MODE", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&cropMode)});
     396            1 :       else if(member == "readout_speed") return logMetaDetail({"READOUT SPEED", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&readout_speed)});
     397              :       else
     398              :       {
     399            1 :          std::cerr << "No member " << member << " in telem_stdcam\n";
     400            1 :          return logMetaDetail();
     401              :       }
     402              :    }
     403              : 
     404              : }; //telem_stdcam
     405              : 
     406              : 
     407              : 
     408              : } //namespace logger
     409              : } //namespace MagAOX
     410              : 
     411              : #endif //logger_types_telem_stdcam_hpp
     412              : 
        

Generated by: LCOV version 2.0-1