1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-11-13 05:37:20 +00:00

Redesign of pointer management

Avoid indirection caused by passing shared_ptr by reference

The block factory does not have responsability on the lifetime of their inputs

Define std::make_unique when using C++11 and make use of it

Printers are turned into unique_ptr to express ownership

Printers do not participate on the lifelime of the data, so they take const raw pointers

Modernize tests code
This commit is contained in:
Carles Fernandez
2020-06-18 11:49:28 +02:00
parent 7307e82d48
commit 81af1a531b
135 changed files with 1295 additions and 1302 deletions

View File

@@ -35,6 +35,7 @@
#include "glonass_gnav_utc_model.h"
#include "gnss_frequencies.h"
#include "gnss_sdr_create_directory.h"
#include "gnss_sdr_make_unique.h"
#include "gps_almanac.h"
#include "gps_cnav_ephemeris.h"
#include "gps_cnav_iono.h"
@@ -137,13 +138,11 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
mapStringValues_["B2"] = evBDS_B2;
mapStringValues_["B3"] = evBDS_B3;
initial_carrier_phase_offset_estimation_rads = std::vector<double>(nchannels, 0.0);
channel_initialized = std::vector<bool>(nchannels, false);
max_obs_block_rx_clock_offset_ms = conf_.max_obs_block_rx_clock_offset_ms;
d_output_rate_ms = conf_.output_rate_ms;
d_display_rate_ms = conf_.display_rate_ms;
d_report_rate_ms = 1000; // report every second PVT to gnss_synchro
@@ -211,7 +210,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
}
if (d_kml_output_enabled)
{
d_kml_dump = std::make_shared<Kml_Printer>(conf_.kml_output_path);
d_kml_dump = std::make_unique<Kml_Printer>(conf_.kml_output_path);
d_kml_dump->set_headers(kml_dump_filename);
}
else
@@ -230,7 +229,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
}
if (d_gpx_output_enabled)
{
d_gpx_dump = std::make_shared<Gpx_Printer>(conf_.gpx_output_path);
d_gpx_dump = std::make_unique<Gpx_Printer>(conf_.gpx_output_path);
d_gpx_dump->set_headers(gpx_dump_filename);
}
else
@@ -249,7 +248,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
}
if (d_geojson_output_enabled)
{
d_geojson_printer = std::make_shared<GeoJSON_Printer>(conf_.geojson_output_path);
d_geojson_printer = std::make_unique<GeoJSON_Printer>(conf_.geojson_output_path);
d_geojson_printer->set_headers(geojson_dump_filename);
}
else
@@ -267,7 +266,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
if (d_nmea_output_file_enabled)
{
d_nmea_printer = std::make_shared<Nmea_Printer>(conf_.nmea_dump_filename, conf_.nmea_output_file_enabled, conf_.flag_nmea_tty_port, conf_.nmea_dump_devname, conf_.nmea_output_file_path);
d_nmea_printer = std::make_unique<Nmea_Printer>(conf_.nmea_dump_filename, conf_.nmea_output_file_enabled, conf_.flag_nmea_tty_port, conf_.nmea_dump_devname, conf_.nmea_output_file_path);
}
else
{
@@ -279,7 +278,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
rtcm_dump_filename = d_dump_filename;
if (conf_.flag_rtcm_server or conf_.flag_rtcm_tty_port or conf_.rtcm_output_file_enabled)
{
d_rtcm_printer = std::make_shared<Rtcm_Printer>(rtcm_dump_filename, conf_.rtcm_output_file_enabled, conf_.flag_rtcm_server, conf_.flag_rtcm_tty_port, conf_.rtcm_tcp_port, conf_.rtcm_station_id, conf_.rtcm_dump_devname, true, conf_.rtcm_output_file_path);
d_rtcm_printer = std::make_unique<Rtcm_Printer>(rtcm_dump_filename, conf_.rtcm_output_file_enabled, conf_.flag_rtcm_server, conf_.flag_rtcm_tty_port, conf_.rtcm_tcp_port, conf_.rtcm_station_id, conf_.rtcm_dump_devname, true, conf_.rtcm_output_file_path);
std::map<int, int> rtcm_msg_rate_ms = conf_.rtcm_msg_rate_ms;
if (rtcm_msg_rate_ms.find(1019) != rtcm_msg_rate_ms.end())
{
@@ -355,7 +354,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
d_rinex_version = conf_.rinex_version;
if (b_rinex_output_enabled)
{
rp = std::make_shared<Rinex_Printer>(d_rinex_version, conf_.rinex_output_path, conf_.rinex_name);
rp = std::make_unique<Rinex_Printer>(d_rinex_version, conf_.rinex_output_path, conf_.rinex_name);
rp->set_pre_2009_file(conf_.pre_2009_file);
}
else
@@ -413,7 +412,7 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
std::sort(udp_addr_vec.begin(), udp_addr_vec.end());
udp_addr_vec.erase(std::unique(udp_addr_vec.begin(), udp_addr_vec.end()), udp_addr_vec.end());
udp_sink_ptr = std::unique_ptr<Monitor_Pvt_Udp_Sink>(new Monitor_Pvt_Udp_Sink(udp_addr_vec, conf_.udp_port, conf_.protobuf_enabled));
udp_sink_ptr = std::make_unique<Monitor_Pvt_Udp_Sink>(udp_addr_vec, conf_.udp_port, conf_.protobuf_enabled);
}
else
{
@@ -2283,28 +2282,28 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item
{
if (current_RX_time_ms % d_kml_rate_ms == 0)
{
d_kml_dump->print_position(d_user_pvt_solver, false);
d_kml_dump->print_position(d_user_pvt_solver.get(), false);
}
}
if (d_gpx_output_enabled)
{
if (current_RX_time_ms % d_gpx_rate_ms == 0)
{
d_gpx_dump->print_position(d_user_pvt_solver, false);
d_gpx_dump->print_position(d_user_pvt_solver.get(), false);
}
}
if (d_geojson_output_enabled)
{
if (current_RX_time_ms % d_geojson_rate_ms == 0)
{
d_geojson_printer->print_position(d_user_pvt_solver, false);
d_geojson_printer->print_position(d_user_pvt_solver.get(), false);
}
}
if (d_nmea_output_file_enabled)
{
if (current_RX_time_ms % d_nmea_rate_ms == 0)
{
d_nmea_printer->Print_Nmea_Line(d_user_pvt_solver, false);
d_nmea_printer->Print_Nmea_Line(d_user_pvt_solver.get(), false);
}
}

View File

@@ -191,12 +191,12 @@ private:
int32_t d_display_rate_ms;
int32_t d_report_rate_ms;
std::shared_ptr<Rinex_Printer> rp;
std::shared_ptr<Kml_Printer> d_kml_dump;
std::shared_ptr<Gpx_Printer> d_gpx_dump;
std::shared_ptr<Nmea_Printer> d_nmea_printer;
std::shared_ptr<GeoJSON_Printer> d_geojson_printer;
std::shared_ptr<Rtcm_Printer> d_rtcm_printer;
std::unique_ptr<Rinex_Printer> rp;
std::unique_ptr<Kml_Printer> d_kml_dump;
std::unique_ptr<Gpx_Printer> d_gpx_dump;
std::unique_ptr<Nmea_Printer> d_nmea_printer;
std::unique_ptr<GeoJSON_Printer> d_geojson_printer;
std::unique_ptr<Rtcm_Printer> d_rtcm_printer;
double d_rx_time;
bool d_geojson_output_enabled;

View File

@@ -176,25 +176,23 @@ bool GeoJSON_Printer::set_headers(const std::string& filename, bool time_tag_nam
}
bool GeoJSON_Printer::print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values)
bool GeoJSON_Printer::print_position(const Pvt_Solution* position, bool print_average_values)
{
double latitude;
double longitude;
double height;
const std::shared_ptr<Pvt_Solution>& position_ = position;
if (print_average_values == false)
{
latitude = position_->get_latitude();
longitude = position_->get_longitude();
height = position_->get_height();
latitude = position->get_latitude();
longitude = position->get_longitude();
height = position->get_height();
}
else
{
latitude = position_->get_avg_latitude();
longitude = position_->get_avg_longitude();
height = position_->get_avg_height();
latitude = position->get_avg_latitude();
longitude = position->get_avg_longitude();
height = position->get_avg_height();
}
if (geojson_file.is_open())

View File

@@ -40,7 +40,7 @@ public:
explicit GeoJSON_Printer(const std::string& base_path = ".");
~GeoJSON_Printer();
bool set_headers(const 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 Pvt_Solution* position, bool print_average_values);
bool close_file();
private:

View File

@@ -20,7 +20,7 @@
#include "gpx_printer.h"
#include "rtklib_solver.h"
#include "pvt_solution.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <glog/logging.h>
#include <ctime> // for tm
@@ -162,22 +162,21 @@ bool Gpx_Printer::set_headers(const std::string& filename, bool time_tag_name)
}
bool Gpx_Printer::print_position(const std::shared_ptr<Rtklib_Solver>& position, bool print_average_values)
bool Gpx_Printer::print_position(const Pvt_Solution* position, bool print_average_values)
{
double latitude;
double longitude;
double height;
positions_printed = true;
const std::shared_ptr<Rtklib_Solver>& position_ = position;
double speed_over_ground = position_->get_speed_over_ground(); // expressed in m/s
double course_over_ground = position_->get_course_over_ground(); // expressed in deg
double speed_over_ground = position->get_speed_over_ground(); // expressed in m/s
double course_over_ground = position->get_course_over_ground(); // expressed in deg
double hdop = position_->get_hdop();
double vdop = position_->get_vdop();
double pdop = position_->get_pdop();
std::string utc_time = to_iso_extended_string(position_->get_position_UTC_time());
double hdop = position->get_hdop();
double vdop = position->get_vdop();
double pdop = position->get_pdop();
std::string utc_time = to_iso_extended_string(position->get_position_UTC_time());
if (utc_time.length() < 23)
{
utc_time += ".";
@@ -187,15 +186,15 @@ bool Gpx_Printer::print_position(const std::shared_ptr<Rtklib_Solver>& position,
if (print_average_values == false)
{
latitude = position_->get_latitude();
longitude = position_->get_longitude();
height = position_->get_height();
latitude = position->get_latitude();
longitude = position->get_longitude();
height = position->get_height();
}
else
{
latitude = position_->get_avg_latitude();
longitude = position_->get_avg_longitude();
height = position_->get_avg_height();
latitude = position->get_avg_latitude();
longitude = position->get_avg_longitude();
height = position->get_avg_height();
}
if (gpx_file.is_open())

View File

@@ -27,7 +27,7 @@
#include <memory>
#include <string>
class Rtklib_Solver;
class Pvt_Solution;
/*!
* \brief Prints PVT information to GPX format file
@@ -40,7 +40,7 @@ public:
explicit Gpx_Printer(const std::string& base_path = ".");
~Gpx_Printer();
bool set_headers(const std::string& filename, bool time_tag_name = true);
bool print_position(const std::shared_ptr<Rtklib_Solver>& position, bool print_average_values);
bool print_position(const Pvt_Solution* position, bool print_average_values);
bool close_file();
private:

View File

@@ -20,7 +20,7 @@
*/
#include "kml_printer.h"
#include "rtklib_solver.h"
#include "pvt_solution.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <glog/logging.h>
#include <cstdlib> // for mkstemp
@@ -231,7 +231,7 @@ bool Kml_Printer::set_headers(const std::string& filename, bool time_tag_name)
}
bool Kml_Printer::print_position(const std::shared_ptr<Rtklib_Solver>& position, bool print_average_values)
bool Kml_Printer::print_position(const Pvt_Solution* position, bool print_average_values)
{
double latitude;
double longitude;
@@ -239,15 +239,13 @@ bool Kml_Printer::print_position(const std::shared_ptr<Rtklib_Solver>& position,
positions_printed = true;
const std::shared_ptr<Rtklib_Solver>& position_ = position;
double speed_over_ground = position->get_speed_over_ground(); // expressed in m/s
double course_over_ground = position->get_course_over_ground(); // expressed in deg
double speed_over_ground = position_->get_speed_over_ground(); // expressed in m/s
double course_over_ground = position_->get_course_over_ground(); // expressed in deg
double hdop = position_->get_hdop();
double vdop = position_->get_vdop();
double pdop = position_->get_pdop();
std::string utc_time = to_iso_extended_string(position_->get_position_UTC_time());
double hdop = position->get_hdop();
double vdop = position->get_vdop();
double pdop = position->get_pdop();
std::string utc_time = to_iso_extended_string(position->get_position_UTC_time());
if (utc_time.length() < 23)
{
utc_time += ".";
@@ -257,15 +255,15 @@ bool Kml_Printer::print_position(const std::shared_ptr<Rtklib_Solver>& position,
if (print_average_values == false)
{
latitude = position_->get_latitude();
longitude = position_->get_longitude();
height = position_->get_height();
latitude = position->get_latitude();
longitude = position->get_longitude();
height = position->get_height();
}
else
{
latitude = position_->get_avg_latitude();
longitude = position_->get_avg_longitude();
height = position_->get_avg_height();
latitude = position->get_avg_latitude();
longitude = position->get_avg_longitude();
height = position->get_avg_height();
}
if (kml_file.is_open() && tmp_file.is_open())

View File

@@ -26,7 +26,7 @@
#include <memory> // for shared_ptr
#include <string>
class Rtklib_Solver;
class Pvt_Solution;
/*!
* \brief Prints PVT information to OGC KML format file (can be viewed with Google Earth)
@@ -39,7 +39,7 @@ public:
explicit Kml_Printer(const std::string& base_path = std::string("."));
~Kml_Printer();
bool set_headers(const std::string& filename, bool time_tag_name = true);
bool print_position(const std::shared_ptr<Rtklib_Solver>& position, bool print_average_values);
bool print_position(const Pvt_Solution* position, bool print_average_values);
bool close_file();
private:

View File

@@ -22,6 +22,7 @@
#include <boost/archive/binary_oarchive.hpp>
#include <iostream>
#include <sstream>
#include <utility>
Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(const std::vector<std::string>& addresses, const uint16_t& port, bool protobuf_enabled) : socket{io_context}
@@ -40,19 +41,20 @@ Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(const std::vector<std::string>& addre
}
bool Monitor_Pvt_Udp_Sink::write_monitor_pvt(const std::shared_ptr<Monitor_Pvt>& monitor_pvt)
bool Monitor_Pvt_Udp_Sink::write_monitor_pvt(std::shared_ptr<Monitor_Pvt> monitor_pvt)
{
monitor_pvt_ = std::move(monitor_pvt);
std::string outbound_data;
if (use_protobuf == false)
{
std::ostringstream archive_stream;
boost::archive::binary_oarchive oa{archive_stream};
oa << *monitor_pvt.get();
oa << *monitor_pvt_.get();
outbound_data = archive_stream.str();
}
else
{
outbound_data = serdes.createProtobuffer(monitor_pvt);
outbound_data = serdes.createProtobuffer(monitor_pvt_);
}
for (const auto& endpoint : endpoints)

View File

@@ -38,7 +38,7 @@ class Monitor_Pvt_Udp_Sink
{
public:
Monitor_Pvt_Udp_Sink(const std::vector<std::string>& addresses, const uint16_t& port, bool protobuf_enabled);
bool write_monitor_pvt(const std::shared_ptr<Monitor_Pvt>& monitor_pvt);
bool write_monitor_pvt(std::shared_ptr<Monitor_Pvt> monitor_pvt);
private:
b_io_context io_context;
@@ -46,6 +46,7 @@ private:
boost::system::error_code error;
std::vector<boost::asio::ip::udp::endpoint> endpoints;
Serdes_Monitor_Pvt serdes;
std::shared_ptr<Monitor_Pvt> monitor_pvt_;
bool use_protobuf;
};

View File

@@ -119,6 +119,7 @@ Nmea_Printer::Nmea_Printer(const std::string& filename, bool flag_nmea_output_fi
nmea_dev_descriptor = -1;
}
print_avg_pos = false;
d_PVT_data = nullptr;
}
@@ -213,7 +214,7 @@ void Nmea_Printer::close_serial()
}
bool Nmea_Printer::Print_Nmea_Line(const std::shared_ptr<Rtklib_Solver>& pvt_data, bool print_average_values)
bool Nmea_Printer::Print_Nmea_Line(const Rtklib_Solver* pvt_data, bool print_average_values)
{
std::string GPRMC;
std::string GPGGA;

View File

@@ -49,7 +49,7 @@ public:
/*!
* \brief Print NMEA PVT and satellite info to the initialized device
*/
bool Print_Nmea_Line(const std::shared_ptr<Rtklib_Solver>& pvt_data, bool print_average_values);
bool Print_Nmea_Line(const Rtklib_Solver* pvt_data, bool print_average_values);
/*!
* \brief Default destructor.
@@ -62,7 +62,7 @@ private:
std::ofstream nmea_file_descriptor; // Output file stream for NMEA log file
std::string nmea_devname;
int nmea_dev_descriptor; // NMEA serial device descriptor (i.e. COM port)
std::shared_ptr<Rtklib_Solver> d_PVT_data;
const Rtklib_Solver* d_PVT_data;
int init_serial(const std::string& serial_device); // serial port control
void close_serial();
std::string get_GPGGA(); // fix data

View File

@@ -38,6 +38,7 @@ class Pvt_Solution
{
public:
Pvt_Solution();
virtual ~Pvt_Solution() = default;
void set_pre_2009_file(bool pre_2009_file); //!< Flag for the week rollover computation in post processing mode for signals older than 2009
double get_time_offset_s() const; //!< Get RX time offset [s]
void set_time_offset_s(double offset); //!< Set RX time offset [s]
@@ -123,6 +124,11 @@ public:
*/
int tropo(double *ddr_m, double sinel, double hsta_km, double p_mb, double t_kel, double hum, double hp_km, double htkel_km, double hhum_km);
virtual double get_hdop() const = 0;
virtual double get_vdop() const = 0;
virtual double get_pdop() const = 0;
virtual double get_gdop() const = 0;
protected:
bool d_pre_2009_file; // Flag to correct week rollover in post processing mode for signals older than 2009
private:

View File

@@ -75,10 +75,10 @@ public:
sol_t pvt_sol{};
std::array<ssat_t, MAXSAT> pvt_ssat{};
double get_hdop() const;
double get_vdop() const;
double get_pdop() const;
double get_gdop() const;
double get_hdop() const override;
double get_vdop() const override;
double get_pdop() const override;
double get_gdop() const override;
Monitor_Pvt get_monitor_pvt() const;
std::map<int, Galileo_Ephemeris> galileo_ephemeris_map; //!< Map storing new Galileo_Ephemeris