From b6c7e4a6f1d782a710b26483cb4956c55df76ce0 Mon Sep 17 00:00:00 2001 From: Jeff Melville Date: Tue, 20 Sep 2022 10:16:02 -0400 Subject: [PATCH 1/2] Fix register unpacking for Labsat3W files This change fixes a bug in the unpacking of Labsat 3 Wideband files when using the Labsat_Signal_Source. The original endian conversion loop includes a cast from char->uint64_t that (surprisingly) incurs a sign extension when the MSB of the char is set. ORing the unmasked uint64_t into the register can set undesired bits. The changes replace the old endian conversion loop with a ``boost`` utility function. Signed-off-by: Jeff Melville --- .../gnuradio_blocks/labsat23_source.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc b/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc index ea92274f3..2c88841fc 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc @@ -21,6 +21,7 @@ #include "INIReader.h" #include "command_event.h" #include "gnss_sdr_make_unique.h" +#include #include #include #include @@ -737,7 +738,8 @@ void labsat23_source::decode_ls3w_register(uint64_t input, std::vector bs(input); - // Reverse, since register are written to file as 64-bit little endian words + // Earlier samples are written in the MSBs of the register. Bit-reverse the register + // for easier indexing. Note this bit-reverses individual samples as well for quant > 1 bit for (std::size_t i = 0; i < 32; ++i) { bool t = bs[i]; @@ -1074,14 +1076,10 @@ int labsat23_source::general_work(int noutput_items, std::size_t output_pointer = 0; for (int i = 0; i < registers_to_read; i++) { - std::array memory_block{}; - binary_input_file.read(memory_block.data(), 8); uint64_t read_register = 0ULL; - for (int k = 7; k >= 0; --k) - { - read_register <<= 8; - read_register |= uint64_t(memory_block[k]); - } + // Labsat3W writes its 64-bit shift register to files in little endian. Read and convert to host endianness. + binary_input_file.read(reinterpret_cast(&read_register), sizeof(read_register)); + boost::endian::little_to_native_inplace(read_register); if (binary_input_file.gcount() == 8) { From cecf7e5e434daff37d7cdd60f6571a7503df0c93 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 5 Dec 2022 15:02:35 +0100 Subject: [PATCH 2/2] Fix building if boost::endian is not available --- .../signal_source/adapters/CMakeLists.txt | 49 +++++++------------ .../gnuradio_blocks/labsat23_source.cc | 15 +++++- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index ab24d5fc1..717b8ac00 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -6,48 +6,41 @@ # Optional drivers -set(OPT_DRIVER_SOURCES "") -set(OPT_DRIVER_HEADERS "") if(ENABLE_RAW_UDP AND PCAP_FOUND) - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} custom_udp_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} custom_udp_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES custom_udp_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS custom_udp_signal_source.h) endif() - if(ENABLE_PLUTOSDR) ############################################## # ADALM-PLUTO (Analog Devices Inc.) ############################################## - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} plutosdr_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} plutosdr_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES plutosdr_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS plutosdr_signal_source.h) endif() - if(ENABLE_FMCOMMS2) ############################################### # FMCOMMS2 based SDR Hardware ############################################### - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} fmcomms2_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} fmcomms2_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES fmcomms2_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS fmcomms2_signal_source.h) endif() - if(ENABLE_AD9361) ############################################### # AD9361 DIRECT TO FPGA Hardware ############################################### - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} ad9361_fpga_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ad9361_fpga_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES ad9361_fpga_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS ad9361_fpga_signal_source.h) endif() - if(ENABLE_FLEXIBAND AND TELEORBIT_FOUND) - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} flexiband_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} flexiband_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES flexiband_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS flexiband_signal_source.h) endif() - if(ENABLE_ARRAY) ############################################## # DBFCTTC GNSS EXPERIMENTAL ARRAY PROTOTYPE @@ -56,32 +49,30 @@ if(ENABLE_ARRAY) message(" gr-dbfcttc not found, install it from https://github.com/gnss-sdr/gr-dbfcttc") message(FATAL_ERROR "gr-dbfcttc required for building gnss-sdr with this option enabled") endif() - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} raw_array_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} raw_array_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES raw_array_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS raw_array_signal_source.h) endif() - if(ENABLE_OSMOSDR) ################################################################################ # OsmoSDR - https://osmocom.org/projects/gr-osmosdr/ ################################################################################ if(GROSMOSDR_FOUND) - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} osmosdr_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} osmosdr_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES osmosdr_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS osmosdr_signal_source.h) endif() endif() if(ENABLE_LIMESDR) if(GRLIMESDR_FOUND) - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} limesdr_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} limesdr_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES limesdr_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS limesdr_signal_source.h) endif() endif() - if(ENABLE_UHD) - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} uhd_signal_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} uhd_signal_source.h) + list(APPEND OPT_DRIVER_SOURCES uhd_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS uhd_signal_source.h) endif() if(ENABLE_ZMQ) @@ -89,7 +80,6 @@ if(ENABLE_ZMQ) list(APPEND OPT_DRIVER_HEADERS zmq_signal_source.h) endif() - set(SIGNAL_SOURCE_ADAPTER_SOURCES signal_source_base.cc file_source_base.cc @@ -218,7 +208,6 @@ if(ENABLE_LIMESDR AND GRLIMESDR_FOUND) ) endif() - if(ENABLE_AD9361 AND LIBIIO_FOUND) target_link_libraries(signal_source_adapters PRIVATE @@ -302,8 +291,6 @@ target_compile_definitions(signal_source_adapters PRIVATE -DGNSSSDR_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}" ) - - set_property(TARGET signal_source_adapters APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ diff --git a/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc b/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc index 2c88841fc..dafa79e37 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc @@ -21,7 +21,6 @@ #include "INIReader.h" #include "command_event.h" #include "gnss_sdr_make_unique.h" -#include #include #include #include @@ -33,6 +32,10 @@ #include #include +#if HAS_BOOST_ENDIAN +#include +#endif + labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, const std::vector &channel_selector, Concurrent_Queue *queue, bool digital_io_enabled) { @@ -1078,8 +1081,18 @@ int labsat23_source::general_work(int noutput_items, { uint64_t read_register = 0ULL; // Labsat3W writes its 64-bit shift register to files in little endian. Read and convert to host endianness. +#if HAS_BOOST_ENDIAN binary_input_file.read(reinterpret_cast(&read_register), sizeof(read_register)); boost::endian::little_to_native_inplace(read_register); +#else + std::array memory_block{}; + binary_input_file.read(memory_block.data(), 8); + for (int k = 7; k >= 0; --k) + { + read_register <<= 8; + read_register |= uint64_t(memory_block[k]); // This is buggy if the MSB of the char is set. + } +#endif if (binary_input_file.gcount() == 8) {