API
 
Loading...
Searching...
No Matches
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
14#include "flatbuffer_log.hpp"
15
16#include <cmath>
17
18namespace MagAOX
19{
20namespace logger
21{
22
23
24/// Log entry recording the statistics from chrony.
25/** \ingroup logger_types
26 */
28{
29 ///The event code
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
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 the logMetaDetail for a member by name
173 /**
174 * \returns the a logMetaDetail filled in with the appropriate details
175 * \returns an empty logMetaDetail if member not recognized
176 */
177 static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
178 {
179 if( member == "systemTime") return logMetaDetail({"CHRONY SYSTEM TIME", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&systemTime), true});
180 else if( member == "lastOffset") return logMetaDetail({ "CHRONY LAST OFFSET", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&lastOffset), true});
181 else if( member == "rmsOffset") return logMetaDetail({ "CHRONY RMS OFFSET", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&rmsOffset), true});
182 else if( member == "freq") return logMetaDetail({"CHRONY FREQ", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&freq), true});
183 else if( member == "residFreq") return logMetaDetail({"CHRONY RESID FREQ", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&residFreq), true});
184 else if( member == "skew") return logMetaDetail({"CHRONY SKEW", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&skew), true});
185 else if( member == "rootDelay") return logMetaDetail({"CHRONY ROOT DELAY", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&rootDelay), true});
186 else if( member == "rootDispersion") return logMetaDetail({"CHRONY ROOT DISPERSION", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&rootDispersion), true});
187 else if( member == "updateInt") return logMetaDetail({"CHRONY UPDATE INT", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&updateInt), true});
188 else
189 {
190 std::cerr << "No member " << member << " in telem_chrony_stats\n";
191 return logMetaDetail();
192 }
193 }
194
195
196}; //telem_chrony_stats
197
198} //namespace logger
199} //namespace MagAOX
200
201#endif //logger_types_telem_chrony_stats_hpp
202
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.
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
static constexpr flatlogs::eventCodeT TELEM_CHRONY_STATS
Definition logCodes.hpp:55
bool VerifyTelem_chrony_stats_fbBuffer(::flatbuffers::Verifier &verifier)
inline ::flatbuffers::Offset< Telem_chrony_stats_fb > CreateTelem_chrony_stats_fb(::flatbuffers::FlatBufferBuilder &_fbb, double systemTime=0.0, double lastOffset=0.0, double rmsOffset=0.0, double freq=0.0, double residFreq=0.0, double skew=0.0, double rootDelay=0.0, double rootDispersion=0.0, double updateInt=0.0)
const MagAOX::logger::Telem_chrony_stats_fb * GetTelem_chrony_stats_fb(const void *buf)
Definition dm.hpp:28
static constexpr logPrioT LOG_TELEM
A telemetry recording.
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 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 logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static const flatlogs::eventCodeT eventCode
The event code.
static double residFreq(void *msgBuffer)