From 4de86b1f8aa30478a1f02992e8945b8be87fab33 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 3 Jul 2019 23:47:42 +0200 Subject: [PATCH 1/6] Use std::array instead of pointers and memcpy --- src/algorithms/PVT/libs/serdes_monitor_pvt.h | 2 +- src/core/monitor/serdes_gnss_synchro.h | 27 +++++++++---------- .../unit-tests/control-plane/protobuf_test.cc | 5 +++- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/algorithms/PVT/libs/serdes_monitor_pvt.h b/src/algorithms/PVT/libs/serdes_monitor_pvt.h index 7b3fdafc5..490580818 100644 --- a/src/algorithms/PVT/libs/serdes_monitor_pvt.h +++ b/src/algorithms/PVT/libs/serdes_monitor_pvt.h @@ -50,6 +50,7 @@ public: GOOGLE_PROTOBUF_VERIFY_VERSION; monitor_.New(); } + ~Serdes_Monitor_Pvt() { // google::protobuf::ShutdownProtobufLibrary(); @@ -94,7 +95,6 @@ public: return data; } - inline Monitor_Pvt readProtobuffer(const gnss_sdr::MonitorPvt& mon) //!< Deserialization { Monitor_Pvt monitor; diff --git a/src/core/monitor/serdes_gnss_synchro.h b/src/core/monitor/serdes_gnss_synchro.h index ee79ce993..3f18a3ac2 100644 --- a/src/core/monitor/serdes_gnss_synchro.h +++ b/src/core/monitor/serdes_gnss_synchro.h @@ -34,7 +34,7 @@ #include "gnss_synchro.h" #include "gnss_synchro.pb.h" // file created by Protocol Buffers at compile time -#include // for memcpy +#include #include @@ -52,6 +52,7 @@ public: GOOGLE_PROTOBUF_VERIFY_VERSION; observables.New(); } + ~Serdes_Gnss_Synchro() { google::protobuf::ShutdownProtobufLibrary(); @@ -60,21 +61,17 @@ public: inline std::string createProtobuffer(const std::vector& vgs) //!< Serialization into a string { observables.Clear(); - std::string data; for (auto gs : vgs) { gnss_sdr::GnssSynchro* obs = observables.add_observable(); - char c[2]; - c[0] = gs.System; - c[1] = '\0'; - const std::string sys(c); + char c = gs.System; + const std::string sys(1, c); - char cc[3]; + std::array cc; cc[0] = gs.Signal[0]; cc[1] = gs.Signal[1]; - cc[2] = '\0'; - const std::string sig(cc); + const std::string sig(cc.cbegin(), cc.cend()); obs->set_system(sys); obs->set_signal(sig); @@ -109,20 +106,19 @@ public: return data; } - - inline std::vector readProtobuffer(const gnss_sdr::Observables& obs) //!< Deserialization + inline std::vector readProtobuffer(const gnss_sdr::Observables& obs) const //!< Deserialization { std::vector vgs; vgs.reserve(obs.observable_size()); - for (int i = 0; i < obs.observable_size(); ++i) { const gnss_sdr::GnssSynchro& gs_read = obs.observable(i); Gnss_Synchro gs = Gnss_Synchro(); const std::string& sys = gs_read.system(); - gs.System = *sys.c_str(); - const std::string& sig = gs_read.signal(); - std::memcpy(static_cast(gs.Signal), sig.c_str(), 3); + gs.System = gs_read.system()[0]; + gs.Signal[0] = gs_read.signal()[0]; + gs.Signal[1] = gs_read.signal()[1]; + gs.Signal[2] = '\0'; gs.PRN = gs_read.prn(); gs.Channel_ID = gs_read.channel_id(); @@ -153,6 +149,7 @@ public: } return vgs; } + private: gnss_sdr::Observables observables; }; diff --git a/src/tests/unit-tests/control-plane/protobuf_test.cc b/src/tests/unit-tests/control-plane/protobuf_test.cc index 95d83a519..9bece14eb 100644 --- a/src/tests/unit-tests/control-plane/protobuf_test.cc +++ b/src/tests/unit-tests/control-plane/protobuf_test.cc @@ -95,12 +95,15 @@ TEST(Protobuf, Works) Gnss_Synchro gs_read = vgs_read[0]; uint32_t prn_read = gs_read.PRN; uint32_t prn_read2 = vgs_read[1].PRN; + std::string system_read(1, gs_read.System); + std::string signal_read(gs_read.Signal); // or without the need of gnss_synchro: int obs_size = obs.observable_size(); uint32_t prn_read3 = obs.observable(0).prn(); - EXPECT_EQ(prn_true, prn_read); + EXPECT_EQ(sig, signal_read); + EXPECT_EQ(sys, system_read); EXPECT_EQ(prn_true2, prn_read2); EXPECT_EQ(prn_true, prn_read3); EXPECT_EQ(2, obs_size); From 9ba6f4d6709b025e63178c6a7b76654131a5d03a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 4 Jul 2019 00:00:29 +0200 Subject: [PATCH 2/6] Make header file more readable. Remove unused private method interpolate_data() --- .../gnuradio_blocks/hybrid_observables_gs.h | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.h b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.h index b40beada9..f21510254 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.h +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.h @@ -34,7 +34,7 @@ #ifndef GNSS_SDR_HYBRID_OBSERVABLES_GS_H #define GNSS_SDR_HYBRID_OBSERVABLES_GS_H -#include // for boost::curcular_buffer +#include // for boost::circular_buffer #include // for boost::shared_ptr #include // for block #include // for gr_vector_int @@ -50,8 +50,12 @@ class Gnss_circular_deque; using hybrid_observables_gs_sptr = boost::shared_ptr; -hybrid_observables_gs_sptr -hybrid_observables_gs_make(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, bool dump_mat, std::string dump_filename); +hybrid_observables_gs_sptr hybrid_observables_gs_make( + unsigned int nchannels_in, + unsigned int nchannels_out, + bool dump, + bool dump_mat, + std::string dump_filename); /*! * \brief This class implements a block that computes observables @@ -60,38 +64,44 @@ class hybrid_observables_gs : public gr::block { public: ~hybrid_observables_gs(); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); int general_work(int noutput_items, gr_vector_int& ninput_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items); - void forecast(int noutput_items, gr_vector_int& ninput_items_required); private: - friend hybrid_observables_gs_sptr - hybrid_observables_gs_make(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, bool dump_mat, std::string dump_filename); - hybrid_observables_gs(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, bool dump_mat, std::string dump_filename); - void msg_handler_pvt_to_observables(const pmt::pmt_t& msg); - bool interpolate_data(Gnss_Synchro& out, const uint32_t& ch, const double& ti); - bool interp_trk_obs(Gnss_Synchro& interpolated_obs, const uint32_t& ch, const uint64_t& rx_clock); - double compute_T_rx_s(const Gnss_Synchro& a); - void compute_pranges(std::vector& data); - void update_TOW(const std::vector& data); - int32_t save_matfile(); + friend hybrid_observables_gs_sptr hybrid_observables_gs_make( + uint32_t nchannels_in, + uint32_t nchannels_out, + bool dump, + bool dump_mat, + std::string dump_filename); - //time history - boost::circular_buffer d_Rx_clock_buffer; - //Tracking observable history - Gnss_circular_deque* d_gnss_synchro_history; - //rx time follow GPST - bool T_rx_TOW_set; + hybrid_observables_gs( + uint32_t nchannels_in, + uint32_t nchannels_out, + bool dump, + bool dump_mat, + std::string dump_filename); + + bool T_rx_TOW_set; // rx time follow GPST + bool d_dump; + bool d_dump_mat; uint32_t T_rx_TOW_ms; uint32_t T_rx_remnant_to_20ms; uint32_t T_rx_step_ms; - double T_rx_offset_ms; - bool d_dump; - bool d_dump_mat; uint32_t d_nchannels_in; uint32_t d_nchannels_out; + double T_rx_offset_ms; std::string d_dump_filename; std::ofstream d_dump_file; + boost::circular_buffer d_Rx_clock_buffer; // time history + Gnss_circular_deque* d_gnss_synchro_history; // Tracking observable history + void msg_handler_pvt_to_observables(const pmt::pmt_t& msg); + double compute_T_rx_s(const Gnss_Synchro& a); + bool interp_trk_obs(Gnss_Synchro& interpolated_obs, const uint32_t& ch, const uint64_t& rx_clock); + void update_TOW(const std::vector& data); + void compute_pranges(std::vector& data); + int32_t save_matfile(); }; #endif From fd9edf248639ec468a46e33998f3b3d4a716b1b2 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 4 Jul 2019 08:06:02 +0200 Subject: [PATCH 3/6] Remove duplicate character if GROSMOSDR_PKG_VERSION contains a v --- cmake/Modules/FindGROSMOSDR.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/Modules/FindGROSMOSDR.cmake b/cmake/Modules/FindGROSMOSDR.cmake index 78fb58a31..175ef6c58 100644 --- a/cmake/Modules/FindGROSMOSDR.cmake +++ b/cmake/Modules/FindGROSMOSDR.cmake @@ -101,6 +101,9 @@ find_package_handle_standard_args(GROSMOSDR DEFAULT_MSG GROSMOSDR_LIBRARIES GROS if(GROSMOSDR_PKG_VERSION) set(GROSMOSDR_VERSION ${GROSMOSDR_PKG_VERSION}) + set(KK "v1.2.3") + string(REGEX REPLACE "^v" "" KK_AUX KK) + message(STATUS "++++++++++++++++++++${KK_AUX}") endif() set_package_properties(GROSMOSDR PROPERTIES From 2d276526a81f5b25e93a19e512548243e0709860 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 4 Jul 2019 08:11:25 +0200 Subject: [PATCH 4/6] Remove duplicate character if GROSMOSDR_PKG_VERSION contains a v (Fix) --- cmake/Modules/FindGROSMOSDR.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/FindGROSMOSDR.cmake b/cmake/Modules/FindGROSMOSDR.cmake index 175ef6c58..ce2e655b5 100644 --- a/cmake/Modules/FindGROSMOSDR.cmake +++ b/cmake/Modules/FindGROSMOSDR.cmake @@ -100,10 +100,8 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GROSMOSDR DEFAULT_MSG GROSMOSDR_LIBRARIES GROSMOSDR_INCLUDE_DIR) if(GROSMOSDR_PKG_VERSION) - set(GROSMOSDR_VERSION ${GROSMOSDR_PKG_VERSION}) - set(KK "v1.2.3") - string(REGEX REPLACE "^v" "" KK_AUX KK) - message(STATUS "++++++++++++++++++++${KK_AUX}") + set(GROSMOSDR_VERSION_AUX ${GROSMOSDR_PKG_VERSION}) + string(REGEX REPLACE "^v" "" GROSMOSDR_VERSION ${GROSMOSDR_VERSION_AUX}) endif() set_package_properties(GROSMOSDR PROPERTIES From ad389cf2677c3174a2efae966a11b97dc58a08b5 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 4 Jul 2019 08:24:48 +0200 Subject: [PATCH 5/6] Remove unused variable --- src/core/monitor/serdes_gnss_synchro.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/monitor/serdes_gnss_synchro.h b/src/core/monitor/serdes_gnss_synchro.h index 3f18a3ac2..0e63aed6c 100644 --- a/src/core/monitor/serdes_gnss_synchro.h +++ b/src/core/monitor/serdes_gnss_synchro.h @@ -114,7 +114,6 @@ public: { const gnss_sdr::GnssSynchro& gs_read = obs.observable(i); Gnss_Synchro gs = Gnss_Synchro(); - const std::string& sys = gs_read.system(); gs.System = gs_read.system()[0]; gs.Signal[0] = gs_read.signal()[0]; gs.Signal[1] = gs_read.signal()[1]; From 620191f818f5500f87c384ec55613d7593b6a0a2 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 4 Jul 2019 08:52:06 +0200 Subject: [PATCH 6/6] Fix warning (unused variable) --- src/tests/unit-tests/control-plane/protobuf_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/unit-tests/control-plane/protobuf_test.cc b/src/tests/unit-tests/control-plane/protobuf_test.cc index 9bece14eb..671150717 100644 --- a/src/tests/unit-tests/control-plane/protobuf_test.cc +++ b/src/tests/unit-tests/control-plane/protobuf_test.cc @@ -106,5 +106,6 @@ TEST(Protobuf, Works) EXPECT_EQ(sys, system_read); EXPECT_EQ(prn_true2, prn_read2); EXPECT_EQ(prn_true, prn_read3); + EXPECT_EQ(prn_read, prn_read3); EXPECT_EQ(2, obs_size); }