API
telem_zaber.hpp
Go to the documentation of this file.
1 /** \file telem_zaber.hpp
2  * \brief The MagAO-X logger telem_zaber log type.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_types_files
6  *
7  * History:
8  * - 2018-09-06 created by JRM
9  */
10 #ifndef logger_types_telem_zaber_hpp
11 #define logger_types_telem_zaber_hpp
12 
13 #include "generated/telem_zaber_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording zaber stage specific status.
23 /** \ingroup logger_types
24  */
25 struct telem_zaber : public flatbuffer_log
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_ZABER;
29 
30  ///The default level
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  messageT( const float & pos, ///<[in] stage position in mm
40  const float & rawPos, ///<[in] stage raw position, in counts
41  const float & temp ///<[in] stage temperature
42  )
43  {
44  auto fp = CreateTelem_zaber_fb(builder, pos, rawPos, temp);
45  builder.Finish(fp);
46  }
47 
48  };
49 
50 
51  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
52  flatlogs::msgLenT len ///< [in] length of msgBuffer.
53  )
54  {
55  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
56  return VerifyTelem_zaber_fbBuffer(verifier);
57  }
58 
59  ///Get the message formatte for human consumption.
60  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
61  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
62  )
63  {
64  static_cast<void>(len);
65 
66  auto fbs = GetTelem_zaber_fb(msgBuffer);
67 
68  std::string msg = "[zaber] ";
69 
70  msg += "pos: ";
71  msg += std::to_string(fbs->pos()) + " ";
72 
73  msg += "rawPos: ";
74  msg += std::to_string(fbs->rawPos()) + " ";
75 
76  msg += "temp: ";
77  msg += std::to_string(fbs->temp());
78 
79  return msg;
80 
81  }
82 
83  static float pos( void * msgBuffer )
84  {
85  auto fbs = GetTelem_zaber_fb(msgBuffer);
86  return fbs->pos();
87  }
88 
89  static float rawPos( void * msgBuffer )
90  {
91  auto fbs = GetTelem_zaber_fb(msgBuffer);
92  return fbs->rawPos();
93  }
94 
95  static float temp( void * msgBuffer )
96  {
97  auto fbs = GetTelem_zaber_fb(msgBuffer);
98  return fbs->temp();
99  }
100 
101  /// Get the logMetaDetail for a member by name
102  /**
103  * \returns the a logMetaDetail filled in with the appropriate details
104  * \returns an empty logmegaDetail if member not recognized
105  */
106  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
107  {
108  if( member == "pos") return logMetaDetail({"POS", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&pos)});
109  else if(member == "rawPos") return logMetaDetail({"COUNTS", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&rawPos)});
110  else if(member == "temp") return logMetaDetail({"TEMP", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&temp)});
111  else
112  {
113  std::cerr << "No string member " << member << " in telem_zaber\n";
114  return logMetaDetail();
115  }
116  }
117 
118 }; //telem_zaber
119 
120 
121 
122 } //namespace logger
123 } //namespace MagAOX
124 
125 #endif //logger_types_telem_zaber_hpp
126 
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.
Definition: logHeader.hpp:621
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition: logHeader.hpp:58
std::ostream & cerr()
std::stringstream msg
Definition: dm.hpp:24
constexpr static logPrioT LOG_TELEM
A telemetry recording.
Definition: logPriority.hpp:58
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
The type of the input message.
Definition: telem_zaber.hpp:37
messageT(const float &pos, const float &rawPos, const float &temp)
Construct from components.
Definition: telem_zaber.hpp:39
Log entry recording zaber stage specific status.
Definition: telem_zaber.hpp:26
static float pos(void *msgBuffer)
Definition: telem_zaber.hpp:83
static float temp(void *msgBuffer)
Definition: telem_zaber.hpp:95
static const flatlogs::logPrioT defaultLevel
The default level.
Definition: telem_zaber.hpp:31
static const flatlogs::eventCodeT eventCode
The event code.
Definition: telem_zaber.hpp:28
static float rawPos(void *msgBuffer)
Definition: telem_zaber.hpp:89
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
Definition: telem_zaber.hpp:51
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
Definition: telem_zaber.hpp:33
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
Definition: telem_zaber.hpp:60