API
 
Loading...
Searching...
No Matches
telem_rhusb.hpp
Go to the documentation of this file.
1/** \file telem_rhusb.hpp
2 * \brief The MagAO-X logger telem_rhusb log type.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_types_files
6 *
7 * History:
8 * - 2021-08-22 created by JRM
9 */
10#ifndef logger_types_telem_rhusb_hpp
11#define logger_types_telem_rhusb_hpp
12
13#include "generated/telem_rhusb_generated.h"
14#include "flatbuffer_log.hpp"
15
16namespace MagAOX
17{
18namespace logger
19{
20
21
22/// Log entry recording the build-time git state.
23/** \ingroup logger_types
24 */
26{
27 ///The event code
28 static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_RHUSB;
29
30 ///The default level
32
33 static timespec lastRecord; ///< The time 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 & temp, ///< [in]
40 const float & rh ///< [in]
41 )
42 {
43 auto fp = CreateTelem_rhusb_fb(builder, temp, rh);
44 builder.Finish(fp);
45 }
46
47 };
48
49 static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
50 flatlogs::msgLenT len ///< [in] length of msgBuffer.
51 )
52 {
53 auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
54 return VerifyTelem_rhusb_fbBuffer(verifier);
55 }
56
57 ///Get the message formatte for human consumption.
58 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 static_cast<void>(len);
63
64 auto fbs = GetTelem_rhusb_fb(msgBuffer);
65
66 std::string msg = "[rhusb] ";
67
68
69
70 msg += "temp: ";
71 msg += std::to_string(fbs->temp()) + "C ";
72
73 msg += "RH: ";
74 msg += std::to_string(fbs->rh()) + "%";
75
76
77 return msg;
78
79 }
80
81 static float temp(void * msgBuffer)
82 {
83 auto fbs = GetTelem_rhusb_fb(msgBuffer);
84 return fbs->temp();
85 }
86
87 static float rh(void * msgBuffer)
88 {
89 auto fbs = GetTelem_rhusb_fb(msgBuffer);
90 return fbs->rh();
91 }
92
93 /// Get pointer to the accessor for a member by name
94 /**
95 * \returns the function pointer cast to void*
96 * \returns -1 for an unknown member
97 */
98 static void * getAccessor( const std::string & member /**< [in] the name of the member */ )
99 {
100 if(member == "temp") return reinterpret_cast<void*>(&temp);
101 else if(member == "rh") return reinterpret_cast<void*>(&rh);
102 else
103 {
104 std::cerr << "No string member " << member << " in telem_rhusb\n";
105 return 0;
106 }
107 }
108
109
110}; //telem_rhusb
111
112
113
114} //namespace logger
115} //namespace MagAOX
116
117#endif //logger_types_telem_rhusb_hpp
118
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.
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
Definition dm.hpp:24
static constexpr logPrioT LOG_TELEM
A telemetry recording.
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 &temp, const float &rh)
Construct from components.
Log entry recording the build-time git state.
static float rh(void *msgBuffer)
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static float temp(void *msgBuffer)
static const flatlogs::logPrioT defaultLevel
The default level.
static void * getAccessor(const std::string &member)
Get pointer to the accessor for a member by name.
static const flatlogs::eventCodeT eventCode
The event code.