API
telem_telpos.hpp
Go to the documentation of this file.
1 /** \file telem_telpos.hpp
2  * \brief The MagAO-X logger telem_telpos 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_telpos_hpp
11 #define logger_types_telem_telpos_hpp
12 
13 #include "generated/telem_telpos_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 #include <cmath>
17 
18 namespace MagAOX
19 {
20 namespace logger
21 {
22 
23 
24 /// Log entry recording the build-time git state.
25 /** \ingroup logger_types
26  */
28 {
29  ///The event code
30  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_TELPOS;
31 
32  ///The default level
34 
35  static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
36 
38 
39  ///The type of the input message
40  struct messageT : public fbMessage
41  {
42  ///Construct from components
43  messageT( const double & epoch, ///<[in] epoch
44  const double & ra, ///<[in] right ascension
45  const double & dec, ///<[in] declination
46  const double & el, ///<[in] elevation
47  const double & ha, ///<[in] hour angle
48  const double & am, ///<[in] air mass
49  const double & rotoff ///<[in] rotoff
50  )
51  {
52  auto fp = CreateTelem_telpos_fb(builder, epoch, ra, dec, el, ha, am, rotoff);
53  builder.Finish(fp);
54  }
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_telpos_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_telpos_fb(msgBuffer);
75 
76  std::string msg = "[telpos] ";
77 
78  msg += "ep: ";
79  msg += std::to_string(fbs->epoch()) + " ";
80 
81  msg += "ra: ";
82  msg += std::to_string(fbs->ra()) + " ";
83 
84  msg += "dec: ";
85  msg += std::to_string(fbs->dec()) + " ";
86 
87  msg += "el: ";
88  msg += std::to_string(fbs->el()) + " ";
89 
90  msg += "ha: ";
91  msg += std::to_string(fbs->ha()) + " ";
92 
93  msg += "am: ";
94  msg += std::to_string(fbs->am()) + " ";
95 
96  msg += "ro: ";
97  msg += std::to_string(fbs->rotoff());
98 
99  return msg;
100 
101  }
102 
103  static double epoch( void * msgBuffer )
104  {
105  auto fbs = GetTelem_telpos_fb(msgBuffer);
106  return fbs->epoch();
107  }
108 
109  static double ra( void * msgBuffer )
110  {
111  auto fbs = GetTelem_telpos_fb(msgBuffer);
112  return fbs->ra();
113  }
114 
115  static double dec( void * msgBuffer )
116  {
117  auto fbs = GetTelem_telpos_fb(msgBuffer);
118  return fbs->dec();
119  }
120 
121  static double el( void * msgBuffer )
122  {
123  auto fbs = GetTelem_telpos_fb(msgBuffer);
124  return fbs->el();
125  }
126 
127  static double ha( void * msgBuffer )
128  {
129  auto fbs = GetTelem_telpos_fb(msgBuffer);
130  return fbs->ha();
131  }
132 
133  static double am( void * msgBuffer )
134  {
135  auto fbs = GetTelem_telpos_fb(msgBuffer);
136  return fbs->am();
137  }
138 
139  static double ro( void * msgBuffer )
140  {
141  auto fbs = GetTelem_telpos_fb(msgBuffer);
142  return fbs->rotoff();
143  }
144 
145 
146  /// Get the logMetaDetail for a member by name
147  /**
148  * \returns the a logMetaDetail filled in with the appropriate details
149  * \returns an empty logmegaDetail if member not recognized
150  */
151  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
152  {
153  if( member == "epoch") return logMetaDetail({"EPOCH", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&epoch), false});
154  else if(member == "ra") return logMetaDetail({"RA", "right ascension [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&ra), false});
155  else if(member == "dec") return logMetaDetail({"DEC", "declination [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&dec), false});
156  else if(member == "el") return logMetaDetail({"EL", "elevation [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&el), false});
157  else if(member == "ha") return logMetaDetail({"HA", "hour angle [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&ha), false});
158  else if(member == "am") return logMetaDetail({"AIRMASS", "airmass", "%0.2f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&am), false});
159  else if(member == "ro") return logMetaDetail({"RO", "rotator offset [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&ro), false});
160  else
161  {
162  std::cerr << "No string member " << member << " in telem_telpos\n";
163  return logMetaDetail();
164  }
165  }
166 
167 }; //telem_telpos
168 
169 
170 
171 } //namespace logger
172 } //namespace MagAOX
173 
174 #endif //logger_types_telem_telpos_hpp
175 
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 double &epoch, const double &ra, const double &dec, const double &el, const double &ha, const double &am, const double &rotoff)
Construct from components.
Log entry recording the build-time git state.
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static double dec(void *msgBuffer)
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static double epoch(void *msgBuffer)
static double el(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static double ra(void *msgBuffer)
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 double ro(void *msgBuffer)
static double am(void *msgBuffer)
static const flatlogs::logPrioT defaultLevel
The default level.
static double ha(void *msgBuffer)