From 79ae0a6c9d21f133da76c73548e5228a6b61d232 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 6 Oct 2018 20:10:16 +0200 Subject: [PATCH] Fix writing of XML files. Previously, the tag boost_serialization was not closed, which caused a failure when trying to read those XML files with Boost >= 1.66 --- src/algorithms/PVT/adapters/rtklib_pvt.cc | 4 +-- .../PVT/gnuradio_blocks/rtklib_pvt_cc.cc | 29 ++++++++++--------- src/core/libs/gnss_sdr_supl_client.cc | 22 ++++---------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc index dc8cf894a..13bcd6faf 100644 --- a/src/algorithms/PVT/adapters/rtklib_pvt.cc +++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc @@ -506,12 +506,12 @@ bool RtklibPvt::save_assistance_to_XML() if (eph_map.empty() == false) { + std::ofstream ofs; try { std::ofstream ofs(eph_xml_filename_.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", eph_map); - ofs.close(); LOG(INFO) << "Saved GPS L1 Ephemeris map data"; } catch (const std::exception& e) @@ -519,13 +519,13 @@ bool RtklibPvt::save_assistance_to_XML() LOG(WARNING) << e.what(); return false; } - return true; // return variable (true == succeeded) } else { LOG(WARNING) << "Failed to save Ephemeris, map is empty"; return false; } + return true; // return variable (true == succeeded) } diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc index 3a1228ec4..2f9bb177d 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc @@ -400,12 +400,12 @@ rtklib_pvt_cc::~rtklib_pvt_cc() if (d_ls_pvt->gps_cnav_ephemeris_map.empty() == false) { + std::ofstream ofs; try { - std::ofstream ofs(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); + ofs.open(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", d_ls_pvt->gps_cnav_ephemeris_map); - ofs.close(); LOG(INFO) << "Saved GPS L2CM or L5 Ephemeris map data"; } catch (std::exception& e) @@ -423,12 +423,12 @@ rtklib_pvt_cc::~rtklib_pvt_cc() if (d_ls_pvt->gps_ephemeris_map.empty() == false) { + std::ofstream ofs; try { - std::ofstream ofs(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); + ofs.open(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", d_ls_pvt->gps_ephemeris_map); - ofs.close(); LOG(INFO) << "Saved GPS L1 CA Ephemeris map data"; } catch (const std::exception& e) @@ -446,12 +446,12 @@ rtklib_pvt_cc::~rtklib_pvt_cc() if (d_ls_pvt->galileo_ephemeris_map.empty() == false) { + std::ofstream ofs; try { - std::ofstream ofs(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); + ofs.open(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", d_ls_pvt->galileo_ephemeris_map); - ofs.close(); LOG(INFO) << "Saved Galileo E1 Ephemeris map data"; } catch (const std::exception& e) @@ -469,12 +469,12 @@ rtklib_pvt_cc::~rtklib_pvt_cc() if (d_ls_pvt->glonass_gnav_ephemeris_map.empty() == false) { + std::ofstream ofs; try { - std::ofstream ofs(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); + ofs.open(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", d_ls_pvt->glonass_gnav_ephemeris_map); - ofs.close(); LOG(INFO) << "Saved GLONASS GNAV Ephemeris map data"; } catch (std::exception& e) @@ -515,12 +515,12 @@ bool rtklib_pvt_cc::save_gnss_synchro_map_xml(const std::string file_name) { if (gnss_observables_map.empty() == false) { + std::ofstream ofs; try { - std::ofstream ofs(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); + ofs.open(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_gnss_synchro_map", gnss_observables_map); - ofs.close(); LOG(INFO) << "Saved gnss_sychro map data"; } catch (std::exception& e) @@ -537,17 +537,17 @@ bool rtklib_pvt_cc::save_gnss_synchro_map_xml(const std::string file_name) } } + bool rtklib_pvt_cc::load_gnss_synchro_map_xml(const std::string file_name) { - //load from xml (boost serialize) + // load from xml (boost serialize) + std::ifstream ifs; try { - std::ifstream ifs(file_name.c_str(), std::ifstream::binary | std::ifstream::in); + ifs.open(file_name.c_str(), std::ifstream::binary | std::ifstream::in); boost::archive::xml_iarchive xml(ifs); gnss_observables_map.clear(); xml >> boost::serialization::make_nvp("GNSS-SDR_gnss_synchro_map", gnss_observables_map); - ifs.close(); - return true; //std::cout << "Loaded gnss_synchro map data with " << gnss_synchro_map.size() << " pseudoranges" << std::endl; } catch (std::exception& e) @@ -555,6 +555,7 @@ bool rtklib_pvt_cc::load_gnss_synchro_map_xml(const std::string file_name) std::cout << e.what() << "File: " << file_name; return false; } + return true; } diff --git a/src/core/libs/gnss_sdr_supl_client.cc b/src/core/libs/gnss_sdr_supl_client.cc index fdd08b9a9..4d3668adc 100644 --- a/src/core/libs/gnss_sdr_supl_client.cc +++ b/src/core/libs/gnss_sdr_supl_client.cc @@ -384,7 +384,6 @@ bool gnss_sdr_supl_client::load_ephemeris_xml(const std::string file_name) LOG(WARNING) << e.what() << "File: " << file_name; return false; } - ifs.close(); return true; } @@ -399,7 +398,6 @@ bool gnss_sdr_supl_client::save_ephemeris_map_xml(const std::string file_name, s ofs.open(file_name.c_str(), std::ofstream::trunc | std::ofstream::out); boost::archive::xml_oarchive xml(ofs); xml << boost::serialization::make_nvp("GNSS-SDR_ephemeris_map", eph_map); - LOG(INFO) << "Saved Ephemeris map data"; } catch (std::exception& e) @@ -407,14 +405,13 @@ bool gnss_sdr_supl_client::save_ephemeris_map_xml(const std::string file_name, s LOG(WARNING) << e.what(); return false; } - ofs.close(); - return true; } else { LOG(WARNING) << "Failed to save Ephemeris, map is empty"; return false; } + return true; } @@ -426,7 +423,6 @@ bool gnss_sdr_supl_client::load_utc_xml(const std::string file_name) ifs.open(file_name.c_str(), std::ifstream::binary | std::ifstream::in); boost::archive::xml_iarchive xml(ifs); xml >> boost::serialization::make_nvp("GNSS-SDR_utc_map", this->gps_utc); - LOG(INFO) << "Loaded UTC model data"; } catch (std::exception& e) @@ -434,7 +430,6 @@ bool gnss_sdr_supl_client::load_utc_xml(const std::string file_name) LOG(WARNING) << e.what() << "File: " << file_name; return false; } - ifs.close(); return true; } @@ -456,14 +451,13 @@ bool gnss_sdr_supl_client::save_utc_map_xml(const std::string file_name, std::ma LOG(WARNING) << e.what(); return false; } - ofs.close(); - return true; } else { LOG(WARNING) << "Failed to save UTC model, map is empty"; return false; } + return true; } @@ -482,7 +476,6 @@ bool gnss_sdr_supl_client::load_iono_xml(const std::string file_name) LOG(WARNING) << e.what() << "File: " << file_name; return false; } - ifs.close(); return true; } @@ -504,14 +497,13 @@ bool gnss_sdr_supl_client::save_iono_map_xml(const std::string file_name, std::m LOG(WARNING) << e.what(); return false; } - ofs.close(); - return true; } else { LOG(WARNING) << "Failed to save IONO model, map is empty"; return false; } + return true; } @@ -530,7 +522,6 @@ bool gnss_sdr_supl_client::load_ref_time_xml(const std::string file_name) LOG(WARNING) << e.what() << "File: " << file_name; return false; } - ifs.close(); return true; } @@ -553,14 +544,13 @@ bool gnss_sdr_supl_client::save_ref_time_map_xml(const std::string file_name, st LOG(WARNING) << e.what(); return false; } - ofs.close(); - return true; } else { LOG(WARNING) << "Failed to save Ref Time, map is empty"; return false; } + return true; } @@ -579,7 +569,6 @@ bool gnss_sdr_supl_client::load_ref_location_xml(const std::string file_name) LOG(WARNING) << e.what() << "File: " << file_name; return false; } - ifs.close(); return true; } @@ -601,12 +590,11 @@ bool gnss_sdr_supl_client::save_ref_location_map_xml(const std::string file_name LOG(WARNING) << e.what(); return false; } - ofs.close(); - return true; } else { LOG(WARNING) << "Failed to save Ref Location, map is empty"; return false; } + return true; }