Main MRPT website > C++ reference for MRPT 1.9.9
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 // Class factory:
46 gnss_message* gnss_message::Factory(const gnss_message_type_t msg_id)
47 {
48 #define DOFOR(_MSG_ID) \
49  case _MSG_ID: \
50  return new Message_##_MSG_ID();
51  switch (msg_id)
52  {
54  default:
55  return nullptr;
56  };
57 #undef DOFOR
58 }
59 bool gnss_message::FactoryKnowsMsgType(const gnss_message_type_t msg_id)
60 {
61 #define DOFOR(_MSG_ID) \
62  case _MSG_ID: \
63  return true;
64  switch (msg_id)
65  {
67  default:
68  return false;
69  };
70 #undef DOFOR
71 }
72 
73 const std::string& gnss_message::getMessageTypeAsString() const
74 {
75  static bool first_call = true;
76  static std::map<gnss_message_type_t, std::string> gnss_type2str;
77  if (first_call)
78  {
79  first_call = false;
80 #define DOFOR(_MSG_ID) gnss_type2str[_MSG_ID] = #_MSG_ID;
82 #undef DOFOR
83  }
84 
85  return gnss_type2str[this->message_type];
86 }
87 
88 // Save to binary stream. Launches an exception upon error
89 void gnss_message::writeToStream(mrpt::utils::CStream& out) const
90 {
91  const int32_t msg_id = message_type;
92  out << msg_id;
93  this->internal_writeToStream(out);
94 }
95 
96 // Load from binary stream. Launches an exception upon error
97 void gnss_message::readFromStream(mrpt::utils::CStream& in)
98 {
99  int32_t msg_id;
100  in >> msg_id;
101  ASSERT_EQUAL_((int32_t)msg_id, this->message_type);
102  this->internal_readFromStream(in);
103 }
104 
105 // Load from binary stream and creates object detecting its type (class
106 // factory). Launches an exception upon error
107 gnss_message* gnss_message::readAndBuildFromStream(mrpt::utils::CStream& in)
108 {
109  int32_t msg_id;
110  in >> msg_id;
111  gnss_message* msg =
112  gnss_message::Factory(static_cast<gnss_message_type_t>(msg_id));
113  if (!msg)
115  "Error deserializing gnss_message: unknown message type '%i'",
116  static_cast<int>(msg_id));
118  return msg;
119 }
120 
121 // Ctor (default: nullptr pointer)
122 gnss_message_ptr::gnss_message_ptr() : ptr(nullptr) {}
123 // Ctor:Makes a copy of the pointee
125 {
126  if (!o.ptr)
127  {
128  ptr = nullptr;
129  }
130  else
131  {
133  o->writeToStream(buf);
134  buf.Seek(0);
136  }
137 }
138 /** Assigns a pointer */
140  : ptr(const_cast<gnss_message*>(p))
141 {
142 }
144 {
145  if (ptr)
146  {
147  delete ptr;
148  ptr = nullptr;
149  }
150  ptr = p;
151 }
152 // Makes a copy of the pointee
154 {
156  o->writeToStream(buf);
157  buf.Seek(0);
159  return *this;
160 }
162 {
163  if (ptr)
164  {
165  delete ptr;
166  ptr = nullptr;
167  }
168 }
169 
170 // ---------------------------------------
171 UTC_time::UTC_time() : hour(0), minute(0), sec(0) {}
173 {
174  out << hour << minute << sec;
175 }
177 {
178  in >> hour >> minute >> sec;
179 }
180 
181 // Build an MRPT timestamp with the hour/minute/sec of this structure and the
182 // date from the given timestamp.
184  const mrpt::system::TTimeStamp& date) const
185 {
186  using namespace mrpt::system;
187 
188  TTimeParts parts;
189  timestampToParts(date, parts, false /* UTC, not local */);
190 
191  parts.hour = this->hour;
192  parts.minute = this->minute;
193  parts.second = this->sec;
194 
195  return buildTimestampFromParts(parts);
196 }
#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:32
void 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:103
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:30
static gnss_message * readAndBuildFromStream(mrpt::utils::CStream &in)
Load from binary stream and creates object detecting its type (class factory).
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
void writeToStream(mrpt::utils::CStream &out) const
Save to binary stream.
gnss_message_type_t
List of all known GNSS message types.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
mrpt::system::TTimeStamp 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.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
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:27
The parts of a date/time (it&#39;s like the standard &#39;tm&#39; but with fractions of seconds).
Definition: datetime.h:38
GLsizei const GLchar ** string
Definition: glext.h:4101
GNSS (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS.
virtual void internal_readFromStream(mrpt::utils::CStream &in)=0
Save to binary stream.
gnss_message_ptr()
Ctor (default: nullptr pointer)
double second
Minute (0-59)
Definition: datetime.h:45
__int32 int32_t
Definition: rptypes.h:46
#define LIST_ALL_MSGS
uint8_t minute
Hour (0-23)
Definition: datetime.h:44
Pure virtual base for all message types.
GLuint in
Definition: glext.h:7274
void readFromStream(mrpt::utils::CStream &in)
Save to binary stream.
uint8_t hour
Day (1-31)
Definition: datetime.h:43
void set(gnss_message *p)
Replaces the pointee with a new pointer.
GLfloat GLfloat p
Definition: glext.h:6305
A smart pointer to a GNSS message.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019