API
telem_chrony_stats.hpp
Go to the documentation of this file.
1 /** \file telem_chrony_stats.hpp
2  * \brief The MagAO-X logger telem_chrony_stats 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_stats_hpp
11 #define logger_types_telem_chrony_stats_hpp
12 
13 #include "generated/telem_chrony_stats_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 statistics from chrony.
25 /** \ingroup logger_types
26  */
28 {
29  ///The event code
30  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_CHRONY_STATS;
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 double systemTime, ///< [in] the error in system time
42  const double lastOffset, ///< [in] the last clock offset
43  const double rmsOffset, ///< [in] the rms avg offset
44  const double freq, ///< [in] freq drift of clock
45  const double residFreq, ///< [in] residual after correction
46  const double skew, ///< [in] skew of the drif
47  const double rootDelay, ///< [in] root delay
48  const double rootDispersion, ///< [in] root dispersion
49  const double updateInt ///< [in] the update interval
50  )
51  {
52 
53  auto fp = CreateTelem_chrony_stats_fb(builder, systemTime, lastOffset, rmsOffset, freq, residFreq, skew, rootDelay, rootDispersion, updateInt);
54  builder.Finish(fp);
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_chrony_stats_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  char num[128];
74 
75  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
76 
77  std::string msg = "[chrony_stats] ";
78 
79  msg += "sys_time: ";
80  snprintf(num, sizeof(num), "%g",fbs->systemTime());
81  msg += num;
82 
83  msg += " last_off: ";
84  snprintf(num, sizeof(num), "%g",fbs->lastOffset());
85  msg += num;
86 
87  msg += " rms_off: ";
88  snprintf(num, sizeof(num), "%g",fbs->rmsOffset());
89  msg += num;
90 
91  msg += " freq: ";
92  snprintf(num, sizeof(num), "%g",fbs->freq());
93  msg += num;
94 
95  msg += " rfreq: ";
96  snprintf(num, sizeof(num), "%g",fbs->residFreq());
97  msg += num;
98 
99  msg += " skew: ";
100  snprintf(num, sizeof(num), "%g",fbs->skew());
101  msg += num;
102 
103  msg += " root_del: ";
104  snprintf(num, sizeof(num), "%g",fbs->rootDelay());
105  msg += num;
106 
107  msg += " root_disp: ";
108  snprintf(num, sizeof(num), "%g",fbs->rootDispersion());
109  msg += num;
110 
111  msg += " upd_int: ";
112  msg += std::to_string(fbs->updateInt());
113 
114  return msg;
115 
116  }
117 
118  static double systemTime(void * msgBuffer )
119  {
120  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
121  return fbs->systemTime();
122  }
123 
124  static double lastOffset(void * msgBuffer )
125  {
126  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
127  return fbs->lastOffset();
128  }
129 
130  static double rmsOffset(void * msgBuffer )
131  {
132  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
133  return fbs->rmsOffset();
134  }
135 
136  static double freq(void * msgBuffer )
137  {
138  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
139  return fbs->freq();
140  }
141 
142  static double residFreq(void * msgBuffer )
143  {
144  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
145  return fbs->residFreq();
146  }
147 
148  static double skew(void * msgBuffer )
149  {
150  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
151  return fbs->skew();
152  }
153 
154  static double rootDelay(void * msgBuffer )
155  {
156  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
157  return fbs->rootDelay();
158  }
159 
160  static double rootDispersion(void * msgBuffer )
161  {
162  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
163  return fbs->rootDispersion();
164  }
165 
166  static double updateInt(void * msgBuffer )
167  {
168  auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
169  return fbs->updateInt();
170  }
171 
172  /// Get pointer to the accessor for a member by name
173  /**
174  * \returns the function pointer cast to void*
175  * \returns -1 for an unknown member
176  */
177  static void * getAccessor( const std::string & member /**< [in] the name of the member */ )
178  {
179  if(member == "systemTime") return reinterpret_cast<void*>(&systemTime);
180  if(member == "lastOffset") return reinterpret_cast<void*>(&lastOffset);
181  if(member == "rmsOffset") return reinterpret_cast<void*>(&rmsOffset);
182  if(member == "freq") return reinterpret_cast<void*>(&freq);
183  if(member == "residFreq") return reinterpret_cast<void*>(&residFreq);
184  if(member == "skew") return reinterpret_cast<void*>(&skew);
185  if(member == "rootDelay") return reinterpret_cast<void*>(&rootDelay);
186  if(member == "rootDispersion") return reinterpret_cast<void*>(&rootDispersion);
187  if(member == "updateInt") return reinterpret_cast<void*>(&updateInt);
188  else
189  {
190  std::cerr << "No string member " << member << " in telem_chrony_stats\n";
191  return 0;
192  }
193  }
194 
195 
196 
197 }; //telem_chrony_stats
198 
199 } //namespace logger
200 } //namespace MagAOX
201 
202 #endif //logger_types_telem_chrony_stats_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.
messageT(const double systemTime, const double lastOffset, const double rmsOffset, const double freq, const double residFreq, const double skew, const double rootDelay, const double rootDispersion, const double updateInt)
Construct from components.
Log entry recording the statistics from chrony.
static double rootDispersion(void *msgBuffer)
static void * getAccessor(const std::string &member)
Get pointer to the accessor for a member by name.
static const flatlogs::logPrioT defaultLevel
The default level.
static double skew(void *msgBuffer)
static double freq(void *msgBuffer)
static double lastOffset(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static double systemTime(void *msgBuffer)
static double rmsOffset(void *msgBuffer)
static double rootDelay(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static double updateInt(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static double residFreq(void *msgBuffer)