1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-17 04:33:03 +00:00
This commit is contained in:
Carles Fernandez 2017-06-16 21:25:44 +02:00
commit e7cacc228e
32 changed files with 1592 additions and 1440 deletions

View File

@ -18,5 +18,7 @@
add_subdirectory(adapters) add_subdirectory(adapters)
add_subdirectory(gnuradio_blocks) add_subdirectory(gnuradio_blocks)
#add_subdirectory(libs) if(ENABLE_FPGA)
add_subdirectory(libs)
endif(ENABLE_FPGA)

View File

@ -198,7 +198,7 @@ signed int GalileoE1Pcps8msAmbiguousAcquisition::mag()
void GalileoE1Pcps8msAmbiguousAcquisition::init() void GalileoE1Pcps8msAmbiguousAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -234,7 +234,7 @@ void GalileoE1PcpsAmbiguousAcquisition::init()
acquisition_cc_->init(); acquisition_cc_->init();
} }
set_local_code(); //set_local_code();
} }

View File

@ -200,7 +200,7 @@ signed int GalileoE1PcpsCccwsrAmbiguousAcquisition::mag()
void GalileoE1PcpsCccwsrAmbiguousAcquisition::init() void GalileoE1PcpsCccwsrAmbiguousAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -240,7 +240,7 @@ void
GalileoE1PcpsQuickSyncAmbiguousAcquisition::init() GalileoE1PcpsQuickSyncAmbiguousAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -204,7 +204,7 @@ signed int GalileoE1PcpsTongAmbiguousAcquisition::mag()
void GalileoE1PcpsTongAmbiguousAcquisition::init() void GalileoE1PcpsTongAmbiguousAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -206,7 +206,7 @@ signed int GalileoE5aNoncoherentIQAcquisitionCaf::mag()
void GalileoE5aNoncoherentIQAcquisitionCaf::init() void GalileoE5aNoncoherentIQAcquisitionCaf::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -230,7 +230,7 @@ void GpsL1CaPcpsAcquisition::init()
acquisition_cc_->init(); acquisition_cc_->init();
} }
set_local_code(); //set_local_code();
} }

View File

@ -136,7 +136,7 @@ signed int GpsL1CaPcpsAcquisitionFineDoppler::mag()
void GpsL1CaPcpsAcquisitionFineDoppler::init() void GpsL1CaPcpsAcquisitionFineDoppler::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -34,11 +34,9 @@
#include "gps_l1_ca_pcps_acquisition_fpga.h" #include "gps_l1_ca_pcps_acquisition_fpga.h"
#include <boost/math/distributions/exponential.hpp> #include <boost/math/distributions/exponential.hpp>
#include <glog/logging.h> #include <glog/logging.h>
#include "gps_sdr_signal_processing.h"
#include "GPS_L1_CA.h" #include "GPS_L1_CA.h"
#include "configuration_interface.h" #include "configuration_interface.h"
using google::LogMessage; using google::LogMessage;
GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga(
@ -46,6 +44,18 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga(
unsigned int in_streams, unsigned int out_streams) : unsigned int in_streams, unsigned int out_streams) :
role_(role), in_streams_(in_streams), out_streams_(out_streams) role_(role), in_streams_(in_streams), out_streams_(out_streams)
{ {
unsigned int code_length;
bool bit_transition_flag;
bool use_CFAR_algorithm_flag;
unsigned int sampled_ms;
long fs_in;
long ifreq;
bool dump;
std::string dump_filename;
unsigned int nsamples_total;
unsigned int select_queue_Fpga;
std::string device_name;
configuration_ = configuration; configuration_ = configuration;
std::string default_item_type = "cshort"; std::string default_item_type = "cshort";
@ -53,60 +63,70 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga(
DLOG(INFO) << "role " << role; DLOG(INFO) << "role " << role;
item_type_ = configuration_->property(role + ".item_type", default_item_type); item_type_ = configuration_->property(role + ".item_type",
default_item_type);
fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000); fs_in = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000);
if_ = configuration_->property(role + ".if", 0); ifreq = configuration_->property(role + ".if", 0);
dump_ = configuration_->property(role + ".dump", false); dump = configuration_->property(role + ".dump", false);
doppler_max_ = configuration_->property(role + ".doppler_max", 5000); doppler_max_ = configuration_->property(role + ".doppler_max", 5000);
sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 1); sampled_ms = configuration_->property(
role + ".coherent_integration_time_ms", 1);
// note : the FPGA is implemented according to bit transition flag = 0. Setting bit transition flag to 1 has no effect. // note : the FPGA is implemented according to bit transition flag = 0. Setting bit transition flag to 1 has no effect.
bit_transition_flag_ = configuration_->property(role + ".bit_transition_flag", false); bit_transition_flag = configuration_->property(
role + ".bit_transition_flag", false);
// note : the FPGA is implemented according to use_CFAR_algorithm = 0. Setting use_CFAR_algorithm to 1 has no effect. // note : the FPGA is implemented according to use_CFAR_algorithm = 0. Setting use_CFAR_algorithm to 1 has no effect.
use_CFAR_algorithm_flag_=configuration_->property(role + ".use_CFAR_algorithm", false); use_CFAR_algorithm_flag = configuration_->property(
role + ".use_CFAR_algorithm", false);
// note : the FPGA does not use the max_dwells variable. // note : the FPGA does not use the max_dwells variable.
max_dwells_ = configuration_->property(role + ".max_dwells", 1); max_dwells_ = configuration_->property(role + ".max_dwells", 1);
dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename); dump_filename = configuration_->property(role + ".dump_filename",
default_dump_filename);
//--- Find number of samples per spreading code ------------------------- //--- Find number of samples per spreading code -------------------------
code_length_ = round(fs_in_ / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); code_length = round(
fs_in / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS));
// code length has the same value as d_fft_size // code length has the same value as d_fft_size
float nbits; float nbits;
nbits = ceilf(log2f(code_length_)); nbits = ceilf(log2f(code_length));
nsamples_total_ = pow(2,nbits); nsamples_total = pow(2, nbits);
//vector_length_ = code_length_ * sampled_ms_; //vector_length_ = code_length_ * sampled_ms_;
vector_length_ = nsamples_total_ * sampled_ms_; vector_length_ = nsamples_total * sampled_ms;
// if( bit_transition_flag_ )
// {
// vector_length_ *= 2;
// }
if( bit_transition_flag_ ) select_queue_Fpga = configuration_->property(role + ".select_queue_Fpga",
{ 0);
vector_length_ *= 2;
}
code_ = new gr_complex[vector_length_]; std::string default_device_name = "/dev/uio0";
device_name = configuration_->property(role + ".devicename",
select_queue_Fpga_ = configuration_->property(role + ".select_queue_Fpga", 0); default_device_name);
if (item_type_.compare("cshort") == 0) if (item_type_.compare("cshort") == 0)
{ {
item_size_ = sizeof(lv_16sc_t); item_size_ = sizeof(lv_16sc_t);
gps_acquisition_fpga_sc_ = gps_pcps_make_acquisition_fpga_sc(sampled_ms_, max_dwells_, gps_acquisition_fpga_sc_ = gps_pcps_make_acquisition_fpga_sc(
doppler_max_, if_, fs_in_, code_length_, code_length_, vector_length_, sampled_ms, max_dwells_, doppler_max_, ifreq, fs_in,
bit_transition_flag_, use_CFAR_algorithm_flag_, select_queue_Fpga_, dump_, dump_filename_); code_length, code_length, vector_length_, nsamples_total,
DLOG(INFO) << "acquisition(" << gps_acquisition_fpga_sc_->unique_id() << ")"; bit_transition_flag, use_CFAR_algorithm_flag,
select_queue_Fpga, device_name, dump, dump_filename);
DLOG(INFO) << "acquisition("
<< gps_acquisition_fpga_sc_->unique_id() << ")";
} }
else{ else
{
LOG(FATAL) << item_type_ << " FPGA only accepts chsort"; LOG(FATAL) << item_type_ << " FPGA only accepts chsort";
} }
channel_ = 0; channel_ = 0;
threshold_ = 0.0; threshold_ = 0.0;
doppler_step_ = 0; doppler_step_ = 0;
@ -116,16 +136,13 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga(
GpsL1CaPcpsAcquisitionFpga::~GpsL1CaPcpsAcquisitionFpga() GpsL1CaPcpsAcquisitionFpga::~GpsL1CaPcpsAcquisitionFpga()
{ {
delete[] code_;
} }
void GpsL1CaPcpsAcquisitionFpga::set_channel(unsigned int channel) void GpsL1CaPcpsAcquisitionFpga::set_channel(unsigned int channel)
{ {
channel_ = channel; channel_ = channel;
gps_acquisition_fpga_sc_->set_channel(channel_); gps_acquisition_fpga_sc_->set_channel(channel_);
} }
@ -143,101 +160,68 @@ void GpsL1CaPcpsAcquisitionFpga::set_threshold(float threshold)
} }
DLOG(INFO) << "Channel " << channel_ << " Threshold = " << threshold_; DLOG(INFO) << "Channel " << channel_ << " Threshold = " << threshold_;
gps_acquisition_fpga_sc_->set_threshold(threshold_); gps_acquisition_fpga_sc_->set_threshold(threshold_);
} }
void GpsL1CaPcpsAcquisitionFpga::set_doppler_max(unsigned int doppler_max) void GpsL1CaPcpsAcquisitionFpga::set_doppler_max(unsigned int doppler_max)
{ {
doppler_max_ = doppler_max; doppler_max_ = doppler_max;
gps_acquisition_fpga_sc_->set_doppler_max(doppler_max_); gps_acquisition_fpga_sc_->set_doppler_max(doppler_max_);
} }
void GpsL1CaPcpsAcquisitionFpga::set_doppler_step(unsigned int doppler_step) void GpsL1CaPcpsAcquisitionFpga::set_doppler_step(unsigned int doppler_step)
{ {
doppler_step_ = doppler_step; doppler_step_ = doppler_step;
gps_acquisition_fpga_sc_->set_doppler_step(doppler_step_); gps_acquisition_fpga_sc_->set_doppler_step(doppler_step_);
} }
void GpsL1CaPcpsAcquisitionFpga::set_gnss_synchro(Gnss_Synchro* gnss_synchro) void GpsL1CaPcpsAcquisitionFpga::set_gnss_synchro(Gnss_Synchro* gnss_synchro)
{ {
gnss_synchro_ = gnss_synchro; gnss_synchro_ = gnss_synchro;
gps_acquisition_fpga_sc_->set_gnss_synchro(gnss_synchro_); gps_acquisition_fpga_sc_->set_gnss_synchro(gnss_synchro_);
} }
signed int GpsL1CaPcpsAcquisitionFpga::mag() signed int GpsL1CaPcpsAcquisitionFpga::mag()
{ {
return gps_acquisition_fpga_sc_->mag(); return gps_acquisition_fpga_sc_->mag();
} }
void GpsL1CaPcpsAcquisitionFpga::init() void GpsL1CaPcpsAcquisitionFpga::init()
{ {
gps_acquisition_fpga_sc_->init(); gps_acquisition_fpga_sc_->init();
set_local_code(); set_local_code();
} }
void GpsL1CaPcpsAcquisitionFpga::set_local_code() void GpsL1CaPcpsAcquisitionFpga::set_local_code()
{ {
gps_acquisition_fpga_sc_->set_local_code();
std::complex<float>* code = new std::complex<float>[vector_length_];
//init to zeros for the zero padding of the fft
for (uint s=0;s<vector_length_;s++)
{
code[s] = std::complex<float>(0, 0);
}
gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_ , 0);
for (unsigned int i = 0; i < sampled_ms_; i++)
{
memcpy(&(code_[i*vector_length_]), code, sizeof(gr_complex)*vector_length_);
}
gps_acquisition_fpga_sc_->set_local_code(code_);
delete[] code;
} }
void GpsL1CaPcpsAcquisitionFpga::reset() void GpsL1CaPcpsAcquisitionFpga::reset()
{ {
gps_acquisition_fpga_sc_->set_active(true); gps_acquisition_fpga_sc_->set_active(true);
} }
void GpsL1CaPcpsAcquisitionFpga::set_state(int state) void GpsL1CaPcpsAcquisitionFpga::set_state(int state)
{ {
gps_acquisition_fpga_sc_->set_state(state); gps_acquisition_fpga_sc_->set_state(state);
} }
float GpsL1CaPcpsAcquisitionFpga::calculate_threshold(float pfa) float GpsL1CaPcpsAcquisitionFpga::calculate_threshold(float pfa)
{ {
//Calculate the threshold //Calculate the threshold
unsigned int frequency_bins = 0; unsigned int frequency_bins = 0;
for (int doppler = (int)(-doppler_max_); doppler <= (int)doppler_max_; doppler += doppler_step_) for (int doppler = (int) (-doppler_max_); doppler <= (int) doppler_max_;
doppler += doppler_step_)
{ {
frequency_bins++; frequency_bins++;
} }
@ -252,33 +236,25 @@ float GpsL1CaPcpsAcquisitionFpga::calculate_threshold(float pfa)
return threshold; return threshold;
} }
void GpsL1CaPcpsAcquisitionFpga::connect(gr::top_block_sptr top_block) void GpsL1CaPcpsAcquisitionFpga::connect(gr::top_block_sptr top_block)
{ {
//nothing to connect //nothing to connect
} }
void GpsL1CaPcpsAcquisitionFpga::disconnect(gr::top_block_sptr top_block) void GpsL1CaPcpsAcquisitionFpga::disconnect(gr::top_block_sptr top_block)
{ {
//nothing to disconnect //nothing to disconnect
} }
gr::basic_block_sptr GpsL1CaPcpsAcquisitionFpga::get_left_block() gr::basic_block_sptr GpsL1CaPcpsAcquisitionFpga::get_left_block()
{ {
return gps_acquisition_fpga_sc_; return gps_acquisition_fpga_sc_;
} }
gr::basic_block_sptr GpsL1CaPcpsAcquisitionFpga::get_right_block() gr::basic_block_sptr GpsL1CaPcpsAcquisitionFpga::get_right_block()
{ {
return gps_acquisition_fpga_sc_; return gps_acquisition_fpga_sc_;
} }

View File

