MRPT  2.0.2
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-2020, 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_GSA) \
25  DOFOR(NMEA_RMC) \
26  DOFOR(NMEA_ZDA) \
27  DOFOR(NMEA_VTG) \
28  DOFOR(NMEA_GLL) \
29  /* ====== TopCon mmGPS ====== */ \
30  DOFOR(TOPCON_PZS) \
31  DOFOR(TOPCON_SATS) \
32  /* ====== Novatel OEM6 ====== */ \
33  DOFOR(NV_OEM6_GENERIC_FRAME) \
34  DOFOR(NV_OEM6_BESTPOS) \
35  /* ====== Novatel SPAN+OEM6 ====== */ \
36  DOFOR(NV_OEM6_GENERIC_SHORT_FRAME) \
37  DOFOR(NV_OEM6_INSPVAS) \
38  DOFOR(NV_OEM6_RANGECMP) \
39  DOFOR(NV_OEM6_RXSTATUS) \
40  DOFOR(NV_OEM6_RAWEPHEM) \
41  DOFOR(NV_OEM6_VERSION) \
42  DOFOR(NV_OEM6_RAWIMUS) \
43  DOFOR(NV_OEM6_MARKPOS) \
44  DOFOR(NV_OEM6_MARKTIME) \
45  DOFOR(NV_OEM6_MARK2TIME) \
46  DOFOR(NV_OEM6_IONUTC)
47 
48 // Class factory:
49 gnss_message* gnss_message::Factory(const gnss_message_type_t msg_id)
50 {
51 #define DOFOR(_MSG_ID) \
52  case _MSG_ID: \
53  return new Message_##_MSG_ID();
54  switch (msg_id)
55  {
57  default:
58  return nullptr;
59  };
60 #undef DOFOR
61 }
62 bool gnss_message::FactoryKnowsMsgType(const gnss_message_type_t msg_id)
63 {
64 #define DOFOR(_MSG_ID) \
65  case _MSG_ID: \
66  return true;
67  switch (msg_id)
68  {
70  default:
71  return false;
72  };
73 #undef DOFOR
74 }
75 
76 const std::string& gnss_message::getMessageTypeAsString() const
77 {
78  static bool first_call = true;
79  static std::map<gnss_message_type_t, std::string> gnss_type2str;
80  if (first_call)
81  {
82  first_call = false;
83 #define DOFOR(_MSG_ID) gnss_type2str[_MSG_ID] = #_MSG_ID;
85 #undef DOFOR
86  }
87 
88  return gnss_type2str[this->message_type];
89 }
90 
91 // Save to binary stream. Launches an exception upon error
92 void gnss_message::writeToStream(mrpt::serialization::CArchive& out) const
93 {
94  out.WriteAs<int32_t>(message_type);
95  this->internal_writeToStream(out);
96 }
97 
98 // Load from binary stream. Launches an exception upon error
99 void gnss_message::readFromStream(mrpt::serialization::CArchive& in)
100 {
101  int32_t msg_id;
102  in >> msg_id;
103  ASSERT_EQUAL_((int32_t)msg_id, this->message_type);
104  this->internal_readFromStream(in);
105 }
106 
107 void gnss_message::dumpToConsole(std::ostream& o) const
108 {
110  o << "\n";
112  o << "\n";
113 }
114 
115 // Load from binary stream and creates object detecting its type (class
116 // factory). Launches an exception upon error
117 gnss_message* gnss_message::readAndBuildFromStream(
119 {
120  int32_t msg_id;
121  in >> msg_id;
122  gnss_message* msg =
123  gnss_message::Factory(static_cast<gnss_message_type_t>(msg_id));
124  if (!msg)
126  "Error deserializing gnss_message: unknown message type '%i'",
127  static_cast<int>(msg_id));
128  msg->internal_readFromStream(in);
129  // internal_readFromStream() already calls fixEndianness().
130  return msg;
131 }
132 
133 // Ctor (default: nullptr pointer)
134 gnss_message_ptr::gnss_message_ptr() = default;
135 // Ctor:Makes a copy of the pointee
136 gnss_message_ptr::gnss_message_ptr(const gnss_message_ptr& o)
137 {
138  if (!o.ptr)
139  {
140  ptr = nullptr;
141  }
142  else
143  {
145  auto arch = mrpt::serialization::archiveFrom(buf);
146  o->writeToStream(arch);
147  buf.Seek(0);
148  ptr = gnss_message::readAndBuildFromStream(arch);
149  }
150 }
151 /** Assigns a pointer */
152 gnss_message_ptr::gnss_message_ptr(const gnss_message* p)
153  : ptr(const_cast<gnss_message*>(p))
154 {
155 }
157 {
158  if (ptr)
159  {
160  delete ptr;
161  ptr = nullptr;
162  }
163  ptr = p;
164 }
165 // Makes a copy of the pointee
167 {
169  auto arch = mrpt::serialization::archiveFrom(buf);
170  o->writeToStream(arch);
171  buf.Seek(0);
173  return *this;
174 }
176 {
177  if (ptr)
178  {
179  delete ptr;
180  ptr = nullptr;
181  }
182 }
183 
184 // ---------------------------------------
185 UTC_time::UTC_time() = default;
187 {
188  out << hour << minute << sec;
189 }
191 {
192  in >> hour >> minute >> sec;
193 }
194 
195 // Build an MRPT timestamp with the hour/minute/sec of this structure and the
196 // date from the given timestamp.
198  const mrpt::system::TTimeStamp& date) const
199 {
200  using namespace mrpt::system;
201 
202  TTimeParts parts;
203  timestampToParts(date, parts, false /* UTC, not local */);
204 
205  parts.hour = this->hour;
206  parts.minute = this->minute;
207  parts.second = this->sec;
208 
209  return buildTimestampFromParts(parts);
210 }
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:592
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 2.0.2 Git: 9efc2a654 Mon Apr 6 11:24:47 2020 +0200 at lun abr 6 11:30:12 CEST 2020