Main MRPT website > C++ reference for MRPT 1.5.7
gnss_messages_common.cpp
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 
10 #include "obs-precomp.h" // Precompiled headers
11 
12 #include <mrpt/obs/gnss_messages.h> // Must include all message classes so we can implemente the class factory here
14 #include <map>
15 
16 using namespace std;
17 using namespace mrpt::obs::gnss;
18 
19 #define LIST_ALL_MSGS \
20  /* ====== NMEA ====== */ \
21  DOFOR(NMEA_GGA) \
22  DOFOR(NMEA_RMC) \
23  DOFOR(NMEA_ZDA) \
24  DOFOR(NMEA_VTG) \
25  DOFOR(NMEA_GLL) \
26  /* ====== TopCon mmGPS ====== */ \
27  DOFOR(TOPCON_PZS) \
28  DOFOR(TOPCON_SATS) \
29  /* ====== Novatel OEM6 ====== */ \
30  DOFOR(NV_OEM6_GENERIC_FRAME) \
31  DOFOR(NV_OEM6_BESTPOS) \
32  /* ====== Novatel SPAN+OEM6 ====== */ \
33  DOFOR(NV_OEM6_GENERIC_SHORT_FRAME) \
34  DOFOR(NV_OEM6_INSPVAS) \
35  DOFOR(NV_OEM6_RANGECMP) \
36  DOFOR(NV_OEM6_RXSTATUS) \
37  DOFOR(NV_OEM6_RAWEPHEM) \
38  DOFOR(NV_OEM6_VERSION) \
39  DOFOR(NV_OEM6_RAWIMUS) \
40  DOFOR(NV_OEM6_MARKPOS) \
41  DOFOR(NV_OEM6_MARKTIME) \
42  DOFOR(NV_OEM6_MARK2TIME) \
43  DOFOR(NV_OEM6_IONUTC) \
44 
45 
46 // Class factory:
47 gnss_message* gnss_message::Factory(const gnss_message_type_t msg_id)
48 {
49 #define DOFOR(_MSG_ID) case _MSG_ID: return new Message_##_MSG_ID();
50  switch (msg_id)
51  {
53  default:
54  return NULL;
55  };
56 #undef DOFOR
57 }
58 bool gnss_message::FactoryKnowsMsgType(const gnss_message_type_t msg_id)
59 {
60 #define DOFOR(_MSG_ID) case _MSG_ID: return true;
61  switch (msg_id)
62  {
64  default:
65  return false;
66  };
67 #undef DOFOR
68 }
69 
70 const std::string & gnss_message::getMessageTypeAsString() const
71 {
72  static bool first_call = true;
73  static std::map<gnss_message_type_t,std::string> gnss_type2str;
74  if (first_call)
75  {
76  first_call=false;
77 #define DOFOR(_MSG_ID) gnss_type2str[_MSG_ID] = #_MSG_ID;
79 #undef DOFOR
80  }
81 
82  return gnss_type2str[this->message_type];
83 }
84 
85 
86 // Save to binary stream. Launches an exception upon error
87 void gnss_message::writeToStream(mrpt::utils::CStream &out) const
88 {
89  const int32_t msg_id = message_type;
90  out << msg_id;
91  this->internal_writeToStream(out);
92 }
93 
94 // Load from binary stream. Launches an exception upon error
95 void gnss_message::readFromStream(mrpt::utils::CStream &in)
96 {
97  int32_t msg_id;
98  in >> msg_id;
99  ASSERT_EQUAL_((int32_t)msg_id,this->message_type);
100  this->internal_readFromStream(in);
101 }
102 
103 // Load from binary stream and creates object detecting its type (class factory). Launches an exception upon error
104 gnss_message* gnss_message::readAndBuildFromStream(mrpt::utils::CStream &in)
105 {
106  int32_t msg_id;
107  in >> msg_id;
108  gnss_message* msg = gnss_message::Factory(static_cast<gnss_message_type_t>(msg_id) );
109  if (!msg)
110  THROW_EXCEPTION_FMT("Error deserializing gnss_message: unknown message type '%i'",static_cast<int>(msg_id));
112  return msg;
113 }
114 
115 
116 // Ctor (default: NULL pointer)
117 gnss_message_ptr::gnss_message_ptr() : ptr(NULL)
118 {}
119 // Ctor:Makes a copy of the pointee
121 {
122  if (!o.ptr) {
123  ptr=NULL;
124  }
125  else {
127  o->writeToStream(buf);
128  buf.Seek(0);
130  }
131 }
132 /** Assigns a pointer */
134  ptr(const_cast<gnss_message*>(p))
135 {
136 }
138 {
139  if (ptr) { delete ptr; ptr=NULL; }
140  ptr = p;
141 }
142 // Makes a copy of the pointee
144 {
146  o->writeToStream(buf);
147  buf.Seek(0);
149  return *this;
150 }
152 {
153  if (ptr) { delete ptr; ptr=NULL; }
154 }
155 
156 // ---------------------------------------
158  hour(0), minute(0), sec(0)
159 {
160 }
162  out << hour << minute << sec;
163 }
165  in >> hour >> minute >> sec;
166 }
167 
168 // Build an MRPT timestamp with the hour/minute/sec of this structure and the date from the given timestamp.
170 {
171  using namespace mrpt::system;
172 
173  TTimeParts parts;
174  timestampToParts(date,parts, false /* UTC, not local */);
175 
176  parts.hour = this->hour;
177  parts.minute = this->minute;
178  parts.second = this->sec;
179 
180  return buildTimestampFromParts(parts);
181 }
#define ASSERT_EQUAL_(__A, __B)
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
void BASE_IMPEXP timestampToParts(TTimeStamp t, TTimeParts &p, bool localTime=false)
Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time...
Definition: datetime.cpp:101
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...
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:29
static gnss_message * readAndBuildFromStream(mrpt::utils::CStream &in)
Load from binary stream and creates object detecting its type (class factory). Launches an exception ...
void writeToStream(mrpt::utils::CStream &out) const
Save to binary stream. Launches an exception upon error.
gnss_message_type_t
List of all known GNSS message types.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
Definition: datetime.cpp:127
gnss_message_ptr & operator=(const gnss_message_ptr &o)
STL namespace.
void writeToStream(mrpt::utils::CStream &out) const
Save to binary stream. Launches an exception upon error.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
virtual ~gnss_message_ptr()
Dtor: it frees the pointee memory.
This CStream derived class allow using a memory buffer as a CStream.
Definition: CMemoryStream.h:26
The parts of a date/time (it&#39;s like the standard &#39;tm&#39; but with fractions of seconds).
Definition: datetime.h:35
GLsizei const GLchar ** string
Definition: glext.h:3919
GNSS (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS.
virtual void internal_readFromStream(mrpt::utils::CStream &in)=0
Save to binary stream. Launches an exception upon error.
gnss_message_ptr()
Ctor (default: NULL pointer)
double second
Minute (0-59)
Definition: datetime.h:42
__int32 int32_t
Definition: rptypes.h:48
#define LIST_ALL_MSGS
uint8_t minute
Hour (0-23)
Definition: datetime.h:41
Pure virtual base for all message types.
GLuint in
Definition: glext.h:6301
void readFromStream(mrpt::utils::CStream &in)
Save to binary stream. Launches an exception upon error.
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) MRPT_OVERRIDE
Introduces a pure virtual method for moving to a specified position in the streamed resource...
uint8_t hour
Day (1-31)
Definition: datetime.h:40
void set(gnss_message *p)
Replaces the pointee with a new pointer. Its memory now belongs to this object, do not free manually...
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.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019