@ -43,8 +43,6 @@
#include "complex_byte_to_float_x2.h" #include "complex_byte_to_float_x2.h"
#include <volk_gnsssdr/volk_gnsssdr.h> #include <volk_gnsssdr/volk_gnsssdr.h>
class ConfigurationInterface; class ConfigurationInterface;
/*! /*!
@ -137,35 +135,19 @@ public:
private: private:
ConfigurationInterface* configuration_; ConfigurationInterface* configuration_;
gps_pcps_acquisition_fpga_sc_sptr gps_acquisition_fpga_sc_; gps_pcps_acquisition_fpga_sc_sptr gps_acquisition_fpga_sc_;
gr::blocks::stream_to_vector::sptr stream_to_vector_;
gr::blocks::float_to_complex::sptr float_to_complex_;
complex_byte_to_float_x2_sptr cbyte_to_float_x2_;
size_t item_size_; size_t item_size_;
std::string item_type_; std::string item_type_;
unsigned int vector_length_; unsigned int vector_length_;
unsigned int code_length_;
bool bit_transition_flag_;
bool use_CFAR_algorithm_flag_;
unsigned int channel_; unsigned int channel_;
float threshold_; float threshold_;
unsigned int doppler_max_; unsigned int doppler_max_;
unsigned int doppler_step_; unsigned int doppler_step_;
unsigned int sampled_ms_;
unsigned int max_dwells_; unsigned int max_dwells_;
long fs_in_;
long if_;
bool dump_;
std::string dump_filename_;
std::complex<float> * code_;
Gnss_Synchro * gnss_synchro_; Gnss_Synchro * gnss_synchro_;
std::string role_; std::string role_;
unsigned int in_streams_; unsigned int in_streams_;
unsigned int out_streams_; unsigned int out_streams_;
unsigned int nsamples_total_;
unsigned int select_queue_Fpga_;
float calculate_threshold(float pfa); float calculate_threshold(float pfa);
}; };

View File

@ -137,7 +137,7 @@ signed int GpsL1CaPcpsAssistedAcquisition::mag()
void GpsL1CaPcpsAssistedAcquisition::init() void GpsL1CaPcpsAssistedAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }
void GpsL1CaPcpsAssistedAcquisition::set_local_code() void GpsL1CaPcpsAssistedAcquisition::set_local_code()

View File

@ -197,7 +197,7 @@ signed int GpsL1CaPcpsMultithreadAcquisition::mag()
void GpsL1CaPcpsMultithreadAcquisition::init() void GpsL1CaPcpsMultithreadAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -194,7 +194,7 @@ signed int GpsL1CaPcpsOpenClAcquisition::mag()
void GpsL1CaPcpsOpenClAcquisition::init() void GpsL1CaPcpsOpenClAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -227,7 +227,7 @@ signed int GpsL1CaPcpsQuickSyncAcquisition::mag()
void GpsL1CaPcpsQuickSyncAcquisition::init() void GpsL1CaPcpsQuickSyncAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }

View File

@ -186,7 +186,7 @@ signed int GpsL1CaPcpsTongAcquisition::mag()
void GpsL1CaPcpsTongAcquisition::init() void GpsL1CaPcpsTongAcquisition::init()
{ {
acquisition_cc_->init(); acquisition_cc_->init();
set_local_code(); //set_local_code();
} }
void GpsL1CaPcpsTongAcquisition::set_local_code() void GpsL1CaPcpsTongAcquisition::set_local_code()

View File

@ -233,7 +233,7 @@ void GpsL2MPcpsAcquisition::init()
acquisition_cc_->init(); acquisition_cc_->init();
} }
set_local_code(); //set_local_code();
} }

View File

@ -67,7 +67,11 @@ add_library(acq_gr_blocks ${ACQ_GR_BLOCKS_SOURCES} ${ACQ_GR_BLOCKS_HEADERS})
source_group(Headers FILES ${ACQ_GR_BLOCKS_HEADERS}) source_group(Headers FILES ${ACQ_GR_BLOCKS_HEADERS})
#target_link_libraries(acq_gr_blocks gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES} #target_link_libraries(acq_gr_blocks gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES}
#target_link_libraries(acq_gr_blocks acquisition_lib gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${OPT_LIBRARIES} ${OPT_ACQUISITION_LIBRARIES}) #target_link_libraries(acq_gr_blocks acquisition_lib gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${OPT_LIBRARIES} ${OPT_ACQUISITION_LIBRARIES})
if(ENABLE_FPGA)
target_link_libraries(acq_gr_blocks acquisition_lib gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${OPT_LIBRARIES} ${OPT_ACQUISITION_LIBRARIES})
else(ENABLE_FPGA)
target_link_libraries(acq_gr_blocks gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${OPT_LIBRARIES} ${OPT_ACQUISITION_LIBRARIES}) target_link_libraries(acq_gr_blocks gnss_sp_libs gnss_system_parameters ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FFT_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${OPT_LIBRARIES} ${OPT_ACQUISITION_LIBRARIES})
endif(ENABLE_FPGA)
if(NOT VOLK_GNSSSDR_FOUND) if(NOT VOLK_GNSSSDR_FOUND)
add_dependencies(acq_gr_blocks volk_gnsssdr_module) add_dependencies(acq_gr_blocks volk_gnsssdr_module)
endif(NOT VOLK_GNSSSDR_FOUND) endif(NOT VOLK_GNSSSDR_FOUND)

View File

@ -40,172 +40,87 @@
#include <volk_gnsssdr/volk_gnsssdr.h> #include <volk_gnsssdr/volk_gnsssdr.h>
#include "control_message_factory.h" #include "control_message_factory.h"
#include "GPS_L1_CA.h" //GPS_TWO_PI #include "GPS_L1_CA.h" //GPS_TWO_PI
using google::LogMessage; using google::LogMessage;
void wait3(int seconds) void wait3(int seconds)
{ {
boost::this_thread::sleep_for(boost::chrono::seconds{seconds}); boost::this_thread::sleep_for(boost::chrono::seconds
{ seconds });
} }
gps_pcps_acquisition_fpga_sc_sptr gps_pcps_make_acquisition_fpga_sc( gps_pcps_acquisition_fpga_sc_sptr gps_pcps_make_acquisition_fpga_sc(
unsigned int sampled_ms, unsigned int max_dwells, unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in, unsigned int doppler_max, long freq, long fs_in, int samples_per_ms,
int samples_per_ms, int samples_per_code, int vector_length, int samples_per_code, int vector_length, unsigned int nsamples_total,
bool bit_transition_flag, bool use_CFAR_algorithm_flag, bool bit_transition_flag, bool use_CFAR_algorithm_flag,
unsigned int select_queue_Fpga, unsigned int select_queue_Fpga, std::string device_name, bool dump,
bool dump,
std::string dump_filename) std::string dump_filename)
{ {
return gps_pcps_acquisition_fpga_sc_sptr( return gps_pcps_acquisition_fpga_sc_sptr(
new gps_pcps_acquisition_fpga_sc(sampled_ms, max_dwells, doppler_max, freq, fs_in, samples_per_ms, new gps_pcps_acquisition_fpga_sc(sampled_ms, max_dwells,
samples_per_code, vector_length, bit_transition_flag, use_CFAR_algorithm_flag, select_queue_Fpga, dump, dump_filename)); doppler_max, freq, fs_in, samples_per_ms, samples_per_code,
vector_length, nsamples_total, bit_transition_flag,
use_CFAR_algorithm_flag, select_queue_Fpga, device_name,
dump, dump_filename));
} }
gps_pcps_acquisition_fpga_sc::gps_pcps_acquisition_fpga_sc( gps_pcps_acquisition_fpga_sc::gps_pcps_acquisition_fpga_sc(
unsigned int sampled_ms, unsigned int max_dwells, unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in, unsigned int doppler_max, long freq, long fs_in, int samples_per_ms,
int samples_per_ms, int samples_per_code, int vector_length, int samples_per_code, int vector_length, unsigned int nsamples_total,
bool bit_transition_flag, bool use_CFAR_algorithm_flag, bool bit_transition_flag, bool use_CFAR_algorithm_flag,
unsigned int select_queue_Fpga, unsigned int select_queue_Fpga, std::string device_name, bool dump,
bool dump,
std::string dump_filename) : std::string dump_filename) :
gr::block("pcps_acquisition_fpga_sc",gr::io_signature::make(0, 0, sizeof(lv_16sc_t)),gr::io_signature::make(0, 0, 0)) gr::block("pcps_acquisition_fpga_sc",
gr::io_signature::make(0, 0, sizeof(lv_16sc_t)),
gr::io_signature::make(0, 0, 0))
{ {
this->message_port_register_out(pmt::mp("events")); this->message_port_register_out(pmt::mp("events"));
d_sample_counter = 0; // SAMPLE COUNTER d_sample_counter = 0; // SAMPLE COUNTER
d_active = false; d_active = false;
d_state = 0; d_state = 0;
d_freq = freq;
d_fs_in = fs_in;
d_samples_per_ms = samples_per_ms;
d_samples_per_code = samples_per_code; d_samples_per_code = samples_per_code;
d_sampled_ms = sampled_ms;
d_max_dwells = max_dwells; // Note : d_max_dwells is not used in the FPGA implementation d_max_dwells = max_dwells; // Note : d_max_dwells is not used in the FPGA implementation
d_well_count = 0; d_well_count = 0;
d_doppler_max = doppler_max; d_doppler_max = doppler_max;
d_fft_size = d_sampled_ms * d_samples_per_ms; d_fft_size = sampled_ms * samples_per_ms;
d_mag = 0; d_mag = 0;
d_input_power = 0.0;
d_num_doppler_bins = 0; d_num_doppler_bins = 0;
d_bit_transition_flag = bit_transition_flag; // Note : bit transition flag is ignored and assumed 0 in the FPGA implementation d_bit_transition_flag = bit_transition_flag; // Note : bit transition flag is ignored and assumed 0 in the FPGA implementation
d_use_CFAR_algorithm_flag = use_CFAR_algorithm_flag; // Note : user CFAR algorithm flag is ignored and assumed 0 in the FPGA implementation d_use_CFAR_algorithm_flag = use_CFAR_algorithm_flag; // Note : user CFAR algorithm flag is ignored and assumed 0 in the FPGA implementation
d_threshold = 0.0; d_threshold = 0.0;
d_doppler_step = 250; d_doppler_step = 250;
d_code_phase = 0;
d_test_statistics = 0.0;
d_channel = 0; d_channel = 0;
d_doppler_freq = 0.0;
d_nsamples_total = vector_length;
//if( d_bit_transition_flag )
// {
// d_fft_size *= 2;
// d_max_dwells = 1;
// }
d_fft_codes = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
d_magnitude = static_cast<float*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(float), volk_gnsssdr_get_alignment()));
//temporary storage for the input conversion from 16sc to float 32fc
d_in_32fc = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
d_fft_codes_padded = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
// Direct FFT
d_fft_if = new gr::fft::fft_complex(d_nsamples_total, true);
// Inverse FFT
d_ifft = new gr::fft::fft_complex(d_nsamples_total, false);
// FPGA queue selection
d_select_queue_Fpga = select_queue_Fpga;
// For dumping samples into a file // For dumping samples into a file
d_dump = dump; d_dump = dump;
d_dump_filename = dump_filename; d_dump_filename = dump_filename;
d_gnss_synchro = 0; d_gnss_synchro = 0;
d_grid_doppler_wipeoffs = 0;
// instantiate HW accelerator class
acquisition_fpga_8sc = std::make_shared < gps_fpga_acquisition_8sc>
(device_name, vector_length, d_fft_size, nsamples_total, fs_in, freq, sampled_ms, select_queue_Fpga);
} }
gps_pcps_acquisition_fpga_sc::~gps_pcps_acquisition_fpga_sc() gps_pcps_acquisition_fpga_sc::~gps_pcps_acquisition_fpga_sc()
{ {
if (d_num_doppler_bins > 0)
{
for (unsigned int i = 0; i < d_num_doppler_bins; i++)
{
volk_gnsssdr_free(d_grid_doppler_wipeoffs[i]);
}
delete[] d_grid_doppler_wipeoffs;
}
volk_gnsssdr_free(d_fft_codes);
volk_gnsssdr_free(d_magnitude);
volk_gnsssdr_free(d_in_32fc);
delete d_ifft;
delete d_fft_if;
if (d_dump) if (d_dump)
{ {
d_dump_file.close(); d_dump_file.close();
} }
acquisition_fpga_8sc->free();
acquisition_fpga_8sc.free();
} }
void gps_pcps_acquisition_fpga_sc::set_local_code(std::complex<float> * code) void gps_pcps_acquisition_fpga_sc::set_local_code()
{ {
// COD acquisition_fpga_8sc->set_local_code(d_gnss_synchro->PRN);
// Here we want to create a buffer that looks like this:
// [ 0 0 0 ... 0 c_0 c_1 ... c_L]
// where c_i is the local code and there are L zeros and L chips
int offset = 0;
// if( d_bit_transition_flag )
// {
// std::fill_n( d_fft_if->get_inbuf(), d_nsamples_total, gr_complex( 0.0, 0.0 ) );
// offset = d_nsamples_total;
// }
memcpy(d_fft_if->get_inbuf() + offset, code, sizeof(gr_complex) * d_nsamples_total);
d_fft_if->execute(); // We need the FFT of local code
volk_32fc_conjugate_32fc(d_fft_codes_padded, d_fft_if->get_outbuf(), d_nsamples_total);
acquisition_fpga_8sc.set_local_code(d_fft_codes_padded);
}
void gps_pcps_acquisition_fpga_sc::update_local_carrier(gr_complex* carrier_vector, int correlator_length_samples, float freq)
{
float phase_step_rad = GPS_TWO_PI * freq / static_cast<float>(d_fs_in);
float _phase[1];
_phase[0] = 0;
volk_gnsssdr_s32f_sincos_32fc(carrier_vector, - phase_step_rad, _phase, correlator_length_samples);
} }
@ -215,32 +130,20 @@ void gps_pcps_acquisition_fpga_sc::init()
d_gnss_synchro->Flag_valid_symbol_output = false; d_gnss_synchro->Flag_valid_symbol_output = false;
d_gnss_synchro->Flag_valid_pseudorange = false; d_gnss_synchro->Flag_valid_pseudorange = false;
d_gnss_synchro->Flag_valid_word = false; d_gnss_synchro->Flag_valid_word = false;
d_gnss_synchro->Flag_preamble = false;
d_gnss_synchro->Acq_delay_samples = 0.0; d_gnss_synchro->Acq_delay_samples = 0.0;
d_gnss_synchro->Acq_doppler_hz = 0.0; d_gnss_synchro->Acq_doppler_hz = 0.0;
d_gnss_synchro->Acq_samplestamp_samples = 0; d_gnss_synchro->Acq_samplestamp_samples = 0;
d_mag = 0.0; d_mag = 0.0;
d_input_power = 0.0;
d_num_doppler_bins = ceil( static_cast<double>(static_cast<int>(d_doppler_max) - static_cast<int>(-d_doppler_max)) / static_cast<double>(d_doppler_step)); d_num_doppler_bins = ceil(
static_cast<double>(static_cast<int>(d_doppler_max)
- static_cast<int>(-d_doppler_max))
/ static_cast<double>(d_doppler_step));
// Create the carrier Doppler wipeoff signals acquisition_fpga_8sc->open_device();
d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins];
for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) acquisition_fpga_8sc->init();
{
d_grid_doppler_wipeoffs[doppler_index] = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
int doppler = -static_cast<int>(d_doppler_max) + d_doppler_step * doppler_index;
update_local_carrier(d_grid_doppler_wipeoffs[doppler_index], d_fft_size, d_freq + doppler);
} }
acquisition_fpga_8sc.init(d_fft_size, d_nsamples_total, d_freq, d_doppler_max, d_doppler_step, d_num_doppler_bins, d_fs_in, d_select_queue_Fpga);
}
void gps_pcps_acquisition_fpga_sc::set_state(int state) void gps_pcps_acquisition_fpga_sc::set_state(int state)
@ -253,36 +156,27 @@ void gps_pcps_acquisition_fpga_sc::set_state(int state)
d_gnss_synchro->Acq_samplestamp_samples = 0; d_gnss_synchro->Acq_samplestamp_samples = 0;
d_well_count = 0; d_well_count = 0;
d_mag = 0.0; d_mag = 0.0;
d_input_power = 0.0;
d_test_statistics = 0.0;
} }
else if (d_state == 0) else if (d_state == 0)
{} {
}
else else
{ {
LOG(ERROR) << "State can only be set to 0 or 1"; LOG(ERROR) << "State can only be set to 0 or 1";
} }
} }
void gps_pcps_acquisition_fpga_sc::set_active(bool active) void gps_pcps_acquisition_fpga_sc::set_active(bool active)
{ {
float temp_peak_to_noise_level = 0.0; float temp_peak_to_noise_level = 0.0;
float peak_to_noise_level = 0.0; float peak_to_noise_level = 0.0;
acquisition_fpga_8sc.block_samples(); // block the samples to run the acquisition this is only necessary for the tests float input_power;
float test_statistics = 0.0;
acquisition_fpga_8sc->block_samples(); // block the samples to run the acquisition this is only necessary for the tests
d_active = active; d_active = active;
// while (d_well_count < d_max_dwells)
// {
int acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL int acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL
d_state = 1; d_state = 1;
@ -302,123 +196,121 @@ void gps_pcps_acquisition_fpga_sc::set_active(bool active)
d_well_count++; d_well_count++;
DLOG(INFO) << "Channel: " << d_channel DLOG(INFO) << "Channel: " << d_channel
<< " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN << " , doing acquisition of satellite: " << d_gnss_synchro->System
<< " ,sample stamp: " << d_sample_counter << ", threshold: " << " " << d_gnss_synchro->PRN << " ,sample stamp: "
<< ", threshold: " << d_sample_counter << ", threshold: " << ", threshold: "
<< d_threshold << ", doppler_max: " << d_doppler_max << d_threshold << ", doppler_max: " << d_doppler_max
<< ", doppler_step: " << d_doppler_step; << ", doppler_step: " << d_doppler_step;
// Doppler frequency search loop // Doppler frequency search loop
for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins;
doppler_index++)
{ {
doppler = -static_cast<int>(d_doppler_max)
+ d_doppler_step * doppler_index;
doppler = -static_cast<int>(d_doppler_max) + d_doppler_step * doppler_index; acquisition_fpga_8sc->set_phase_step(doppler_index);
acquisition_fpga_8sc->run_acquisition(); // runs acquisition and waits until it is finished
acquisition_fpga_8sc.set_phase_step(doppler_index); acquisition_fpga_8sc->read_acquisition_results(&indext, &magt,
acquisition_fpga_8sc.run_acquisition(); // runs acquisition and waits until it is finished &initial_sample, &input_power);
acquisition_fpga_8sc.read_acquisition_results(&indext, &magt, &initial_sample, &d_input_power);
d_sample_counter = initial_sample; d_sample_counter = initial_sample;
temp_peak_to_noise_level = (float) (magt / d_input_power); temp_peak_to_noise_level = (float) (magt / input_power);
if (peak_to_noise_level < temp_peak_to_noise_level) if (peak_to_noise_level < temp_peak_to_noise_level)
{ {
peak_to_noise_level = temp_peak_to_noise_level; peak_to_noise_level = temp_peak_to_noise_level;
d_mag = magt; d_mag = magt;
d_input_power = (d_input_power - d_mag) / (effective_fft_size - 1); input_power = (input_power - d_mag)
/ (effective_fft_size - 1);
//if (d_test_statistics < (d_mag / d_input_power) || !d_bit_transition_flag) d_gnss_synchro->Acq_delay_samples =
// { static_cast<double>(indext % d_samples_per_code);
d_gnss_synchro->Acq_delay_samples = static_cast<double>(indext % d_samples_per_code); d_gnss_synchro->Acq_doppler_hz =
d_gnss_synchro->Acq_doppler_hz = static_cast<double>(doppler); static_cast<double>(doppler);
d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter;
d_test_statistics = d_mag / d_input_power; test_statistics = d_mag / input_power;
// }
} }
// Record results to file if required // Record results to file if required
if (d_dump) if (d_dump)
{ {
std::stringstream filename; std::stringstream filename;
std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write //std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write
filename.str(""); filename.str("");
boost::filesystem::path p = d_dump_filename; boost::filesystem::path p = d_dump_filename;
filename << p.parent_path().string() filename << p.parent_path().string()
<< boost::filesystem::path::preferred_separator << boost::filesystem::path::preferred_separator
<< p.stem().string() << p.stem().string() << "_"
<< "_" << d_gnss_synchro->System << d_gnss_synchro->System << "_"
<<"_" << d_gnss_synchro->Signal << "_sat_" << d_gnss_synchro->Signal << "_sat_"
<< d_gnss_synchro->PRN << "_doppler_" << d_gnss_synchro->PRN << "_doppler_" << doppler
<< doppler
<< p.extension().string(); << p.extension().string();
DLOG(INFO) << "Writing ACQ out to " << filename.str(); DLOG(INFO) << "Writing ACQ out to " << filename.str();
d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary); d_dump_file.open(filename.str().c_str(),
d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin? std::ios::out | std::ios::binary);
d_dump_file.close(); d_dump_file.close();
} }
} }
if (test_statistics > d_threshold)
if (d_test_statistics > d_threshold)
{ {
d_state = 2; // Positive acquisition d_state = 2; // Positive acquisition
// 6.1- Declare positive acquisition using a message port // 6.1- Declare positive acquisition using a message port
DLOG(INFO) << "positive acquisition"; DLOG(INFO) << "positive acquisition";
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; DLOG(INFO) << "satellite " << d_gnss_synchro->System << " "
<< d_gnss_synchro->PRN;
DLOG(INFO) << "sample_stamp " << d_sample_counter; DLOG(INFO) << "sample_stamp " << d_sample_counter;
DLOG(INFO) << "test statistics value " << d_test_statistics; DLOG(INFO) << "test statistics value " << test_statistics;
DLOG(INFO) << "test statistics threshold " << d_threshold; DLOG(INFO) << "test statistics threshold " << d_threshold;
DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples;
DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz;
DLOG(INFO) << "magnitude " << d_mag; DLOG(INFO) << "magnitude " << d_mag;
DLOG(INFO) << "input signal power " << d_input_power; DLOG(INFO) << "input signal power " << input_power;
d_active = false; d_active = false;
d_state = 0; d_state = 0;
acquisition_message = 1; acquisition_message = 1;
this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message)); this->message_port_pub(pmt::mp("events"),
pmt::from_long(acquisition_message));
// break;
} }
else //if (d_well_count == d_max_dwells) else
{ {
d_state = 3; // Negative acquisition d_state = 3; // Negative acquisition
// 6.2- Declare negative acquisition using a message port // 6.2- Declare negative acquisition using a message port
DLOG(INFO) << "negative acquisition"; DLOG(INFO) << "negative acquisition";
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; DLOG(INFO) << "satellite " << d_gnss_synchro->System << " "
<< d_gnss_synchro->PRN;
DLOG(INFO) << "sample_stamp " << d_sample_counter; DLOG(INFO) << "sample_stamp " << d_sample_counter;
DLOG(INFO) << "test statistics value " << d_test_statistics; DLOG(INFO) << "test statistics value " << test_statistics;
DLOG(INFO) << "test statistics threshold " << d_threshold; DLOG(INFO) << "test statistics threshold " << d_threshold;
DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples;
DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz;
DLOG(INFO) << "magnitude " << d_mag; DLOG(INFO) << "magnitude " << d_mag;
DLOG(INFO) << "input signal power " << d_input_power; DLOG(INFO) << "input signal power " << input_power;
d_active = false; d_active = false;
d_state = 0; d_state = 0;
acquisition_message = 2; acquisition_message = 2;
this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message)); this->message_port_pub(pmt::mp("events"),
pmt::from_long(acquisition_message));
// break;
} }
// } acquisition_fpga_8sc->unblock_samples();
acquisition_fpga_8sc.unblock_samples(); acquisition_fpga_8sc->close_device();
DLOG(INFO) << "Done. Consumed 1 item."; DLOG(INFO) << "Done. Consumed 1 item.";
} }

View File

@ -62,12 +62,12 @@ class gps_pcps_acquisition_fpga_sc;
typedef boost::shared_ptr<gps_pcps_acquisition_fpga_sc> gps_pcps_acquisition_fpga_sc_sptr; typedef boost::shared_ptr<gps_pcps_acquisition_fpga_sc> gps_pcps_acquisition_fpga_sc_sptr;
gps_pcps_acquisition_fpga_sc_sptr gps_pcps_acquisition_fpga_sc_sptr
gps_pcps_make_acquisition_fpga_sc(unsigned int sampled_ms, unsigned int max_dwells, gps_pcps_make_acquisition_fpga_sc(unsigned int sampled_ms,
unsigned int doppler_max, long freq, long fs_in, unsigned int max_dwells, unsigned int doppler_max, long freq,
int samples_per_ms, int samples_per_code, int vector_length_, long fs_in, int samples_per_ms, int samples_per_code,
int vector_length_, unsigned int nsamples_total_,
bool bit_transition_flag, bool use_CFAR_algorithm_flag, bool bit_transition_flag, bool use_CFAR_algorithm_flag,
unsigned int select_queue_Fpga, unsigned int select_queue_Fpga, std::string device_name, bool dump,
bool dump,
std::string dump_filename); std::string dump_filename);
/*! /*!
@ -80,65 +80,40 @@ class gps_pcps_acquisition_fpga_sc: public gr::block
{ {
private: private:
friend gps_pcps_acquisition_fpga_sc_sptr friend gps_pcps_acquisition_fpga_sc_sptr
gps_pcps_make_acquisition_fpga_sc(unsigned int sampled_ms, unsigned int max_dwells, gps_pcps_make_acquisition_fpga_sc(unsigned int sampled_ms,
unsigned int doppler_max, long freq, long fs_in, unsigned int max_dwells, unsigned int doppler_max, long freq,
int samples_per_ms, int samples_per_code, int vector_length, long fs_in, int samples_per_ms, int samples_per_code,
int vector_length, unsigned int nsamples_total,
bool bit_transition_flag, bool use_CFAR_algorithm_flag, bool bit_transition_flag, bool use_CFAR_algorithm_flag,
unsigned int select_queue_Fpga, unsigned int select_queue_Fpga, std::string device_name, bool dump,
bool dump,
std::string dump_filename); std::string dump_filename);
gps_pcps_acquisition_fpga_sc(unsigned int sampled_ms, unsigned int max_dwells, gps_pcps_acquisition_fpga_sc(unsigned int sampled_ms,
unsigned int doppler_max, long freq, long fs_in, unsigned int max_dwells, unsigned int doppler_max, long freq,
int samples_per_ms, int samples_per_code, int vector_length, long fs_in, int samples_per_ms, int samples_per_code,
int vector_length, unsigned int nsamples_total,
bool bit_transition_flag, bool use_CFAR_algorithm_flag, bool bit_transition_flag, bool use_CFAR_algorithm_flag,
unsigned int select_queue_Fpga, unsigned int select_queue_Fpga, std::string device_name, bool dump,
bool dump,
std::string dump_filename); std::string dump_filename);
void update_local_carrier(gr_complex* carrier_vector,
int correlator_length_samples,
float freq);
long d_fs_in;
long d_freq;
int d_samples_per_ms;
int d_samples_per_code; int d_samples_per_code;
float d_threshold; float d_threshold;
std::string d_satellite_str;
unsigned int d_doppler_max; unsigned int d_doppler_max;
unsigned int d_doppler_step; unsigned int d_doppler_step;
unsigned int d_sampled_ms;
unsigned int d_max_dwells; unsigned int d_max_dwells;
unsigned int d_well_count; unsigned int d_well_count;
unsigned int d_fft_size; unsigned int d_fft_size;
unsigned int d_nsamples_total; // the closest power of two approximation to d_fft_size
unsigned long int d_sample_counter; unsigned long int d_sample_counter;
gr_complex** d_grid_doppler_wipeoffs;
unsigned int d_num_doppler_bins; unsigned int d_num_doppler_bins;
gr_complex* d_fft_codes;
gr_complex* d_fft_codes_padded;
gr_complex* d_in_32fc;
gr::fft::fft_complex* d_fft_if;
gr::fft::fft_complex* d_ifft;
Gnss_Synchro *d_gnss_synchro; Gnss_Synchro *d_gnss_synchro;
unsigned int d_code_phase; float d_mag;bool d_bit_transition_flag;bool d_use_CFAR_algorithm_flag;
float d_doppler_freq; std::ofstream d_dump_file;bool d_active;
float d_mag; int d_state;bool d_dump;
float* d_magnitude;
float d_input_power;
float d_test_statistics;
bool d_bit_transition_flag;
bool d_use_CFAR_algorithm_flag;
std::ofstream d_dump_file;
bool d_active;
int d_state;
bool d_dump;
unsigned int d_channel; unsigned int d_channel;
unsigned int d_select_queue_Fpga;
std::string d_dump_filename; std::string d_dump_filename;
gps_fpga_acquisition_8sc acquisition_fpga_8sc; std::shared_ptr<gps_fpga_acquisition_8sc> acquisition_fpga_8sc;
public: public:
/*! /*!
@ -173,7 +148,7 @@ public:
* \brief Sets local code for PCPS acquisition algorithm. * \brief Sets local code for PCPS acquisition algorithm.
* \param code - Pointer to the PRN code. * \param code - Pointer to the PRN code.
*/ */
void set_local_code(std::complex<float> * code); void set_local_code();
/*! /*!
* \brief Starts acquisition algorithm, turning from standby mode to * \brief Starts acquisition algorithm, turning from standby mode to
@ -215,6 +190,7 @@ public:
void set_doppler_max(unsigned int doppler_max) void set_doppler_max(unsigned int doppler_max)
{ {
d_doppler_max = doppler_max; d_doppler_max = doppler_max;
acquisition_fpga_8sc->set_doppler_max(doppler_max);
} }
/*! /*!
@ -224,9 +200,9 @@ public:
void set_doppler_step(unsigned int doppler_step) void set_doppler_step(unsigned int doppler_step)
{ {
d_doppler_step = doppler_step; d_doppler_step = doppler_step;
acquisition_fpga_8sc->set_doppler_step(doppler_step);
} }
/*! /*!
* \brief Parallel Code Phase Search Acquisition signal processing. * \brief Parallel Code Phase Search Acquisition signal processing.
*/ */

View File

@ -55,6 +55,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/core/system_parameters ${CMAKE_SOURCE_DIR}/src/core/system_parameters
${CMAKE_SOURCE_DIR}/src/core/interfaces ${CMAKE_SOURCE_DIR}/src/core/interfaces
${CMAKE_SOURCE_DIR}/src/core/receiver ${CMAKE_SOURCE_DIR}/src/core/receiver
${CMAKE_SOURCE_DIR}/src/algorithms/libs
${VOLK_INCLUDE_DIRS} ${VOLK_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS} ${GLOG_INCLUDE_DIRS}
${GFlags_INCLUDE_DIRS} ${GFlags_INCLUDE_DIRS}

View File

