Main MRPT website > C++ reference for MRPT 1.5.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()
15 #include <mrpt/obs/link_pragmas.h>
17 
18 namespace mrpt {
19 namespace obs {
20 /** GNSS (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS */
21 namespace gnss {
22 
23 /** Pure virtual base for all message types. \sa mrpt::obs::CObservationGPS */
25  gnss_message_type_t message_type; //!< Type of GNSS message
26 
27  gnss_message(gnss_message_type_t msg_type_id) : message_type(msg_type_id) {}
28  void writeToStream(mrpt::utils::CStream &out) const; //!< Save to binary stream. Launches an exception upon error
29  void readFromStream(mrpt::utils::CStream &in); //!< Load from binary stream into this existing object. Launches an exception upon error.
30 
31  bool isOfType(const gnss_message_type_t type_id) const;
32  template <class MSG_CLASS>
33  bool isOfClass() const { return isOfType(MSG_CLASS::msg_type); }
34 
35  static gnss_message* readAndBuildFromStream(mrpt::utils::CStream &in); //!< Load from binary stream and creates object detecting its type (class factory). Launches an exception upon error
36  static gnss_message* Factory(const gnss_message_type_t msg_id); //!< Creates message \return NULL on unknown msg type
37  static bool FactoryKnowsMsgType(const gnss_message_type_t msg_id); //!< Returns true if Factory() has a registered constructor for this msg type
38 
39  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 \sa dumpToConsole()
40  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)
41  virtual bool getAllFieldDescriptions( std::ostream &o ) const { return false; } //!< Dumps a header for getAllFieldValues() \return false if not implemented for this message type
42  virtual bool getAllFieldValues( std::ostream &o ) const { return false; } //!< Dumps a line with the sequence of all field values (without a line feed at the end). \sa getAllFieldDescriptions() \return false if not implemented for this message type
43  const std::string & getMessageTypeAsString() const; //!< Returns "NMEA_GGA", etc.
44  virtual ~gnss_message() {}
45 protected:
46  virtual void internal_writeToStream(mrpt::utils::CStream &out) const = 0; //!< Save to binary stream. Launches an exception upon error
47  virtual void internal_readFromStream(mrpt::utils::CStream &in) = 0; //!< Save to binary stream. Launches an exception upon error
48 };
49 
50 /** A smart pointer to a GNSS message. \sa gnss_message, mrpt::obs::CObservationGPS */
52 {
53 protected:
55 public:
56  gnss_message_ptr(); //!< Ctor (default: NULL pointer)
57  gnss_message_ptr(const gnss_message_ptr &o); //!< Makes a copy of the pointee
58  /** Assigns a pointer. Memory now belongs to this class. */
59  explicit gnss_message_ptr(const gnss_message* p);
60  gnss_message_ptr &operator =(const gnss_message_ptr&o); // Makes a copy of the pointee
61  virtual ~gnss_message_ptr(); //!< Dtor: it frees the pointee memory
62  bool operator == ( const gnss_message *o ) const { return o==ptr; }
63  bool operator == ( const gnss_message_ptr &o )const { return o.ptr==ptr; }
64  bool operator != ( const gnss_message *o )const { return o!=ptr; }
65  bool operator != ( const gnss_message_ptr &o )const { return o.ptr!=ptr; }
66  gnss_message*& get() { return ptr; }
67  const gnss_message* get()const { return ptr; }
68  gnss_message *& operator ->() { ASSERT_(ptr); return ptr; }
69  const gnss_message * operator ->() const { ASSERT_(ptr); return ptr; }
70  void set(gnss_message* p); //!< Replaces the pointee with a new pointer. Its memory now belongs to this object, do not free manually.
71 };
72 
73 #define GNSS_MESSAGE_BINARY_BLOCK(DATA_PTR,DATA_LEN) \
74  protected: \
75  void internal_writeToStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE { \
76  out << static_cast<uint32_t>(DATA_LEN); out.WriteBuffer(DATA_PTR,DATA_LEN); } \
77  void internal_readFromStream(mrpt::utils::CStream &in) MRPT_OVERRIDE { \
78  uint32_t nBytesInStream; in >> nBytesInStream; \
79  ASSERT_EQUAL_(nBytesInStream,DATA_LEN); \
80  in.ReadBuffer(DATA_PTR,DATA_LEN); } \
81  public:
82 
83 #define GNSS_BINARY_MSG_DEFINITION_START(_MSG_ID) \
84  struct OBS_IMPEXP Message_##_MSG_ID : public gnss_message { \
85  GNSS_MESSAGE_BINARY_BLOCK(&fields,sizeof(fields)) \
86  enum { msg_type = _MSG_ID }; /* Static msg type (member expected by templates)*/ \
87  Message_##_MSG_ID() : gnss_message((gnss_message_type_t)msg_type) {} \
88  struct OBS_IMPEXP content_t {
89 
90 #define GNSS_BINARY_MSG_DEFINITION_MID \
91  content_t() { ::memset(this,0,sizeof(*this)); } \
92  }; \
93  content_t fields; /** Message content, accesible by individual fields */ \
94  void dumpToStream( mrpt::utils::CStream &out ) const MRPT_OVERRIDE;
95 
96 
97 #define GNSS_BINARY_MSG_DEFINITION_MID_END \
98  };
99 
100 #define GNSS_BINARY_MSG_DEFINITION_END \
101  GNSS_BINARY_MSG_DEFINITION_MID \
102  GNSS_BINARY_MSG_DEFINITION_MID_END
103 
104 
105 // Pragma to ensure we can safely serialize some of these structures
106 #pragma pack(push,1)
107 
108 /** UTC (Coordinated Universal Time) time-stamp structure for GPS messages. \sa mrpt::obs::CObservationGPS */
110 {
113  double sec;
114 
115  UTC_time();
116  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 timestamp.
117  bool operator == (const UTC_time& o) const { return hour==o.hour && minute==o.minute && sec==o.sec; }
118  bool operator != (const UTC_time& o) const { return hour!=o.hour || minute!=o.minute || sec!=o.sec; }
119  void writeToStream(mrpt::utils::CStream &out) const; //!< Save to binary stream. Launches an exception upon error
120  void readFromStream(mrpt::utils::CStream &in); //!< Save to binary stream. Launches an exception upon error
121 };
122 
123 #pragma pack(pop) // End of pack = 1
124 } } } // End of namespaces
125 
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
bool operator==(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
UTC (Coordinated Universal Time) time-stamp structure for GPS messages.
gnss_message_type_t
List of all known GNSS message types.
bool operator!=(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
unsigned char uint8_t
Definition: rptypes.h:43
gnss_message(gnss_message_type_t msg_type_id)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
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:3919
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.
Pure virtual base for all message types.
GLuint in
Definition: glext.h:6301
#define ASSERT_(f)
GLfloat GLfloat p
Definition: glext.h:5587
A smart pointer to a GNSS message.



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020