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
11#include "generated/telem_pokecenter_generated.h"
12#include "flatbuffer_log.hpp"
13
14namespace MagAOX
15{
16namespace logger
17{
18
19
20/// Log entry recording DM poke centering results
21/** \ingroup logger_types
22 */
24{
25 ///The event code
26 static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_POKECENTER;
27
28 ///The default level
30
31 static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
32
33 ///The type of the input message
34 struct messageT : public fbMessage
35 {
36 ///Construct from components
37 messageT( const uint8_t & measuring, ///<[in] whether or not measurements are in progress
38 const float & pupil_x, ///<[in] the pupil x position
39 const float & pupil_y, ///<[in] the pupil y position
40 const std::vector<float> & poke_x, ///<[in] the poke x positions, last one the average
41 const std::vector<float> & poke_y ///<[in] the poke y positions, last one the average
42 )
43 {
44 if(measuring == 0)
45 {
46 Telem_pokecenter_fbBuilder telem_pokecenter_builder(builder);
47 telem_pokecenter_builder.add_measuring(measuring);
48 auto fb = telem_pokecenter_builder.Finish();
49 builder.Finish(fb);
50 return;
51 }
52
53 auto _poke_xs = builder.CreateVector(poke_x);
54 auto _poke_ys = builder.CreateVector(poke_y);
55
56 auto fb = CreateTelem_pokecenter_fb(builder, measuring, pupil_x, pupil_y, _poke_xs, _poke_ys);
57
58 builder.Finish(fb);
59 }
60
61 ///Construct from components with single vector for pokes
62 messageT( const uint8_t & measuring, ///<[in] whether or not measurements are in progress
63 const float & pupil_x, ///<[in] the pupil x position
64 const float & pupil_y, ///<[in] the pupil y position
65 const std::vector<float> & pokes ///<[in] the combined poke positions, last two the averages
66 )
67 {
68 if(measuring == 0)
69 {
70 Telem_pokecenter_fbBuilder telem_pokecenter_builder(builder);
71 telem_pokecenter_builder.add_measuring(measuring);
72 auto fb = telem_pokecenter_builder.Finish();
73 builder.Finish(fb);
74 return;
75 }
76
77 std::vector<float> poke_x(pokes.size()/2);
78 std::vector<float> poke_y(pokes.size()/2);
79
80 for(size_t n = 0; n < poke_x.size(); ++n)
81 {
82 poke_x[n] = pokes[2*n + 0];
83 poke_y[n] = pokes[2*n + 1];
84 }
85
86 auto _poke_xs = builder.CreateVector(poke_x);
87 auto _poke_ys = builder.CreateVector(poke_y);
88
89 auto fb = CreateTelem_pokecenter_fb(builder, measuring, pupil_x, pupil_y, _poke_xs, _poke_ys);
90
91 builder.Finish(fb);
92 }
93 };
94
95 static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
96 flatlogs::msgLenT len ///< [in] length of msgBuffer.
97 )
98 {
99 auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), 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
169}; //telem_pokecenter
170
171
172
173} //namespace logger
174} //namespace MagAOX
175
176#endif //logger_types_telem_pokecenter_hpp
177
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
Definition dm.hpp:24
static constexpr logPrioT LOG_TELEM
A telemetry recording.
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 std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatted for human consumption.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
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.