API
telem_chrony_status.hpp
Go to the documentation of this file.
1 /** \file telem_chrony_status.hpp
2  * \brief The MagAO-X logger telem_chrony_status 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_chrony_status_hpp
11 #define logger_types_telem_chrony_status_hpp
12 
13 #include "generated/telem_chrony_status_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 status of chrony.
25 /** \ingroup logger_types
26  */
28 {
29  ///The event code
30  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_CHRONY_STATUS;
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 
37  ///The type of the input message
38  struct messageT : public fbMessage
39  {
40  ///Construct from components
41  messageT( const std::string & mac, ///< [in] Source MAC
42  const std::string & ip, ///< [in] Source IP
43  const std::string & sync, ///< [in] Synch status
44  const std::string & leap ///< [in] leap status
45  )
46  {
47  auto _mac = builder.CreateString(mac);
48  auto _ip = builder.CreateString(ip);
49  auto _sync = builder.CreateString(sync);
50  auto _leap = builder.CreateString(leap);
51 
52  auto fp = CreateTelem_chrony_status_fb(builder, _mac, _ip, _sync, _leap);
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_chrony_status_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_chrony_status_fb(msgBuffer);
74 
75  std::string msg = "[chrony_status] ";
76 
77  msg += "source: ";
78  if(fbs->sourceMAC())
79  {
80  msg += fbs->sourceMAC()->c_str();
81  msg +="/";
82  }
83 
84  if(fbs->sourceIP())
85  {
86  msg += fbs->sourceIP()->c_str();
87  }
88 
89  if(fbs->synch())
90  {
91  msg += " synch: ";
92  msg += fbs->synch()->c_str();
93  }
94 
95  if(fbs->leap())
96  {
97  msg += " leap: ";
98  msg += fbs->leap()->c_str();
99  }
100 
101  return msg;
102 
103  }
104 
105  static std::string sourceMAC(void * msgBuffer )
106  {
107  auto fbs = GetTelem_chrony_status_fb(msgBuffer);
108  if(fbs->sourceMAC()) return std::string(fbs->sourceMAC()->c_str());
109  else return "";
110  }
111 
112  static std::string sourceIP(void * msgBuffer )
113  {
114  auto fbs = GetTelem_chrony_status_fb(msgBuffer);
115  if(fbs->sourceIP()) return std::string(fbs->sourceIP()->c_str());
116  else return "";
117  }
118 
119  static std::string synch(void * msgBuffer )
120  {
121  auto fbs = GetTelem_chrony_status_fb(msgBuffer);
122  if(fbs->synch()) return std::string(fbs->synch()->c_str());
123  else return "";
124  }
125 
126  static std::string leap(void * msgBuffer )
127  {
128  auto fbs = GetTelem_chrony_status_fb(msgBuffer);
129  if(fbs->leap()) return std::string(fbs->leap()->c_str());
130  else return "";
131  }
132 
133  /// Get pointer to the accessor for a member by name
134  /**
135  * \returns the function pointer cast to void*
136  * \returns -1 for an unknown member
137  */
138  static void * getAccessor( const std::string & member /**< [in] the name of the member */ )
139  {
140  if(member == "sourceMAC") return reinterpret_cast<void*>(&sourceMAC);
141  else if(member == "sourceIP") return reinterpret_cast<void*>(&sourceIP);
142  else if(member == "synch") return reinterpret_cast<void*>(&synch);
143  else if(member == "leap") return reinterpret_cast<void*>(&leap);
144  else
145  {
146  std::cerr << "No string member " << member << " in telem_chrony_status\n";
147  return 0;
148  }
149  }
150 
151 }; //telem_chrony_status
152 
153 
154 } //namespace logger
155 } //namespace MagAOX
156 
157 #endif //logger_types_telem_chrony_status_hpp
158 
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.
messageT(const std::string &mac, const std::string &ip, const std::string &sync, const std::string &leap)
Construct from components.
Log entry recording the status of chrony.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static std::string leap(void *msgBuffer)
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static const flatlogs::logPrioT defaultLevel
The default level.
static void * getAccessor(const std::string &member)
Get pointer to the accessor for a member by name.
static const flatlogs::eventCodeT eventCode
The event code.
static std::string sourceIP(void *msgBuffer)
static std::string synch(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static std::string sourceMAC(void *msgBuffer)