Line data Source code
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 : */
27 : struct telem_chrony_status : public flatbuffer_log
28 : {
29 : ///The event code
30 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_CHRONY_STATUS;
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 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 1 : {
47 1 : auto _mac = builder.CreateString(mac);
48 1 : auto _ip = builder.CreateString(ip);
49 1 : auto _sync = builder.CreateString(sync);
50 1 : auto _leap = builder.CreateString(leap);
51 :
52 1 : auto fp = CreateTelem_chrony_status_fb(builder, _mac, _ip, _sync, _leap);
53 1 : builder.Finish(fp);
54 1 : }
55 :
56 : };
57 :
58 1 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
59 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
60 : )
61 : {
62 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
63 2 : return VerifyTelem_chrony_status_fbBuffer(verifier);
64 : }
65 :
66 : ///Get the message formatte for human consumption.
67 0 : 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 0 : auto fbs = GetTelem_chrony_status_fb(msgBuffer);
74 :
75 0 : std::string msg = "[chrony_status] ";
76 :
77 0 : msg += "source: ";
78 0 : if(fbs->sourceMAC())
79 : {
80 0 : msg += fbs->sourceMAC()->c_str();
81 0 : msg +="/";
82 : }
83 :
84 0 : if(fbs->sourceIP())
85 : {
86 0 : msg += fbs->sourceIP()->c_str();
87 : }
88 :
89 0 : if(fbs->synch())
90 : {
91 0 : msg += " synch: ";
92 0 : msg += fbs->synch()->c_str();
93 : }
94 :
95 0 : if(fbs->leap())
96 : {
97 0 : msg += " leap: ";
98 0 : msg += fbs->leap()->c_str();
99 : }
100 :
101 0 : return msg;
102 :
103 0 : }
104 :
105 0 : static std::string sourceMAC(void * msgBuffer )
106 : {
107 0 : auto fbs = GetTelem_chrony_status_fb(msgBuffer);
108 0 : if(fbs->sourceMAC()) return std::string(fbs->sourceMAC()->c_str());
109 0 : else return "";
110 : }
111 :
112 0 : static std::string sourceIP(void * msgBuffer )
113 : {
114 0 : auto fbs = GetTelem_chrony_status_fb(msgBuffer);
115 0 : if(fbs->sourceIP()) return std::string(fbs->sourceIP()->c_str());
116 0 : else return "";
117 : }
118 :
119 0 : static std::string synch(void * msgBuffer )
120 : {
121 0 : auto fbs = GetTelem_chrony_status_fb(msgBuffer);
122 0 : if(fbs->synch()) return std::string(fbs->synch()->c_str());
123 0 : else return "";
124 : }
125 :
126 0 : static std::string leap(void * msgBuffer )
127 : {
128 0 : auto fbs = GetTelem_chrony_status_fb(msgBuffer);
129 0 : if(fbs->leap()) return std::string(fbs->leap()->c_str());
130 0 : else return "";
131 : }
132 :
133 : /// Get the logMetaDetail for a member by name
134 : /**
135 : * \returns the a logMetaDetail filled in with the appropriate details
136 : * \returns an empty logMetaDetail if member not recognized
137 : */
138 1 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
139 : {
140 1 : if( member == "sourceMAC") return logMetaDetail({"CHRONY SOURCE MAC", "", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&sourceMAC), false});
141 1 : else if( member == "sourceIP") return logMetaDetail({"CHRONY SOURCE IP", "", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&sourceIP), false});
142 1 : else if( member == "synch") return logMetaDetail({"CHRONY SYNC STATUS", "", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&synch), false});
143 1 : else if( member == "leap") return logMetaDetail({"CHRONY LEAP STATUS", "", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&leap), false});
144 : else
145 : {
146 1 : std::cerr << "No member " << member << " in telem_chrony_status\n";
147 1 : return logMetaDetail();
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 :
|