LCOV - code coverage report
Current view: top level - libMagAOX/logger/types - telem_fxngen.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 23.6 % 55 13
Test Date: 2026-01-03 21:03:39 Functions: 50.0 % 6 3

            Line data    Source code
       1              : /** \file telem_fxngen.hpp
       2              :   * \brief The MagAO-X logger telem_fxngen 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_fxngen_hpp
      11              : #define logger_types_telem_fxngen_hpp
      12              : 
      13              : #include "generated/telem_fxngen_generated.h"
      14              : #include "flatbuffer_log.hpp"
      15              : 
      16              : #define TELEM_FXNGEN_WVTP_DC (0)
      17              : #define TELEM_FXNGEN_WVTP_SINE (1)
      18              : #define TELEM_FXNGEN_WVTP_PULSE (2)
      19              : 
      20              : namespace MagAOX
      21              : {
      22              : namespace logger
      23              : {
      24              : 
      25              : 
      26              : /// Log entry recording the function generator parameters
      27              : /** \ingroup logger_types
      28              :   */
      29              : struct telem_fxngen : public flatbuffer_log
      30              : {
      31              :     ///The event code
      32              :     static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_FXNGEN;
      33              : 
      34              :     ///The default level
      35              :     static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
      36              : 
      37              :     static timespec lastRecord; ///< The timestamp of the last time this log was recorded.  Used by the telemetry system.
      38              : 
      39              : 
      40              : 
      41              : 
      42              :    ///The type of the input message
      43              :    struct messageT : public fbMessage
      44              :    {
      45              :       ///Construct from components
      46            1 :       messageT( const uint8_t & C1outp, ///< [in] Channel 1 output status
      47              :                 const double & C1freq,  ///< [in] Channel 1 frequency [Hz]
      48              :                 const double & C1vpp,   ///< [in] Channel 1 P2P voltage [V]
      49              :                 const double & C1ofst,  ///< [in] Channel 1 offset [V]
      50              :                 const double & C1phse,  ///< [in] Channel 1 phase [deg]
      51              :                 const uint8_t & C1wvtp, ///< [in] Channel 1 wavetype (SINE or DC)
      52              :                 const uint8_t & C2outp, ///< [in] Channel 2 output status
      53              :                 const double & C2freq,  ///< [in] Channel 2 frequency [Hz]
      54              :                 const double & C2vpp,   ///< [in] Channel 2 P2P voltage [V]
      55              :                 const double & C2ofst,  ///< [in] Channel 2 offset [V]
      56              :                 const double & C2phse,  ///< [in] Channel 2 phase [deg]
      57              :                 const uint8_t & C2wvtp, ///< [in] Channel 2 wavetype  (SINE or DC)
      58              :                 const uint8_t & C1sync, ///< [in] Channel 1 sync status
      59              :                 const uint8_t & C2sync, ///< [in] Channel 2 sync status
      60              :                 const double & C1wdth,  ///< [in] Channel 1 width [s]
      61              :                 const double & C2wdth   ///< [in] Channel 2 width [s]
      62              :               )
      63            1 :       {
      64            1 :          auto fp = CreateTelem_fxngen_fb(builder, C1outp, C1freq, C1vpp, C1ofst, C1phse, C1wvtp,
      65              :                                                C2outp, C2freq, C2vpp, C2ofst, C2phse, C2wvtp, C1sync, C2sync, C1wdth, C2wdth);
      66            1 :          builder.Finish(fp);
      67            1 :       }
      68              : 
      69              :    };
      70              : 
      71            1 :    static bool verify( flatlogs::bufferPtrT & logBuff,  ///< [in] Buffer containing the flatbuffer serialized message.
      72              :                        flatlogs::msgLenT len            ///< [in] length of msgBuffer.
      73              :                      )
      74              :    {
      75            1 :       auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
      76            2 :       return VerifyTelem_fxngen_fbBuffer(verifier);
      77              :    }
      78              : 
      79              :    ///Get the message formatte for human consumption.
      80            0 :    static std::string msgString( void * msgBuffer,  /**< [in] Buffer containing the flatbuffer serialized message.*/
      81              :                                  flatlogs::msgLenT len  /**< [in] [unused] length of msgBuffer.*/
      82              :                                )
      83              :    {
      84              :       static_cast<void>(len);
      85              : 
      86            0 :       auto fbs = GetTelem_fxngen_fb(msgBuffer);
      87              : 
      88            0 :       std::string msg = "Ch 1: ";
      89              : 
      90            0 :       if(fbs->C1wvtp() == TELEM_FXNGEN_WVTP_DC) msg += "DC ";
      91            0 :       else if(fbs->C1wvtp() == TELEM_FXNGEN_WVTP_SINE) msg += "SINE ";
      92            0 :       else if(fbs->C1wvtp() == TELEM_FXNGEN_WVTP_PULSE) msg += "PULSE ";
      93            0 :       else msg += "UNK ";
      94              : 
      95            0 :       if(fbs->C1outp() == 0) msg += "OFF ";
      96            0 :       else if(fbs->C1outp() == 1) msg += "ON ";
      97            0 :       else msg += "UNK ";
      98              : 
      99            0 :       msg += std::to_string(fbs->C1freq()) + " Hz ";
     100            0 :       msg += std::to_string(fbs->C1vpp()) + " Vp2p ";
     101            0 :       msg += std::to_string(fbs->C1ofst()) + " V ";
     102            0 :       msg += std::to_string(fbs->C1phse()) + " deg ";
     103            0 :       msg += std::to_string(fbs->C1wdth()) + " s ";
     104            0 :       msg += "SYNC ";
     105            0 :       if(fbs->C1sync()) msg += "ON ";
     106            0 :       else msg += "OFF ";
     107              : 
     108            0 :       msg += " | Ch 2: ";
     109              : 
     110            0 :       if(fbs->C2wvtp() == TELEM_FXNGEN_WVTP_DC) msg += "DC ";
     111            0 :       else if(fbs->C2wvtp() == TELEM_FXNGEN_WVTP_SINE) msg += "SINE ";
     112            0 :       else if(fbs->C2wvtp() == TELEM_FXNGEN_WVTP_PULSE) msg += "PULSE ";
     113            0 :       else msg += "UNK ";
     114              : 
     115            0 :       if(fbs->C2outp() == 0) msg += "OFF ";
     116            0 :       else if(fbs->C2outp() == 1) msg += "ON ";
     117            0 :       else msg += "UNK ";
     118              : 
     119            0 :       msg += std::to_string(fbs->C2freq()) + " Hz ";
     120            0 :       msg += std::to_string(fbs->C2vpp()) + " Vp2p ";
     121            0 :       msg += std::to_string(fbs->C2ofst()) + " V ";
     122            0 :       msg += std::to_string(fbs->C2phse()) + " deg ";
     123            0 :       msg += std::to_string(fbs->C2wdth()) + " s ";
     124            0 :       msg += "SYNC ";
     125            0 :       if(fbs->C2sync()) msg += "ON ";
     126            0 :       else msg += "OFF ";
     127              : 
     128            0 :       return msg;
     129              : 
     130            0 :    }
     131              : 
     132            0 :    static double C1freq( void * msgBuffer )
     133              :    {
     134            0 :       auto fbs = GetTelem_fxngen_fb(msgBuffer);
     135            0 :       return fbs->C1freq();
     136              :    }
     137              : 
     138            0 :    static double C2freq( void * msgBuffer )
     139              :    {
     140            0 :       auto fbs = GetTelem_fxngen_fb(msgBuffer);
     141            0 :       return fbs->C2freq();
     142              :    }
     143              : 
     144              :    /// Get the logMetaDetail for a member by name
     145              :    /**
     146              :      * \returns the a logMetaDetail filled in with the appropriate details
     147              :      * \returns an empty logMetaDetail if member not recognized
     148              :      */
     149            1 :    static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
     150              :    {
     151            1 :       if(     member == "C1freq") return logMetaDetail({"C1 FREQ", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&C1freq)});
     152            1 :       else if(member == "C2freq") return logMetaDetail({"C2 FREQ", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&C2freq)});
     153              :       else
     154              :       {
     155            1 :          std::cerr << "No member " << member << " in telem_fxngen\n";
     156            1 :          return logMetaDetail();
     157              :       }
     158              :    }
     159              : }; //telem_fxngen
     160              : 
     161              : 
     162              : 
     163              : } //namespace logger
     164              : } //namespace MagAOX
     165              : 
     166              : #endif //logger_types_telem_fxngen_hpp
     167              : 
        

Generated by: LCOV version 2.0-1