1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 12:10:34 +00:00

Merge branch 'next' of https://github.com/gnss-sdr/gnss-sdr into pps_lime

This commit is contained in:
Javier Arribas 2021-03-12 10:10:00 +01:00
commit 02f3e0c3ed
5 changed files with 898 additions and 331 deletions

View File

@ -62,6 +62,8 @@ SPDX-FileCopyrightText: 2011-2021 Carles Fernandez-Prades <carles.fernandez@cttc
configurations.
- Fix bug that made the Monitor block to always set to 0 the
`carrier_phase_rads` parameter value.
- The `Labsat_Signal_Source` implementation of the `SignalSource` block now can
read files in the LabSat 3 Wideband format (`.LS3W`).
&nbsp;

View File

@ -42,10 +42,12 @@ LabsatSignalSource::LabsatSignalSource(const ConfigurationInterface* configurati
const std::string default_filename("./example_capture.LS3");
filename_ = configuration->property(role + ".filename", default_filename);
const bool digital_io_enabled = configuration->property(role + ".digital_io_enabled", false);
if (item_type_ == "gr_complex")
{
item_size_ = sizeof(gr_complex);
labsat23_source_ = labsat23_make_source_sptr(filename_.c_str(), channel_selector, queue);
labsat23_source_ = labsat23_make_source_sptr(filename_.c_str(), channel_selector, queue, digital_io_enabled);
DLOG(INFO) << "Item size " << item_size_;
DLOG(INFO) << "labsat23_source_(" << labsat23_source_->unique_id() << ")";
}

View File

@ -62,6 +62,7 @@ target_link_libraries(signal_source_gr_blocks
signal_source_libs
Boost::thread
PRIVATE
algorithms_libs
core_libs
Gflags::gflags
Glog::glog

View File

@ -1,7 +1,8 @@
/*!
* \file labsat23_source.cc
*
* \brief Unpacks the Labsat 2 (ls2) and (ls3) capture files
* \brief Unpacks capture files in the Labsat 2 (ls2), Labsat 3 (ls3), or Labsat
* 3 Wideband (LS3W) formats.
* \author Javier Arribas jarribas (at) cttc.es
*
* -----------------------------------------------------------------------------
@ -9,7 +10,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -17,10 +18,14 @@
#include "labsat23_source.h"
#include "INIReader.h"
#include "command_event.h"
#include "gnss_sdr_make_unique.h"
#include <boost/any.hpp>
#include <gnuradio/io_signature.h>
#include <array>
#include <bitset>
#include <cstddef>
#include <exception>
#include <iostream>
#include <sstream>
@ -28,15 +33,16 @@
#include <vector>
labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, int channel_selector, Concurrent_Queue<pmt::pmt_t> *queue)
labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, int channel_selector, Concurrent_Queue<pmt::pmt_t> *queue, bool digital_io_enabled)
{
return labsat23_source_sptr(new labsat23_source(signal_file_basename, channel_selector, queue));
return labsat23_source_sptr(new labsat23_source(signal_file_basename, channel_selector, queue, digital_io_enabled));
}
labsat23_source::labsat23_source(const char *signal_file_basename,
int channel_selector,
Concurrent_Queue<pmt::pmt_t> *queue) : gr::block("labsat23_source",
Concurrent_Queue<pmt::pmt_t> *queue,
bool digital_io_enabled) : gr::block("labsat23_source",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
d_queue(queue)
@ -54,10 +60,24 @@ labsat23_source::labsat23_source(const char *signal_file_basename,
d_ref_clock = 0;
d_channel_selector = 0;
d_signal_file_basename = std::string(signal_file_basename);
d_ls3w_digital_io_enabled = digital_io_enabled;
std::string signal_file;
this->set_output_multiple(8);
signal_file = generate_filename();
if (d_is_ls3w)
{
d_labsat_version = 3;
std::cout << "Labsat file version 3 wideband detected.\n";
// Read ini file
std::string ini_file = signal_file.substr(0, signal_file.length() - 4) + std::string("ini");
if (read_ls3w_ini(ini_file) != 0)
{
exit(1);
}
}
binary_input_file.open(signal_file.c_str(), std::ios::in | std::ios::binary);
if (binary_input_file.is_open())
@ -83,7 +103,7 @@ labsat23_source::~labsat23_source()
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem closing input file" << '\n';
std::cerr << "Problem closing input file.\n";
}
catch (const std::exception &e)
{
@ -102,6 +122,12 @@ std::string labsat23_source::generate_filename()
}
return std::string("donotexist"); // just to stop processing
}
if (d_signal_file_basename.substr(d_signal_file_basename.length() - 5, 5) == ".ls3w" or d_signal_file_basename.substr(d_signal_file_basename.length() - 5, 5) == ".LS3W")
{
d_is_ls3w = true;
return d_signal_file_basename;
}
std::ostringstream ss;
ss << std::setw(4) << std::setfill('0') << d_current_file_number;
return d_signal_file_basename + "_" + ss.str() + ".LS3";
@ -189,6 +215,469 @@ void labsat23_source::decode_samples_one_channel(int16_t input_short, gr_complex
}
int labsat23_source::read_ls3w_ini(const std::string &filename)
{
std::cout << "Reading " << filename << " file ...\n";
auto ini_reader = std::make_unique<INIReader>(filename);
int error_ = ini_reader->ParseError();
if (error_ > 0)
{
std::cerr << "Warning: Labsat ini file " << filename
<< " contains a syntax error in line " << error_ << ", continuing anyway.\n";
}
if (error_ < 0)
{
std::cerr << "Error: Labsat ini file " << filename << " cannot be opened.\n";
return 1;
}
const std::string empty_string("");
if (ini_reader->HasSection("config"))
{
// Reference clock
d_ls3w_OSC = ini_reader->Get("config", "OSC", empty_string);
if (d_ls3w_OSC.empty())
{
std::cerr << "Labsat reference clock: not found.\n";
}
else
{
// Sanity check
if ((d_ls3w_OSC != "OCXO") and (d_ls3w_OSC != "TCXO") and (d_ls3w_OSC != "EXT"))
{
std::cerr << "Labsat reference clock is unknown.\n";
}
else
{
std::cout << "Labsat reference clock: " << d_ls3w_OSC << '\n';
}
}
// Sample rate
std::string ls3w_SMP_aux = ini_reader->Get("config", "SMP", empty_string);
if (!ls3w_SMP_aux.empty())
{
std::stringstream smp_ss(ls3w_SMP_aux);
smp_ss >> d_ls3w_SMP;
std::cout << "Labsat sample rate: " << d_ls3w_SMP << " Sps\n";
}
// Quantization
std::string ls3w_QUA_aux = ini_reader->Get("config", "QUA", empty_string);
if (!ls3w_QUA_aux.empty())
{
std::stringstream qua_ss(ls3w_QUA_aux);
qua_ss >> d_ls3w_QUA;
// Sanity check
if (d_ls3w_QUA > 3)
{
std::cerr << "Labsat sample quantization of " << d_ls3w_QUA << " bits is not supported.\n";
d_ls3w_QUA = 0;
}
else
{
std::cout << "Labsat sample quantization: " << d_ls3w_QUA << " bits for I + " << d_ls3w_QUA << " bits for Q.\n";
}
}
// Number of RF channels
std::string ls3w_CHN_aux = ini_reader->Get("config", "CHN", empty_string);
if (!ls3w_CHN_aux.empty())
{
std::stringstream chn_ss(ls3w_CHN_aux);
chn_ss >> d_ls3w_CHN;
// Sanity check
if (d_ls3w_CHN > 3)
{
std::cerr << "Labsat files with " << d_ls3w_CHN << " RF channels are not supported.\n";
d_ls3w_CHN = 0;
}
else
{
std::cout << "Labsat data file contains " << d_ls3w_CHN << " RF channels.\n";
}
}
// Number of bits shifted per channel
std::string ls3w_SFT_aux = ini_reader->Get("config", "SFT", empty_string);
if (!ls3w_SFT_aux.empty())
{
std::stringstream sft_ss(ls3w_SFT_aux);
sft_ss >> d_ls3w_SFT;
// Sanity check
if (d_ls3w_SFT != d_ls3w_CHN * d_ls3w_QUA * 2)
{
std::cerr << "SFT parameter value in the .ini file is not valid.\n";
d_ls3w_SFT = d_ls3w_CHN * d_ls3w_QUA * 2;
}
}
}
// Channel A
if (ini_reader->HasSection("channel A"))
{
std::string ls3w_CFA_aux = ini_reader->Get("channel A", "CFA", empty_string);
if (!ls3w_CFA_aux.empty())
{
std::stringstream cfa_ss(ls3w_CFA_aux);
cfa_ss >> d_ls3w_CFA;
std::cout << "Labsat center frequency for RF channel A: " << d_ls3w_CFA << " Hz\n";
}
std::string ls3w_BWA_aux = ini_reader->Get("channel A", "BWA", empty_string);
if (!ls3w_BWA_aux.empty())
{
std::stringstream bwa_ss(ls3w_BWA_aux);
bwa_ss >> d_ls3w_BWA;
std::cout << "Labsat RF filter bandwidth for RF channel A: " << d_ls3w_BWA << " Hz\n";
}
}
// Channel B
if (ini_reader->HasSection("channel B"))
{
std::string ls3w_CFB_aux = ini_reader->Get("channel B", "CFB", empty_string);
if (!ls3w_CFB_aux.empty())
{
std::stringstream cfb_ss(ls3w_CFB_aux);
cfb_ss >> d_ls3w_CFB;
std::cout << "Labsat center frequency for RF channel B: " << d_ls3w_CFB << " Hz\n";
}
std::string ls3w_BWB_aux = ini_reader->Get("channel B", "BWB", empty_string);
if (!ls3w_BWB_aux.empty())
{
std::stringstream bwb_ss(ls3w_BWB_aux);
bwb_ss >> d_ls3w_BWB;
std::cout << "Labsat RF filter bandwidth for RF channel B: " << d_ls3w_BWB << " Hz\n";
}
}
// Channel C
if (ini_reader->HasSection("channel C"))
{
std::string ls3w_CFC_aux = ini_reader->Get("channel C", "CFC", empty_string);
if (!ls3w_CFC_aux.empty())
{
std::stringstream cfc_ss(ls3w_CFC_aux);
cfc_ss >> d_ls3w_CFC;
std::cout << "Labsat center frequency for RF channel C: " << d_ls3w_CFC << " Hz\n";
}
std::string ls3w_BWC_aux = ini_reader->Get("channel C", "BWC", empty_string);
if (!ls3w_BWC_aux.empty())
{
std::stringstream bwc_ss(ls3w_BWC_aux);
bwc_ss >> d_ls3w_BWC;
std::cout << "Labsat RF filter bandwidth for RF channel C: " << d_ls3w_BWC << " Hz\n";
}
}
std::cout << "Labsat selected channel";
if (d_channel_selector_config == 1)
{
std::cout << ": A\n";
}
if (d_channel_selector_config == 2)
{
if (d_ls3w_CHN > 1)
{
std::cout << ": B\n";
}
else
{
std::cout << " is not found.\n";
}
}
if (d_channel_selector_config == 3)
{
if (d_ls3w_CHN > 2)
{
std::cout << ": C\n";
}
else
{
std::cout << " is not found.\n";
}
}
d_ls3w_samples_per_register = this->number_of_samples_per_ls3w_register();
d_ls3w_spare_bits = 64 - d_ls3w_samples_per_register * d_ls3w_QUA * 2;
d_ls3w_selected_channel_offset = (d_channel_selector_config - 1) * d_ls3w_QUA * 2;
return 0;
}
int labsat23_source::number_of_samples_per_ls3w_register() const
{
int number_samples = 0;
switch (d_ls3w_QUA)
{
case 1:
if (d_ls3w_CHN == 1)
{
if (!d_ls3w_digital_io_enabled)
{
number_samples = 32;
}
else
{
number_samples = 30;
}
}
if (d_ls3w_CHN == 2)
{
if (!d_ls3w_digital_io_enabled)
{
number_samples = 16;
}
else
{
number_samples = 15;
}
}
if (d_ls3w_CHN == 3)
{
number_samples = 10;
}
break;
case 2:
if (d_ls3w_CHN == 1)
{
if (!d_ls3w_digital_io_enabled)
{
number_samples = 16;
}
else
{
number_samples = 15;
}
}
if (d_ls3w_CHN == 2)
{
if (!d_ls3w_digital_io_enabled)
{
number_samples = 8;
}
else
{
number_samples = 7;
}
}
if (d_ls3w_CHN == 3)
{
number_samples = 5;
}
break;
case 3:
if (d_ls3w_CHN == 1)
{
number_samples = 10;
}
if (d_ls3w_CHN == 2)
{
number_samples = 5;
}
if (d_ls3w_CHN == 3)
{
number_samples = 3;
}
break;
default:
number_samples = 0;
break;
}
return number_samples;
}
void labsat23_source::decode_ls3w_register_one_channel(uint64_t input, gr_complex *out) const
{
std::bitset<64> bs(input);
// Reverse, since register are written to file as 64-bit little endian words
for (std::size_t i = 0; i < 32; ++i)
{
bool t = bs[i];
bs[i] = bs[64 - i - 1];
bs[64 - i - 1] = t;
}
for (int i = 0; i < d_ls3w_samples_per_register; i++)
{
float sampleI = 0.0;
float sampleQ = 0.0;
const int bit_offset = d_ls3w_spare_bits + i * d_ls3w_SFT + d_ls3w_selected_channel_offset;
switch (d_ls3w_QUA)
{
case 1:
sampleI = bs[bit_offset] ? -1.0 : 1.0;
sampleQ = bs[bit_offset + 1] ? -1.0 : 1.0;
break;
case 2:
if (bs[bit_offset])
{
if (bs[bit_offset + 1]) // 11
{
sampleI = -0.5;
}
else // 10
{
sampleI = -1.0;
}
}
else
{
if (bs[bit_offset + 1]) // 01
{
sampleI = 1.0;
}
else // 00
{
sampleI = 0.5;
}
}
if (bs[bit_offset + 2])
{
if (bs[bit_offset + 3]) // 11
{
sampleQ = -0.5;
}
else // 10
{
sampleQ = -1.0;
}
}
else
{
if (bs[bit_offset + 3]) // 01
{
sampleQ = 1.0;
}
else // 00
{
sampleQ = 0.5;
}
}
break;
case 3:
if (bs[bit_offset])
{
if (bs[bit_offset + 1])
{
if (bs[bit_offset + 2]) // 111
{
sampleI = -0.25;
}
else // 110
{
sampleI = -0.5;
}
}
else
{
if (bs[bit_offset + 2]) // 101
{
sampleI = -0.75;
}
else // 100
{
sampleI = -1.0;
}
}
}
else
{
if (bs[bit_offset + 1])
{
if (bs[bit_offset + 2]) // 011
{
sampleI = 1;
}
else // 010
{
sampleI = 0.75;
}
}
else
{
if (bs[bit_offset + 2]) // 001
{
sampleI = 0.5;
}
else // 000
{
sampleI = 0.25;
}
}
}
if (bs[bit_offset + 3])
{
if (bs[bit_offset + 4])
{
if (bs[bit_offset + 5]) // 111
{
sampleQ = -0.25;
}
else // 110
{
sampleQ = -0.5;
}
}
else
{
if (bs[bit_offset + 5]) // 101
{
sampleQ = -0.75;
}
else // 100
{
sampleQ = -1.0;
}
}
}
else
{
if (bs[bit_offset + 4])
{
if (bs[bit_offset + 5]) // 011
{
sampleQ = 1;
}
else // 010
{
sampleQ = 0.75;
}
}
else
{
if (bs[bit_offset + 5]) // 001
{
sampleQ = 0.5;
}
else // 000
{
sampleQ = 0.25;
}
}
}
break;
default:
break;
}
out[i] = gr_complex(sampleI, sampleQ);
}
}
int labsat23_source::general_work(int noutput_items,
__attribute__((unused)) gr_vector_int &ninput_items,
__attribute__((unused)) gr_vector_const_void_star &input_items,
@ -196,6 +685,8 @@ int labsat23_source::general_work(int noutput_items,
{
auto *out = reinterpret_cast<gr_complex *>(output_items[0]);
if (!d_is_ls3w)
{
if (d_header_parsed == false)
{
if (binary_input_file.eof() == false)
@ -520,6 +1011,50 @@ int labsat23_source::general_work(int noutput_items,
default:
return -1;
}
}
else // Labsat 3 Wideband
{
if (binary_input_file.eof() == false)
{
// Integer division, any fractional part of the answer is discarded
int registers_to_read = noutput_items / d_ls3w_samples_per_register;
if (registers_to_read < 1)
{
return 0;
}
int output_pointer = 0;
for (int i = 0; i < registers_to_read; i++)
{
std::array<char, 8> 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]);
}
if (binary_input_file.gcount() == 8)
{
decode_ls3w_register_one_channel(read_register, &out[output_pointer]);
output_pointer += d_ls3w_samples_per_register;
}
else
{
std::cout << "End of file reached, LabSat source stop.\n";
d_queue->push(pmt::make_any(command_event_make(200, 0)));
return -1;
}
}
return output_pointer;
}
else
{
std::cout << "End of file reached, LabSat source stop.\n";
d_queue->push(pmt::make_any(command_event_make(200, 0)));
return -1;
}
}
std::cout << "Warning!!\n";
return 0;

View File

@ -1,7 +1,8 @@
/*!
* \file labsat23_source.h
*
* \brief Unpacks the Labsat 2 (ls2) and (ls3) capture files
* \brief Unpacks capture files in the Labsat 2 (ls2), Labsat 3 (ls3), or Labsat
* 3 Wideband (LS3W) formats.
* \author Javier Arribas jarribas (at) cttc.es
*
* -----------------------------------------------------------------------------
@ -9,7 +10,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -39,7 +40,8 @@ using labsat23_source_sptr = gnss_shared_ptr<labsat23_source>;
labsat23_source_sptr labsat23_make_source_sptr(
const char *signal_file_basename,
int channel_selector,
Concurrent_Queue<pmt::pmt_t> *queue);
Concurrent_Queue<pmt::pmt_t> *queue,
bool digital_io_enabled);
/*!
* \brief This class implements conversion between Labsat2 and 3 format byte packet samples to gr_complex
@ -58,15 +60,22 @@ private:
friend labsat23_source_sptr labsat23_make_source_sptr(
const char *signal_file_basename,
int channel_selector,
Concurrent_Queue<pmt::pmt_t> *queue);
Concurrent_Queue<pmt::pmt_t> *queue,
bool digital_io_enabled);
labsat23_source(const char *signal_file_basename,
int channel_selector,
Concurrent_Queue<pmt::pmt_t> *queue);
Concurrent_Queue<pmt::pmt_t> *queue,
bool digital_io_enabled);
std::string generate_filename();
void decode_samples_one_channel(int16_t input_short, gr_complex *out, int type);
int getBit(uint8_t byte, int position);
int read_ls3w_ini(const std::string &filename);
int number_of_samples_per_ls3w_register() const;
void decode_samples_one_channel(int16_t input_short, gr_complex *out, int type);
void decode_ls3w_register_one_channel(uint64_t input, gr_complex *out) const;
std::ifstream binary_input_file;
std::string d_signal_file_basename;
@ -78,6 +87,24 @@ private:
uint8_t d_ref_clock;
uint8_t d_bits_per_sample;
bool d_header_parsed;
// Data members for Labsat 3 Wideband
std::string d_ls3w_OSC;
int64_t d_ls3w_SMP{};
int32_t d_ls3w_QUA{};
int32_t d_ls3w_CHN{};
int32_t d_ls3w_SFT{};
int32_t d_ls3w_CFA{};
int32_t d_ls3w_CFB{};
int32_t d_ls3w_CFC{};
int32_t d_ls3w_BWA{};
int32_t d_ls3w_BWB{};
int32_t d_ls3w_BWC{};
int d_ls3w_spare_bits{};
int d_ls3w_selected_channel_offset{};
int d_ls3w_samples_per_register{};
bool d_is_ls3w = false;
bool d_ls3w_digital_io_enabled = false;
};