| 1 |
/* +------------------------------------------------------------------------+ |
| 2 |
| Mobile Robot Programming Toolkit (MRPT) | |
| 3 |
| https://www.mrpt.org/ | |
| 4 |
| | |
| 5 |
| Copyright (c) 2005-2026, 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 <gtest/gtest.h> |
| 11 |
#include <mrpt/hwdrivers/CGPSInterface.h> |
| 12 |
#include <mrpt/io/CMemoryStream.h> |
| 13 |
|
| 14 |
using namespace mrpt; |
| 15 |
using namespace mrpt::hwdrivers; |
| 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"; |
| 29 |
mrpt::obs::CObservationGPS obsGPS; |
| 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 = obsGPS.getMsgByClassPtr<gnss::Message_NMEA_GGA>(); |
| 34 |
EXPECT_TRUE(msg != nullptr); |
| 35 |
if (!msg) return; |
| 36 |
EXPECT_NEAR(msg->fields.latitude_degrees, 36 + 49.76162994 / 60.0, 1e-10); |
| 37 |
EXPECT_NEAR(msg->fields.longitude_degrees, -(002 + 24.53709052 / 60.0), 1e-10); |
| 38 |
EXPECT_NEAR(msg->fields.altitude_meters, 9.3, 1e-10); |
| 39 |
} |
| 40 |
// Test with an empty frame: |
| 41 |
{ |
| 42 |
const char* test_cmd = "$GPGGA,,,,,,0,,,,M,,M,,*6"; |
| 43 |
mrpt::obs::CObservationGPS obsGPS; |
| 44 |
const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS); |
| 45 |
EXPECT_FALSE(parse_ret); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
TEST(CGPSInterface, parse_NMEA_RMC) |
| 50 |
{ |
| 51 |
const char* test_cmd = "$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10"; |
| 52 |
mrpt::obs::CObservationGPS obsGPS; |
| 53 |
const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS); |
| 54 |
EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl; |
| 55 |
|
| 56 |
const gnss::Message_NMEA_RMC* msg = obsGPS.getMsgByClassPtr<gnss::Message_NMEA_RMC>(); |
| 57 |
|
| 58 |
EXPECT_TRUE(msg != nullptr); |
| 59 |
if (!msg) return; |
| 60 |
EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10); |
| 61 |
EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10); |
| 62 |
} |
| 63 |
|
| 64 |
TEST(CGPSInterface, parse_NMEA_GLL) |
| 65 |
{ |
| 66 |
const char* test_cmd = "$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41"; |
| 67 |
mrpt::obs::CObservationGPS obsGPS; |
| 68 |
const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS); |
| 69 |
EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl; |
| 70 |
|
| 71 |
const gnss::Message_NMEA_GLL* msg = obsGPS.getMsgByClassPtr<gnss::Message_NMEA_GLL>(); |
| 72 |
|
| 73 |
EXPECT_TRUE(msg != nullptr); |
| 74 |
if (!msg) return; |
| 75 |
EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10); |
| 76 |
EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10); |
| 77 |
} |
| 78 |
|
| 79 |
TEST(CGPSInterface, parse_NMEA_VTG) |
| 80 |
{ |
| 81 |
const char* test_cmd = "$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48"; |
| 82 |
mrpt::obs::CObservationGPS obsGPS; |
| 83 |
const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS); |
| 84 |
EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl; |
| 85 |
|
| 86 |
const gnss::Message_NMEA_VTG* msg = obsGPS.getMsgByClassPtr<gnss::Message_NMEA_VTG>(); |
| 87 |
|
| 88 |
EXPECT_TRUE(msg != nullptr); |
| 89 |
if (!msg) return; |
| 90 |
EXPECT_NEAR(msg->fields.true_track, 54.7, 1e-6); |
| 91 |
EXPECT_NEAR(msg->fields.magnetic_track, 34.4, 1e-6); |
| 92 |
EXPECT_NEAR(msg->fields.ground_speed_knots, 5.5, 1e-6); |
| 93 |
EXPECT_NEAR(msg->fields.ground_speed_kmh, 10.2, 1e-6); |
| 94 |
} |
| 95 |
|
| 96 |
TEST(CGPSInterface, parse_NMEA_ZDA) |
| 97 |
{ |
| 98 |
const char* test_cmd = "$GPZDA,181813,14,10,2003,00,00*4F"; |
| 99 |
mrpt::obs::CObservationGPS obsGPS; |
| 100 |
const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS); |
| 101 |
EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl; |
| 102 |
|
| 103 |
const gnss::Message_NMEA_ZDA* msg = obsGPS.getMsgByClassPtr<gnss::Message_NMEA_ZDA>(); |
| 104 |
|
| 105 |
EXPECT_TRUE(msg != nullptr); |
| 106 |
if (!msg) return; |
| 107 |
EXPECT_TRUE(msg->fields.date_day == 14); |
| 108 |
EXPECT_TRUE(msg->fields.date_month == 10); |
| 109 |
EXPECT_TRUE(msg->fields.date_year == 2003); |
| 110 |
EXPECT_TRUE(msg->fields.UTCTime.hour == 18); |
| 111 |
EXPECT_TRUE(msg->fields.UTCTime.minute == 18); |
| 112 |
EXPECT_TRUE(msg->fields.UTCTime.sec == 13.0); |
| 113 |
// Replaced from EXPECT_EQ() to avoid a "bus error" in a gtest template |
| 114 |
// under armhf. |
| 115 |
} |
| 116 |
|
| 117 |
TEST(CGPSInterface, parse_NMEA_ZDA_stream) |
| 118 |
{ |
| 119 |
auto buf = std::make_shared<mrpt::io::CMemoryStream>(); |
| 120 |
{ |
| 121 |
const std::string s("$GPZDA,181813,14,10,2003,00,00*4F\n"); |
| 122 |
buf->Write(s.c_str(), s.size()); |
| 123 |
buf->Seek(0); |
| 124 |
} |
| 125 |
|
| 126 |
CGPSInterface gps; |
| 127 |
gps.bindStream(buf); |
| 128 |
|
| 129 |
gps.initialize(); |
| 130 |
gps.doProcess(); |
| 131 |
|
| 132 |
const auto obss = gps.getObservations(); |
| 133 |
|
| 134 |
EXPECT_EQ(obss.size(), 1U); |
| 135 |
|
| 136 |
auto obsGPS = mrpt::ptr_cast<CObservationGPS>::from(obss.begin()->second); |
| 137 |
|
| 138 |
const gnss::Message_NMEA_ZDA* msg = obsGPS->getMsgByClassPtr<gnss::Message_NMEA_ZDA>(); |
| 139 |
|
| 140 |
EXPECT_TRUE(msg != nullptr); |
| 141 |
if (!msg) return; |
| 142 |
EXPECT_TRUE(msg->fields.date_day == 14); |
| 143 |
EXPECT_TRUE(msg->fields.date_month == 10); |
| 144 |
EXPECT_TRUE(msg->fields.date_year == 2003); |
| 145 |
EXPECT_TRUE(msg->fields.UTCTime.hour == 18); |
| 146 |
EXPECT_TRUE(msg->fields.UTCTime.minute == 18); |
| 147 |
EXPECT_TRUE(msg->fields.UTCTime.sec == 13.0); |
| 148 |
// Replaced from EXPECT_EQ() to avoid a "bus error" in a gtest template |
| 149 |
// under armhf. |
| 150 |
} |
| 151 |
|
| 152 |
TEST(CGPSInterface, parse_NOVATEL6_stream) |
| 153 |
{ |
| 154 |
auto buf = std::make_shared<mrpt::io::CMemoryStream>(); |
| 155 |
{ |
| 156 |
const uint8_t sample_novatel6_gps[] = { |
| 157 |
0xaa, 0x44, 0x12, 0x1c, 0x2a, 0x00, 0x00, 0xa0, 0x48, 0x00, 0x00, 0x00, 0x5a, 0xb4, 0x59, |
| 158 |
0x07, 0x10, 0x4a, 0xb7, 0x16, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xb1, 0x4a, 0x34, 0x00, 0x00, |
| 159 |
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x97, 0x2b, 0x45, 0xa9, 0xc8, 0x6a, 0x42, 0x40, 0xfc, |
| 160 |
0x54, 0x43, 0x6f, 0x11, 0x18, 0x03, 0xc0, 0x00, 0x00, 0x20, 0x8f, 0xe8, 0x0e, 0x1c, 0x40, |
| 161 |
0x66, 0x66, 0x48, 0x42, 0x3d, 0x00, 0x00, 0x00, 0x1d, 0x9b, 0x96, 0x3c, 0x2c, 0xd5, 0x9c, |
| 162 |
0x3c, 0xd1, 0x39, 0xa8, 0x3c, 0x35, 0x35, 0x35, 0x00, 0x00, 0x00, 0x60, 0x41, 0x00, 0x00, |
| 163 |
0x00, 0x00, 0x0f, 0x0e, 0x0e, 0x0d, 0x00, 0x00, 0x00, 0x33, 0x82, 0xba, 0x79, 0xe5, 0xaa, |
| 164 |
0x44, 0x13, 0x58, 0xfc, 0x01, 0x59, 0x07, 0x10, 0x4a, 0xb7, 0x16, 0x59, 0x07, 0x00, 0x00, |
| 165 |
0x33, 0x33, 0x33, 0x33, 0xdb, 0x42, 0x17, 0x41, 0xa7, 0xf0, 0xaf, 0xa5, 0xc8, 0x6a, 0x42, |
| 166 |
0x40, 0xa2, 0xad, 0xac, 0x28, 0x12, 0x18, 0x03, 0xc0, 0x00, 0x00, 0x8a, 0x8b, 0x52, 0x8d, |
| 167 |
0x4c, 0x40, 0x10, 0xe2, 0xdb, 0x3c, 0x4b, 0xbd, 0x82, 0xbf, 0x52, 0x23, 0x1e, 0x50, 0x08, |
| 168 |
0xf1, 0x9b, 0xbf, 0xd4, 0xa6, 0xd1, 0x7c, 0xcd, 0x16, 0xc8, 0x3f, 0x31, 0x27, 0xe1, 0x16, |
| 169 |
0xa2, 0x6b, 0x10, 0x40, 0xc7, 0x1c, 0xc7, 0x39, 0x6a, 0x9c, 0x00, 0x40, 0xa0, 0x3c, 0x9f, |
| 170 |
0x79, 0xca, 0xdd, 0x63, 0x40, 0x03, 0x00, 0x00, 0x00, 0x27, 0xbb, 0xff, 0xf8, 0xaa, 0x44, |
| 171 |
0x12, 0x1c, 0x2a, 0x00, 0x00, 0xa0, 0x48, 0x00, 0x00, 0x00, 0x5a, 0xb4, 0x59, 0x07, 0x42, |
| 172 |
0x4a, 0xb7, 0x16, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xb1, 0x4a, 0x34, 0x00, 0x00, 0x00, 0x00, |
| 173 |
0x38, 0x00, 0x00, 0x00, 0xf0, 0x23, 0x3c, 0xa9, 0xc8, 0x6a, 0x42, 0x40, 0xdd, 0x10, 0x6c, |
| 174 |
0x71, 0x11, 0x18, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x03, 0xa7, 0x18, 0x1c, 0x40, 0x66, 0x66, |
| 175 |
0x48, 0x42, 0x3d, 0x00, 0x00, 0x00, 0x32, 0x9b, 0x96, 0x3c, 0x82, 0xd4, 0x9c, 0x3c, 0x5d, |
| 176 |
0x3a, 0xa8, 0x3c, 0x35, 0x35, 0x35, 0x00, 0x00, 0x00, 0x60, 0x41, 0x00, 0x00, 0x00, 0x00, |
| 177 |
0x0f, 0x0e, 0x0e, 0x0d, 0x00, 0x00, 0x00, 0x33, 0xcb, 0x95, 0xa0, 0x9b, 0xaa, 0x44, 0x13, |
| 178 |
0x58, 0xfc, 0x01, 0x59, 0x07, 0x42, 0x4a, 0xb7, 0x16, 0x59, 0x07, 0x00, 0x00, 0x67, 0x66, |
| 179 |
0x66, 0x66, 0xdb, 0x42, 0x17, 0x41, 0xe6, 0xae, 0xa1, 0xa5, 0xc8, 0x6a, 0x42, 0x40, 0x26, |
| 180 |
0x1e, 0x82, 0x2b, 0x12, 0x18, 0x03, 0xc0, 0x00, 0x00, 0x62, 0xb6, 0x8b, 0x8e, 0x4c, 0x40, |
| 181 |
0x10, 0x63, 0x42, 0x19, 0x38, 0x19, 0x7a, 0xbf, 0x1e, 0xa9, 0x79, 0x02, 0x24, 0x6c, 0x9d, |
| 182 |
0xbf, 0x52, 0x13, 0x38, 0xa4, 0x35, 0x2c, 0xc8, 0x3f, 0xa9, 0x3b, 0x21, 0x59, 0xe0, 0xa0, |
| 183 |
0x10, 0x40, 0x51, 0xd1, 0x8c, 0x50, 0x0b, 0xa0, 0x00, 0x40, 0x16, 0x40, 0x94, 0xbe, 0xc2, |
| 184 |
0xdd, 0x63, 0x40, 0x03, 0x00, 0x00, 0x00, 0x20, 0x4d, 0xe7, 0xa2, 0xaa, 0x44, 0x12, 0x1c, |
| 185 |
0x2a, 0x00, 0x00, 0xa0, 0x48, 0x00, 0x00, 0x00, 0x5a, 0xb4, 0x59, 0x07, 0x74, 0x4a, 0xb7, |
| 186 |
0x16, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xb1, 0x4a, 0x34, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, |
| 187 |
0x00, 0x00, 0xaa, 0x41, 0x32, 0xa9, 0xc8, 0x6a, 0x42, 0x40, 0xff, 0x59, 0xa8, 0x73, 0x11, |
| 188 |
0x18, 0x03, 0xc0, 0x00, 0x00, 0xa0, 0xd6, 0x6b, 0x22, 0x1c, 0x40, 0x66, 0x66, 0x48, 0x42, |
| 189 |
0x3d, 0x00, 0x00, 0x00, 0x92, 0x9b, 0x96, 0x3c, 0x70, 0xd3, 0x9c, 0x3c, 0x06, 0x3b, 0xa8, |
| 190 |
0x3c, 0x35, 0x35, 0x35, 0x00}; |
| 191 |
const unsigned int sample_novatel6_gps_len = 500; |
| 192 |
buf->Write(sample_novatel6_gps, sample_novatel6_gps_len); |
| 193 |
buf->Seek(0); |
| 194 |
} |
| 195 |
|
| 196 |
CGPSInterface gps; |
| 197 |
gps.bindStream(buf); |
| 198 |
|
| 199 |
gps.initialize(); |
| 200 |
gps.doProcess(); |
| 201 |
|
| 202 |
const auto obss = gps.getObservations(); |
| 203 |
|
| 204 |
EXPECT_EQ(obss.size(), 4U); |
| 205 |
if (obss.empty()) return; |
| 206 |
|
| 207 |
auto itObs = obss.begin(); |
| 208 |
auto obsGPS1 = mrpt::ptr_cast<CObservationGPS>::from(itObs->second); |
| 209 |
++itObs; |
| 210 |
auto obsGPS2 = mrpt::ptr_cast<CObservationGPS>::from(itObs->second); |
| 211 |
|
| 212 |
EXPECT_TRUE(obsGPS1); |
| 213 |
EXPECT_TRUE(obsGPS2); |
| 214 |
|
| 215 |
const auto* msg1 = obsGPS1->getMsgByClassPtr<gnss::Message_NV_OEM6_BESTPOS>(); |
| 216 |
EXPECT_TRUE(msg1 != nullptr); |
| 217 |
if (!msg1) return; |
| 218 |
EXPECT_TRUE(msg1->fields.num_sats_tracked == 15); |
| 219 |
|
| 220 |
const auto* msg2 = obsGPS2->getMsgByClassPtr<gnss::Message_NV_OEM6_INSPVAS>(); |
| 221 |
EXPECT_TRUE(msg2 != nullptr); |
| 222 |
if (!msg2) return; |
| 223 |
EXPECT_NEAR(msg2->fields.roll, 4.10511, 1e-4); |
| 224 |
} |
| 225 |
|
| 226 |
TEST(CGPSInterface, parse_NMEA_stream) |
| 227 |
{ |
| 228 |
auto buf = std::make_shared<mrpt::io::CMemoryStream>(); |
| 229 |
{ |
| 230 |
// Data captured with a uBlox8 (University of Almeria, 2020) |
| 231 |
const uint8_t sample_nmea_gps[] = { |
| 232 |
0x31, 0x33, 0x2c, 0x32, 0x34, 0x2c, 0x33, 0x30, 0x2c, 0x32, 0x36, 0x34, 0x2c, 0x33, 0x30, |
| 233 |
0x2c, 0x32, 0x38, 0x2c, 0x34, 0x35, 0x2c, 0x30, 0x36, 0x30, 0x2c, 0x31, 0x37, 0x2c, 0x33, |
| 234 |
0x30, 0x2c, 0x31, 0x38, 0x2c, 0x30, 0x35, 0x39, 0x2c, 0x33, 0x31, 0x2c, 0x33, 0x36, 0x2c, |
| 235 |
0x33, 0x34, 0x2c, 0x31, 0x33, 0x32, 0x2c, 0x2a, 0x37, 0x37, 0x0a, 0x24, 0x47, 0x50, 0x47, |
| 236 |
0x53, 0x56, 0x2c, 0x34, 0x2c, 0x34, 0x2c, 0x31, 0x33, 0x2c, 0x34, 0x39, 0x2c, 0x34, 0x37, |
| 237 |
0x2c, 0x31, 0x36, 0x38, 0x2c, 0x2a, 0x34, 0x41, 0x0a, 0x24, 0x47, 0x4c, 0x47, 0x53, 0x56, |
| 238 |
0x2c, 0x32, 0x2c, 0x31, 0x2c, 0x30, 0x36, 0x2c, 0x36, 0x36, 0x2c, 0x34, 0x32, 0x2c, 0x31, |
| 239 |
0x34, 0x30, 0x2c, 0x2c, 0x36, 0x37, 0x2c, 0x37, 0x39, 0x2c, 0x33, 0x34, 0x37, 0x2c, 0x31, |
| 240 |
0x30, 0x2c, 0x36, 0x38, 0x2c, 0x32, 0x35, 0x2c, 0x33, 0x32, 0x38, 0x2c, 0x32, 0x36, 0x2c, |
| 241 |
0x37, 0x36, 0x2c, 0x32, 0x35, 0x2c, 0x30, 0x33, 0x34, 0x2c, 0x31, 0x31, 0x2a, 0x36, 0x38, |
| 242 |
0x0a, 0x24, 0x47, 0x4c, 0x47, 0x53, 0x56, 0x2c, 0x32, 0x2c, 0x32, 0x2c, 0x30, 0x36, 0x2c, |
| 243 |
0x37, 0x37, 0x2c, 0x37, 0x36, 0x2c, 0x33, 0x34, 0x33, 0x2c, 0x2c, 0x37, 0x38, 0x2c, 0x33, |
| 244 |
0x39, 0x2c, 0x32, 0x33, 0x32, 0x2c, 0x31, 0x38, 0x2a, 0x36, 0x39, 0x0a, 0x24, 0x47, 0x4e, |
| 245 |
0x47, 0x53, 0x54, 0x2c, 0x31, 0x30, 0x30, 0x33, 0x35, 0x34, 0x2e, 0x34, 0x30, 0x2c, 0x32, |
| 246 |
0x35, 0x2c, 0x2c, 0x2c, 0x2c, 0x34, 0x35, 0x2c, 0x32, 0x30, 0x2c, 0x36, 0x31, 0x2a, 0x36, |
| 247 |
0x33, 0x0a, 0xb5, 0x62, 0x01, 0x01, 0x14, 0x00, 0xb8, 0x9b, 0xc2, 0x16, 0xc1, 0x84, 0x70, |
| 248 |
0x1e, 0x24, 0x55, 0xb8, 0xfe, 0xb0, 0xee, 0xa9, 0x16, 0x8e, 0x19, 0x00, 0x00, 0x47, 0xb2, |
| 249 |
0xb5, 0x62, 0x01, 0x12, 0x24, 0x00, 0xb8, 0x9b, 0xc2, 0x16, 0xee, 0xff, 0xff, 0xff, 0xf9, |
| 250 |
0xff, 0xff, 0xff, 0xea, 0xff, 0xff, 0xff, 0x1d, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 251 |
0x99, 0xa6, 0x14, 0x02, 0x08, 0x01, 0x00, 0x00, 0x80, 0xa8, 0x12, 0x01, 0xf3, 0xeb, 0x24, |
| 252 |
0x47, 0x4e, 0x52, 0x4d, 0x43, 0x2c, 0x31, 0x30, 0x30, 0x33, 0x35, 0x34, 0x2e, 0x36, 0x30, |
| 253 |
0x2c, 0x41, 0x2c, 0x33, 0x36, 0x34, 0x39, 0x2e, 0x37, 0x38, 0x39, 0x32, 0x39, 0x2c, 0x4e, |
| 254 |
0x2c, 0x30, 0x30, 0x32, 0x32, 0x34, 0x2e, 0x34, 0x36, 0x38, 0x36, 0x33, 0x2c, 0x57, 0x2c, |
| 255 |
0x30, 0x2e, 0x33, 0x37, 0x38, 0x2c, 0x33, 0x34, 0x39, 0x2e, 0x30, 0x38, 0x2c, 0x32, 0x37, |
| 256 |
0x30, 0x32, 0x32, 0x30, 0x2c, 0x2c, 0x2c, 0x41, 0x2a, 0x36, 0x36, 0x0a, 0x24, 0x47, 0x4e, |
| 257 |
0x47, 0x4e, 0x53, 0x2c, 0x31, 0x30, 0x30, 0x33, 0x35, 0x34, 0x2e, 0x36, 0x30, 0x2c, 0x33, |
| 258 |
0x36, 0x34, 0x39, 0x2e, 0x37, 0x38, 0x39, 0x32, 0x39, 0x2c, 0x4e, 0x2c, 0x30, 0x30, 0x32, |
| 259 |
0x32, 0x34, 0x2e, 0x34, 0x36, 0x38, 0x36, 0x33, 0x2c, 0x57, 0x2c, 0x41, 0x4e, 0x2c, 0x30, |
| 260 |
0x34, 0x2c, 0x32, 0x2e, 0x33, 0x31, 0x2c, 0x35, 0x35, 0x2e, 0x34, 0x2c, 0x34, 0x36, 0x2e, |
| 261 |
0x32, 0x2c, 0x2c, 0x2a, 0x34, 0x45, 0x0a, 0x24, 0x47, 0x4e, 0x47, 0x53, 0x41, 0x2c, 0x4d, |
| 262 |
0x2c, 0x33, 0x2c, 0x31, 0x35, 0x2c, 0x32, 0x34, 0x2c, 0x33, 0x30, 0x2c, 0x31, 0x37, 0x2c, |
| 263 |
0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x34, 0x2e, 0x32, 0x31, 0x2c, 0x32, 0x2e, |
| 264 |
0x33, 0x31, 0x2c, 0x33, 0x2e, 0x35, 0x32, 0x2a, 0x31, 0x34, 0x0a, 0x24, 0x47, 0x4e, 0x47, |
| 265 |
0x53, 0x41, 0x2c, 0x4d, 0x2c, 0x33, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, |
| 266 |
0x2c, 0x2c, 0x2c, 0x2c, 0x34, 0x2e, 0x32, 0x31, 0x2c, 0x32, 0x2e, 0x33, 0x31, 0x2c, 0x33, |
| 267 |
0x2e, 0x35, 0x32, 0x2a, 0x31, 0x33, 0x0a, 0x24, 0x47, 0x50, 0x47, 0x53, 0x56, 0x2c, 0x34, |
| 268 |
0x2c, 0x31, 0x2c, 0x31, 0x33, 0x2c, 0x30, 0x35, 0x2c, 0x33, 0x36, 0x2c, 0x31, 0x38, 0x32, |
| 269 |
0x2c, 0x32, 0x30, 0x2c, 0x31, 0x32, 0x2c, 0x30, 0x33, 0x2c, 0x32, 0x30, 0x32, 0x2c, 0x2c, |
| 270 |
0x31, 0x33, 0x2c, 0x36, 0x39, 0x2c, 0x30, 0x34, 0x36, 0x2c, 0x31, 0x32, 0x2c, 0x31, 0x35, |
| 271 |
0x2c, 0x36, 0x31, 0x2c, 0x33, 0x32, 0x31, 0x2c, 0x32, 0x39, 0x2a, 0x37, 0x33, 0x0a, 0x24, |
| 272 |
0x47, 0x50, 0x47, 0x53, 0x56, 0x2c, 0x34, 0x2c, 0x32, 0x2c, 0x31, 0x33, 0x2c, 0x31, 0x37, |
| 273 |
0x2c, 0x31, 0x31, 0x2c, 0x31, 0x30, 0x38, 0x2c, 0x32, 0x38, 0x2c, 0x31, 0x39, 0x2c, 0x30, |
| 274 |
0x34, 0x2c, 0x31, 0x33, 0x31, 0x2c, 0x31, 0x36, 0x2c, 0x32, 0x30, 0x2c, 0x31, 0x33, 0x2c, |
| 275 |
0x33, 0x31, 0x38, 0x2c, 0x31, 0x37, 0x2c, 0x32, 0x31, 0x2c, 0x30, 0x33, 0x2c, 0x32, 0x38, |
| 276 |
0x38, 0x2c, 0x2a, 0x37, 0x45, 0x0a, 0x24, 0x47, 0x50, 0x47, 0x53, 0x56, 0x2c, 0x34, 0x2c, |
| 277 |
0x33, 0x2c, 0x31, 0x33, 0x2c, 0x32, 0x34, 0x2c, 0x33, 0x30, 0x2c, 0x32, 0x36, 0x34, 0x2c, |
| 278 |
0x33, 0x30, 0x2c, 0x32, 0x38, 0x2c, 0x34, 0x35, 0x2c, 0x30, 0x36, 0x30, 0x2c, 0x31, 0x37, |
| 279 |
0x2c, 0x33, 0x30, 0x2c, 0x31, 0x38, 0x2c, 0x30, 0x35, 0x39, 0x2c, 0x33, 0x31, 0x2c, 0x33, |
| 280 |
0x36, 0x2c, 0x33, 0x34, 0x2c, 0x31, 0x33, 0x32, 0x2c, 0x2a, 0x37, 0x37, 0x0a, 0x24, 0x47, |
| 281 |
0x50, 0x47, 0x53, 0x56, 0x2c, 0x34, 0x2c, 0x34, 0x2c, 0x31, 0x33, 0x2c, 0x34, 0x39, 0x2c, |
| 282 |
0x34, 0x37, 0x2c, 0x31, 0x36, 0x38, 0x2c, 0x2a, 0x34, 0x41, 0x0a, 0x24, 0x47, 0x4c, 0x47, |
| 283 |
0x53, 0x56, 0x2c, 0x32, 0x2c, 0x31, 0x2c, 0x30, 0x36, 0x2c, 0x36, 0x36, 0x2c, 0x34, 0x32, |
| 284 |
0x2c, 0x31, 0x34, 0x30, 0x2c, 0x2c, 0x36, 0x37, 0x2c, 0x37, 0x39, 0x2c, 0x33, 0x34, 0x37, |
| 285 |
0x2c, 0x31, 0x31, 0x2c, 0x36, 0x38, 0x2c, 0x32, 0x35, 0x2c, 0x33, 0x32, 0x38, 0x2c, 0x32, |
| 286 |
0x36, 0x2c, 0x37, 0x36, 0x2c, 0x32, 0x35, 0x2c, 0x30, 0x33, 0x34, 0x2c, 0x31, 0x31, 0x2a, |
| 287 |
0x36, 0x39, 0x0a, 0x24, 0x47, 0x4c, 0x47, 0x53, 0x56, 0x2c, 0x32, 0x2c, 0x32, 0x2c, 0x30, |
| 288 |
0x36, 0x2c, 0x37, 0x37, 0x2c, 0x37, 0x36, 0x2c, 0x33, 0x34, 0x33, 0x2c, 0x2c, 0x37, 0x38, |
| 289 |
0x2c, 0x33, 0x39, 0x2c, 0x32, 0x33, 0x32, 0x2c, 0x31, 0x38, 0x2a, 0x36, 0x39, 0x0a, 0x24, |
| 290 |
0x47, 0x4e, 0x47, 0x53, 0x54, 0x2c, 0x31, 0x30, 0x30, 0x33, 0x35, 0x34, 0x2e, 0x36, 0x30, |
| 291 |
0x2c, 0x32, 0x35, 0x2c, 0x2c, 0x2c, 0x2c, 0x33, 0x36, 0x2c, 0x31, 0x37, 0x2c, 0x35, 0x32, |
| 292 |
0x2a, 0x36, 0x31, 0x0a, 0xb5, 0x62, 0x01, 0x01, 0x14, 0x00, 0x80, 0x9c, 0xc2, 0x16, 0xc6, |
| 293 |
0x84, 0x70, 0x1e, 0x22, 0x55, 0xb8, 0xfe, 0xaf, 0xee, 0xa9, 0x16, 0x90, 0x19, 0x00, 0x00, |
| 294 |
0x14, 0x9d, 0xb5, 0x62, 0x01, 0x12, 0x24, 0x00, 0x80, 0x9c, 0xc2, 0x16, 0xee, 0xff, 0xff, |
| 295 |
0xff, 0xf9, 0xff, 0xff, 0xff, 0xea, 0xff, 0xff, 0xff, 0x1d, 0x00, 0x00, 0x00, 0x13, 0x00, |
| 296 |
0x00, 0x00, 0x99, 0xa6, 0x14, 0x02, 0x14, 0x02, 0x00, 0x00, 0x80, 0xa8, 0x12, 0x01, 0xc9, |
| 297 |
0x95, 0x24, 0x47, 0x4e, 0x52, 0x4d, 0x43, 0x2c, 0x31, 0x30, 0x30, 0x33, 0x35, 0x34, 0x2e, |
| 298 |
0x38, 0x30, 0x2c, 0x56, 0x2c, 0x33, 0x36, 0x34, 0x39, 0x2e}; |
| 299 |
const unsigned int sample_nmea_gps_len = 1000; |
| 300 |
buf->Write(sample_nmea_gps, sample_nmea_gps_len); |
| 301 |
buf->Seek(0); |
| 302 |
} |
| 303 |
|
| 304 |
CGPSInterface gps; |
| 305 |
gps.bindStream(buf); |
| 306 |
|
| 307 |
gps.initialize(); |
| 308 |
gps.doProcess(); |
| 309 |
|
| 310 |
const auto obss = gps.getObservations(); |
| 311 |
|
| 312 |
EXPECT_EQ(obss.size(), 3U); |
| 313 |
if (obss.empty()) return; |
| 314 |
|
| 315 |
auto itObs = obss.begin(); |
| 316 |
auto obsGPS1 = mrpt::ptr_cast<CObservationGPS>::from(itObs->second); |
| 317 |
++itObs; |
| 318 |
auto obsGPS2 = mrpt::ptr_cast<CObservationGPS>::from(itObs->second); |
| 319 |
++itObs; |
| 320 |
auto obsGPS3 = mrpt::ptr_cast<CObservationGPS>::from(itObs->second); |
| 321 |
|
| 322 |
EXPECT_TRUE(obsGPS1); |
| 323 |
EXPECT_TRUE(obsGPS2); |
| 324 |
EXPECT_TRUE(obsGPS3); |
| 325 |
|
| 326 |
const auto* msgRMC = obsGPS1->getMsgByClassPtr<gnss::Message_NMEA_RMC>(); |
| 327 |
EXPECT_TRUE(msgRMC != nullptr); |
| 328 |
if (!msgRMC) return; |
| 329 |
EXPECT_NEAR(msgRMC->fields.longitude_degrees, -2.407810500, 0.0001); |
| 330 |
EXPECT_NEAR(msgRMC->fields.latitude_degrees, 36.829821500, 0.0001); |
| 331 |
|
| 332 |
const auto* msgGSA1 = obsGPS2->getMsgByClassPtr<gnss::Message_NMEA_GSA>(); |
| 333 |
EXPECT_TRUE(msgGSA1 != nullptr); |
| 334 |
if (!msgGSA1) return; |
| 335 |
EXPECT_EQ(msgGSA1->fields.PRNs[0][0], '1'); |
| 336 |
EXPECT_EQ(msgGSA1->fields.PRNs[0][1], '5'); |
| 337 |
EXPECT_NEAR(msgGSA1->fields.HDOP, 2.31, 0.1); |
| 338 |
|
| 339 |
const auto* msgGSA2 = obsGPS3->getMsgByClassPtr<gnss::Message_NMEA_GSA>(); |
| 340 |
EXPECT_TRUE(msgGSA2 != nullptr); |
| 341 |
} |