2018-01-23 16:31:42 +00:00
|
|
|
/*!
|
|
|
|
* \file labsat23_source.cc
|
|
|
|
*
|
2021-03-14 19:00:18 +00:00
|
|
|
* \brief Unpacks capture files in the LabSat 2 (ls2), LabSat 3 (ls3), or LabSat
|
2021-03-11 21:13:23 +00:00
|
|
|
* 3 Wideband (LS3W) formats.
|
2018-01-23 16:31:42 +00:00
|
|
|
* \author Javier Arribas jarribas (at) cttc.es
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2018-01-23 16:31:42 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2018-01-23 16:31:42 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2021-03-11 21:13:23 +00:00
|
|
|
* Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2018-01-23 16:31:42 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2018-01-23 16:31:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "labsat23_source.h"
|
2021-03-11 21:13:23 +00:00
|
|
|
#include "INIReader.h"
|
2019-07-16 15:41:12 +00:00
|
|
|
#include "command_event.h"
|
2021-03-11 21:13:23 +00:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2018-01-23 16:31:42 +00:00
|
|
|
#include <gnuradio/io_signature.h>
|
2021-03-14 19:00:18 +00:00
|
|
|
#include <algorithm>
|
2019-07-14 12:09:12 +00:00
|
|
|
#include <array>
|
2021-03-11 21:13:23 +00:00
|
|
|
#include <bitset>
|
2019-02-10 20:55:51 +00:00
|
|
|
#include <exception>
|
2021-11-23 12:30:48 +00:00
|
|
|
#include <iomanip>
|
2018-02-25 21:49:06 +00:00
|
|
|
#include <iostream>
|
2021-10-08 09:15:01 +00:00
|
|
|
#include <memory>
|
2018-01-23 16:31:42 +00:00
|
|
|
#include <sstream>
|
2019-04-27 10:49:37 +00:00
|
|
|
#include <utility>
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2022-12-05 14:02:35 +00:00
|
|
|
#if HAS_BOOST_ENDIAN
|
|
|
|
#include <boost/endian/conversion.hpp>
|
|
|
|
#endif
|
|
|
|
|
2018-01-23 19:07:43 +00:00
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, const std::vector<int> &channel_selector, Concurrent_Queue<pmt::pmt_t> *queue, bool digital_io_enabled)
|
2018-01-23 16:31:42 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
return labsat23_source_sptr(new labsat23_source(signal_file_basename, channel_selector, queue, digital_io_enabled));
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 19:07:43 +00:00
|
|
|
|
2018-04-29 11:26:21 +00:00
|
|
|
labsat23_source::labsat23_source(const char *signal_file_basename,
|
2021-03-14 19:00:18 +00:00
|
|
|
const std::vector<int> &channel_selector,
|
2021-03-11 21:13:23 +00:00
|
|
|
Concurrent_Queue<pmt::pmt_t> *queue,
|
|
|
|
bool digital_io_enabled) : gr::block("labsat23_source",
|
|
|
|
gr::io_signature::make(0, 0, 0),
|
2021-03-14 19:00:18 +00:00
|
|
|
gr::io_signature::make(1, 3, sizeof(gr_complex))),
|
2021-12-14 13:06:37 +00:00
|
|
|
d_queue(queue),
|
|
|
|
d_channel_selector_config(channel_selector),
|
|
|
|
d_current_file_number(0),
|
|
|
|
d_labsat_version(0),
|
|
|
|
d_channel_selector(0),
|
|
|
|
d_ref_clock(0),
|
|
|
|
d_bits_per_sample(0),
|
|
|
|
d_header_parsed(false),
|
|
|
|
d_ls3w_digital_io_enabled(digital_io_enabled)
|
2018-01-23 16:31:42 +00:00
|
|
|
{
|
2018-01-23 19:07:43 +00:00
|
|
|
d_signal_file_basename = std::string(signal_file_basename);
|
2018-01-23 16:31:42 +00:00
|
|
|
std::string signal_file;
|
|
|
|
this->set_output_multiple(8);
|
2018-01-23 19:07:43 +00:00
|
|
|
signal_file = generate_filename();
|
2021-03-11 21:13:23 +00:00
|
|
|
|
|
|
|
if (d_is_ls3w)
|
|
|
|
{
|
|
|
|
d_labsat_version = 3;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat file version 3 Wideband detected.\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
binary_input_file.open(signal_file.c_str(), std::ios::in | std::ios::binary);
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
if (binary_input_file.is_open())
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat file source is reading samples from " << signal_file << '\n';
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat file " << signal_file << " could not be opened!\n";
|
2018-01-23 19:07:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
labsat23_source::~labsat23_source()
|
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
try
|
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
if (binary_input_file.is_open())
|
2019-02-10 20:55:51 +00:00
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
binary_input_file.close();
|
2019-02-10 20:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
std::cerr << "Problem closing input file.\n";
|
2019-02-10 20:55:51 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
std::cerr << e.what() << '\n';
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 19:07:43 +00:00
|
|
|
|
2019-04-12 10:59:57 +00:00
|
|
|
std::string labsat23_source::generate_filename()
|
|
|
|
{
|
|
|
|
if (d_signal_file_basename.substr(d_signal_file_basename.length() - 4, 4) == ".ls2" or d_signal_file_basename.substr(d_signal_file_basename.length() - 4, 4) == ".LS2")
|
|
|
|
{
|
|
|
|
if (d_current_file_number == 0)
|
|
|
|
{
|
|
|
|
return d_signal_file_basename;
|
|
|
|
}
|
2021-10-08 12:50:05 +00:00
|
|
|
return {"donotexist"}; // just to stop processing
|
2019-04-12 10:59:57 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-04-12 10:59:57 +00:00
|
|
|
std::ostringstream ss;
|
|
|
|
ss << std::setw(4) << std::setfill('0') << d_current_file_number;
|
|
|
|
return d_signal_file_basename + "_" + ss.str() + ".LS3";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-23 16:31:42 +00:00
|
|
|
int labsat23_source::getBit(uint8_t byte, int position)
|
|
|
|
{
|
|
|
|
return (byte >> position) & 0x01;
|
|
|
|
}
|
|
|
|
|
2018-01-23 19:07:43 +00:00
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
int labsat23_source::parse_header()
|
|
|
|
{
|
|
|
|
if (binary_input_file.eof() == false)
|
|
|
|
{
|
|
|
|
std::array<char, 1024> memblock{};
|
|
|
|
binary_input_file.read(memblock.data(), 1024);
|
|
|
|
// parse Labsat header
|
|
|
|
// check preamble
|
|
|
|
int byte_counter = 0;
|
|
|
|
bool preamble_ok = true;
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (memblock[byte_counter] != 0x00)
|
|
|
|
{
|
|
|
|
preamble_ok = false;
|
|
|
|
}
|
|
|
|
byte_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preamble_ok == false)
|
|
|
|
{
|
|
|
|
std::cout << "LabSat source do not detect the preamble in the selected file\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check Labsat version
|
|
|
|
if (memblock[byte_counter] == 0x4C and memblock[byte_counter + 1] == 0x53 and memblock[byte_counter + 2] == 0x32)
|
|
|
|
{
|
|
|
|
d_labsat_version = 2;
|
|
|
|
std::cout << "LabSat file version 2 detected\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memblock[byte_counter] == 0x4C and memblock[byte_counter + 1] == 0x53 and memblock[byte_counter + 2] == 0x33)
|
|
|
|
{
|
|
|
|
d_labsat_version = 3;
|
|
|
|
std::cout << "LabSat file version 3 detected\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d_labsat_version == 0)
|
|
|
|
{
|
|
|
|
std::cout << "LabSat source do not detect the version number in the file header\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_counter += 3;
|
|
|
|
|
|
|
|
int sub_version = static_cast<int>(memblock[byte_counter]);
|
|
|
|
|
|
|
|
std::cout << "LabSat file sub version " << sub_version << '\n';
|
|
|
|
|
|
|
|
byte_counter++;
|
|
|
|
|
|
|
|
int header_bytes = 0;
|
|
|
|
header_bytes += memblock[byte_counter] | (memblock[byte_counter + 1] << 8) | (memblock[byte_counter + 2] << 16) | (memblock[byte_counter + 3] << 24);
|
|
|
|
|
|
|
|
byte_counter += 4;
|
|
|
|
|
|
|
|
// read first section
|
|
|
|
// section ID (little-endian)
|
|
|
|
uint8_t section_id = static_cast<int>(memblock[byte_counter]) + static_cast<int>(memblock[byte_counter + 1]) * 256;
|
|
|
|
byte_counter += 2;
|
|
|
|
|
|
|
|
// uint8_t section_lenght_bytes = 0;
|
|
|
|
// section_lenght_bytes += memblock[byte_counter] | (memblock[byte_counter + 1] << 8) | (memblock[byte_counter + 2] << 16) | (memblock[byte_counter + 3] << 24);
|
|
|
|
|
|
|
|
byte_counter += 4;
|
|
|
|
if (section_id == 2)
|
|
|
|
{
|
|
|
|
d_ref_clock = static_cast<uint8_t>(memblock[byte_counter]);
|
|
|
|
switch (d_ref_clock)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
std::cout << "LabSat reference clock: internal OCXO\n";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
std::cout << "LabSat reference clock: internal TCXO\n";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
std::cout << "LabSat reference clock: external 10 MHz\n";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
std::cout << "LabSat reference clock: external 16.386 MHz\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "LabSat Unknown reference clock ID " << static_cast<int>(d_ref_clock) << '\n';
|
|
|
|
}
|
|
|
|
byte_counter++;
|
|
|
|
d_bits_per_sample = static_cast<uint8_t>(memblock[byte_counter]);
|
|
|
|
switch (d_bits_per_sample)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
std::cout << "LabSat is using 2 bits per sample\n";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
std::cout << "LabSat is using 4 bits per sample\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "LabSat Unknown bits per sample ID " << static_cast<int>(d_bits_per_sample) << '\n';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_counter++;
|
|
|
|
d_channel_selector = static_cast<uint8_t>(memblock[byte_counter]);
|
|
|
|
switch (d_channel_selector)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
std::cout << "Available channels: Channel A + B, 1 bit quantisation (I & Q)\n";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
std::cout << "Available channels: Channel A, 1 bit quantisation (I & Q)\n";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
std::cout << "Available channels: Channel B, 1 bit quantisation (I & Q)\n";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
std::cout << "Available channels: Channel A, 2 bit quantisation (I & Q)\n";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
std::cout << "Available channels: Channel B, 2 bit quantisation (I & Q)\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "Unknown channel selection ID " << static_cast<int>(d_channel_selector) << '\n';
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the selected channel in config file match the file encoding
|
|
|
|
if (d_channel_selector_config[0] == 2 and d_channel_selector != 0)
|
|
|
|
{
|
|
|
|
std::cout << "LabSat source channel config inconsistency: channel 2 is selected but the file has only one channel.\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: Add support for dual channel files
|
|
|
|
if (d_channel_selector == 0)
|
|
|
|
{
|
|
|
|
std::cout << "ERROR: LabSat file contains more than one channel and this is not currently supported for LabSat version " << d_labsat_version << ".\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
byte_counter++;
|
|
|
|
auto quantization = static_cast<uint8_t>(memblock[byte_counter]);
|
|
|
|
switch (quantization)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
std::cout << "1 bit per sample\n";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
std::cout << "2 bit per sample\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "Unknown quantization ID " << static_cast<int>(quantization) << '\n';
|
|
|
|
}
|
|
|
|
byte_counter++;
|
|
|
|
auto channel_a_constellation = static_cast<uint8_t>(memblock[byte_counter]);
|
|
|
|
switch (channel_a_constellation)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
std::cout << "LabSat Channel A is GPS\n";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
std::cout << "LabSat Channel A is GLONASS\n";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
std::cout << "LabSat Channel A is BDS\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "Unknown channel A constellation ID " << static_cast<int>(channel_a_constellation) << '\n';
|
|
|
|
}
|
|
|
|
byte_counter++;
|
|
|
|
auto channel_b_constellation = static_cast<uint8_t>(memblock[byte_counter]);
|
|
|
|
switch (channel_b_constellation)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
std::cout << "LabSat Channel B is GPS\n";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
std::cout << "LabSat Channel B is GLONASS\n";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
std::cout << "LabSat Channel B is BDS\n";
|
|
|
|
break;
|
|
|
|
case 255:
|
|
|
|
// No channel B
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << "Unknown channel B constellation ID " << static_cast<int>(channel_b_constellation) << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of header
|
|
|
|
d_header_parsed = true;
|
|
|
|
// seek file to the first signal sample
|
|
|
|
binary_input_file.clear();
|
|
|
|
binary_input_file.seekg(header_bytes, binary_input_file.beg);
|
|
|
|
if (d_channel_selector_config.size() > 1)
|
|
|
|
{
|
|
|
|
std::cerr << "Multiple RF source is not implemented for LabSat version " << d_labsat_version << "files.\n";
|
|
|
|
std::cerr << "The Multiple RF source feature is only available for LabSat 3 Wideband format files.\n";
|
|
|
|
std::cerr << "Selecting channel";
|
|
|
|
if (d_channel_selector_config[0] == 1)
|
|
|
|
{
|
|
|
|
std::cerr << " A.";
|
|
|
|
}
|
|
|
|
if (d_channel_selector_config[0] == 2)
|
|
|
|
{
|
|
|
|
std::cerr << " B.";
|
|
|
|
}
|
|
|
|
if (d_channel_selector_config[0] == 3)
|
|
|
|
{
|
|
|
|
std::cerr << " C.";
|
|
|
|
}
|
|
|
|
std::cerr << '\n';
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
std::cout << "LabSat file header error: section 2 is not available.\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
std::cout << "LabSat file read error: file is empty.\n";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
void labsat23_source::decode_samples_one_channel(int16_t input_short, gr_complex *out, int type)
|
2018-01-23 16:31:42 +00:00
|
|
|
{
|
|
|
|
std::bitset<16> bs(input_short);
|
2018-03-03 01:03:39 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 2:
|
2019-04-12 10:59:57 +00:00
|
|
|
// two bits per sample, 8 samples per int16
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
out[i] = gr_complex(static_cast<float>(bs[15 - (2 * i)]),
|
|
|
|
static_cast<float>(bs[14 - (2 * i)]));
|
|
|
|
out[i] = out[i] * gr_complex(2, 0) - gr_complex(1, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2019-04-12 10:59:57 +00:00
|
|
|
// bits per sample, 4 samples per int16
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2019-08-18 20:16:13 +00:00
|
|
|
// out[i] = gr_complex(0.0, 0.0);
|
2019-04-12 10:59:57 +00:00
|
|
|
// In-Phase
|
2018-03-03 01:03:39 +00:00
|
|
|
if (bs[15 - 4 * i])
|
|
|
|
{
|
2019-04-12 10:59:57 +00:00
|
|
|
if (bs[13 - 4 * i]) // 11
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2019-05-06 10:55:32 +00:00
|
|
|
out[i] = gr_complex(-1, 0);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2019-04-12 10:59:57 +00:00
|
|
|
else // 10
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2019-05-06 10:55:32 +00:00
|
|
|
out[i] = gr_complex(-2, 0);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-12 10:59:57 +00:00
|
|
|
if (bs[13 - 4 * i]) // 01
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2019-05-06 10:55:32 +00:00
|
|
|
out[i] = gr_complex(2, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out[i] = gr_complex(1, 0);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2019-04-12 10:59:57 +00:00
|
|
|
// Quadrature
|
2018-03-03 01:03:39 +00:00
|
|
|
if (bs[14 - 4 * i])
|
|
|
|
{
|
2019-04-12 10:59:57 +00:00
|
|
|
if (bs[12 - 4 * i]) // 11
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
out[i] += gr_complex(0, -1);
|
|
|
|
}
|
2019-04-12 10:59:57 +00:00
|
|
|
else // 10
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
out[i] += gr_complex(0, -2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-12 10:59:57 +00:00
|
|
|
if (bs[12 - 4 * i]) // 01
|
2019-05-06 10:55:32 +00:00
|
|
|
{
|
|
|
|
out[i] += gr_complex(0, 2);
|
|
|
|
}
|
|
|
|
else
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
out[i] += gr_complex(0, 1);
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 20:16:13 +00:00
|
|
|
// out[i] += gr_complex(0.5, 0.5);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-05-12 08:59:11 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 19:07:43 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
int labsat23_source::read_ls3w_ini(const std::string &filename)
|
2018-01-23 16:31:42 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
std::cout << "Reading " << filename << " file ...\n";
|
|
|
|
auto ini_reader = std::make_unique<INIReader>(filename);
|
|
|
|
int error_ = ini_reader->ParseError();
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
if (error_ > 0)
|
2018-01-23 16:31:42 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "Warning: LabSat ini file " << filename
|
2021-03-11 21:13:23 +00:00
|
|
|
<< " contains a syntax error in line " << error_ << ", continuing anyway.\n";
|
|
|
|
}
|
|
|
|
if (error_ < 0)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "Error: LabSat ini file " << filename << " cannot be opened.\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
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())
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "LabSat reference clock: not found.\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
else
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
// Sanity check
|
|
|
|
if ((d_ls3w_OSC != "OCXO") and (d_ls3w_OSC != "TCXO") and (d_ls3w_OSC != "EXT"))
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "LabSat reference clock is unknown.\n";
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
else
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat reference clock: " << d_ls3w_OSC << '\n';
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
// 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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat sample rate: " << d_ls3w_SMP << " Sps\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "LabSat sample quantization of " << d_ls3w_QUA << " bits is not supported.\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
d_ls3w_QUA = 0;
|
|
|
|
}
|
|
|
|
else
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat sample quantization: " << d_ls3w_QUA << " bits for I + " << d_ls3w_QUA << " bits for Q.\n";
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
// 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)
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "LabSat files with " << d_ls3w_CHN << " RF channels are not supported.\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
d_ls3w_CHN = 0;
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat data file contains " << d_ls3w_CHN << " RF channels.\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
// Sanity check
|
|
|
|
if (d_ls3w_SFT != d_ls3w_CHN * d_ls3w_QUA * 2)
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
std::cerr << "SFT parameter value in the .ini file is not valid.\n";
|
|
|
|
d_ls3w_SFT = d_ls3w_CHN * d_ls3w_QUA * 2;
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
// 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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat center frequency for RF channel A: " << d_ls3w_CFA << " Hz\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat RF filter bandwidth for RF channel A: " << d_ls3w_BWA << " Hz\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
// 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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat center frequency for RF channel B: " << d_ls3w_CFB << " Hz\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat RF filter bandwidth for RF channel B: " << d_ls3w_BWB << " Hz\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat center frequency for RF channel C: " << d_ls3w_CFC << " Hz\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat RF filter bandwidth for RF channel C: " << d_ls3w_BWC << " Hz\n";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat selected channel" << ((d_channel_selector_config.size() > 1) ? "s" : "") << ": ";
|
|
|
|
if (std::find(d_channel_selector_config.begin(), d_channel_selector_config.end(), 1) != d_channel_selector_config.end())
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "A";
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
if (std::find(d_channel_selector_config.begin(), d_channel_selector_config.end(), 2) != d_channel_selector_config.end())
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
|
|
|
if (d_ls3w_CHN > 1)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (d_channel_selector_config.size() == 1)
|
|
|
|
{
|
|
|
|
std::cout << "B";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << ", B";
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "\nConfiguration error: RF channel B is selected but not found in data file.\n";
|
|
|
|
std::cerr << "Exiting the program.\n";
|
|
|
|
return -1;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
if (std::find(d_channel_selector_config.begin(), d_channel_selector_config.end(), 3) != d_channel_selector_config.end())
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
|
|
|
if (d_ls3w_CHN > 2)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (d_channel_selector_config.size() == 1)
|
|
|
|
{
|
|
|
|
std::cout << "C";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << ", C";
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cerr << "\nConfiguration error: RF channel C is selected but not found in data file.\n";
|
|
|
|
std::cerr << "Exiting the program.\n";
|
|
|
|
return -1;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << '\n';
|
2021-03-11 21:13:23 +00:00
|
|
|
|
|
|
|
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;
|
2021-03-14 19:00:18 +00:00
|
|
|
for (auto ch_select : d_channel_selector_config)
|
|
|
|
{
|
|
|
|
d_ls3w_selected_channel_offset.push_back((ch_select - 1) * d_ls3w_QUA * 2);
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
void labsat23_source::decode_ls3w_register(uint64_t input, std::vector<gr_complex *> &out, size_t output_pointer) const
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
|
|
|
std::bitset<64> bs(input);
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2022-09-20 14:16:02 +00:00
|
|
|
// 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
|
2021-03-11 21:13:23 +00:00
|
|
|
for (std::size_t i = 0; i < 32; ++i)
|
|
|
|
{
|
|
|
|
bool t = bs[i];
|
|
|
|
bs[i] = bs[64 - i - 1];
|
|
|
|
bs[64 - i - 1] = t;
|
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
int output_chan = 0;
|
|
|
|
for (auto channel_offset : d_ls3w_selected_channel_offset)
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
for (int i = 0; i < d_ls3w_samples_per_register; i++)
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
float sampleI = 0.0;
|
|
|
|
float sampleQ = 0.0;
|
2018-01-23 16:31:42 +00:00
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
const int bit_offset = d_ls3w_spare_bits + i * d_ls3w_SFT + channel_offset;
|
|
|
|
switch (d_ls3w_QUA)
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
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])
|
2018-01-23 19:07:43 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 1]) // 11
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleI = -0.5;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else // 10
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleI = -1.0;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-01-23 19:07:43 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 1]) // 01
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleI = 1.0;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else // 00
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleI = 0.5;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 2])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 3]) // 11
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleQ = -0.5;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else // 10
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleQ = -1.0;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 3]) // 01
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleQ = 1.0;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else // 00
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
sampleQ = 0.5;
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (bs[bit_offset])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 1])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 2]) // 111
|
|
|
|
{
|
|
|
|
sampleI = -0.25;
|
|
|
|
}
|
|
|
|
else // 110
|
|
|
|
{
|
|
|
|
sampleI = -0.5;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 2]) // 101
|
|
|
|
{
|
|
|
|
sampleI = -0.75;
|
|
|
|
}
|
|
|
|
else // 100
|
|
|
|
{
|
|
|
|
sampleI = -1.0;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 1])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 2]) // 011
|
|
|
|
{
|
|
|
|
sampleI = 1;
|
|
|
|
}
|
|
|
|
else // 010
|
|
|
|
{
|
|
|
|
sampleI = 0.75;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 2]) // 001
|
|
|
|
{
|
|
|
|
sampleI = 0.5;
|
|
|
|
}
|
|
|
|
else // 000
|
|
|
|
{
|
|
|
|
sampleI = 0.25;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 3])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 4])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 5]) // 111
|
|
|
|
{
|
|
|
|
sampleQ = -0.25;
|
|
|
|
}
|
|
|
|
else // 110
|
|
|
|
{
|
|
|
|
sampleQ = -0.5;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 5]) // 101
|
|
|
|
{
|
|
|
|
sampleQ = -0.75;
|
|
|
|
}
|
|
|
|
else // 100
|
|
|
|
{
|
|
|
|
sampleQ = -1.0;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 4])
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 5]) // 011
|
|
|
|
{
|
|
|
|
sampleQ = 1;
|
|
|
|
}
|
|
|
|
else // 010
|
|
|
|
{
|
|
|
|
sampleQ = 0.75;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
else
|
2021-03-11 21:13:23 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
if (bs[bit_offset + 5]) // 001
|
|
|
|
{
|
|
|
|
sampleQ = 0.5;
|
|
|
|
}
|
|
|
|
else // 000
|
|
|
|
{
|
|
|
|
sampleQ = 0.25;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
break;
|
2021-03-11 21:13:23 +00:00
|
|
|
|
2021-03-14 19:00:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gr_complex *aux = out[output_chan];
|
|
|
|
aux[output_pointer + i] = gr_complex(sampleI, sampleQ);
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
output_chan++;
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
int labsat23_source::general_work(int noutput_items,
|
|
|
|
__attribute__((unused)) gr_vector_int &ninput_items,
|
|
|
|
__attribute__((unused)) gr_vector_const_void_star &input_items,
|
|
|
|
gr_vector_void_star &output_items)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::vector<gr_complex *> out;
|
2021-03-14 21:17:22 +00:00
|
|
|
for (auto &output_item : output_items)
|
2021-03-14 19:00:18 +00:00
|
|
|
{
|
|
|
|
out.push_back(reinterpret_cast<gr_complex *>(output_item));
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
if (!d_is_ls3w)
|
2018-01-23 16:31:42 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
if (d_header_parsed == false)
|
2019-05-12 08:59:11 +00:00
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
return parse_header();
|
2019-05-12 08:59:11 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
|
|
|
|
// ready to start reading samples
|
|
|
|
switch (d_bits_per_sample)
|
2019-05-12 08:59:11 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
case 2:
|
|
|
|
switch (d_channel_selector)
|
2019-05-12 08:59:11 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
case 0:
|
|
|
|
// dual channel 2 bits per complex sample
|
|
|
|
// todo: implement dual channel reader
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// single channel 2 bits per complex sample (1 bit I + 1 bit Q, 8 samples per int16)
|
|
|
|
int n_int16_to_read = noutput_items / 8;
|
2019-05-12 08:59:11 +00:00
|
|
|
if (n_int16_to_read > 0)
|
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
std::vector<int16_t> memblock(n_int16_to_read);
|
|
|
|
binary_input_file.read(reinterpret_cast<char *>(memblock.data()), n_int16_to_read * 2);
|
|
|
|
n_int16_to_read = static_cast<int>(binary_input_file.gcount()) / 2; // from bytes to int16
|
|
|
|
if (n_int16_to_read > 0)
|
2019-05-12 08:59:11 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
int output_pointer = 0;
|
|
|
|
for (int i = 0; i < n_int16_to_read; i++)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
decode_samples_one_channel(memblock[i], out[0] + output_pointer, d_bits_per_sample);
|
2021-03-11 21:13:23 +00:00
|
|
|
output_pointer += 8;
|
|
|
|
}
|
|
|
|
return output_pointer;
|
2019-05-12 08:59:11 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 21:13:23 +00:00
|
|
|
// trigger the read of the next file in the sequence
|
|
|
|
d_current_file_number++;
|
|
|
|
if (d_labsat_version == 3)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "End of current file, reading the next LabSat file in sequence: " << generate_filename() << '\n';
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
binary_input_file.close();
|
|
|
|
binary_input_file.open(generate_filename().c_str(), std::ios::in | std::ios::binary);
|
|
|
|
if (binary_input_file.is_open())
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
std::cout << "LabSat file source is reading samples from " << generate_filename() << '\n';
|
2021-03-11 21:13:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d_labsat_version == 3)
|
|
|
|
{
|
|
|
|
std::cout << "Last file reached, LabSat source stop\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "End of file reached, LabSat source stop\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
d_queue->push(pmt::make_any(command_event_make(200, 0)));
|
|
|
|
return -1;
|
2019-05-12 08:59:11 +00:00
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
else
|
2019-05-12 08:59:11 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
switch (d_channel_selector)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
// dual channel
|
|
|
|
// todo: implement dual channel reader
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// single channel 4 bits per complex sample (2 bit I + 2 bit Q, 4 samples per int16)
|
|
|
|
int n_int16_to_read = noutput_items / 4;
|
|
|
|
if (n_int16_to_read > 0)
|
2019-08-04 11:15:03 +00:00
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
std::vector<int16_t> memblock(n_int16_to_read);
|
|
|
|
binary_input_file.read(reinterpret_cast<char *>(memblock.data()), n_int16_to_read * 2);
|
|
|
|
n_int16_to_read = static_cast<int>(binary_input_file.gcount()) / 2; // from bytes to int16
|
|
|
|
if (n_int16_to_read > 0)
|
|
|
|
{
|
|
|
|
int output_pointer = 0;
|
|
|
|
for (int i = 0; i < n_int16_to_read; i++)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
decode_samples_one_channel(memblock[i], out[0] + output_pointer, d_bits_per_sample);
|
2021-03-11 21:13:23 +00:00
|
|
|
output_pointer += 4;
|
|
|
|
}
|
|
|
|
return output_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// trigger the read of the next file in the sequence
|
|
|
|
d_current_file_number++;
|
|
|
|
if (d_labsat_version == 3)
|
|
|
|
{
|
|
|
|
std::cout << "End of current file, reading the next Labsat file in sequence: " << generate_filename() << '\n';
|
|
|
|
}
|
|
|
|
binary_input_file.close();
|
|
|
|
binary_input_file.open(generate_filename().c_str(), std::ios::in | std::ios::binary);
|
|
|
|
if (binary_input_file.is_open())
|
|
|
|
{
|
|
|
|
std::cout << "Labsat file source is reading samples from " << generate_filename() << '\n';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d_labsat_version == 3)
|
|
|
|
{
|
|
|
|
std::cout << "Last file reached, LabSat source stop\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "End of file reached, LabSat source stop\n";
|
|
|
|
}
|
|
|
|
d_queue->push(pmt::make_any(command_event_make(200, 0)));
|
|
|
|
return -1;
|
2019-08-04 11:15:03 +00:00
|
|
|
}
|
2019-05-12 08:59:11 +00:00
|
|
|
else
|
|
|
|
{
|
2021-03-11 21:13:23 +00:00
|
|
|
return 0;
|
2019-05-12 08:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-11 21:13:23 +00:00
|
|
|
break;
|
|
|
|
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)
|
2019-05-12 08:59:11 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2021-03-14 19:00:18 +00:00
|
|
|
std::size_t output_pointer = 0;
|
2021-03-11 21:13:23 +00:00
|
|
|
for (int i = 0; i < registers_to_read; i++)
|
|
|
|
{
|
|
|
|
uint64_t read_register = 0ULL;
|
2022-09-20 14:16:02 +00:00
|
|
|
// Labsat3W writes its 64-bit shift register to files in little endian. Read and convert to host endianness.
|
2022-12-05 14:02:35 +00:00
|
|
|
#if HAS_BOOST_ENDIAN
|
2022-09-20 14:16:02 +00:00
|
|
|
binary_input_file.read(reinterpret_cast<char *>(&read_register), sizeof(read_register));
|
|
|
|
boost::endian::little_to_native_inplace(read_register);
|
2022-12-05 14:02:35 +00:00
|
|
|
#else
|
|
|
|
std::array<char, 8> 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
|
2021-03-11 21:13:23 +00:00
|
|
|
|
|
|
|
if (binary_input_file.gcount() == 8)
|
|
|
|
{
|
2021-03-14 19:00:18 +00:00
|
|
|
decode_ls3w_register(read_register, out, output_pointer);
|
2021-03-11 21:13:23 +00:00
|
|
|
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;
|
2019-05-12 08:59:11 +00:00
|
|
|
}
|
2018-01-23 16:31:42 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "Warning!!\n";
|
2018-01-23 16:31:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|