mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-31 15:23:04 +00:00 
			
		
		
		
	working on the printers: added time tag to KML and GeoJSON names, some
fixes of CRC computation and check, more tests
This commit is contained in:
		| @@ -73,14 +73,12 @@ galileo_e1_pvt_cc::galileo_e1_pvt_cc(unsigned int nchannels, boost::shared_ptr<g | |||||||
|     //initialize kml_printer |     //initialize kml_printer | ||||||
|     std::string kml_dump_filename; |     std::string kml_dump_filename; | ||||||
|     kml_dump_filename = d_dump_filename; |     kml_dump_filename = d_dump_filename; | ||||||
|     kml_dump_filename.append(".kml"); |  | ||||||
|     d_kml_dump = std::make_shared<Kml_Printer>(); |     d_kml_dump = std::make_shared<Kml_Printer>(); | ||||||
|     d_kml_dump->set_headers(kml_dump_filename); |     d_kml_dump->set_headers(kml_dump_filename); | ||||||
|  |  | ||||||
|     //initialize geojson_printer |     //initialize geojson_printer | ||||||
|     std::string geojson_dump_filename; |     std::string geojson_dump_filename; | ||||||
|     geojson_dump_filename = d_dump_filename; |     geojson_dump_filename = d_dump_filename; | ||||||
|     geojson_dump_filename.append(".geojson"); |  | ||||||
|     d_geojson_printer = std::make_shared<GeoJSON_Printer>(); |     d_geojson_printer = std::make_shared<GeoJSON_Printer>(); | ||||||
|     d_geojson_printer->set_headers(geojson_dump_filename); |     d_geojson_printer->set_headers(geojson_dump_filename); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -86,14 +86,12 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, | |||||||
|     //initialize kml_printer |     //initialize kml_printer | ||||||
|     std::string kml_dump_filename; |     std::string kml_dump_filename; | ||||||
|     kml_dump_filename = d_dump_filename; |     kml_dump_filename = d_dump_filename; | ||||||
|     kml_dump_filename.append(".kml"); |  | ||||||
|     d_kml_printer = std::make_shared<Kml_Printer>(); |     d_kml_printer = std::make_shared<Kml_Printer>(); | ||||||
|     d_kml_printer->set_headers(kml_dump_filename); |     d_kml_printer->set_headers(kml_dump_filename); | ||||||
|  |  | ||||||
|     //initialize geojson_printer |     //initialize geojson_printer | ||||||
|     std::string geojson_dump_filename; |     std::string geojson_dump_filename; | ||||||
|     geojson_dump_filename = d_dump_filename; |     geojson_dump_filename = d_dump_filename; | ||||||
|     geojson_dump_filename.append(".geojson"); |  | ||||||
|     d_geojson_printer = std::make_shared<GeoJSON_Printer>(); |     d_geojson_printer = std::make_shared<GeoJSON_Printer>(); | ||||||
|     d_geojson_printer->set_headers(geojson_dump_filename); |     d_geojson_printer->set_headers(geojson_dump_filename); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -77,14 +77,12 @@ hybrid_pvt_cc::hybrid_pvt_cc(unsigned int nchannels, boost::shared_ptr<gr::msg_q | |||||||
|     //initialize kml_printer |     //initialize kml_printer | ||||||
|     std::string kml_dump_filename; |     std::string kml_dump_filename; | ||||||
|     kml_dump_filename = d_dump_filename; |     kml_dump_filename = d_dump_filename; | ||||||
|     kml_dump_filename.append(".kml"); |  | ||||||
|     d_kml_dump = std::make_shared<Kml_Printer>(); |     d_kml_dump = std::make_shared<Kml_Printer>(); | ||||||
|     d_kml_dump->set_headers(kml_dump_filename); |     d_kml_dump->set_headers(kml_dump_filename); | ||||||
|  |  | ||||||
|     //initialize geojson_printer |     //initialize geojson_printer | ||||||
|     std::string geojson_dump_filename; |     std::string geojson_dump_filename; | ||||||
|     geojson_dump_filename = d_dump_filename; |     geojson_dump_filename = d_dump_filename; | ||||||
|     geojson_dump_filename.append(".geojson"); |  | ||||||
|     d_geojson_printer = std::make_shared<GeoJSON_Printer>(); |     d_geojson_printer = std::make_shared<GeoJSON_Printer>(); | ||||||
|     d_geojson_printer->set_headers(geojson_dump_filename); |     d_geojson_printer->set_headers(geojson_dump_filename); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,8 +31,10 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
| #include "geojson_printer.h" | #include "geojson_printer.h" | ||||||
|  | #include <ctime> | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <iomanip> | #include <iomanip> | ||||||
|  | #include <sstream> | ||||||
| #include <glog/logging.h> | #include <glog/logging.h> | ||||||
|  |  | ||||||
| GeoJSON_Printer::GeoJSON_Printer () {} | GeoJSON_Printer::GeoJSON_Printer () {} | ||||||
| @@ -45,10 +47,58 @@ GeoJSON_Printer::~GeoJSON_Printer () | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| bool GeoJSON_Printer::set_headers(std::string filename) | bool GeoJSON_Printer::set_headers(std::string filename, bool time_tag_name) | ||||||
| { | { | ||||||
|     geojson_file.open(filename.c_str()); |     time_t rawtime; | ||||||
|     filename_ = filename; |     struct tm * timeinfo; | ||||||
|  |     time ( &rawtime ); | ||||||
|  |     timeinfo = localtime ( &rawtime ); | ||||||
|  |  | ||||||
|  |     if (time_tag_name) | ||||||
|  |         { | ||||||
|  |             std::stringstream strm0; | ||||||
|  |             const int year = timeinfo->tm_year - 100; | ||||||
|  |             strm0 << year; | ||||||
|  |             const int month = timeinfo->tm_mon + 1; | ||||||
|  |             if(month < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << month; | ||||||
|  |             const int day = timeinfo->tm_mday; | ||||||
|  |             if(day < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << day << "_"; | ||||||
|  |             const int hour = timeinfo->tm_hour; | ||||||
|  |             if(hour < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << hour; | ||||||
|  |             const int min = timeinfo->tm_min; | ||||||
|  |             if(min < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << min; | ||||||
|  |             const int sec = timeinfo->tm_sec; | ||||||
|  |             if(sec < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << sec; | ||||||
|  |  | ||||||
|  |             filename_ = filename + "_" +  strm0.str() + ".geojson"; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|  |             filename_ = filename + ".geojson"; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     geojson_file.open(filename_.c_str()); | ||||||
|  |  | ||||||
|     first_pos = true; |     first_pos = true; | ||||||
|     if (geojson_file.is_open()) |     if (geojson_file.is_open()) | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -54,7 +54,7 @@ private: | |||||||
| public: | public: | ||||||
|     GeoJSON_Printer(); |     GeoJSON_Printer(); | ||||||
|     ~GeoJSON_Printer(); |     ~GeoJSON_Printer(); | ||||||
|     bool set_headers(std::string filename); |     bool set_headers(std::string filename, bool time_tag_name = true); | ||||||
|     bool print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values); |     bool print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values); | ||||||
|     bool close_file(); |     bool close_file(); | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -31,17 +31,63 @@ | |||||||
|  |  | ||||||
| #include "kml_printer.h" | #include "kml_printer.h" | ||||||
| #include <ctime> | #include <ctime> | ||||||
|  | #include <sstream> | ||||||
| #include <glog/logging.h> | #include <glog/logging.h> | ||||||
|  |  | ||||||
| using google::LogMessage; | using google::LogMessage; | ||||||
|  |  | ||||||
| bool Kml_Printer::set_headers(std::string filename) | bool Kml_Printer::set_headers(std::string filename,  bool time_tag_name) | ||||||
| { | { | ||||||
|  |  | ||||||
|     time_t rawtime; |     time_t rawtime; | ||||||
|     struct tm * timeinfo; |     struct tm * timeinfo; | ||||||
|     time ( &rawtime ); |     time ( &rawtime ); | ||||||
|     timeinfo = localtime ( &rawtime ); |     timeinfo = localtime ( &rawtime ); | ||||||
|     kml_file.open(filename.c_str()); |     if (time_tag_name) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             std::stringstream strm0; | ||||||
|  |             const int year = timeinfo->tm_year - 100; | ||||||
|  |             strm0 << year; | ||||||
|  |             const int month = timeinfo->tm_mon + 1; | ||||||
|  |             if(month < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << month; | ||||||
|  |             const int day = timeinfo->tm_mday; | ||||||
|  |             if(day < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << day << "_"; | ||||||
|  |             const int hour = timeinfo->tm_hour; | ||||||
|  |             if(hour < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << hour; | ||||||
|  |             const int min = timeinfo->tm_min; | ||||||
|  |             if(min < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << min; | ||||||
|  |             const int sec = timeinfo->tm_sec; | ||||||
|  |             if(sec < 10) | ||||||
|  |                 { | ||||||
|  |                     strm0 << "0"; | ||||||
|  |                 } | ||||||
|  |             strm0 << sec; | ||||||
|  |  | ||||||
|  |             kml_filename = filename + "_" +  strm0.str() + ".kml"; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|  |             kml_filename = filename + ".kml"; | ||||||
|  |         } | ||||||
|  |     kml_file.open(kml_filename.c_str()); | ||||||
|     if (kml_file.is_open()) |     if (kml_file.is_open()) | ||||||
|         { |         { | ||||||
|             DLOG(INFO) << "KML printer writing on " << filename.c_str(); |             DLOG(INFO) << "KML printer writing on " << filename.c_str(); | ||||||
| @@ -88,6 +134,8 @@ bool Kml_Printer::print_position(const std::shared_ptr<Pvt_Solution>& position, | |||||||
|     double longitude; |     double longitude; | ||||||
|     double height; |     double height; | ||||||
|  |  | ||||||
|  |     positions_printed = true; | ||||||
|  |  | ||||||
|     std::shared_ptr<Pvt_Solution> position_ = position; |     std::shared_ptr<Pvt_Solution> position_ = position; | ||||||
|  |  | ||||||
|     if (print_average_values == false) |     if (print_average_values == false) | ||||||
| @@ -119,6 +167,7 @@ bool Kml_Printer::close_file() | |||||||
| { | { | ||||||
|     if (kml_file.is_open()) |     if (kml_file.is_open()) | ||||||
|         { |         { | ||||||
|  |  | ||||||
|             kml_file << "</coordinates>" << std::endl |             kml_file << "</coordinates>" << std::endl | ||||||
|                      << "</LineString>" << std::endl |                      << "</LineString>" << std::endl | ||||||
|                      << "</Placemark>" << std::endl |                      << "</Placemark>" << std::endl | ||||||
| @@ -135,12 +184,19 @@ bool Kml_Printer::close_file() | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Kml_Printer::Kml_Printer () {} | Kml_Printer::Kml_Printer () | ||||||
|  | { | ||||||
|  |     positions_printed = false; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Kml_Printer::~Kml_Printer () | Kml_Printer::~Kml_Printer () | ||||||
| { | { | ||||||
|     close_file(); |     close_file(); | ||||||
|  |     if(!positions_printed) | ||||||
|  |         { | ||||||
|  |             if(remove(kml_filename.c_str()) != 0) LOG(INFO) << "Error deleting temporary KML file"; | ||||||
|  |         } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -48,10 +48,12 @@ class Kml_Printer | |||||||
| { | { | ||||||
| private: | private: | ||||||
|     std::ofstream kml_file; |     std::ofstream kml_file; | ||||||
|  |     bool positions_printed; | ||||||
|  |     std::string kml_filename; | ||||||
| public: | public: | ||||||
|     Kml_Printer(); |     Kml_Printer(); | ||||||
|     ~Kml_Printer(); |     ~Kml_Printer(); | ||||||
|     bool set_headers(std::string filename); |     bool set_headers(std::string filename, bool time_tag_name = true); | ||||||
|     bool print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values); |     bool print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values); | ||||||
|     bool close_file(); |     bool close_file(); | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -73,11 +73,11 @@ Rtcm_Printer::~Rtcm_Printer() | |||||||
|     if (rtcm_file_descriptor.is_open()) |     if (rtcm_file_descriptor.is_open()) | ||||||
|         { |         { | ||||||
|             long pos; |             long pos; | ||||||
|             rtcm_file_descriptor.close(); |  | ||||||
|             pos = rtcm_file_descriptor.tellp(); |             pos = rtcm_file_descriptor.tellp(); | ||||||
|  |             rtcm_file_descriptor.close(); | ||||||
|             if (pos == 0) |             if (pos == 0) | ||||||
|                 { |                 { | ||||||
|                     if(remove(rtcm_filename.c_str()) != 0) LOG(INFO) << "Error deleting temporary file"; |                     if(remove(rtcm_filename.c_str()) != 0) LOG(INFO) << "Error deleting temporary RTCM file"; | ||||||
|                 } |                 } | ||||||
|         } |         } | ||||||
|     close_serial(); |     close_serial(); | ||||||
|   | |||||||
| @@ -66,6 +66,7 @@ Rtcm::Rtcm() | |||||||
| std::string Rtcm::add_CRC (const std::string& message_without_crc) | std::string Rtcm::add_CRC (const std::string& message_without_crc) | ||||||
| { | { | ||||||
|     // ******  Computes Qualcomm CRC-24Q ****** |     // ******  Computes Qualcomm CRC-24Q ****** | ||||||
|  |     crc_24_q_type CRC_RTCM; | ||||||
|     // 1) Converts the string to a vector of unsigned char: |     // 1) Converts the string to a vector of unsigned char: | ||||||
|     boost::dynamic_bitset<unsigned char> frame_bits(message_without_crc); |     boost::dynamic_bitset<unsigned char> frame_bits(message_without_crc); | ||||||
|     std::vector<unsigned char> bytes; |     std::vector<unsigned char> bytes; | ||||||
| @@ -84,6 +85,8 @@ std::string Rtcm::add_CRC (const std::string& message_without_crc) | |||||||
|  |  | ||||||
| bool Rtcm::check_CRC(const std::string & message) | bool Rtcm::check_CRC(const std::string & message) | ||||||
| { | { | ||||||
|  |     crc_24_q_type CRC_RTCM_CHECK; | ||||||
|  |  | ||||||
|     // Convert message to binary |     // Convert message to binary | ||||||
|     std::string message_bin = Rtcm::hex_to_bin(message); |     std::string message_bin = Rtcm::hex_to_bin(message); | ||||||
|     // Check CRC |     // Check CRC | ||||||
| @@ -96,8 +99,8 @@ bool Rtcm::check_CRC(const std::string & message) | |||||||
|     boost::to_block_range(frame_bits, std::back_inserter(bytes)); |     boost::to_block_range(frame_bits, std::back_inserter(bytes)); | ||||||
|     std::reverse(bytes.begin(),bytes.end()); |     std::reverse(bytes.begin(),bytes.end()); | ||||||
|  |  | ||||||
|     CRC_RTCM.process_bytes(bytes.data(), bytes.size()); |     CRC_RTCM_CHECK.process_bytes(bytes.data(), bytes.size()); | ||||||
|     std::bitset<24> computed_crc = std::bitset<24>(CRC_RTCM.checksum()); |     std::bitset<24> computed_crc = std::bitset<24>(CRC_RTCM_CHECK.checksum()); | ||||||
|     if(read_crc == computed_crc) |     if(read_crc == computed_crc) | ||||||
|         { |         { | ||||||
|             return true; |             return true; | ||||||
|   | |||||||
| @@ -78,6 +78,7 @@ public: | |||||||
|     std::string print_M1005_test(); //<! For testing purposes |     std::string print_M1005_test(); //<! For testing purposes | ||||||
|     int read_M1005(const std::string & message, unsigned int & ref_id, double & ecef_x, double & ecef_y, double & ecef_z, bool & gps, bool & glonass, bool & galileo); |     int read_M1005(const std::string & message, unsigned int & ref_id, double & ecef_x, double & ecef_y, double & ecef_z, bool & gps, bool & glonass, bool & galileo); | ||||||
|  |  | ||||||
|  |     bool check_CRC(const std::string & message); | ||||||
| private: | private: | ||||||
|     // |     // | ||||||
|     // Messages |     // Messages | ||||||
| @@ -123,9 +124,8 @@ private: | |||||||
|     std::bitset<10> message_length; |     std::bitset<10> message_length; | ||||||
|     std::bitset<24> crc_frame; |     std::bitset<24> crc_frame; | ||||||
|     typedef boost::crc_optimal<24, 0x1864CFBu, 0x0, 0x0, false, false> crc_24_q_type; |     typedef boost::crc_optimal<24, 0x1864CFBu, 0x0, 0x0, false, false> crc_24_q_type; | ||||||
|     crc_24_q_type CRC_RTCM; |  | ||||||
|     std::string add_CRC(const std::string& m); |     std::string add_CRC(const std::string& m); | ||||||
|     bool check_CRC(const std::string & message); |  | ||||||
|  |  | ||||||
|     std::string build_message(std::string data); // adds 0s to complete a byte and adds the CRC |     std::string build_message(std::string data); // adds 0s to complete a byte and adds the CRC | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										172
									
								
								src/tests/formats/rtcm_test.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										172
									
								
								src/tests/formats/rtcm_test.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,172 @@ | |||||||
|  | /*! | ||||||
|  |  * \file rtcm_test.cc | ||||||
|  |  * \brief  This file implements unit tests for the Rtcm class. | ||||||
|  |  * \author Carles Fernandez-Prades, 2015. cfernandez(at)cttc.es | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  |  * ------------------------------------------------------------------------- | ||||||
|  |  * | ||||||
|  |  * Copyright (C) 2010-2015  (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 <memory> | ||||||
|  | #include "rtcm.h" | ||||||
|  |  | ||||||
|  | TEST(Rtcm_Test, Hex_to_bin) | ||||||
|  | { | ||||||
|  |     auto  rtcm = std::make_shared<Rtcm>(); | ||||||
|  |  | ||||||
|  |     std::string test1 = "2A"; | ||||||
|  |     std::string test1_bin = rtcm->hex_to_bin(test1); | ||||||
|  |     EXPECT_EQ(0, test1_bin.compare("00101010")); | ||||||
|  |  | ||||||
|  |     std::string test2 = "FF"; | ||||||
|  |     std::string test2_bin = rtcm->hex_to_bin(test2); | ||||||
|  |     EXPECT_EQ(0, test2_bin.compare("11111111")); | ||||||
|  |  | ||||||
|  |     std::string test3 = "ff"; | ||||||
|  |     std::string test3_bin = rtcm->hex_to_bin(test3); | ||||||
|  |     EXPECT_EQ(0, test3_bin.compare("11111111")); | ||||||
|  |  | ||||||
|  |     std::string test4 = "100"; | ||||||
|  |     std::string test4_bin = rtcm->hex_to_bin(test4); | ||||||
|  |     EXPECT_EQ(0, test4_bin.compare("000100000000")); | ||||||
|  |  | ||||||
|  |     std::string test5 = "1101"; | ||||||
|  |     std::string test5_bin = rtcm->hex_to_bin(test5); | ||||||
|  |     EXPECT_EQ(0, test5_bin.compare("0001000100000001")); | ||||||
|  |  | ||||||
|  |     std::string test6 = "3"; | ||||||
|  |     std::string test6_bin = rtcm->hex_to_bin(test6); | ||||||
|  |     EXPECT_EQ(0, test6_bin.compare("0011")); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | TEST(Rtcm_Test, Bin_to_hex) | ||||||
|  | { | ||||||
|  |     auto  rtcm = std::make_shared<Rtcm>(); | ||||||
|  |  | ||||||
|  |     std::string test1 = "00101010"; | ||||||
|  |     std::string test1_hex = rtcm->bin_to_hex(test1); | ||||||
|  |     EXPECT_EQ(0, test1_hex.compare("2A")); | ||||||
|  |  | ||||||
|  |     std::string test2 = "11111111"; | ||||||
|  |     std::string test2_hex = rtcm->bin_to_hex(test2); | ||||||
|  |     EXPECT_EQ(0, test2_hex.compare("FF")); | ||||||
|  |  | ||||||
|  |     std::string test4 = "000100000000"; | ||||||
|  |     std::string test4_hex = rtcm->bin_to_hex(test4); | ||||||
|  |     EXPECT_EQ(0, test4_hex.compare("100")); | ||||||
|  |  | ||||||
|  |     std::string test5 = "0001000100000001"; | ||||||
|  |     std::string test5_hex = rtcm->bin_to_hex(test5); | ||||||
|  |     EXPECT_EQ(0, test5_hex.compare("1101")); | ||||||
|  |  | ||||||
|  |     std::string test6 = "0011"; | ||||||
|  |     std::string test6_hex = rtcm->bin_to_hex(test6); | ||||||
|  |     EXPECT_EQ(0, test6_hex.compare("3")); | ||||||
|  |  | ||||||
|  |     std::string test7 = "11"; | ||||||
|  |     std::string test7_hex = rtcm->bin_to_hex(test7); | ||||||
|  |     EXPECT_EQ(0, test7_hex.compare("3")); | ||||||
|  |  | ||||||
|  |     std::string test8 = "1000100000001"; | ||||||
|  |     std::string test8_hex = rtcm->bin_to_hex(test8); | ||||||
|  |     EXPECT_EQ(0, test8_hex.compare("1101")); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | TEST(Rtcm_Test, Hex_to_int) | ||||||
|  | { | ||||||
|  |     auto rtcm = std::make_shared<Rtcm>(); | ||||||
|  |  | ||||||
|  |     std::string test1 = "2A"; | ||||||
|  |     long int test1_int = rtcm->hex_to_int(test1); | ||||||
|  |     long int expected1 = 42; | ||||||
|  |     EXPECT_EQ(expected1, test1_int); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | TEST(Rtcm_Test, Bin_to_double) | ||||||
|  | { | ||||||
|  |     auto rtcm = std::make_shared<Rtcm>(); | ||||||
|  |  | ||||||
|  |     std::bitset<4> test1(5); | ||||||
|  |     long int test1_int = static_cast<long int>(rtcm->bin_to_double(test1.to_string())); | ||||||
|  |     long int expected1 = 5; | ||||||
|  |     EXPECT_EQ(expected1, test1_int); | ||||||
|  |  | ||||||
|  |     std::bitset<4> test2(-5); | ||||||
|  |     EXPECT_DOUBLE_EQ(-5, rtcm->bin_to_double(test2.to_string())); | ||||||
|  |  | ||||||
|  |     std::bitset<65> test3(-5); | ||||||
|  |     EXPECT_DOUBLE_EQ(0, rtcm->bin_to_double(test3.to_string())); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST(Rtcm_Test, Test_Read_M1005) | ||||||
|  | { | ||||||
|  |     auto rtcm = std::make_shared<Rtcm>(); | ||||||
|  |     std::string reference_msg = rtcm->print_M1005_test(); | ||||||
|  |  | ||||||
|  |     unsigned int ref_id; | ||||||
|  |     double ecef_x; | ||||||
|  |     double ecef_y; | ||||||
|  |     double ecef_z; | ||||||
|  |     bool gps; | ||||||
|  |     bool glonass; | ||||||
|  |     bool galileo; | ||||||
|  |  | ||||||
|  |     rtcm->read_M1005(reference_msg, ref_id, ecef_x, ecef_y, ecef_z, gps, glonass, galileo); | ||||||
|  |  | ||||||
|  |     EXPECT_EQ(true, gps); | ||||||
|  |     EXPECT_EQ(false, glonass); | ||||||
|  |     EXPECT_EQ(false, galileo); | ||||||
|  |  | ||||||
|  |     EXPECT_EQ(2003, ref_id); | ||||||
|  |     EXPECT_DOUBLE_EQ(1114104.5999, ecef_x); | ||||||
|  |     EXPECT_DOUBLE_EQ(-4850729.7108, ecef_y); | ||||||
|  |     EXPECT_DOUBLE_EQ(3975521.4643, ecef_z); | ||||||
|  |  | ||||||
|  |     rtcm->read_M1005("D300133ED7D30202980EDEEF34B4BD62AC0941986F33360B98", ref_id, ecef_x, ecef_y, ecef_z, gps, glonass, galileo); | ||||||
|  |  | ||||||
|  |     EXPECT_EQ(true, gps); | ||||||
|  |     EXPECT_EQ(false, glonass); | ||||||
|  |     EXPECT_EQ(false, galileo); | ||||||
|  |  | ||||||
|  |     EXPECT_EQ(2003, ref_id); | ||||||
|  |     EXPECT_DOUBLE_EQ(1114104.5999, ecef_x); | ||||||
|  |     EXPECT_DOUBLE_EQ(-4850729.7108, ecef_y); | ||||||
|  |     EXPECT_DOUBLE_EQ(3975521.4643, ecef_z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST(Rtcm_Test, Check_CRC) | ||||||
|  | { | ||||||
|  |     auto rtcm = std::make_shared<Rtcm>(); | ||||||
|  |     EXPECT_EQ(true, rtcm->check_CRC("D300133ED7D30202980EDEEF34B4BD62AC0941986F33360B98")); | ||||||
|  |     EXPECT_EQ(false, rtcm->check_CRC("D300133ED7D30202980EDEEF34B4BD62AC0941986F33360B99")); | ||||||
|  |  | ||||||
|  |     EXPECT_EQ(true, rtcm->check_CRC(rtcm->print_M1005_test())); | ||||||
|  |     EXPECT_EQ(true, rtcm->check_CRC(rtcm->print_M1005_test())); | ||||||
|  | } | ||||||
|  |  | ||||||
| @@ -28,13 +28,13 @@ | |||||||
|  * ------------------------------------------------------------------------- |  * ------------------------------------------------------------------------- | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include <fstream> | //#include <fstream> | ||||||
| #include <map> | //#include <map> | ||||||
| #include <string> | #include <string> | ||||||
| #include <boost/archive/xml_iarchive.hpp> | //#include <boost/archive/xml_iarchive.hpp> | ||||||
| #include <boost/serialization/nvp.hpp> | //#include <boost/serialization/nvp.hpp> | ||||||
| #include "rtcm_printer.h" | #include "rtcm_printer.h" | ||||||
| #include "gps_ephemeris.h" | //#include "gps_ephemeris.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -48,111 +48,35 @@ TEST(Rtcm_Printer_Test, Instantiate) | |||||||
|     std::unique_ptr<Rtcm_Printer> RTCM_printer(new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname)); |     std::unique_ptr<Rtcm_Printer> RTCM_printer(new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname)); | ||||||
| } | } | ||||||
|  |  | ||||||
| TEST(Rtcm_Printer_Test, Instantiate_and_Run) | TEST(Rtcm_Printer_Test, Run) | ||||||
| { | { | ||||||
|     std::string file_name = "./gps_ephemeris_rx.xml"; |     //    std::string file_name = "./gps_ephemeris_rx.xml"; | ||||||
|     std::map<int,Gps_Ephemeris> gps_ephemeris_map; |     //    std::map<int,Gps_Ephemeris> gps_ephemeris_map; | ||||||
|     try |     //    try | ||||||
|     { |     //    { | ||||||
|             std::ifstream ifs(file_name.c_str(), std::ifstream::binary | std::ifstream::in); |     //            std::ifstream ifs(file_name.c_str(), std::ifstream::binary | std::ifstream::in); | ||||||
|             boost::archive::xml_iarchive xml(ifs); |     //            boost::archive::xml_iarchive xml(ifs); | ||||||
|             gps_ephemeris_map.clear(); |     //            gps_ephemeris_map.clear(); | ||||||
|             xml >> boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", gps_ephemeris_map); |     //            xml >> boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", gps_ephemeris_map); | ||||||
|             ifs.close(); |     //            ifs.close(); | ||||||
|     } |     //    } | ||||||
|     catch (std::exception& e) |     //    catch (std::exception& e) | ||||||
|     { |     //    { | ||||||
|             //LOG(WARNING) << e.what() << "File: " << file_name; |     //            //LOG(WARNING) << e.what() << "File: " << file_name; | ||||||
|             //std::cout << "File not found" << std::endl; |     //            //std::cout << "File not found" << std::endl; | ||||||
|     } |     //    } | ||||||
|  |  | ||||||
|     std::string filename = "hello.rtcm"; |     std::string filename = "test.rtcm"; | ||||||
|     bool flag_rtcm_tty_port = false; |     bool flag_rtcm_tty_port = false; | ||||||
|     std::string rtcm_dump_devname = "/dev/pts/4"; |     std::string rtcm_dump_devname = "/dev/pts/4"; | ||||||
|  |  | ||||||
|     std::unique_ptr<Rtcm_Printer> RTCM_printer(new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname)); |     std::unique_ptr<Rtcm_Printer> RTCM_printer(new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname)); | ||||||
|  |  | ||||||
|     std::string reference_msg = "D300133ED7D30202980EDEEF34B4BD62AC0941986F33360B98"; |     std::string reference_msg = "D300133ED7D30202980EDEEF34B4BD62AC0941986F33360B98"; | ||||||
|     std::string testing_msg = RTCM_printer->print_M1005_test(); |     std::string testing_msg = RTCM_printer->print_M1005_test(); | ||||||
|  |  | ||||||
|     EXPECT_EQ(reference_msg, testing_msg); |     EXPECT_EQ(reference_msg, testing_msg); | ||||||
| } | } | ||||||
|  |  | ||||||
| TEST(Rtcm_Printer_Test, Bin_to_hex) |  | ||||||
| { |  | ||||||
|     auto  rtcm = std::make_shared<Rtcm>(); |  | ||||||
|  |  | ||||||
|     std::string test1 = "2A"; |  | ||||||
|     std::string test1_bin = rtcm->hex_to_bin(test1); |  | ||||||
|     EXPECT_EQ(0, test1_bin.compare("00101010")); |  | ||||||
|  |  | ||||||
|     std::string test2 = "FF"; |  | ||||||
|     std::string test2_bin = rtcm->hex_to_bin(test2); |  | ||||||
|     EXPECT_EQ(0, test2_bin.compare("11111111")); |  | ||||||
|  |  | ||||||
|     std::string test3 = "ff"; |  | ||||||
|     std::string test3_bin = rtcm->hex_to_bin(test3); |  | ||||||
|     EXPECT_EQ(0, test3_bin.compare("11111111")); |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| TEST(Rtcm_Printer_Test, Hex_to_int) |  | ||||||
| { |  | ||||||
|     auto  rtcm = std::make_shared<Rtcm>(); |  | ||||||
|  |  | ||||||
|     std::string test1 = "2A"; |  | ||||||
|     long int test1_int = rtcm->hex_to_int(test1); |  | ||||||
|     long int expected1 = 42; |  | ||||||
|     EXPECT_EQ(expected1, test1_int); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| TEST(Rtcm_Printer_Test, Bin_to_double) |  | ||||||
| { |  | ||||||
|     auto  rtcm = std::make_shared<Rtcm>(); |  | ||||||
|  |  | ||||||
|     std::bitset<4> test1(5); |  | ||||||
|     long int test1_int = static_cast<long int>(rtcm->bin_to_double(test1.to_string())); |  | ||||||
|     long int expected1 = 5; |  | ||||||
|     EXPECT_EQ(expected1, test1_int); |  | ||||||
|  |  | ||||||
|     std::bitset<4> test2(-5); |  | ||||||
|     long int test2_int = static_cast<long int>(rtcm->bin_to_double(test2.to_string())); |  | ||||||
|     long int expected2 = -5; |  | ||||||
|     EXPECT_EQ(expected2, test2_int); |  | ||||||
|  |  | ||||||
|     std::bitset<65> test3(-5); |  | ||||||
|     long int test3_int = static_cast<long int>(rtcm->bin_to_double(test3.to_string())); |  | ||||||
|     long int expected3 = 0; |  | ||||||
|     EXPECT_EQ(expected3, test3_int); |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| TEST(Rtcm_Printer_Test, Read_M1005) |  | ||||||
| { |  | ||||||
|     std::string filename = "hello.rtcm"; |  | ||||||
|     bool flag_rtcm_tty_port = false; |  | ||||||
|     std::string rtcm_dump_devname = "/dev/pts/4"; |  | ||||||
|  |  | ||||||
|     auto rtcm = std::make_shared<Rtcm>(); |  | ||||||
|     auto rtcm_printer = std::make_shared<Rtcm_Printer>(filename, flag_rtcm_tty_port, rtcm_dump_devname); |  | ||||||
|     std::string reference_msg = rtcm_printer->print_M1005_test(); |  | ||||||
|  |  | ||||||
|     unsigned int ref_id; |  | ||||||
|     double ecef_x; |  | ||||||
|     double ecef_y; |  | ||||||
|     double ecef_z; |  | ||||||
|     bool gps; |  | ||||||
|     bool glonass; |  | ||||||
|     bool galileo; |  | ||||||
|  |  | ||||||
|     rtcm->read_M1005(reference_msg, ref_id, ecef_x, ecef_y, ecef_z, gps, glonass, galileo); |  | ||||||
|  |  | ||||||
|     EXPECT_EQ(true, gps); |  | ||||||
|     EXPECT_EQ(false, glonass); |  | ||||||
|     EXPECT_EQ(false, galileo); |  | ||||||
|  |  | ||||||
|     EXPECT_EQ(2003, ref_id); |  | ||||||
|     EXPECT_DOUBLE_EQ(1114104.5999, ecef_x); |  | ||||||
|     EXPECT_DOUBLE_EQ(-4850729.7108, ecef_y); |  | ||||||
|     EXPECT_DOUBLE_EQ(3975521.4643, ecef_z); |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -79,6 +79,8 @@ DECLARE_string(log_dir); | |||||||
| #include "control_thread/control_thread_test.cc" | #include "control_thread/control_thread_test.cc" | ||||||
| #include "flowgraph/pass_through_test.cc" | #include "flowgraph/pass_through_test.cc" | ||||||
| #include "flowgraph/gnss_flowgraph_test.cc" | #include "flowgraph/gnss_flowgraph_test.cc" | ||||||
|  | #include "formats/string_converter_test.cc" | ||||||
|  | #include "formats/rtcm_test.cc" | ||||||
| #include "gnss_block/gnss_block_factory_test.cc" | #include "gnss_block/gnss_block_factory_test.cc" | ||||||
| #include "gnss_block/rtcm_printer_test.cc" | #include "gnss_block/rtcm_printer_test.cc" | ||||||
| #include "gnss_block/file_output_filter_test.cc" | #include "gnss_block/file_output_filter_test.cc" | ||||||
| @@ -103,7 +105,6 @@ DECLARE_string(log_dir); | |||||||
| #include "gnss_block/galileo_e1_dll_pll_veml_tracking_test.cc" | #include "gnss_block/galileo_e1_dll_pll_veml_tracking_test.cc" | ||||||
| #include "gnuradio_block/gnss_sdr_valve_test.cc" | #include "gnuradio_block/gnss_sdr_valve_test.cc" | ||||||
| #include "gnuradio_block/direct_resampler_conditioner_cc_test.cc" | #include "gnuradio_block/direct_resampler_conditioner_cc_test.cc" | ||||||
| #include "string_converter/string_converter_test.cc" |  | ||||||
|  |  | ||||||
| //#include "gnss_block/galileo_e5a_pcps_acquisition_test.cc" | //#include "gnss_block/galileo_e5a_pcps_acquisition_test.cc" | ||||||
| //#include "gnss_block/galileo_e5a_pcps_acquisition_test_2.cc" | //#include "gnss_block/galileo_e5a_pcps_acquisition_test_2.cc" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez