API
telem_teldata.hpp
Go to the documentation of this file.
1 /** \file telem_teldata.hpp
2  * \brief The MagAO-X logger telem_teldata 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_teldata_hpp
11 #define logger_types_telem_teldata_hpp
12 
13 #include "generated/telem_teldata_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 build-time git state.
24 /** \ingroup logger_types
25  */
27 {
28  ///The event code
29  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_TELDATA;
30 
31  ///The default level
33 
34  static timespec lastRecord; ///< The time 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 int & roi, ///<[in] rotator of interest
41  const int & tracking, ///<[in] tracking state
42  const int & guiding, ///<[in] guiding state
43  const int & slewing, ///<[in] slewing state
44  const int & guiderMoving, ///<[in] guider moving state
45  const double & az, ///<[in] azimuth
46  const double & zd, ///<[in] zenith distance
47  const double & pa, ///<[in] parallactic angle
48  const double & domeAz, ///<[in] dome azimuth
49  const int & domeStat ///<[in] dome status
50  )
51  {
52  auto fp = CreateTelem_teldata_fb(builder, roi, tracking, guiding, slewing, guiderMoving, az, zd, pa, domeAz, domeStat);
53  builder.Finish(fp);
54  }
55 
56  };
57 
58  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
59  flatlogs::msgLenT len ///< [in] length of msgBuffer.
60  )
61  {
62  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
63  return VerifyTelem_teldata_fbBuffer(verifier);
64  }
65 
66  ///Get the message formatte for human consumption.
67  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
68  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
69  )
70  {
71  static_cast<void>(len);
72 
73  auto fbs = GetTelem_teldata_fb(msgBuffer);
74 
75  std::string msg = "[teldata] ";
76 
77  msg += "roi: ";
78  msg += std::to_string(fbs->roi()) + " ";
79 
80  msg += "tr: ";
81  msg += std::to_string(fbs->tracking()) + " ";
82 
83  msg += "gd: ";
84  msg += std::to_string(fbs->guiding()) + " ";
85 
86  msg += "sl: ";
87  msg += std::to_string(fbs->slewing()) + " ";
88 
89  msg += "gm: ";
90  msg += std::to_string(fbs->guiderMoving()) + " ";
91 
92  msg += "az: ";
93  msg += std::to_string(fbs->az()) + " ";
94 
95  msg += "zd: ";
96  msg += std::to_string(fbs->zd()) + " ";
97 
98  msg += "pa: ";
99  msg += std::to_string(fbs->pa()) + " ";
100 
101  msg += "da: ";
102  msg += std::to_string(fbs->domeAz()) + " ";
103 
104  msg += "ds: ";
105  msg += std::to_string(fbs->domeStat());
106 
107  return msg;
108 
109  }
110 
111  static int roi( void * msgBuffer )
112  {
113  auto fbs = GetTelem_teldata_fb(msgBuffer);
114  return fbs->roi();
115  }
116 
117  static int tracking( void * msgBuffer )
118  {
119  auto fbs = GetTelem_teldata_fb(msgBuffer);
120  return fbs->tracking();
121  }
122 
123  static int guiding( void * msgBuffer )
124  {
125  auto fbs = GetTelem_teldata_fb(msgBuffer);
126  return fbs->guiding();
127  }
128 
129  static int slewing( void * msgBuffer )
130  {
131  auto fbs = GetTelem_teldata_fb(msgBuffer);
132  return fbs->slewing();
133  }
134 
135  static int guiderMoving( void * msgBuffer )
136  {
137  auto fbs = GetTelem_teldata_fb(msgBuffer);
138  return fbs->guiderMoving();
139  }
140 
141  static double az( void * msgBuffer )
142  {
143  auto fbs = GetTelem_teldata_fb(msgBuffer);
144  return fbs->az();
145  }
146 
147  static double zd( void * msgBuffer )
148  {
149  auto fbs = GetTelem_teldata_fb(msgBuffer);
150  return fbs->zd();
151  }
152 
153  static double pa( void * msgBuffer )
154  {
155  auto fbs = GetTelem_teldata_fb(msgBuffer);
156  return fbs->pa();
157  }
158 
159  static double domeAz( void * msgBuffer )
160  {
161  auto fbs = GetTelem_teldata_fb(msgBuffer);
162  return fbs->domeAz();
163  }
164 
165  static int domeStat( void * msgBuffer )
166  {
167  auto fbs = GetTelem_teldata_fb(msgBuffer);
168  return fbs->domeStat();
169  }
170 
171  /// Get the logMetaDetail for a member by name
172  /**
173  * \returns the function pointer cast to void*
174  * \returns -1 for an unknown member
175  */
176  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
177  {
178  if( member == "roi") return logMetaDetail({"ROI", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&roi)});
179  else if(member == "tracking") return logMetaDetail({"TRACKING", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&tracking)});
180  else if(member == "guiding") return logMetaDetail({"GUIDING", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&guiding)});
181  else if(member == "slewing") return logMetaDetail({"SLEWING", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&slewing)});
182  else if(member == "guiderMoving") return logMetaDetail({"GUIDER MOVING", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&guiderMoving)});
183  else if(member == "az") return logMetaDetail({"AZ", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&az), false});
184  else if(member == "zd") return logMetaDetail({"ZD", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&zd), false});
185  else if(member == "pa") return logMetaDetail({"PARANG", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&pa), false});
186  else if(member == "domeAz") return logMetaDetail({"DOME AZ", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&domeAz)});
187  else if(member == "domeStat") return logMetaDetail({"DOME STATUS", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&domeStat)});
188  else
189  {
190  std::cerr << "No string member " << member << " in telem_teldata\n";
191  return logMetaDetail();
192  }
193  }
194 
195 }; //telem_teldata
196 
197 
198 
199 } //namespace logger
200 } //namespace MagAOX
201 
202 #endif //logger_types_telem_teldata_hpp
203 
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 int &roi, const int &tracking, const int &guiding, const int &slewing, const int &guiderMoving, const double &az, const double &zd, const double &pa, const double &domeAz, const int &domeStat)
Construct from components.
Log entry recording the build-time git state.
static const flatlogs::logPrioT defaultLevel
The default level.
static int roi(void *msgBuffer)
static double domeAz(void *msgBuffer)
static double pa(void *msgBuffer)
static int domeStat(void *msgBuffer)
static int guiding(void *msgBuffer)
static double zd(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static int tracking(void *msgBuffer)
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static const flatlogs::eventCodeT eventCode
The event code.
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static int guiderMoving(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static double az(void *msgBuffer)
static int slewing(void *msgBuffer)