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 #include "../logMeta.hpp"
16 
17 namespace MagAOX
18 {
19 namespace logger
20 {
21 
22 
23 /// Log entry recording zaber stage specific status.
24 /** \ingroup logger_types
25  */
26 struct telem_zaber : public flatbuffer_log
27 {
28  ///The event code
29  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_ZABER;
30 
31  ///The default level
33 
34  static timespec lastRecord; ///< The timestamp of the last time this log was recorded. Used by the telemetry system.
35 
36  ///The type of the input message
37  struct messageT : public fbMessage
38  {
39  ///Construct from components
40  messageT( const float & pos, ///<[in] stage position in mm
41  const float & rawPos, ///<[in] stage raw position, in counts
42  const float & temp ///<[in] stage temperature
43  )
44  {
45  auto fp = CreateTelem_zaber_fb(builder, pos, rawPos, temp);
46  builder.Finish(fp);
47  }
48 
49  };
50 
51 
52  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
53  flatlogs::msgLenT len ///< [in] length of msgBuffer.
54  )
55  {
56  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
57  return VerifyTelem_zaber_fbBuffer(verifier);
58  }
59 
60  ///Get the message formatte for human consumption.
61  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
62  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
63  )
64  {
65  static_cast<void>(len);
66 
67  auto fbs = GetTelem_zaber_fb(msgBuffer);
68 
69  std::string msg = "[zaber] ";
70 
71  msg += "pos: ";
72  msg += std::to_string(fbs->pos()) + " ";
73 
74  msg += "rawPos: ";
75  msg += std::to_string(fbs->rawPos()) + " ";
76 
77  msg += "temp: ";
78  msg += std::to_string(fbs->temp());
79 
80  return msg;
81 
82  }
83 
84  static float pos( void * msgBuffer )
85  {
86  auto fbs = GetTelem_zaber_fb(msgBuffer);
87  return fbs->pos();
88  }
89 
90  static float rawPos( void * msgBuffer )
91  {
92  auto fbs = GetTelem_zaber_fb(msgBuffer);
93  return fbs->rawPos();
94  }
95 
96  static float temp( void * msgBuffer )
97  {
98  auto fbs = GetTelem_zaber_fb(msgBuffer);
99  return fbs->temp();
100  }
101 
102  /// Get the logMetaDetail for a member by name
103  /**
104  * \returns the a logMetaDetail filled in with the appropriate details
105  * \returns an empty logmegaDetail if member not recognized
106  */
107  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
108  {
109  if( member == "pos") return logMetaDetail({"POS", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&pos)});
110  else if(member == "rawPos") return logMetaDetail({"COUNTS", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&rawPos)});
111  else if(member == "temp") return logMetaDetail({"TEMP", logMeta::valTypes::Float, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&temp)});
112  else
113  {
114  std::cerr << "No string member " << member << " in telem_zaber\n";
115  return logMetaDetail();
116  }
117  }
118 
119 }; //telem_zaber
120 
121 
122 
123 } //namespace logger
124 } //namespace MagAOX
125 
126 #endif //logger_types_telem_zaber_hpp
127 
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:38
messageT(const float &pos, const float &rawPos, const float &temp)
Construct from components.
Definition: telem_zaber.hpp:40
Log entry recording zaber stage specific status.
Definition: telem_zaber.hpp:27
static float pos(void *msgBuffer)
Definition: telem_zaber.hpp:84
static float temp(void *msgBuffer)
Definition: telem_zaber.hpp:96
static const flatlogs::logPrioT defaultLevel
The default level.
Definition: telem_zaber.hpp:32
static const flatlogs::eventCodeT eventCode
The event code.
Definition: telem_zaber.hpp:29
static float rawPos(void *msgBuffer)
Definition: telem_zaber.hpp:90
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:52
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
Definition: telem_zaber.hpp:34
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
Definition: telem_zaber.hpp:61