API
telem_stage.hpp
Go to the documentation of this file.
1 /** \file telem_stage.hpp
2  * \brief The MagAO-X logger telem_stage 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_stage_hpp
11 #define logger_types_telem_stage_hpp
12 
13 #include "generated/telem_stage_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording stdMotionStage status.
23 /** \ingroup logger_types
24  */
25 struct telem_stage : public flatbuffer_log
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_STAGE;
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 int8_t & moving, ///<[in] whether or not stage is in motion
40  const float & preset, ///<[in] current position of stage in preset units
41  const std::string & presetName ///<[in] current preset name
42  )
43  {
44  auto _name = builder.CreateString(presetName);
45 
46  auto fp = CreateTelem_stage_fb(builder, moving, preset, _name);
47  builder.Finish(fp);
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_stage_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_stage_fb(msgBuffer);
68 
69  std::string msg = "[stage] ";
70 
71  msg += "status: ";
72  if(fbs->moving() == -2) msg += " OFF ";
73  else if(fbs->moving() == -1) msg += " NOTHOMED ";
74  else if(fbs->moving() == 0) msg += " STOPPED ";
75  else if(fbs->moving() == 1) msg += " MOVING ";
76  else if(fbs->moving() == 2) msg += " HOMING ";
77 
78  msg += "preset: ";
79  msg += std::to_string(fbs->preset()) + " ";
80 
81  msg += "name: ";
82  if(fbs->presetName())
83  {
84  msg += fbs->presetName()->c_str();
85  }
86 
87  return msg;
88 
89  }
90 
91  static int moving( void * msgBuffer )
92  {
93  auto fbs = GetTelem_stage_fb(msgBuffer);
94  return fbs->moving();
95  }
96 
97  static float preset( void * msgBuffer )
98  {
99  auto fbs = GetTelem_stage_fb(msgBuffer);
100  return fbs->preset();
101  }
102 
103  static std::string presetName( void * msgBuffer )
104  {
105  auto fbs = GetTelem_stage_fb(msgBuffer);
106  if(fbs->presetName())
107  {
108  return std::string(fbs->presetName()->c_str());
109  }
110  else return std::string();
111  }
112 
113  /// Get the logMetaDetail for a member by name
114  /**
115  * \returns the function pointer cast to void*
116  * \returns -1 for an unknown member
117  */
118  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
119  {
120  if( member == "moving") return logMetaDetail({"MOVING", logMeta::valTypes::Int, logMeta::metaTypes::State, reinterpret_cast<void*>(&moving)});
121  else if(member == "preset") return logMetaDetail({"PRESET POSITION", logMeta::valTypes::Float, logMeta::metaTypes::State, reinterpret_cast<void*>(&preset)});
122  else if(member == "presetName") return logMetaDetail({"PRESET NAME", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&presetName)});
123  else
124  {
125  std::cerr << "No string member " << member << " in telem_stage\n";
126  return logMetaDetail();
127  }
128  }
129 
130 }; //telem_stage
131 
132 
133 
134 } //namespace logger
135 } //namespace MagAOX
136 
137 #endif //logger_types_telem_stage_hpp
138 
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_stage.hpp:37
messageT(const int8_t &moving, const float &preset, const std::string &presetName)
Construct from components.
Definition: telem_stage.hpp:39
Log entry recording stdMotionStage status.
Definition: telem_stage.hpp:26
static const flatlogs::logPrioT defaultLevel
The default level.
Definition: telem_stage.hpp:31
static float preset(void *msgBuffer)
Definition: telem_stage.hpp:97
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static std::string presetName(void *msgBuffer)
static timespec lastRecord
The timestamp of the last time this log was recorded. Used by the telemetry system.
Definition: telem_stage.hpp:33
static const flatlogs::eventCodeT eventCode
The event code.
Definition: telem_stage.hpp:28
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
Definition: telem_stage.hpp:61
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
Definition: telem_stage.hpp:52
static int moving(void *msgBuffer)
Definition: telem_stage.hpp:91