diff --git a/src/algorithms/PVT/libs/nmea_printer.cc b/src/algorithms/PVT/libs/nmea_printer.cc index bb49a1c3a..97ab793a7 100644 --- a/src/algorithms/PVT/libs/nmea_printer.cc +++ b/src/algorithms/PVT/libs/nmea_printer.cc @@ -236,9 +236,10 @@ std::string Nmea_Printer::latitude_to_hm(double lat) out_string.fill('0'); out_string.width(2); out_string << deg; - out_string.width(6); - out_string.precision(4); - out_string << mins; + out_string.width(2); + out_string << static_cast(mins) << "."; + out_string.width(4); + out_string << static_cast((mins - static_cast(static_cast(mins))) * 1e4); if (north == true) { @@ -273,9 +274,10 @@ std::string Nmea_Printer::longitude_to_hm(double longitude) out_string.width(3); out_string.fill('0'); out_string << deg; - out_string.width(6); - out_string.precision(4); - out_string << mins; + out_string.width(2); + out_string << static_cast(mins) << "."; + out_string.width(4); + out_string << static_cast((mins - static_cast(static_cast(mins))) * 1e4); if (east == true) { diff --git a/src/algorithms/PVT/libs/pvt_solution.cc b/src/algorithms/PVT/libs/pvt_solution.cc index 25ddea211..8b9842411 100644 --- a/src/algorithms/PVT/libs/pvt_solution.cc +++ b/src/algorithms/PVT/libs/pvt_solution.cc @@ -619,6 +619,9 @@ void Pvt_Solution::set_valid_position(bool is_valid) void Pvt_Solution::set_rx_pos(const arma::vec & pos) { d_rx_pos = pos; + d_latitude_d = d_rx_pos(0); + d_longitude_d = d_rx_pos(1); + d_height_m = d_rx_pos(2); } diff --git a/src/algorithms/PVT/libs/pvt_solution.h b/src/algorithms/PVT/libs/pvt_solution.h index bf503c024..0a7cc451d 100644 --- a/src/algorithms/PVT/libs/pvt_solution.h +++ b/src/algorithms/PVT/libs/pvt_solution.h @@ -77,7 +77,7 @@ private: double d_VDOP; double d_TDOP; - int d_visible_satellites_IDs[PVT_MAX_CHANNELS] = {}; // Array with the IDs of the valid satellites + int d_visible_satellites_IDs[PVT_MAX_CHANNELS] = {}; // Array with the IDs of the valid satellites double d_visible_satellites_El[PVT_MAX_CHANNELS] = {}; // Array with the LOS Elevation of the valid satellites double d_visible_satellites_Az[PVT_MAX_CHANNELS] = {}; // Array with the LOS Azimuth of the valid satellites double d_visible_satellites_Distance[PVT_MAX_CHANNELS] = {}; // Array with the LOS Distance of the valid satellites @@ -86,18 +86,18 @@ private: public: Pvt_Solution(); - double get_time_offset_s() const; //!< Get RX time offset [s] - void set_time_offset_s(double offset); //!< Set RX time offset [s] + double get_time_offset_s() const; //!< Get RX time offset [s] + void set_time_offset_s(double offset); //!< Set RX time offset [s] - double get_latitude() const; //!< Get RX position Latitude WGS84 [deg] - double get_longitude() const; //!< Get RX position Longitude WGS84 [deg] - double get_height() const; //!< Get RX position height WGS84 [m] + double get_latitude() const; //!< Get RX position Latitude WGS84 [deg] + double get_longitude() const; //!< Get RX position Longitude WGS84 [deg] + double get_height() const; //!< Get RX position height WGS84 [m] - double get_avg_latitude() const; //!< Get RX position averaged Latitude WGS84 [deg] - double get_avg_longitude() const; //!< Get RX position averaged Longitude WGS84 [deg] - double get_avg_height() const; //!< Get RX position averaged height WGS84 [m] + double get_avg_latitude() const; //!< Get RX position averaged Latitude WGS84 [deg] + double get_avg_longitude() const; //!< Get RX position averaged Longitude WGS84 [deg] + double get_avg_height() const; //!< Get RX position averaged height WGS84 [m] - void set_rx_pos(const arma::vec & pos); + void set_rx_pos(const arma::vec & pos); //!< Set position: Latitude [deg], longitude [deg], height [m] arma::vec get_rx_pos() const; bool is_valid_position() const; diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index b86bde939..60b33a4d0 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -125,6 +125,7 @@ DECLARE_string(log_dir); #include "unit-tests/signal-processing-blocks/pvt/rtcm_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rtcm_printer_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rinex_printer_test.cc" +#include "unit-tests/signal-processing-blocks/pvt/nmea_printer_test.cc" #if EXTRA_TESTS #include "unit-tests/signal-processing-blocks/acquisition/gps_l2_m_pcps_acquisition_test.cc" diff --git a/src/tests/unit-tests/signal-processing-blocks/pvt/nmea_printer_test.cc b/src/tests/unit-tests/signal-processing-blocks/pvt/nmea_printer_test.cc new file mode 100644 index 000000000..328b4c998 --- /dev/null +++ b/src/tests/unit-tests/signal-processing-blocks/pvt/nmea_printer_test.cc @@ -0,0 +1,115 @@ +/*! + * \file nma_printer_test.cc + * \brief Implements Unit Tests for the Nmea_Printer class. + * \author Carles Fernandez-Prades, 2017. cfernandez(at)cttc.es + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2016 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + +#include +#include +#include +#include +#include "nmea_printer.h" + + +TEST(NmeaPrinterTest, PrintLine) +{ + std::string filename("nmea_test.nmea"); + + std::shared_ptr pvt_solution = std::make_shared(); + + boost::posix_time::ptime pt(boost::gregorian::date(1994, boost::date_time::Nov, 19), + boost::posix_time::hours(22) + boost::posix_time::minutes(54) + boost::posix_time::seconds(46)); // example from http://aprs.gids.nl/nmea/#rmc + pvt_solution->set_position_UTC_time(pt); + + arma::vec pos = {49.27416667, -123.18533333, 0}; + pvt_solution->set_rx_pos(pos); + + pvt_solution->set_valid_position(true); + + ASSERT_NO_THROW( { + std::shared_ptr nmea_printer = std::make_shared(filename, false, ""); + nmea_printer->Print_Nmea_Line(pvt_solution, false); + } ) << "Failure printing NMEA messages."; + + std::ifstream test_file(filename); + std::string line; + std::string GPRMC("$GPRMC"); + if(test_file.is_open()) + { + while(getline (test_file,line)) + { + std::size_t found = line.find(GPRMC); + if (found != std::string::npos) + { + EXPECT_EQ(line, "$GPRMC,225446.000,A,4916.4500,N,12311.1199,W,0.00,0.00,191194,,*1c\r"); + } + } + test_file.close(); + } + EXPECT_EQ(0, remove(filename.c_str())) << "Failure deleting a temporary file."; +} + + + +TEST(NmeaPrinterTest, PrintLineLessthan10min) +{ + std::string filename("nmea_test.nmea"); + + std::shared_ptr pvt_solution = std::make_shared(); + + boost::posix_time::ptime pt(boost::gregorian::date(1994, boost::date_time::Nov, 19), + boost::posix_time::hours(22) + boost::posix_time::minutes(54) + boost::posix_time::seconds(46)); // example from http://aprs.gids.nl/nmea/#rmc + pvt_solution->set_position_UTC_time(pt); + + arma::vec pos = {49.07416667, -123.02527778, 0}; + pvt_solution->set_rx_pos(pos); + + pvt_solution->set_valid_position(true); + + ASSERT_NO_THROW( { + std::shared_ptr nmea_printer = std::make_shared(filename, false, ""); + nmea_printer->Print_Nmea_Line(pvt_solution, false); + } ) << "Failure printing NMEA messages."; + + std::ifstream test_file(filename); + std::string line; + std::string GPRMC("$GPRMC"); + if(test_file.is_open()) + { + while(getline (test_file,line)) + { + std::size_t found = line.find(GPRMC); + if (found != std::string::npos) + { + EXPECT_EQ(line, "$GPRMC,225446.000,A,4904.4500,N,12301.5166,W,0.00,0.00,191194,,*1a\r"); + } + } + test_file.close(); + } + EXPECT_EQ(0, remove(filename.c_str())) << "Failure deleting a temporary file."; +}