LCOV - code coverage report
Current view: top level - libMagAOX/logger/types - telem_w2tcsoffloader.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 29.4 % 34 10
Test Date: 2026-04-15 19:34:29 Functions: 40.0 % 5 2

            Line data    Source code
       1              : /** \file telem_w2tcsoffloader.hpp
       2              :  * \brief The MagAO-X logger telem_w2tcsoffloader log type.
       3              :  *
       4              :  * \ingroup logger_types_files
       5              :  *
       6              :  */
       7              : #ifndef logger_types_telem_w2tcsoffloader_hpp
       8              : #define logger_types_telem_w2tcsoffloader_hpp
       9              : 
      10              : #include "generated/telem_w2tcsoffloader_generated.h"
      11              : #include "flatbuffer_log.hpp"
      12              : 
      13              : namespace MagAOX
      14              : {
      15              : namespace logger
      16              : {
      17              : 
      18              : /// Log entry recording the woofer-to-TCS Zernike coefficient vector.
      19              : /** \ingroup logger_types
      20              :  */
      21              : struct telem_w2tcsoffloader : public flatbuffer_log
      22              : {
      23              :     /// The event code.
      24              :     static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_W2TCSOFFLOADER;
      25              : 
      26              :     /// The default level.
      27              :     static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
      28              : 
      29              :     static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
      30              : 
      31              :     /// The type of the input message.
      32              :     struct messageT : public fbMessage
      33              :     {
      34              :         /// Construct from components.
      35            1 :         explicit messageT( const std::vector<float> &coeffs /**< [in] the offloaded Zernike coefficients */ )
      36            1 :         {
      37            1 :             auto coeffVec = builder.CreateVector( coeffs );
      38            1 :             auto fp       = CreateTelem_w2tcsoffloader_fb( builder, coeffVec );
      39              : 
      40            1 :             builder.Finish( fp );
      41            1 :         }
      42              :     };
      43              : 
      44            1 :     static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
      45              :                         flatlogs::msgLenT     len      ///< [in] length of msgBuffer.
      46              :     )
      47              :     {
      48            1 :         auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
      49            1 :                                                static_cast<size_t>( len ) );
      50            2 :         return VerifyTelem_w2tcsoffloader_fbBuffer( verifier );
      51              :     }
      52              : 
      53              :     /// Get the message formatted for human consumption.
      54            0 :     static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message. */
      55              :                                   flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer. */
      56              :     )
      57              :     {
      58              :         static_cast<void>( len );
      59              : 
      60            0 :         auto fbs = GetTelem_w2tcsoffloader_fb( msgBuffer );
      61              : 
      62            0 :         std::string msg = "[w2tcsoffloader coeffs] ";
      63              : 
      64            0 :         if( fbs->coeffs() != nullptr )
      65              :         {
      66            0 :             for( flatbuffers::Vector<float>::const_iterator it = fbs->coeffs()->begin(); it != fbs->coeffs()->end();
      67            0 :                  ++it )
      68              :             {
      69            0 :                 msg += std::to_string( *it );
      70            0 :                 msg += " ";
      71              :             }
      72              :         }
      73              : 
      74            0 :         return msg;
      75            0 :     }
      76              : 
      77              :     /// Recover the coefficient vector from a serialized message.
      78            0 :     static std::vector<float> coeffs( void *msgBuffer )
      79              :     {
      80            0 :         std::vector<float> coeffVec;
      81            0 :         auto               fbs = GetTelem_w2tcsoffloader_fb( msgBuffer );
      82              : 
      83            0 :         if( fbs->coeffs() != nullptr )
      84              :         {
      85            0 :             for( flatbuffers::Vector<float>::const_iterator it = fbs->coeffs()->begin(); it != fbs->coeffs()->end();
      86            0 :                  ++it )
      87              :             {
      88            0 :                 coeffVec.push_back( *it );
      89              :             }
      90              :         }
      91              : 
      92            0 :         return coeffVec;
      93            0 :     }
      94              : 
      95              :     /// Get the logMetaDetail for a member by name.
      96              :     /**
      97              :      * \returns a logMetaDetail filled in with the appropriate details
      98              :      * \returns an empty logMetaDetail if member not recognized
      99              :      */
     100            0 :     static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
     101              :     {
     102            0 :         if( member == "coeffs" )
     103              :         {
     104              :             return logMetaDetail( { "COEFFS",
     105              :                                     logMeta::valTypes::Vector_Float,
     106              :                                     logMeta::metaTypes::Continuous,
     107              :                                     reinterpret_cast<void *>( &coeffs ),
     108            0 :                                     false } );
     109              :         }
     110              :         else
     111              :         {
     112            0 :             std::cerr << "No member " << member << " in telem_w2tcsoffloader\n";
     113            0 :             return logMetaDetail();
     114              :         }
     115              :     }
     116              : 
     117              : }; // struct telem_w2tcsoffloader
     118              : 
     119              : } // namespace logger
     120              : } // namespace MagAOX
     121              : 
     122              : #endif // logger_types_telem_w2tcsoffloader_hpp
        

Generated by: LCOV version 2.0-1