Line data Source code
1 : /** \file telem_position.hpp
2 : * \brief The MagAO-X logger telem_position log type.
3 : * \author Jared R. Males (jaredmales@gmail.com)
4 : *
5 : * \ingroup logger_types_files
6 : *
7 : */
8 : #ifndef logger_types_telem_position_hpp
9 : #define logger_types_telem_position_hpp
10 :
11 : #include "generated/telem_position_generated.h"
12 : #include "flatbuffer_log.hpp"
13 :
14 : namespace MagAOX
15 : {
16 : namespace logger
17 : {
18 :
19 :
20 : /// Log entry recording position stage specific status.
21 : /** \ingroup logger_types
22 : */
23 : struct telem_position : public flatbuffer_log
24 : {
25 : ///The event code
26 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_POSITION;
27 :
28 : ///The default level
29 : static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_TELEM;
30 :
31 : static timespec lastRecord; ///< The timestamp 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 2 : messageT( const float & pos /**<[in] stage position in mm */ )
38 2 : {
39 2 : auto fp = CreateTelem_position_fb(builder, pos);
40 2 : builder.Finish(fp);
41 2 : }
42 :
43 : };
44 :
45 :
46 1 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
47 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
48 : )
49 : {
50 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
51 2 : return VerifyTelem_position_fbBuffer(verifier);
52 : }
53 :
54 : ///Get the message formatte for human consumption.
55 0 : static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
56 : flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
57 : )
58 : {
59 : static_cast<void>(len);
60 :
61 0 : auto fbs = GetTelem_position_fb(msgBuffer);
62 :
63 0 : std::string msg = "[position] ";
64 :
65 0 : msg += "pos: ";
66 0 : msg += std::to_string(fbs->pos()) + " ";
67 :
68 0 : return msg;
69 :
70 0 : }
71 :
72 0 : static float pos( void * msgBuffer )
73 : {
74 0 : auto fbs = GetTelem_position_fb(msgBuffer);
75 0 : return fbs->pos();
76 : }
77 :
78 :
79 : /// Get the logMetaDetail for a member by name
80 : /**
81 : * \returns the a logMetaDetail filled in with the appropriate details
82 : * \returns an empty logMetaDetail if member not recognized
83 : */
84 1 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
85 : {
86 1 : if( member == "pos") return logMetaDetail({"POS", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&pos)});
87 : else
88 : {
89 1 : std::cerr << "No member " << member << " in telem_position\n";
90 1 : return logMetaDetail();
91 : }
92 : }
93 :
94 : }; //telem_position
95 :
96 :
97 :
98 : } //namespace logger
99 : } //namespace MagAOX
100 :
101 : #endif //logger_types_telem_position_hpp
102 :
|