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
mrpt::obs::gnss::gnss_message_ptr::operator!=
bool operator!=(const gnss_message *o) const
Definition: gnss_messages_common.h:102
mrpt::obs::gnss::gnss_message_ptr::operator->
const gnss_message * operator->() const
Definition: gnss_messages_common.h:111
mrpt::obs::gnss::gnss_message_ptr::~gnss_message_ptr
virtual ~gnss_message_ptr()
Dtor: it frees the pointee memory.
Definition: gnss_messages_common.cpp:164
gnss_messages_type_list.h
mrpt::obs::gnss::gnss_message_type_t
gnss_message_type_t
List of all known GNSS message types.
Definition: gnss_messages_type_list.h:26
mrpt::obs::gnss::gnss_message_ptr::ptr
gnss_message * ptr
Definition: gnss_messages_common.h:87
mrpt::obs::gnss::UTC_time::readFromStream
void readFromStream(mrpt::serialization::CArchive &in)
Save to binary stream.
Definition: gnss_messages_common.cpp:179
mrpt::obs::gnss::gnss_message_ptr::get
const gnss_message * get() const
Definition: gnss_messages_common.h:105
mrpt::obs::gnss::gnss_message_ptr::operator!=
bool operator!=(const gnss_message_ptr &o) const
Definition: gnss_messages_common.h:103
mrpt::obs::gnss::gnss_message::dumpToConsole
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...
mrpt::obs::gnss::gnss_message::getAllFieldDescriptions
virtual bool getAllFieldDescriptions(std::ostream &o) const
Dumps a header for getAllFieldValues()
Definition: gnss_messages_common.h:63
mrpt::obs::gnss::gnss_message_ptr::operator==
bool operator==(const gnss_message_ptr &o) const
Definition: gnss_messages_common.h:101
mrpt::obs::gnss::gnss_message::internal_writeToStream
virtual void internal_writeToStream(mrpt::serialization::CArchive &out) const =0
Save to binary stream.
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::obs::gnss::gnss_message::isOfClass
bool isOfClass() const
Definition: gnss_messages_common.h:40
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::obs::gnss::gnss_message_ptr::get
gnss_message *& get()
Definition: gnss_messages_common.h:104
mrpt::obs::gnss::gnss_message::~gnss_message
virtual ~gnss_message()
Definition: gnss_messages_common.h:73
mrpt::obs::gnss::gnss_message::isOfType
bool isOfType(const gnss_message_type_t type_id) const
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::obs::gnss::UTC_time::operator==
bool operator==(const UTC_time &o) const
Definition: gnss_messages_common.h:181
mrpt::system::TTimeStamp
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:31
mrpt::obs::gnss::UTC_time
UTC (Coordinated Universal Time) time-stamp structure for GPS messages.
Definition: gnss_messages_common.h:170
mrpt::obs::gnss::gnss_message::message_type
gnss_message_type_t message_type
Type of GNSS message.
Definition: gnss_messages_common.h:29
mrpt::obs::gnss::gnss_message_ptr
A smart pointer to a GNSS message.
Definition: gnss_messages_common.h:84
mrpt::obs::gnss::UTC_time::getAsTimestamp
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...
Definition: gnss_messages_common.cpp:186
mrpt::obs::gnss::UTC_time::hour
uint8_t hour
Definition: gnss_messages_common.h:172
mrpt::obs::gnss::gnss_message::getAllFieldValues
virtual bool getAllFieldValues(std::ostream &o) const
Dumps a line with the sequence of all field values (without a line feed at the end).
Definition: gnss_messages_common.h:70
mrpt::obs::gnss::UTC_time::minute
uint8_t minute
Definition: gnss_messages_common.h:173
mrpt::obs::gnss::gnss_message::FactoryKnowsMsgType
static bool FactoryKnowsMsgType(const gnss_message_type_t msg_id)
Returns true if Factory() has a registered constructor for this msg type.
Definition: gnss_messages_common.cpp:60
mrpt::obs::gnss::gnss_message::dumpToStream
virtual void dumpToStream(std::ostream &out) const =0
Dumps the contents of the observation in a human-readable form to a given output stream.
mrpt::obs::gnss::UTC_time::operator!=
bool operator!=(const UTC_time &o) const
Definition: gnss_messages_common.h:185
mrpt::obs::gnss::gnss_message::readAndBuildFromStream
static gnss_message * readAndBuildFromStream(mrpt::serialization::CArchive &in)
Load from binary stream and creates object detecting its type (class factory).
Definition: gnss_messages_common.cpp:107
mrpt::obs::gnss::gnss_message::getMessageTypeAsString
const std::string & getMessageTypeAsString() const
Returns "NMEA_GGA", etc.
Definition: gnss_messages_common.cpp:74
mrpt::obs::gnss::gnss_message::writeToStream
void writeToStream(mrpt::serialization::CArchive &out) const
Save to binary stream.
Definition: gnss_messages_common.cpp:90
mrpt::obs::gnss::gnss_message_ptr::set
void set(gnss_message *p)
Replaces the pointee with a new pointer.
Definition: gnss_messages_common.cpp:145
mrpt::obs::gnss::gnss_message::Factory
static gnss_message * Factory(const gnss_message_type_t msg_id)
Creates message.
Definition: gnss_messages_common.cpp:47
mrpt::obs::gnss::gnss_message::internal_readFromStream
virtual void internal_readFromStream(mrpt::serialization::CArchive &in)=0
Save to binary stream.
mrpt::obs::gnss::gnss_message_ptr::operator==
bool operator==(const gnss_message *o) const
Definition: gnss_messages_common.h:100
in
GLuint in
Definition: glext.h:7274
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::obs::gnss::gnss_message
Pure virtual base for all message types.
Definition: gnss_messages_common.h:26
mrpt::obs::gnss::gnss_message_ptr::operator=
gnss_message_ptr & operator=(const gnss_message_ptr &o)
Definition: gnss_messages_common.cpp:155
CArchive.h
mrpt::obs::gnss::UTC_time::UTC_time
UTC_time()
Definition: gnss_messages_common.cpp:174
mrpt::obs::gnss::UTC_time::writeToStream
void writeToStream(mrpt::serialization::CArchive &out) const
Save to binary stream.
Definition: gnss_messages_common.cpp:175
mrpt::obs::gnss::gnss_message::gnss_message
gnss_message(gnss_message_type_t msg_type_id)
Definition: gnss_messages_common.h:31
mrpt::obs::gnss::gnss_message::readFromStream
void readFromStream(mrpt::serialization::CArchive &in)
Load from binary stream into this existing object.
Definition: gnss_messages_common.cpp:97
mrpt::obs::gnss::gnss_message_ptr::operator->
gnss_message *& operator->()
Definition: gnss_messages_common.h:106
mrpt::obs::gnss::UTC_time::sec
double sec
Definition: gnss_messages_common.h:174
datetime.h
mrpt::obs::gnss::gnss_message_ptr::gnss_message_ptr
gnss_message_ptr()
Ctor (default: nullptr pointer)
Definition: gnss_messages_common.cpp:123



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST