Main MRPT website > C++ reference for MRPT 1.9.9
CGPSInterface_unittest.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 
11 #include <gtest/gtest.h>
12 
13 using namespace mrpt;
14 using namespace mrpt::hwdrivers;
15 using namespace mrpt::obs;
16 using namespace std;
17 
18 // Example cmds:
19 // https://www.sparkfun.com/datasheets/GPS/NMEA%20Reference%20Manual-Rev2.1-Dec07.pdf
20 
21 TEST(CGPSInterface, parse_NMEA_GGA)
22 {
23  // Test with a correct frame:
24  {
25  const char* test_cmd =
26  "$GPGGA,101830.00,3649.76162994,N,00224.53709052,W,2,08,1.1,9.3,M,"
27  "47.4,M,5.0,0120*58";
29  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
30  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
31 
32  const gnss::Message_NMEA_GGA* msg =
34  EXPECT_TRUE(msg != nullptr);
35  if (!msg) return;
36  EXPECT_NEAR(
37  msg->fields.latitude_degrees, 36 + 49.76162994 / 60.0, 1e-10);
38  EXPECT_NEAR(
39  msg->fields.longitude_degrees, -(002 + 24.53709052 / 60.0), 1e-10);
40  EXPECT_NEAR(msg->fields.altitude_meters, 9.3, 1e-10);
41  }
42  // Test with an empty frame:
43  {
44  const char* test_cmd = "$GPGGA,,,,,,0,,,,M,,M,,*6";
46  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
47  EXPECT_FALSE(parse_ret);
48  }
49 }
50 
51 TEST(CGPSInterface, parse_NMEA_RMC)
52 {
53  const char* test_cmd =
54  "$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10";
56  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
57  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
58 
59  const gnss::Message_NMEA_RMC* msg =
61 
62  EXPECT_TRUE(msg != nullptr);
63  if (!msg) return;
64  EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10);
65  EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10);
66 }
67 
68 TEST(CGPSInterface, parse_NMEA_GLL)
69 {
70  const char* test_cmd = "$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41";
72  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
73  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
74 
75  const gnss::Message_NMEA_GLL* msg =
77 
78  EXPECT_TRUE(msg != nullptr);
79  if (!msg) return;
80  EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10);
81  EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10);
82 }
83 
84 TEST(CGPSInterface, parse_NMEA_VTG)
85 {
86  const char* test_cmd = "$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48";
88  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
89  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
90 
91  const gnss::Message_NMEA_VTG* msg =
93 
94  EXPECT_TRUE(msg != nullptr);
95  if (!msg) return;
96  EXPECT_NEAR(msg->fields.true_track, 54.7, 1e-6);
97  EXPECT_NEAR(msg->fields.magnetic_track, 34.4, 1e-6);
98  EXPECT_NEAR(msg->fields.ground_speed_knots, 5.5, 1e-6);
99  EXPECT_NEAR(msg->fields.ground_speed_kmh, 10.2, 1e-6);
100 }
101 
102 TEST(CGPSInterface, parse_NMEA_ZDA)
103 {
104  const char* test_cmd = "$GPZDA,181813,14,10,2003,00,00*4F";
106  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
107  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
108 
109  const gnss::Message_NMEA_ZDA* msg =
111 
112  EXPECT_TRUE(msg != nullptr);
113  if (!msg) return;
114  EXPECT_TRUE(msg->fields.date_day == 14);
115  EXPECT_TRUE(msg->fields.date_month == 10);
116  EXPECT_TRUE(msg->fields.date_year == 2003);
117  EXPECT_TRUE(msg->fields.UTCTime.hour == 18);
118  EXPECT_TRUE(msg->fields.UTCTime.minute == 18);
119  EXPECT_TRUE(msg->fields.UTCTime.sec == 13.0); // Replaced from EXPECT_EQ()
120  // to avoid a "bus error" in
121  // a gtest template under
122  // armhf.
123 }
mrpt::obs::gnss::Message_NMEA_VTG::content_t::ground_speed_kmh
double ground_speed_kmh
Definition: gnss_messages_ascii_nmea.h:194
mrpt::obs::gnss::Message_NMEA_VTG::fields
content_t fields
Message content, accesible by individual fields.
Definition: gnss_messages_ascii_nmea.h:198
mrpt::hwdrivers::CGPSInterface::parse_NMEA
static bool parse_NMEA(const std::string &cmd_line, mrpt::obs::CObservationGPS &out_obs, const bool verbose=false)
Parses one line of NMEA data from a GPS receiver, and writes the recognized fields (if any) into an o...
Definition: CGPSInterface_parser_NMEA.cpp:96
mrpt::obs::gnss::Message_NMEA_GGA::content_t::longitude_degrees
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
Definition: gnss_messages_ascii_nmea.h:39
mrpt::hwdrivers::CGPSInterface
A class capable of reading GPS/GNSS/GNSS+IMU receiver data, from a serial port or from any input stre...
Definition: CGPSInterface.h:145
mrpt::obs::gnss::Message_NMEA_VTG::content_t::ground_speed_knots
double ground_speed_knots
Definition: gnss_messages_ascii_nmea.h:194
mrpt::obs::gnss::Message_NMEA_GGA
NMEA datum: GGA.
Definition: gnss_messages_ascii_nmea.h:23
mrpt::obs::gnss::Message_NMEA_GGA::fields
content_t fields
Message content, accesible by individual fields.
Definition: gnss_messages_ascii_nmea.h:67
mrpt::obs::gnss::Message_NMEA_GLL::fields
content_t fields
Message content, accesible by individual fields.
Definition: gnss_messages_ascii_nmea.h:130
mrpt::obs::gnss::Message_NMEA_ZDA::fields
content_t fields
Message content, accesible by individual fields.
Definition: gnss_messages_ascii_nmea.h:227
mrpt::obs::gnss::Message_NMEA_ZDA
NMEA datum: ZDA.
Definition: gnss_messages_ascii_nmea.h:205
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::obs::gnss::Message_NMEA_ZDA::content_t::date_year
uint16_t date_year
2000-...
Definition: gnss_messages_ascii_nmea.h:223
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
mrpt::obs::gnss::Message_NMEA_ZDA::content_t::date_day
uint8_t date_day
1-31
Definition: gnss_messages_ascii_nmea.h:219
mrpt::obs::gnss::Message_NMEA_GGA::content_t::latitude_degrees
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
Definition: gnss_messages_ascii_nmea.h:37
mrpt::obs::gnss::Message_NMEA_RMC::content_t::latitude_degrees
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
Definition: gnss_messages_ascii_nmea.h:153
mrpt::obs::gnss::Message_NMEA_GLL::content_t::longitude_degrees
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
Definition: gnss_messages_ascii_nmea.h:124
mrpt::obs::gnss::UTC_time::hour
uint8_t hour
Definition: gnss_messages_common.h:172
mrpt::obs::gnss::Message_NMEA_RMC::content_t::longitude_degrees
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
Definition: gnss_messages_ascii_nmea.h:155
mrpt::obs::gnss::UTC_time::minute
uint8_t minute
Definition: gnss_messages_common.h:173
mrpt::obs::gnss::Message_NMEA_RMC::fields
content_t fields
Message content, accesible by individual fields.
Definition: gnss_messages_ascii_nmea.h:170
mrpt::obs::gnss::Message_NMEA_GLL::content_t::latitude_degrees
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
Definition: gnss_messages_ascii_nmea.h:122
mrpt::obs::CObservationGPS::getMsgByClassPtr
MSG_CLASS * getMsgByClassPtr()
Like CObservationGPS::getMsgByClass() but returns a nullptr pointer if message is not found,...
Definition: CObservationGPS.h:177
mrpt::obs::gnss::Message_NMEA_GGA::content_t::altitude_meters
double altitude_meters
The measured altitude, in meters (A).
Definition: gnss_messages_ascii_nmea.h:46
TEST
TEST(CGPSInterface, parse_NMEA_GGA)
Definition: CGPSInterface_unittest.cpp:21
mrpt::obs::gnss::Message_NMEA_VTG::content_t::true_track
double true_track
Degrees.
Definition: gnss_messages_ascii_nmea.h:193
mrpt::obs::gnss::Message_NMEA_GLL
NMEA datum: GLL.
Definition: gnss_messages_ascii_nmea.h:108
mrpt::obs::gnss::Message_NMEA_ZDA::content_t::UTCTime
UTC_time UTCTime
The GPS sensor measured timestamp (in UTC time)
Definition: gnss_messages_ascii_nmea.h:217
mrpt::obs::CObservationGPS
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
Definition: CObservationGPS.h:70
mrpt::obs::gnss::Message_NMEA_RMC
NMEA datum: RMC.
Definition: gnss_messages_ascii_nmea.h:137
mrpt::obs::gnss::Message_NMEA_ZDA::content_t::date_month
uint8_t date_month
1-12
Definition: gnss_messages_ascii_nmea.h:221
CGPSInterface.h
mrpt::obs::gnss::Message_NMEA_VTG
NMEA datum: VTG.
Definition: gnss_messages_ascii_nmea.h:181
mrpt::obs::gnss::Message_NMEA_VTG::content_t::magnetic_track
double magnetic_track
Definition: gnss_messages_ascii_nmea.h:193
mrpt::obs::gnss::UTC_time::sec
double sec
Definition: gnss_messages_common.h:174



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