Line data Source code
1 : /** \file telem_dmspeck.hpp
2 : * \brief The MagAO-X logger telem_dmspeck log type.
3 : * \author Jared R. Males (jaredmales@gmail.com)
4 : *
5 : * \ingroup logger_types_files
6 : *
7 : * History:
8 : * - 2022-02-06 created by JRM
9 : */
10 : #ifndef logger_types_telem_dmspeck_hpp
11 : #define logger_types_telem_dmspeck_hpp
12 :
13 : #include "generated/telem_dmspeck_generated.h"
14 : #include "flatbuffer_log.hpp"
15 :
16 : namespace MagAOX
17 : {
18 : namespace logger
19 : {
20 :
21 :
22 : /// Log entry recording stdMotionStage status.
23 : /** \ingroup logger_types
24 : */
25 : struct telem_dmspeck : public flatbuffer_log
26 : {
27 : ///The event code
28 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_DMSPECK;
29 :
30 : ///The default level
31 : static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
32 :
33 : static timespec lastRecord; ///< The timestamp of the last time this log was recorded. Used by the telemetry system.
34 :
35 : ///The type of the input message
36 : struct messageT : public fbMessage
37 : {
38 : ///Construct from components
39 1 : messageT( const bool & modulating, ///< [in] whether or not the speckle is being modulated
40 : const bool & trigger, ///< [in] whether or not the speckle is being triggered
41 : const float & frequency, ///< [in] frequency of modulation is not triggered
42 : const std::vector<float> & separations, ///< [in] the separations of the speckle(s)
43 : const std::vector<float> & angles, ///< [in] the angles of the speckle(s)
44 : const std::vector<float> & amplitudes, ///< [in] the amplitudes of the speckle(s)
45 : const std::vector<bool> & crosses ///< [in] whether or not the cross speckle(s) are produced
46 : )
47 1 : {
48 1 : auto _separationsVec = builder.CreateVector(separations);
49 1 : auto _anglesVec = builder.CreateVector(angles);
50 1 : auto _amplitudesVec = builder.CreateVector(amplitudes);
51 1 : auto _crossesVec = builder.CreateVector(crosses);
52 :
53 1 : auto fp = CreateTelem_dmspeck_fb(builder, modulating, trigger, frequency, _separationsVec, _anglesVec, _amplitudesVec, _crossesVec);
54 1 : builder.Finish(fp);
55 1 : }
56 :
57 : };
58 :
59 1 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
60 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
61 : )
62 : {
63 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
64 2 : return VerifyTelem_dmspeck_fbBuffer(verifier);
65 : }
66 :
67 : ///Get the message formatte for human consumption.
68 0 : static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
69 : flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
70 : )
71 : {
72 : static_cast<void>(len);
73 :
74 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
75 :
76 0 : std::string msg = "[speckles] ";
77 :
78 0 : if(!fbs->modulating())
79 : {
80 0 : msg += "not modulating";
81 0 : return msg;
82 : }
83 :
84 0 : msg += "modulating";
85 0 : if(fbs->trigger())
86 : {
87 0 : msg += " by trigger ";
88 : }
89 : else
90 : {
91 0 : msg += " at ";
92 0 : msg += std::to_string(fbs->frequency());
93 0 : msg += " Hz ";
94 : }
95 :
96 0 : msg += "seps: ";
97 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->separations()->begin(); it != fbs->separations()->end(); ++it)
98 : {
99 0 : msg+= std::to_string(*it);
100 0 : msg+= " ";
101 : }
102 0 : msg += "angs: ";
103 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->angles()->begin(); it != fbs->angles()->end(); ++it)
104 : {
105 0 : msg+= std::to_string(*it);
106 0 : msg+= " ";
107 : }
108 0 : msg += "amps: ";
109 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->amplitudes()->begin(); it != fbs->amplitudes()->end(); ++it)
110 : {
111 0 : msg+= std::to_string(*it);
112 0 : msg+= " ";
113 : }
114 0 : for(flatbuffers::Vector<unsigned char>::const_iterator it = fbs->crosses()->begin(); it != fbs->crosses()->end(); ++it)
115 : {
116 0 : if(*it) msg += "+";
117 0 : else msg += "-";
118 : }
119 :
120 :
121 0 : return msg;
122 :
123 0 : }
124 :
125 0 : static bool modulating( void * msgBuffer )
126 : {
127 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
128 0 : return fbs->modulating();
129 : }
130 :
131 0 : static bool trigger( void * msgBuffer )
132 : {
133 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
134 0 : return fbs->trigger();
135 : }
136 :
137 0 : static float frequency( void * msgBuffer )
138 : {
139 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
140 0 : return fbs->frequency();
141 : }
142 :
143 0 : static std::vector<float> separations( void * msgBuffer )
144 : {
145 0 : std::vector<float> v;
146 :
147 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
148 :
149 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->separations()->begin(); it != fbs->separations()->end(); ++it)
150 : {
151 0 : v.push_back(*it);
152 : }
153 :
154 0 : return v;
155 0 : }
156 :
157 0 : static std::vector<float> angles( void * msgBuffer )
158 : {
159 0 : std::vector<float> v;
160 :
161 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
162 :
163 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->angles()->begin(); it != fbs->angles()->end(); ++it)
164 : {
165 0 : v.push_back(*it);
166 : }
167 :
168 0 : return v;
169 0 : }
170 :
171 0 : static std::vector<float> amplitudes( void * msgBuffer )
172 : {
173 0 : std::vector<float> v;
174 :
175 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
176 :
177 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->amplitudes()->begin(); it != fbs->amplitudes()->end(); ++it)
178 : {
179 0 : v.push_back(*it);
180 : }
181 :
182 0 : return v;
183 0 : }
184 :
185 0 : static std::vector<bool> crosses( void * msgBuffer )
186 : {
187 0 : std::vector<bool> v;
188 :
189 0 : auto fbs = GetTelem_dmspeck_fb(msgBuffer);
190 :
191 0 : for(flatbuffers::Vector<unsigned char>::const_iterator it = fbs->crosses()->begin(); it != fbs->crosses()->end(); ++it)
192 : {
193 0 : v.push_back(*it);
194 : }
195 :
196 0 : return v;
197 0 : }
198 :
199 : /// Get the logMetaDetail for a member by name
200 : /**
201 : * \returns the a logMetaDetail filled in with the appropriate details
202 : * \returns an empty logMetaDetail if member not recognized
203 : */
204 1 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
205 : {
206 1 : if(member == "modulating") return logMetaDetail({"MODULATING", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&modulating)});
207 1 : else if(member == "trigger") return logMetaDetail({"TRIGGERED", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&trigger)});
208 1 : else if(member == "frequency") return logMetaDetail({"FREQUENCY", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&frequency)});
209 1 : else if(member == "separations") return logMetaDetail({"SEPARATIONS", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&separations)});
210 1 : else if(member == "angles") return logMetaDetail({"ANGLES", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&angles)});
211 1 : else if(member == "amplitudes") return logMetaDetail({"AMPLITUDES", logMeta::valTypes::Vector_Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&litudes)});
212 1 : else if(member == "crosses") return logMetaDetail({"CROSSES", logMeta::valTypes::Vector_Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&crosses)});
213 : else
214 : {
215 1 : std::cerr << "No member " << member << " in telem_dmspeck\n";
216 1 : return logMetaDetail();
217 : }
218 : }
219 :
220 : }; //telem_dmspeck
221 :
222 :
223 :
224 : } //namespace logger
225 : } //namespace MagAOX
226 :
227 : #endif //logger_types_telem_dmspeck_hpp
228 :
|