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-2018, 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 
12 #include <mrpt/system/datetime.h>
13 #include <iosfwd>
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 */
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 */
49  /** Creates message \return nullptr on unknown msg type */
50  static gnss_message* Factory(const gnss_message_type_t msg_id);
51  /** Returns true if Factory() has a registered constructor for this msg type
52  */
53  static bool FactoryKnowsMsgType(const gnss_message_type_t msg_id);
54 
55  /** Dumps the contents of the observation in a human-readable form to a
56  * given output stream \sa dumpToConsole() */
57  virtual void dumpToStream(std::ostream& out) const = 0;
58  /** Dumps the contents of the observation in a human-readable form to an
59  * std::ostream (set to std::cout to print to console) */
60  void dumpToConsole(std::ostream& o) const;
61  /** Dumps a header for getAllFieldValues() \return false if not implemented
62  * for this message type */
63  virtual bool getAllFieldDescriptions(std::ostream& o) const
64  {
65  return false;
66  }
67  /** Dumps a line with the sequence of all field values (without a line feed
68  * at the end). \sa getAllFieldDescriptions() \return false if not
69  * implemented for this message type */
70  virtual bool getAllFieldValues(std::ostream& o) const { return false; }
71  /** Returns "NMEA_GGA", etc. */
72  const std::string& getMessageTypeAsString() const;
73  virtual ~gnss_message() {}
74  protected:
75  /** Save to binary stream. Launches an exception upon error */
76  virtual void internal_writeToStream(
77  mrpt::serialization::CArchive& out) const = 0;
78  /** Save to binary stream. Launches an exception upon error */
80 };
81 
82 /** A smart pointer to a GNSS message. \sa gnss_message,
83  * mrpt::obs::CObservationGPS */
85 {
86  protected:
88 
89  public:
90  /** Ctor (default: nullptr pointer) */
92  /** Makes a copy of the pointee */
94  /** Assigns a pointer. Memory now belongs to this class. */
95  explicit gnss_message_ptr(const gnss_message* p);
97  const gnss_message_ptr& o); // Makes a copy of the pointee
98  /** Dtor: it frees the pointee memory */
99  virtual ~gnss_message_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  bool operator!=(const gnss_message* o) const { return o != ptr; }
103  bool operator!=(const gnss_message_ptr& o) const { return o.ptr != ptr; }
104  gnss_message*& get() { return ptr; }
105  const gnss_message* get() const { return ptr; }
107  {
108  ASSERT_(ptr);
109  return ptr;
110  }
111  const gnss_message* operator->() const
112  {
113  ASSERT_(ptr);
114  return ptr;
115  }
116  /** Replaces the pointee with a new pointer. Its memory now belongs to this
117  * object, do not free manually. */
118  void set(gnss_message* p);
119 };
120 
121 #define GNSS_MESSAGE_BINARY_BLOCK(DATA_PTR, DATA_LEN) \
122  protected: \
123  void internal_writeToStream(mrpt::serialization::CArchive& out) \
124  const override \
125  { \
126  out << static_cast<uint32_t>(DATA_LEN); \
127  out.WriteBuffer(DATA_PTR, DATA_LEN); \
128  } \
129  void internal_readFromStream(mrpt::serialization::CArchive& in) override \
130  { \
131  uint32_t nBytesInStream; \
132  in >> nBytesInStream; \
133  ASSERT_EQUAL_(nBytesInStream, DATA_LEN); \
134  in.ReadBuffer(DATA_PTR, DATA_LEN); \
135  } \
136  \
137  public:
138 
139 #define GNSS_BINARY_MSG_DEFINITION_START(_MSG_ID) \
140  struct Message_##_MSG_ID : public gnss_message \
141  { \
142  GNSS_MESSAGE_BINARY_BLOCK(&fields, sizeof(fields)) \
143  enum : uint32_t \
144  { \
145  msg_type = _MSG_ID \
146  }; /* Static msg type (member expected by templates)*/ \
147  Message_##_MSG_ID() : gnss_message((gnss_message_type_t)msg_type) {} \
148  struct content_t \
149  {
150 #define GNSS_BINARY_MSG_DEFINITION_MID \
151  content_t() { ::memset(this, 0, sizeof(*this)); } \
152  } \
153  ; \
154  content_t fields; /** Message content, accesible by individual fields */ \
155  void dumpToStream(std::ostream& out) const override;
156 
157 #define GNSS_BINARY_MSG_DEFINITION_MID_END \
158  } \
159  ;
160 
161 #define GNSS_BINARY_MSG_DEFINITION_END \
162  GNSS_BINARY_MSG_DEFINITION_MID \
163  GNSS_BINARY_MSG_DEFINITION_MID_END
164 
165 // Pragma to ensure we can safely serialize some of these structures
166 #pragma pack(push, 1)
167 
168 /** UTC (Coordinated Universal Time) time-stamp structure for GPS messages. \sa
169  * mrpt::obs::CObservationGPS */
170 struct UTC_time
171 {
174  double sec;
175 
176  UTC_time();
177  /** Build an MRPT timestamp with the hour/minute/sec of this structure and
178  * the date from the given timestamp. */
180  const mrpt::system::TTimeStamp& date) const;
181  bool operator==(const UTC_time& o) const
182  {
183  return hour == o.hour && minute == o.minute && sec == o.sec;
184  }
185  bool operator!=(const UTC_time& o) const
186  {
187  return hour != o.hour || minute != o.minute || sec != o.sec;
188  }
189  /** Save to binary stream. Launches an exception upon error */
191  /** Save to binary stream. Launches an exception upon error */
193 };
194 
195 #pragma pack(pop) // End of pack = 1
196 } // namespace gnss
197 } // namespace obs
198 } // namespace mrpt
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.
gnss_message_type_t
List of all known GNSS message types.
void readFromStream(mrpt::serialization::CArchive &in)
Save to binary stream.
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 dumpToConsole(std::ostream &o) const
Dumps the contents of the observation in a human-readable form to an std::ostream (set to std::cout t...
bool operator==(const gnss_message_ptr &o) const
unsigned char uint8_t
Definition: rptypes.h:41
gnss_message(gnss_message_type_t msg_type_id)
void readFromStream(mrpt::serialization::CArchive &in)
Load from binary stream into this existing object.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
bool operator!=(const UTC_time &o) const
virtual void dumpToStream(std::ostream &out) const =0
Dumps the contents of the observation in a human-readable form to a given output stream.
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).
static gnss_message * readAndBuildFromStream(mrpt::serialization::CArchive &in)
Load from binary stream and creates object detecting its type (class factory).
void writeToStream(mrpt::serialization::CArchive &out) const
Save to binary stream.
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.
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 base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
Pure virtual base for all message types.
bool operator==(const gnss_message *o) const
GLuint in
Definition: glext.h:7274
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:31
virtual void internal_readFromStream(mrpt::serialization::CArchive &in)=0
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::serialization::CArchive &out) const =0
Save to binary stream.
GLfloat GLfloat p
Definition: glext.h:6305
void writeToStream(mrpt::serialization::CArchive &out) const
Save to binary stream.
A smart pointer to a GNSS message.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019