API
 
Loading...
Searching...
No Matches
telem_tcsi_offload.hpp
Go to the documentation of this file.
1/** \file telem_tcsi_offload.hpp
2 * \brief Shared MagAO-X logger type for tcsInterface offload-control telemetry.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_types_files
6 *
7 */
8#ifndef logger_types_telem_tcsi_offload_hpp
9#define logger_types_telem_tcsi_offload_hpp
10
12#include "flatbuffer_log.hpp"
13
14namespace MagAOX
15{
16namespace logger
17{
18
19/// Shared base class for tcsInterface offload-control telemetry.
20/** This provides the common payload and accessors for both tip/tilt and focus
21 * offload-control telemetry records. It is not intended to be used directly as
22 * a logged type.
23 *
24 * \ingroup logger_types_basic
25 */
27{
28 protected:
29 /// Format a shared offload-control message body with a caller-supplied label.
30 static std::string
31 formatMsgString( const char *label, /**< [in] Label identifying the telemetry type. */
32 void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message. */
33 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer. */
34 )
35 {
36 static_cast<void>( len );
37
38 auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
39
40 std::string msg = "[";
41 msg += label;
42 msg += "] ";
43
44 msg += "enabled: ";
45 msg += std::to_string( fbs->enabled() );
46 msg += " avgInt: ";
47 msg += std::to_string( fbs->avgInt() );
48 msg += " gain: ";
49 msg += std::to_string( fbs->gain() );
50 msg += " thresh: ";
51 msg += std::to_string( fbs->thresh() );
52
53 return msg;
54 }
55
56 public:
57 /// The type of the input message
58 struct messageT : public fbMessage
59 {
60 /// Construct from components.
61 messageT( const bool &enabled, ///< [in] whether the offload path is enabled
62 const float &avgInt, ///< [in] the current averaging interval
63 const float &gain, ///< [in] the current offload gain
64 const float &thresh ///< [in] the current offload threshold
65 )
66 {
68 builder.Finish( fp );
69 }
70 };
71
72 static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
73 flatlogs::msgLenT len ///< [in] length of msgBuffer.
74 )
75 {
76 auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
77 static_cast<size_t>( len ) );
78 return VerifyTelem_tcsi_offload_fbBuffer( verifier );
79 }
80
81 /// Format the message for human consumption.
82 static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
83 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
84 )
85 {
86 return formatMsgString( "tcsi_offload", msgBuffer, len );
87 }
88
89 /// Access the enabled state.
90 static bool enabled( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
91 {
92 auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
93 return fbs->enabled();
94 }
95
96 /// Access the offload gain.
97 static float gain( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
98 {
99 auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
100 return fbs->gain();
101 }
102
103 /// Access the offload averaging interval.
104 static float avgInt( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
105 {
106 auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
107 return fbs->avgInt();
108 }
109
110 /// Access the offload threshold.
111 static float thresh( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
112 {
113 auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
114 return fbs->thresh();
115 }
116
117 /// Get the logMetaDetail for a member by name.
118 /**
119 * \returns the a logMetaDetail filled in with the appropriate details
120 * \returns an empty logMetaDetail if member not recognized
121 */
122 static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
123 {
124 if( member == "enabled" )
125 {
126 return logMetaDetail( { "ENABLED",
129 reinterpret_cast<void *>( &enabled ) } );
130 }
131 else if( member == "avgInt" )
132 {
133 return logMetaDetail( { "AVGINT",
136 reinterpret_cast<void *>( &avgInt ) } );
137 }
138 else if( member == "gain" )
139 {
140 return logMetaDetail(
141 { "GAIN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void *>( &gain ) } );
142 }
143 else if( member == "thresh" )
144 {
145 return logMetaDetail( { "THRESH",
148 reinterpret_cast<void *>( &thresh ) } );
149 }
150 else
151 {
152 std::cerr << "No member " << member << " in telem_tcsi_offload\n";
153 return logMetaDetail();
154 }
155 }
156};
157
158} // namespace logger
159} // namespace MagAOX
160
161#endif // logger_types_telem_tcsi_offload_hpp
The MagAO-X logger flatbuffer log base type.
msgLen2T msgLenT
The type used to refer to the message length, regardless of length.
Definition logDefs.hpp:69
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
bool VerifyTelem_tcsi_offload_fbBuffer(::flatbuffers::Verifier &verifier)
inline ::flatbuffers::Offset< Telem_tcsi_offload_fb > CreateTelem_tcsi_offload_fb(::flatbuffers::FlatBufferBuilder &_fbb, bool enabled=false, float avgInt=0.0f, float gain=0.0f, float thresh=0.0f)
const MagAOX::logger::Telem_tcsi_offload_fb * GetTelem_tcsi_offload_fb(const void *buf)
Definition dm.hpp:19
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 bool &enabled, const float &avgInt, const float &gain, const float &thresh)
Construct from components.
Shared base class for tcsInterface offload-control telemetry.
static float gain(void *msgBuffer)
Access the offload gain.
static float thresh(void *msgBuffer)
Access the offload threshold.
static float avgInt(void *msgBuffer)
Access the offload averaging interval.
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static std::string formatMsgString(const char *label, void *msgBuffer, flatlogs::msgLenT len)
Format a shared offload-control message body with a caller-supplied label.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static bool enabled(void *msgBuffer)
Access the enabled state.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Format the message for human consumption.