@ -34,6 +34,7 @@
*/ */
#include "gps_fpga_acquisition_8sc.h" #include "gps_fpga_acquisition_8sc.h"
#include "gps_sdr_signal_processing.h"
#include <cmath> #include <cmath>
// allocate memory dynamically // allocate memory dynamically
@ -59,144 +60,135 @@
// logging // logging
#include <glog/logging.h> #include <glog/logging.h>
#include <volk/volk.h>
#include "GPS_L1_CA.h" #include "GPS_L1_CA.h"
#define PAGE_SIZE 0x10000 #define PAGE_SIZE 0x10000
#define CODE_RESAMPLER_NUM_BITS_PRECISION 20
#define CODE_PHASE_STEP_CHIPS_NUM_NBITS CODE_RESAMPLER_NUM_BITS_PRECISION
#define pwrtwo(x) (1 << (x))
#define MAX_CODE_RESAMPLER_COUNTER pwrtwo(CODE_PHASE_STEP_CHIPS_NUM_NBITS) // 2^CODE_PHASE_STEP_CHIPS_NUM_NBITS
#define PHASE_CARR_NBITS 32
#define PHASE_CARR_NBITS_INT 1
#define PHASE_CARR_NBITS_FRAC PHASE_CARR_NBITS - PHASE_CARR_NBITS_INT
#define MAX_PHASE_STEP_RAD 0.999999999534339 // 1 - pow(2,-31); #define MAX_PHASE_STEP_RAD 0.999999999534339 // 1 - pow(2,-31);
#define NUM_PRNs 32
#define TEST_REGISTER_ACQ_WRITEVAL 0x55AA
bool gps_fpga_acquisition_8sc::init()
bool gps_fpga_acquisition_8sc::init(unsigned int fft_size, unsigned int nsamples_total, long freq, unsigned int doppler_max, unsigned int doppler_step, int num_doppler_bins, long fs_in, unsigned select_queue)
{ {
float phase_step_rad_fpga; // configure the acquisition with the main initialization values
gps_fpga_acquisition_8sc::configure_acquisition();
d_phase_step_rad_vector = new float[num_doppler_bins]; return true;
for (int doppler_index = 0; doppler_index < num_doppler_bins; doppler_index++)
{
int doppler = -static_cast<int>(doppler_max) + doppler_step * doppler_index;
float phase_step_rad = GPS_TWO_PI * (freq + doppler) / static_cast<float>(fs_in);
// The doppler step can never be outside the range -pi to +pi, otherwise there would be aliasing
// The FPGA expects phase_step_rad between -1 (-pi) to +1 (+pi)
// The FPGA also expects the phase to be negative since it produces cos(x) -j*sin(x)
// while the gnss-sdr software (volk_gnsssdr_s32f_sincos_32fc) generates cos(x) + j*sin(x)
phase_step_rad_fpga = phase_step_rad / (GPS_TWO_PI / 2);
// avoid saturation of the fixed point representation in the fpga
// (only the positive value can saturate due to the 2's complement representation)
if (phase_step_rad_fpga == 1.0)
{
phase_step_rad_fpga = MAX_PHASE_STEP_RAD;
}
d_phase_step_rad_vector[doppler_index] = phase_step_rad_fpga;
} }
// sanity check : check test register bool gps_fpga_acquisition_8sc::set_local_code(unsigned int PRN)
unsigned writeval = 0x55AA;
unsigned readval;
readval = gps_fpga_acquisition_8sc::fpga_acquisition_test_register(writeval);
if (writeval != readval)
{ {
printf("test register fail\n");
LOG(WARNING) << "Acquisition test register sanity check failed"; // select the code with the chosen PRN
} gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(
else &d_all_fft_codes[d_vector_length * PRN]);
{ return true;
printf("test register success\n");
LOG(INFO) << "Acquisition test register sanity check success !";
} }
d_nsamples = fft_size; gps_fpga_acquisition_8sc::gps_fpga_acquisition_8sc(std::string device_name,
d_nsamples_total = nsamples_total; unsigned int vector_length, unsigned int nsamples,
unsigned int nsamples_total, long fs_in, long freq,
unsigned int sampled_ms, unsigned select_queue)
{
// initial values
d_device_name = device_name;
d_freq = freq;
d_fs_in = fs_in;
d_vector_length = vector_length;
d_nsamples = nsamples; // number of samples not including padding
d_select_queue = select_queue; d_select_queue = select_queue;
gps_fpga_acquisition_8sc::configure_acquisition(); d_doppler_max = 0;
d_doppler_step = 0;
d_fd = 0; // driver descriptor
d_map_base = nullptr; // driver memory map
return true; // compute all the possible code ffts
}
// Direct FFT
d_fft_if = new gr::fft::fft_complex(vector_length, true);
// allocate memory to compute all the PRNs
// and compute all the possible codes
std::complex<float>* code = new std::complex<float>[nsamples_total]; // buffer for the local code
std::complex<float> * code_total = new gr_complex[vector_length]; // buffer for the local code repeate every number of ms
bool gps_fpga_acquisition_8sc::set_local_code(gr_complex* fft_codes) gr_complex* d_fft_codes_padded =
static_cast<gr_complex*>(volk_gnsssdr_malloc(
vector_length * sizeof(gr_complex),
volk_gnsssdr_get_alignment()));
d_all_fft_codes = new lv_16sc_t[vector_length * NUM_PRNs]; // memory containing all the possible fft codes for PRN 0 to 32
float max; // temporary maxima search
for (unsigned int PRN = 0; PRN < NUM_PRNs; PRN++)
{ {
unsigned int i; gps_l1_ca_code_gen_complex_sampled(code, PRN, fs_in, 0); // generate PRN code
float max = 0;
d_fft_codes = new lv_16sc_t[d_nsamples_total];
for (i=0;i<d_nsamples_total;i++) for (unsigned int i = 0; i < sampled_ms; i++)
{ {
if(std::abs(fft_codes[i].real()) > max) memcpy(&(code_total[i * nsamples_total]), code,
sizeof(gr_complex) * nsamples_total); // repeat for each ms
}
int offset = 0;
memcpy(d_fft_if->get_inbuf() + offset, code_total,
sizeof(gr_complex) * vector_length); // copy to FFT buffer
d_fft_if->execute(); // Run the FFT of local code
volk_32fc_conjugate_32fc(d_fft_codes_padded, d_fft_if->get_outbuf(),
vector_length); // conjugate values
max = 0; // initialize maximum value
for (unsigned int i = 0; i < vector_length; i++) // search for maxima
{ {
max = std::abs(fft_codes[i].real()); if (std::abs(d_fft_codes_padded[i].real()) > max)
}
if(std::abs(fft_codes[i].imag()) > max)
{ {
max = std::abs(fft_codes[i].imag()); max = std::abs(d_fft_codes_padded[i].real());
} }
} if (std::abs(d_fft_codes_padded[i].imag()) > max)
for (i=0;i<d_nsamples_total;i++)
{ {
d_fft_codes[i] = lv_16sc_t((int) (fft_codes[i].real()*(pow(2,7) - 1)/max), (int) (fft_codes[i].imag()*(pow(2,7) - 1)/max)); max = std::abs(d_fft_codes_padded[i].imag());
}
} }
gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(d_fft_codes); for (unsigned int i = 0; i < vector_length; i++) // map the FFT to the dynamic range of the fixed point values an copy to buffer containing all FFTs
return true;
}
gps_fpga_acquisition_8sc::gps_fpga_acquisition_8sc()
{ {
if ((d_fd = open(d_device_io_name, O_RDWR | O_SYNC )) == -1) d_all_fft_codes[i + vector_length * PRN] = lv_16sc_t(
{ (int) (d_fft_codes_padded[i].real()
LOG(WARNING) << "Cannot open deviceio" << d_device_io_name; * (pow(2, 7) - 1) / max),
} (int) (d_fft_codes_padded[i].imag()
d_map_base = (volatile unsigned *)mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, d_fd,0); * (pow(2, 7) - 1) / max));
if (d_map_base == (void *) -1)
{
LOG(WARNING) << "Cannot map the FPGA acquisition module into user memory";
}
} }
}
// temporary buffers that we can delete
delete[] code;
delete[] code_total;
delete d_fft_if;
delete[] d_fft_codes_padded;
}
gps_fpga_acquisition_8sc::~gps_fpga_acquisition_8sc() gps_fpga_acquisition_8sc::~gps_fpga_acquisition_8sc()
{ {
if (munmap((void*)d_map_base, PAGE_SIZE) == -1) delete[] d_all_fft_codes;
{
printf("Failed to unmap memory uio\n");
} }
close(d_fd);
}
bool gps_fpga_acquisition_8sc::free() bool gps_fpga_acquisition_8sc::free()
{ {
if (d_fft_codes != nullptr)
{
delete [] d_fft_codes;
d_fft_codes = nullptr;
}
if (d_phase_step_rad_vector != nullptr)
{
delete [] d_phase_step_rad_vector;
d_phase_step_rad_vector = nullptr;
}
return true; return true;
} }
unsigned gps_fpga_acquisition_8sc::fpga_acquisition_test_register(
unsigned gps_fpga_acquisition_8sc::fpga_acquisition_test_register(unsigned writeval) unsigned writeval)
{ {
unsigned readval; unsigned readval;
// write value to test register // write value to test register
@ -207,15 +199,15 @@ unsigned gps_fpga_acquisition_8sc::fpga_acquisition_test_register(unsigned write
return readval; return readval;
} }
void gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(
void gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(lv_16sc_t fft_local_code[]) lv_16sc_t fft_local_code[])
{ {
short int local_code; short int local_code;
unsigned int k, tmp, tmp2; unsigned int k, tmp, tmp2;
// clear memory address counter // clear memory address counter
d_map_base[4] = 0x10000000; d_map_base[4] = 0x10000000;
for (k = 0; k < d_nsamples_total; k++) for (k = 0; k < d_vector_length; k++)
{ {
tmp = fft_local_code[k].real(); tmp = fft_local_code[k].real();
tmp2 = fft_local_code[k].imag(); tmp2 = fft_local_code[k].imag();
@ -224,7 +216,6 @@ void gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(lv_16sc_t f
} }
} }
void gps_fpga_acquisition_8sc::run_acquisition(void) void gps_fpga_acquisition_8sc::run_acquisition(void)
{ {
// enable interrupts // enable interrupts
@ -244,31 +235,42 @@ void gps_fpga_acquisition_8sc::run_acquisition(void)
} }
} }
void gps_fpga_acquisition_8sc::configure_acquisition() void gps_fpga_acquisition_8sc::configure_acquisition()
{ {
d_map_base[0] = d_select_queue; d_map_base[0] = d_select_queue;
d_map_base[1] = d_nsamples_total; d_map_base[1] = d_vector_length;
d_map_base[2] = d_nsamples; d_map_base[2] = d_nsamples;
} }
void gps_fpga_acquisition_8sc::set_phase_step(unsigned int doppler_index) void gps_fpga_acquisition_8sc::set_phase_step(unsigned int doppler_index)
{ {
float phase_step_rad_real; float phase_step_rad_real;
float phase_step_rad_int_temp; float phase_step_rad_int_temp;
int32_t phase_step_rad_int; int32_t phase_step_rad_int;
phase_step_rad_real = d_phase_step_rad_vector[doppler_index]; int doppler = -static_cast<int>(d_doppler_max)
+ d_doppler_step * doppler_index;
float phase_step_rad = GPS_TWO_PI * (d_freq + doppler)
/ static_cast<float>(d_fs_in);
// The doppler step can never be outside the range -pi to +pi, otherwise there would be aliasing
// The FPGA expects phase_step_rad between -1 (-pi) to +1 (+pi)
// The FPGA also expects the phase to be negative since it produces cos(x) -j*sin(x)
// while the gnss-sdr software (volk_gnsssdr_s32f_sincos_32fc) generates cos(x) + j*sin(x)
phase_step_rad_real = phase_step_rad / (GPS_TWO_PI / 2);
// avoid saturation of the fixed point representation in the fpga
// (only the positive value can saturate due to the 2's complement representation)
if (phase_step_rad_real == 1.0)
{
phase_step_rad_real = MAX_PHASE_STEP_RAD;
}
phase_step_rad_int_temp = phase_step_rad_real * 4; // * 2^2 phase_step_rad_int_temp = phase_step_rad_real * 4; // * 2^2
phase_step_rad_int = (int32_t) (phase_step_rad_int_temp * (536870912)); // * 2^29 (in total it makes x2^31 in two steps to avoid the warnings phase_step_rad_int = (int32_t) (phase_step_rad_int_temp * (536870912)); // * 2^29 (in total it makes x2^31 in two steps to avoid the warnings
d_map_base[3] = phase_step_rad_int; d_map_base[3] = phase_step_rad_int;
} }
void gps_fpga_acquisition_8sc::read_acquisition_results(uint32_t* max_index,
void gps_fpga_acquisition_8sc::read_acquisition_results(uint32_t* max_index, float* max_magnitude, unsigned *initial_sample, float *power_sum) float* max_magnitude, unsigned *initial_sample, float *power_sum)
{ {
unsigned readval = 0; unsigned readval = 0;
readval = d_map_base[0]; readval = d_map_base[0];
@ -280,18 +282,62 @@ void gps_fpga_acquisition_8sc::read_acquisition_results(uint32_t* max_index, flo
*power_sum = (float) readval; *power_sum = (float) readval;
readval = d_map_base[3]; readval = d_map_base[3];
*max_index = readval; *max_index = readval;
}
}
void gps_fpga_acquisition_8sc::block_samples() void gps_fpga_acquisition_8sc::block_samples()
{ {
d_map_base[14] = 1; // block the samples d_map_base[14] = 1; // block the samples
} }
void gps_fpga_acquisition_8sc::unblock_samples() void gps_fpga_acquisition_8sc::unblock_samples()
{ {
d_map_base[14] = 0; // unblock the samples d_map_base[14] = 0; // unblock the samples
} }
void gps_fpga_acquisition_8sc::open_device()
{
if ((d_fd = open(d_device_name.c_str(), O_RDWR | O_SYNC)) == -1)
{
LOG(WARNING) << "Cannot open deviceio" << d_device_name;
}
d_map_base = (volatile unsigned *) mmap(NULL, PAGE_SIZE,
PROT_READ | PROT_WRITE, MAP_SHARED, d_fd, 0);
if (d_map_base == (void *) -1)
{
LOG(WARNING)
<< "Cannot map the FPGA acquisition module into user memory";
}
// sanity check : check test register
// we only nee to do this when the class is created
// but the device is not opened yet when the class is create
// because we need to open and close the device every time we run an acquisition
// since the same device may be used by more than one class (gps acquisition, galileo
// acquisition, etc ..)
unsigned writeval = TEST_REGISTER_ACQ_WRITEVAL;
unsigned readval;
readval = gps_fpga_acquisition_8sc::fpga_acquisition_test_register(
writeval);
if (writeval != readval)
{
LOG(WARNING) << "Acquisition test register sanity check failed";
}
else
{
LOG(INFO) << "Acquisition test register sanity check success !";
}
}
void gps_fpga_acquisition_8sc::close_device()
{
if (munmap((void*) d_map_base, PAGE_SIZE) == -1)
{
printf("Failed to unmap memory uio\n");
}
close(d_fd);
}

View File

@ -39,7 +39,7 @@
#include <volk_gnsssdr/volk_gnsssdr.h> #include <volk_gnsssdr/volk_gnsssdr.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <gnuradio/fft/fft.h>
/*! /*!
* \brief Class that implements carrier wipe-off and correlators. * \brief Class that implements carrier wipe-off and correlators.
@ -47,35 +47,56 @@
class gps_fpga_acquisition_8sc class gps_fpga_acquisition_8sc
{ {
public: public:
gps_fpga_acquisition_8sc(); gps_fpga_acquisition_8sc(std::string device_name,
~gps_fpga_acquisition_8sc(); unsigned int vector_length, unsigned int nsamples,
bool init(unsigned int fft_size, unsigned int nsamples_total, long d_freq, unsigned int doppler_max, unsigned int doppler_step, int num_doppler_bins, long fs_in, unsigned select_queue); unsigned int nsamples_total, long fs_in, long freq,
bool set_local_code(gr_complex* fft_codes); //int code_length_chips, const lv_16sc_t* local_code_in, float *shifts_chips); unsigned int sampled_ms, unsigned select_queue);
~gps_fpga_acquisition_8sc();bool init();bool set_local_code(
unsigned int PRN); //int code_length_chips, const lv_16sc_t* local_code_in, float *shifts_chips);
bool free(); bool free();
void run_acquisition(void); void run_acquisition(void);
void set_phase_step(unsigned int doppler_index); void set_phase_step(unsigned int doppler_index);
void read_acquisition_results(uint32_t* max_index, float* max_magnitude, unsigned *initial_sample, float *power_sum); void read_acquisition_results(uint32_t* max_index, float* max_magnitude,
unsigned *initial_sample, float *power_sum);
void block_samples(); void block_samples();
void unblock_samples(); void unblock_samples();
void open_device();
void close_device();
/*!
* \brief Set maximum Doppler grid search
* \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
*/
void set_doppler_max(unsigned int doppler_max)
{
d_doppler_max = doppler_max;
}
/*!
* \brief Set Doppler steps for the grid search
* \param doppler_step - Frequency bin of the search grid [Hz].
*/
void set_doppler_step(unsigned int doppler_step)
{
d_doppler_step = doppler_step;
}
private: private:
const lv_16sc_t *d_local_code_in;
lv_16sc_t *d_corr_out; long d_freq;
float *d_shifts_chips; long d_fs_in;
int d_code_length_chips; gr::fft::fft_complex* d_fft_if; // function used to run the fft of the local codes
int d_n_correlators;
// data related to the hardware module and the driver // data related to the hardware module and the driver
char d_device_io_name[11] = "/dev/uio13"; // driver io name
int d_fd; // driver descriptor int d_fd; // driver descriptor
volatile unsigned *d_map_base; // driver memory map volatile unsigned *d_map_base; // driver memory map
lv_16sc_t *d_all_fft_codes; // memory that contains all the code ffts
// configuration data received from the interface unsigned int d_vector_length; // number of samples incluing padding and number of ms
lv_16sc_t *d_fft_codes = nullptr;
float *d_phase_step_rad_vector = nullptr;
unsigned int d_nsamples_total; // total number of samples in the fft including padding
unsigned int d_nsamples; // number of samples not including padding unsigned int d_nsamples; // number of samples not including padding
unsigned int d_select_queue; // queue selection unsigned int d_select_queue; // queue selection
std::string d_device_name; // HW device name
unsigned int d_doppler_max; // max doppler
unsigned int d_doppler_step; // doppler step
// FPGA private functions // FPGA private functions
unsigned fpga_acquisition_test_register(unsigned writeval); unsigned fpga_acquisition_test_register(unsigned writeval);
@ -84,5 +105,4 @@ private:
}; };
#endif /* GNSS_SDR_FPGA_MULTICORRELATOR_H_ */ #endif /* GNSS_SDR_FPGA_MULTICORRELATOR_H_ */

View File

