API
telem_cooler.hpp
Go to the documentation of this file.
1 /** \file telem_cooler.hpp
2  * \brief The MagAO-X logger telem_cooler 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_cooler_hpp
11 #define logger_types_telem_cooler_hpp
12 
13 #include "generated/telem_cooler_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 #include <cmath>
17 
18 namespace MagAOX
19 {
20 namespace logger
21 {
22 
23 
24 /// Log entry recording the build-time git state.
25 /** \ingroup logger_types
26  */
28 {
29  ///The event code
30  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_COOLER;
31 
32  ///The default level
34 
35  static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
36 
38 
39  ///The type of the input message
40  struct messageT : public fbMessage
41  {
42  ///Construct from components
43  messageT( const float & liqTemp, ///<[in] liquid temperature
44  const float & flowRate, ///<[in] flow rate
45  const uint8_t & pumpLvl, ///<[in] pump level
46  const uint16_t & pumpSpd, ///<[in] pump speed
47  const uint8_t & fanLvl, ///<[in] fan level
48  const uint16_t & fanSpd ///<[in] fan speed
49  )
50  {
51  auto fp = CreateTelem_cooler_fb(builder, liqTemp, flowRate, pumpLvl, pumpSpd, fanLvl, fanSpd);
52  builder.Finish(fp);
53  }
54 
55  };
56 
57 
58  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
59  flatlogs::msgLenT len ///< [in] length of msgBuffer.
60  )
61  {
62  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
63  return VerifyTelem_cooler_fbBuffer(verifier);
64  }
65 
66  ///Get the message formatte for human consumption.
67  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
68  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
69  )
70  {
71  static_cast<void>(len);
72 
73  auto fbs = GetTelem_cooler_fb(msgBuffer);
74 
75  std::string msg = "[cooler] ";
76 
77  msg += "temp: ";
78  msg += std::to_string(fbs->liquidTemp()) + " C ";
79 
80  msg += "flow: ";
81  msg += std::to_string(fbs->flowRate()) + " L/min ";
82 
83  msg += "pump lvl: ";
84  msg += std::to_string(fbs->pumpLevel()) + " ";
85 
86  msg += "spd: ";
87  msg += std::to_string(fbs->pumpSpeed()) + " RPM ";
88 
89  msg += "fan lvl: ";
90  msg += std::to_string(fbs->fanLevel()) + " ";
91 
92  msg += "speed: ";
93  msg += std::to_string(fbs->fanSpeed()) + " RPM ";
94 
95  return msg;
96 
97  }
98 
99  static double getDouble( flatlogs::bufferPtrT & buffer,
100  member m
101  )
102  {
103  switch(m)
104  {
105  case em_liquidTemp:
106  return GetTelem_cooler_fb(flatlogs::logHeader::messageBuffer(buffer))->liquidTemp();
107  case em_flowRate:
108  return GetTelem_cooler_fb(flatlogs::logHeader::messageBuffer(buffer))->flowRate();
109  case em_pumpLevel:
110  return GetTelem_cooler_fb(flatlogs::logHeader::messageBuffer(buffer))->pumpLevel();
111  case em_pumpSpeed:
112  return GetTelem_cooler_fb(flatlogs::logHeader::messageBuffer(buffer))->pumpSpeed();
113  case em_fanLevel:
114  return GetTelem_cooler_fb(flatlogs::logHeader::messageBuffer(buffer))->fanLevel();
115  case em_fanSpeed:
116  return GetTelem_cooler_fb(flatlogs::logHeader::messageBuffer(buffer))->fanSpeed();
117  default:
118  return nan("");
119  }
120  }
121 
122 
123 }; //telem_cooler
124 
125 
126 
127 } //namespace logger
128 } //namespace MagAOX
129 
130 #endif //logger_types_telem_cooler_hpp
131 
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::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.
messageT(const float &liqTemp, const float &flowRate, const uint8_t &pumpLvl, const uint16_t &pumpSpd, const uint8_t &fanLvl, const uint16_t &fanSpd)
Construct from components.
Log entry recording the build-time git state.
static const flatlogs::eventCodeT eventCode
The event code.
static double getDouble(flatlogs::bufferPtrT &buffer, member m)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static const flatlogs::logPrioT defaultLevel
The default level.