Line data Source code
1 : /** \file telem_pico.hpp
2 : * \brief The MagAO-X logger telem_pico log type.
3 : * \author Chris Bohlman (cbohlmanaz@gmail.com)
4 : *
5 : * \ingroup logger_types_files
6 : *
7 : * History:
8 : * - 2018-10-15 created by CJB
9 : */
10 : #ifndef logger_types_telem_pico_hpp
11 : #define logger_types_telem_pico_hpp
12 :
13 : #include "generated/telem_pico_generated.h"
14 : #include "flatbuffer_log.hpp"
15 :
16 : namespace MagAOX
17 : {
18 : namespace logger
19 : {
20 :
21 :
22 : /// Log entry recording CPU temperatures
23 : /** \ingroup logger_types
24 : */
25 : struct telem_pico : public flatbuffer_log
26 : {
27 :
28 : static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_PICO;
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 : messageT( std::vector<int64_t> & counts )
38 1 : {
39 1 : auto _countsVec = builder.CreateVector(counts);
40 :
41 1 : auto fp = CreateTelem_pico_fb(builder, _countsVec );
42 :
43 1 : builder.Finish(fp);
44 :
45 1 : }
46 :
47 : };
48 :
49 1 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
50 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
51 : )
52 : {
53 1 : auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
54 2 : return VerifyTelem_pico_fbBuffer(verifier);
55 : }
56 :
57 : ///Get the message formatte for human consumption.
58 0 : static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
59 : flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
60 : )
61 : {
62 :
63 : static_cast<void>(len); // unused by most log types
64 :
65 0 : auto rgs = GetTelem_pico_fb(msgBuffer);
66 :
67 0 : std::string msg;
68 :
69 0 : if (rgs->counts() != nullptr)
70 : {
71 0 : msg+= "[pico pos] ";
72 0 : for(flatbuffers::Vector<int64_t>::const_iterator it = rgs->counts()->begin(); it != rgs->counts()->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<long long int> counts( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
84 : {
85 0 : std::vector<long long int> countsvec;
86 :
87 0 : auto rgs = GetTelem_pico_fb(msgBuffer);
88 :
89 0 : if (rgs->counts() != nullptr)
90 : {
91 0 : for(auto it = rgs->counts()->begin(); it != rgs->counts()->end(); ++it)
92 : {
93 0 : countsvec.push_back(*it);
94 : }
95 : }
96 :
97 0 : return countsvec;
98 0 : }
99 :
100 : /// Get the logMetaDetail for a member by name
101 : /**
102 : * \returns the a logMetaDetail filled in with the appropriate details
103 : * \returns an empty logMetaDetail if member not recognized
104 : */
105 1 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
106 : {
107 1 : if( member == "counts") return logMetaDetail({"COUNTS", "motor positions in counts", logMeta::valTypes::Vector_LongLong, logMeta::metaTypes::State, reinterpret_cast<void*>(&counts), false});
108 : else
109 : {
110 1 : std::cerr << "No member " << member << " in telem_pico\n";
111 1 : return logMetaDetail();
112 : }
113 : }
114 : }; //telem_pico
115 :
116 :
117 :
118 : } //namespace logger
119 : } //namespace MagAOX
120 :
121 : #endif //logger_types_telem_pico_hpp
|