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-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 }
mrpt::io::CMemoryStream::Seek
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.
Definition: CMemoryStream.cpp:120
LIST_ALL_MSGS
#define LIST_ALL_MSGS
Definition: gnss_messages_common.cpp:20
mrpt::obs::gnss::gnss_message_ptr::~gnss_message_ptr
virtual ~gnss_message_ptr()
Dtor: it frees the pointee memory.
Definition: gnss_messages_common.cpp:164
mrpt::obs::gnss::gnss_message_type_t
gnss_message_type_t
List of all known GNSS message types.
Definition: gnss_messages_type_list.h:26
mrpt::obs::gnss::gnss_message_ptr::ptr
gnss_message * ptr
Definition: gnss_messages_common.h:87
ASSERT_EQUAL_
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:153
mrpt::obs::gnss::UTC_time::readFromStream
void readFromStream(mrpt::serialization::CArchive &in)
Save to binary stream.
Definition: gnss_messages_common.cpp:179
mrpt::system::TTimeParts::hour
uint8_t hour
Day (1-31)
Definition: datetime.h:42
mrpt::system::buildTimestampFromParts
mrpt::system::TTimeStamp buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
Definition: datetime.cpp:128
mrpt::system::TTimeParts::second
double second
Minute (0-59)
Definition: datetime.h:44
CMemoryStream.h
obs-precomp.h
THROW_EXCEPTION_FMT
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:43
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::system::TTimeParts
The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
Definition: datetime.h:37
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::system::TTimeStamp
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:31
mrpt::obs::gnss::gnss_message_ptr
A smart pointer to a GNSS message.
Definition: gnss_messages_common.h:84
mrpt::system::timestampToParts
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:104
mrpt::obs::gnss::UTC_time::getAsTimestamp
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...
Definition: gnss_messages_common.cpp:186
mrpt::obs::gnss::UTC_time::hour
uint8_t hour
Definition: gnss_messages_common.h:172
mrpt::serialization::CArchive::WriteAs
void WriteAs(const TYPE_FROM_ACTUAL &value)
Definition: CArchive.h:152
mrpt::obs::gnss::UTC_time::minute
uint8_t minute
Definition: gnss_messages_common.h:173
gnss_messages.h
mrpt::io::CMemoryStream
This CStream derived class allow using a memory buffer as a CStream.
Definition: io/CMemoryStream.h:26
int32_t
__int32 int32_t
Definition: rptypes.h:46
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:561
mrpt::obs::gnss::gnss_message::readAndBuildFromStream
static gnss_message * readAndBuildFromStream(mrpt::serialization::CArchive &in)
Load from binary stream and creates object detecting its type (class factory).
Definition: gnss_messages_common.cpp:107
mrpt::obs::gnss::gnss_message::writeToStream
void writeToStream(mrpt::serialization::CArchive &out) const
Save to binary stream.
Definition: gnss_messages_common.cpp:90
mrpt::obs::gnss::gnss_message_ptr::set
void set(gnss_message *p)
Replaces the pointee with a new pointer.
Definition: gnss_messages_common.cpp:145
mrpt::obs::gnss::gnss_message::internal_readFromStream
virtual void internal_readFromStream(mrpt::serialization::CArchive &in)=0
Save to binary stream.
mrpt::obs::gnss
GNSS (GPS) data structures, mainly for use within mrpt::obs::CObservationGPS.
Definition: gnss_messages_ascii_nmea.h:17
mrpt::system::TTimeParts::minute
uint8_t minute
Hour (0-23)
Definition: datetime.h:43
in
GLuint in
Definition: glext.h:7274
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::obs::gnss::gnss_message
Pure virtual base for all message types.
Definition: gnss_messages_common.h:26
mrpt::obs::gnss::gnss_message_ptr::operator=
gnss_message_ptr & operator=(const gnss_message_ptr &o)
Definition: gnss_messages_common.cpp:155
CArchive.h
mrpt::obs::gnss::UTC_time::UTC_time
UTC_time()
Definition: gnss_messages_common.cpp:174
mrpt::obs::gnss::UTC_time::writeToStream
void writeToStream(mrpt::serialization::CArchive &out) const
Save to binary stream.
Definition: gnss_messages_common.cpp:175
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
mrpt::obs::gnss::UTC_time::sec
double sec
Definition: gnss_messages_common.h:174
mrpt::obs::gnss::gnss_message_ptr::gnss_message_ptr
gnss_message_ptr()
Ctor (default: nullptr pointer)
Definition: gnss_messages_common.cpp:123



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST