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