Line data Source code
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 :
11 : #include "generated/telem_tcsi_offload_generated.h"
12 : #include "flatbuffer_log.hpp"
13 :
14 : namespace MagAOX
15 : {
16 : namespace 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 : */
26 : struct telem_tcsi_offload : public flatbuffer_log
27 : {
28 : protected:
29 : /// Format a shared offload-control message body with a caller-supplied label.
30 : static std::string
31 0 : 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 0 : auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
39 :
40 0 : std::string msg = "[";
41 0 : msg += label;
42 0 : msg += "] ";
43 :
44 0 : msg += "enabled: ";
45 0 : msg += std::to_string( fbs->enabled() );
46 0 : msg += " avgInt: ";
47 0 : msg += std::to_string( fbs->avgInt() );
48 0 : msg += " gain: ";
49 0 : msg += std::to_string( fbs->gain() );
50 0 : msg += " thresh: ";
51 0 : msg += std::to_string( fbs->thresh() );
52 :
53 0 : return msg;
54 0 : }
55 :
56 : public:
57 : /// The type of the input message
58 : struct messageT : public fbMessage
59 : {
60 : /// Construct from components.
61 2 : 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 2 : {
67 2 : auto fp = CreateTelem_tcsi_offload_fb( builder, enabled, avgInt, gain, thresh );
68 2 : builder.Finish( fp );
69 2 : }
70 : };
71 :
72 2 : static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
73 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
74 : )
75 : {
76 2 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
77 2 : static_cast<size_t>( len ) );
78 4 : 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 0 : static bool enabled( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
91 : {
92 0 : auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
93 0 : return fbs->enabled();
94 : }
95 :
96 : /// Access the offload gain.
97 0 : static float gain( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
98 : {
99 0 : auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
100 0 : return fbs->gain();
101 : }
102 :
103 : /// Access the offload averaging interval.
104 0 : static float avgInt( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
105 : {
106 0 : auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
107 0 : return fbs->avgInt();
108 : }
109 :
110 : /// Access the offload threshold.
111 0 : static float thresh( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
112 : {
113 0 : auto fbs = GetTelem_tcsi_offload_fb( msgBuffer );
114 0 : 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 0 : static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
123 : {
124 0 : if( member == "enabled" )
125 : {
126 : return logMetaDetail( { "ENABLED",
127 : logMeta::valTypes::Bool,
128 : logMeta::metaTypes::State,
129 0 : reinterpret_cast<void *>( &enabled ) } );
130 : }
131 0 : else if( member == "avgInt" )
132 : {
133 : return logMetaDetail( { "AVGINT",
134 : logMeta::valTypes::Float,
135 : logMeta::metaTypes::State,
136 0 : reinterpret_cast<void *>( &avgInt ) } );
137 : }
138 0 : else if( member == "gain" )
139 : {
140 : return logMetaDetail(
141 0 : { "GAIN", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void *>( &gain ) } );
142 : }
143 0 : else if( member == "thresh" )
144 : {
145 : return logMetaDetail( { "THRESH",
146 : logMeta::valTypes::Float,
147 : logMeta::metaTypes::State,
148 0 : reinterpret_cast<void *>( &thresh ) } );
149 : }
150 : else
151 : {
152 0 : std::cerr << "No member " << member << " in telem_tcsi_offload\n";
153 0 : return logMetaDetail();
154 : }
155 : }
156 : };
157 :
158 : } // namespace logger
159 : } // namespace MagAOX
160 :
161 : #endif // logger_types_telem_tcsi_offload_hpp
|