API
telem_dmspeck.hpp
Go to the documentation of this file.
1 /** \file telem_dmspeck.hpp
2  * \brief The MagAO-X logger telem_dmspeck 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_dmspeck_hpp
11 #define logger_types_telem_dmspeck_hpp
12 
13 #include "generated/telem_dmspeck_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording stdMotionStage 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 std::vector<float> & separations, ///< [in] the separations of the speckle(s)
43  const std::vector<float> & angles, ///< [in] the angles of the speckle(s)
44  const std::vector<float> & amplitudes, ///< [in] the amplitudes of the speckle(s)
45  const std::vector<bool> & crosses ///< [in] whether or not the cross speckle(s) are produced
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_dmspeck_fb(builder, modulating, trigger, frequency, _separationsVec, _anglesVec, _amplitudesVec, _crossesVec);
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_dmspeck_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_dmspeck_fb(msgBuffer);
75 
76  std::string msg = "[speckles] ";
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 += "angs: ";
103  for(flatbuffers::Vector<float>::const_iterator it = fbs->angles()->begin(); it != fbs->angles()->end(); ++it)
104  {
105  msg+= std::to_string(*it);
106  msg+= " ";
107  }
108  msg += "amps: ";
109  for(flatbuffers::Vector<float>::const_iterator it = fbs->amplitudes()->begin(); it != fbs->amplitudes()->end(); ++it)
110  {
111  msg+= std::to_string(*it);
112  msg+= " ";
113  }
114  for(flatbuffers::Vector<unsigned char>::const_iterator it = fbs->crosses()->begin(); it != fbs->crosses()->end(); ++it)
115  {
116  if(*it) msg += "+";
117  else msg += "-";
118  }
119 
120 
121  return msg;
122 
123  }
124 
125  static bool modulating( void * msgBuffer )
126  {
127  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
128  return fbs->modulating();
129  }
130 
131  static bool trigger( void * msgBuffer )
132  {
133  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
134  return fbs->trigger();
135  }
136 
137  static float frequency( void * msgBuffer )
138  {
139  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
140  return fbs->frequency();
141  }
142 
143  static std::vector<float> separations( void * msgBuffer )
144  {
145  std::vector<float> v;
146 
147  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
148 
149  for(flatbuffers::Vector<float>::const_iterator it = fbs->separations()->begin(); it != fbs->separations()->end(); ++it)
150  {
151  v.push_back(*it);
152  }
153 
154  return v;
155  }
156 
157  static std::vector<float> angles( void * msgBuffer )
158  {
159  std::vector<float> v;
160 
161  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
162 
163  for(flatbuffers::Vector<float>::const_iterator it = fbs->angles()->begin(); it != fbs->angles()->end(); ++it)
164  {
165  v.push_back(*it);
166  }
167 
168  return v;
169  }
170 
171  static std::vector<float> amplitudes( void * msgBuffer )
172  {
173  std::vector<float> v;
174 
175  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
176 
177  for(flatbuffers::Vector<float>::const_iterator it = fbs->amplitudes()->begin(); it != fbs->amplitudes()->end(); ++it)
178  {
179  v.push_back(*it);
180  }
181 
182  return v;
183  }
184 
185  static std::vector<bool> crosses( void * msgBuffer )
186  {
187  std::vector<bool> v;
188 
189  auto fbs = GetTelem_dmspeck_fb(msgBuffer);
190 
191  for(flatbuffers::Vector<unsigned char>::const_iterator it = fbs->crosses()->begin(); it != fbs->crosses()->end(); ++it)
192  {
193  v.push_back(*it);
194  }
195 
196  return v;
197  }
198 
199  /// Get pointer to the accessor for a member by name
200  /**
201  * \returns the function pointer cast to void*
202  * \returns -1 for an unknown member
203  */
204  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
205  {
206  if(member == "modulating") return logMetaDetail({"MODULATING", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&modulating)});
207  else if(member == "trigger") return logMetaDetail({"TRIGGERED", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&trigger)});
208  else if(member == "frequency") return logMetaDetail({"FREQUENCY", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&frequency)});
209  else if(member == "separations") return logMetaDetail({"SEPARATIONS", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&separations)});
210  else if(member == "angles") return logMetaDetail({"ANGLES", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&angles)});
211  else if(member == "amplitudes") return logMetaDetail({"AMPLITUDES", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&amplitudes)});
212  else if(member == "crosses") return logMetaDetail({"CROSSES", logMeta::valTypes::Vector_Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&crosses)});
213  else
214  {
215  std::cerr << "No string member " << member << " in telem_dmspeck\n";
216  return logMetaDetail();
217  }
218  }
219 
220 }; //telem_dmspeck
221 
222 
223 
224 } //namespace logger
225 } //namespace MagAOX
226 
227 #endif //logger_types_telem_dmspeck_hpp
228 
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 bool &modulating, const bool &trigger, const float &frequency, const std::vector< float > &separations, const std::vector< float > &angles, const std::vector< float > &amplitudes, const std::vector< bool > &crosses)
Construct from components.
Log entry recording stdMotionStage status.
static std::vector< float > amplitudes(void *msgBuffer)
static bool trigger(void *msgBuffer)
static std::vector< float > angles(void *msgBuffer)
static bool modulating(void *msgBuffer)
static float frequency(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
static const flatlogs::eventCodeT eventCode
The event code.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static const flatlogs::logPrioT defaultLevel
The default level.
static logMetaDetail getAccessor(const std::string &member)
Get pointer to the accessor for a member by name.
static std::vector< bool > crosses(void *msgBuffer)
static std::vector< float > separations(void *msgBuffer)