@ -32,20 +32,14 @@
#include <ctime> #include <ctime>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <random>
#include <volk_gnsssdr/volk_gnsssdr.h> #include <volk_gnsssdr/volk_gnsssdr.h>
#include <volk_gnsssdr/volk_gnsssdr_cpu.h> #include <volk_gnsssdr/volk_gnsssdr_cpu.h>
#include <volk_gnsssdr/volk_gnsssdr_common.h> #include <volk_gnsssdr/volk_gnsssdr_common.h>
#include <volk_gnsssdr/volk_gnsssdr_malloc.h> #include <volk_gnsssdr/volk_gnsssdr_malloc.h>
float uniform() float uniform() {
{ return 2.0f * ((float) rand() / RAND_MAX - 0.5f); // uniformly (-1, 1)
// Seed with a real random value, if available
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<> uniform_dist(-1, 1);
return static_cast<float>(uniform_dist(e1));
} }
template <class t> template <class t>
@ -57,9 +51,6 @@ void random_floats (t *buf, unsigned n)
void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n) void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n)
{ {
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<float> uniform_dist(-1, 1);
if(type.is_complex) n *= 2; if(type.is_complex) n *= 2;
if(type.is_float) if(type.is_float)
{ {
@ -72,7 +63,7 @@ void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n)
if(type.is_signed) int_max /= 2.0; if(type.is_signed) int_max /= 2.0;
for(unsigned int i = 0; i < n; i++) for(unsigned int i = 0; i < n; i++)
{ {
float scaled_rand = static_cast<float>(uniform_dist(e1)) * int_max; float scaled_rand = (((float) (rand() - (RAND_MAX/2))) / static_cast<float>((RAND_MAX/2))) * int_max;
//man i really don't know how to do this in a more clever way, you have to cast down at some point //man i really don't know how to do this in a more clever way, you have to cast down at some point
switch(type.size) switch(type.size)
{ {

View File

@ -36,13 +36,11 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include "gps_l1_ca_dll_pll_c_aid_tracking_fpga.h" #include "gps_l1_ca_dll_pll_c_aid_tracking_fpga.h"
#include <glog/logging.h> #include <glog/logging.h>
#include "GPS_L1_CA.h" #include "GPS_L1_CA.h"
#include "configuration_interface.h" #include "configuration_interface.h"
using google::LogMessage; using google::LogMessage;
GpsL1CaDllPllCAidTrackingFpga::GpsL1CaDllPllCAidTrackingFpga( GpsL1CaDllPllCAidTrackingFpga::GpsL1CaDllPllCAidTrackingFpga(
@ -63,22 +61,34 @@ GpsL1CaDllPllCAidTrackingFpga::GpsL1CaDllPllCAidTrackingFpga(
float dll_bw_hz; float dll_bw_hz;
float dll_bw_narrow_hz; float dll_bw_narrow_hz;
float early_late_space_chips; float early_late_space_chips;
item_type_ = configuration->property(role + ".item_type", default_item_type); std::string device_name;
unsigned int device_base;
item_type_ = configuration->property(role + ".item_type",
default_item_type);
fs_in = configuration->property("GNSS-SDR.internal_fs_hz", 2048000); fs_in = configuration->property("GNSS-SDR.internal_fs_hz", 2048000);
f_if = configuration->property(role + ".if", 0); f_if = configuration->property(role + ".if", 0);
dump = configuration->property(role + ".dump", false); dump = configuration->property(role + ".dump", false);
pll_bw_hz = configuration->property(role + ".pll_bw_hz", 50.0); pll_bw_hz = configuration->property(role + ".pll_bw_hz", 50.0);
dll_bw_hz = configuration->property(role + ".dll_bw_hz", 2.0); dll_bw_hz = configuration->property(role + ".dll_bw_hz", 2.0);
pll_bw_narrow_hz = configuration->property(role + ".pll_bw_narrow_hz", 20.0); pll_bw_narrow_hz = configuration->property(role + ".pll_bw_narrow_hz",
20.0);
dll_bw_narrow_hz = configuration->property(role + ".dll_bw_narrow_hz", 2.0); dll_bw_narrow_hz = configuration->property(role + ".dll_bw_narrow_hz", 2.0);
int extend_correlation_ms; int extend_correlation_ms;
extend_correlation_ms = configuration->property(role + ".extend_correlation_ms", 1); extend_correlation_ms = configuration->property(
role + ".extend_correlation_ms", 1);
early_late_space_chips = configuration->property(role + ".early_late_space_chips", 0.5); early_late_space_chips = configuration->property(
role + ".early_late_space_chips", 0.5);
std::string default_dump_filename = "./track_ch"; std::string default_dump_filename = "./track_ch";
dump_filename = configuration->property(role + ".dump_filename", dump_filename = configuration->property(role + ".dump_filename",
default_dump_filename); //unused! default_dump_filename);
vector_length = std::round(fs_in / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); std::string default_device_name = "/dev/uio";
device_name = configuration->property(role + ".devicename",
default_device_name);
device_base = configuration->property(role + ".device_base", 1);
vector_length = std::round(
fs_in / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS));
//################# MAKE TRACKING GNURadio object ################### //################# MAKE TRACKING GNURadio object ###################
@ -86,36 +96,30 @@ GpsL1CaDllPllCAidTrackingFpga::GpsL1CaDllPllCAidTrackingFpga(
{ {
item_size_ = sizeof(lv_16sc_t); item_size_ = sizeof(lv_16sc_t);
tracking_fpga_sc = gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc( tracking_fpga_sc = gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc(
f_if, f_if, fs_in, vector_length, dump, dump_filename, pll_bw_hz,
fs_in, dll_bw_hz, pll_bw_narrow_hz, dll_bw_narrow_hz,
vector_length, extend_correlation_ms, early_late_space_chips, device_name,
dump, device_base);
dump_filename, DLOG(INFO) << "tracking(" << tracking_fpga_sc->unique_id()
pll_bw_hz, << ")";
dll_bw_hz,
pll_bw_narrow_hz,
dll_bw_narrow_hz,
extend_correlation_ms,
early_late_space_chips);
DLOG(INFO) << "tracking(" << tracking_fpga_sc->unique_id() << ")";
} }
else else
{ {
item_size_ = sizeof(lv_16sc_t); item_size_ = sizeof(lv_16sc_t);
// LOG(WARNING) << item_type_ << " unknown tracking item type"; // LOG(WARNING) << item_type_ << " unknown tracking item type";
LOG(WARNING) << item_type_ << " the tracking item type for the FPGA tracking test has to be cshort"; LOG(WARNING) << item_type_
} << " the tracking item type for the FPGA tracking test has to be cshort";
channel_ = 0;
} }
channel_ = 0;
}
GpsL1CaDllPllCAidTrackingFpga::~GpsL1CaDllPllCAidTrackingFpga() GpsL1CaDllPllCAidTrackingFpga::~GpsL1CaDllPllCAidTrackingFpga()
{ {
LOG(INFO) << "gspl1cadllpllcaidtrackingfpga destructor called"; LOG(INFO) << "gspl1cadllpllcaidtrackingfpga destructor called";
} }
void GpsL1CaDllPllCAidTrackingFpga::start_tracking() void GpsL1CaDllPllCAidTrackingFpga::start_tracking()
{ {
@ -126,11 +130,11 @@ void GpsL1CaDllPllCAidTrackingFpga::start_tracking()
else else
{ {
// LOG(WARNING) << item_type_ << " unknown tracking item type"; // LOG(WARNING) << item_type_ << " unknown tracking item type";
LOG(WARNING) << item_type_ << " the tracking item type for the FPGA tracking test has to be cshort"; LOG(WARNING) << item_type_
<< " the tracking item type for the FPGA tracking test has to be cshort";
} }
} }
/* /*
* Set tracking channel unique ID * Set tracking channel unique ID
*/ */
@ -145,12 +149,13 @@ void GpsL1CaDllPllCAidTrackingFpga::set_channel(unsigned int channel)
else else
{ {
// LOG(WARNING) << item_type_ << " unknown tracking item type"; // LOG(WARNING) << item_type_ << " unknown tracking item type";
LOG(WARNING) << item_type_ << " the tracking item type for the FPGA tracking test has to be cshort"; LOG(WARNING) << item_type_
<< " the tracking item type for the FPGA tracking test has to be cshort";
} }
} }
void GpsL1CaDllPllCAidTrackingFpga::set_gnss_synchro(
void GpsL1CaDllPllCAidTrackingFpga::set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) Gnss_Synchro* p_gnss_synchro)
{ {
if (item_type_.compare("cshort") == 0) if (item_type_.compare("cshort") == 0)
{ {
@ -159,25 +164,27 @@ void GpsL1CaDllPllCAidTrackingFpga::set_gnss_synchro(Gnss_Synchro* p_gnss_synchr
else else
{ {
// LOG(WARNING) << item_type_ << " unknown tracking item type"; // LOG(WARNING) << item_type_ << " unknown tracking item type";
LOG(WARNING) << item_type_ << " the tracking item type for the FPGA tracking test has to be cshort"; LOG(WARNING) << item_type_
<< " the tracking item type for the FPGA tracking test has to be cshort";
} }
} }
void GpsL1CaDllPllCAidTrackingFpga::connect(gr::top_block_sptr top_block) void GpsL1CaDllPllCAidTrackingFpga::connect(gr::top_block_sptr top_block)
{ {
if(top_block) { /* top_block is not null */}; if (top_block)
{ /* top_block is not null */
};
//nothing to connect, now the tracking uses gr_sync_decimator //nothing to connect, now the tracking uses gr_sync_decimator
} }
void GpsL1CaDllPllCAidTrackingFpga::disconnect(gr::top_block_sptr top_block) void GpsL1CaDllPllCAidTrackingFpga::disconnect(gr::top_block_sptr top_block)
{ {
if(top_block) { /* top_block is not null */}; if (top_block)
{ /* top_block is not null */
};
//nothing to disconnect, now the tracking uses gr_sync_decimator //nothing to disconnect, now the tracking uses gr_sync_decimator
} }
// CONVERT TO SOURCE // CONVERT TO SOURCE
gr::basic_block_sptr GpsL1CaDllPllCAidTrackingFpga::get_left_block() gr::basic_block_sptr GpsL1CaDllPllCAidTrackingFpga::get_left_block()
{ {
@ -188,12 +195,12 @@ gr::basic_block_sptr GpsL1CaDllPllCAidTrackingFpga::get_left_block()
else else
{ {
//LOG(WARNING) << item_type_ << " unknown tracking item type"; //LOG(WARNING) << item_type_ << " unknown tracking item type";
LOG(WARNING) << item_type_ << " the tracking item type for the FPGA tracking test has to be cshort"; LOG(WARNING) << item_type_
<< " the tracking item type for the FPGA tracking test has to be cshort";
return nullptr; return nullptr;
} }
} }
gr::basic_block_sptr GpsL1CaDllPllCAidTrackingFpga::get_right_block() gr::basic_block_sptr GpsL1CaDllPllCAidTrackingFpga::get_right_block()
{ {
if (item_type_.compare("cshort") == 0) if (item_type_.compare("cshort") == 0)
@ -203,7 +210,16 @@ gr::basic_block_sptr GpsL1CaDllPllCAidTrackingFpga::get_right_block()
else else
{ {
//LOG(WARNING) << item_type_ << " unknown tracking item type"; //LOG(WARNING) << item_type_ << " unknown tracking item type";
LOG(WARNING) << item_type_ << " the tracking item type for the FPGA tracking test has to be cshort"; LOG(WARNING) << item_type_
<< " the tracking item type for the FPGA tracking test has to be cshort";
return nullptr; return nullptr;
} }
} }
void GpsL1CaDllPllCAidTrackingFpga::reset(void)
{
tracking_fpga_sc->reset();
}

View File

@ -43,7 +43,6 @@
#include "tracking_interface.h" #include "tracking_interface.h"
#include "gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc.h" #include "gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc.h"
class ConfigurationInterface; class ConfigurationInterface;
/*! /*!
@ -53,8 +52,7 @@ class GpsL1CaDllPllCAidTrackingFpga : public TrackingInterface
{ {
public: public:
GpsL1CaDllPllCAidTrackingFpga(ConfigurationInterface* configuration, GpsL1CaDllPllCAidTrackingFpga(ConfigurationInterface* configuration,
std::string role, std::string role, unsigned int in_streams,
unsigned int in_streams,
unsigned int out_streams); unsigned int out_streams);
virtual ~GpsL1CaDllPllCAidTrackingFpga(); virtual ~GpsL1CaDllPllCAidTrackingFpga();
@ -80,7 +78,6 @@ public:
gr::basic_block_sptr get_left_block(); gr::basic_block_sptr get_left_block();
gr::basic_block_sptr get_right_block(); gr::basic_block_sptr get_right_block();
/*! /*!
* \brief Set tracking channel unique ID * \brief Set tracking channel unique ID
*/ */
@ -92,9 +89,10 @@ public:
*/ */
void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro); void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro);
void start_tracking(); void start_tracking();
void reset(void);
private: private:
gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr tracking_fpga_sc; gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr tracking_fpga_sc;
size_t item_size_; size_t item_size_;

View File

@ -47,7 +47,6 @@
#include "GPS_L1_CA.h" #include "GPS_L1_CA.h"
#include "control_message_factory.h" #include "control_message_factory.h"
/*! /*!
* \todo Include in definition header file * \todo Include in definition header file
*/ */
@ -56,32 +55,29 @@
#define MAXIMUM_LOCK_FAIL_COUNTER 50 #define MAXIMUM_LOCK_FAIL_COUNTER 50
#define CARRIER_LOCK_THRESHOLD 0.85 #define CARRIER_LOCK_THRESHOLD 0.85
using google::LogMessage; using google::LogMessage;
gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc(
gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc( long if_freq, long fs_in, unsigned int vector_length, bool dump,
long if_freq, std::string dump_filename, float pll_bw_hz, float dll_bw_hz,
long fs_in, float pll_bw_narrow_hz, float dll_bw_narrow_hz,
unsigned int vector_length, int extend_correlation_ms, float early_late_space_chips,
bool dump, std::string device_name, unsigned int device_base)
std::string dump_filename,
float pll_bw_hz,
float dll_bw_hz,
float pll_bw_narrow_hz,
float dll_bw_narrow_hz,
int extend_correlation_ms,
float early_late_space_chips)
{ {
return gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr(new gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc(if_freq, return gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr(
fs_in, vector_length, dump, dump_filename, pll_bw_hz, dll_bw_hz, pll_bw_narrow_hz, dll_bw_narrow_hz, extend_correlation_ms, early_late_space_chips)); new gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc(if_freq, fs_in,
vector_length, dump, dump_filename, pll_bw_hz, dll_bw_hz,
pll_bw_narrow_hz, dll_bw_narrow_hz, extend_correlation_ms,
early_late_space_chips, device_name, device_base));
} }
void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::msg_handler_preamble_index(pmt::pmt_t msg) void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::msg_handler_preamble_index(
pmt::pmt_t msg)
{ {
//pmt::print(msg); DLOG(INFO) << "Extended correlation enabled for Tracking CH "
DLOG(INFO) << "Extended correlation enabled for Tracking CH " << d_channel << ": Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN); << d_channel << ": Satellite "
<< Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN);
if (d_enable_extended_integration == false) //avoid re-setting preamble indicator if (d_enable_extended_integration == false) //avoid re-setting preamble indicator
{ {
d_preamble_timestamp_s = pmt::to_double(msg); d_preamble_timestamp_s = pmt::to_double(msg);
@ -90,26 +86,24 @@ void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::msg_handler_preamble_index(pmt::p
} }
} }
gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc( gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc(
long if_freq, long if_freq, long fs_in, unsigned int vector_length, bool dump,
long fs_in, std::string dump_filename, float pll_bw_hz, float dll_bw_hz,
unsigned int vector_length, float pll_bw_narrow_hz, float dll_bw_narrow_hz,
bool dump, int extend_correlation_ms, float early_late_space_chips,
std::string dump_filename, std::string device_name, unsigned int device_base) :
float pll_bw_hz, gr::block("gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc",
float dll_bw_hz, gr::io_signature::make(0, 0, sizeof(lv_16sc_t)),
float pll_bw_narrow_hz,
float dll_bw_narrow_hz,
int extend_correlation_ms,
float early_late_space_chips) :
gr::block("gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc", gr::io_signature::make(0, 0, sizeof(lv_16sc_t)),
gr::io_signature::make(1, 1, sizeof(Gnss_Synchro))) gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)))
{ {
// Telemetry bit synchronization message port input // Telemetry bit synchronization message port input
this->message_port_register_in(pmt::mp("preamble_timestamp_s")); this->message_port_register_in(pmt::mp("preamble_timestamp_s"));
this->set_msg_handler(pmt::mp("preamble_timestamp_s"), this->set_msg_handler(pmt::mp("preamble_timestamp_s"),
boost::bind(&gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::msg_handler_preamble_index, this, _1)); boost::bind(
&gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::msg_handler_preamble_index,
this, _1));
this->message_port_register_out(pmt::mp("events")); this->message_port_register_out(pmt::mp("events"));
// initialize internal vars // initialize internal vars
d_dump = dump; d_dump = dump;
@ -133,25 +127,34 @@ gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::gps_l1_ca_dll_pll_c_aid_tracking_fpga_
// Initialization of local code replica // Initialization of local code replica
// Get space for a vector with the C/A code replica sampled 1x/chip // Get space for a vector with the C/A code replica sampled 1x/chip
d_ca_code = static_cast<gr_complex*>(volk_gnsssdr_malloc(static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); d_ca_code = static_cast<gr_complex*>(volk_gnsssdr_malloc(
d_ca_code_16sc = static_cast<lv_16sc_t*>(volk_gnsssdr_malloc(static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(lv_16sc_t), volk_gnsssdr_get_alignment())); static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex),
volk_gnsssdr_get_alignment()));
d_ca_code_16sc = static_cast<lv_16sc_t*>(volk_gnsssdr_malloc(
static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(lv_16sc_t),
volk_gnsssdr_get_alignment()));
// correlator outputs (scalar) // correlator outputs (scalar)
d_n_correlator_taps = 3; // Early, Prompt, and Late d_n_correlator_taps = 3; // Early, Prompt, and Late
d_correlator_outs_16sc = static_cast<lv_16sc_t*>(volk_gnsssdr_malloc(d_n_correlator_taps*sizeof(lv_16sc_t), volk_gnsssdr_get_alignment())); d_correlator_outs_16sc = static_cast<lv_16sc_t*>(volk_gnsssdr_malloc(
d_n_correlator_taps * sizeof(lv_16sc_t),
volk_gnsssdr_get_alignment()));
for (int n = 0; n < d_n_correlator_taps; n++) for (int n = 0; n < d_n_correlator_taps; n++)
{ {
d_correlator_outs_16sc[n] = lv_cmake(0, 0); d_correlator_outs_16sc[n] = lv_cmake(0, 0);
} }
d_local_code_shift_chips = static_cast<float*>(volk_gnsssdr_malloc(d_n_correlator_taps*sizeof(float), volk_gnsssdr_get_alignment())); d_local_code_shift_chips = static_cast<float*>(volk_gnsssdr_malloc(
d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment()));
// Set TAPs delay values [chips] // Set TAPs delay values [chips]
d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[0] = -d_early_late_spc_chips;
d_local_code_shift_chips[1] = 0.0; d_local_code_shift_chips[1] = 0.0;
d_local_code_shift_chips[2] = d_early_late_spc_chips; d_local_code_shift_chips[2] = d_early_late_spc_chips;
multicorrelator_fpga_8sc.init(d_n_correlator_taps); // create multicorrelator class
multicorrelator_fpga_8sc = std::make_shared < fpga_multicorrelator_8sc
> (d_n_correlator_taps, device_name, device_base);
//--- Perform initializations ------------------------------ //--- Perform initializations ------------------------------
// define initial code frequency basis of NCO // define initial code frequency basis of NCO
@ -214,41 +217,55 @@ void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::start_tracking()
long int acq_trk_diff_samples; long int acq_trk_diff_samples;
double acq_trk_diff_seconds; double acq_trk_diff_seconds;
acq_trk_diff_samples = static_cast<long int>(d_sample_counter) - static_cast<long int>(d_acq_sample_stamp);//-d_vector_length; acq_trk_diff_samples = static_cast<long int>(d_sample_counter)
DLOG(INFO) << "Number of samples between Acquisition and Tracking =" << acq_trk_diff_samples; - static_cast<long int>(d_acq_sample_stamp); //-d_vector_length;
acq_trk_diff_seconds = static_cast<double>(acq_trk_diff_samples) / static_cast<double>(d_fs_in); DLOG(INFO) << "Number of samples between Acquisition and Tracking ="
<< acq_trk_diff_samples;
acq_trk_diff_seconds = static_cast<double>(acq_trk_diff_samples)
/ static_cast<double>(d_fs_in);
// Doppler effect // Doppler effect
// Fd=(C/(C+Vr))*F // Fd=(C/(C+Vr))*F
double radial_velocity = (GPS_L1_FREQ_HZ + d_acq_carrier_doppler_hz) / GPS_L1_FREQ_HZ; double radial_velocity = (GPS_L1_FREQ_HZ + d_acq_carrier_doppler_hz)
/ GPS_L1_FREQ_HZ;
// new chip and prn sequence periods based on acq Doppler // new chip and prn sequence periods based on acq Doppler
double T_chip_mod_seconds; double T_chip_mod_seconds;
double T_prn_mod_seconds; double T_prn_mod_seconds;
double T_prn_mod_samples; double T_prn_mod_samples;
d_code_freq_chips = radial_velocity * GPS_L1_CA_CODE_RATE_HZ; d_code_freq_chips = radial_velocity * GPS_L1_CA_CODE_RATE_HZ;
d_code_phase_step_chips = static_cast<double>(d_code_freq_chips) / static_cast<double>(d_fs_in); d_code_phase_step_chips = static_cast<double>(d_code_freq_chips)
/ static_cast<double>(d_fs_in);
T_chip_mod_seconds = 1.0 / d_code_freq_chips; T_chip_mod_seconds = 1.0 / d_code_freq_chips;
T_prn_mod_seconds = T_chip_mod_seconds * GPS_L1_CA_CODE_LENGTH_CHIPS; T_prn_mod_seconds = T_chip_mod_seconds * GPS_L1_CA_CODE_LENGTH_CHIPS;
T_prn_mod_samples = T_prn_mod_seconds * static_cast<double>(d_fs_in); T_prn_mod_samples = T_prn_mod_seconds * static_cast<double>(d_fs_in);
d_correlation_length_samples = round(T_prn_mod_samples); d_correlation_length_samples = round(T_prn_mod_samples);
double T_prn_true_seconds = GPS_L1_CA_CODE_LENGTH_CHIPS / GPS_L1_CA_CODE_RATE_HZ; double T_prn_true_seconds = GPS_L1_CA_CODE_LENGTH_CHIPS
double T_prn_true_samples = T_prn_true_seconds * static_cast<double>(d_fs_in); / GPS_L1_CA_CODE_RATE_HZ;
double T_prn_true_samples = T_prn_true_seconds
* static_cast<double>(d_fs_in);
double T_prn_diff_seconds = T_prn_true_seconds - T_prn_mod_seconds; double T_prn_diff_seconds = T_prn_true_seconds - T_prn_mod_seconds;
double N_prn_diff = acq_trk_diff_seconds / T_prn_true_seconds; double N_prn_diff = acq_trk_diff_seconds / T_prn_true_seconds;
double corrected_acq_phase_samples, delay_correction_samples; double corrected_acq_phase_samples, delay_correction_samples;
corrected_acq_phase_samples = fmod((d_acq_code_phase_samples + T_prn_diff_seconds * N_prn_diff * static_cast<double>(d_fs_in)), T_prn_true_samples); corrected_acq_phase_samples = fmod(
(d_acq_code_phase_samples
+ T_prn_diff_seconds * N_prn_diff
* static_cast<double>(d_fs_in)),
T_prn_true_samples);
if (corrected_acq_phase_samples < 0) if (corrected_acq_phase_samples < 0)
{ {
corrected_acq_phase_samples = T_prn_mod_samples + corrected_acq_phase_samples; corrected_acq_phase_samples = T_prn_mod_samples
+ corrected_acq_phase_samples;
} }
delay_correction_samples = d_acq_code_phase_samples - corrected_acq_phase_samples; delay_correction_samples = d_acq_code_phase_samples
- corrected_acq_phase_samples;
d_acq_code_phase_samples = corrected_acq_phase_samples; d_acq_code_phase_samples = corrected_acq_phase_samples;
d_carrier_doppler_hz = d_acq_carrier_doppler_hz; d_carrier_doppler_hz = d_acq_carrier_doppler_hz;
d_carrier_phase_step_rad = GPS_TWO_PI * d_carrier_doppler_hz / static_cast<double>(d_fs_in); d_carrier_phase_step_rad = GPS_TWO_PI * d_carrier_doppler_hz
/ static_cast<double>(d_fs_in);
// DLL/PLL filter initialization // DLL/PLL filter initialization
d_carrier_loop_filter.initialize(d_acq_carrier_doppler_hz); // The carrier loop filter implements the Doppler accumulator d_carrier_loop_filter.initialize(d_acq_carrier_doppler_hz); // The carrier loop filter implements the Doppler accumulator
@ -256,9 +273,12 @@ void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::start_tracking()
// generate local reference ALWAYS starting at chip 1 (1 sample per chip) // generate local reference ALWAYS starting at chip 1 (1 sample per chip)
gps_l1_ca_code_gen_complex(d_ca_code, d_acquisition_gnss_synchro->PRN, 0); gps_l1_ca_code_gen_complex(d_ca_code, d_acquisition_gnss_synchro->PRN, 0);
volk_gnsssdr_32fc_convert_16ic(d_ca_code_16sc, d_ca_code, static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS)); volk_gnsssdr_32fc_convert_16ic(d_ca_code_16sc, d_ca_code,
static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS));
multicorrelator_fpga_8sc.set_local_code_and_taps(static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code_16sc, d_local_code_shift_chips); multicorrelator_fpga_8sc->set_local_code_and_taps(
static_cast<int>(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code_16sc,
d_local_code_shift_chips);
for (int n = 0; n < d_n_correlator_taps; n++) for (int n = 0; n < d_n_correlator_taps; n++)
{ {
d_correlator_outs_16sc[n] = lv_16sc_t(0, 0); d_correlator_outs_16sc[n] = lv_16sc_t(0, 0);
@ -276,8 +296,12 @@ void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::start_tracking()
sys = sys_.substr(0, 1); sys = sys_.substr(0, 1);
// DEBUG OUTPUT // DEBUG OUTPUT
std::cout << "Tracking of GPS L1 C/A signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << std::endl; std::cout << "Tracking start on channel " << d_channel << " for satellite "
LOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel; << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
<< std::endl;
LOG(INFO) << "Starting tracking of satellite "
<< Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
<< " on channel " << d_channel;
// enable tracking // enable tracking
d_pull_in = true; d_pull_in = true;
@ -285,6 +309,9 @@ void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::start_tracking()
d_enable_extended_integration = false; d_enable_extended_integration = false;
d_preamble_synchronized = false; d_preamble_synchronized = false;
// lock the channel
multicorrelator_fpga_8sc->lock_channel();
LOG(INFO) << "PULL-IN Doppler [Hz]=" << d_carrier_doppler_hz LOG(INFO) << "PULL-IN Doppler [Hz]=" << d_carrier_doppler_hz
<< " Code Phase correction [samples]=" << delay_correction_samples << " Code Phase correction [samples]=" << delay_correction_samples
<< " PULL-IN Code Phase [samples]=" << d_acq_code_phase_samples; << " PULL-IN Code Phase [samples]=" << d_acq_code_phase_samples;
@ -301,14 +328,19 @@ gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::~gps_l1_ca_dll_pll_c_aid_tracking_fpga
volk_gnsssdr_free(d_correlator_outs_16sc); volk_gnsssdr_free(d_correlator_outs_16sc);
delete[] d_Prompt_buffer; delete[] d_Prompt_buffer;
multicorrelator_fpga_8sc.free(); multicorrelator_fpga_8sc->free();
} }
int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work(
int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), int noutput_items __attribute__((unused)),
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) gr_vector_int &ninput_items __attribute__((unused)),
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{ {
// samples offset
int samples_offset;
// Block input data and block output stream pointers // Block input data and block output stream pointers
Gnss_Synchro **out = (Gnss_Synchro **) &output_items[0]; Gnss_Synchro **out = (Gnss_Synchro **) &output_items[0];
@ -326,34 +358,44 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
// Receiver signal alignment // Receiver signal alignment
if (d_pull_in == true) if (d_pull_in == true)
{ {
int samples_offset;
double acq_trk_shif_correction_samples; double acq_trk_shif_correction_samples;
int acq_to_trk_delay_samples; int acq_to_trk_delay_samples;
acq_to_trk_delay_samples = d_sample_counter - d_acq_sample_stamp; acq_to_trk_delay_samples = d_sample_counter
acq_trk_shif_correction_samples = d_correlation_length_samples - fmod(static_cast<double>(acq_to_trk_delay_samples), static_cast<double>(d_correlation_length_samples)); - d_acq_sample_stamp;
samples_offset = round(d_acq_code_phase_samples + acq_trk_shif_correction_samples); acq_trk_shif_correction_samples =
current_synchro_data.Tracking_sample_counter = d_sample_counter + samples_offset; d_correlation_length_samples
- fmod(
static_cast<double>(acq_to_trk_delay_samples),
static_cast<double>(d_correlation_length_samples));
samples_offset = round(
d_acq_code_phase_samples
+ acq_trk_shif_correction_samples);
current_synchro_data.Tracking_sample_counter =
d_sample_counter + samples_offset;
d_sample_counter += samples_offset; // count for the processed samples d_sample_counter += samples_offset; // count for the processed samples
d_pull_in = false; d_pull_in = false;
d_acc_carrier_phase_cycles -= d_carrier_phase_step_rad * samples_offset / GPS_TWO_PI; d_acc_carrier_phase_cycles -= d_carrier_phase_step_rad
current_synchro_data.Carrier_phase_rads = d_acc_carrier_phase_cycles * GPS_TWO_PI; * samples_offset / GPS_TWO_PI;
current_synchro_data.Carrier_Doppler_hz = d_carrier_doppler_hz; current_synchro_data.Carrier_phase_rads =
d_acc_carrier_phase_cycles * GPS_TWO_PI;
current_synchro_data.Carrier_Doppler_hz =
d_carrier_doppler_hz;
current_synchro_data.fs = d_fs_in; current_synchro_data.fs = d_fs_in;
*out[0] = current_synchro_data; *out[0] = current_synchro_data;
consume_each(samples_offset); // shift input to perform alignment with local replica //consume_each(samples_offset); // shift input to perform alignment with local replica
multicorrelator_fpga_8sc.set_initial_sample(samples_offset); multicorrelator_fpga_8sc->set_initial_sample(
samples_offset);
return 1; return 1;
} }
// ################# CARRIER WIPEOFF AND CORRELATORS ############################## // ################# CARRIER WIPEOFF AND CORRELATORS ##############################
// perform carrier wipe-off and compute Early, Prompt and Late correlation // perform carrier wipe-off and compute Early, Prompt and Late correlation
//multicorrelator_fpga_8sc.set_input_output_vectors(d_correlator_outs_16sc, in); multicorrelator_fpga_8sc->set_output_vectors(
multicorrelator_fpga_8sc.set_output_vectors(d_correlator_outs_16sc); d_correlator_outs_16sc);
multicorrelator_fpga_8sc.Carrier_wipeoff_multicorrelator_resampler(d_rem_carrier_phase_rad, multicorrelator_fpga_8sc->Carrier_wipeoff_multicorrelator_resampler(
d_carrier_phase_step_rad, d_rem_carrier_phase_rad, d_carrier_phase_step_rad,
d_rem_code_phase_chips, d_rem_code_phase_chips, d_code_phase_step_chips,
d_code_phase_step_chips,
d_correlation_length_samples); d_correlation_length_samples);
// ####### coherent intergration extension // ####### coherent intergration extension
@ -372,8 +414,14 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
bool enable_dll_pll; bool enable_dll_pll;
if (d_enable_extended_integration == true) if (d_enable_extended_integration == true)
{ {
long int symbol_diff = round(1000.0 * ((static_cast<double>(d_sample_counter) + d_rem_code_phase_samples) / static_cast<double>(d_fs_in) - d_preamble_timestamp_s)); long int symbol_diff = round(
if (symbol_diff > 0 and symbol_diff % d_extend_correlation_ms == 0) 1000.0
* ((static_cast<double>(d_sample_counter)
+ d_rem_code_phase_samples)
/ static_cast<double>(d_fs_in)
- d_preamble_timestamp_s));
if (symbol_diff > 0
and symbol_diff % d_extend_correlation_ms == 0)
{ {
// compute coherent integration and enable tracking loop // compute coherent integration and enable tracking loop
// perform coherent integration using correlator output history // perform coherent integration using correlator output history
@ -383,22 +431,40 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
d_correlator_outs_16sc[2] = lv_cmake(0, 0); d_correlator_outs_16sc[2] = lv_cmake(0, 0);
for (int n = 0; n < d_extend_correlation_ms; n++) for (int n = 0; n < d_extend_correlation_ms; n++)
{ {
d_correlator_outs_16sc[0] += d_E_history.at(n); d_correlator_outs_16sc[0] += d_E_history.at(
d_correlator_outs_16sc[1] += d_P_history.at(n); n);
d_correlator_outs_16sc[2] += d_L_history.at(n); d_correlator_outs_16sc[1] += d_P_history.at(
n);
d_correlator_outs_16sc[2] += d_L_history.at(
n);
} }
if (d_preamble_synchronized == false) if (d_preamble_synchronized == false)
{ {
d_code_loop_filter.set_DLL_BW(d_dll_bw_narrow_hz); d_code_loop_filter.set_DLL_BW(
d_carrier_loop_filter.set_params(10.0, d_pll_bw_narrow_hz,2); d_dll_bw_narrow_hz);
d_carrier_loop_filter.set_params(10.0,
d_pll_bw_narrow_hz, 2);
d_preamble_synchronized = true; d_preamble_synchronized = true;
std::cout << "Enabled " << d_extend_correlation_ms << " [ms] extended correlator for CH "<< d_channel << " : Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) std::cout << "Enabled "
<< " pll_bw = " << d_pll_bw_hz << " [Hz], pll_narrow_bw = " << d_pll_bw_narrow_hz << " [Hz]" << std::endl << d_extend_correlation_ms
<< " dll_bw = " << d_dll_bw_hz << " [Hz], dll_narrow_bw = " << d_dll_bw_narrow_hz << " [Hz]" << std::endl; << " [ms] extended correlator for CH "
<< d_channel << " : Satellite "
<< Gnss_Satellite(systemName[sys],
d_acquisition_gnss_synchro->PRN)
<< " pll_bw = " << d_pll_bw_hz
<< " [Hz], pll_narrow_bw = "
<< d_pll_bw_narrow_hz << " [Hz]"
<< std::endl << " dll_bw = "
<< d_dll_bw_hz
<< " [Hz], dll_narrow_bw = "
<< d_dll_bw_narrow_hz << " [Hz]"
<< std::endl;
} }
// UPDATE INTEGRATION TIME // UPDATE INTEGRATION TIME
CURRENT_INTEGRATION_TIME_S = static_cast<double>(d_extend_correlation_ms) * GPS_L1_CA_CODE_PERIOD; CURRENT_INTEGRATION_TIME_S =
static_cast<double>(d_extend_correlation_ms)
* GPS_L1_CA_CODE_PERIOD;
enable_dll_pll = true; enable_dll_pll = true;
} }
else else
@ -407,25 +473,49 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
{ {
// continue extended coherent correlation // continue extended coherent correlation
// Compute the next buffer length based on the period of the PRN sequence and the code phase error estimation // Compute the next buffer length based on the period of the PRN sequence and the code phase error estimation
double T_chip_seconds = 1.0 / d_code_freq_chips; double T_chip_seconds = 1.0
double T_prn_seconds = T_chip_seconds * GPS_L1_CA_CODE_LENGTH_CHIPS; / d_code_freq_chips;
double T_prn_samples = T_prn_seconds * static_cast<double>(d_fs_in); double T_prn_seconds = T_chip_seconds
* GPS_L1_CA_CODE_LENGTH_CHIPS;
double T_prn_samples = T_prn_seconds
* static_cast<double>(d_fs_in);
int K_prn_samples = round(T_prn_samples); int K_prn_samples = round(T_prn_samples);
double K_T_prn_error_samples = K_prn_samples - T_prn_samples; double K_T_prn_error_samples = K_prn_samples
- T_prn_samples;
d_rem_code_phase_samples = d_rem_code_phase_samples - K_T_prn_error_samples; d_rem_code_phase_samples =
d_rem_code_phase_integer_samples = round(d_rem_code_phase_samples); // round to a discrete number of samples d_rem_code_phase_samples
d_correlation_length_samples = K_prn_samples + d_rem_code_phase_integer_samples; - K_T_prn_error_samples;
d_rem_code_phase_samples = d_rem_code_phase_samples - d_rem_code_phase_integer_samples; d_rem_code_phase_integer_samples = round(
d_rem_code_phase_samples); // round to a discrete number of samples
d_correlation_length_samples = K_prn_samples
+ d_rem_code_phase_integer_samples;
d_rem_code_phase_samples =
d_rem_code_phase_samples
- d_rem_code_phase_integer_samples;
// code phase step (Code resampler phase increment per sample) [chips/sample] // code phase step (Code resampler phase increment per sample) [chips/sample]
d_code_phase_step_chips = d_code_freq_chips / static_cast<double>(d_fs_in); d_code_phase_step_chips = d_code_freq_chips
/ static_cast<double>(d_fs_in);
// remnant code phase [chips] // remnant code phase [chips]
d_rem_code_phase_chips = d_rem_code_phase_samples * (d_code_freq_chips / static_cast<double>(d_fs_in)); d_rem_code_phase_chips =
d_rem_carrier_phase_rad = fmod(d_rem_carrier_phase_rad + d_carrier_phase_step_rad * static_cast<double>(d_correlation_length_samples), GPS_TWO_PI); d_rem_code_phase_samples
* (d_code_freq_chips
/ static_cast<double>(d_fs_in));
d_rem_carrier_phase_rad =
fmod(
d_rem_carrier_phase_rad
+ d_carrier_phase_step_rad
* static_cast<double>(d_correlation_length_samples),
GPS_TWO_PI);
// UPDATE ACCUMULATED CARRIER PHASE // UPDATE ACCUMULATED CARRIER PHASE
CORRECTED_INTEGRATION_TIME_S = (static_cast<double>(d_correlation_length_samples) / static_cast<double>(d_fs_in)); CORRECTED_INTEGRATION_TIME_S =
d_acc_carrier_phase_cycles -= d_carrier_phase_step_rad * d_correlation_length_samples / GPS_TWO_PI; (static_cast<double>(d_correlation_length_samples)
/ static_cast<double>(d_fs_in));
d_acc_carrier_phase_cycles -=
d_carrier_phase_step_rad
* d_correlation_length_samples
/ GPS_TWO_PI;
// disable tracking loop and inform telemetry decoder // disable tracking loop and inform telemetry decoder
enable_dll_pll = false; enable_dll_pll = false;
@ -434,7 +524,9 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
{ {
// perform basic (1ms) correlation // perform basic (1ms) correlation
// UPDATE INTEGRATION TIME // UPDATE INTEGRATION TIME
CURRENT_INTEGRATION_TIME_S = static_cast<double>(d_correlation_length_samples) / static_cast<double>(d_fs_in); CURRENT_INTEGRATION_TIME_S =
static_cast<double>(d_correlation_length_samples)
/ static_cast<double>(d_fs_in);
enable_dll_pll = true; enable_dll_pll = true;
} }
} }
@ -442,7 +534,9 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
else else
{ {
// UPDATE INTEGRATION TIME // UPDATE INTEGRATION TIME
CURRENT_INTEGRATION_TIME_S = static_cast<double>(d_correlation_length_samples) / static_cast<double>(d_fs_in); CURRENT_INTEGRATION_TIME_S =
static_cast<double>(d_correlation_length_samples)
/ static_cast<double>(d_fs_in);
enable_dll_pll = true; enable_dll_pll = true;
} }
@ -450,98 +544,160 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
{ {
// ################## PLL ########################################################## // ################## PLL ##########################################################
// Update PLL discriminator [rads/Ti -> Secs/Ti] // Update PLL discriminator [rads/Ti -> Secs/Ti]
d_carr_phase_error_secs_Ti = pll_cloop_two_quadrant_atan(std::complex<float>(d_correlator_outs_16sc[1].real(),d_correlator_outs_16sc[1].imag())) / GPS_TWO_PI; //prompt output d_carr_phase_error_secs_Ti = pll_cloop_two_quadrant_atan(
std::complex<float>(
d_correlator_outs_16sc[1].real(),
d_correlator_outs_16sc[1].imag()))
/ GPS_TWO_PI; //prompt output
// Carrier discriminator filter // Carrier discriminator filter
// NOTICE: The carrier loop filter includes the Carrier Doppler accumulator, as described in Kaplan // NOTICE: The carrier loop filter includes the Carrier Doppler accumulator, as described in Kaplan
// Input [s/Ti] -> output [Hz] // Input [s/Ti] -> output [Hz]
d_carrier_doppler_hz = d_carrier_loop_filter.get_carrier_error(0.0, d_carr_phase_error_secs_Ti, CURRENT_INTEGRATION_TIME_S); d_carrier_doppler_hz =
d_carrier_loop_filter.get_carrier_error(0.0,
d_carr_phase_error_secs_Ti,
CURRENT_INTEGRATION_TIME_S);
// PLL to DLL assistance [Secs/Ti] // PLL to DLL assistance [Secs/Ti]
d_pll_to_dll_assist_secs_Ti = (d_carrier_doppler_hz * CURRENT_INTEGRATION_TIME_S) / GPS_L1_FREQ_HZ; d_pll_to_dll_assist_secs_Ti = (d_carrier_doppler_hz
* CURRENT_INTEGRATION_TIME_S) / GPS_L1_FREQ_HZ;
// code Doppler frequency update // code Doppler frequency update
d_code_freq_chips = GPS_L1_CA_CODE_RATE_HZ + ((d_carrier_doppler_hz * GPS_L1_CA_CODE_RATE_HZ) / GPS_L1_FREQ_HZ); d_code_freq_chips = GPS_L1_CA_CODE_RATE_HZ
+ ((d_carrier_doppler_hz * GPS_L1_CA_CODE_RATE_HZ)
/ GPS_L1_FREQ_HZ);
// ################## DLL ########################################################## // ################## DLL ##########################################################
// DLL discriminator // DLL discriminator
d_code_error_chips_Ti = dll_nc_e_minus_l_normalized(std::complex<float>(d_correlator_outs_16sc[0].real(),d_correlator_outs_16sc[0].imag()), std::complex<float>(d_correlator_outs_16sc[2].real(),d_correlator_outs_16sc[2].imag())); // [chips/Ti] //early and late d_code_error_chips_Ti = dll_nc_e_minus_l_normalized(
std::complex<float>(
d_correlator_outs_16sc[0].real(),
d_correlator_outs_16sc[0].imag()),
std::complex<float>(
d_correlator_outs_16sc[2].real(),
d_correlator_outs_16sc[2].imag())); // [chips/Ti] //early and late
// Code discriminator filter // Code discriminator filter
d_code_error_filt_chips_s = d_code_loop_filter.get_code_nco(d_code_error_chips_Ti); // input [chips/Ti] -> output [chips/second] d_code_error_filt_chips_s = d_code_loop_filter.get_code_nco(
d_code_error_filt_chips_Ti = d_code_error_filt_chips_s * CURRENT_INTEGRATION_TIME_S; d_code_error_chips_Ti); // input [chips/Ti] -> output [chips/second]
code_error_filt_secs_Ti = d_code_error_filt_chips_Ti / d_code_freq_chips; // [s/Ti] d_code_error_filt_chips_Ti = d_code_error_filt_chips_s
* CURRENT_INTEGRATION_TIME_S;
code_error_filt_secs_Ti = d_code_error_filt_chips_Ti
/ d_code_freq_chips; // [s/Ti]
// ################## CARRIER AND CODE NCO BUFFER ALIGNEMENT ####################### // ################## CARRIER AND CODE NCO BUFFER ALIGNEMENT #######################
// keep alignment parameters for the next input buffer // keep alignment parameters for the next input buffer
// Compute the next buffer length based in the new period of the PRN sequence and the code phase error estimation // Compute the next buffer length based in the new period of the PRN sequence and the code phase error estimation
double T_chip_seconds = 1.0 / d_code_freq_chips; double T_chip_seconds = 1.0 / d_code_freq_chips;
double T_prn_seconds = T_chip_seconds * GPS_L1_CA_CODE_LENGTH_CHIPS; double T_prn_seconds = T_chip_seconds
double T_prn_samples = T_prn_seconds * static_cast<double>(d_fs_in); * GPS_L1_CA_CODE_LENGTH_CHIPS;
double T_prn_samples = T_prn_seconds
* static_cast<double>(d_fs_in);
double K_prn_samples = round(T_prn_samples); double K_prn_samples = round(T_prn_samples);
double K_T_prn_error_samples = K_prn_samples - T_prn_samples; double K_T_prn_error_samples = K_prn_samples
- T_prn_samples;
d_rem_code_phase_samples = d_rem_code_phase_samples - K_T_prn_error_samples + code_error_filt_secs_Ti * static_cast<double>(d_fs_in); //(code_error_filt_secs_Ti + d_pll_to_dll_assist_secs_Ti) * static_cast<double>(d_fs_in); d_rem_code_phase_samples = d_rem_code_phase_samples
d_rem_code_phase_integer_samples = round(d_rem_code_phase_samples); // round to a discrete number of samples - K_T_prn_error_samples
d_correlation_length_samples = K_prn_samples + d_rem_code_phase_integer_samples; + code_error_filt_secs_Ti
d_rem_code_phase_samples = d_rem_code_phase_samples - d_rem_code_phase_integer_samples; * static_cast<double>(d_fs_in); //(code_error_filt_secs_Ti + d_pll_to_dll_assist_secs_Ti) * static_cast<double>(d_fs_in);
d_rem_code_phase_integer_samples = round(
d_rem_code_phase_samples); // round to a discrete number of samples
d_correlation_length_samples = K_prn_samples
+ d_rem_code_phase_integer_samples;
d_rem_code_phase_samples = d_rem_code_phase_samples
- d_rem_code_phase_integer_samples;
//################### PLL COMMANDS ################################################# //################### PLL COMMANDS #################################################
//carrier phase step (NCO phase increment per sample) [rads/sample] //carrier phase step (NCO phase increment per sample) [rads/sample]
d_carrier_phase_step_rad = GPS_TWO_PI * d_carrier_doppler_hz / static_cast<double>(d_fs_in); d_carrier_phase_step_rad = GPS_TWO_PI * d_carrier_doppler_hz
d_acc_carrier_phase_cycles -= d_carrier_phase_step_rad * d_correlation_length_samples / GPS_TWO_PI; / static_cast<double>(d_fs_in);
d_acc_carrier_phase_cycles -= d_carrier_phase_step_rad
* d_correlation_length_samples / GPS_TWO_PI;
// UPDATE ACCUMULATED CARRIER PHASE // UPDATE ACCUMULATED CARRIER PHASE
CORRECTED_INTEGRATION_TIME_S = (static_cast<double>(d_correlation_length_samples) / static_cast<double>(d_fs_in)); CORRECTED_INTEGRATION_TIME_S =
(static_cast<double>(d_correlation_length_samples)
/ static_cast<double>(d_fs_in));
//remnant carrier phase [rad] //remnant carrier phase [rad]
d_rem_carrier_phase_rad = fmod(d_rem_carrier_phase_rad + GPS_TWO_PI * d_carrier_doppler_hz * CORRECTED_INTEGRATION_TIME_S, GPS_TWO_PI); d_rem_carrier_phase_rad = fmod(
d_rem_carrier_phase_rad
+ GPS_TWO_PI * d_carrier_doppler_hz
* CORRECTED_INTEGRATION_TIME_S,
GPS_TWO_PI);
//################### DLL COMMANDS ################################################# //################### DLL COMMANDS #################################################
//code phase step (Code resampler phase increment per sample) [chips/sample] //code phase step (Code resampler phase increment per sample) [chips/sample]
d_code_phase_step_chips = d_code_freq_chips / static_cast<double>(d_fs_in); d_code_phase_step_chips = d_code_freq_chips
/ static_cast<double>(d_fs_in);
//remnant code phase [chips] //remnant code phase [chips]
d_rem_code_phase_chips = d_rem_code_phase_samples * (d_code_freq_chips / static_cast<double>(d_fs_in)); d_rem_code_phase_chips =
d_rem_code_phase_samples
* (d_code_freq_chips
/ static_cast<double>(d_fs_in));
// ####### CN0 ESTIMATION AND LOCK DETECTORS ####################################### // ####### CN0 ESTIMATION AND LOCK DETECTORS #######################################
if (d_cn0_estimation_counter < CN0_ESTIMATION_SAMPLES) if (d_cn0_estimation_counter < CN0_ESTIMATION_SAMPLES)
{ {
// fill buffer with prompt correlator output values // fill buffer with prompt correlator output values
d_Prompt_buffer[d_cn0_estimation_counter] = lv_cmake(static_cast<float>(d_correlator_outs_16sc[1].real()), static_cast<float>(d_correlator_outs_16sc[1].imag()) ); // prompt d_Prompt_buffer[d_cn0_estimation_counter] =
lv_cmake(
static_cast<float>(d_correlator_outs_16sc[1].real()),
static_cast<float>(d_correlator_outs_16sc[1].imag())); // prompt
d_cn0_estimation_counter++; d_cn0_estimation_counter++;
} }
else else
{ {
d_cn0_estimation_counter = 0; d_cn0_estimation_counter = 0;
// Code lock indicator // Code lock indicator
d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS); d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer,
CN0_ESTIMATION_SAMPLES, d_fs_in,
GPS_L1_CA_CODE_LENGTH_CHIPS);
// Carrier lock indicator // Carrier lock indicator
d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); d_carrier_lock_test = carrier_lock_detector(
d_Prompt_buffer, CN0_ESTIMATION_SAMPLES);
// Loss of lock detection // Loss of lock detection
if (d_carrier_lock_test < d_carrier_lock_threshold or d_CN0_SNV_dB_Hz < MINIMUM_VALID_CN0) if (d_carrier_lock_test
< d_carrier_lock_threshold or d_CN0_SNV_dB_Hz < MINIMUM_VALID_CN0)
{ {
d_carrier_lock_fail_counter++; d_carrier_lock_fail_counter++;
} }
else else
{ {
if (d_carrier_lock_fail_counter > 0) d_carrier_lock_fail_counter--; if (d_carrier_lock_fail_counter > 0)
}
if (d_carrier_lock_fail_counter > MAXIMUM_LOCK_FAIL_COUNTER)
{ {
std::cout << "Loss of lock in channel " << d_channel << "!" << std::endl; d_carrier_lock_fail_counter--;
LOG(INFO) << "Loss of lock in channel " << d_channel << "!"; }
this->message_port_pub(pmt::mp("events"), pmt::from_long(3));//3 -> loss of lock }
if (d_carrier_lock_fail_counter
> MAXIMUM_LOCK_FAIL_COUNTER)
{
std::cout << "Loss of lock in channel "
<< d_channel << "!" << std::endl;
LOG(INFO) << "Loss of lock in channel "
<< d_channel << "!";
this->message_port_pub(pmt::mp("events"),
pmt::from_long(3)); //3 -> loss of lock
d_carrier_lock_fail_counter = 0; d_carrier_lock_fail_counter = 0;
d_enable_tracking = false; // TODO: check if disabling tracking is consistent with the channel state machine d_enable_tracking = false; // TODO: check if disabling tracking is consistent with the channel state machine
multicorrelator_fpga_8sc->unlock_channel();
} }
} }
// ########### Output the tracking data to navigation and PVT ########## // ########### Output the tracking data to navigation and PVT ##########
current_synchro_data.Prompt_I = static_cast<double>((d_correlator_outs_16sc[1]).real()); current_synchro_data.Prompt_I =
current_synchro_data.Prompt_Q = static_cast<double>((d_correlator_outs_16sc[1]).imag()); static_cast<double>((d_correlator_outs_16sc[1]).real());
current_synchro_data.Tracking_sample_counter = d_sample_counter + d_correlation_length_samples; current_synchro_data.Prompt_Q =
current_synchro_data.Code_phase_samples = d_rem_code_phase_samples; static_cast<double>((d_correlator_outs_16sc[1]).imag());
current_synchro_data.Carrier_phase_rads = GPS_TWO_PI * d_acc_carrier_phase_cycles; current_synchro_data.Tracking_sample_counter =
current_synchro_data.Carrier_Doppler_hz = d_carrier_doppler_hz; d_sample_counter + d_correlation_length_samples;
current_synchro_data.Code_phase_samples =
d_rem_code_phase_samples;
current_synchro_data.Carrier_phase_rads = GPS_TWO_PI
* d_acc_carrier_phase_cycles;
current_synchro_data.Carrier_Doppler_hz =
d_carrier_doppler_hz;
current_synchro_data.CN0_dB_hz = d_CN0_SNV_dB_Hz; current_synchro_data.CN0_dB_hz = d_CN0_SNV_dB_Hz;
current_synchro_data.Flag_valid_symbol_output = true; current_synchro_data.Flag_valid_symbol_output = true;
if (d_preamble_synchronized == true) if (d_preamble_synchronized == true)
{ {
current_synchro_data.correlation_length_ms = d_extend_correlation_ms; current_synchro_data.correlation_length_ms =
d_extend_correlation_ms;
} }
else else
{ {
@ -550,12 +706,18 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
} }
else else
{ {
current_synchro_data.Prompt_I = static_cast<double>((d_correlator_outs_16sc[1]).real()); current_synchro_data.Prompt_I =
current_synchro_data.Prompt_Q = static_cast<double>((d_correlator_outs_16sc[1]).imag()); static_cast<double>((d_correlator_outs_16sc[1]).real());
current_synchro_data.Tracking_sample_counter = d_sample_counter + d_correlation_length_samples; current_synchro_data.Prompt_Q =
current_synchro_data.Code_phase_samples = d_rem_code_phase_samples; static_cast<double>((d_correlator_outs_16sc[1]).imag());
current_synchro_data.Carrier_phase_rads = GPS_TWO_PI * d_acc_carrier_phase_cycles; current_synchro_data.Tracking_sample_counter =
current_synchro_data.Carrier_Doppler_hz = d_carrier_doppler_hz;// todo: project the carrier doppler d_sample_counter + d_correlation_length_samples;
current_synchro_data.Code_phase_samples =
d_rem_code_phase_samples;
current_synchro_data.Carrier_phase_rads = GPS_TWO_PI
* d_acc_carrier_phase_cycles;
current_synchro_data.Carrier_Doppler_hz =
d_carrier_doppler_hz; // todo: project the carrier doppler
current_synchro_data.CN0_dB_hz = d_CN0_SNV_dB_Hz; current_synchro_data.CN0_dB_hz = d_CN0_SNV_dB_Hz;
} }
} }
@ -566,8 +728,10 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
d_correlator_outs_16sc[n] = lv_cmake(0, 0); d_correlator_outs_16sc[n] = lv_cmake(0, 0);
} }
current_synchro_data.System = {'G'}; current_synchro_data.System =
current_synchro_data.Tracking_sample_counter = d_sample_counter + d_correlation_length_samples; { 'G'};
current_synchro_data.Tracking_sample_counter = d_sample_counter
+ d_correlation_length_samples;
} }
current_synchro_data.fs = d_fs_in; current_synchro_data.fs = d_fs_in;
*out[0] = current_synchro_data; *out[0] = current_synchro_data;
@ -580,57 +744,88 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
double tmp_double; double tmp_double;
prompt_I = d_correlator_outs_16sc[1].real(); prompt_I = d_correlator_outs_16sc[1].real();
prompt_Q = d_correlator_outs_16sc[1].imag(); prompt_Q = d_correlator_outs_16sc[1].imag();
tmp_E = std::abs<float>(std::complex<float>(d_correlator_outs_16sc[0].real(),d_correlator_outs_16sc[0].imag())); tmp_E = std::abs<float>(
tmp_P = std::abs<float>(std::complex<float>(d_correlator_outs_16sc[1].real(),d_correlator_outs_16sc[1].imag())); std::complex<float>(d_correlator_outs_16sc[0].real(),
tmp_L = std::abs<float>(std::complex<float>(d_correlator_outs_16sc[2].real(),d_correlator_outs_16sc[2].imag())); d_correlator_outs_16sc[0].imag()));
tmp_P = std::abs<float>(
std::complex<float>(d_correlator_outs_16sc[1].real(),
d_correlator_outs_16sc[1].imag()));
tmp_L = std::abs<float>(
std::complex<float>(d_correlator_outs_16sc[2].real(),
d_correlator_outs_16sc[2].imag()));
try try
{ {
// EPR // EPR
d_dump_file.write(reinterpret_cast<char*>(&tmp_E), sizeof(float)); d_dump_file.write(reinterpret_cast<char*>(&tmp_E),
d_dump_file.write(reinterpret_cast<char*>(&tmp_P), sizeof(float)); sizeof(float));
d_dump_file.write(reinterpret_cast<char*>(&tmp_L), sizeof(float)); d_dump_file.write(reinterpret_cast<char*>(&tmp_P),
sizeof(float));
d_dump_file.write(reinterpret_cast<char*>(&tmp_L),
sizeof(float));
// PROMPT I and Q (to analyze navigation symbols) // PROMPT I and Q (to analyze navigation symbols)
d_dump_file.write(reinterpret_cast<char*>(&prompt_I), sizeof(float)); d_dump_file.write(reinterpret_cast<char*>(&prompt_I),
d_dump_file.write(reinterpret_cast<char*>(&prompt_Q), sizeof(float)); sizeof(float));
d_dump_file.write(reinterpret_cast<char*>(&prompt_Q),
sizeof(float));
// PRN start sample stamp // PRN start sample stamp
//tmp_float=(float)d_sample_counter; //tmp_float=(float)d_sample_counter;
d_dump_file.write(reinterpret_cast<char*>(&d_sample_counter), sizeof(unsigned long int)); d_dump_file.write(
reinterpret_cast<char*>(&d_sample_counter),
sizeof(unsigned long int));
// accumulated carrier phase // accumulated carrier phase
d_dump_file.write(reinterpret_cast<char*>(&d_acc_carrier_phase_cycles), sizeof(double)); d_dump_file.write(
reinterpret_cast<char*>(&d_acc_carrier_phase_cycles),
sizeof(double));
// carrier and code frequency // carrier and code frequency
d_dump_file.write(reinterpret_cast<char*>(&d_carrier_doppler_hz), sizeof(double)); d_dump_file.write(
d_dump_file.write(reinterpret_cast<char*>(&d_code_freq_chips), sizeof(double)); reinterpret_cast<char*>(&d_carrier_doppler_hz),
sizeof(double));
d_dump_file.write(
reinterpret_cast<char*>(&d_code_freq_chips),
sizeof(double));
//PLL commands //PLL commands
d_dump_file.write(reinterpret_cast<char*>(&d_carr_phase_error_secs_Ti), sizeof(double)); d_dump_file.write(
d_dump_file.write(reinterpret_cast<char*>(&d_carrier_doppler_hz), sizeof(double)); reinterpret_cast<char*>(&d_carr_phase_error_secs_Ti),
sizeof(double));
d_dump_file.write(
reinterpret_cast<char*>(&d_carrier_doppler_hz),
sizeof(double));
//DLL commands //DLL commands
d_dump_file.write(reinterpret_cast<char*>(&d_code_error_chips_Ti), sizeof(double)); d_dump_file.write(
d_dump_file.write(reinterpret_cast<char*>(&d_code_error_filt_chips_Ti), sizeof(double)); reinterpret_cast<char*>(&d_code_error_chips_Ti),
sizeof(double));
d_dump_file.write(
reinterpret_cast<char*>(&d_code_error_filt_chips_Ti),
sizeof(double));
// CN0 and carrier lock test // CN0 and carrier lock test
d_dump_file.write(reinterpret_cast<char*>(&d_CN0_SNV_dB_Hz), sizeof(double)); d_dump_file.write(reinterpret_cast<char*>(&d_CN0_SNV_dB_Hz),
d_dump_file.write(reinterpret_cast<char*>(&d_carrier_lock_test), sizeof(double)); sizeof(double));
d_dump_file.write(
reinterpret_cast<char*>(&d_carrier_lock_test),
sizeof(double));
// AUX vars (for debug purposes) // AUX vars (for debug purposes)
tmp_double = d_code_error_chips_Ti * CURRENT_INTEGRATION_TIME_S; tmp_double = d_code_error_chips_Ti
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double)); * CURRENT_INTEGRATION_TIME_S;
tmp_double = static_cast<double>(d_sample_counter + d_correlation_length_samples); d_dump_file.write(reinterpret_cast<char*>(&tmp_double),
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double)); sizeof(double));
tmp_double = static_cast<double>(d_sample_counter
// PRN + d_correlation_length_samples);
unsigned int prn_ = d_acquisition_gnss_synchro->PRN; d_dump_file.write(reinterpret_cast<char*>(&tmp_double),
d_dump_file.write(reinterpret_cast<char*>(&prn_), sizeof(unsigned int)); sizeof(double));
} }
catch (const std::ifstream::failure* e) catch (const std::ifstream::failure* e)
{ {
LOG(WARNING) << "Exception writing trk dump file " << e->what(); LOG(WARNING) << "Exception writing trk dump file "
<< e->what();
} }
} }
consume_each(d_correlation_length_samples); // this is necessary in gr::block derivates //consume_each(d_correlation_length_samples); // this is necessary in gr::block derivates
d_sample_counter += d_correlation_length_samples; //count for the processed samples d_sample_counter += d_correlation_length_samples; //count for the processed samples
return 1; //output tracking result ALWAYS even in the case of d_enable_tracking==false return 1; //output tracking result ALWAYS even in the case of d_enable_tracking==false
@ -640,8 +835,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work (int noutput_items __
void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::set_channel(unsigned int channel) void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::set_channel(unsigned int channel)
{ {
d_channel = channel; d_channel = channel;
multicorrelator_fpga_8sc.set_channel(d_channel); multicorrelator_fpga_8sc->set_channel(d_channel);
LOG(INFO) << "Tracking Channel set to " << d_channel; LOG(INFO) << "Tracking Channel set to " << d_channel;
// ############# ENABLE DATA FILE LOG ################# // ############# ENABLE DATA FILE LOG #################
if (d_dump == true) if (d_dump == true)
@ -650,22 +844,38 @@ void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::set_channel(unsigned int channel)
{ {
try try
{ {
d_dump_filename.append(boost::lexical_cast<std::string>(d_channel)); d_dump_filename.append(
boost::lexical_cast<std::string>(
d_channel));
d_dump_filename.append(".dat"); d_dump_filename.append(".dat");
d_dump_file.exceptions (std::ifstream::failbit | std::ifstream::badbit); d_dump_file.exceptions(
d_dump_file.open(d_dump_filename.c_str(), std::ios::out | std::ios::binary); std::ifstream::failbit
LOG(INFO) << "Tracking dump enabled on channel " << d_channel << " Log file: " << d_dump_filename.c_str(); | std::ifstream::badbit);
d_dump_file.open(d_dump_filename.c_str(),
std::ios::out | std::ios::binary);
LOG(INFO) << "Tracking dump enabled on channel "
<< d_channel << " Log file: "
<< d_dump_filename.c_str();
} }
catch (const std::ifstream::failure* e) catch (const std::ifstream::failure* e)
{ {
LOG(WARNING) << "channel " << d_channel << " Exception opening trk dump file " << e->what(); LOG(WARNING) << "channel " << d_channel
<< " Exception opening trk dump file "
<< e->what();
} }
} }
} }
} }
void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::set_gnss_synchro(
Gnss_Synchro* p_gnss_synchro)
{ {
d_acquisition_gnss_synchro = p_gnss_synchro; d_acquisition_gnss_synchro = p_gnss_synchro;
} }
void gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::reset(void)
{
multicorrelator_fpga_8sc->unlock_channel();
}

