1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-10-30 14:53:03 +00:00

New feature: GNSS-SDR now reads the IFEN NSR 2bit sample file format. The GNSS-SDR receiver can now be used with the SX-NSR scientific navigation front-end receiver using its native .stream binary captures.

More information of this high-end front-end can be found here:  http://www.ifen.com/products/sx-scientific-gnss-solutions/nsr-software-receiver.html


git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@421 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Javier Arribas
2013-10-14 16:51:47 +00:00
parent 025a24bb20
commit ee43872704
13 changed files with 1086 additions and 16 deletions

View File

@@ -32,7 +32,6 @@
#include "configuration_interface.h"
#include <string>
#include <boost/lexical_cast.hpp>
//#include <gnuradio/io_signature.h>
#include <gnuradio/blocks/file_sink.h>
#include <gnuradio/filter/pm_remez.h>
#include <glog/log_severity.h>
@@ -55,14 +54,24 @@ FreqXlatingFirFilter::FreqXlatingFirFilter(ConfigurationInterface* configuration
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
item_size = sizeof(gr_complex);
item_size = sizeof(gr_complex); //output
input_size_=sizeof(gr_complex); //input
freq_xlating_fir_filter_ccf_ = gr::filter::freq_xlating_fir_filter_ccf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_ccf_->unique_id() << ")";
}
else if((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("float") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
item_size = sizeof(gr_complex);
input_size_=sizeof(float); //input
freq_xlating_fir_filter_fcf_ = gr::filter::freq_xlating_fir_filter_fcf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_fcf_->unique_id() << ")";
}
else
{
LOG_AT_LEVEL(ERROR) << taps_item_type_ << " unknown input filter item type";
}
if (dump_)
{
DLOG(INFO) << "Dumping output into file " << dump_filename_;
@@ -82,7 +91,12 @@ void FreqXlatingFirFilter::connect(gr::top_block_sptr top_block)
{
if (dump_)
{
top_block->connect(freq_xlating_fir_filter_ccf_, 0, file_sink_, 0);
if (input_size_==sizeof(float))
{
top_block->connect(freq_xlating_fir_filter_fcf_, 0, file_sink_, 0);
}else{
top_block->connect(freq_xlating_fir_filter_ccf_, 0, file_sink_, 0);
}
}
else
{
@@ -96,7 +110,12 @@ void FreqXlatingFirFilter::disconnect(gr::top_block_sptr top_block)
{
if (dump_)
{
top_block->connect(freq_xlating_fir_filter_ccf_, 0, file_sink_, 0);
if (input_size_==sizeof(float))
{
top_block->disconnect(freq_xlating_fir_filter_fcf_, 0, file_sink_, 0);
}else{
top_block->disconnect(freq_xlating_fir_filter_ccf_, 0, file_sink_, 0);
}
}
}
@@ -104,13 +123,24 @@ void FreqXlatingFirFilter::disconnect(gr::top_block_sptr top_block)
gr::basic_block_sptr FreqXlatingFirFilter::get_left_block()
{
return freq_xlating_fir_filter_ccf_;
if (input_size_==sizeof(float))
{
return freq_xlating_fir_filter_fcf_;
}else{
return freq_xlating_fir_filter_ccf_;
}
}
gr::basic_block_sptr FreqXlatingFirFilter::get_right_block()
{
return freq_xlating_fir_filter_ccf_;
if (input_size_==sizeof(float))
{
return freq_xlating_fir_filter_fcf_;
}else{
return freq_xlating_fir_filter_ccf_;
}
}

View File

@@ -36,6 +36,7 @@
#include "gnss_synchro.h"
#include "gnss_block_interface.h"
#include <gnuradio/filter/freq_xlating_fir_filter_ccf.h>
#include <gnuradio/filter/freq_xlating_fir_filter_fcf.h>
#include <gnuradio/blocks/file_sink.h>
#include <gnuradio/msg_queue.h>
@@ -82,10 +83,12 @@ public:
private:
gr::filter::freq_xlating_fir_filter_ccf::sptr freq_xlating_fir_filter_ccf_;
gr::filter::freq_xlating_fir_filter_fcf::sptr freq_xlating_fir_filter_fcf_;
ConfigurationInterface* config_;
bool dump_;
std::string dump_filename_;
std::string input_item_type_;
size_t input_size_;
std::string output_item_type_;
std::string taps_item_type_;
std::vector <float> taps_;

View File

@@ -17,4 +17,4 @@
#
add_subdirectory(adapters)
#add_subdirectory(gnuradio_blocks)
add_subdirectory(gnuradio_blocks)

View File

@@ -74,7 +74,7 @@ if(RTLSDR_DRIVER)
set(OPT_DRIVER_INCLUDE_DIRS ${OPT_DRIVER_INCLUDE_DIRS} ${RTL_DRIVER_INCLUDE_DIRS})
endif(RTLSDR_DRIVER)
set(SIGNAL_SOURCE_ADAPTER_SOURCES file_signal_source.cc gen_signal_source.cc uhd_signal_source.cc ${OPT_DRIVER_SOURCES})
set(SIGNAL_SOURCE_ADAPTER_SOURCES file_signal_source.cc gen_signal_source.cc uhd_signal_source.cc nsr_file_signal_source.cc ${OPT_DRIVER_SOURCES})
include_directories(
@@ -83,6 +83,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/core/system_parameters
${CMAKE_SOURCE_DIR}/src/core/interfaces
${CMAKE_SOURCE_DIR}/src/algorithms/libs
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/gnuradio_blocks
${UHD_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS}
${GFlags_INCLUDE_DIRS}
@@ -90,4 +91,4 @@ include_directories(
)
add_library(signal_source_adapters ${SIGNAL_SOURCE_ADAPTER_SOURCES})
target_link_libraries(signal_source_adapters ${Boost_LIBRARIES} ${GNURADIO_PMT_LIBRARIES} ${GNURADIO_BLOCKS_LIBRARIES} ${UHD_LIBRARIES} ${GNURADIO_UHD_LIBRARIES} ${OPT_LIBRARIES} gnss_sp_libs)
target_link_libraries(signal_source_adapters signal_source_gr_blocks ${Boost_LIBRARIES} ${GNURADIO_PMT_LIBRARIES} ${GNURADIO_BLOCKS_LIBRARIES} ${UHD_LIBRARIES} ${GNURADIO_UHD_LIBRARIES} ${OPT_LIBRARIES} gnss_sp_libs)

View File

@@ -36,11 +36,8 @@
#define GNSS_SDR_FILE_SIGNAL_SOURCE_H_
#include "gnss_block_interface.h"
//#include <gnuradio/gr_file_source.h>
#include <gnuradio/blocks/file_source.h>
//#include <gnuradio/gr_file_sink.h>
#include <gnuradio/blocks/file_sink.h>
//#include <gnuradio/gr_throttle.h>
#include <gnuradio/blocks/throttle.h>
#include <gnuradio/hier_block2.h>
#include <gnuradio/msg_queue.h>
@@ -101,7 +98,7 @@ public:
}
private:
long samples_;
unsigned long long samples_;
long sampling_frequency_;
std::string filename_;
std::string item_type_;
@@ -111,12 +108,9 @@ private:
std::string role_;
unsigned int in_streams_;
unsigned int out_streams_;
// gr_file_source_sptr file_source_;
gr::blocks::file_source::sptr file_source_;
//gr_block_sptr valve_;
boost::shared_ptr<gr::block> valve_;
gr::blocks::file_sink::sptr sink_;
// gr_block_sptr throttle_;
gr::blocks::throttle::sptr throttle_;
boost::shared_ptr<gr::msg_queue> queue_;
size_t item_size_;

View File

@@ -0,0 +1,333 @@
/*!
* \file nsr_file_signal_source.cc
* \brief Implementation of a class that reads signals samples from a NSR 2 bits sampler front-end file
* and adapts it to a SignalSourceInterface. More information about the front-end here
* http://www.ifen.com/products/sx-scientific-gnss-solutions/nsr-software-receiver.html
* \author Javier Arribas, 2013 jarribas(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2013 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "nsr_file_signal_source.h"
#include "gnss_sdr_valve.h"
#include "configuration_interface.h"
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <exception>
#include <gflags/gflags.h>
#include <glog/log_severity.h>
#include <glog/logging.h>
using google::LogMessage;
DEFINE_string(nsr_signal_source, "-",
"If defined, path to the file containing the NSR (byte to 2-bit packed) signal samples (overrides the configuration file)");
NsrFileSignalSource::NsrFileSignalSource(ConfigurationInterface* configuration,
std::string role, unsigned int in_streams, unsigned int out_streams,
boost::shared_ptr<gr::msg_queue> queue) :
role_(role), in_streams_(in_streams), out_streams_(out_streams), queue_(queue)
{
std::string default_filename = "../data/my_capture.dat";
std::string default_item_type = "byte";
std::string default_dump_filename = "../data/my_capture_dump.dat";
samples_ = configuration->property(role + ".samples", 0);
sampling_frequency_ = configuration->property(role + ".sampling_frequency", 0);
filename_ = configuration->property(role + ".filename", default_filename);
// override value with commandline flag, if present
if (FLAGS_nsr_signal_source.compare("-") != 0) filename_= FLAGS_nsr_signal_source;
item_type_ = configuration->property(role + ".item_type", default_item_type);
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);
if (item_type_.compare("byte") == 0)
{
item_size_ = sizeof(char);
}
else
{
LOG_AT_LEVEL(WARNING) << item_type_
<< " unrecognized item type. Using byte.";
item_size_ = sizeof(char);
}
try
{
file_source_ = gr::blocks::file_source::make(item_size_, filename_.c_str(), repeat_);
unpack_byte_ = make_unpack_byte_2bit_samples();
}
catch (const std::exception &e)
{
std::cerr
<< "The receiver was configured to work with a file signal source "
<< std::endl
<< "but the specified file is unreachable by GNSS-SDR."
<< std::endl
<< "Please modify the configuration at "
<< "conf/gnss-sdr.conf (the default configuration file)"
<< std::endl
<< "and point SignalSource.filename to a valid file,"
<< std::endl
<< "or specify your own receiver and source with the flag"
<< std::endl
<<"gnss-sdr --config_file=my_GNSS_SDR_configuration.conf"
<< std::endl;
LOG_AT_LEVEL(INFO) << "file_signal_source: Unable to open the samples file "
<< 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
* valve block
*/
std::ifstream file (filename_.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
std::ifstream::pos_type size;
if (file.is_open())
{
size = file.tellg();
DLOG(INFO) << "Total samples in the file= " << floor((double)size / (double)item_size());
}
else
{
std::cout << "file_signal_source: Unable to open the samples file " << filename_.c_str() << std::endl;
LOG_AT_LEVEL(ERROR) << "file_signal_source: Unable to open the samples file " << filename_.c_str();
}
std::cout << std::setprecision(16);
std::cout << "Processing file " << filename_ << ", which contains " << (double)size << " [bytes]" << std::endl;
if (size > 0)
{
int sample_packet_factor=4; // 1 byte -> 4 samples
samples_ = floor((double)size / (double)item_size())*sample_packet_factor;
samples_=samples_- ceil(0.002 * (double)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;
signal_duration_s = (double)samples_ * ( 1 /(double)sampling_frequency_);
DLOG(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;
valve_ = gnss_sdr_make_valve(sizeof(float), samples_, queue_);
DLOG(INFO) << "valve(" << valve_->unique_id() << ")";
if (dump_)
{
//sink_ = gr_make_file_sink(item_size_, dump_filename_.c_str());
sink_ = gr::blocks::file_sink::make(sizeof(float), dump_filename_.c_str());
DLOG(INFO) << "file_sink(" << sink_->unique_id() << ")";
}
if (enable_throttle_control_)
{
throttle_ = gr::blocks::throttle::make(sizeof(float), sampling_frequency_);
}
DLOG(INFO) << "File source filename " << filename_;
DLOG(INFO) << "Samples " << samples_;
DLOG(INFO) << "Sampling frequency " << sampling_frequency_;
DLOG(INFO) << "Item type " << item_type_;
DLOG(INFO) << "Item size " << item_size_;
DLOG(INFO) << "Repeat " << repeat_;
DLOG(INFO) << "Dump " << dump_;
DLOG(INFO) << "Dump filename " << dump_filename_;
}
NsrFileSignalSource::~NsrFileSignalSource()
{}
void NsrFileSignalSource::connect(gr::top_block_sptr top_block)
{
if (samples_ > 0)
{
if (enable_throttle_control_ == true)
{
top_block->connect(file_source_, 0, unpack_byte_, 0);
top_block->connect(unpack_byte_, 0,throttle_,0);
DLOG(INFO) << "connected file source to throttle";
top_block->connect(throttle_, 0, valve_, 0);
DLOG(INFO) << "connected throttle to valve";
if (dump_)
{
top_block->connect(valve_, 0, sink_, 0);
DLOG(INFO) << "connected valve to file sink";
}
}
else
{
top_block->connect(file_source_, 0, unpack_byte_, 0);
top_block->connect(unpack_byte_, 0,valve_,0);
DLOG(INFO) << "connected file source to valve";
if (dump_)
{
top_block->connect(valve_, 0, sink_, 0);
DLOG(INFO) << "connected valve to file sink";
}
}
}
else
{
if (enable_throttle_control_ == true)
{
top_block->connect(file_source_, 0, unpack_byte_, 0);
top_block->connect(unpack_byte_, 0,throttle_,0);
DLOG(INFO) << "connected file source to throttle";
if (dump_)
{
top_block->connect(throttle_, 0, sink_, 0);
DLOG(INFO) << "connected file source to sink";
}
}
else
{
if (dump_)
{
top_block->connect(file_source_, 0, unpack_byte_, 0);
top_block->connect(unpack_byte_, 0, sink_, 0);
DLOG(INFO) << "connected file source to sink";
}
}
}
}
void NsrFileSignalSource::disconnect(gr::top_block_sptr top_block)
{
if (samples_ > 0)
{
if (enable_throttle_control_ == true)
{
top_block->disconnect(file_source_, 0, unpack_byte_, 0);
DLOG(INFO) << "disconnected file source to unpack_byte_";
top_block->connect(unpack_byte_, 0,throttle_,0);
DLOG(INFO) << "disconnected unpack_byte_ to throttle_";
top_block->disconnect(throttle_, 0, valve_, 0);
DLOG(INFO) << "disconnected throttle to valve";
if (dump_)
{
top_block->disconnect(valve_, 0, sink_, 0);
DLOG(INFO) << "disconnected valve to file sink";
}
}
else
{
top_block->disconnect(file_source_, 0, unpack_byte_, 0);
DLOG(INFO) << "disconnected file source to unpack_byte_";
top_block->disconnect(unpack_byte_, 0, valve_, 0);
DLOG(INFO) << "disconnected unpack_byte_ to valve";
if (dump_)
{
top_block->disconnect(valve_, 0, sink_, 0);
DLOG(INFO) << "disconnected valve to file sink";
}
}
}
else
{
if (enable_throttle_control_ == true)
{
top_block->disconnect(file_source_, 0, unpack_byte_, 0);
DLOG(INFO) << "disconnected file source to unpack_byte_";
top_block->disconnect(unpack_byte_, 0, throttle_, 0);
DLOG(INFO) << "disconnected unpack_byte_ to throttle";
if (dump_)
{
top_block->disconnect(unpack_byte_, 0, sink_, 0);
DLOG(INFO) << "disconnected funpack_byte_ to sink";
}
}
else
{
if (dump_)
{
top_block->disconnect(file_source_, 0, unpack_byte_, 0);
DLOG(INFO) << "disconnected file source to unpack_byte_";
top_block->disconnect(unpack_byte_, 0, sink_, 0);
DLOG(INFO) << "disconnected unpack_byte_ to sink";
}
}
}
}
gr::basic_block_sptr NsrFileSignalSource::get_left_block()
{
LOG_AT_LEVEL(WARNING) << "Left block of a signal source should not be retrieved";
//return gr_block_sptr();
return gr::blocks::file_source::sptr();
}
gr::basic_block_sptr NsrFileSignalSource::get_right_block()
{
if (samples_ > 0)
{
return valve_;
}
else
{
if (enable_throttle_control_ == true)
{
return throttle_;
}
else
{
return unpack_byte_;
}
}
}

View File

@@ -0,0 +1,123 @@
/*!
* \file nsr_file_signal_source.h
* \brief Implementation of a class that reads signals samples from a NSR 2 bits sampler front-end file
* and adapts it to a SignalSourceInterface. More information about the front-end here
* http://www.ifen.com/products/sx-scientific-gnss-solutions/nsr-software-receiver.html
* \author Javier Arribas, 2013 jarribas(at)cttc.es
*
* This class represents a file signal source.
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_NSR_FILE_SIGNAL_SOURCE_H_
#define GNSS_SDR_NSR_FILE_SIGNAL_SOURCE_H_
#include "gnss_block_interface.h"
#include <gnuradio/blocks/file_source.h>
#include "unpack_byte_2bit_samples.h"
#include <gnuradio/blocks/file_sink.h>
#include <gnuradio/blocks/throttle.h>
#include <gnuradio/hier_block2.h>
#include <gnuradio/msg_queue.h>
class ConfigurationInterface;
/*!
* \brief Class that reads signals samples from a file
* and adapts it to a SignalSourceInterface
*/
class NsrFileSignalSource: public GNSSBlockInterface
{
public:
NsrFileSignalSource(ConfigurationInterface* configuration, std::string role,
unsigned int in_streams, unsigned int out_streams,
boost::shared_ptr<gr::msg_queue> queue);
virtual ~NsrFileSignalSource();
std::string role()
{
return role_;
}
/*!
* \brief Returns "Nsr_File_Signal_Source".
*/
std::string implementation()
{
return "Nsr_File_Signal_Source";
}
size_t item_size()
{
return item_size_;
}
void connect(gr::top_block_sptr top_block);
void disconnect(gr::top_block_sptr top_block);
gr::basic_block_sptr get_left_block();
gr::basic_block_sptr get_right_block();
std::string filename()
{
return filename_;
}
std::string item_type()
{
return item_type_;
}
bool repeat()
{
return repeat_;
}
long sampling_frequency()
{
return sampling_frequency_;
}
long samples()
{
return samples_;
}
private:
unsigned long long samples_;
long sampling_frequency_;
std::string filename_;
std::string item_type_;
bool repeat_;
bool dump_;
std::string dump_filename_;
std::string role_;
unsigned int in_streams_;
unsigned int out_streams_;
gr::blocks::file_source::sptr file_source_;
unpack_byte_2bit_samples_sptr unpack_byte_;
boost::shared_ptr<gr::block> valve_;
gr::blocks::file_sink::sptr sink_;
gr::blocks::throttle::sptr throttle_;
boost::shared_ptr<gr::msg_queue> queue_;
size_t item_size_;
// Throttle control
bool enable_throttle_control_;
};
#endif /*GNSS_SDR_NSR_FILE_SIGNAL_SOURCE_H_*/

View File

@@ -0,0 +1,32 @@
# Copyright (C) 2012-2013 (see AUTHORS file for a list of contributors)
#
# This file is part of GNSS-SDR.
#
# GNSS-SDR is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# at your option) any later version.
#
# GNSS-SDR is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
#
set(SIGNAL_SOURCE_GR_BLOCKS_SOURCES
unpack_byte_2bit_samples.cc
)
include_directories(
$(CMAKE_CURRENT_SOURCE_DIR)
${GLOG_INCLUDE_DIRS}
${GFlags_INCLUDE_DIRS}
${GNURADIO_RUNTIME_INCLUDE_DIRS}
)
add_library(signal_source_gr_blocks ${SIGNAL_SOURCE_GR_BLOCKS_SOURCES})
target_link_libraries(signal_source_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES})

View File

@@ -0,0 +1,87 @@
/*!
* \file unpack_byte_2bit_samples.cc
*
* \brief Unpacks byte samples to NSR 2 bits samples
* \author Javier Arribas jarribas (at) cttc.es
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "unpack_byte_2bit_samples.h"
#include <iostream>
#include <gnuradio/io_signature.h>
struct byte_2bit_struct
{
signed two_bit_sample:2; // <- 2 bits wide only
};
unpack_byte_2bit_samples_sptr make_unpack_byte_2bit_samples()
{
return unpack_byte_2bit_samples_sptr(new unpack_byte_2bit_samples());
}
unpack_byte_2bit_samples::unpack_byte_2bit_samples()
: sync_interpolator("unpack_byte_2bit_samples",
gr::io_signature::make(1, 1,sizeof(signed char)),
gr::io_signature::make(1, 1,sizeof(float)),
4)
{
}
unpack_byte_2bit_samples::~unpack_byte_2bit_samples()
{
}
int unpack_byte_2bit_samples::work(int noutput_items,gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const signed char *in = (const signed char *)input_items[0];
float *out = (float*)output_items[0];
byte_2bit_struct sample;
int n=0;
for(int i = 0; i < noutput_items/4; i++) {
// Read packed input sample (1 byte = 4 samples)
signed char c = in[i];
sample.two_bit_sample=c & 3;
out[n++]=(float)sample.two_bit_sample;
sample.two_bit_sample=(c>>2) & 3;
out[n++]=(float)sample.two_bit_sample;
sample.two_bit_sample=(c>>4) & 3;
out[n++]=(float)sample.two_bit_sample;
sample.two_bit_sample=(c>>6) & 3;
out[n++]=(float)sample.two_bit_sample;
}
return noutput_items;
}

View File

@@ -0,0 +1,58 @@
/*!
* \file unpack_byte_2bit_samples.h
*
* \brief Unpacks byte samples to NSR 2 bits samples
* \author Javier Arribas jarribas (at) cttc.es
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_unpack_byte_2bit_samples_H
#define GNSS_SDR_unpack_byte_2bit_samples_H
#include <gnuradio/sync_interpolator.h>
class unpack_byte_2bit_samples;
typedef boost::shared_ptr<unpack_byte_2bit_samples> unpack_byte_2bit_samples_sptr;
unpack_byte_2bit_samples_sptr make_unpack_byte_2bit_samples();
/*!
* \brief This class implements conversion between byte packet samples to 2bit samples
* 1 byte = 4 2bit samples
*/
class unpack_byte_2bit_samples: public gr::sync_interpolator
{
private:
friend unpack_byte_2bit_samples_sptr
make_unpack_byte_2bit_samples_sptr();
public:
unpack_byte_2bit_samples();
~unpack_byte_2bit_samples();
int work (int noutput_items,gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif