API
telem_sparkleclock.hpp
Go to the documentation of this file.
1 /** \file telem_sparkleclock.hpp
2  * \brief The MagAO-X logger telem_sparkleclock log type.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_types_files
6  *
7  * History:
8  * - 2022-02-06 created by JRM
9  */
10 #ifndef logger_types_telem_sparkleclock_hpp
11 #define logger_types_telem_sparkleclock_hpp
12 
13 #include "generated/telem_sparkleclock_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording sparkle clock status
23 /** \ingroup logger_types
24  */
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_DMSPECK;
29 
30  ///The default level
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  messageT( const bool & modulating, ///< [in] whether or not the speckle is being modulated
40  const bool & trigger, ///< [in] whether or not the speckle is being triggered
41  const float & frequency, ///< [in] frequency of modulation is not triggered
42  const float & interval, ///< [in] time for one complete cycle of the sparkle clock (e.g. exposure time of some camera)
43  const std::vector<float> & separations, ///< [in] the separations of the speckle(s)
44  const float & angleOffset, ///< [in] starting angle offset of the sparkle clock
45  const float & amplitude ///< [in] starting angle offset of the sparkle clock
46  )
47  {
48  auto _separationsVec = builder.CreateVector(separations);
49  // auto _anglesVec = builder.CreateVector(angles);
50  // auto _amplitudesVec = builder.CreateVector(amplitudes);
51  // auto _crossesVec = builder.CreateVector(crosses);
52 
53  auto fp = CreateTelem_sparkleclock_fb(builder, modulating, trigger, frequency, interval, _separationsVec, angleOffset, amplitude);
54  builder.Finish(fp);
55  }
56 
57  };
58 
59  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
60  flatlogs::msgLenT len ///< [in] length of msgBuffer.
61  )
62  {
63  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
64  return VerifyTelem_sparkleclock_fbBuffer(verifier);
65  }
66 
67  ///Get the message formatte for human consumption.
68  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
69  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
70  )
71  {
72  static_cast<void>(len);
73 
74  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
75 
76  std::string msg = "[sparkleclock] ";
77 
78  if(!fbs->modulating())
79  {
80  msg += "not modulating";
81  return msg;
82  }
83 
84  msg += "modulating";
85  if(fbs->trigger())
86  {
87  msg += " by trigger ";
88  }
89  else
90  {
91  msg += " at ";
92  msg += std::to_string(fbs->frequency());
93  msg += " Hz ";
94  }
95 
96  msg += "seps: ";
97  for(flatbuffers::Vector<float>::const_iterator it = fbs->separations()->begin(); it != fbs->separations()->end(); ++it)
98  {
99  msg+= std::to_string(*it);
100  msg+= " ";
101  }
102  msg += "angle offset: ";
103  msg += std::to_string(fbs->angleOffset());
104  msg += "amp: ";
105  msg += std::to_string(fbs->amplitude());
106 
107  return msg;
108 
109  }
110 
111  static bool modulating( void * msgBuffer )
112  {
113  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
114  return fbs->modulating();
115  }
116 
117  static bool trigger( void * msgBuffer )
118  {
119  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
120  return fbs->trigger();
121  }
122 
123  static float frequency( void * msgBuffer )
124  {
125  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
126  return fbs->frequency();
127  }
128 
129  static std::vector<float> separations( void * msgBuffer )
130  {
131  std::vector<float> v;
132 
133  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
134 
135  for(flatbuffers::Vector<float>::const_iterator it = fbs->separations()->begin(); it != fbs->separations()->end(); ++it)
136  {
137  v.push_back(*it);
138  }
139 
140  return v;
141  }
142 
143  static float angleOffset( void * msgBuffer )
144  {
145  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
146  return fbs->angleOffset();
147  }
148  static float amplitude( void * msgBuffer )
149  {
150  auto fbs = GetTelem_sparkleclock_fb(msgBuffer);
151  return fbs->amplitude();
152  }
153 
154  /// Get pointer to the accessor for a member by name
155  /**
156  * \returns the function pointer cast to void*
157  * \returns -1 for an unknown member
158  */
159  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
160  {
161  if(member == "modulating") return logMetaDetail({"MODULATING", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&modulating)});
162  else if(member == "trigger") return logMetaDetail({"TRIGGERED", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&trigger)});
163  else if(member == "frequency") return logMetaDetail({"FREQUENCY", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&frequency)});
164  else if(member == "separations") return logMetaDetail({"SEPARATIONS", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&separations)});
165  else if(member == "angleOffset") return logMetaDetail({"ANGLEOFFSET", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&angleOffset)});
166  else if(member == "amplitude") return logMetaDetail({"AMPLITUDES", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&amplitude)});
167  else
168  {
169  std::cerr << "No string member " << member << " in telem_sparkleclock\n";
170  return logMetaDetail();
171  }
172  }
173 
174 }; //telem_sparkleclock
175 
176 
177 
178 } //namespace logger
179 } //namespace MagAOX
180 
181 #endif //logger_types_telem_sparkleclock_hpp
182 
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.
messageT(const bool &modulating, const bool &trigger, const float &frequency, const float &interval, const std::vector< float > &separations, const float &angleOffset, const float &amplitude)
Construct from components.
Log entry recording sparkle clock status.
static bool trigger(void *msgBuffer)
static bool modulating(void *msgBuffer)
static logMetaDetail getAccessor(const std::string &member)
Get pointer to the accessor for a member by name.
static float frequency(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static float amplitude(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static std::vector< float > separations(void *msgBuffer)
static float angleOffset(void *msgBuffer)
static const flatlogs::logPrioT defaultLevel
The default level.