API
telem_stdcam.hpp
Go to the documentation of this file.
1 /** \file telem_stdcam.hpp
2  * \brief The MagAO-X logger telem_stdcam 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_stdcam_hpp
11 #define logger_types_telem_stdcam_hpp
12 
13 #include "generated/telem_stdcam_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording stdcam stage specific status.
23 /** \ingroup logger_types
24  */
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_STDCAM;
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 std::string & mode, ///<[in]
40  const float & xcen, ///<[in]
41  const float & ycen, ///<[in]
42  const int & width, ///<[in]
43  const int & height, ///<[in]
44  const int & xbin, ///<[in]
45  const int & ybin, ///<[in]
46  const float & exptime, ///<[in]
47  const float & fps, ///<[in]
48  const float & emGain, ///<[in]
49  const float & adcSpeed, ///<[in]
50  const float & temp, ///<[in]
51  const float & setpt, ///<[in]
52  const uint8_t & status, ///<[in]
53  const uint8_t & ontarget, ///<[in]
54  const std::string & statusStr, ///<[in]
55  const std::string & shutterStatusSr, ///<[in]
56  const int8_t & shutterState, ///<[in]
57  const uint8_t & synchro, ///<[in]
58  const float & vshift, ///<[in]
59  const uint8_t & cropMode ///<[in]
60  )
61  {
62  auto _mode = builder.CreateString(mode);
63  auto _roi = CreateROI(builder,xcen, ycen, width, height, xbin, ybin);
64 
65  auto _statusStr = builder.CreateString(statusStr);
66  auto _tempCtrl = CreateTempCtrl(builder, temp, setpt, status, ontarget, _statusStr);
67 
68  auto _shutterStatusStr = builder.CreateString(shutterStatusSr);
69  auto _shutter = CreateShutter(builder, _shutterStatusStr, shutterState);
70 
71  auto fp = CreateTelem_stdcam_fb(builder, _mode, _roi, exptime, fps, emGain, adcSpeed, _tempCtrl, _shutter, synchro, vshift, cropMode);
72  builder.Finish(fp);
73  }
74 
75  ///Construct from components, without vShift and cropMode for backwards compat.
76  messageT( const std::string & mode, ///<[in]
77  const float & xcen, ///<[in]
78  const float & ycen, ///<[in]
79  const int & width, ///<[in]
80  const int & height, ///<[in]
81  const int & xbin, ///<[in]
82  const int & ybin, ///<[in]
83  const float & exptime, ///<[in]
84  const float & fps, ///<[in]
85  const float & emGain, ///<[in]
86  const float & adcSpeed, ///<[in]
87  const float & temp, ///<[in]
88  const float & setpt, ///<[in]
89  const uint8_t & status, ///<[in]
90  const uint8_t & ontarget, ///<[in]
91  const std::string & statusStr, ///<[in]
92  const std::string & shutterStatusSr, ///<[in]
93  const int8_t & shutterState, ///<[in]
94  const uint8_t & synchro ///<[in]
95  )
96  {
97  auto _mode = builder.CreateString(mode);
98  auto _roi = CreateROI(builder,xcen, ycen, width, height, xbin, ybin);
99 
100  auto _statusStr = builder.CreateString(statusStr);
101  auto _tempCtrl = CreateTempCtrl(builder, temp, setpt, status, ontarget, _statusStr);
102 
103  auto _shutterStatusStr = builder.CreateString(shutterStatusSr);
104  auto _shutter = CreateShutter(builder, _shutterStatusStr, shutterState);
105 
106  auto fp = CreateTelem_stdcam_fb(builder, _mode, _roi, exptime, fps, emGain, adcSpeed, _tempCtrl, _shutter, synchro, 0, -1);
107  builder.Finish(fp);
108  }
109 
110  };
111 
112  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
113  flatlogs::msgLenT len ///< [in] length of msgBuffer.
114  )
115  {
116  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
117  return VerifyTelem_stdcam_fbBuffer(verifier);
118  }
119 
120  ///Get the message formatted for human consumption.
121  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
122  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
123  )
124  {
125  static_cast<void>(len);
126 
127  auto fbs = GetTelem_stdcam_fb(msgBuffer);
128 
129  std::string msg = "[stdcam] ";
130 
131  if(fbs->mode() != nullptr)
132  {
133  msg+= "mode: ";
134  msg += fbs->mode()->c_str();
135  msg += " ";
136  }
137 
138  if(fbs->roi() != nullptr)
139  {
140  msg += "ROI-x: ";
141  msg += std::to_string(fbs->roi()->xcen());
142  msg += " y: ";
143  msg += std::to_string(fbs->roi()->ycen());
144  msg += " w: ";
145  msg += std::to_string(fbs->roi()->w());
146  msg += " h: ";
147  msg += std::to_string(fbs->roi()->h());
148  msg += " xbin: ";
149  msg += std::to_string(fbs->roi()->xbin());
150  msg += " ybin: ";
151  msg += std::to_string(fbs->roi()->ybin());
152  msg += " ";
153  }
154 
155  msg += "expt: ";
156  msg += std::to_string(fbs->exptime());
157  msg += " fps: ";
158  msg += std::to_string(fbs->fps());
159  msg += " emG: ";
160  msg += std::to_string(fbs->emGain());
161  msg += " adc: ";
162  msg += std::to_string(fbs->adcSpeed());
163 
164  if(fbs->tempCtrl() != nullptr)
165  {
166  msg += " temp: ";
167  msg += std::to_string(fbs->tempCtrl()->temp());
168  msg += " setpt: ";
169  msg += std::to_string(fbs->tempCtrl()->setpt());
170  msg += " tempctr-stat: ";
171  msg += std::to_string(fbs->tempCtrl()->status());
172  msg += " tempctr-ontgt: ";
173  msg += std::to_string(fbs->tempCtrl()->ontarget());
174 
175  if(fbs->tempCtrl()->statusStr())
176  {
177  msg += " tempctr-statstr: ";
178  msg += fbs->tempCtrl()->statusStr()->c_str();
179  }
180  }
181 
182  if(fbs->shutter() != nullptr)
183  {
184  if(fbs->shutter()->statusStr())
185  {
186  msg += " shutter-statstr: ";
187  msg += fbs->shutter()->statusStr()->c_str();
188  }
189  msg+= " shutter: ";
190  if( fbs->shutter()->state() == -1)
191  {
192  msg += "UNKN";
193  }
194  else if( fbs->shutter()->state() == 0)
195  {
196  msg += "SHUT";
197  }
198  else if( fbs->shutter()->state() == 1)
199  {
200  msg += "OPEN";
201  }
202  }
203 
204  msg += " Sync: ";
205  if(fbs->synchro()) msg += "ON";
206  else msg += "OFF";
207 
208  msg += " vshift: ";
209  if(fbs->vshift() == 0) msg += "---";
210  else msg += std::to_string(fbs->vshift());
211 
212  msg += " crop: ";
213  if(fbs->cropMode()==-1) msg += "---";
214  else if(fbs->cropMode()==1) msg += "ON";
215  else msg += "OFF";
216 
217  return msg;
218 
219  }
220 
221  static std::string mode( void * msgBuffer )
222  {
223  auto fbs = GetTelem_stdcam_fb(msgBuffer);
224  if(fbs->mode() != nullptr)
225  {
226  return std::string(fbs->mode()->c_str());
227  }
228  else return "";
229  }
230 
231  static float xcen( void * msgBuffer )
232  {
233  auto fbs = GetTelem_stdcam_fb(msgBuffer);
234  if(fbs->roi() != nullptr) return fbs->roi()->xcen();
235  else return -1;
236  }
237 
238  static float ycen( void * msgBuffer )
239  {
240  auto fbs = GetTelem_stdcam_fb(msgBuffer);
241  if(fbs->roi() != nullptr) return fbs->roi()->ycen();
242  else return -1;
243  }
244 
245  static int width( void * msgBuffer )
246  {
247  auto fbs = GetTelem_stdcam_fb(msgBuffer);
248  if(fbs->roi() != nullptr) return fbs->roi()->w();
249  else return -1;
250  }
251 
252  static int height( void * msgBuffer )
253  {
254  auto fbs = GetTelem_stdcam_fb(msgBuffer);
255  if(fbs->roi() != nullptr) return fbs->roi()->h();
256  else return -1;
257  }
258 
259  static int xbin( void * msgBuffer )
260  {
261  auto fbs = GetTelem_stdcam_fb(msgBuffer);
262  if(fbs->roi() != nullptr) return fbs->roi()->xbin();
263  else return -1;
264  }
265 
266  static int ybin( void * msgBuffer )
267  {
268  auto fbs = GetTelem_stdcam_fb(msgBuffer);
269  if(fbs->roi() != nullptr) return fbs->roi()->ybin();
270  else return -1;
271  }
272 
273  static float exptime( void * msgBuffer )
274  {
275  auto fbs = GetTelem_stdcam_fb(msgBuffer);
276  return fbs->exptime();
277  }
278 
279  static float fps( void * msgBuffer )
280  {
281  auto fbs = GetTelem_stdcam_fb(msgBuffer);
282  return fbs->fps();
283  }
284 
285  static float emGain( void * msgBuffer )
286  {
287  auto fbs = GetTelem_stdcam_fb(msgBuffer);
288  return fbs->emGain();
289  }
290 
291  static float adcSpeed( void * msgBuffer )
292  {
293  auto fbs = GetTelem_stdcam_fb(msgBuffer);
294  return fbs->adcSpeed();
295  }
296 
297  static float temp( void * msgBuffer )
298  {
299  auto fbs = GetTelem_stdcam_fb(msgBuffer);
300  if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->temp();
301  else return -9999;
302  }
303 
304  static float tempSetpt( void * msgBuffer )
305  {
306  auto fbs = GetTelem_stdcam_fb(msgBuffer);
307  if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->setpt();
308  else return -9999;
309  }
310 
311  static int tempStatus( void * msgBuffer )
312  {
313  auto fbs = GetTelem_stdcam_fb(msgBuffer);
314  if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->status();
315  else return -9999;
316  }
317 
318  static int tempOnTarget( void * msgBuffer )
319  {
320  auto fbs = GetTelem_stdcam_fb(msgBuffer);
321  if(fbs->tempCtrl() != nullptr) return fbs->tempCtrl()->ontarget();
322  else return -9999;
323  }
324 
325  static std::string tempStatusStr( void * msgBuffer )
326  {
327  auto fbs = GetTelem_stdcam_fb(msgBuffer);
328  if(fbs->tempCtrl() != nullptr)
329  {
330  if(fbs->tempCtrl()->statusStr()) return fbs->tempCtrl()->statusStr()->c_str();
331  else return "";
332  }
333  else return "";
334  }
335 
336  static std::string shutterStatusStr( void * msgBuffer)
337  {
338  auto fbs = GetTelem_stdcam_fb(msgBuffer);
339  if(fbs->shutter() != nullptr)
340  {
341  if(fbs->shutter()->statusStr()) return fbs->shutter()->statusStr()->c_str();
342  else return "";
343  }
344  else return "";
345  }
346 
347  static std::string shutterState( void * msgBuffer )
348  {
349  auto fbs = GetTelem_stdcam_fb(msgBuffer);
350  if(fbs->shutter() != nullptr)
351  {
352  if( fbs->shutter()->state() == -1) return "UNKNOWN";
353  else if( fbs->shutter()->state() == 0) return "SHUT";
354  else if( fbs->shutter()->state() == 1) return "OPEN";
355  else return "INVALID";
356  }
357  else return "INVALID";
358  }
359 
360  static bool synchro( void * msgBuffer )
361  {
362  auto fbs = GetTelem_stdcam_fb(msgBuffer);
363  return fbs->synchro();
364  }
365 
366  static float vshift( void * msgBuffer )
367  {
368  auto fbs = GetTelem_stdcam_fb(msgBuffer);
369  return fbs->vshift();
370  }
371 
372  static bool cropMode( void * msgBuffer )
373  {
374  auto fbs = GetTelem_stdcam_fb(msgBuffer);
375 
376  //slightly different because define a default to indicated not-used.
377  if(fbs->cropMode() == 1) return true;
378  else return false;
379  }
380 
381  /// Get the logMetaDetail for a member by name
382  /**
383  * \returns the function pointer cast to void*
384  * \returns -1 for an unknown member
385  */
386  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
387  {
388  if(member == "mode") return logMetaDetail({"MODE", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&mode)});
389  else if(member == "xcen") return logMetaDetail({"ROI XCEN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&xcen)});
390  else if(member == "ycen") return logMetaDetail({"ROI YCEN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&ycen)});
391  else if(member == "width") return logMetaDetail({"ROI WIDTH", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&width)});
392  else if(member == "height") return logMetaDetail({"ROI HEIGHT", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&height)});
393  else if(member == "xbin") return logMetaDetail({"ROI XBIN", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&xbin)});
394  else if(member == "ybin") return logMetaDetail({"ROI YBIN", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&ybin)});
395  else if(member == "exptime") return logMetaDetail({"EXPTIME", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&exptime)});
396  else if(member == "fps") return logMetaDetail({"FPS", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&fps)});
397  else if(member == "emGain") return logMetaDetail({"EMGAIN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&emGain)});
398  else if(member == "adcSpeed") return logMetaDetail({"ADC SPEED", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&adcSpeed)});
399  else if(member == "temp") return logMetaDetail({"TEMP", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&temp)});
400  else if(member == "tempSetpt") return logMetaDetail({"TEMP SETPT", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&tempSetpt)});
401  else if(member == "tempStatus") return logMetaDetail({"TEMP STATUS", logMeta::valTypes::Int, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&tempStatus)});
402  else if(member == "tempOnTarget") return logMetaDetail({"TEMP ONTGT", logMeta::valTypes::Int, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&tempOnTarget)});
403  else if(member == "tempStatusStr") return logMetaDetail({"TEMP STATUSSTR", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&tempStatusStr)});
404  else if(member == "shutterStatusStr") return logMetaDetail({"SHUTTER STATUS", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&shutterStatusStr)});
405  else if(member == "shutterState") return logMetaDetail({"SHUTTER", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&shutterState)});
406  else if(member == "synchro") return logMetaDetail({"SYNCHRO", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&synchro)});
407  else if(member == "vshift") return logMetaDetail({"VSHIFTSPD", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&vshift)});
408  else if(member == "cropMode") return logMetaDetail({"CROPMODE", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&cropMode)});
409  else
410  {
411  std::cerr << "No string member " << member << " in telem_stdcam\n";
412  return logMetaDetail();
413  }
414  }
415 
416 }; //telem_stdcam
417 
418 
419 
420 } //namespace logger
421 } //namespace MagAOX
422 
423 #endif //logger_types_telem_stdcam_hpp
424 
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 std::string &mode, const float &xcen, const float &ycen, const int &width, const int &height, const int &xbin, const int &ybin, const float &exptime, const float &fps, const float &emGain, const float &adcSpeed, const float &temp, const float &setpt, const uint8_t &status, const uint8_t &ontarget, const std::string &statusStr, const std::string &shutterStatusSr, const int8_t &shutterState, const uint8_t &synchro)
Construct from components, without vShift and cropMode for backwards compat.
messageT(const std::string &mode, const float &xcen, const float &ycen, const int &width, const int &height, const int &xbin, const int &ybin, const float &exptime, const float &fps, const float &emGain, const float &adcSpeed, const float &temp, const float &setpt, const uint8_t &status, const uint8_t &ontarget, const std::string &statusStr, const std::string &shutterStatusSr, const int8_t &shutterState, const uint8_t &synchro, const float &vshift, const uint8_t &cropMode)
Construct from components.
Log entry recording stdcam stage specific status.
static float temp(void *msgBuffer)
static bool synchro(void *msgBuffer)
static std::string shutterStatusStr(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static bool cropMode(void *msgBuffer)
static float vshift(void *msgBuffer)
static std::string shutterState(void *msgBuffer)
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
static float tempSetpt(void *msgBuffer)
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static int tempStatus(void *msgBuffer)
static const flatlogs::logPrioT defaultLevel
The default level.
static float adcSpeed(void *msgBuffer)
static int tempOnTarget(void *msgBuffer)
static std::string tempStatusStr(void *msgBuffer)
static float ycen(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static int height(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatted for human consumption.
static float fps(void *msgBuffer)
static float emGain(void *msgBuffer)
static std::string mode(void *msgBuffer)
static int xbin(void *msgBuffer)
static float xcen(void *msgBuffer)
static int ybin(void *msgBuffer)
static float exptime(void *msgBuffer)
static int width(void *msgBuffer)