1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 12:40:35 +00:00

Fix GSS6450 signal source

This commit is contained in:
Antonio Ramos 2018-01-18 16:57:15 +01:00
parent 282c3d8659
commit 4873ea2b88
4 changed files with 153 additions and 173 deletions

View File

@ -1,12 +1,12 @@
/*!
* \file spir_file_signal_source.cc
* \file spir_gss6450_file_signal_source.cc
* \brief Implementation of a class that reads signals samples from a SPIR file
* and adapts it to a SignalSourceInterface.
* \author Fran Fabra, 2014 fabra(at)ice.csic.es
* \author Antonio Ramos, 2017 antonio.ramos(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
@ -35,16 +35,11 @@
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include "configuration_interface.h"
using google::LogMessage;
DEFINE_string(spir_gss6450_signal_source, "-",
"If defined, path to the file containing the Spirent GSS6450 signal samples (overrides the configuration file)");
SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface* configuration,
std::string role, unsigned int in_streams, unsigned int out_streams, gr::msg_queue::sptr queue) :
@ -55,31 +50,35 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface*
item_type_ = "int";
samples_ = configuration->property(role + ".samples", 0);
sampling_frequency_ = configuration->property(role + ".sampling_frequency", 0);
sampling_frequency_ = configuration->property(role + ".sampling_frequency", 0.0);
filename_ = configuration->property(role + ".filename", default_filename);
// override value with commandline flag, if present
if (FLAGS_spir_gss6450_signal_source.compare("-") != 0) filename_= FLAGS_spir_gss6450_signal_source;
repeat_ = configuration->property(role + ".repeat", false);
dump_ = configuration->property(role + ".dump", false);
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_filename);
enable_throttle_control_ = configuration->property(role + ".enable_throttle_control", false);
adc_bits_ = configuration->property(role + ".adc_bits", 4);
n_channels_ = configuration->property(role + ".RF_channels", 1);
n_channels_ = configuration->property(role + ".total_channels", 1);
sel_ch_ = configuration->property(role + ".sel_ch", 1);
item_size_ = sizeof(int);
long bytes_seek = 65536;
long bytes_seek = configuration->property(role + ".bytes_to_skip", 65536);
double sample_size_byte = static_cast<double>(adc_bits_) / 4.0;
int samples_per_item = 16 / adc_bits_;
if(sel_ch_ > n_channels_) { LOG(WARNING) << "Invalid RF channel selection"; }
if(n_channels_ > 1)
{
for(unsigned int i = 0; i < (n_channels_ - 1); i++)
{
null_sinks_.push_back(gr::blocks::null_sink::make(item_size_));
}
std::cout << "NUMBER OF NULL SINKS = " << null_sinks_.size() << std::endl;
}
try
{
file_source_ = gr::blocks::file_source::make(item_size_, filename_.c_str(), repeat_);
file_source_->seek(bytes_seek, SEEK_SET);
unpack_ii_ = gr::blocks::packed_to_unpacked_ii::make(adc_bits_, gr::GR_MSB_FIRST);
unpack_spir_ = make_unpack_spir_gss6450_samples(n_channels_, sel_ch_, samples_per_item, item_size_);
file_source_ = gr::blocks::file_source::make(item_size_, filename_.c_str(), repeat_);
file_source_->seek(bytes_seek / item_size_, SEEK_SET);
unpack_spir_ = make_unpack_spir_gss6450_samples(adc_bits_);
deint_ = gr::blocks::deinterleave::make(item_size_);
endian_ = gr::blocks::endian_swap::make(item_size_);
}
catch (const std::exception &e)
{
@ -103,14 +102,13 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface*
<< filename_.c_str() << ", exiting the program.";
throw(e);
}
DLOG(INFO) << "file_source(" << file_source_->unique_id() << ")";
if(samples_ == 0) // read all file
{
/*!
* BUG workaround: The GNU Radio file source does not stop the receiver after reaching the End of File.
* A possible solution is to compute the file length in samples using file size, excluding the last 100 milliseconds, and enable always the
* A possible solution is to compute the file length in samples using file size, excluding the last 2 milliseconds, and enable always the
* valve block
*/
std::ifstream file (filename_.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
@ -119,7 +117,7 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface*
if (file.is_open())
{
size = file.tellg();
LOG(INFO) << "Total samples in the file= " << floor(static_cast<double>(size) / static_cast<double>(item_size()));
LOG(INFO) << "Total samples in the file= " << floor(static_cast<double>(size) / static_cast<double>(item_size_));
}
else
{
@ -133,13 +131,13 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface*
if(size > 0)
{
samples_ = floor(static_cast<double>(size - bytes_seek) / (sample_size_byte * static_cast<double>(n_channels_)));
samples_ = samples_- ceil(0.002 * static_cast<double>(sampling_frequency_)); //process all the samples available in the file excluding the last 2 ms
samples_ = static_cast<unsigned long long>(floor(static_cast<double>(size - bytes_seek) / (sample_size_byte * static_cast<double>(n_channels_))));
samples_ = samples_- static_cast<unsigned long long>(ceil(0.002 * sampling_frequency_)); //process all the samples available in the file excluding the last 2 ms
}
}
CHECK(samples_ > 0) << "File does not contain enough samples to process.";
double signal_duration_s = static_cast<double>(samples_) * ( 1 /static_cast<double>(sampling_frequency_));
double signal_duration_s = static_cast<double>(samples_) / sampling_frequency_;
LOG(INFO) << "Total number samples to be processed= " << samples_ << " GNSS signal duration= " << signal_duration_s << " [s]";
std::cout << "GNSS signal recorded time to be processed: " << signal_duration_s << " [s]" << std::endl;
@ -149,9 +147,9 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface*
if (dump_)
{
sink_ = gr::blocks::file_sink::make(sizeof(gr_complex), dump_filename_.c_str());
//sink_test = gr::blocks::file_sink::make(sizeof(int), "/home/aramos/Escritorio/test_int.dat");
DLOG(INFO) << "file_sink(" << sink_->unique_id() << ")";
}
if (enable_throttle_control_)
{
throttle_ = gr::blocks::throttle::make(sizeof(gr_complex), sampling_frequency_);
@ -167,36 +165,46 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface*
}
SpirGSS6450FileSignalSource::~SpirGSS6450FileSignalSource()
{}
void SpirGSS6450FileSignalSource::connect(gr::top_block_sptr top_block)
{
if (samples_ > 0)
{
top_block->connect(file_source_, 0, deint_, 0);
/*
top_block->connect(deint_, sel_ch_ - 1, endian_ ,0);
top_block->connect(endian_, 0, unpack_spir_, 0);
*/
top_block->connect(deint_, sel_ch_ - 1, unpack_spir_, 0);
if(n_channels_ > 1)
{
unsigned int aux = 0;
for(unsigned int i = 0; i < n_channels_; i++)
{
if(i != (sel_ch_ - 1))
{
top_block->connect(deint_, i, null_sinks_.at(aux), 0);
aux++;
}
}
}
if (enable_throttle_control_)
{
top_block->connect(file_source_, 0, unpack_ii_, 0);
top_block->connect(unpack_ii_, 0, unpack_spir_, 0);
top_block->connect(unpack_spir_, 0, throttle_, 0);
top_block->connect(throttle_, 0, valve_, 0);
}
else
{
top_block->connect(file_source_, 0, unpack_ii_, 0);
top_block->connect(unpack_ii_, 0, unpack_spir_, 0);
top_block->connect(unpack_spir_, 0, valve_, 0);
}
if(dump_)
{
top_block->connect(valve_, 0, sink_, 0);
DLOG(INFO) << "connected valve to file sink";
}
{
top_block->connect(valve_, 0, sink_, 0);
//top_block->connect(deint_, sel_ch_ - 1, sink_test, 0);
}
}
else
{
@ -205,40 +213,43 @@ void SpirGSS6450FileSignalSource::connect(gr::top_block_sptr top_block)
}
void SpirGSS6450FileSignalSource::disconnect(gr::top_block_sptr top_block)
{
if (samples_ > 0)
{
top_block->disconnect(file_source_, 0, deint_, 0);
top_block->disconnect(deint_, sel_ch_ - 1, unpack_spir_, 0);
if(n_channels_ > 1)
{
if (enable_throttle_control_)
unsigned int aux = 0;
for(unsigned int i = 0; i < n_channels_; i++)
{
if(i != (sel_ch_ - 1))
{
top_block->disconnect(file_source_, 0, unpack_ii_, 0);
top_block->disconnect(unpack_ii_, 0, unpack_spir_, 0);
top_block->disconnect(unpack_spir_, 0, throttle_, 0);
top_block->disconnect(throttle_, 0, valve_, 0);
if (dump_)
{
top_block->disconnect(valve_, 0, sink_, 0);
}
}
else
{
top_block->disconnect(file_source_, 0, unpack_ii_, 0);
top_block->disconnect(unpack_ii_, 0, unpack_spir_, 0);
top_block->disconnect(unpack_spir_, 0, valve_, 0);
if (dump_)
{
top_block->disconnect(valve_, 0, sink_, 0);
}
top_block->disconnect(deint_, i, null_sinks_.at(aux), 0);
aux++;
}
}
}
if (enable_throttle_control_)
{
top_block->disconnect(unpack_spir_, 0, throttle_, 0);
top_block->disconnect(throttle_, 0, valve_, 0);
}
else
{
top_block->disconnect(unpack_spir_, 0, valve_, 0);
}
if(dump_)
{
top_block->disconnect(valve_, 0, sink_, 0);
//top_block->disconnect(deint_, sel_ch_ - 1, sink_test, 0);
}
}
else
{
LOG(WARNING) << "Nothing to disconnect";
}
{
LOG(WARNING) << "Nothing to disconnect";
}
}

View File

@ -1,12 +1,12 @@
/*!
* \file spir_file_signal_source.h
* \file spir_gss6450_file_signal_source.h
* \brief Implementation of a class that reads signals samples from a SPIR file
* and adapts it to a SignalSourceInterface.
* \author Fran Fabra, 2014 fabra(at)ice.csic.es
* \author Antonio Ramos, 2017 antonio.ramos(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
@ -33,10 +33,14 @@
#define GNSS_SDR_SPIR_GSS6450_FILE_SIGNAL_SOURCE_H_
#include <string>
#include <vector>
#include <gnuradio/blocks/file_source.h>
#include <gnuradio/blocks/file_sink.h>
#include <gnuradio/blocks/throttle.h>
#include <gnuradio/blocks/packed_to_unpacked_ii.h>
#include <gnuradio/blocks/deinterleave.h>
#include <gnuradio/blocks/null_sink.h>
#include <gnuradio/blocks/endian_swap.h>
#include <gnuradio/hier_block2.h>
#include <gnuradio/msg_queue.h>
#include "gnss_block_interface.h"
@ -104,10 +108,11 @@ public:
private:
unsigned long long samples_;
long sampling_frequency_;
double sampling_frequency_;
std::string filename_;
bool repeat_;
bool dump_;
bool enable_throttle_control_;
std::string dump_filename_;
std::string role_;
std::string item_type_;
@ -117,14 +122,16 @@ private:
unsigned int n_channels_;
unsigned int sel_ch_;
gr::blocks::file_source::sptr file_source_;
gr::blocks::packed_to_unpacked_ii::sptr unpack_ii_;
gr::blocks::deinterleave::sptr deint_;
gr::blocks::endian_swap::sptr endian_;
std::vector<gr::blocks::null_sink::sptr> null_sinks_;
unpack_spir_gss6450_samples_sptr unpack_spir_;
boost::shared_ptr<gr::block> valve_;
gr::blocks::file_sink::sptr sink_;
gr::blocks::file_sink::sptr sink_test;
gr::blocks::throttle::sptr throttle_;
gr::msg_queue::sptr queue_;
size_t item_size_;
bool enable_throttle_control_;
};
#endif /*GNSS_SDR_SPIR_GSS6450_FILE_SIGNAL_SOURCE_H_*/

View File

@ -34,123 +34,90 @@
unpack_spir_gss6450_samples_sptr make_unpack_spir_gss6450_samples(unsigned int n_chann, unsigned int sel_ch, int samp_item, size_t item_size)
unpack_spir_gss6450_samples_sptr make_unpack_spir_gss6450_samples(unsigned int adc_nbit)
{
return unpack_spir_gss6450_samples_sptr(new unpack_spir_gss6450_samples(n_chann, sel_ch, samp_item, item_size));
return unpack_spir_gss6450_samples_sptr(new unpack_spir_gss6450_samples(adc_nbit));
}
unpack_spir_gss6450_samples::unpack_spir_gss6450_samples(
unsigned int n_chann, unsigned int sel_ch, int samp_item, size_t item_size) : gr::block("unpack_spir_gss6450_samples",
unpack_spir_gss6450_samples::unpack_spir_gss6450_samples(unsigned int adc_nbit) : gr::sync_interpolator("unpack_spir_gss6450_samples",
gr::io_signature::make(1, 1, sizeof(int)),
gr::io_signature::make(1, 1, sizeof(gr_complex)))
gr::io_signature::make(1, 1, sizeof(gr_complex)), 16 / adc_nbit)
{
d_channels = n_chann;
d_sel_ch = sel_ch;
item_size_ = item_size;
ch_processing = 1;
d_samp_item = samp_item;
samp_frame = 0;
adc_bits = 16 / d_samp_item;
i_ = true;
new_sample = false;
adc_bits = adc_nbit;
i_data = 0;
q_data = 0;
samples_per_int = 16 / adc_bits;
if(adc_bits == 2)
{
mask_data = 0x00000003;
map_ = {0, 1, -2, -1};
}
else
{
mask_data = 0x0000000F;
map_ = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1};
}
}
unpack_spir_gss6450_samples::~unpack_spir_gss6450_samples()
{}
void unpack_spir_gss6450_samples::process_sample(gr_complex* out)
void unpack_spir_gss6450_samples::process_sample(gr_complex& out)
{
gr_complex result = gr_complex(0.5, 0.5);
out = gr_complex(0.5, 0.5);
compute_two_complement(i_data);
compute_two_complement(q_data);
result += gr_complex(static_cast<float>(i_data), static_cast<float>(q_data));
*out = result;
out += gr_complex(static_cast<float>(i_data), static_cast<float>(q_data));
}
int unpack_spir_gss6450_samples::general_work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
int unpack_spir_gss6450_samples::work(int noutput_items,
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
{
const int* in = reinterpret_cast<const int*>(input_items[0]);
gr_complex* out = reinterpret_cast<gr_complex*>(output_items[0]);
int samples_produced = 0;
unsigned int n_sample = 0;
unsigned int in_counter = 0;
for(int i = 0; i < noutput_items; i++)
{
if(ch_processing == d_sel_ch)
int sample_aux = in[in_counter];
//reverse_bits(sample_aux);
int aux_i = sample_aux;
int aux_q = sample_aux;
int i_shift = adc_bits * 2 * (samples_per_int - n_sample - 1) + adc_bits;
int q_shift = adc_bits * 2 * (samples_per_int - n_sample - 1);
i_data = (aux_i >> i_shift) & mask_data;
q_data = (aux_q >> q_shift) & mask_data;
process_sample(out[samples_per_int * in_counter + samples_per_int - n_sample - 1]);
n_sample++;
if(n_sample == samples_per_int)
{
if(i_)
{
i_data = in[i];
swap_data(i_data);
i_ = false;
}
else
{
q_data = in[i];
swap_data(q_data);
i_ = true;
process_sample(out);
out++;
samples_produced++;
new_sample = true;
}
}
else
{
if(i_) { i_ = false;}
else
{
i_ = true;
new_sample = true;
}
}
if(new_sample)
{
new_sample = false;
samp_frame++;
if(samp_frame == d_samp_item)
{
samp_frame = 0;
ch_processing++;
if(ch_processing > d_channels) { ch_processing = 1; }
}
n_sample = 0;
in_counter++;
}
}
consume_each(noutput_items);
return samples_produced;
return noutput_items;
}
void unpack_spir_gss6450_samples::swap_data(int& data)
void unpack_spir_gss6450_samples::reverse_bits(int& data)
{
int result = 0;
int aux = data;
int mask = 1;
for (int i = 0; i < adc_bits; i++)
unsigned int v = data; // input bits to be reversed
unsigned int r = v; // r will be reversed bits of v; first get LSB of v
int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end
for (v >>= 1; v; v >>= 1)
{
result = result << 1;
result += (aux & mask);
aux = aux >> 1;
r <<= 1;
r |= v & 1;
s--;
}
data = result;
r <<= s; // shift when v's highest bits are zero
data = r;
}
void unpack_spir_gss6450_samples::compute_two_complement(int& data)
{
int result = 0;
int mask = 1;
for(int i = 0; i < (adc_bits - 1); i++)
{
result = result << 1;
result += (data >> i) & mask;
}
if((data >> (adc_bits - 1)) == 1)
{
if(adc_bits == 2) { result -= 2; }
else { result -= 8; }
}
data = result;
data = map_[data];
}

View File

@ -31,40 +31,35 @@
#ifndef GNSS_SDR_UNPACK_SPIR_GSS6450_SAMPLES_H
#define GNSS_SDR_UNPACK_SPIR_GSS6450_SAMPLES_H
#include <gnuradio/block.h>
#include <gnuradio/sync_interpolator.h>
#include <vector>
class unpack_spir_gss6450_samples;
typedef boost::shared_ptr<unpack_spir_gss6450_samples> unpack_spir_gss6450_samples_sptr;
unpack_spir_gss6450_samples_sptr make_unpack_spir_gss6450_samples(unsigned int n_chann, unsigned int sel_ch, int samp_item, size_t item_size);
unpack_spir_gss6450_samples_sptr make_unpack_spir_gss6450_samples(unsigned int adc_nbit);
class unpack_spir_gss6450_samples: public gr::block
class unpack_spir_gss6450_samples: public gr::sync_interpolator
{
public:
int general_work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
friend unpack_spir_gss6450_samples_sptr make_unpack_spir_gss6450_samples_sptr(unsigned int n_chann, unsigned int sel_ch, int samp_item, size_t item_size);
unpack_spir_gss6450_samples(unsigned int n_chann, unsigned int sel_ch, int samp_item, size_t item_size);
int work(int noutput_items,
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
friend unpack_spir_gss6450_samples_sptr make_unpack_spir_gss6450_samples_sptr(unsigned int adc_nbit);
unpack_spir_gss6450_samples(unsigned int adc_nbit);
~unpack_spir_gss6450_samples();
private:
unsigned int d_channels;
unsigned int d_sel_ch;
unsigned int ch_processing;
int d_samp_item;
int samp_frame;
int adc_bits;
size_t item_size_;
void process_sample(gr_complex* out);
void swap_data(int& data);
unsigned int adc_bits;
unsigned int samples_per_int;
void process_sample(gr_complex& out);
void compute_two_complement(int& data);
bool i_;
bool new_sample;
void reverse_bits(int& data);
int i_data;
int q_data;
int mask_data;
std::vector<int> map_;
};
#endif