API
 
Loading...
Searching...
No Matches
telem_pokecenter.hpp
Go to the documentation of this file.
1/** \file telem_pokecenter.hpp
2 * \brief The MagAO-X logger telem_pokecenter log type.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_types_files
6 *
7 */
8#ifndef logger_types_telem_pokecenter_hpp
9#define logger_types_telem_pokecenter_hpp
10
12#include "flatbuffer_log.hpp"
13
14namespace MagAOX
15{
16namespace logger
17{
18
19/// Log entry recording DM poke centering results
20/** \ingroup logger_types
21 */
23{
24 /// The event code
26
27 /// The default level
29
30 static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
31
32 /// The type of the input message
33 struct messageT : public fbMessage
34 {
35 /// Construct from components
36 messageT( const uint8_t &measuring, ///<[in] whether or not measurements are in progress
37 const float &pupil_x, ///<[in] the pupil x position
38 const float &pupil_y, ///<[in] the pupil y position
39 const std::vector<float> &poke_x, ///<[in] the poke x positions, last one the average
40 const std::vector<float> &poke_y ///<[in] the poke y positions, last one the average
41 )
42 {
43 if( measuring == 0 )
44 {
45 Telem_pokecenter_fbBuilder telem_pokecenter_builder( builder );
46 telem_pokecenter_builder.add_measuring( measuring );
47 auto fb = telem_pokecenter_builder.Finish();
48 builder.Finish( fb );
49 return;
50 }
51
52 auto _poke_xs = builder.CreateVector( poke_x );
53 auto _poke_ys = builder.CreateVector( poke_y );
54
55 auto fb = CreateTelem_pokecenter_fb( builder, measuring, pupil_x, pupil_y, _poke_xs, _poke_ys );
56
57 builder.Finish( fb );
58 }
59
60 /// Construct from components with single vector for pokes
61 messageT( const uint8_t &measuring, ///<[in] whether or not measurements are in progress
62 const float &pupil_x, ///<[in] the pupil x position
63 const float &pupil_y, ///<[in] the pupil y position
64 const std::vector<float> &pokes ///<[in] the combined poke positions, last two the averages
65 )
66 {
67 if( measuring == 0 )
68 {
69 Telem_pokecenter_fbBuilder telem_pokecenter_builder( builder );
70 telem_pokecenter_builder.add_measuring( measuring );
71 auto fb = telem_pokecenter_builder.Finish();
72 builder.Finish( fb );
73 return;
74 }
75
76 std::vector<float> poke_x( pokes.size() / 2 );
77 std::vector<float> poke_y( pokes.size() / 2 );
78
79 for( size_t n = 0; n < poke_x.size(); ++n )
80 {
81 poke_x[n] = pokes[2 * n + 0];
82 poke_y[n] = pokes[2 * n + 1];
83 }
84
85 auto _poke_xs = builder.CreateVector( poke_x );
86 auto _poke_ys = builder.CreateVector( poke_y );
87
88 auto fb = CreateTelem_pokecenter_fb( builder, measuring, pupil_x, pupil_y, _poke_xs, _poke_ys );
89
90 builder.Finish( fb );
91 }
92 };
93
94 static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
95 flatlogs::msgLenT len ///< [in] length of msgBuffer.
96 )
97 {
98 auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
99 static_cast<size_t>( len ) );
100 return VerifyTelem_pokecenter_fbBuffer( verifier );
101 }
102
103 /// Get the message formatted for human consumption.
104 static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
105 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
106 )
107 {
108 static_cast<void>( len );
109
110 auto fbs = GetTelem_pokecenter_fb( msgBuffer );
111
112 std::string msg;
113 if( fbs->measuring() == 0 )
114 {
115 msg = "not measuring";
116 return msg;
117 }
118
119 if( fbs->measuring() == 1 )
120 {
121 msg = "single ";
122 }
123 else
124 {
125 msg = "continuous ";
126 }
127
128 msg += "[pupil] ";
129
130 msg += std::to_string( fbs->pupil_x() );
131 msg += " ";
132 msg += std::to_string( fbs->pupil_y() );
133
134 // being very paranoid about existence and length here
135 if( fbs->poke_x() && fbs->poke_y() )
136 {
137 if( fbs->poke_x()->size() == fbs->poke_y()->size() )
138 {
139 size_t N = fbs->poke_x()->size();
140
141 msg += " [poke-avg] ";
142 msg += std::to_string( fbs->poke_x()->Get( N - 1 ) );
143 msg += " ";
144 msg += std::to_string( fbs->poke_y()->Get( N - 1 ) );
145
146 msg += " [pokes]";
147 for( size_t i = 0; i < N - 1; ++i )
148 {
149 msg += " ";
150 msg += std::to_string( fbs->poke_x()->Get( i ) );
151 msg += " ";
152 msg += std::to_string( fbs->poke_y()->Get( i ) );
153 }
154 }
155 else
156 {
157 msg += " [poke-avg] ? [pokes] ?";
158 }
159 }
160 else
161 {
162 msg += " [poke-avg] ? [pokes] ?";
163 }
164
165 return msg;
166 }
167
168 static bool measuring( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
169 {
170 auto fbs = GetTelem_pokecenter_fb( msgBuffer );
171 return fbs->measuring();
172 }
173
174 static float pupil_x( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
175 {
176 auto fbs = GetTelem_pokecenter_fb( msgBuffer );
177 return fbs->pupil_x();
178 }
179
180 static float pupil_y( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
181 {
182 auto fbs = GetTelem_pokecenter_fb( msgBuffer );
183 return fbs->pupil_y();
184 }
185
186 static std::vector<float> poke_x( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
187 {
188 std::vector<float> p;
189
190 auto fbs = GetTelem_pokecenter_fb( msgBuffer );
191
192 if( fbs->poke_x() != nullptr )
193 {
194 for( auto it = fbs->poke_x()->begin(); it != fbs->poke_x()->end(); ++it )
195 {
196 p.push_back( *it );
197 }
198 }
199 return p;
200 }
201
202 static std::vector<float> poke_y( void *msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
203 {
204 std::vector<float> p;
205
206 auto fbs = GetTelem_pokecenter_fb( msgBuffer );
207
208 if( fbs->poke_y() != nullptr )
209 {
210 for( auto it = fbs->poke_y()->begin(); it != fbs->poke_y()->end(); ++it )
211 {
212 p.push_back( *it );
213 }
214 }
215 return p;
216 }
217
218 /// Get the logMetaDetail for a member by name
219 /**
220 * \returns the a logMetaDetail filled in with the appropriate details
221 * \returns an empty logMetaDetail if member not recognized
222 */
223 static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
224 {
225 if( member == "measuring" )
226 return logMetaDetail( { "MEASURING",
227 "measuring state",
230 reinterpret_cast<void *>( &measuring ),
231 false } );
232 else if( member == "pupil_x" )
233 return logMetaDetail( { "PUPIL X",
234 "measured pupil x",
237 reinterpret_cast<void *>( &pupil_x ),
238 false } );
239 else if( member == "pupil_y" )
240 return logMetaDetail( { "PUPIL Y",
241 "measured pupil y",
244 reinterpret_cast<void *>( &pupil_y ),
245 false } );
246 else if( member == "poke_x" )
247 return logMetaDetail( { "POKE X",
248 "actuator poke x, last is avg",
251 reinterpret_cast<void *>( &poke_x ),
252 false } );
253 else if( member == "poke_y" )
254 return logMetaDetail( { "POKE Y",
255 "actuator poke y, last is avg",
258 reinterpret_cast<void *>( &poke_y ),
259 false } );
260 else
261 {
262 std::cerr << "No member " << member << " in telem_pokecenter\n";
263 return logMetaDetail();
264 }
265 }
266
267}; // telem_pokecenter
268
269} // namespace logger
270} // namespace MagAOX
271
272#endif // logger_types_telem_pokecenter_hpp
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_POKECENTER
Definition logCodes.hpp:43
const MagAOX::logger::Telem_pokecenter_fb * GetTelem_pokecenter_fb(const void *buf)
inline ::flatbuffers::Offset< Telem_pokecenter_fb > CreateTelem_pokecenter_fb(::flatbuffers::FlatBufferBuilder &_fbb, uint8_t measuring=0, float pupil_x=0.0f, float pupil_y=0.0f, ::flatbuffers::Offset<::flatbuffers::Vector< float > > poke_x=0, ::flatbuffers::Offset<::flatbuffers::Vector< float > > poke_y=0)
bool VerifyTelem_pokecenter_fbBuffer(::flatbuffers::Verifier &verifier)
Definition dm.hpp:28
static constexpr logPrioT LOG_TELEM
A telemetry recording.
::flatbuffers::Offset< Telem_pokecenter_fb > Finish()
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 uint8_t &measuring, const float &pupil_x, const float &pupil_y, const std::vector< float > &pokes)
Construct from components with single vector for pokes.
messageT(const uint8_t &measuring, const float &pupil_x, const float &pupil_y, const std::vector< float > &poke_x, const std::vector< float > &poke_y)
Construct from components.
Log entry recording DM poke centering results.
static const flatlogs::logPrioT defaultLevel
The default level.
static float pupil_x(void *msgBuffer)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatted for human consumption.
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static float pupil_y(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static std::vector< float > poke_x(void *msgBuffer)
static std::vector< float > poke_y(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static bool measuring(void *msgBuffer)