LCOV - code coverage report
Current view: top level - libMagAOX/logger/types - telem_pokecenter.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 31.1 % 103 32
Test Date: 2026-01-03 21:03:39 Functions: 40.0 % 10 4

            Line data    Source code
       1              : /** \file telem_pokecenter.hpp
       2              :  * \brief The MagAO-X logger telem_pokecenter log type.
       3              :  * \author Jared R. Males (jaredmales@gmail.com)
       4              :  *
       5              :  * \ingroup logger_types_files
       6              :  *
       7              :  */
       8              : #ifndef logger_types_telem_pokecenter_hpp
       9              : #define logger_types_telem_pokecenter_hpp
      10              : 
      11              : #include "generated/telem_pokecenter_generated.h"
      12              : #include "flatbuffer_log.hpp"
      13              : 
      14              : namespace MagAOX
      15              : {
      16              : namespace logger
      17              : {
      18              : 
      19              : /// Log entry recording DM poke centering results
      20              : /** \ingroup logger_types
      21              :  */
      22              : struct telem_pokecenter : public flatbuffer_log
      23              : {
      24              :     /// The event code
      25              :     static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_POKECENTER;
      26              : 
      27              :     /// The default level
      28              :     static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
      29              : 
      30              :     static timespec lastRecord; ///< The time of the last time this log was recorded.  Used by the telemetry system.
      31              : 
      32              :     /// The type of the input message
      33              :     struct messageT : public fbMessage
      34              :     {
      35              :         /// Construct from components
      36            1 :         messageT( const uint8_t            &measuring, ///<[in] whether or not measurements are in progress
      37              :                   const float              &pupil_x,   ///<[in] the pupil x position
      38              :                   const float              &pupil_y,   ///<[in] the pupil y position
      39              :                   const std::vector<float> &poke_x,    ///<[in] the poke x positions, last one the average
      40              :                   const std::vector<float> &poke_y     ///<[in] the poke y positions, last one the average
      41              :         )
      42            1 :         {
      43            1 :             if( measuring == 0 )
      44              :             {
      45            0 :                 Telem_pokecenter_fbBuilder telem_pokecenter_builder( builder );
      46            0 :                 telem_pokecenter_builder.add_measuring( measuring );
      47            0 :                 auto fb = telem_pokecenter_builder.Finish();
      48            0 :                 builder.Finish( fb );
      49            0 :                 return;
      50              :             }
      51              : 
      52            1 :             auto _poke_xs = builder.CreateVector( poke_x );
      53            1 :             auto _poke_ys = builder.CreateVector( poke_y );
      54              : 
      55            1 :             auto fb = CreateTelem_pokecenter_fb( builder, measuring, pupil_x, pupil_y, _poke_xs, _poke_ys );
      56              : 
      57            1 :             builder.Finish( fb );
      58            0 :         }
      59              : 
      60              :         /// Construct from components with single vector for pokes
      61            1 :         messageT( const uint8_t            &measuring, ///<[in] whether or not measurements are in progress
      62              :                   const float              &pupil_x,   ///<[in] the pupil x position
      63              :                   const float              &pupil_y,   ///<[in] the pupil y position
      64              :                   const std::vector<float> &pokes      ///<[in] the combined poke positions, last two the averages
      65              :         )
      66            1 :         {
      67            1 :             if( measuring == 0 )
      68              :             {
      69            0 :                 Telem_pokecenter_fbBuilder telem_pokecenter_builder( builder );
      70            0 :                 telem_pokecenter_builder.add_measuring( measuring );
      71            0 :                 auto fb = telem_pokecenter_builder.Finish();
      72            0 :                 builder.Finish( fb );
      73            0 :                 return;
      74              :             }
      75              : 
      76            2 :             std::vector<float> poke_x( pokes.size() / 2 );
      77            1 :             std::vector<float> poke_y( pokes.size() / 2 );
      78              : 
      79            6 :             for( size_t n = 0; n < poke_x.size(); ++n )
      80              :             {
      81            5 :                 poke_x[n] = pokes[2 * n + 0];
      82            5 :                 poke_y[n] = pokes[2 * n + 1];
      83              :             }
      84              : 
      85            1 :             auto _poke_xs = builder.CreateVector( poke_x );
      86            1 :             auto _poke_ys = builder.CreateVector( poke_y );
      87              : 
      88            1 :             auto fb = CreateTelem_pokecenter_fb( builder, measuring, pupil_x, pupil_y, _poke_xs, _poke_ys );
      89              : 
      90            1 :             builder.Finish( fb );
      91            1 :         }
      92              :     };
      93              : 
      94            2 :     static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
      95              :                         flatlogs::msgLenT     len      ///< [in] length of msgBuffer.
      96              :     )
      97              :     {
      98            2 :         auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
      99            2 :                                                static_cast<size_t>( len ) );
     100            4 :         return VerifyTelem_pokecenter_fbBuffer( verifier );
     101              :     }
     102              : 
     103              :     /// Get the message formatted for human consumption.
     104            0 :     static std::string msgString( void *msgBuffer,      /**< [in] Buffer containing the flatbuffer serialized message.*/
     105              :                                   flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
     106              :     )
     107              :     {
     108              :         static_cast<void>( len );
     109              : 
     110            0 :         auto fbs = GetTelem_pokecenter_fb( msgBuffer );
     111              : 
     112            0 :         std::string msg;
     113            0 :         if( fbs->measuring() == 0 )
     114              :         {
     115            0 :             msg = "not measuring";
     116            0 :             return msg;
     117              :         }
     118              : 
     119            0 :         if( fbs->measuring() == 1 )
     120              :         {
     121            0 :             msg = "single ";
     122              :         }
     123              :         else
     124              :         {
     125            0 :             msg = "continuous ";
     126              :         }
     127              : 
     128            0 :         msg += "[pupil] ";
     129              : 
     130            0 :         msg += std::to_string( fbs->pupil_x() );
     131            0 :         msg += " ";
     132            0 :         msg += std::to_string( fbs->pupil_y() );
     133              : 
     134              :         // being very paranoid about existence and length here
     135            0 :         if( fbs->poke_x() && fbs->poke_y() )
     136              :         {
     137            0 :             if( fbs->poke_x()->size() == fbs->poke_y()->size() )
     138              :             {
     139            0 :                 size_t N = fbs->poke_x()->size();
     140              : 
     141            0 :                 msg += " [poke-avg] ";
     142            0 :                 msg += std::to_string( fbs->poke_x()->Get( N - 1 ) );
     143            0 :                 msg += " ";
     144            0 :                 msg += std::to_string( fbs->poke_y()->Get( N - 1 ) );
     145              : 
     146            0 :                 msg += " [pokes]";
     147            0 :                 for( size_t i = 0; i < N - 1; ++i )
     148              :                 {
     149            0 :                     msg += " ";
     150            0 :                     msg += std::to_string( fbs->poke_x()->Get( i ) );
     151            0 :                     msg += " ";
     152            0 :                     msg += std::to_string( fbs->poke_y()->Get( i ) );
     153              :                 }
     154              :             }
     155              :             else
     156              :             {
     157            0 :                 msg += " [poke-avg] ? [pokes] ?";
     158              :             }
     159              :         }
     160              :         else
     161              :         {
     162            0 :             msg += " [poke-avg] ? [pokes] ?";
     163              :         }
     164              : 
     165            0 :         return msg;
     166            0 :     }
     167              : 
     168            0 :     static bool measuring( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
     169              :     {
     170            0 :         auto fbs = GetTelem_pokecenter_fb( msgBuffer );
     171            0 :         return fbs->measuring();
     172              :     }
     173              : 
     174            0 :     static float pupil_x( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
     175              :     {
     176            0 :         auto fbs = GetTelem_pokecenter_fb( msgBuffer );
     177            0 :         return fbs->pupil_x();
     178              :     }
     179              : 
     180            0 :     static float pupil_y( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
     181              :     {
     182            0 :         auto fbs = GetTelem_pokecenter_fb( msgBuffer );
     183            0 :         return fbs->pupil_y();
     184              :     }
     185              : 
     186            0 :     static std::vector<float> poke_x( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
     187              :     {
     188            0 :         std::vector<float> p;
     189              : 
     190            0 :         auto fbs = GetTelem_pokecenter_fb( msgBuffer );
     191              : 
     192            0 :         if( fbs->poke_x() != nullptr )
     193              :         {
     194            0 :             for( auto it = fbs->poke_x()->begin(); it != fbs->poke_x()->end(); ++it )
     195              :             {
     196            0 :                 p.push_back( *it );
     197              :             }
     198              :         }
     199            0 :         return p;
     200            0 :     }
     201              : 
     202            0 :     static std::vector<float> poke_y( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
     203              :     {
     204            0 :         std::vector<float> p;
     205              : 
     206            0 :         auto fbs = GetTelem_pokecenter_fb( msgBuffer );
     207              : 
     208            0 :         if( fbs->poke_y() != nullptr )
     209              :         {
     210            0 :             for( auto it = fbs->poke_y()->begin(); it != fbs->poke_y()->end(); ++it )
     211              :             {
     212            0 :                 p.push_back( *it );
     213              :             }
     214              :         }
     215            0 :         return p;
     216            0 :     }
     217              : 
     218              :     /// Get the logMetaDetail for a member by name
     219              :     /**
     220              :      * \returns the a logMetaDetail filled in with the appropriate details
     221              :      * \returns an empty logMetaDetail if member not recognized
     222              :      */
     223            1 :     static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
     224              :     {
     225            1 :         if( member == "measuring" )
     226              :             return logMetaDetail( { "MEASURING",
     227              :                                     "measuring state",
     228              :                                     logMeta::valTypes::Bool,
     229              :                                     logMeta::metaTypes::State,
     230              :                                     reinterpret_cast<void *>( &measuring ),
     231            0 :                                     false } );
     232            1 :         else if( member == "pupil_x" )
     233              :             return logMetaDetail( { "PUPIL X",
     234              :                                     "measured pupil x",
     235              :                                     logMeta::valTypes::Float,
     236              :                                     logMeta::metaTypes::State,
     237              :                                     reinterpret_cast<void *>( &pupil_x ),
     238            0 :                                     false } );
     239            1 :         else if( member == "pupil_y" )
     240              :             return logMetaDetail( { "PUPIL Y",
     241              :                                     "measured pupil y",
     242              :                                     logMeta::valTypes::Float,
     243              :                                     logMeta::metaTypes::State,
     244              :                                     reinterpret_cast<void *>( &pupil_y ),
     245            0 :                                     false } );
     246            1 :         else if( member == "poke_x" )
     247              :             return logMetaDetail( { "POKE X",
     248              :                                     "actuator poke x, last is avg",
     249              :                                     logMeta::valTypes::Vector_Float,
     250              :                                     logMeta::metaTypes::State,
     251              :                                     reinterpret_cast<void *>( &poke_x ),
     252            0 :                                     false } );
     253            1 :         else if( member == "poke_y" )
     254              :             return logMetaDetail( { "POKE Y",
     255              :                                     "actuator poke y, last is avg",
     256              :                                     logMeta::valTypes::Vector_Float,
     257              :                                     logMeta::metaTypes::State,
     258              :                                     reinterpret_cast<void *>( &poke_y ),
     259            0 :                                     false } );
     260              :         else
     261              :         {
     262            1 :             std::cerr << "No member " << member << " in telem_pokecenter\n";
     263            1 :             return logMetaDetail();
     264              :         }
     265              :     }
     266              : 
     267              : }; // telem_pokecenter
     268              : 
     269              : } // namespace logger
     270              : } // namespace MagAOX
     271              : 
     272              : #endif // logger_types_telem_pokecenter_hpp
        

Generated by: LCOV version 2.0-1