Main MRPT website > C++ reference for MRPT 1.9.9
gnss_messages_common.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/utils/CStream.h>
12 #include <mrpt/system/datetime.h>
13 #include <iostream>
14 #include <cstring> // memset()
16 
17 namespace mrpt
18 {
19 namespace obs
20 {
21 /** GNSS (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS
22  */
23 namespace gnss
24 {
25 /** Pure virtual base for all message types. \sa mrpt::obs::CObservationGPS */
27 {
28  /** Type of GNSS message */
30 
31  gnss_message(gnss_message_type_t msg_type_id) : message_type(msg_type_id) {}
32  /** Save to binary stream. Launches an exception upon error */
33  void writeToStream(mrpt::utils::CStream& out) const;
34  /** Load from binary stream into this existing object. Launches an exception
35  * upon error. */
37 
38  bool isOfType(const gnss_message_type_t type_id) const;
39  template <class MSG_CLASS>
40  bool isOfClass() const
41  {
42  return isOfType(MSG_CLASS::msg_type);
43  }
44 
45  /** Load from binary stream and creates object detecting its type (class
46  * factory). Launches an exception upon error */
48  /** Creates message \return nullptr on unknown msg type */
49  static gnss_message* Factory(const gnss_message_type_t msg_id);
50  /** Returns true if Factory() has a registered constructor for this msg type
51  */
52  static bool FactoryKnowsMsgType(const gnss_message_type_t msg_id);
53 
54  /** Dumps the contents of the observation in a human-readable form to a
55  * given output stream \sa dumpToConsole() */
56  virtual void dumpToStream(mrpt::utils::CStream& out) const = 0;
57  /** Dumps the contents of the observation in a human-readable form to an
58  * std::ostream (default=console) */
59  void dumpToConsole(std::ostream& o = std::cout) const;
60  /** Dumps a header for getAllFieldValues() \return false if not implemented
61  * for this message type */
62  virtual bool getAllFieldDescriptions(std::ostream& o) const
63  {
64  return false;
65  }
66  /** Dumps a line with the sequence of all field values (without a line feed
67  * at the end). \sa getAllFieldDescriptions() \return false if not
68  * implemented for this message type */
69  virtual bool getAllFieldValues(std::ostream& o) const { return false; }
70  /** Returns "NMEA_GGA", etc. */
71  const std::string& getMessageTypeAsString() const;
72  virtual ~gnss_message() {}
73  protected:
74  /** Save to binary stream. Launches an exception upon error */
75  virtual void internal_writeToStream(mrpt::utils::CStream& out) const = 0;
76  /** Save to binary stream. Launches an exception upon error */
78 };
79 
80 /** A smart pointer to a GNSS message. \sa gnss_message,
81  * mrpt::obs::CObservationGPS */
83 {
84  protected:
86 
87  public:
88  /** Ctor (default: nullptr pointer) */
90  /** Makes a copy of the pointee */
92  /** Assigns a pointer. Memory now belongs to this class. */
93  explicit gnss_message_ptr(const gnss_message* p);
95  const gnss_message_ptr& o); // Makes a copy of the pointee
96  /** Dtor: it frees the pointee memory */
97  virtual ~gnss_message_ptr();
98  bool operator==(const gnss_message* o) const { return o == ptr; }
99  bool operator==(const gnss_message_ptr& o) const { return o.ptr == ptr; }
100  bool operator!=(const gnss_message* o) const { return o != ptr; }
101  bool operator!=(const gnss_message_ptr& o) const { return o.ptr != ptr; }
102  gnss_message*& get() { return ptr; }
103  const gnss_message* get() const { return ptr; }
105  {
106  ASSERT_(ptr);
107  return ptr;
108  }
109  const gnss_message* operator->() const
110  {
111  ASSERT_(ptr);
112  return ptr;
113  }
114  /** Replaces the pointee with a new pointer. Its memory now belongs to this
115  * object, do not free manually. */
116  void set(gnss_message* p);
117 };
118 
119 #define GNSS_MESSAGE_BINARY_BLOCK(DATA_PTR, DATA_LEN) \
120  protected: \
121  void internal_writeToStream(mrpt::utils::CStream& out) const override \
122  { \
123  out << static_cast<uint32_t>(DATA_LEN); \
124  out.WriteBuffer(DATA_PTR, DATA_LEN); \
125  } \
126  void internal_readFromStream(mrpt::utils::CStream& in) override \
127  { \
128  uint32_t nBytesInStream; \
129  in >> nBytesInStream; \
130  ASSERT_EQUAL_(nBytesInStream, DATA_LEN); \
131  in.ReadBuffer(DATA_PTR, DATA_LEN); \
132  } \
133  \
134  public:
135 
136 #define GNSS_BINARY_MSG_DEFINITION_START(_MSG_ID) \
137  struct Message_##_MSG_ID : public gnss_message \
138  { \
139  GNSS_MESSAGE_BINARY_BLOCK(&fields, sizeof(fields)) \
140  enum : uint32_t \
141  { \
142  msg_type = _MSG_ID \
143  }; /* Static msg type (member expected by templates)*/ \
144  Message_##_MSG_ID() : gnss_message((gnss_message_type_t)msg_type) {} \
145  struct content_t \
146  {
147 #define GNSS_BINARY_MSG_DEFINITION_MID \
148  content_t() { ::memset(this, 0, sizeof(*this)); } \
149  } \
150  ; \
151  content_t fields; /** Message content, accesible by individual fields */ \
152  void dumpToStream(mrpt::utils::CStream& out) const override;
153 
154 #define GNSS_BINARY_MSG_DEFINITION_MID_END \
155  } \
156  ;
157 
158 #define GNSS_BINARY_MSG_DEFINITION_END \
159  GNSS_BINARY_MSG_DEFINITION_MID \
160  GNSS_BINARY_MSG_DEFINITION_MID_END
161 
162 // Pragma to ensure we can safely serialize some of these structures
163 #pragma pack(push, 1)
164 
165 /** UTC (Coordinated Universal Time) time-stamp structure for GPS messages. \sa
166  * mrpt::obs::CObservationGPS */
167 struct UTC_time
168 {
171  double sec;
172 
173  UTC_time();
174  /** Build an MRPT timestamp with the hour/minute/sec of this structure and
175  * the date from the given timestamp. */
177  const mrpt::system::TTimeStamp& date) const;
178  bool operator==(const UTC_time& o) const
179  {
180  return hour == o.hour && minute == o.minute && sec == o.sec;
181  }
182  bool operator!=(const UTC_time& o) const
183  {
184  return hour != o.hour || minute != o.minute || sec != o.sec;
185  }
186  /** Save to binary stream. Launches an exception upon error */
187  void writeToStream(mrpt::utils::CStream& out) const;
188  /** Save to binary stream. Launches an exception upon error */
190 };
191 
192 #pragma pack(pop) // End of pack = 1
193 }
194 }
195 } // End of namespaces
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
bool operator==(const UTC_time &o) const
const gnss_message * operator->() const
mrpt::system::TTimeStamp getAsTimestamp(const mrpt::system::TTimeStamp &date) const
Build an MRPT timestamp with the hour/minute/sec of this structure and the date from the given timest...
UTC (Coordinated Universal Time) time-stamp structure for GPS messages.
static gnss_message * readAndBuildFromStream(mrpt::utils::CStream &in)
Load from binary stream and creates object detecting its type (class factory).
void writeToStream(mrpt::utils::CStream &out) const
Save to binary stream.
gnss_message_type_t
List of all known GNSS message types.
gnss_message_ptr & operator=(const gnss_message_ptr &o)
bool isOfType(const gnss_message_type_t type_id) const
bool operator!=(const gnss_message_ptr &o) const
void writeToStream(mrpt::utils::CStream &out) const
Save to binary stream.
bool operator==(const gnss_message_ptr &o) const
void dumpToConsole(std::ostream &o=std::cout) const
Dumps the contents of the observation in a human-readable form to an std::ostream (default=console) ...
unsigned char uint8_t
Definition: rptypes.h:41
gnss_message(gnss_message_type_t msg_type_id)
bool operator!=(const UTC_time &o) const
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
virtual ~gnss_message_ptr()
Dtor: it frees the pointee memory.
virtual bool getAllFieldValues(std::ostream &o) const
Dumps a line with the sequence of all field values (without a line feed at the end).
gnss_message_type_t message_type
Type of GNSS message.
GLsizei const GLchar ** string
Definition: glext.h:4101
static gnss_message * Factory(const gnss_message_type_t msg_id)
Creates message.
virtual void internal_readFromStream(mrpt::utils::CStream &in)=0
Save to binary stream.
gnss_message_ptr()
Ctor (default: nullptr pointer)
bool operator!=(const gnss_message *o) const
virtual bool getAllFieldDescriptions(std::ostream &o) const
Dumps a header for getAllFieldValues()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual void dumpToStream(mrpt::utils::CStream &out) const =0
Dumps the contents of the observation in a human-readable form to a given output stream.
Pure virtual base for all message types.
bool operator==(const gnss_message *o) const
void readFromStream(mrpt::utils::CStream &in)
Load from binary stream into this existing object.
GLuint in
Definition: glext.h:7274
#define ASSERT_(f)
void readFromStream(mrpt::utils::CStream &in)
Save to binary stream.
static bool FactoryKnowsMsgType(const gnss_message_type_t msg_id)
Returns true if Factory() has a registered constructor for this msg type.
const std::string & getMessageTypeAsString() const
Returns "NMEA_GGA", etc.
virtual void internal_writeToStream(mrpt::utils::CStream &out) const =0
Save to binary stream.
GLfloat GLfloat p
Definition: glext.h:6305
A smart pointer to a GNSS message.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019