From 130261461335874626b2da1db5895c5033251517 Mon Sep 17 00:00:00 2001 From: Javier Arribas Date: Thu, 29 Nov 2018 17:53:01 +0100 Subject: [PATCH] Improving SPIR GSS6450 signal source --- .../spir_gss6450_file_signal_source.cc | 3 +- .../unpack_spir_gss6450_samples.cc | 112 ++++++++++++------ .../unpack_spir_gss6450_samples.h | 9 +- 3 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/algorithms/signal_source/adapters/spir_gss6450_file_signal_source.cc b/src/algorithms/signal_source/adapters/spir_gss6450_file_signal_source.cc index 8b124a3fd..874cbe2f8 100644 --- a/src/algorithms/signal_source/adapters/spir_gss6450_file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/spir_gss6450_file_signal_source.cc @@ -153,7 +153,8 @@ SpirGSS6450FileSignalSource::SpirGSS6450FileSignalSource(ConfigurationInterface* valve_vec_.push_back(gnss_sdr_make_valve(sizeof(gr_complex), samples_, queue_)); if (dump_) { - sink_vec_.push_back(gr::blocks::file_sink::make(sizeof(gr_complex), dump_filename_.c_str())); + std::string tmp_str = dump_filename_ + "_ch" + std::to_string(i); + sink_vec_.push_back(gr::blocks::file_sink::make(sizeof(gr_complex), tmp_str.c_str())); } if (enable_throttle_control_) { diff --git a/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.cc b/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.cc index 84d7ad0fc..8722288d3 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.cc @@ -3,6 +3,7 @@ * * \brief Unpacks SPIR int samples * \author Antonio Ramos, antonio(at)cttc.es + * \author Javier Arribas jarribas (at) cttc.es * ------------------------------------------------------------------------- * * Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors) @@ -45,10 +46,6 @@ unpack_spir_gss6450_samples::unpack_spir_gss6450_samples(unsigned int adc_nbit) { adc_bits = adc_nbit; samples_per_int = 16 / adc_bits; - i_data.resize(adc_bits, false); - q_data.resize(adc_bits, false); - adc_bits_two_pow = static_cast(std::exp2(adc_bits)); - two_compl_thres = adc_bits_two_pow / 2; } @@ -56,50 +53,87 @@ unpack_spir_gss6450_samples::~unpack_spir_gss6450_samples() { } - -int unpack_spir_gss6450_samples::compute_two_complement(unsigned long data) +void unpack_spir_gss6450_samples::decode_4bits_word(uint32_t input_uint32, gr_complex* out, int adc_bits) { - int res = 0; - if (static_cast(data) < two_compl_thres) + int8_t tmp_char; + float Q; + float I; + switch (adc_bits) { - res = static_cast(data); - } - else - { - res = static_cast(data) - adc_bits_two_pow; - } - return res; -} + case 2: + //four bits per complex sample (2 I + 2 Q), 8 samples per int32[s0,s1,s2,s3,s4,s5,s6,s7] + for (int i = 0; i < 8; i++) + { + tmp_char = input_uint32 & 3; + if (tmp_char >= 2) + { + I = (tmp_char - 4); + } + else + { + I = tmp_char; + } + input_uint32 = input_uint32 >> 2; + tmp_char = input_uint32 & 3; + if (tmp_char >= 2) + { + Q = (tmp_char - 4); + } + else + { + Q = tmp_char; + } + input_uint32 = input_uint32 >> 2; + + out[7 - i] = gr_complex(I, Q); + } + break; + case 4: + //eight bits per complex sample (4 I + 4 Q), 4 samples per int32= [s0,s1,s2,s3] + for (int i = 0; i < 4; i++) + { + tmp_char = input_uint32 & 0x0F; + + if (tmp_char >= 8) + { + I = (tmp_char - 16); + } + else + { + I = tmp_char; + } + input_uint32 = input_uint32 >> 4; + tmp_char = input_uint32 & 0x0F; + if (tmp_char >= 8) + { + Q = (tmp_char - 16); + } + else + { + Q = tmp_char; + } + input_uint32 = input_uint32 >> 4; + + out[3 - i] = gr_complex(I, Q); + } + break; + } +} 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(input_items[0]); + const int32_t* in = reinterpret_cast(input_items[0]); gr_complex* out = reinterpret_cast(output_items[0]); - unsigned int n_sample = 0; - unsigned int in_counter = 0; - std::bitset<32> bs; - for (int i = 0; i < noutput_items; i++) + int n_sample = 0; + int in_counter = 0; + do { - bs = in[in_counter]; - 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); - for (unsigned int k = 0; k < adc_bits; k++) - { - i_data[k] = bs[i_shift + k]; - q_data[k] = bs[q_shift + k]; - } - //out[i] = gr_complex(static_cast(compute_two_complement(i_data.to_ulong())) + 0.5, - // static_cast(compute_two_complement(q_data.to_ulong())) + 0.5); - out[i] = gr_complex(static_cast(compute_two_complement(q_data.to_ulong())) + 0.5, - static_cast(compute_two_complement(i_data.to_ulong())) + 0.5); - n_sample++; - if (n_sample == samples_per_int) - { - n_sample = 0; - in_counter++; - } + decode_4bits_word(in[in_counter++], &out[n_sample], adc_bits); + n_sample += samples_per_int; } + while (n_sample < noutput_items); + return noutput_items; } diff --git a/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.h b/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.h index a604982f1..a8f4b47f9 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.h +++ b/src/algorithms/signal_source/gnuradio_blocks/unpack_spir_gss6450_samples.h @@ -3,6 +3,7 @@ * * \brief Unpacks SPIR int samples * \author Antonio Ramos, antonio.ramos(at)cttc.es + * \author Javier Arribas jarribas (at) cttc.es * ------------------------------------------------------------------------- * * Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors) @@ -32,7 +33,6 @@ #define GNSS_SDR_UNPACK_SPIR_GSS6450_SAMPLES_H #include -#include class unpack_spir_gss6450_samples; @@ -47,18 +47,13 @@ public: 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); + void decode_4bits_word(uint32_t input_int32, gr_complex *out, int adc_bits); unpack_spir_gss6450_samples(unsigned int adc_nbit); ~unpack_spir_gss6450_samples(); private: - int compute_two_complement(unsigned long data); - unsigned int adc_bits; unsigned int samples_per_int; - int two_compl_thres; - int adc_bits_two_pow; - boost::dynamic_bitset<> i_data; - boost::dynamic_bitset<> q_data; }; #endif