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 #include "../logMeta.hpp"
16 
17 #include <cmath>
18 
19 namespace MagAOX
20 {
21 namespace logger
22 {
23 
24 
25 /// Log entry recording the build-time git state.
26 /** \ingroup logger_types
27  */
29 {
30  ///The event code
31  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_TELPOS;
32 
33  ///The default level
35 
36  static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
37 
39 
40  ///The type of the input message
41  struct messageT : public fbMessage
42  {
43  ///Construct from components
44  messageT( const double & epoch, ///<[in] epoch
45  const double & ra, ///<[in] right ascension
46  const double & dec, ///<[in] declination
47  const double & el, ///<[in] elevation
48  const double & ha, ///<[in] hour angle
49  const double & am, ///<[in] air mass
50  const double & rotoff ///<[in] rotoff
51  )
52  {
53  auto fp = CreateTelem_telpos_fb(builder, epoch, ra, dec, el, ha, am, rotoff);
54  builder.Finish(fp);
55  }
56 
57  };
58 
59 
60  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
61  flatlogs::msgLenT len ///< [in] length of msgBuffer.
62  )
63  {
64  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
65  return VerifyTelem_telpos_fbBuffer(verifier);
66  }
67 
68  ///Get the message formatte for human consumption.
69  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
70  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
71  )
72  {
73  static_cast<void>(len);
74 
75  auto fbs = GetTelem_telpos_fb(msgBuffer);
76 
77  std::string msg = "[telpos] ";
78 
79  msg += "ep: ";
80  msg += std::to_string(fbs->epoch()) + " ";
81 
82  msg += "ra: ";
83  msg += std::to_string(fbs->ra()) + " ";
84 
85  msg += "dec: ";
86  msg += std::to_string(fbs->dec()) + " ";
87 
88  msg += "el: ";
89  msg += std::to_string(fbs->el()) + " ";
90 
91  msg += "ha: ";
92  msg += std::to_string(fbs->ha()) + " ";
93 
94  msg += "am: ";
95  msg += std::to_string(fbs->am()) + " ";
96 
97  msg += "ro: ";
98  msg += std::to_string(fbs->rotoff());
99 
100  return msg;
101 
102  }
103 
104  static double epoch( void * msgBuffer )
105  {
106  auto fbs = GetTelem_telpos_fb(msgBuffer);
107  return fbs->epoch();
108  }
109 
110  static double ra( void * msgBuffer )
111  {
112  auto fbs = GetTelem_telpos_fb(msgBuffer);
113  return fbs->ra();
114  }
115 
116  static double dec( void * msgBuffer )
117  {
118  auto fbs = GetTelem_telpos_fb(msgBuffer);
119  return fbs->dec();
120  }
121 
122  static double el( void * msgBuffer )
123  {
124  auto fbs = GetTelem_telpos_fb(msgBuffer);
125  return fbs->el();
126  }
127 
128  static double ha( void * msgBuffer )
129  {
130  auto fbs = GetTelem_telpos_fb(msgBuffer);
131  return fbs->ha();
132  }
133 
134  static double am( void * msgBuffer )
135  {
136  auto fbs = GetTelem_telpos_fb(msgBuffer);
137  return fbs->am();
138  }
139 
140  static double ro( void * msgBuffer )
141  {
142  auto fbs = GetTelem_telpos_fb(msgBuffer);
143  return fbs->rotoff();
144  }
145 
146 
147  /// Get the logMetaDetail for a member by name
148  /**
149  * \returns the a logMetaDetail filled in with the appropriate details
150  * \returns an empty logmegaDetail if member not recognized
151  */
152  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
153  {
154  if( member == "epoch") return logMetaDetail({"EPOCH", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&epoch), false});
155  else if(member == "ra") return logMetaDetail({"RA", "right ascension [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&ra), false});
156  else if(member == "dec") return logMetaDetail({"DEC", "declination [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&dec), false});
157  else if(member == "el") return logMetaDetail({"EL", "elevation [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&el), false});
158  else if(member == "ha") return logMetaDetail({"HA", "hour angle [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&ha), false});
159  else if(member == "am") return logMetaDetail({"AIRMASS", "airmass", "%0.2f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&am), false});
160  else if(member == "ro") return logMetaDetail({"RO", "rotator offset [degrees]", "%0.8f", logMeta::valTypes::Double, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&ro), false});
161  else
162  {
163  std::cerr << "No string member " << member << " in telem_telpos\n";
164  return logMetaDetail();
165  }
166  }
167 
168 }; //telem_telpos
169 
170 
171 
172 } //namespace logger
173 } //namespace MagAOX
174 
175 #endif //logger_types_telem_telpos_hpp
176 
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)