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-2018, 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
13 #include <mrpt/io/CMemoryStream.h>
15 #include <map>
16 
17 using namespace std;
18 using namespace mrpt::obs::gnss;
19 
20 #define LIST_ALL_MSGS \
21  /* ====== NMEA ====== */ \
22  DOFOR(NMEA_GGA) \
23  DOFOR(NMEA_RMC) \
24  DOFOR(NMEA_ZDA) \
25  DOFOR(NMEA_VTG) \
26  DOFOR(NMEA_GLL) \
27  /* ====== TopCon mmGPS ====== */ \
28  DOFOR(TOPCON_PZS) \
29  DOFOR(TOPCON_SATS) \
30  /* ====== Novatel OEM6 ====== */ \
31  DOFOR(NV_OEM6_GENERIC_FRAME) \
32  DOFOR(NV_OEM6_BESTPOS) \
33  /* ====== Novatel SPAN+OEM6 ====== */ \
34  DOFOR(NV_OEM6_GENERIC_SHORT_FRAME) \
35  DOFOR(NV_OEM6_INSPVAS) \
36  DOFOR(NV_OEM6_RANGECMP) \
37  DOFOR(NV_OEM6_RXSTATUS) \
38  DOFOR(NV_OEM6_RAWEPHEM) \
39  DOFOR(NV_OEM6_VERSION) \
40  DOFOR(NV_OEM6_RAWIMUS) \
41  DOFOR(NV_OEM6_MARKPOS) \
42  DOFOR(NV_OEM6_MARKTIME) \
43  DOFOR(NV_OEM6_MARK2TIME) \
44  DOFOR(NV_OEM6_IONUTC)
45 
46 // Class factory:
47 gnss_message* gnss_message::Factory(const gnss_message_type_t msg_id)
48 {
49 #define DOFOR(_MSG_ID) \
50  case _MSG_ID: \
51  return new Message_##_MSG_ID();
52  switch (msg_id)
53  {
55  default:
56  return nullptr;
57  };
58 #undef DOFOR
59 }
60 bool gnss_message::FactoryKnowsMsgType(const gnss_message_type_t msg_id)
61 {
62 #define DOFOR(_MSG_ID) \
63  case _MSG_ID: \
64  return true;
65  switch (msg_id)
66  {
68  default:
69  return false;
70  };
71 #undef DOFOR
72 }
73 
74 const std::string& gnss_message::getMessageTypeAsString() const
75 {
76  static bool first_call = true;
77  static std::map<gnss_message_type_t, std::string> gnss_type2str;
78  if (first_call)
79  {
80  first_call = false;
81 #define DOFOR(_MSG_ID) gnss_type2str[_MSG_ID] = #_MSG_ID;
83 #undef DOFOR
84  }
85 
86  return gnss_type2str[this->message_type];
87 }
88 
89 // Save to binary stream. Launches an exception upon error
90 void gnss_message::writeToStream(mrpt::serialization::CArchive& out) const
91 {
92  out.WriteAs<int32_t>(message_type);
93  this->internal_writeToStream(out);
94 }
95 
96 // Load from binary stream. Launches an exception upon error
97 void gnss_message::readFromStream(mrpt::serialization::CArchive& 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(
109 {
110  int32_t msg_id;
111  in >> msg_id;
112  gnss_message* msg =
113  gnss_message::Factory(static_cast<gnss_message_type_t>(msg_id));
114  if (!msg)
116  "Error deserializing gnss_message: unknown message type '%i'",
117  static_cast<int>(msg_id));
119  return msg;
120 }
121 
122 // Ctor (default: nullptr pointer)
123 gnss_message_ptr::gnss_message_ptr() : ptr(nullptr) {}
124 // Ctor:Makes a copy of the pointee
126 {
127  if (!o.ptr)
128  {
129  ptr = nullptr;
130  }
131  else
132  {
134  auto arch = mrpt::serialization::archiveFrom(buf);
135  o->writeToStream(arch);
136  buf.Seek(0);
138  }
139 }
140 /** Assigns a pointer */
142  : ptr(const_cast<gnss_message*>(p))
143 {
144 }
146 {
147  if (ptr)
148  {
149  delete ptr;
150  ptr = nullptr;
151  }
152  ptr = p;
153 }
154 // Makes a copy of the pointee
156 {
158  auto arch = mrpt::serialization::archiveFrom(buf);
159  o->writeToStream(arch);
160  buf.Seek(0);
162  return *this;
163 }
165 {
166  if (ptr)
167  {
168  delete ptr;
169  ptr = nullptr;
170  }
171 }
172 
173 // ---------------------------------------
174 UTC_time::UTC_time() : hour(0), minute(0), sec(0) {}
176 {
177  out << hour << minute << sec;
178 }
180 {
181  in >> hour >> minute >> sec;
182 }
183 
184 // Build an MRPT timestamp with the hour/minute/sec of this structure and the
185 // date from the given timestamp.
187  const mrpt::system::TTimeStamp& date) const
188 {
189  using namespace mrpt::system;
190 
191  TTimeParts parts;
192  timestampToParts(date, parts, false /* UTC, not local */);
193 
194  parts.hour = this->hour;
195  parts.minute = this->minute;
196  parts.second = this->sec;
197 
198  return buildTimestampFromParts(parts);
199 }
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:61
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:85
gnss_message_ptr & operator=(const gnss_message_ptr &o)
STL namespace.
void WriteAs(const TYPE_FROM_ACTUAL &value)
Definition: CArchive.h:156
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:555
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:153
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.
GLsizei const GLchar ** string
Definition: glext.h:4101
GNSS (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS.
gnss_message_ptr()
Ctor (default: nullptr pointer)
double second
Minute (0-59)
Definition: datetime.h:56
__int32 int32_t
Definition: rptypes.h:46
#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:52
Pure virtual base for all message types.
GLuint in
Definition: glext.h:7274
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:43
GLfloat GLfloat p
Definition: glext.h:6305
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020