MRPT  1.9.9
gnss_messages_common.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
13 #include <mrpt/system/datetime.h>
14 #include <cstring> // memset()
15 #include <iosfwd>
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() = default;
74 
75  protected:
76  /** Save to binary stream. Launches an exception upon error */
77  virtual void internal_writeToStream(
78  mrpt::serialization::CArchive& out) const = 0;
79  /** Save to binary stream. Launches an exception upon error */
81 };
82 
83 /** A smart pointer to a GNSS message. \sa gnss_message,
84  * mrpt::obs::CObservationGPS */
86 {
87  protected:
88  gnss_message* ptr{nullptr};
89 
90  public:
91  /** Ctor (default: nullptr pointer) */
93  /** Makes a copy of the pointee */
95  /** Assigns a pointer. Memory now belongs to this class. */
96  explicit gnss_message_ptr(const gnss_message* p);
98  const gnss_message_ptr& o); // Makes a copy of the pointee
99  /** Dtor: it frees the pointee memory */
100  virtual ~gnss_message_ptr();
101  bool operator==(const gnss_message* o) const { return o == ptr; }
102  bool operator==(const gnss_message_ptr& o) const { return o.ptr == ptr; }
103  bool operator!=(const gnss_message* o) const { return o != ptr; }
104  bool operator!=(const gnss_message_ptr& o) const { return o.ptr != ptr; }
105  gnss_message*& get() { return ptr; }
106  const gnss_message* get() const { return ptr; }
108  {
109  ASSERT_(ptr);
110  return ptr;
111  }
112  const gnss_message* operator->() const
113  {
114  ASSERT_(ptr);
115  return ptr;
116  }
117  /** Replaces the pointee with a new pointer. Its memory now belongs to this
118  * object, do not free manually. */
119  void set(gnss_message* p);
120 };
121 
122 #define GNSS_MESSAGE_BINARY_BLOCK(DATA_PTR, DATA_LEN) \
123  protected: \
124  void internal_writeToStream(mrpt::serialization::CArchive& out) \
125  const override \
126  { \
127  out << static_cast<uint32_t>(DATA_LEN); \
128  out.WriteBuffer(DATA_PTR, DATA_LEN); \
129  } \
130  void internal_readFromStream(mrpt::serialization::CArchive& in) override \
131  { \
132  uint32_t nBytesInStream; \
133  in >> nBytesInStream; \
134  ASSERT_EQUAL_(nBytesInStream, DATA_LEN); \
135  in.ReadBuffer(DATA_PTR, DATA_LEN); \
136  } \
137  \
138  public:
139 
140 #define GNSS_BINARY_MSG_DEFINITION_START(_MSG_ID) \
141  struct Message_##_MSG_ID : public gnss_message \
142  { \
143  GNSS_MESSAGE_BINARY_BLOCK(&fields, sizeof(fields)) \
144  enum : uint32_t \
145  { \
146  msg_type = _MSG_ID \
147  }; /* Static msg type (member expected by templates)*/ \
148  Message_##_MSG_ID() : gnss_message((gnss_message_type_t)msg_type) {} \
149  struct content_t \
150  {
151 #define GNSS_BINARY_MSG_DEFINITION_MID \
152  content_t() { ::memset(this, 0, sizeof(*this)); } \
153  } \
154  ; \
155  content_t fields; /** Message content, accesible by individual fields */ \
156  void dumpToStream(std::ostream& out) const override;
157 
158 #define GNSS_BINARY_MSG_DEFINITION_MID_END \
159  } \
160  ;
161 
162 #define GNSS_BINARY_MSG_DEFINITION_END \
163  GNSS_BINARY_MSG_DEFINITION_MID \
164  GNSS_BINARY_MSG_DEFINITION_MID_END
165 
166 // Pragma to ensure we can safely serialize some of these structures
167 #pragma pack(push, 1)
168 
169 /** UTC (Coordinated Universal Time) time-stamp structure for GPS messages. \sa
170  * mrpt::obs::CObservationGPS */
171 struct UTC_time
172 {
175  double sec{0};
176 
177  UTC_time();
178  /** Build an MRPT timestamp with the hour/minute/sec of this structure and
179  * the date from the given timestamp. */
181  const mrpt::system::TTimeStamp& date) const;
182  bool operator==(const UTC_time& o) const
183  {
184  return hour == o.hour && minute == o.minute && sec == o.sec;
185  }
186  bool operator!=(const UTC_time& o) const
187  {
188  return hour != o.hour || minute != o.minute || sec != o.sec;
189  }
190  /** Save to binary stream. Launches an exception upon error */
192  /** Save to binary stream. Launches an exception upon error */
194 };
195 
196 #pragma pack(pop) // End of pack = 1
197 } // namespace gnss
198 } // namespace obs
199 } // namespace mrpt
bool operator==(const UTC_time &o) const
const gnss_message * operator->() const
virtual ~gnss_message()=default
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:44
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:120
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
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:4116
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:53
Pure virtual base for all message types.
bool operator==(const gnss_message *o) const
GLuint in
Definition: glext.h:7391
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:6398
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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019