View File

@ -53,23 +53,14 @@
class gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc; class gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc;
typedef boost::shared_ptr<gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc> typedef boost::shared_ptr<gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc> gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr;
gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr;
gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr
gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc(long if_freq, gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc(long if_freq, long fs_in, unsigned
long fs_in, unsigned int vector_length, bool dump, std::string dump_filename, float pll_bw_hz,
int vector_length, float dll_bw_hz, float pll_bw_narrow_hz, float dll_bw_narrow_hz,
bool dump, int extend_correlation_ms, float early_late_space_chips,
std::string dump_filename, std::string device_name, unsigned int device_base);
float pll_bw_hz,
float dll_bw_hz,
float pll_bw_narrow_hz,
float dll_bw_narrow_hz,
int extend_correlation_ms,
float early_late_space_chips);
/*! /*!
* \brief This class implements a DLL + PLL tracking loop block * \brief This class implements a DLL + PLL tracking loop block
@ -84,37 +75,29 @@ public:
void start_tracking(); void start_tracking();
int general_work(int noutput_items, gr_vector_int &ninput_items, int general_work(int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
void reset(void);
private: private:
friend gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr friend gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc_sptr
gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc(long if_freq, gps_l1_ca_dll_pll_c_aid_make_tracking_fpga_sc(long if_freq, long fs_in,
long fs_in, unsigned unsigned
int vector_length, int vector_length, bool dump, std::string dump_filename,
bool dump, float pll_bw_hz, float dll_bw_hz, float pll_bw_narrow_hz,
std::string dump_filename, float dll_bw_narrow_hz, int extend_correlation_ms,
float pll_bw_hz, float early_late_space_chips, std::string device_name,
float dll_bw_hz, unsigned int device_base);
float pll_bw_narrow_hz,
float dll_bw_narrow_hz,
int extend_correlation_ms,
float early_late_space_chips);
gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc(long if_freq, gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc(long if_freq, long fs_in, unsigned
long fs_in, unsigned int vector_length, bool dump, std::string dump_filename, float pll_bw_hz,
int vector_length, float dll_bw_hz, float pll_bw_narrow_hz, float dll_bw_narrow_hz,
bool dump, int extend_correlation_ms, float early_late_space_chips,
std::string dump_filename, std::string device_name, unsigned int device_base);
float pll_bw_hz,
float dll_bw_hz,
float pll_bw_narrow_hz,
float dll_bw_narrow_hz,
int extend_correlation_ms,
float early_late_space_chips);
// tracking configuration vars // tracking configuration vars
unsigned int d_vector_length; unsigned int d_vector_length;bool d_dump;
bool d_dump;
Gnss_Synchro* d_acquisition_gnss_synchro; Gnss_Synchro* d_acquisition_gnss_synchro;
unsigned int d_channel; unsigned int d_channel;
@ -128,9 +111,9 @@ private:
gr_complex* d_ca_code; gr_complex* d_ca_code;
lv_16sc_t* d_ca_code_16sc; lv_16sc_t* d_ca_code_16sc;
float* d_local_code_shift_chips; float* d_local_code_shift_chips;
//gr_complex* d_correlator_outs;
lv_16sc_t* d_correlator_outs_16sc; lv_16sc_t* d_correlator_outs_16sc;
fpga_multicorrelator_8sc multicorrelator_fpga_8sc; //fpga_multicorrelator_8sc multicorrelator_fpga_8sc;
std::shared_ptr<fpga_multicorrelator_8sc> multicorrelator_fpga_8sc;
// remaining code phase and carrier phase between tracking loops // remaining code phase and carrier phase between tracking loops
double d_rem_code_phase_samples; double d_rem_code_phase_samples;
@ -161,9 +144,7 @@ private:
double d_carr_phase_error_secs_Ti; double d_carr_phase_error_secs_Ti;
double d_code_error_chips_Ti; double d_code_error_chips_Ti;
double d_preamble_timestamp_s; double d_preamble_timestamp_s;
int d_extend_correlation_ms; int d_extend_correlation_ms;bool d_enable_extended_integration;bool d_preamble_synchronized;
bool d_enable_extended_integration;
bool d_preamble_synchronized;
double d_code_error_filt_chips_s; double d_code_error_filt_chips_s;
double d_code_error_filt_chips_Ti; double d_code_error_filt_chips_Ti;
void msg_handler_preamble_index(pmt::pmt_t msg); void msg_handler_preamble_index(pmt::pmt_t msg);
@ -189,8 +170,7 @@ private:
int d_carrier_lock_fail_counter; int d_carrier_lock_fail_counter;
// control vars // control vars
bool d_enable_tracking; bool d_enable_tracking;bool d_pull_in;
bool d_pull_in;
// file dump // file dump
std::string d_dump_filename; std::string d_dump_filename;

View File

@ -60,6 +60,9 @@
// logging // logging
#include <glog/logging.h> #include <glog/logging.h>
// string manipulation
#include <string>
#define PAGE_SIZE 0x10000 #define PAGE_SIZE 0x10000
#define MAX_LENGTH_DEVICEIO_NAME 50 #define MAX_LENGTH_DEVICEIO_NAME 50
#define CODE_RESAMPLER_NUM_BITS_PRECISION 20 #define CODE_RESAMPLER_NUM_BITS_PRECISION 20
@ -69,31 +72,18 @@
#define PHASE_CARR_NBITS 32 #define PHASE_CARR_NBITS 32
#define PHASE_CARR_NBITS_INT 1 #define PHASE_CARR_NBITS_INT 1
#define PHASE_CARR_NBITS_FRAC PHASE_CARR_NBITS - PHASE_CARR_NBITS_INT #define PHASE_CARR_NBITS_FRAC PHASE_CARR_NBITS - PHASE_CARR_NBITS_INT
#define LOCAL_CODE_FPGA_CORRELATOR_SELECT_COUNT 0x20000000
#define LOCAL_CODE_FPGA_CLEAR_ADDRESS_COUNTER 0x10000000
#define LOCAL_CODE_FPGA_ENABLE_WRITE_MEMORY 0x0C000000
bool fpga_multicorrelator_8sc::init(int n_correlators) #define TEST_REGISTER_TRACK_WRITEVAL 0x55AA
{
d_n_correlators = n_correlators;
// instantiate variable length vectors
d_initial_index = static_cast<unsigned*>(volk_gnsssdr_malloc(n_correlators * sizeof(unsigned), volk_gnsssdr_get_alignment()));
d_initial_interp_counter = static_cast<unsigned*>(volk_gnsssdr_malloc(n_correlators * sizeof(unsigned), volk_gnsssdr_get_alignment()));
return true;
}
void fpga_multicorrelator_8sc::set_initial_sample(int samples_offset) void fpga_multicorrelator_8sc::set_initial_sample(int samples_offset)
{ {
d_initial_sample_counter = samples_offset; d_initial_sample_counter = samples_offset;
} }
bool fpga_multicorrelator_8sc::set_local_code_and_taps(int code_length_chips,
bool fpga_multicorrelator_8sc::set_local_code_and_taps( const lv_16sc_t* local_code_in, float *shifts_chips)
int code_length_chips,
const lv_16sc_t* local_code_in,
float *shifts_chips)
{ {
d_local_code_in = local_code_in; d_local_code_in = local_code_in;
d_shifts_chips = shifts_chips; d_shifts_chips = shifts_chips;
@ -104,7 +94,6 @@ bool fpga_multicorrelator_8sc::set_local_code_and_taps(
return true; return true;
} }
bool fpga_multicorrelator_8sc::set_output_vectors(lv_16sc_t* corr_out) bool fpga_multicorrelator_8sc::set_output_vectors(lv_16sc_t* corr_out)
{ {
// Save CPU pointers // Save CPU pointers
@ -113,7 +102,6 @@ bool fpga_multicorrelator_8sc::set_output_vectors(lv_16sc_t* corr_out)
return true; return true;
} }
void fpga_multicorrelator_8sc::update_local_code(float rem_code_phase_chips) void fpga_multicorrelator_8sc::update_local_code(float rem_code_phase_chips)
{ {
d_rem_code_phase_chips = rem_code_phase_chips; d_rem_code_phase_chips = rem_code_phase_chips;
@ -122,12 +110,9 @@ void fpga_multicorrelator_8sc::update_local_code(float rem_code_phase_chips)
fpga_multicorrelator_8sc::fpga_configure_code_parameters_in_fpga(); fpga_multicorrelator_8sc::fpga_configure_code_parameters_in_fpga();
} }
bool fpga_multicorrelator_8sc::Carrier_wipeoff_multicorrelator_resampler( bool fpga_multicorrelator_8sc::Carrier_wipeoff_multicorrelator_resampler(
float rem_carrier_phase_in_rad, float rem_carrier_phase_in_rad, float phase_step_rad,
float phase_step_rad, float rem_code_phase_chips, float code_phase_step_chips,
float rem_code_phase_chips,
float code_phase_step_chips,
int signal_length_samples) int signal_length_samples)
{ {
update_local_code(rem_code_phase_chips); update_local_code(rem_code_phase_chips);
@ -144,7 +129,7 @@ bool fpga_multicorrelator_8sc::Carrier_wipeoff_multicorrelator_resampler(
int irq_count; int irq_count;
ssize_t nb; ssize_t nb;
// wait for interrupt // wait for interrupt
nb=read(d_fd, &irq_count, sizeof(irq_count)); nb = read(d_device_descriptor, &irq_count, sizeof(irq_count));
if (nb != sizeof(irq_count)) if (nb != sizeof(irq_count))
{ {
printf("Tracking_module Read failed to retrive 4 bytes!\n"); printf("Tracking_module Read failed to retrive 4 bytes!\n");
@ -156,26 +141,47 @@ bool fpga_multicorrelator_8sc::Carrier_wipeoff_multicorrelator_resampler(
return true; return true;
} }
fpga_multicorrelator_8sc::fpga_multicorrelator_8sc(int n_correlators,
fpga_multicorrelator_8sc::fpga_multicorrelator_8sc() std::string device_name, unsigned int device_base)
{ {
d_n_correlators = n_correlators;
d_device_name = device_name;
d_device_base = device_base;
d_device_descriptor = 0;
d_map_base = nullptr;
// instantiate variable length vectors
d_initial_index = static_cast<unsigned*>(volk_gnsssdr_malloc(
n_correlators * sizeof(unsigned), volk_gnsssdr_get_alignment()));
d_initial_interp_counter = static_cast<unsigned*>(volk_gnsssdr_malloc(
n_correlators * sizeof(unsigned), volk_gnsssdr_get_alignment()));
d_local_code_in = nullptr; d_local_code_in = nullptr;
d_shifts_chips = nullptr; d_shifts_chips = nullptr;
d_corr_out = nullptr; d_corr_out = nullptr;
d_code_length_chips = 0; d_code_length_chips = 0;
d_n_correlators = 0; d_rem_code_phase_chips = 0;
} d_code_phase_step_chips = 0;
d_rem_carrier_phase_in_rad = 0;
d_phase_step_rad = 0;
d_rem_carr_phase_rad_int = 0;
d_phase_step_rad_int = 0;
d_initial_sample_counter = 0;
d_channel = 0;
d_correlator_length_samples = 0;
}
fpga_multicorrelator_8sc::~fpga_multicorrelator_8sc() fpga_multicorrelator_8sc::~fpga_multicorrelator_8sc()
{ {
close(d_fd); close(d_device_descriptor);
} }
bool fpga_multicorrelator_8sc::free() bool fpga_multicorrelator_8sc::free()
{ {
// unlock the hardware // unlock the hardware
fpga_multicorrelator_8sc::unlock_channel(); // unlock the channel fpga_multicorrelator_8sc::unlock_channel(); // unlock the channel
// free the FPGA dynamically created variables // free the FPGA dynamically created variables
@ -194,29 +200,40 @@ bool fpga_multicorrelator_8sc::free()
return true; return true;
} }
void fpga_multicorrelator_8sc::set_channel(unsigned int channel) void fpga_multicorrelator_8sc::set_channel(unsigned int channel)
{ {
char device_io_name[MAX_LENGTH_DEVICEIO_NAME]; // driver io name
d_channel = channel; d_channel = channel;
snprintf(d_device_io_name, MAX_LENGTH_DEVICEIO_NAME, "/dev/uio%d",d_channel); // open the device corresponding to the assigned channel
printf("Opening Device Name : %s\n", d_device_io_name); std::string mergedname;
std::stringstream devicebasetemp;
if ((d_fd = open(d_device_io_name, O_RDWR | O_SYNC )) == -1) int numdevice = d_device_base + d_channel;
devicebasetemp << numdevice;
mergedname = d_device_name + devicebasetemp.str();
strcpy(device_io_name, mergedname.c_str());
printf("Opening Device Name : %s\n", device_io_name);
if ((d_device_descriptor = open(device_io_name, O_RDWR | O_SYNC)) == -1)
{ {
LOG(WARNING) << "Cannot open deviceio" << d_device_io_name; LOG(WARNING) << "Cannot open deviceio" << device_io_name;
} }
d_map_base = (volatile unsigned *)mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, d_fd,0);
d_map_base = (volatile unsigned *) mmap(NULL, PAGE_SIZE,
PROT_READ | PROT_WRITE, MAP_SHARED, d_device_descriptor, 0);
if (d_map_base == (void *) -1) if (d_map_base == (void *) -1)
{ {
LOG(WARNING) << "Cannot map the FPGA tracking module " << d_channel << "into user memory"; LOG(WARNING) << "Cannot map the FPGA tracking module "
<< d_channel << "into user memory";
} }
// sanity check : check test register // sanity check : check test register
unsigned writeval = 0x55AA; unsigned writeval = TEST_REGISTER_TRACK_WRITEVAL;
unsigned readval; unsigned readval;
readval = fpga_multicorrelator_8sc::fpga_acquisition_test_register(writeval); readval = fpga_multicorrelator_8sc::fpga_acquisition_test_register(
writeval);
if (writeval != readval) if (writeval != readval)
{ {
LOG(WARNING) << "Test register sanity check failed"; LOG(WARNING) << "Test register sanity check failed";
@ -228,8 +245,8 @@ void fpga_multicorrelator_8sc::set_channel(unsigned int channel)
} }
unsigned fpga_multicorrelator_8sc::fpga_acquisition_test_register(
unsigned fpga_multicorrelator_8sc::fpga_acquisition_test_register(unsigned writeval) unsigned writeval)
{ {
unsigned readval; unsigned readval;
// write value to test register // write value to test register
@ -240,75 +257,67 @@ unsigned fpga_multicorrelator_8sc::fpga_acquisition_test_register(unsigned write
return readval; return readval;
} }
void fpga_multicorrelator_8sc::fpga_configure_tracking_gps_local_code(void) void fpga_multicorrelator_8sc::fpga_configure_tracking_gps_local_code(void)
{ {
int k, s; int k, s;
unsigned temp; unsigned code_chip;
unsigned *ena_write_signals; unsigned select_fpga_correlator;
ena_write_signals = new unsigned[d_n_correlators];
ena_write_signals[0] = 0x00000000; select_fpga_correlator = 0;
ena_write_signals[1] = 0x20000000;
for (s = 2; s < d_n_correlators; s++)
{
ena_write_signals[s]= ena_write_signals[s-1]*2; //0x40000000;
}
for (s = 0; s < d_n_correlators; s++) for (s = 0; s < d_n_correlators; s++)
{ {
// clear memory address counter
d_map_base[11] = 0x10000000; d_map_base[11] = LOCAL_CODE_FPGA_CLEAR_ADDRESS_COUNTER;
// write correlator 0
for (k = 0; k < d_code_length_chips; k++) for (k = 0; k < d_code_length_chips; k++)
{ {
if (lv_creal(d_local_code_in[k]) == 1) if (lv_creal(d_local_code_in[k]) == 1)
{ {
temp = 1; code_chip = 1;
} }
else else
{ {
temp = 0; code_chip = 0;
} }
d_map_base[11] = 0x0C000000 | (temp & 0xFFFF) | ena_write_signals[s]; // copy the local code to the FPGA memory one by one
d_map_base[11] = LOCAL_CODE_FPGA_ENABLE_WRITE_MEMORY
| code_chip | select_fpga_correlator;
}
select_fpga_correlator = select_fpga_correlator
+ LOCAL_CODE_FPGA_CORRELATOR_SELECT_COUNT;
} }
} }
delete [] ena_write_signals;
}
void fpga_multicorrelator_8sc::fpga_compute_code_shift_parameters(void) void fpga_multicorrelator_8sc::fpga_compute_code_shift_parameters(void)
{ {
float tempvalues[3]; float temp_calculation;
float tempvalues2[3];
float tempvalues3[3];
int i; int i;
for (i = 0; i < d_n_correlators; i++) for (i = 0; i < d_n_correlators; i++)
{ {
// initial index calculation // initial index calculation
tempvalues[i] = floor(d_shifts_chips[i] + d_rem_code_phase_chips); temp_calculation = floor(
if (tempvalues[i] < 0) d_shifts_chips[i] + d_rem_code_phase_chips);
if (temp_calculation < 0)
{ {
tempvalues2[i] = tempvalues[i] + d_code_length_chips; // % operator does not work as in Matlab with negative numbers temp_calculation = temp_calculation + d_code_length_chips; // % operator does not work as in Matlab with negative numbers
} }
else d_initial_index[i] = (unsigned) ((int) temp_calculation)
{ % d_code_length_chips;
tempvalues2[i] = tempvalues[i];
}
d_initial_index[i] = (unsigned) ((int) tempvalues2[i]) % d_code_length_chips;
// initial interpolator counter calculation // initial interpolator counter calculation
tempvalues3[i] = fmod(d_shifts_chips[i]+ d_rem_code_phase_chips,1.0); temp_calculation = fmod(d_shifts_chips[i] + d_rem_code_phase_chips,
if (tempvalues3[i] < 0) 1.0);
if (temp_calculation < 0)
{ {
tempvalues3[i] = tempvalues3[i] + 1.0; // fmod operator does not work as in Matlab with negative numbers temp_calculation = temp_calculation + 1.0; // fmod operator does not work as in Matlab with negative numbers
} }
d_initial_interp_counter[i] = (unsigned) floor(MAX_CODE_RESAMPLER_COUNTER * tempvalues3[i]); d_initial_interp_counter[i] = (unsigned) floor(
MAX_CODE_RESAMPLER_COUNTER * temp_calculation);
} }
} }
void fpga_multicorrelator_8sc::fpga_configure_code_parameters_in_fpga(void) void fpga_multicorrelator_8sc::fpga_configure_code_parameters_in_fpga(void)
{ {
int i; int i;
@ -320,33 +329,38 @@ void fpga_multicorrelator_8sc::fpga_configure_code_parameters_in_fpga(void)
d_map_base[8] = d_code_length_chips - 1; // number of samples - 1 d_map_base[8] = d_code_length_chips - 1; // number of samples - 1
} }
void fpga_multicorrelator_8sc::fpga_compute_signal_parameters_in_fpga(void) void fpga_multicorrelator_8sc::fpga_compute_signal_parameters_in_fpga(void)
{ {
float d_rem_carrier_phase_in_rad_temp; float d_rem_carrier_phase_in_rad_temp;
d_code_phase_step_chips_num = (unsigned) roundf(MAX_CODE_RESAMPLER_COUNTER * d_code_phase_step_chips); d_code_phase_step_chips_num = (unsigned) roundf(
MAX_CODE_RESAMPLER_COUNTER * d_code_phase_step_chips);
if (d_rem_carrier_phase_in_rad > M_PI) if (d_rem_carrier_phase_in_rad > M_PI)
{ {
d_rem_carrier_phase_in_rad_temp = -2*M_PI + d_rem_carrier_phase_in_rad; d_rem_carrier_phase_in_rad_temp = -2 * M_PI
+ d_rem_carrier_phase_in_rad;
} }
else if (d_rem_carrier_phase_in_rad < -M_PI) else if (d_rem_carrier_phase_in_rad < -M_PI)
{ {
d_rem_carrier_phase_in_rad_temp = 2*M_PI + d_rem_carrier_phase_in_rad; d_rem_carrier_phase_in_rad_temp = 2 * M_PI
+ d_rem_carrier_phase_in_rad;
} }
else else
{ {
d_rem_carrier_phase_in_rad_temp = d_rem_carrier_phase_in_rad; d_rem_carrier_phase_in_rad_temp = d_rem_carrier_phase_in_rad;
} }
d_rem_carr_phase_rad_int = (int) roundf((fabs(d_rem_carrier_phase_in_rad_temp)/M_PI)*pow(2, PHASE_CARR_NBITS_FRAC)); d_rem_carr_phase_rad_int = (int) roundf(
(fabs(d_rem_carrier_phase_in_rad_temp) / M_PI)
* pow(2, PHASE_CARR_NBITS_FRAC));
if (d_rem_carrier_phase_in_rad_temp < 0) if (d_rem_carrier_phase_in_rad_temp < 0)
{ {
d_rem_carr_phase_rad_int = -d_rem_carr_phase_rad_int; d_rem_carr_phase_rad_int = -d_rem_carr_phase_rad_int;
} }
d_phase_step_rad_int = (int) roundf((fabs(d_phase_step_rad)/M_PI)*pow(2, PHASE_CARR_NBITS_FRAC)); // the FPGA accepts a range for the phase step between -pi and +pi d_phase_step_rad_int = (int) roundf(
(fabs(d_phase_step_rad) / M_PI) * pow(2, PHASE_CARR_NBITS_FRAC)); // the FPGA accepts a range for the phase step between -pi and +pi
if (d_phase_step_rad < 0) if (d_phase_step_rad < 0)
{ {
@ -354,68 +368,60 @@ void fpga_multicorrelator_8sc::fpga_compute_signal_parameters_in_fpga(void)
} }
} }
void fpga_multicorrelator_8sc::fpga_configure_signal_parameters_in_fpga(void) void fpga_multicorrelator_8sc::fpga_configure_signal_parameters_in_fpga(void)
{ {
d_map_base[0] = d_code_phase_step_chips_num; d_map_base[0] = d_code_phase_step_chips_num;
d_map_base[7] = d_correlator_length_samples - 1; d_map_base[7] = d_correlator_length_samples - 1;
d_map_base[9] = d_rem_carr_phase_rad_int; d_map_base[9] = d_rem_carr_phase_rad_int;
d_map_base[10] = d_phase_step_rad_int; d_map_base[10] = d_phase_step_rad_int;
d_map_base[12] = 0; // lock the channel
d_map_base[13] = d_initial_sample_counter; d_map_base[13] = d_initial_sample_counter;
} }
void fpga_multicorrelator_8sc::fpga_launch_multicorrelator_fpga(void) void fpga_multicorrelator_8sc::fpga_launch_multicorrelator_fpga(void)
{ {
// enable interrupts // enable interrupts
int reenable = 1; int reenable = 1;
write(d_fd, (void *)&reenable, sizeof(int)); write(d_device_descriptor, (void *) &reenable, sizeof(int));
d_map_base[14] = 0; // writing anything to reg 14 launches the tracking d_map_base[14] = 0; // writing anything to reg 14 launches the tracking
} }
void fpga_multicorrelator_8sc::read_tracking_gps_results(void) void fpga_multicorrelator_8sc::read_tracking_gps_results(void)
{ {
int *readval_real; int readval_real;
int *readval_imag; int readval_imag;
int k; int k;
readval_real = new int[d_n_correlators];
readval_imag = new int[d_n_correlators];
for (k = 0; k < d_n_correlators; k++) for (k = 0; k < d_n_correlators; k++)
{ {
readval_real[k] = d_map_base[1 + k]; readval_real = d_map_base[1 + k];
if (readval_real[k] >= 1048576) // 0x100000 (21 bits two's complement) if (readval_real >= 1048576) // 0x100000 (21 bits two's complement)
{ {
readval_real[k] = -2097152 + readval_real[k]; readval_real = -2097152 + readval_real;
}
readval_real = readval_real * 2; // the results are shifted two bits to the left due to the complex multiplier in the FPGA
readval_imag = d_map_base[1 + d_n_correlators + k];
if (readval_imag >= 1048576) // 0x100000 (21 bits two's complement)
{
readval_imag = -2097152 + readval_imag;
}
readval_imag = readval_imag * 2; // the results are shifted two bits to the left due to the complex multiplier in the FPGA
d_corr_out[k] = lv_cmake(readval_real, readval_imag);
} }
readval_real[k] = readval_real[k] * 2; // the results are shifted two bits to the left due to the complex multiplier in the FPGA
} }
for (k = 0; k < d_n_correlators; k++)
{
readval_imag[k] = d_map_base[1 + d_n_correlators + k];
if (readval_imag[k] >= 1048576) // 0x100000 (21 bits two's complement)
{
readval_imag[k] = -2097152 + readval_imag[k];
}
readval_imag[k] = readval_imag[k] * 2; // the results are shifted two bits to the left due to the complex multiplier in the FPGA
}
for (k = 0; k < d_n_correlators; k++)
{
d_corr_out[k] = lv_cmake(readval_real[k], readval_imag[k]);
}
delete[] readval_real;
delete[] readval_imag;
}
void fpga_multicorrelator_8sc::unlock_channel(void) void fpga_multicorrelator_8sc::unlock_channel(void)
{ {
// unlock the channel to let the next samples go through // unlock the channel to let the next samples go through
d_map_base[12] = 1; // unlock the channel d_map_base[12] = 1; // unlock the channel
} }
void fpga_multicorrelator_8sc::lock_channel(void)
{
// lock the channel for processing
d_map_base[12] = 0; // lock the channel
}

View File

@ -39,7 +39,6 @@
#include <volk_gnsssdr/volk_gnsssdr.h> #include <volk_gnsssdr/volk_gnsssdr.h>
#define MAX_LENGTH_DEVICEIO_NAME 50 #define MAX_LENGTH_DEVICEIO_NAME 50
/*! /*!
@ -48,17 +47,20 @@
class fpga_multicorrelator_8sc class fpga_multicorrelator_8sc
{ {
public: public:
fpga_multicorrelator_8sc(); fpga_multicorrelator_8sc(int n_correlators, std::string device_name,
~fpga_multicorrelator_8sc(); unsigned int device_base);
bool init(int n_correlators); ~fpga_multicorrelator_8sc();bool set_local_code_and_taps(
bool set_local_code_and_taps(int code_length_chips, const lv_16sc_t* local_code_in, float *shifts_chips); int code_length_chips, const lv_16sc_t* local_code_in,
bool set_output_vectors(lv_16sc_t* corr_out); float *shifts_chips);bool set_output_vectors(lv_16sc_t* corr_out);
void update_local_code(float rem_code_phase_chips); void update_local_code(float rem_code_phase_chips);bool Carrier_wipeoff_multicorrelator_resampler(
bool Carrier_wipeoff_multicorrelator_resampler(float rem_carrier_phase_in_rad, float phase_step_rad, float rem_code_phase_chips, float code_phase_step_chips, int signal_length_samples); float rem_carrier_phase_in_rad, float phase_step_rad,
bool free(); float rem_code_phase_chips, float code_phase_step_chips,
int signal_length_samples);bool free();
void set_channel(unsigned int channel); void set_channel(unsigned int channel);
void set_initial_sample(int samples_offset); void set_initial_sample(int samples_offset);
void lock_channel(void);
void unlock_channel(void);
private: private:
const lv_16sc_t *d_local_code_in; const lv_16sc_t *d_local_code_in;
@ -68,8 +70,7 @@ private:
int d_n_correlators; int d_n_correlators;
// data related to the hardware module and the driver // data related to the hardware module and the driver
char d_device_io_name[MAX_LENGTH_DEVICEIO_NAME]; // driver io name int d_device_descriptor; // driver descriptor
int d_fd; // driver descriptor
volatile unsigned *d_map_base; // driver memory map volatile unsigned *d_map_base; // driver memory map
// configuration data received from the interface // configuration data received from the interface
@ -89,6 +90,13 @@ private:
int d_phase_step_rad_int; int d_phase_step_rad_int;
unsigned d_initial_sample_counter; unsigned d_initial_sample_counter;
// driver
std::string d_device_name;
unsigned int d_device_base;
// results
//int *d_readval_real;
//int *d_readval_imag;
// FPGA private functions // FPGA private functions
unsigned fpga_acquisition_test_register(unsigned writeval); unsigned fpga_acquisition_test_register(unsigned writeval);
void fpga_configure_tracking_gps_local_code(void); void fpga_configure_tracking_gps_local_code(void);
@ -98,8 +106,9 @@ private:
void fpga_configure_signal_parameters_in_fpga(void); void fpga_configure_signal_parameters_in_fpga(void);
void fpga_launch_multicorrelator_fpga(void); void fpga_launch_multicorrelator_fpga(void);
void read_tracking_gps_results(void); void read_tracking_gps_results(void);
void unlock_channel(void);
//void unlock_channel(void);
}; };
#endif /* GNSS_SDR_FPGA_MULTICORRELATOR_H_ */ #endif /* GNSS_SDR_FPGA_MULTICORRELATOR_H_ */

