Line data Source code
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 : */
27 : struct telem_chrony_stats : public flatbuffer_log
28 : {
29 : ///The event code
30 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_CHRONY_STATS;
31 :
32 : ///The default level
33 : static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
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 1 : 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 1 : {
52 :
53 1 : auto fp = CreateTelem_chrony_stats_fb(builder, systemTime, lastOffset, rmsOffset, freq, residFreq, skew, rootDelay, rootDispersion, updateInt);
54 1 : builder.Finish(fp);
55 1 : }
56 :
57 : };
58 :
59 1 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
60 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
61 : )
62 : {
63 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
64 2 : return VerifyTelem_chrony_stats_fbBuffer(verifier);
65 : }
66 :
67 : ///Get the message formatte for human consumption.
68 0 : 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 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
76 :
77 0 : std::string msg = "[chrony_stats] ";
78 :
79 0 : msg += "sys_time: ";
80 0 : snprintf(num, sizeof(num), "%g",fbs->systemTime());
81 0 : msg += num;
82 :
83 0 : msg += " last_off: ";
84 0 : snprintf(num, sizeof(num), "%g",fbs->lastOffset());
85 0 : msg += num;
86 :
87 0 : msg += " rms_off: ";
88 0 : snprintf(num, sizeof(num), "%g",fbs->rmsOffset());
89 0 : msg += num;
90 :
91 0 : msg += " freq: ";
92 0 : snprintf(num, sizeof(num), "%g",fbs->freq());
93 0 : msg += num;
94 :
95 0 : msg += " rfreq: ";
96 0 : snprintf(num, sizeof(num), "%g",fbs->residFreq());
97 0 : msg += num;
98 :
99 0 : msg += " skew: ";
100 0 : snprintf(num, sizeof(num), "%g",fbs->skew());
101 0 : msg += num;
102 :
103 0 : msg += " root_del: ";
104 0 : snprintf(num, sizeof(num), "%g",fbs->rootDelay());
105 0 : msg += num;
106 :
107 0 : msg += " root_disp: ";
108 0 : snprintf(num, sizeof(num), "%g",fbs->rootDispersion());
109 0 : msg += num;
110 :
111 0 : msg += " upd_int: ";
112 0 : msg += std::to_string(fbs->updateInt());
113 :
114 0 : return msg;
115 :
116 0 : }
117 :
118 0 : static double systemTime(void * msgBuffer )
119 : {
120 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
121 0 : return fbs->systemTime();
122 : }
123 :
124 0 : static double lastOffset(void * msgBuffer )
125 : {
126 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
127 0 : return fbs->lastOffset();
128 : }
129 :
130 0 : static double rmsOffset(void * msgBuffer )
131 : {
132 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
133 0 : return fbs->rmsOffset();
134 : }
135 :
136 0 : static double freq(void * msgBuffer )
137 : {
138 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
139 0 : return fbs->freq();
140 : }
141 :
142 0 : static double residFreq(void * msgBuffer )
143 : {
144 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
145 0 : return fbs->residFreq();
146 : }
147 :
148 0 : static double skew(void * msgBuffer )
149 : {
150 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
151 0 : return fbs->skew();
152 : }
153 :
154 0 : static double rootDelay(void * msgBuffer )
155 : {
156 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
157 0 : return fbs->rootDelay();
158 : }
159 :
160 0 : static double rootDispersion(void * msgBuffer )
161 : {
162 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
163 0 : return fbs->rootDispersion();
164 : }
165 :
166 0 : static double updateInt(void * msgBuffer )
167 : {
168 0 : auto fbs = GetTelem_chrony_stats_fb(msgBuffer);
169 0 : 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 1 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
178 : {
179 1 : if( member == "systemTime") return logMetaDetail({"CHRONY SYSTEM TIME", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&systemTime), true});
180 1 : else if( member == "lastOffset") return logMetaDetail({ "CHRONY LAST OFFSET", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&lastOffset), true});
181 1 : else if( member == "rmsOffset") return logMetaDetail({ "CHRONY RMS OFFSET", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&rmsOffset), true});
182 1 : else if( member == "freq") return logMetaDetail({"CHRONY FREQ", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&freq), true});
183 1 : else if( member == "residFreq") return logMetaDetail({"CHRONY RESID FREQ", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&residFreq), true});
184 1 : else if( member == "skew") return logMetaDetail({"CHRONY SKEW", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&skew), true});
185 1 : else if( member == "rootDelay") return logMetaDetail({"CHRONY ROOT DELAY", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&rootDelay), true});
186 1 : else if( member == "rootDispersion") return logMetaDetail({"CHRONY ROOT DISPERSION", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&rootDispersion), true});
187 1 : else if( member == "updateInt") return logMetaDetail({"CHRONY UPDATE INT", "", logMeta::valTypes::Double, logMeta::metaTypes::State, reinterpret_cast<void*>(&updateInt), true});
188 : else
189 : {
190 1 : std::cerr << "No member " << member << " in telem_chrony_stats\n";
191 1 : 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 :
|