MRPT  1.9.9
gnss_messages_common.cpp
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 
10 #include "obs-precomp.h" // Precompiled headers
11 
12 #include <mrpt/io/CMemoryStream.h>
13 #include <mrpt/obs/gnss_messages.h> // Must include all message classes so we can implemente the class factory here
15 #include <iostream>
16 #include <map>
17 
18 using namespace std;
19 using namespace mrpt::obs::gnss;
20 
21 #define LIST_ALL_MSGS \
22  /* ====== NMEA ====== */ \
23  DOFOR(NMEA_GGA) \
24  DOFOR(NMEA_RMC) \
25  DOFOR(NMEA_ZDA) \
26  DOFOR(NMEA_VTG) \
27  DOFOR(NMEA_GLL) \
28  /* ====== TopCon mmGPS ====== */ \
29  DOFOR(TOPCON_PZS) \
30  DOFOR(TOPCON_SATS) \
31  /* ====== Novatel OEM6 ====== */ \
32  DOFOR(NV_OEM6_GENERIC_FRAME) \
33  DOFOR(NV_OEM6_BESTPOS) \
34  /* ====== Novatel SPAN+OEM6 ====== */ \
35  DOFOR(NV_OEM6_GENERIC_SHORT_FRAME) \
36  DOFOR(NV_OEM6_INSPVAS) \
37  DOFOR(NV_OEM6_RANGECMP) \
38  DOFOR(NV_OEM6_RXSTATUS) \
39  DOFOR(NV_OEM6_RAWEPHEM) \
40  DOFOR(NV_OEM6_VERSION) \
41  DOFOR(NV_OEM6_RAWIMUS) \
42  DOFOR(NV_OEM6_MARKPOS) \
43  DOFOR(NV_OEM6_MARKTIME) \
44  DOFOR(NV_OEM6_MARK2TIME) \
45  DOFOR(NV_OEM6_IONUTC)
46 
47 // Class factory:
48 gnss_message* gnss_message::Factory(const gnss_message_type_t msg_id)
49 {
50 #define DOFOR(_MSG_ID) \
51  case _MSG_ID: \
52  return new Message_##_MSG_ID();
53  switch (msg_id)
54  {
56  default:
57  return nullptr;
58  };
59 #undef DOFOR
60 }
61 bool gnss_message::FactoryKnowsMsgType(const gnss_message_type_t msg_id)
62 {
63 #define DOFOR(_MSG_ID) \
64  case _MSG_ID: \
65  return true;
66  switch (msg_id)
67  {
69  default:
70  return false;
71  };
72 #undef DOFOR
73 }
74 
75 const std::string& gnss_message::getMessageTypeAsString() const
76 {
77  static bool first_call = true;
78  static std::map<gnss_message_type_t, std::string> gnss_type2str;
79  if (first_call)
80  {
81  first_call = false;
82 #define DOFOR(_MSG_ID) gnss_type2str[_MSG_ID] = #_MSG_ID;
84 #undef DOFOR
85  }
86 
87  return gnss_type2str[this->message_type];
88 }
89 
90 // Save to binary stream. Launches an exception upon error
91 void gnss_message::writeToStream(mrpt::serialization::CArchive& out) const
92 {
93  out.WriteAs<int32_t>(message_type);
94  this->internal_writeToStream(out);
95 }
96 
97 // Load from binary stream. Launches an exception upon error
98 void gnss_message::readFromStream(mrpt::serialization::CArchive& in)
99 {
100  int32_t msg_id;
101  in >> msg_id;
102  ASSERT_EQUAL_((int32_t)msg_id, this->message_type);
103  this->internal_readFromStream(in);
104 }
105 
106 void gnss_message::dumpToConsole(std::ostream& o) const
107 {
109  o << "\n";
111  o << "\n";
112 }
113 
114 // Load from binary stream and creates object detecting its type (class
115 // factory). Launches an exception upon error
116 gnss_message* gnss_message::readAndBuildFromStream(
118 {
119  int32_t msg_id;
120  in >> msg_id;
121  gnss_message* msg =
122  gnss_message::Factory(static_cast<gnss_message_type_t>(msg_id));
123  if (!msg)
125  "Error deserializing gnss_message: unknown message type '%i'",
126  static_cast<int>(msg_id));
127  msg->internal_readFromStream(in);
128  // internal_readFromStream() already calls fixEndianness().
129  return msg;
130 }
131 
132 // Ctor (default: nullptr pointer)
133 gnss_message_ptr::gnss_message_ptr() = default;
134 // Ctor:Makes a copy of the pointee
135 gnss_message_ptr::gnss_message_ptr(const gnss_message_ptr& o)
136 {
137  if (!o.ptr)
138  {
139  ptr = nullptr;
140  }
141  else
142  {
144  auto arch = mrpt::serialization::archiveFrom(buf);
145  o->writeToStream(arch);
146  buf.Seek(0);
147  ptr = gnss_message::readAndBuildFromStream(arch);
148  }
149 }
150 /** Assigns a pointer */
151 gnss_message_ptr::gnss_message_ptr(const gnss_message* p)
152  : ptr(const_cast<gnss_message*>(p))
153 {
154 }
156 {
157  if (ptr)
158  {
159  delete ptr;
160  ptr = nullptr;
161  }
162  ptr = p;
163 }
164 // Makes a copy of the pointee
166 {
168  auto arch = mrpt::serialization::archiveFrom(buf);
169  o->writeToStream(arch);
170  buf.Seek(0);
172  return *this;
173 }
175 {
176  if (ptr)
177  {
178  delete ptr;
179  ptr = nullptr;
180  }
181 }
182 
183 // ---------------------------------------
184 UTC_time::UTC_time() = default;
186 {
187  out << hour << minute << sec;
188 }
190 {
191  in >> hour >> minute >> sec;
192 }
193 
194 // Build an MRPT timestamp with the hour/minute/sec of this structure and the
195 // date from the given timestamp.
197  const mrpt::system::TTimeStamp& date) const
198 {
199  using namespace mrpt::system;
200 
201  TTimeParts parts;
202  timestampToParts(date, parts, false /* UTC, not local */);
203 
204  parts.hour = this->hour;
205  parts.minute = this->minute;
206  parts.second = this->sec;
207 
208  return buildTimestampFromParts(parts);
209 }
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:50
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...
gnss_message_type_t
List of all known GNSS message types.
void readFromStream(mrpt::serialization::CArchive &in)
Save to binary stream.
mrpt::system::TTimeStamp buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
Definition: datetime.cpp:74
gnss_message_ptr & operator=(const gnss_message_ptr &o)
STL namespace.
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream.
Definition: CArchive.h:591
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
virtual ~gnss_message_ptr()
Dtor: it frees the pointee memory.
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
This CStream derived class allow using a memory buffer as a CStream.
The parts of a date/time (it&#39;s like the standard &#39;tm&#39; but with fractions of seconds).
Definition: datetime.h:49
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
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 (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS.
double second
Minute (0-59)
Definition: datetime.h:56
bool getAllFieldDescriptions(std::ostream &o) const override
#define LIST_ALL_MSGS
uint8_t minute
Hour (0-23)
Definition: datetime.h:55
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
Pure virtual base for all message types.
virtual void internal_readFromStream(mrpt::serialization::CArchive &in)=0
Save to binary stream.
uint8_t hour
Day (1-31)
Definition: datetime.h:54
void set(gnss_message *p)
Replaces the pointee with a new pointer.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
bool getAllFieldValues(std::ostream &o) const override
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: d1962bc6a Wed Jan 15 17:38:30 2020 +0100 at miƩ ene 15 17:45:11 CET 2020