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-2017, 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::utils;
16 using namespace mrpt::obs;
17 using namespace std;
18 
19 // Example cmds:
20 // https://www.sparkfun.com/datasheets/GPS/NMEA%20Reference%20Manual-Rev2.1-Dec07.pdf
21 
22 TEST(CGPSInterface, parse_NMEA_GGA)
23 {
24  // Test with a correct frame:
25  {
26  const char* test_cmd =
27  "$GPGGA,101830.00,3649.76162994,N,00224.53709052,W,2,08,1.1,9.3,M,"
28  "47.4,M,5.0,0120*58";
30  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
31  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
32 
33  const gnss::Message_NMEA_GGA* msg =
35  EXPECT_TRUE(msg != nullptr);
36  if (!msg) return;
37  EXPECT_NEAR(
38  msg->fields.latitude_degrees, 36 + 49.76162994 / 60.0, 1e-10);
39  EXPECT_NEAR(
40  msg->fields.longitude_degrees, -(002 + 24.53709052 / 60.0), 1e-10);
41  EXPECT_NEAR(msg->fields.altitude_meters, 9.3, 1e-10);
42  }
43  // Test with an empty frame:
44  {
45  const char* test_cmd = "$GPGGA,,,,,,0,,,,M,,M,,*6";
47  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
48  EXPECT_FALSE(parse_ret);
49  }
50 }
51 
52 TEST(CGPSInterface, parse_NMEA_RMC)
53 {
54  const char* test_cmd =
55  "$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10";
57  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
58  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
59 
60  const gnss::Message_NMEA_RMC* msg =
62 
63  EXPECT_TRUE(msg != nullptr);
64  if (!msg) return;
65  EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10);
66  EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10);
67 }
68 
69 TEST(CGPSInterface, parse_NMEA_GLL)
70 {
71  const char* test_cmd = "$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41";
73  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
74  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
75 
76  const gnss::Message_NMEA_GLL* msg =
78 
79  EXPECT_TRUE(msg != nullptr);
80  if (!msg) return;
81  EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10);
82  EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10);
83 }
84 
85 TEST(CGPSInterface, parse_NMEA_VTG)
86 {
87  const char* test_cmd = "$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48";
89  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
90  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
91 
92  const gnss::Message_NMEA_VTG* msg =
94 
95  EXPECT_TRUE(msg != nullptr);
96  if (!msg) return;
97  EXPECT_NEAR(msg->fields.true_track, 54.7, 1e-6);
98  EXPECT_NEAR(msg->fields.magnetic_track, 34.4, 1e-6);
99  EXPECT_NEAR(msg->fields.ground_speed_knots, 5.5, 1e-6);
100  EXPECT_NEAR(msg->fields.ground_speed_kmh, 10.2, 1e-6);
101 }
102 
103 TEST(CGPSInterface, parse_NMEA_ZDA)
104 {
105  const char* test_cmd = "$GPZDA,181813,14,10,2003,00,00*4F";
107  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
108  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
109 
110  const gnss::Message_NMEA_ZDA* msg =
112 
113  EXPECT_TRUE(msg != nullptr);
114  if (!msg) return;
115  EXPECT_TRUE(msg->fields.date_day == 14);
116  EXPECT_TRUE(msg->fields.date_month == 10);
117  EXPECT_TRUE(msg->fields.date_year == 2003);
118  EXPECT_TRUE(msg->fields.UTCTime.hour == 18);
119  EXPECT_TRUE(msg->fields.UTCTime.minute == 18);
120  EXPECT_TRUE(msg->fields.UTCTime.sec == 13.0); // Replaced from EXPECT_EQ()
121  // to avoid a "bus error" in
122  // a gtest template under
123  // armhf.
124 }
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
content_t fields
Message content, accesible by individual fields.
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
A class capable of reading GPS/GNSS/GNSS+IMU receiver data, from a serial port or from any input stre...
MSG_CLASS * getMsgByClassPtr()
Like CObservationGPS::getMsgByClass() but returns a nullptr pointer if message is not found...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
TEST(CGPSInterface, parse_NMEA_GGA)
content_t fields
Message content, accesible by individual fields.
Contains classes for various device interfaces.
content_t fields
Message content, accesible by individual fields.
UTC_time UTCTime
The GPS sensor measured timestamp (in UTC time)
STL namespace.
double altitude_meters
The measured altitude, in meters (A).
content_t fields
Message content, accesible by individual fields.
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
This namespace contains representation of robot actions and observations.
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
content_t fields
Message content, accesible by individual fields.
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019