diff --git a/src/algorithms/PVT/libs/rinex_printer.cc b/src/algorithms/PVT/libs/rinex_printer.cc index 92098517f..6c2d322d5 100644 --- a/src/algorithms/PVT/libs/rinex_printer.cc +++ b/src/algorithms/PVT/libs/rinex_printer.cc @@ -5651,7 +5651,7 @@ void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::mapsecond.E1B_DVS); - std::string SVhealth_str = std::move(E5B_HS) + std::to_string(galileo_ephemeris_iter->second.E5b_DVS) + "11" + "1" + std::string(E1B_DVS) + std::string(E1B_HS) + std::to_string(galileo_ephemeris_iter->second.E1B_DVS); + std::string SVhealth_str = std::move(E5B_HS) + std::to_string(galileo_ephemeris_iter->second.E5b_DVS) + "11" + "1" + std::move(E1B_DVS) + std::move(E1B_HS) + std::to_string(galileo_ephemeris_iter->second.E1B_DVS); int32_t SVhealth = Rinex_Printer::toInt(SVhealth_str, 9); line += Rinex_Printer::doub2for(static_cast(SVhealth), 18, 2); line += std::string(1, ' '); diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fpga.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fpga.h index d0c0c3849..92ec51781 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fpga.h +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fpga.h @@ -33,6 +33,7 @@ #include // for uint32_t #include // for shared_ptr #include // for string +#include // for move /** \addtogroup Acquisition * \{ */ @@ -118,7 +119,7 @@ public: */ inline void set_channel_fsm(std::weak_ptr channel_fsm) { - d_channel_fsm = channel_fsm; + d_channel_fsm = std::move(channel_fsm); } /*! diff --git a/src/algorithms/acquisition/libs/acq_conf_fpga.cc b/src/algorithms/acquisition/libs/acq_conf_fpga.cc index 5c1e9e0c2..838ab3ae6 100644 --- a/src/algorithms/acquisition/libs/acq_conf_fpga.cc +++ b/src/algorithms/acquisition/libs/acq_conf_fpga.cc @@ -21,6 +21,7 @@ #include #include #include +#include void Acq_Conf_Fpga::SetFromConfiguration(const ConfigurationInterface *configuration, const std::string &role, uint32_t sel_queue_fpga, uint32_t blk_exp, uint32_t downsampling_factor_default, double chip_rate, double code_length_chips) @@ -58,7 +59,7 @@ void Acq_Conf_Fpga::SetFromConfiguration(const ConfigurationInterface *configura std::cout << "Cannot find the FPGA uio device file corresponding to device name " << acquisition_device_name << std::endl; throw std::exception(); } - device_name = device_io_name; + device_name = std::move(device_io_name); // exclusion limit excludelimit = static_cast(1 + ceil((1.0 / chip_rate) * static_cast(fs_in))); diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 977cc17df..7e7e3fa74 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -450,7 +450,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, { return false; } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 0, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1) { return false; } @@ -472,7 +472,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << rx_stream_dev_a << " channel 1 not found\n"; throw std::runtime_error(rx_stream_dev_a + "RX channel 1 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ad9361_phy, rx_chan1, chn, 1, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ad9361_phy, rx_chan1, chn, 1, std::move(filter_filename_), Fpass_, Fstop_) == -1) { return false; } diff --git a/src/algorithms/signal_source/libs/fpga_dynamic_bit_selection.cc b/src/algorithms/signal_source/libs/fpga_dynamic_bit_selection.cc index d71056582..e5725881e 100644 --- a/src/algorithms/signal_source/libs/fpga_dynamic_bit_selection.cc +++ b/src/algorithms/signal_source/libs/fpga_dynamic_bit_selection.cc @@ -29,6 +29,12 @@ Fpga_dynamic_bit_selection::Fpga_dynamic_bit_selection(bool enable_rx1_band, bool enable_rx2_band) : d_enable_rx1_band(enable_rx1_band), d_enable_rx2_band(enable_rx2_band) { + d_map_base_freq_band_1 = nullptr; + d_map_base_freq_band_2 = nullptr; + d_dev_descr_freq_band_1 = 0; + d_dev_descr_freq_band_2 = 0; + d_shift_out_bits_freq_band_1 = 0; + d_shift_out_bits_freq_band_2 = 0; if (d_enable_rx1_band) { open_device(&d_map_base_freq_band_1, d_dev_descr_freq_band_1, 0); @@ -41,7 +47,7 @@ Fpga_dynamic_bit_selection::Fpga_dynamic_bit_selection(bool enable_rx1_band, boo { open_device(&d_map_base_freq_band_2, d_dev_descr_freq_band_2, 1); - // init bit selection corresponding to frequency band 1 + // init bit selection corresponding to frequency band 2 d_shift_out_bits_freq_band_2 = shift_out_bits_default; d_map_base_freq_band_2[0] = d_shift_out_bits_freq_band_2; } diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc index 68df0ec82..070f0d46f 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc @@ -446,7 +446,7 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga & { std::string dump_filename_ = d_dump_filename.substr(d_dump_filename.find_last_of('/') + 1); dump_path = d_dump_filename.substr(0, d_dump_filename.find_last_of('/')); - d_dump_filename = dump_filename_; + d_dump_filename = std::move(dump_filename_); } else { @@ -1383,6 +1383,7 @@ void dll_pll_veml_tracking_fpga::set_gnss_synchro(Gnss_Synchro *p_gnss_synchro) d_acquisition_gnss_synchro = p_gnss_synchro; if (p_gnss_synchro->PRN > 0) { + gr::thread::scoped_lock lock(d_setlock); // A set_gnss_synchro command with a valid PRN is received when the system is going to run acquisition with that PRN. // We can use this command to pre-initialize tracking parameters and variables before the actual acquisition process takes place. // In this way we minimize the latency between acquisition and tracking once the acquisition has been made. @@ -1527,8 +1528,8 @@ int dll_pll_veml_tracking_fpga::general_work(int noutput_items __attribute__((un { case 1: // Pull-in { - d_worker_is_done = false; boost::mutex::scoped_lock lock(d_mutex); + d_worker_is_done = false; while (!d_worker_is_done) { d_m_condition.wait(lock); diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_gaussian_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_gaussian_tracking_cc.cc index df97429eb..6c8e82231 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_gaussian_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_gaussian_tracking_cc.cc @@ -308,10 +308,6 @@ void Gps_L1_Ca_Gaussian_Tracking_cc::start_tracking() sys = std::string(1, d_acquisition_gnss_synchro->System); - // DEBUG OUTPUT - std::cout << "Tracking of GPS L1 C/A signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << '\n'; - LOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel; - // enable tracking d_pull_in = true; d_enable_tracking = true; @@ -319,6 +315,10 @@ void Gps_L1_Ca_Gaussian_Tracking_cc::start_tracking() LOG(INFO) << "PULL-IN Doppler [Hz]=" << d_carrier_doppler_hz << " Code Phase correction [samples]=" << delay_correction_samples << " PULL-IN Code Phase [samples]=" << d_acq_code_phase_samples; + + gr::thread::scoped_lock l(d_setlock); + std::cout << "Tracking of GPS L1 C/A signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << '\n'; + LOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel; } @@ -776,6 +776,7 @@ int Gps_L1_Ca_Gaussian_Tracking_cc::general_work(int noutput_items __attribute__ } if (d_carrier_lock_fail_counter > FLAGS_max_lock_fail) { + gr::thread::scoped_lock l(d_setlock); std::cout << "Loss of lock in channel " << d_channel << "!\n"; LOG(INFO) << "Loss of lock in channel " << d_channel << "!"; this->message_port_pub(pmt::mp("events"), pmt::from_long(3)); // 3 -> loss of lock diff --git a/src/algorithms/tracking/libs/fpga_multicorrelator.cc b/src/algorithms/tracking/libs/fpga_multicorrelator.cc index 0269ed25d..99f5f778c 100644 --- a/src/algorithms/tracking/libs/fpga_multicorrelator.cc +++ b/src/algorithms/tracking/libs/fpga_multicorrelator.cc @@ -57,20 +57,26 @@ Fpga_Multicorrelator_8sc::Fpga_Multicorrelator_8sc(int32_t n_correlators, d_Prompt_Data(nullptr), d_shifts_chips(nullptr), d_prompt_data_shift(nullptr), - d_rem_code_phase_chips(0), - d_code_phase_step_chips(0), - d_rem_carrier_phase_in_rad(0), - d_phase_step_rad(0), + d_rem_code_phase_chips(0.0), + d_code_phase_step_chips(0.0), + d_code_phase_rate_step_chips(0.0), + d_rem_carrier_phase_in_rad(0.0), + d_phase_step_rad(0.0), + d_carrier_phase_rate_step_rad(0.0), d_code_length_samples(code_length_chips * code_samples_per_chip), d_n_correlators(n_correlators), d_device_descriptor(0), d_map_base(nullptr), d_correlator_length_samples(0), d_code_phase_step_chips_num(0), + d_code_phase_rate_step_chips_num(0), d_rem_carr_phase_rad_int(0), d_phase_step_rad_int(0), + d_carrier_phase_rate_step_rad_int(0), d_ca_codes(ca_codes), d_data_codes(data_codes), + d_secondary_code_0_length(0), + d_secondary_code_1_length(0), d_track_pilot(track_pilot), d_secondary_code_enabled(false) { diff --git a/src/core/receiver/gnss_flowgraph.cc b/src/core/receiver/gnss_flowgraph.cc index 1c913a8fc..47e35bfbd 100644 --- a/src/core/receiver/gnss_flowgraph.cc +++ b/src/core/receiver/gnss_flowgraph.cc @@ -2097,6 +2097,7 @@ void GNSSFlowgraph::set_configuration(const std::shared_ptr lock(signal_list_mutex_); for (int i = 0; i < channels_count_; i++) { if (channels_state_[i] == 1) diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test_fpga.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test_fpga.cc index 3206fdc67..714810fd7 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test_fpga.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test_fpga.cc @@ -91,6 +91,7 @@ GalileoE1PcpsAmbiguousAcquisitionTestFpga::GalileoE1PcpsAmbiguousAcquisitionTest doppler_max = 5000; doppler_step = 100; + nsamples_to_transfer = 0; } @@ -280,7 +281,7 @@ public: } private: - bool acquisition_successful; + bool acquisition_successful{}; }; @@ -310,7 +311,7 @@ bool GalileoE1PcpsAmbiguousAcquisitionTestFpga::acquire_signal() args.scaling_factor = DMA_SIGNAL_SCALING_FACTOR; std::string file = "data/Galileo_E1_ID_1_Fs_4Msps_8ms.dat"; - args.file = file; // DMA file configuration + args.file = std::move(file); // DMA file configuration // instantiate the FPGA switch and set the // switch position to DMA. @@ -348,7 +349,7 @@ bool GalileoE1PcpsAmbiguousAcquisitionTestFpga::acquire_signal() args.nsamples_tx = nsamples_to_transfer; // run the acquisition. The acquisition must run in a separate thread because it is a blocking function - args_acq.acquisition = acquisition; + args_acq.acquisition = std::move(acquisition); if (pthread_create(&thread_acquisition, nullptr, handler_acquisition_galileo_e1_pcps_ambiguous_acq_test, reinterpret_cast(&args_acq)) < 0) { diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test_fpga.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test_fpga.cc index eb5d8fe2a..4bc54fba4 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test_fpga.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test_fpga.cc @@ -279,7 +279,7 @@ public: } private: - bool acquisition_successful; + bool acquisition_successful{}; }; @@ -309,7 +309,7 @@ bool GpsL1CaPcpsAcquisitionTestFpga::acquire_signal() args.scaling_factor = DMA_SIGNAL_SCALING_FACTOR; std::string file = "data/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; - args.file = file; // DMA file configuration + args.file = std::move(file); // DMA file configuration // instantiate the FPGA switch and set the // switch position to DMA. @@ -347,7 +347,7 @@ bool GpsL1CaPcpsAcquisitionTestFpga::acquire_signal() args.nsamples_tx = nsamples_to_transfer; // run the acquisition. The acquisition must run in a separate thread because it is a blocking function - args_acq.acquisition = acquisition; + args_acq.acquisition = std::move(acquisition); if (pthread_create(&thread_acquisition, nullptr, handler_acquisition_gps_l1_acq_test, reinterpret_cast(&args_acq)) < 0) { diff --git a/src/tests/unit-tests/signal-processing-blocks/filter/fir_filter_test.cc b/src/tests/unit-tests/signal-processing-blocks/filter/fir_filter_test.cc index ec1b783ef..97b27f51c 100644 --- a/src/tests/unit-tests/signal-processing-blocks/filter/fir_filter_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/filter/fir_filter_test.cc @@ -224,7 +224,7 @@ TEST_F(FirFilterTest, ConnectAndRunGrcomplex) config2->set_property("Test_Source.sampling_frequency", "4000000"); std::string path = std::string(TEST_PATH); std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; - config2->set_property("Test_Source.filename", filename); + config2->set_property("Test_Source.filename", std::move(filename)); config2->set_property("Test_Source.item_type", "gr_complex"); config2->set_property("Test_Source.repeat", "true"); diff --git a/src/tests/unit-tests/signal-processing-blocks/filter/notch_filter_test.cc b/src/tests/unit-tests/signal-processing-blocks/filter/notch_filter_test.cc index 36c7346a2..cf4cde035 100644 --- a/src/tests/unit-tests/signal-processing-blocks/filter/notch_filter_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/filter/notch_filter_test.cc @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef GR_GREATER_38 #include #else @@ -177,7 +178,7 @@ TEST_F(NotchFilterTest, ConnectAndRunGrcomplex) config2->set_property("Test_Source.sampling_frequency", "4000000"); std::string path = std::string(TEST_PATH); std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; - config2->set_property("Test_Source.filename", filename); + config2->set_property("Test_Source.filename", std::move(filename)); config2->set_property("Test_Source.item_type", "gr_complex"); config2->set_property("Test_Source.repeat", "true"); diff --git a/src/tests/unit-tests/signal-processing-blocks/filter/pulse_blanking_filter_test.cc b/src/tests/unit-tests/signal-processing-blocks/filter/pulse_blanking_filter_test.cc index 63038b5f1..4cb3c5c43 100644 --- a/src/tests/unit-tests/signal-processing-blocks/filter/pulse_blanking_filter_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/filter/pulse_blanking_filter_test.cc @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef GR_GREATER_38 #include #else @@ -176,7 +177,7 @@ TEST_F(PulseBlankingFilterTest, ConnectAndRunGrcomplex) config2->set_property("Test_Source.sampling_frequency", "4000000"); std::string path = std::string(TEST_PATH); std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; - config2->set_property("Test_Source.filename", filename); + config2->set_property("Test_Source.filename", std::move(filename)); config2->set_property("Test_Source.item_type", "gr_complex"); config2->set_property("Test_Source.repeat", "true"); diff --git a/src/utils/front-end-cal/main.cc b/src/utils/front-end-cal/main.cc index 4915b35b5..972e4a21e 100644 --- a/src/utils/front-end-cal/main.cc +++ b/src/utils/front-end-cal/main.cc @@ -269,18 +269,26 @@ static time_t utc_time(int week, int64_t tow) int main(int argc, char** argv) { - const std::string intro_help( - std::string("\n RTL-SDR E4000 RF front-end center frequency and sampling rate calibration tool that uses GPS signals\n") + - "Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)\n" + - "This program comes with ABSOLUTELY NO WARRANTY;\n" + - "See COPYING file to see a copy of the General Public License\n \n"); + try + { + const std::string intro_help( + std::string("\n RTL-SDR E4000 RF front-end center frequency and sampling rate calibration tool that uses GPS signals\n") + + "Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)\n" + + "This program comes with ABSOLUTELY NO WARRANTY;\n" + + "See COPYING file to see a copy of the General Public License\n \n"); - gflags::SetUsageMessage(intro_help); - google::SetVersionString(FRONT_END_CAL_VERSION); - gflags::ParseCommandLineFlags(&argc, &argv, true); - - std::cout << "Initializing... Please wait.\n"; + gflags::SetUsageMessage(intro_help); + google::SetVersionString(FRONT_END_CAL_VERSION); + gflags::ParseCommandLineFlags(&argc, &argv, true); + std::cout << "Initializing... Please wait.\n"; + } + catch (const std::exception& e) + { + std::cerr << e.what() << '\n'; + std::cout << "front-end-cal program ended.\n"; + return 1; + } google::InitGoogleLogging(argv[0]); if (FLAGS_log_dir.empty()) { @@ -292,358 +300,390 @@ int main(int argc, char** argv) } else { - const fs::path p(FLAGS_log_dir); - if (!fs::exists(p)) + try { - std::cout << "The path " - << FLAGS_log_dir - << " does not exist, attempting to create it" - << '\n'; - fs::create_directory(p); + const fs::path p(FLAGS_log_dir); + if (!fs::exists(p)) + { + std::cout << "The path " + << FLAGS_log_dir + << " does not exist, attempting to create it" + << '\n'; + errorlib::error_code ec; + if (!fs::create_directory(p, ec)) + { + std::cerr << "Could not create the " << FLAGS_log_dir << " folder. Front-end-cal program ended.\n"; + gflags::ShutDownCommandLineFlags(); + return 1; + } + } + std::cout << "Logging with be done at " + << FLAGS_log_dir << '\n'; + } + catch (const std::exception& e) + { + std::cerr << e.what() << '\n'; + std::cerr << "Could not create the " << FLAGS_log_dir << " folder. Front-end-cal program ended.\n"; + gflags::ShutDownCommandLineFlags(); + return 1; } - std::cout << "Logging with be done at " - << FLAGS_log_dir << '\n'; } // 0. Instantiate the FrontEnd Calibration class - FrontEndCal front_end_cal; - - // 1. Load configuration parameters from config file - std::shared_ptr configuration = std::make_shared(FLAGS_config_file); - front_end_cal.set_configuration(configuration); - - // 2. Get SUPL information from server: Ephemeris record, assistance info and TOW try { - if (front_end_cal.get_ephemeris() == true) - { - std::cout << "SUPL data received OK!\n"; - } - else - { - std::cout << "Failure connecting to SUPL server\n"; - } - } - catch (const boost::exception& e) - { - std::cout << "Failure connecting to SUPL server\n"; - } + FrontEndCal front_end_cal; - // 3. Capture some front-end samples to hard disk - try - { - if (front_end_capture(configuration)) - { - std::cout << "Front-end RAW samples captured\n"; - } - else - { - std::cout << "Failure capturing front-end samples\n"; - } - } - catch (const boost::bad_lexical_cast& e) - { - std::cout << "Exception caught while capturing samples (bad lexical cast)\n"; - } - catch (const std::exception& e) - { - std::cout << "Exception caught while capturing samples: " << e.what() << '\n'; - } - catch (...) - { - std::cout << "Unexpected exception\n"; - } + // 1. Load configuration parameters from config file + std::shared_ptr configuration = std::make_shared(FLAGS_config_file); + front_end_cal.set_configuration(configuration); - // 4. Setup GNU Radio flowgraph (file_source -> Acquisition_10m) - gr::top_block_sptr top_block; - top_block = gr::make_top_block("Acquisition test"); - - // Satellite signal definition - gnss_synchro = Gnss_Synchro(); - gnss_synchro.Channel_ID = 0; - gnss_synchro.System = 'G'; - std::string signal = "1C"; - signal.copy(gnss_synchro.Signal, 2, 0); - gnss_synchro.PRN = 1; - - int64_t fs_in_ = configuration->property("GNSS-SDR.internal_fs_sps", 2048000); - configuration->set_property("Acquisition.max_dwells", "10"); - - auto acquisition = std::make_shared(configuration.get(), "Acquisition", 1, 1); - - acquisition->set_channel(1); - acquisition->set_gnss_synchro(&gnss_synchro); - acquisition->set_threshold(configuration->property("Acquisition.threshold", 2.0)); - acquisition->set_doppler_max(configuration->property("Acquisition.doppler_max", 10000)); - acquisition->set_doppler_step(configuration->property("Acquisition.doppler_step", 250)); - - gr::block_sptr source; - source = gr::blocks::file_source::make(sizeof(gr_complex), "tmp_capture.dat"); -#if GNURADIO_USES_STD_POINTERS - std::shared_ptr msg_rx; -#else - boost::shared_ptr msg_rx; -#endif - try - { - msg_rx = FrontEndCal_msg_rx_make(); - } - catch (const std::exception& e) - { - std::cout << "Failure connecting the message port system: " << e.what() << '\n'; - exit(0); - } - - try - { - acquisition->connect(top_block); - top_block->connect(source, 0, acquisition->get_left_block(), 0); - top_block->msg_connect(acquisition->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events")); - } - catch (const std::exception& e) - { - std::cout << "Failure connecting the GNU Radio blocks: " << e.what() << '\n'; - } - - // 5. Run the flowgraph - // Get visible GPS satellites (positive acquisitions with Doppler measurements) - // Compute Doppler estimations - - // todo: Fix the front-end cal to support new channel internal message system (no more external queues) - std::map doppler_measurements_map; - std::map cn0_measurements_map; - - std::thread ch_thread; - - // record startup time - std::chrono::time_point start; - std::chrono::time_point end; - std::chrono::duration elapsed_seconds{}; - start = std::chrono::system_clock::now(); - - bool start_msg = true; - - for (unsigned int PRN = 1; PRN < 33; PRN++) - { - gnss_synchro.PRN = PRN; - acquisition->set_gnss_synchro(&gnss_synchro); - acquisition->init(); - acquisition->set_local_code(); - acquisition->reset(); - stop = false; + // 2. Get SUPL information from server: Ephemeris record, assistance info and TOW try { - ch_thread = std::thread(wait_message); - } - catch (const std::exception& e) - { - LOG(INFO) << "Exception caught (thread resource error)"; - } - top_block->run(); - if (start_msg == true) - { - std::cout << "Searching for GPS Satellites in L1 band...\n"; - std::cout << "["; - start_msg = false; - } - if (!gnss_sync_vector.empty()) - { - std::cout << " " << PRN << " "; - double doppler_measurement_hz = 0; - for (auto& it : gnss_sync_vector) + if (front_end_cal.get_ephemeris() == true) { - doppler_measurement_hz += it.Acq_doppler_hz; + std::cout << "SUPL data received OK!\n"; + } + else + { + std::cout << "Failure connecting to SUPL server\n"; } - doppler_measurement_hz = doppler_measurement_hz / gnss_sync_vector.size(); - doppler_measurements_map.insert(std::pair(PRN, doppler_measurement_hz)); - } - else - { - std::cout << " . "; - } - try - { - channel_internal_queue.push(3); } catch (const boost::exception& e) { - LOG(INFO) << "Exception caught while pushing to the internal queue."; + std::cout << "Failure connecting to SUPL server\n"; } + + // 3. Capture some front-end samples to hard disk try { - ch_thread.join(); + if (front_end_capture(configuration)) + { + std::cout << "Front-end RAW samples captured\n"; + } + else + { + std::cout << "Failure capturing front-end samples\n"; + } + } + catch (const boost::bad_lexical_cast& e) + { + std::cout << "Exception caught while capturing samples (bad lexical cast)\n"; } catch (const std::exception& e) { - LOG(INFO) << "Exception caught while joining threads."; + std::cout << "Exception caught while capturing samples: " << e.what() << '\n'; } - gnss_sync_vector.clear(); + catch (...) + { + std::cout << "Unexpected exception\n"; + } + + // 4. Setup GNU Radio flowgraph (file_source -> Acquisition_10m) + gr::top_block_sptr top_block; + top_block = gr::make_top_block("Acquisition test"); + + // Satellite signal definition + gnss_synchro = Gnss_Synchro(); + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal, 2, 0); + gnss_synchro.PRN = 1; + + int64_t fs_in_ = configuration->property("GNSS-SDR.internal_fs_sps", 2048000); + configuration->set_property("Acquisition.max_dwells", "10"); + + auto acquisition = std::make_shared(configuration.get(), "Acquisition", 1, 1); + + acquisition->set_channel(1); + acquisition->set_gnss_synchro(&gnss_synchro); + acquisition->set_threshold(configuration->property("Acquisition.threshold", 2.0)); + acquisition->set_doppler_max(configuration->property("Acquisition.doppler_max", 10000)); + acquisition->set_doppler_step(configuration->property("Acquisition.doppler_step", 250)); + + gr::block_sptr source; + source = gr::blocks::file_source::make(sizeof(gr_complex), "tmp_capture.dat"); #if GNURADIO_USES_STD_POINTERS - std::dynamic_pointer_cast(source)->seek(0, 0); + std::shared_ptr msg_rx; #else - boost::dynamic_pointer_cast(source)->seek(0, 0); + boost::shared_ptr msg_rx; #endif - std::cout.flush(); - } - std::cout << "]\n"; - - // report the elapsed time - end = std::chrono::system_clock::now(); - elapsed_seconds = end - start; - std::cout << "Total signal acquisition run time " - << elapsed_seconds.count() - << " [seconds]\n"; - - // 6. find TOW from SUPL assistance - double current_TOW = 0; - try - { - if (global_gps_ephemeris_map.size() > 0) + try { - std::map Eph_map; - Eph_map = global_gps_ephemeris_map.get_map_copy(); - current_TOW = Eph_map.begin()->second.tow; - - time_t t = utc_time(Eph_map.begin()->second.WN, static_cast(current_TOW)); - - std::cout << "Reference Time:\n"; - std::cout << " GPS Week: " << Eph_map.begin()->second.WN << '\n'; - std::cout << " GPS TOW: " << static_cast(current_TOW) << " " << static_cast(current_TOW) * 0.08 << '\n'; - std::cout << " ~ UTC: " << ctime(&t) << '\n'; - std::cout << "Current TOW obtained from SUPL assistance = " << current_TOW << '\n'; + msg_rx = FrontEndCal_msg_rx_make(); } - else + catch (const std::exception& e) { - std::cout << "Unable to get Ephemeris SUPL assistance. TOW is unknown!\n"; + std::cout << "Failure connecting the message port system: " << e.what() << '\n'; + exit(0); + } + + try + { + acquisition->connect(top_block); + top_block->connect(source, 0, acquisition->get_left_block(), 0); + top_block->msg_connect(acquisition->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events")); + } + catch (const std::exception& e) + { + std::cout << "Failure connecting the GNU Radio blocks: " << e.what() << '\n'; + } + + // 5. Run the flowgraph + // Get visible GPS satellites (positive acquisitions with Doppler measurements) + // Compute Doppler estimations + + // todo: Fix the front-end cal to support new channel internal message system (no more external queues) + std::map doppler_measurements_map; + std::map cn0_measurements_map; + + std::thread ch_thread; + + // record startup time + std::chrono::time_point start; + std::chrono::time_point end; + std::chrono::duration elapsed_seconds{}; + start = std::chrono::system_clock::now(); + + bool start_msg = true; + + for (unsigned int PRN = 1; PRN < 33; PRN++) + { + gnss_synchro.PRN = PRN; + acquisition->set_gnss_synchro(&gnss_synchro); + acquisition->init(); + acquisition->set_local_code(); + acquisition->reset(); + stop = false; + try + { + ch_thread = std::thread(wait_message); + } + catch (const std::exception& e) + { + LOG(INFO) << "Exception caught (thread resource error)"; + } + top_block->run(); + if (start_msg == true) + { + std::cout << "Searching for GPS Satellites in L1 band...\n"; + std::cout << "["; + start_msg = false; + } + if (!gnss_sync_vector.empty()) + { + std::cout << " " << PRN << " "; + double doppler_measurement_hz = 0; + for (auto& it : gnss_sync_vector) + { + doppler_measurement_hz += it.Acq_doppler_hz; + } + doppler_measurement_hz = doppler_measurement_hz / gnss_sync_vector.size(); + doppler_measurements_map.insert(std::pair(PRN, doppler_measurement_hz)); + } + else + { + std::cout << " . "; + } + try + { + channel_internal_queue.push(3); + } + catch (const boost::exception& e) + { + LOG(INFO) << "Exception caught while pushing to the internal queue."; + } + try + { + ch_thread.join(); + } + catch (const std::exception& e) + { + LOG(INFO) << "Exception caught while joining threads."; + } + gnss_sync_vector.clear(); +#if GNURADIO_USES_STD_POINTERS + std::dynamic_pointer_cast(source)->seek(0, 0); +#else + boost::dynamic_pointer_cast(source)->seek(0, 0); +#endif + std::cout.flush(); + } + std::cout << "]\n"; + + // report the elapsed time + end = std::chrono::system_clock::now(); + elapsed_seconds = end - start; + std::cout << "Total signal acquisition run time " + << elapsed_seconds.count() + << " [seconds]\n"; + + // 6. find TOW from SUPL assistance + double current_TOW = 0; + try + { + if (global_gps_ephemeris_map.size() > 0) + { + std::map Eph_map; + Eph_map = global_gps_ephemeris_map.get_map_copy(); + current_TOW = Eph_map.begin()->second.tow; + + time_t t = utc_time(Eph_map.begin()->second.WN, static_cast(current_TOW)); + + std::cout << "Reference Time:\n"; + std::cout << " GPS Week: " << Eph_map.begin()->second.WN << '\n'; + std::cout << " GPS TOW: " << static_cast(current_TOW) << " " << static_cast(current_TOW) * 0.08 << '\n'; + std::cout << " ~ UTC: " << ctime(&t) << '\n'; + std::cout << "Current TOW obtained from SUPL assistance = " << current_TOW << '\n'; + } + else + { + std::cout << "Unable to get Ephemeris SUPL assistance. TOW is unknown!\n"; + gflags::ShutDownCommandLineFlags(); + std::cout << "GNSS-SDR Front-end calibration program ended.\n"; + return 0; + } + } + catch (const boost::exception& e) + { + std::cout << "Exception in getting Global ephemeris map\n"; gflags::ShutDownCommandLineFlags(); std::cout << "GNSS-SDR Front-end calibration program ended.\n"; return 0; } + + // Get user position from config file (or from SUPL using GSM Cell ID) + double lat_deg = configuration->property("GNSS-SDR.init_latitude_deg", 41.0); + double lon_deg = configuration->property("GNSS-SDR.init_longitude_deg", 2.0); + double altitude_m = configuration->property("GNSS-SDR.init_altitude_m", 100); + + std::cout << "Reference location (defined in config file):\n"; + + std::cout << "Latitude=" << lat_deg << " [º]\n"; + std::cout << "Longitude=" << lon_deg << " [º]\n"; + std::cout << "Altitude=" << altitude_m << " [m]\n"; + + if (doppler_measurements_map.empty()) + { + std::cout << "Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup...\n"; + gflags::ShutDownCommandLineFlags(); + std::cout << "GNSS-SDR Front-end calibration program ended.\n"; + return 0; + } + + std::map f_if_estimation_Hz_map; + std::map f_fs_estimation_Hz_map; + std::map f_ppm_estimation_Hz_map; + + std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << "Doppler analysis results:\n"; + + std::cout << "SV ID Measured [Hz] Predicted [Hz]\n"; + + for (auto& it : doppler_measurements_map) + { + try + { + double doppler_estimated_hz; + doppler_estimated_hz = front_end_cal.estimate_doppler_from_eph(it.first, current_TOW, lat_deg, lon_deg, altitude_m); + std::cout << " " << it.first << " " << it.second << " " << doppler_estimated_hz << '\n'; + // 7. Compute front-end IF and sampling frequency estimation + // Compare with the measurements and compute clock drift using FE model + double estimated_fs_Hz; + double estimated_f_if_Hz; + double f_osc_err_ppm; + front_end_cal.GPS_L1_front_end_model_E4000(doppler_estimated_hz, it.second, fs_in_, &estimated_fs_Hz, &estimated_f_if_Hz, &f_osc_err_ppm); + + f_if_estimation_Hz_map.insert(std::pair(it.first, estimated_f_if_Hz)); + f_fs_estimation_Hz_map.insert(std::pair(it.first, estimated_fs_Hz)); + f_ppm_estimation_Hz_map.insert(std::pair(it.first, f_osc_err_ppm)); + } + catch (const std::logic_error& e) + { + std::cout << "Logic error caught: " << e.what() << '\n'; + } + catch (const boost::lock_error& e) + { + std::cout << "Exception caught while reading ephemeris\n"; + } + catch (const std::exception& ex) + { + std::cout << " " << it.first << " " << it.second << " (Eph not found)\n"; + } + } + + // FINAL FE estimations + double mean_f_if_Hz = 0; + double mean_fs_Hz = 0; + double mean_osc_err_ppm = 0; + int n_elements = f_if_estimation_Hz_map.size(); + + for (auto& it : f_if_estimation_Hz_map) + { + mean_f_if_Hz += it.second; + const auto est_fs = f_fs_estimation_Hz_map.find(it.first); + if (est_fs != f_fs_estimation_Hz_map.cend()) + { + mean_fs_Hz += est_fs->second; + } + const auto est_ppm = f_ppm_estimation_Hz_map.find(it.first); + if (est_ppm != f_ppm_estimation_Hz_map.cend()) + { + mean_osc_err_ppm += est_ppm->second; + } + } + + mean_f_if_Hz /= n_elements; + mean_fs_Hz /= n_elements; + mean_osc_err_ppm /= n_elements; + + std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << "Parameters estimation for Elonics E4000 Front-End:\n"; + + std::cout << "Sampling frequency =" << mean_fs_Hz << " [Hz]\n"; + std::cout << "IF bias present in baseband=" << mean_f_if_Hz << " [Hz]\n"; + std::cout << "Reference oscillator error =" << mean_osc_err_ppm << " [ppm]\n"; + + std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) + << "Corrected Doppler vs. Predicted\n"; + std::cout << "SV ID Corrected [Hz] Predicted [Hz]\n"; + + for (auto& it : doppler_measurements_map) + { + try + { + double doppler_estimated_hz; + doppler_estimated_hz = front_end_cal.estimate_doppler_from_eph(it.first, current_TOW, lat_deg, lon_deg, altitude_m); + std::cout << " " << it.first << " " << it.second - mean_f_if_Hz << " " << doppler_estimated_hz << '\n'; + } + catch (const std::logic_error& e) + { + std::cout << "Logic error caught: " << e.what() << '\n'; + } + catch (const boost::lock_error& e) + { + std::cout << "Exception caught while reading ephemeris\n"; + } + catch (const std::exception& ex) + { + std::cout << " " << it.first << " " << it.second - mean_f_if_Hz << " (Eph not found)\n"; + } + } } - catch (const boost::exception& e) + catch (const std::exception& e) { - std::cout << "Exception in getting Global ephemeris map\n"; + std::cerr << "Exception: " << e.what(); gflags::ShutDownCommandLineFlags(); - std::cout << "GNSS-SDR Front-end calibration program ended.\n"; - return 0; + return 1; } - - // Get user position from config file (or from SUPL using GSM Cell ID) - double lat_deg = configuration->property("GNSS-SDR.init_latitude_deg", 41.0); - double lon_deg = configuration->property("GNSS-SDR.init_longitude_deg", 2.0); - double altitude_m = configuration->property("GNSS-SDR.init_altitude_m", 100); - - std::cout << "Reference location (defined in config file):\n"; - - std::cout << "Latitude=" << lat_deg << " [º]\n"; - std::cout << "Longitude=" << lon_deg << " [º]\n"; - std::cout << "Altitude=" << altitude_m << " [m]\n"; - - if (doppler_measurements_map.empty()) + catch (...) { - std::cout << "Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup...\n"; + std::cerr << "Unknown error\n"; gflags::ShutDownCommandLineFlags(); - std::cout << "GNSS-SDR Front-end calibration program ended.\n"; - return 0; - } - - std::map f_if_estimation_Hz_map; - std::map f_fs_estimation_Hz_map; - std::map f_ppm_estimation_Hz_map; - - std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << "Doppler analysis results:\n"; - - std::cout << "SV ID Measured [Hz] Predicted [Hz]\n"; - - for (auto& it : doppler_measurements_map) - { - try - { - double doppler_estimated_hz; - doppler_estimated_hz = front_end_cal.estimate_doppler_from_eph(it.first, current_TOW, lat_deg, lon_deg, altitude_m); - std::cout << " " << it.first << " " << it.second << " " << doppler_estimated_hz << '\n'; - // 7. Compute front-end IF and sampling frequency estimation - // Compare with the measurements and compute clock drift using FE model - double estimated_fs_Hz; - double estimated_f_if_Hz; - double f_osc_err_ppm; - front_end_cal.GPS_L1_front_end_model_E4000(doppler_estimated_hz, it.second, fs_in_, &estimated_fs_Hz, &estimated_f_if_Hz, &f_osc_err_ppm); - - f_if_estimation_Hz_map.insert(std::pair(it.first, estimated_f_if_Hz)); - f_fs_estimation_Hz_map.insert(std::pair(it.first, estimated_fs_Hz)); - f_ppm_estimation_Hz_map.insert(std::pair(it.first, f_osc_err_ppm)); - } - catch (const std::logic_error& e) - { - std::cout << "Logic error caught: " << e.what() << '\n'; - } - catch (const boost::lock_error& e) - { - std::cout << "Exception caught while reading ephemeris\n"; - } - catch (const std::exception& ex) - { - std::cout << " " << it.first << " " << it.second << " (Eph not found)\n"; - } - } - - // FINAL FE estimations - double mean_f_if_Hz = 0; - double mean_fs_Hz = 0; - double mean_osc_err_ppm = 0; - int n_elements = f_if_estimation_Hz_map.size(); - - for (auto& it : f_if_estimation_Hz_map) - { - mean_f_if_Hz += it.second; - const auto est_fs = f_fs_estimation_Hz_map.find(it.first); - if (est_fs != f_fs_estimation_Hz_map.cend()) - { - mean_fs_Hz += est_fs->second; - } - const auto est_ppm = f_ppm_estimation_Hz_map.find(it.first); - if (est_ppm != f_ppm_estimation_Hz_map.cend()) - { - mean_osc_err_ppm += est_ppm->second; - } - } - - mean_f_if_Hz /= n_elements; - mean_fs_Hz /= n_elements; - mean_osc_err_ppm /= n_elements; - - std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << "Parameters estimation for Elonics E4000 Front-End:\n"; - - std::cout << "Sampling frequency =" << mean_fs_Hz << " [Hz]\n"; - std::cout << "IF bias present in baseband=" << mean_f_if_Hz << " [Hz]\n"; - std::cout << "Reference oscillator error =" << mean_osc_err_ppm << " [ppm]\n"; - - std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) - << "Corrected Doppler vs. Predicted\n"; - std::cout << "SV ID Corrected [Hz] Predicted [Hz]\n"; - - for (auto& it : doppler_measurements_map) - { - try - { - double doppler_estimated_hz; - doppler_estimated_hz = front_end_cal.estimate_doppler_from_eph(it.first, current_TOW, lat_deg, lon_deg, altitude_m); - std::cout << " " << it.first << " " << it.second - mean_f_if_Hz << " " << doppler_estimated_hz << '\n'; - } - catch (const std::logic_error& e) - { - std::cout << "Logic error caught: " << e.what() << '\n'; - } - catch (const boost::lock_error& e) - { - std::cout << "Exception caught while reading ephemeris\n"; - } - catch (const std::exception& ex) - { - std::cout << " " << it.first << " " << it.second - mean_f_if_Hz << " (Eph not found)\n"; - } + return 1; } gflags::ShutDownCommandLineFlags(); std::cout << "GNSS-SDR Front-end calibration program ended.\n"; + return 0; } diff --git a/src/utils/rinex-tools/obsdiff.cc b/src/utils/rinex-tools/obsdiff.cc index 60c74fe9f..0b156bb86 100644 --- a/src/utils/rinex-tools/obsdiff.cc +++ b/src/utils/rinex-tools/obsdiff.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include #if GNSSTK_USES_GPSTK_NAMESPACE @@ -673,7 +674,7 @@ void carrier_doppler_single_diff( { // 2. RMSE arma::vec err; - err = delta_measured_carrier_doppler_cycles; + err = std::move(delta_measured_carrier_doppler_cycles); arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); @@ -865,7 +866,7 @@ void code_pseudorange_single_diff( // 2. RMSE arma::vec err; - err = delta_measured_obs; + err = std::move(delta_measured_obs); arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); @@ -1014,7 +1015,7 @@ void coderate_phaserate_consistence( // 2. RMSE arma::vec err; - err = ratediff; + err = std::move(ratediff); arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); @@ -1098,7 +1099,7 @@ void code_phase_diff( { // 2. RMSE arma::vec err; - err = code_minus_phase; + err = std::move(code_minus_phase); arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); @@ -1727,22 +1728,42 @@ int main(int argc, char** argv) { std::cout << "Running RINEX observables difference tool...\n"; gflags::ParseCommandLineFlags(&argc, &argv, true); - if (FLAGS_single_diff) + try { - if (FLAGS_dupli_sat) + if (FLAGS_single_diff) { - RINEX_doublediff_dupli_sat(); + if (FLAGS_dupli_sat) + { + RINEX_doublediff_dupli_sat(); + } + else + { + RINEX_singlediff(); + } } else { - RINEX_singlediff(); + RINEX_doublediff(FLAGS_remove_rx_clock_error); } } - else + catch (const gnsstk::Exception& e) { - RINEX_doublediff(FLAGS_remove_rx_clock_error); + std::cerr << e; + gflags::ShutDownCommandLineFlags(); + return 1; + } + catch (const std::exception& e) + { + std::cerr << "Exception: " << e.what(); + gflags::ShutDownCommandLineFlags(); + return 1; + } + catch (...) + { + std::cerr << "Unknown error\n"; + gflags::ShutDownCommandLineFlags(); + return 1; } - gflags::ShutDownCommandLineFlags(); return 0; }