1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-13 11:40:33 +00:00

Fix bug in NMEA messages. Fixes #45

Add a new test for the NMEA printer
This commit is contained in:
Carles Fernandez 2017-08-25 11:42:02 +02:00 committed by Damian Miralles
parent 8bbe4edc64
commit 5530352e8a
5 changed files with 137 additions and 16 deletions

View File

@ -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<int>(mins) << ".";
out_string.width(4);
out_string << static_cast<int>((mins - static_cast<double>(static_cast<int>(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<int>(mins) << ".";
out_string.width(4);
out_string << static_cast<int>((mins - static_cast<double>(static_cast<int>(mins))) * 1e4);
if (east == true)
{

View File

@ -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);
}

View File

@ -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;

View File

@ -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"

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include <cstdio>
#include <iostream>
#include <fstream>
#include <string>
#include "nmea_printer.h"
TEST(NmeaPrinterTest, PrintLine)
{
std::string filename("nmea_test.nmea");
std::shared_ptr<Pvt_Solution> pvt_solution = std::make_shared<Pvt_Solution>();
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> nmea_printer = std::make_shared<Nmea_Printer>(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> pvt_solution = std::make_shared<Pvt_Solution>();
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> nmea_printer = std::make_shared<Nmea_Printer>(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.";
}