Line data Source code
1 : /** \file telem_dmmodes.hpp
2 : * \brief The MagAO-X logger telem_dmmodes log type.
3 : * \author Jared Males (jrmales@arizona.edu)
4 : *
5 : * \ingroup logger_types_files
6 : *
7 : * History:
8 : * - 2022-10-09 created by JRM
9 : */
10 : #ifndef logger_types_telem_dmmodes_hpp
11 : #define logger_types_telem_dmmodes_hpp
12 :
13 : #include "generated/telem_dmmodes_generated.h"
14 : #include "flatbuffer_log.hpp"
15 :
16 : namespace MagAOX
17 : {
18 : namespace logger
19 : {
20 :
21 :
22 : /// Log entry recording DM Mode Amplitudes
23 : /** \ingroup logger_types
24 : */
25 : struct telem_dmmodes : public flatbuffer_log
26 : {
27 :
28 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_DMMODES;
29 : static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
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 1 : explicit messageT( std::vector<float> & amps )
38 1 : {
39 1 : auto _ampsVec = builder.CreateVector(amps);
40 :
41 1 : auto fp = CreateTelem_dmmodes_fb(builder, _ampsVec );
42 :
43 1 : builder.Finish(fp);
44 1 : }
45 :
46 : };
47 :
48 1 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
49 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
50 : )
51 : {
52 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
53 2 : return VerifyTelem_dmmodes_fbBuffer(verifier);
54 : }
55 :
56 : ///Get the message formatte for human consumption.
57 0 : static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
58 : flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
59 : )
60 : {
61 :
62 : static_cast<void>(len); // unused by most log types
63 :
64 0 : auto rgs = GetTelem_dmmodes_fb(msgBuffer);
65 :
66 0 : std::string msg;
67 :
68 0 : msg+= "[dmmodes amps] ";
69 :
70 0 : if (rgs->amps() != nullptr)
71 : {
72 0 : for(flatbuffers::Vector<float>::const_iterator it = rgs->amps()->begin(); it != rgs->amps()->end(); ++it)
73 : {
74 0 : msg+= std::to_string(*it);
75 0 : msg+= " ";
76 : }
77 : }
78 :
79 0 : return msg;
80 :
81 0 : }
82 :
83 0 : static std::vector<float> amps( void * msgBuffer )
84 : {
85 0 : std::vector<float> amps;
86 0 : auto fbs = GetTelem_dmmodes_fb(msgBuffer);
87 :
88 0 : if (fbs->amps() != nullptr)
89 : {
90 0 : for(flatbuffers::Vector<float>::const_iterator it = fbs->amps()->begin(); it != fbs->amps()->end(); ++it)
91 : {
92 0 : amps.push_back(*it);
93 : }
94 : }
95 :
96 0 : return amps;
97 0 : }
98 :
99 : /// Get the logMetaDetail for a member by name
100 : /**
101 : * \returns the a logMetaDetail filled in with the appropriate details
102 : * \returns an empty logMetaDetail if member not recognized
103 : */
104 1 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
105 : {
106 1 : if(member == "amps") return logMetaDetail({"AMPS", logMeta::valTypes::Vector_Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&s), false});
107 : else
108 : {
109 1 : std::cerr << "No member " << member << " in telem_dmmodes\n";
110 1 : return logMetaDetail();
111 : }
112 : }
113 :
114 : }; //telem_dmmodes
115 :
116 :
117 :
118 : } //namespace logger
119 : } //namespace MagAOX
120 :
121 : #endif //logger_types_telem_dmmodes_hpp
|