View File

@ -29,9 +29,6 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
@ -54,21 +51,21 @@
#include <unistd.h> #include <unistd.h>
#define DMA_ACQ_TRANSFER_SIZE 4000 #define DMA_ACQ_TRANSFER_SIZE 2046 // DMA transfer size for the acquisition
#define RX_SIGNAL_MAX_VALUE 127 // 2^7 - 1 for 8-bit signed values #define RX_SIGNAL_MAX_VALUE 127 // 2^7 - 1 for 8-bit signed values
#define NTIMES_CYCLE_THROUGH_RX_SAMPLES_FILE 50 // number of times we cycle through the file containing the received samples #define NTIMES_CYCLE_THROUGH_RX_SAMPLES_FILE 50 // number of times we cycle through the file containing the received samples
#define ONE_SECOND 1000000 // one second in microseconds #define ONE_SECOND 1000000 // one second in microseconds
#define FLOAT_SIZE (sizeof(float)) // size of the float variable in characters #define FLOAT_SIZE (sizeof(float)) // size of the float variable in characters
// thread that reads the file containing the received samples, scales the samples to the dynamic range of the fixed point values, sends // thread that reads the file containing the received samples, scales the samples to the dynamic range of the fixed point values, sends
// the samples to the DMA and finally it stops the top block // the samples to the DMA and finally it stops the top block
void thread_acquisition_send_rx_samples(gr::top_block_sptr top_block, const char * file_name) void thread_acquisition_send_rx_samples(gr::top_block_sptr top_block,
const char * file_name)
{ {
FILE *ptr_myfile; // file descriptor FILE *rx_signal_file; // file descriptor
int fileLen; // length of the file containing the received samples int file_length; // length of the file containing the received samples
int tx_fd; // DMA descriptor int dma_descr; // DMA descriptor
// sleep for 1 second to give some time to GNSS-SDR to activate the acquisition module. // sleep for 1 second to give some time to GNSS-SDR to activate the acquisition module.
// the acquisition module does not block the RX buffer before activation. // the acquisition module does not block the RX buffer before activation.
@ -77,33 +74,33 @@ void thread_acquisition_send_rx_samples(gr::top_block_sptr top_block, const char
// we want for the test // we want for the test
usleep(ONE_SECOND); usleep(ONE_SECOND);
char *buffer_temp; // temporary buffer to convert from binary char to float and from float to char char *buffer_float; // temporary buffer to convert from binary char to float and from float to char
signed char *buffer_char; // temporary buffer to store the samples to be sent to the DMA signed char *buffer_DMA; // temporary buffer to store the samples to be sent to the DMA
buffer_temp = (char *)malloc(FLOAT_SIZE); // allocate space for the temporary buffer buffer_float = (char *) malloc(FLOAT_SIZE); // allocate space for the temporary buffer
if (!buffer_temp) if (!buffer_float)
{ {
fprintf(stderr, "Memory error!"); fprintf(stderr, "Memory error!");
} }
ptr_myfile = fopen(file_name,"rb"); // file containing the received signal rx_signal_file = fopen(file_name, "rb"); // file containing the received signal
if (!ptr_myfile) if (!rx_signal_file)
{ {
printf("Unable to open file!"); printf("Unable to open file!");
} }
// determine the length of the file that contains the received signal // determine the length of the file that contains the received signal
fseek(ptr_myfile, 0, SEEK_END); fseek(rx_signal_file, 0, SEEK_END);
fileLen = ftell(ptr_myfile); file_length = ftell(rx_signal_file);
fseek(ptr_myfile, 0, SEEK_SET); fseek(rx_signal_file, 0, SEEK_SET);
// first step: check for the maximum value of the received signal // first step: check for the maximum value of the received signal
float max = 0; float max = 0;
float *pointer_float; float *pointer_float;
pointer_float = (float *) &buffer_temp[0]; pointer_float = (float *) &buffer_float[0];
for (int k=0;k<fileLen;k=k+FLOAT_SIZE) for (int k = 0; k < file_length; k = k + FLOAT_SIZE)
{ {
fread(buffer_temp, FLOAT_SIZE, 1, ptr_myfile); fread(buffer_float, FLOAT_SIZE, 1, rx_signal_file);
if (fabs(pointer_float[0]) > max) if (fabs(pointer_float[0]) > max)
{ {
@ -113,77 +110,76 @@ void thread_acquisition_send_rx_samples(gr::top_block_sptr top_block, const char
} }
// go back to the beginning of the file containing the received samples // go back to the beginning of the file containing the received samples
fseek(ptr_myfile, 0, SEEK_SET); fseek(rx_signal_file, 0, SEEK_SET);
// allocate memory for the samples to be transferred to the DMA // allocate memory for the samples to be transferred to the DMA
buffer_char = (signed char *)malloc(DMA_ACQ_TRANSFER_SIZE); buffer_DMA = (signed char *) malloc(DMA_ACQ_TRANSFER_SIZE);
if (!buffer_char) if (!buffer_DMA)
{ {
fprintf(stderr, "Memory error!"); fprintf(stderr, "Memory error!");
} }
// open the DMA descriptor // open the DMA descriptor
tx_fd = open("/dev/loop_tx", O_WRONLY); dma_descr = open("/dev/loop_tx", O_WRONLY);
if ( tx_fd < 0 ) if (dma_descr < 0)
{ {
printf("can't open loop device\n"); printf("can't open loop device\n");
exit(1); exit(1);
} }
// cycle through the file containing the received samples // cycle through the file containing the received samples
for (int k = 0; k < NTIMES_CYCLE_THROUGH_RX_SAMPLES_FILE; k++) for (int k = 0; k < NTIMES_CYCLE_THROUGH_RX_SAMPLES_FILE; k++)
{ {
fseek(rx_signal_file, 0, SEEK_SET);
fseek(ptr_myfile, 0, SEEK_SET);
int transfer_size; int transfer_size;
int num_transferred_samples = 0; int num_transferred_samples = 0;
while (num_transferred_samples < (int) (fileLen/FLOAT_SIZE)) while (num_transferred_samples < (int) (file_length / FLOAT_SIZE))
{ {
if (((fileLen/FLOAT_SIZE) - num_transferred_samples) > DMA_ACQ_TRANSFER_SIZE) if (((file_length / FLOAT_SIZE) - num_transferred_samples)
> DMA_ACQ_TRANSFER_SIZE)
{ {
transfer_size = DMA_ACQ_TRANSFER_SIZE; transfer_size = DMA_ACQ_TRANSFER_SIZE;
num_transferred_samples = num_transferred_samples + DMA_ACQ_TRANSFER_SIZE; num_transferred_samples = num_transferred_samples
+ DMA_ACQ_TRANSFER_SIZE;
} }
else else
{ {
transfer_size = fileLen/FLOAT_SIZE - num_transferred_samples; transfer_size = file_length / FLOAT_SIZE
num_transferred_samples = fileLen/FLOAT_SIZE; - num_transferred_samples;
num_transferred_samples = file_length / FLOAT_SIZE;
} }
for (int t = 0; t < transfer_size; t++) for (int t = 0; t < transfer_size; t++)
{ {
fread(buffer_temp, FLOAT_SIZE, 1, ptr_myfile); fread(buffer_float, FLOAT_SIZE, 1, rx_signal_file);
// specify (float) (int) for a quantization maximizing the dynamic range // specify (float) (int) for a quantization maximizing the dynamic range
buffer_char[t] = (signed char) ((pointer_float[0]*(RX_SIGNAL_MAX_VALUE - 1))/max); buffer_DMA[t] = (signed char) ((pointer_float[0]
* (RX_SIGNAL_MAX_VALUE - 1)) / max);
} }
//send_acquisition_gps_input_samples(buffer_char, transfer_size, tx_fd); //send_acquisition_gps_input_samples(buffer_DMA, transfer_size, dma_descr);
assert( transfer_size == write(tx_fd, &buffer_char[0], transfer_size) ); assert(
transfer_size == write(dma_descr, &buffer_DMA[0], transfer_size));
} }
} }
fclose(ptr_myfile); fclose(rx_signal_file);
free(buffer_temp); free(buffer_float);
free(buffer_char); free(buffer_DMA);
close(tx_fd); close(dma_descr);
// when all the samples are sent stop the top block // when all the samples are sent stop the top block
top_block->stop(); top_block->stop();
} }
// ######## GNURADIO BLOCK MESSAGE RECEVER ######### // ######## GNURADIO BLOCK MESSAGE RECEVER #########
@ -204,13 +200,12 @@ public:
~GpsL1CaPcpsAcquisitionTestFpga_msg_rx(); //!< Default destructor ~GpsL1CaPcpsAcquisitionTestFpga_msg_rx(); //!< Default destructor
}; };
GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make() GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make()
{ {
return GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr(new GpsL1CaPcpsAcquisitionTestFpga_msg_rx()); return GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr(
new GpsL1CaPcpsAcquisitionTestFpga_msg_rx());
} }
void GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg) void GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg)
{ {
try try
@ -225,21 +220,22 @@ void GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg)
} }
} }
GpsL1CaPcpsAcquisitionTestFpga_msg_rx::GpsL1CaPcpsAcquisitionTestFpga_msg_rx() : GpsL1CaPcpsAcquisitionTestFpga_msg_rx::GpsL1CaPcpsAcquisitionTestFpga_msg_rx() :
gr::block("GpsL1CaPcpsAcquisitionTestFpga_msg_rx", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) gr::block("GpsL1CaPcpsAcquisitionTestFpga_msg_rx",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0))
{ {
this->message_port_register_in(pmt::mp("events")); this->message_port_register_in(pmt::mp("events"));
this->set_msg_handler(pmt::mp("events"), boost::bind(&GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events, this, _1)); this->set_msg_handler(pmt::mp("events"),
boost::bind(
&GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events,
this, _1));
rx_message = 0; rx_message = 0;
} }
GpsL1CaPcpsAcquisitionTestFpga_msg_rx::~GpsL1CaPcpsAcquisitionTestFpga_msg_rx() GpsL1CaPcpsAcquisitionTestFpga_msg_rx::~GpsL1CaPcpsAcquisitionTestFpga_msg_rx()
{} {
}
// ###########################################################
class GpsL1CaPcpsAcquisitionTestFpga : public ::testing::Test class GpsL1CaPcpsAcquisitionTestFpga : public ::testing::Test
{ {
@ -253,7 +249,8 @@ protected:
} }
~GpsL1CaPcpsAcquisitionTestFpga() ~GpsL1CaPcpsAcquisitionTestFpga()
{} {
}
void init(); void init();
@ -264,7 +261,6 @@ protected:
size_t item_size; size_t item_size;
}; };
void GpsL1CaPcpsAcquisitionTestFpga::init() void GpsL1CaPcpsAcquisitionTestFpga::init()
{ {
gnss_synchro.Channel_ID = 0; gnss_synchro.Channel_ID = 0;
@ -277,21 +273,24 @@ void GpsL1CaPcpsAcquisitionTestFpga::init()
config->set_property("Acquisition.if", "0"); config->set_property("Acquisition.if", "0");
config->set_property("Acquisition.coherent_integration_time_ms", "1"); config->set_property("Acquisition.coherent_integration_time_ms", "1");
config->set_property("Acquisition.dump", "false"); config->set_property("Acquisition.dump", "false");
config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Acquisition"); config->set_property("Acquisition.implementation",
"GPS_L1_CA_PCPS_Acquisition");
config->set_property("Acquisition.threshold", "0.001"); config->set_property("Acquisition.threshold", "0.001");
config->set_property("Acquisition.doppler_max", "5000"); config->set_property("Acquisition.doppler_max", "5000");
config->set_property("Acquisition.doppler_step", "500"); config->set_property("Acquisition.doppler_step", "500");
config->set_property("Acquisition.repeat_satellite", "false"); config->set_property("Acquisition.repeat_satellite", "false");
config->set_property("Acquisition.pfa", "0.0"); config->set_property("Acquisition.pfa", "0.0");
config->set_property("Acquisition.select_queue_Fpga", "0"); config->set_property("Acquisition.select_queue_Fpga", "0");
config->set_property("Acquisition.devicename", "/dev/uio0");
} }
TEST_F(GpsL1CaPcpsAcquisitionTestFpga, Instantiate) TEST_F(GpsL1CaPcpsAcquisitionTestFpga, Instantiate)
{ {
init(); init();
boost::shared_ptr<GpsL1CaPcpsAcquisitionFpga> acquisition = boost::make_shared<GpsL1CaPcpsAcquisitionFpga>(config.get(), "Acquisition", 0, 1); boost::shared_ptr<GpsL1CaPcpsAcquisitionFpga> acquisition =
boost::make_shared<GpsL1CaPcpsAcquisitionFpga>(config.get(),
"Acquisition", 0, 1);
} }
TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults) TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults)
@ -305,31 +304,40 @@ TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults)
double expected_doppler_hz = 1680; double expected_doppler_hz = 1680;
init(); init();
std::shared_ptr<GpsL1CaPcpsAcquisitionFpga> acquisition = std::make_shared<GpsL1CaPcpsAcquisitionFpga>(config.get(), "Acquisition", 0, 1); std::shared_ptr < GpsL1CaPcpsAcquisitionFpga > acquisition =
std::make_shared < GpsL1CaPcpsAcquisitionFpga
> (config.get(), "Acquisition", 0, 1);
boost::shared_ptr<GpsL1CaPcpsAcquisitionTestFpga_msg_rx> msg_rx = GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make(); boost::shared_ptr<GpsL1CaPcpsAcquisitionTestFpga_msg_rx> msg_rx =
GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make();
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
acquisition->set_channel(1); acquisition->set_channel(1);
})<< "Failure setting channel." << std::endl; })<< "Failure setting channel." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
acquisition->set_gnss_synchro(&gnss_synchro); acquisition->set_gnss_synchro(&gnss_synchro);
})<< "Failure setting gnss_synchro." << std::endl; })<< "Failure setting gnss_synchro." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
acquisition->set_threshold(0.1); acquisition->set_threshold(0.1);
})<< "Failure setting threshold." << std::endl; })<< "Failure setting threshold." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
acquisition->set_doppler_max(10000); acquisition->set_doppler_max(10000);
})<< "Failure setting doppler_max." << std::endl; })<< "Failure setting doppler_max." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
acquisition->set_doppler_step(250); acquisition->set_doppler_step(250);
})<< "Failure setting doppler_step." << std::endl; })<< "Failure setting doppler_step." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
acquisition->connect(top_block); acquisition->connect(top_block);
})<< "Failure connecting acquisition to the top_block." << std::endl; })<< "Failure connecting acquisition to the top_block." << std::endl;
@ -342,7 +350,8 @@ TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults)
const char * file_name = file.c_str(); const char * file_name = file.c_str();
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
// for the unit test use dummy blocks to make the flowgraph work and allow the acquisition message to be sent. // for the unit test use dummy blocks to make the flowgraph work and allow the acquisition message to be sent.
// in the actual system there is a flowchart running in parallel so this is not needed // in the actual system there is a flowchart running in parallel so this is not needed
@ -360,9 +369,11 @@ TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults)
top_block->start(); // Start the top block top_block->start(); // Start the top block
// start thread that sends the DMA samples to the FPGA // start thread that sends the DMA samples to the FPGA
boost::thread t3{thread_acquisition_send_rx_samples, top_block, file_name}; boost::thread t3
{ thread_acquisition_send_rx_samples, top_block, file_name };
EXPECT_NO_THROW( { EXPECT_NO_THROW(
{
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
begin = tv.tv_sec * 1000000 + tv.tv_usec; begin = tv.tv_sec * 1000000 + tv.tv_usec;
acquisition->reset(); // launch the tracking process acquisition->reset(); // launch the tracking process
@ -373,16 +384,22 @@ TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults)
t3.join(); t3.join();
std::cout << "Ran GpsL1CaPcpsAcquisitionTestFpga in " << (end - begin) << " microseconds" << std::endl; std::cout << "Ran GpsL1CaPcpsAcquisitionTestFpga in " << (end - begin)
<< " microseconds" << std::endl;
ASSERT_EQ(1, msg_rx->rx_message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; ASSERT_EQ(1, msg_rx->rx_message)
<< "Acquisition failure. Expected message: 1=ACQ SUCCESS.";
double delay_error_samples = std::abs(expected_delay_samples - gnss_synchro.Acq_delay_samples); double delay_error_samples = std::abs(
expected_delay_samples - gnss_synchro.Acq_delay_samples);
float delay_error_chips = (float) (delay_error_samples * 1023 / 4000); float delay_error_chips = (float) (delay_error_samples * 1023 / 4000);
double doppler_error_hz = std::abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); double doppler_error_hz = std::abs(
expected_doppler_hz - gnss_synchro.Acq_doppler_hz);
EXPECT_LE(doppler_error_hz, 666) << "Doppler error exceeds the expected value: 666 Hz = 2/(3*integration period)"; EXPECT_LE(doppler_error_hz, 666)
EXPECT_LT(delay_error_chips, 0.5) << "Delay error exceeds the expected value: 0.5 chips"; << "Doppler error exceeds the expected value: 666 Hz = 2/(3*integration period)";
EXPECT_LT(delay_error_chips, 0.5)
<< "Delay error exceeds the expected value: 0.5 chips";
} }

View File

@ -31,7 +31,6 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include <ctime> #include <ctime>
#include <fcntl.h> #include <fcntl.h>
#include <iostream> #include <iostream>
@ -63,43 +62,33 @@
#include "signal_generator_flags.h" #include "signal_generator_flags.h"
#include "interleaved_byte_to_complex_short.h" #include "interleaved_byte_to_complex_short.h"
#define DMA_TRACK_TRANSFER_SIZE 2046 // DMA transfer size for tracking
#define MAX_NUM_TEST_CASES 20
#define MAX_INPUT_SAMPLES_PER_TEST_CASE (8184)
#define MAX_INPUT_SAMPLES_TOTAL MAX_INPUT_SAMPLES_PER_TEST_CASE*MAX_NUM_TEST_CASES
#define DMA_TRANSFER_SIZE 2046
#define MIN_SAMPLES_REMAINING 20000 // number of remaining samples in the DMA that causes the CPU to stop the flowgraph (it has to be a bit alrger than 2x max packet size) #define MIN_SAMPLES_REMAINING 20000 // number of remaining samples in the DMA that causes the CPU to stop the flowgraph (it has to be a bit alrger than 2x max packet size)
#define FIVE_SECONDS 5000000 // five seconds in microseconds
void send_tracking_gps_input_samples(FILE *rx_signal_file,
void wait(int seconds) int num_remaining_samples, gr::top_block_sptr top_block)
{ {
boost::this_thread::sleep_for(boost::chrono::seconds{seconds}); int num_samples_transferred = 0; // number of samples that have been transferred to the DMA so far
} static int flowgraph_stopped = 0; // flag to indicate if the flowgraph is stopped already
char *buffer_DMA; // temporary buffer to store the samples to be sent to the DMA
void send_tracking_gps_input_samples(FILE *ptr_myfile, int num_remaining_samples, gr::top_block_sptr top_block) int dma_descr; // DMA descriptor
{ dma_descr = open("/dev/loop_tx", O_WRONLY);
int num_samples_transferred = 0; if (dma_descr < 0)
static int flowgraph_stopped = 0;
char *buffer;
// DMA descriptor
int tx_fd;
tx_fd = open("/dev/loop_tx", O_WRONLY);
if ( tx_fd < 0 )
{ {
printf("can't open loop device\n"); printf("can't open loop device\n");
exit(1); exit(1);
} }
buffer = (char *)malloc(DMA_TRANSFER_SIZE); buffer_DMA = (char *) malloc(DMA_TRACK_TRANSFER_SIZE);
if (!buffer) if (!buffer_DMA)
{ {
fprintf(stderr, "Memory error!"); fprintf(stderr, "Memory error!");
} }
while (num_remaining_samples > 0) while (num_remaining_samples > 0)
{ {
if (num_remaining_samples < MIN_SAMPLES_REMAINING) if (num_remaining_samples < MIN_SAMPLES_REMAINING)
{ {
if (flowgraph_stopped == 0) if (flowgraph_stopped == 0)
@ -109,66 +98,67 @@ void send_tracking_gps_input_samples(FILE *ptr_myfile, int num_remaining_samples
flowgraph_stopped = 1; flowgraph_stopped = 1;
} }
} }
if (num_remaining_samples > DMA_TRANSFER_SIZE) if (num_remaining_samples > DMA_TRACK_TRANSFER_SIZE)
{ {
fread(buffer, DMA_TRANSFER_SIZE, 1, ptr_myfile); fread(buffer_DMA, DMA_TRACK_TRANSFER_SIZE, 1,
rx_signal_file);
assert( DMA_TRANSFER_SIZE == write(tx_fd, &buffer[0], DMA_TRANSFER_SIZE) ); assert(
num_remaining_samples = num_remaining_samples - DMA_TRANSFER_SIZE; DMA_TRACK_TRANSFER_SIZE == write(dma_descr, &buffer_DMA[0], DMA_TRACK_TRANSFER_SIZE));
num_samples_transferred = num_samples_transferred + DMA_TRANSFER_SIZE; num_remaining_samples = num_remaining_samples
- DMA_TRACK_TRANSFER_SIZE;
num_samples_transferred = num_samples_transferred
+ DMA_TRACK_TRANSFER_SIZE;
} }
else else
{ {
fread(buffer, num_remaining_samples, 1, ptr_myfile); fread(buffer_DMA, num_remaining_samples, 1, rx_signal_file);
assert( num_remaining_samples == write(tx_fd, &buffer[0], num_remaining_samples) ); assert(
num_samples_transferred = num_samples_transferred + num_remaining_samples; num_remaining_samples == write(dma_descr, &buffer_DMA[0], num_remaining_samples));
num_samples_transferred = num_samples_transferred
+ num_remaining_samples;
num_remaining_samples = 0; num_remaining_samples = 0;
} }
} }
free(buffer); free(buffer_DMA);
close(tx_fd); close(dma_descr);
} }
// thread that sends the samples to the FPGA // thread that sends the samples to the FPGA
void thread(gr::top_block_sptr top_block, const char * file_name) void thread(gr::top_block_sptr top_block, const char * file_name)
{ {
// file descriptor // file descriptor
FILE *ptr_myfile; FILE *rx_signal_file; // file descriptor
int fileLen; int file_length; // length of the file containing the received samples
ptr_myfile = fopen(file_name,"rb"); rx_signal_file = fopen(file_name, "rb");
if (!ptr_myfile) if (!rx_signal_file)
{ {
printf("Unable to open file!"); printf("Unable to open file!");
} }
fseek(ptr_myfile, 0, SEEK_END); fseek(rx_signal_file, 0, SEEK_END);
fileLen = ftell(ptr_myfile); file_length = ftell(rx_signal_file);
fseek(ptr_myfile, 0, SEEK_SET); fseek(rx_signal_file, 0, SEEK_SET);
wait(20); // wait for some time to give time to the other thread to program the device usleep(FIVE_SECONDS); // wait for some time to give time to the other thread to program the device
//send_tracking_gps_input_samples(tx_fd, ptr_myfile, fileLen); //send_tracking_gps_input_samples(dma_descr, rx_signal_file, file_length);
send_tracking_gps_input_samples(ptr_myfile, fileLen, top_block); send_tracking_gps_input_samples(rx_signal_file, file_length, top_block);
fclose(ptr_myfile); fclose(rx_signal_file);
} }
// ######## GNURADIO BLOCK MESSAGE RECEVER ######### // ######## GNURADIO BLOCK MESSAGE RECEVER #########
class GpsL1CADllPllTrackingTestFpga_msg_rx; class GpsL1CADllPllTrackingTestFpga_msg_rx;
typedef boost::shared_ptr<GpsL1CADllPllTrackingTestFpga_msg_rx> GpsL1CADllPllTrackingTestFpga_msg_rx_sptr; typedef boost::shared_ptr<GpsL1CADllPllTrackingTestFpga_msg_rx> GpsL1CADllPllTrackingTestFpga_msg_rx_sptr;
GpsL1CADllPllTrackingTestFpga_msg_rx_sptr GpsL1CADllPllTrackingTestFpga_msg_rx_make(); GpsL1CADllPllTrackingTestFpga_msg_rx_sptr GpsL1CADllPllTrackingTestFpga_msg_rx_make();
class GpsL1CADllPllTrackingTestFpga_msg_rx : public gr::block class GpsL1CADllPllTrackingTestFpga_msg_rx : public gr::block
{ {
private: private:
@ -181,13 +171,12 @@ public:
~GpsL1CADllPllTrackingTestFpga_msg_rx(); //!< Default destructor ~GpsL1CADllPllTrackingTestFpga_msg_rx(); //!< Default destructor
}; };
GpsL1CADllPllTrackingTestFpga_msg_rx_sptr GpsL1CADllPllTrackingTestFpga_msg_rx_make() GpsL1CADllPllTrackingTestFpga_msg_rx_sptr GpsL1CADllPllTrackingTestFpga_msg_rx_make()
{ {
return GpsL1CADllPllTrackingTestFpga_msg_rx_sptr(new GpsL1CADllPllTrackingTestFpga_msg_rx()); return GpsL1CADllPllTrackingTestFpga_msg_rx_sptr(
new GpsL1CADllPllTrackingTestFpga_msg_rx());
} }
void GpsL1CADllPllTrackingTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg) void GpsL1CADllPllTrackingTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg)
{ {
try try
@ -202,22 +191,25 @@ void GpsL1CADllPllTrackingTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg)
} }
} }
GpsL1CADllPllTrackingTestFpga_msg_rx::GpsL1CADllPllTrackingTestFpga_msg_rx() : GpsL1CADllPllTrackingTestFpga_msg_rx::GpsL1CADllPllTrackingTestFpga_msg_rx() :
gr::block("GpsL1CADllPllTrackingTestFpga_msg_rx", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) gr::block("GpsL1CADllPllTrackingTestFpga_msg_rx",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0))
{ {
this->message_port_register_in(pmt::mp("events")); this->message_port_register_in(pmt::mp("events"));
this->set_msg_handler(pmt::mp("events"), boost::bind(&GpsL1CADllPllTrackingTestFpga_msg_rx::msg_handler_events, this, _1)); this->set_msg_handler(pmt::mp("events"),
boost::bind(
&GpsL1CADllPllTrackingTestFpga_msg_rx::msg_handler_events,
this, _1));
rx_message = 0; rx_message = 0;
} }
GpsL1CADllPllTrackingTestFpga_msg_rx::~GpsL1CADllPllTrackingTestFpga_msg_rx() GpsL1CADllPllTrackingTestFpga_msg_rx::~GpsL1CADllPllTrackingTestFpga_msg_rx()
{} {
}
// ########################################################### // ###########################################################
class GpsL1CADllPllTrackingTestFpga : public ::testing::Test class GpsL1CADllPllTrackingTestFpga : public ::testing::Test
{ {
public: public:
@ -235,18 +227,12 @@ public:
int configure_generator(); int configure_generator();
int generate_signal(); int generate_signal();
void check_results_doppler(arma::vec true_time_s, void check_results_doppler(arma::vec true_time_s, arma::vec true_value,
arma::vec true_value, arma::vec meas_time_s, arma::vec meas_value);
arma::vec meas_time_s,
arma::vec meas_value);
void check_results_acc_carrier_phase(arma::vec true_time_s, void check_results_acc_carrier_phase(arma::vec true_time_s,
arma::vec true_value, arma::vec true_value, arma::vec meas_time_s, arma::vec meas_value);
arma::vec meas_time_s, void check_results_codephase(arma::vec true_time_s, arma::vec true_value,
arma::vec meas_value); arma::vec meas_time_s, arma::vec meas_value);
void check_results_codephase(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value);
GpsL1CADllPllTrackingTestFpga() GpsL1CADllPllTrackingTestFpga()
{ {
@ -257,7 +243,8 @@ public:
} }
~GpsL1CADllPllTrackingTestFpga() ~GpsL1CADllPllTrackingTestFpga()
{} {
}
void configure_receiver(); void configure_receiver();
@ -268,7 +255,6 @@ public:
size_t item_size; size_t item_size;
}; };
int GpsL1CADllPllTrackingTestFpga::configure_generator() int GpsL1CADllPllTrackingTestFpga::configure_generator()
{ {
// Configure signal generator // Configure signal generator
@ -277,24 +263,28 @@ int GpsL1CADllPllTrackingTestFpga::configure_generator()
p1 = std::string("-rinex_nav_file=") + FLAGS_rinex_nav_file; p1 = std::string("-rinex_nav_file=") + FLAGS_rinex_nav_file;
if (FLAGS_dynamic_position.empty()) if (FLAGS_dynamic_position.empty())
{ {
p2 = std::string("-static_position=") + FLAGS_static_position + std::string(",") + std::to_string(FLAGS_duration * 10); p2 = std::string("-static_position=") + FLAGS_static_position
+ std::string(",") + std::to_string(FLAGS_duration * 10);
} }
else else
{ {
p2 = std::string("-obs_pos_file=") + std::string(FLAGS_dynamic_position); p2 = std::string("-obs_pos_file=")
+ std::string(FLAGS_dynamic_position);
} }
p3 = std::string("-rinex_obs_file=") + FLAGS_filename_rinex_obs; // RINEX 2.10 observation file output p3 = std::string("-rinex_obs_file=") + FLAGS_filename_rinex_obs; // RINEX 2.10 observation file output
p4 = std::string("-sig_out_file=") + FLAGS_filename_raw_data; // Baseband signal output file. Will be stored in int8_t IQ multiplexed samples p4 = std::string("-sig_out_file=") + FLAGS_filename_raw_data; // Baseband signal output file. Will be stored in int8_t IQ multiplexed samples
p5 = std::string("-sampling_freq=") + std::to_string(baseband_sampling_freq); //Baseband sampling frequency [MSps] p5 = std::string("-sampling_freq=")
+ std::to_string(baseband_sampling_freq); //Baseband sampling frequency [MSps]
return 0; return 0;
} }
int GpsL1CADllPllTrackingTestFpga::generate_signal() int GpsL1CADllPllTrackingTestFpga::generate_signal()
{ {
int child_status; int child_status;
char *const parmList[] = { &generator_binary[0], &generator_binary[0], &p1[0], &p2[0], &p3[0], &p4[0], &p5[0], NULL }; char * const parmList[] =
{ &generator_binary[0], &generator_binary[0], &p1[0], &p2[0], &p3[0],
&p4[0], &p5[0], NULL };
int pid; int pid;
if ((pid = fork()) == -1) if ((pid = fork()) == -1)
@ -302,17 +292,18 @@ int GpsL1CADllPllTrackingTestFpga::generate_signal()
else if (pid == 0) else if (pid == 0)
{ {
execv(&generator_binary[0], parmList); execv(&generator_binary[0], parmList);
std::cout << "Return not expected. Must be an execv err." << std::endl; std::cout << "Return not expected. Must be an execv err."
<< std::endl;
std::terminate(); std::terminate();
} }
waitpid(pid, &child_status, 0); waitpid(pid, &child_status, 0);
std::cout << "Signal and Observables RINEX and RAW files created." << std::endl; std::cout << "Signal and Observables RINEX and RAW files created."
<< std::endl;
return 0; return 0;
} }
void GpsL1CADllPllTrackingTestFpga::configure_receiver() void GpsL1CADllPllTrackingTestFpga::configure_receiver()
{ {
gnss_synchro.Channel_ID = 0; gnss_synchro.Channel_ID = 0;
@ -321,9 +312,11 @@ void GpsL1CADllPllTrackingTestFpga::configure_receiver()
signal.copy(gnss_synchro.Signal, 2, 0); signal.copy(gnss_synchro.Signal, 2, 0);
gnss_synchro.PRN = FLAGS_test_satellite_PRN; gnss_synchro.PRN = FLAGS_test_satellite_PRN;
config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(baseband_sampling_freq)); config->set_property("GNSS-SDR.internal_fs_hz",
std::to_string(baseband_sampling_freq));
// Set Tracking // Set Tracking
config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_C_Aid_Tracking_Fpga"); config->set_property("Tracking_1C.implementation",
"GPS_L1_CA_DLL_PLL_C_Aid_Tracking_Fpga");
config->set_property("Tracking_1C.item_type", "cshort"); config->set_property("Tracking_1C.item_type", "cshort");
config->set_property("Tracking_1C.if", "0"); config->set_property("Tracking_1C.if", "0");
config->set_property("Tracking_1C.dump", "true"); config->set_property("Tracking_1C.dump", "true");
@ -331,13 +324,12 @@ void GpsL1CADllPllTrackingTestFpga::configure_receiver()
config->set_property("Tracking_1C.pll_bw_hz", "30.0"); config->set_property("Tracking_1C.pll_bw_hz", "30.0");
config->set_property("Tracking_1C.dll_bw_hz", "2.0"); config->set_property("Tracking_1C.dll_bw_hz", "2.0");
config->set_property("Tracking_1C.early_late_space_chips", "0.5"); config->set_property("Tracking_1C.early_late_space_chips", "0.5");
config->set_property("Tracking_1C.devicename", "/dev/uio");
config->set_property("Tracking_1C.device_base", "1");
} }
void GpsL1CADllPllTrackingTestFpga::check_results_doppler(arma::vec true_time_s, void GpsL1CADllPllTrackingTestFpga::check_results_doppler(arma::vec true_time_s,
arma::vec true_value, arma::vec true_value, arma::vec meas_time_s, arma::vec meas_value)
arma::vec meas_time_s,
arma::vec meas_value)
{ {
//1. True value interpolation to match the measurement times //1. True value interpolation to match the measurement times
arma::vec true_value_interp; arma::vec true_value_interp;
@ -360,14 +352,13 @@ void GpsL1CADllPllTrackingTestFpga::check_results_doppler(arma::vec true_time_s,
//5. report //5. report
std::cout << std::setprecision(10) << "TRK Doppler RMSE=" << rmse std::cout << std::setprecision(10) << "TRK Doppler RMSE=" << rmse
<< ", mean=" << error_mean << ", mean=" << error_mean << ", stdev=" << sqrt(error_var)
<< ", stdev="<< sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Hz]" << std::endl; << " (max,min)=" << max_error << "," << min_error << " [Hz]"
<< std::endl;
} }
void GpsL1CADllPllTrackingTestFpga::check_results_acc_carrier_phase(
void GpsL1CADllPllTrackingTestFpga::check_results_acc_carrier_phase(arma::vec true_time_s, arma::vec true_time_s, arma::vec true_value, arma::vec meas_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value) arma::vec meas_value)
{ {
//1. True value interpolation to match the measurement times //1. True value interpolation to match the measurement times
@ -391,15 +382,14 @@ void GpsL1CADllPllTrackingTestFpga::check_results_acc_carrier_phase(arma::vec tr
//5. report //5. report
std::cout << std::setprecision(10) << "TRK acc carrier phase RMSE=" << rmse std::cout << std::setprecision(10) << "TRK acc carrier phase RMSE=" << rmse
<< ", mean=" << error_mean << ", mean=" << error_mean << ", stdev=" << sqrt(error_var)
<< ", stdev=" << sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Hz]" << std::endl; << " (max,min)=" << max_error << "," << min_error << " [Hz]"
<< std::endl;
} }
void GpsL1CADllPllTrackingTestFpga::check_results_codephase(
void GpsL1CADllPllTrackingTestFpga::check_results_codephase(arma::vec true_time_s, arma::vec true_time_s, arma::vec true_value, arma::vec meas_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value) arma::vec meas_value)
{ {
//1. True value interpolation to match the measurement times //1. True value interpolation to match the measurement times
@ -422,11 +412,11 @@ void GpsL1CADllPllTrackingTestFpga::check_results_codephase(arma::vec true_time_
//5. report //5. report
std::cout << std::setprecision(10) << "TRK code phase RMSE=" << rmse std::cout << std::setprecision(10) << "TRK code phase RMSE=" << rmse
<< ", mean=" << error_mean << ", mean=" << error_mean << ", stdev=" << sqrt(error_var)
<< ", stdev=" << sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Chips]" << std::endl; << " (max,min)=" << max_error << "," << min_error << " [Chips]"
<< std::endl;
} }
TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga) TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
{ {
configure_generator(); configure_generator();
@ -447,7 +437,8 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
std::string true_obs_file = std::string("./gps_l1_ca_obs_prn"); std::string true_obs_file = std::string("./gps_l1_ca_obs_prn");
true_obs_file.append(std::to_string(test_satellite_PRN)); true_obs_file.append(std::to_string(test_satellite_PRN));
true_obs_file.append(".dat"); true_obs_file.append(".dat");
ASSERT_NO_THROW({ ASSERT_NO_THROW(
{
if (true_obs_data.open_obs_file(true_obs_file) == false) if (true_obs_data.open_obs_file(true_obs_file) == false)
{ {
throw std::exception(); throw std::exception();
@ -455,12 +446,16 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
})<< "Failure opening true observables file" << std::endl; })<< "Failure opening true observables file" << std::endl;
top_block = gr::make_top_block("Tracking test"); top_block = gr::make_top_block("Tracking test");
std::shared_ptr<TrackingInterface> tracking = std::make_shared<GpsL1CaDllPllCAidTrackingFpga>(config.get(), "Tracking_1C", 1, 1); std::shared_ptr<GpsL1CaDllPllCAidTrackingFpga> tracking = std::make_shared
< GpsL1CaDllPllCAidTrackingFpga
> (config.get(), "Tracking_1C", 1, 1);
boost::shared_ptr<GpsL1CADllPllTrackingTestFpga_msg_rx> msg_rx = GpsL1CADllPllTrackingTestFpga_msg_rx_make(); boost::shared_ptr<GpsL1CADllPllTrackingTestFpga_msg_rx> msg_rx =
GpsL1CADllPllTrackingTestFpga_msg_rx_make();
// load acquisition data based on the first epoch of the true observations // load acquisition data based on the first epoch of the true observations
ASSERT_NO_THROW({ ASSERT_NO_THROW(
{
if (true_obs_data.read_binary_obs() == false) if (true_obs_data.read_binary_obs() == false)
{ {
throw std::exception(); throw std::exception();
@ -470,24 +465,32 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
//restart the epoch counter //restart the epoch counter
true_obs_data.restart(); true_obs_data.restart();
std::cout << "Initial Doppler [Hz]=" << true_obs_data.doppler_l1_hz << " Initial code delay [Chips]=" << true_obs_data.prn_delay_chips << std::endl; std::cout << "Initial Doppler [Hz]=" << true_obs_data.doppler_l1_hz
gnss_synchro.Acq_delay_samples = (GPS_L1_CA_CODE_LENGTH_CHIPS - true_obs_data.prn_delay_chips / GPS_L1_CA_CODE_LENGTH_CHIPS) * baseband_sampling_freq * GPS_L1_CA_CODE_PERIOD; << " Initial code delay [Chips]=" << true_obs_data.prn_delay_chips
<< std::endl;
gnss_synchro.Acq_delay_samples = (GPS_L1_CA_CODE_LENGTH_CHIPS
- true_obs_data.prn_delay_chips / GPS_L1_CA_CODE_LENGTH_CHIPS)
* baseband_sampling_freq * GPS_L1_CA_CODE_PERIOD;
gnss_synchro.Acq_doppler_hz = true_obs_data.doppler_l1_hz; gnss_synchro.Acq_doppler_hz = true_obs_data.doppler_l1_hz;
gnss_synchro.Acq_samplestamp_samples = 0; gnss_synchro.Acq_samplestamp_samples = 0;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
tracking->set_channel(gnss_synchro.Channel_ID); tracking->set_channel(gnss_synchro.Channel_ID);
})<< "Failure setting channel." << std::endl; })<< "Failure setting channel." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
tracking->set_gnss_synchro(&gnss_synchro); tracking->set_gnss_synchro(&gnss_synchro);
})<< "Failure setting gnss_synchro." << std::endl; })<< "Failure setting gnss_synchro." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
tracking->connect(top_block); tracking->connect(top_block);
})<< "Failure connecting tracking to the top_block." << std::endl; })<< "Failure connecting tracking to the top_block." << std::endl;
ASSERT_NO_THROW( { ASSERT_NO_THROW(
{
gr::blocks::null_sink::sptr sink = gr::blocks::null_sink::make(sizeof(Gnss_Synchro)); gr::blocks::null_sink::sptr sink = gr::blocks::null_sink::make(sizeof(Gnss_Synchro));
top_block->connect(tracking->get_right_block(), 0, sink, 0); top_block->connect(tracking->get_right_block(), 0, sink, 0);
top_block->msg_connect(tracking->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events")); top_block->msg_connect(tracking->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events"));
@ -500,13 +503,15 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
const char * file_name = file.c_str(); const char * file_name = file.c_str();
// start thread that sends the DMA samples to the FPGA // start thread that sends the DMA samples to the FPGA
boost::thread t{thread, top_block, file_name}; boost::thread t
{ thread, top_block, file_name };
EXPECT_NO_THROW( { EXPECT_NO_THROW(
{
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
begin = tv.tv_sec * 1000000 + tv.tv_usec; begin = tv.tv_sec * 1000000 + tv.tv_usec;
top_block->run(); // Start threads and wait top_block->run(); // Start threads and wait
tracking.reset(); tracking->reset();// unlock the channel
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
end = tv.tv_sec * 1000000 + tv.tv_usec; end = tv.tv_sec * 1000000 + tv.tv_usec;
})<< "Failure running the top_block." << std::endl; })<< "Failure running the top_block." << std::endl;
@ -529,7 +534,8 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
while (true_obs_data.read_binary_obs()) while (true_obs_data.read_binary_obs())
{ {
true_timestamp_s(epoch_counter) = true_obs_data.signal_timestamp_s; true_timestamp_s(epoch_counter) = true_obs_data.signal_timestamp_s;
true_acc_carrier_phase_cycles(epoch_counter) = true_obs_data.acc_carrier_phase_cycles; true_acc_carrier_phase_cycles(epoch_counter) =
true_obs_data.acc_carrier_phase_cycles;
true_Doppler_Hz(epoch_counter) = true_obs_data.doppler_l1_hz; true_Doppler_Hz(epoch_counter) = true_obs_data.doppler_l1_hz;
true_prn_delay_chips(epoch_counter) = true_obs_data.prn_delay_chips; true_prn_delay_chips(epoch_counter) = true_obs_data.prn_delay_chips;
true_tow_s(epoch_counter) = true_obs_data.tow; true_tow_s(epoch_counter) = true_obs_data.tow;
@ -538,7 +544,8 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
//load the measured values //load the measured values
tracking_dump_reader trk_dump; tracking_dump_reader trk_dump;
ASSERT_NO_THROW({ ASSERT_NO_THROW(
{
if (trk_dump.open_obs_file(std::string("./tracking_ch_0.dat")) == false) if (trk_dump.open_obs_file(std::string("./tracking_ch_0.dat")) == false)
{ {
throw std::exception(); throw std::exception();
@ -556,13 +563,21 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
epoch_counter = 0; epoch_counter = 0;
while (trk_dump.read_binary_obs()) while (trk_dump.read_binary_obs())
{ {
trk_timestamp_s(epoch_counter) = static_cast<double>(trk_dump.PRN_start_sample_count) / static_cast<double>(baseband_sampling_freq); trk_timestamp_s(epoch_counter) =
trk_acc_carrier_phase_cycles(epoch_counter) = trk_dump.acc_carrier_phase_rad / GPS_TWO_PI; static_cast<double>(trk_dump.PRN_start_sample_count)
/ static_cast<double>(baseband_sampling_freq);
trk_acc_carrier_phase_cycles(epoch_counter) =
trk_dump.acc_carrier_phase_rad / GPS_TWO_PI;
trk_Doppler_Hz(epoch_counter) = trk_dump.carrier_doppler_hz; trk_Doppler_Hz(epoch_counter) = trk_dump.carrier_doppler_hz;
double delay_chips = GPS_L1_CA_CODE_LENGTH_CHIPS double delay_chips =
GPS_L1_CA_CODE_LENGTH_CHIPS
- GPS_L1_CA_CODE_LENGTH_CHIPS - GPS_L1_CA_CODE_LENGTH_CHIPS
* (fmod((static_cast<double>(trk_dump.PRN_start_sample_count) + trk_dump.aux1) / static_cast<double>(baseband_sampling_freq), 1.0e-3) /1.0e-3); * (fmod(
(static_cast<double>(trk_dump.PRN_start_sample_count)
+ trk_dump.aux1)
/ static_cast<double>(baseband_sampling_freq),
1.0e-3) / 1.0e-3);
trk_prn_delay_chips(epoch_counter) = delay_chips; trk_prn_delay_chips(epoch_counter) = delay_chips;
epoch_counter++; epoch_counter++;
@ -570,16 +585,27 @@ TEST_F(GpsL1CADllPllTrackingTestFpga, ValidationOfResultsFpga)
//Align initial measurements and cut the tracking pull-in transitory //Align initial measurements and cut the tracking pull-in transitory
double pull_in_offset_s = 1.0; double pull_in_offset_s = 1.0;
arma::uvec initial_meas_point = arma::find(trk_timestamp_s >= (true_timestamp_s(0) + pull_in_offset_s), 1, "first"); arma::uvec initial_meas_point = arma::find(
trk_timestamp_s >= (true_timestamp_s(0) + pull_in_offset_s), 1,
"first");
trk_timestamp_s = trk_timestamp_s.subvec(initial_meas_point(0), trk_timestamp_s.size() - 1); trk_timestamp_s = trk_timestamp_s.subvec(initial_meas_point(0),
trk_acc_carrier_phase_cycles = trk_acc_carrier_phase_cycles.subvec(initial_meas_point(0), trk_acc_carrier_phase_cycles.size() - 1); trk_timestamp_s.size() - 1);
trk_Doppler_Hz = trk_Doppler_Hz.subvec(initial_meas_point(0), trk_Doppler_Hz.size() - 1); trk_acc_carrier_phase_cycles = trk_acc_carrier_phase_cycles.subvec(
trk_prn_delay_chips = trk_prn_delay_chips.subvec(initial_meas_point(0), trk_prn_delay_chips.size() - 1); initial_meas_point(0), trk_acc_carrier_phase_cycles.size() - 1);
trk_Doppler_Hz = trk_Doppler_Hz.subvec(initial_meas_point(0),
trk_Doppler_Hz.size() - 1);
trk_prn_delay_chips = trk_prn_delay_chips.subvec(initial_meas_point(0),
trk_prn_delay_chips.size() - 1);
check_results_doppler(true_timestamp_s, true_Doppler_Hz, trk_timestamp_s, trk_Doppler_Hz); check_results_doppler(true_timestamp_s, true_Doppler_Hz, trk_timestamp_s,
check_results_codephase(true_timestamp_s, true_prn_delay_chips, trk_timestamp_s, trk_prn_delay_chips); trk_Doppler_Hz);
check_results_acc_carrier_phase(true_timestamp_s, true_acc_carrier_phase_cycles, trk_timestamp_s, trk_acc_carrier_phase_cycles); check_results_codephase(true_timestamp_s, true_prn_delay_chips,
trk_timestamp_s, trk_prn_delay_chips);
check_results_acc_carrier_phase(true_timestamp_s,
true_acc_carrier_phase_cycles, trk_timestamp_s,
trk_acc_carrier_phase_cycles);
std::cout << "Signal tracking completed in " << (end - begin) << " microseconds" << std::endl; std::cout << "Signal tracking completed in " << (end - begin)
<< " microseconds" << std::endl;
} }