From 64b0fbe70db58d42d456125b66c856e5659ecc8a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 24 Sep 2021 17:25:59 +0200 Subject: [PATCH] Move constructor to the header file to make portability easier Avoid magic numbers Fix clang-tidy warning. Was: performance-inefficient-string-concatenation --- src/core/libs/CMakeLists.txt | 10 +-- src/core/libs/galileo_e6_has_msg_receiver.cc | 91 ++++---------------- src/core/libs/galileo_e6_has_msg_receiver.h | 84 ++++++++++++++---- 3 files changed, 92 insertions(+), 93 deletions(-) diff --git a/src/core/libs/CMakeLists.txt b/src/core/libs/CMakeLists.txt index cc95de249..5de16002d 100644 --- a/src/core/libs/CMakeLists.txt +++ b/src/core/libs/CMakeLists.txt @@ -85,18 +85,18 @@ target_link_libraries(core_libs Gnuradio::runtime Gnuradio::pmt protobuf::libprotobuf + algorithms_libs core_libs_supl core_system_parameters pvt_libs PRIVATE - algorithms_libs Boost::serialization Gflags::gflags Glog::glog Pugixml::pugixml ) -if(USE_GENERIC_LAMBDAS AND NOT GNURADIO_USES_STD_POINTERS) +if(NOT USE_GENERIC_LAMBDAS) target_link_libraries(core_libs PUBLIC Boost::headers) else() target_link_libraries(core_libs PRIVATE Boost::headers) @@ -117,20 +117,20 @@ if(USE_GENERIC_LAMBDAS) set(has_generic_lambdas HAS_GENERIC_LAMBDA=1) set(no_has_generic_lambdas HAS_GENERIC_LAMBDA=0) target_compile_definitions(core_libs - PRIVATE + PUBLIC "$<$:${has_generic_lambdas}>" "$<$>:${no_has_generic_lambdas}>" ) else() target_compile_definitions(core_libs - PRIVATE + PUBLIC -DHAS_GENERIC_LAMBDA=0 ) endif() if(USE_BOOST_BIND_PLACEHOLDERS) target_compile_definitions(core_libs - PRIVATE + PUBLIC -DUSE_BOOST_BIND_PLACEHOLDERS=1 ) endif() diff --git a/src/core/libs/galileo_e6_has_msg_receiver.cc b/src/core/libs/galileo_e6_has_msg_receiver.cc index 20e40aad1..710ee0f1c 100644 --- a/src/core/libs/galileo_e6_has_msg_receiver.cc +++ b/src/core/libs/galileo_e6_has_msg_receiver.cc @@ -19,24 +19,15 @@ #include "galileo_e6_has_msg_receiver.h" -#include "display.h" // for colors in terminal -#include "galileo_has_page.h" // for Galileo_HAS_page -#include "gnss_sdr_make_unique.h" // for std::make_unique in C++11 -#include "reed_solomon.h" // for ReedSolomon -#include -#include -#include -#include // for std::find, std::count -#include // for size_t -#include // for std::back_inserter -#include // for std::stringstream -#include // for std::out_of_range -#include // for typeid - -#if HAS_GENERIC_LAMBDA -#else -#include -#endif +#include "display.h" // for colors in terminal +#include // for boost::any_cast +#include // for DLOG +#include // for std::find, std::count +#include // for size_t +#include // for std::back_inserter +#include // for std::stringstream +#include // for std::out_of_range +#include // for typeid galileo_e6_has_msg_receiver_sptr galileo_e6_has_msg_receiver_make() @@ -45,52 +36,6 @@ galileo_e6_has_msg_receiver_sptr galileo_e6_has_msg_receiver_make() } -galileo_e6_has_msg_receiver::galileo_e6_has_msg_receiver() : gr::block("galileo_e6_has_msg_receiver", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) -{ - // register Gal E6 HAS input message port from telemetry blocks - this->message_port_register_in(pmt::mp("E6_HAS_from_TLM")); - // register nav message monitor out - this->message_port_register_out(pmt::mp("Nav_msg_from_TLM")); - this->set_msg_handler(pmt::mp("E6_HAS_from_TLM"), -#if HAS_GENERIC_LAMBDA - [this](auto&& PH1) { msg_handler_galileo_e6_has(PH1); }); -#else -#if USE_BOOST_BIND_PLACEHOLDERS - boost::bind(&galileo_e6_has_msg_receiver::msg_handler_galileo_e6_has, this, boost::placeholders::_1)); -#else - boost::bind(&galileo_e6_has_msg_receiver::msg_handler_galileo_e6_has, this, _1)); -#endif -#endif - - // register Gal E6 processed HAS async output message port towards PVT - this->message_port_register_out(pmt::mp("E6_HAS_to_PVT")); - - // initialize Reed-Solomon decoder - d_rs = std::make_unique(); - - // Reserve memory for decoding matrices and received PIDs - d_C_matrix = std::vector>>(GALILEO_CNAV_INFORMATION_VECTOR_LENGTH, std::vector>(GALILEO_CNAV_MAX_NUMBER_SYMBOLS_ENCODED_BLOCK, std::vector(GALILEO_CNAV_OCTETS_IN_SUBPAGE))); // 32 x 255 x 53 - d_M_matrix = std::vector>(GALILEO_CNAV_INFORMATION_VECTOR_LENGTH, std::vector(GALILEO_CNAV_OCTETS_IN_SUBPAGE)); // HAS message matrix 32 x 53 - d_received_pids = std::vector>(HAS_MSG_NUMBER_MESSAGE_IDS, std::vector()); - - // Reserve memory to store masks - d_nsat_in_mask_id = std::vector(HAS_MSG_NUMBER_MASK_IDS); - d_gnss_id_in_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); - d_satellite_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); - d_signal_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); - d_cell_mask_availability_flag = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); - d_cell_mask = std::vector>>>(HAS_MSG_NUMBER_MASK_IDS, {HAS_MSG_NUMBER_GNSS_IDS, {HAS_MSG_NUMBER_SATELLITE_IDS, std::vector(HAS_MSG_NUMBER_SIGNAL_MASKS)}}); - d_nsys_in_mask = std::vector(HAS_MSG_NUMBER_MASK_IDS); - d_nav_message_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); - - // Initialize values for d_nav_msg_packet - d_nav_msg_packet.system = std::string("E"); - d_nav_msg_packet.signal = std::string("E6"); - d_nav_msg_packet.prn = 0; - d_nav_msg_packet.tow_at_current_symbol_ms = 0; -} - - void galileo_e6_has_msg_receiver::set_enable_navdata_monitor(bool enable) { d_enable_navdata_monitor = enable; @@ -149,7 +94,7 @@ void galileo_e6_has_msg_receiver::process_HAS_page(const Galileo_HAS_page& has_p { if (has_page.message_type == 1) // contains satellite corrections { - if (has_page.message_id < 32) // MID range is from 0 to 31 + if (has_page.message_id < HAS_MSG_NUMBER_MESSAGE_IDS) // MID range is from 0 to 31 { if (std::find(d_received_pids[has_page.message_id].begin(), d_received_pids[has_page.message_id].end(), has_page.message_page_id) == d_received_pids[has_page.message_id].end()) { @@ -157,8 +102,9 @@ void galileo_e6_has_msg_receiver::process_HAS_page(const Galileo_HAS_page& has_p d_received_pids[has_page.message_id].push_back(has_page.message_page_id); for (int k = 0; k < GALILEO_CNAV_OCTETS_IN_SUBPAGE; k++) { - std::string bits8 = page_string.substr(k * 8, 8); - std::bitset<8> bs(bits8); + constexpr int bits_in_octet = 8; + std::string bits8 = page_string.substr(k * bits_in_octet, bits_in_octet); + std::bitset bs(bits8); d_C_matrix[has_page.message_id][has_page.message_page_id - 1][k] = static_cast(bs.to_ulong()); } } @@ -192,10 +138,11 @@ void galileo_e6_has_msg_receiver::process_HAS_page(const Galileo_HAS_page& has_p int galileo_e6_has_msg_receiver::decode_message_type1(uint8_t message_id, uint8_t message_size) { DLOG(INFO) << "Start decoding of a HAS message"; + constexpr int32_t max_erasure_positions = GALILEO_CNAV_MAX_NUMBER_SYMBOLS_ENCODED_BLOCK - GALILEO_CNAV_INFORMATION_VECTOR_LENGTH; // 223 Maximum erasure positions ( = number of parity symbols in a block) // Compute erasure positions std::vector erasure_positions; - erasure_positions.reserve(223); // Maximum erasure positions ( = number of parity symbols in a block) + erasure_positions.reserve(max_erasure_positions); for (uint8_t i = 1; i < message_size + 1; i++) // we know that from message_size to 32, the value is 0 { @@ -204,7 +151,7 @@ int galileo_e6_has_msg_receiver::decode_message_type1(uint8_t message_id, uint8_ erasure_positions.push_back(i - 1); } } - for (int i = 33; i < 256; i++) + for (int i = GALILEO_CNAV_INFORMATION_VECTOR_LENGTH + 1; i < GALILEO_CNAV_MAX_NUMBER_SYMBOLS_ENCODED_BLOCK + 1; i++) // from 33 to 255 { if (std::find(d_received_pids[message_id].begin(), d_received_pids[message_id].end(), static_cast(i)) == d_received_pids[message_id].end()) { @@ -212,7 +159,7 @@ int galileo_e6_has_msg_receiver::decode_message_type1(uint8_t message_id, uint8_ } } - if (erasure_positions.size() > 223) + if (erasure_positions.size() > static_cast(max_erasure_positions)) { // This should not happen! Maybe message_size < PID < 33 ? // Don't even try to decode @@ -587,11 +534,11 @@ void galileo_e6_has_msg_receiver::read_MT1_body(const std::string& message_body) { if ((aux & mask_value) >= 1) { - binary = "1" + binary; + binary.insert(0, "1"); } else { - binary = "0" + binary; + binary.insert(0, "0"); } aux <<= 1; } diff --git a/src/core/libs/galileo_e6_has_msg_receiver.h b/src/core/libs/galileo_e6_has_msg_receiver.h index 9e0af64d5..f3e704fbd 100644 --- a/src/core/libs/galileo_e6_has_msg_receiver.h +++ b/src/core/libs/galileo_e6_has_msg_receiver.h @@ -20,26 +20,33 @@ #ifndef GNSS_SDR_GALILEO_E6_HAS_MSG_RECEIVER_H #define GNSS_SDR_GALILEO_E6_HAS_MSG_RECEIVER_H -#include "Galileo_CNAV.h" -#include "galileo_has_data.h" -#include "gnss_block_interface.h" -#include "nav_message_packet.h" -#include -#include -#include -#include -#include // for std::unique_ptr -#include -#include // std::pair -#include +#include "Galileo_CNAV.h" // for GALILEO_CNAV_* and HAS_MSG_* constants +#include "galileo_has_data.h" // for Galileo_HAS_data +#include "galileo_has_page.h" // for Galileo_HAS_page +#include "gnss_block_interface.h" // for gnss_shared_ptr +#include "gnss_sdr_make_unique.h" // for std::make_unique in C++11 +#include "nav_message_packet.h" // for Nav_Message_Packet +#include "reed_solomon.h" // for ReedSolomon +#include // for gr::block +#include // for gr::io_signature::make +#include // for pmt::mp +#include // for std::bitset +#include // for uint8_t, ... +#include // for std::unique_ptr +#include // for std::string +#include // std::pair +#include // for std::vector + +#if HAS_GENERIC_LAMBDA +#else +#include // for boost::bind +#endif /** \addtogroup Core * \{ */ /** \addtogroup Core_Receiver_Library * \{ */ -class Galileo_HAS_page; -class ReedSolomon; class galileo_e6_has_msg_receiver; using galileo_e6_has_msg_receiver_sptr = gnss_shared_ptr; @@ -60,7 +67,52 @@ public: private: friend galileo_e6_has_msg_receiver_sptr galileo_e6_has_msg_receiver_make(); - galileo_e6_has_msg_receiver(); + + inline galileo_e6_has_msg_receiver() : gr::block("galileo_e6_has_msg_receiver", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) + { + // register Gal E6 HAS input message port from telemetry blocks + this->message_port_register_in(pmt::mp("E6_HAS_from_TLM")); + // register nav message monitor out + this->message_port_register_out(pmt::mp("Nav_msg_from_TLM")); + this->set_msg_handler(pmt::mp("E6_HAS_from_TLM"), +#if HAS_GENERIC_LAMBDA + [this](auto&& PH1) { msg_handler_galileo_e6_has(PH1); }); +#else +#if USE_BOOST_BIND_PLACEHOLDERS + boost::bind(&galileo_e6_has_msg_receiver::msg_handler_galileo_e6_has, this, boost::placeholders::_1)); +#else + boost::bind(&galileo_e6_has_msg_receiver::msg_handler_galileo_e6_has, this, _1)); +#endif +#endif + + // register Gal E6 processed HAS async output message port towards PVT + this->message_port_register_out(pmt::mp("E6_HAS_to_PVT")); + + // initialize Reed-Solomon decoder + d_rs = std::make_unique(); + + // Reserve memory for decoding matrices and received PIDs + d_C_matrix = std::vector>>(GALILEO_CNAV_INFORMATION_VECTOR_LENGTH, std::vector>(GALILEO_CNAV_MAX_NUMBER_SYMBOLS_ENCODED_BLOCK, std::vector(GALILEO_CNAV_OCTETS_IN_SUBPAGE))); // 32 x 255 x 53 + d_M_matrix = std::vector>(GALILEO_CNAV_INFORMATION_VECTOR_LENGTH, std::vector(GALILEO_CNAV_OCTETS_IN_SUBPAGE)); // HAS message matrix 32 x 53 + d_received_pids = std::vector>(HAS_MSG_NUMBER_MESSAGE_IDS, std::vector()); + + // Reserve memory to store masks + d_nsat_in_mask_id = std::vector(HAS_MSG_NUMBER_MASK_IDS); + d_gnss_id_in_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); + d_satellite_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); + d_signal_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); + d_cell_mask_availability_flag = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); + d_cell_mask = std::vector>>>(HAS_MSG_NUMBER_MASK_IDS, {HAS_MSG_NUMBER_GNSS_IDS, {HAS_MSG_NUMBER_SATELLITE_IDS, std::vector(HAS_MSG_NUMBER_SIGNAL_MASKS)}}); + d_nsys_in_mask = std::vector(HAS_MSG_NUMBER_MASK_IDS); + d_nav_message_mask = std::vector>(HAS_MSG_NUMBER_MASK_IDS, std::vector(HAS_MSG_NUMBER_GNSS_IDS)); + + // Initialize values for d_nav_msg_packet + d_nav_msg_packet.system = std::string("E"); + d_nav_msg_packet.signal = std::string("E6"); + d_nav_msg_packet.prn = 0; + d_nav_msg_packet.tow_at_current_symbol_ms = 0; + }; + void msg_handler_galileo_e6_has(const pmt::pmt_t& msg); void process_HAS_page(const Galileo_HAS_page& has_page); void read_MT1_header(const std::string& message_header); @@ -85,7 +137,7 @@ private: std::unique_ptr d_rs; Galileo_HAS_data d_HAS_data{}; - Nav_Message_Packet d_nav_msg_packet; + Nav_Message_Packet d_nav_msg_packet{}; // Store decoding matrices and received PIDs std::vector>> d_C_matrix;