1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 04:30:33 +00:00

Merge pull request #106 from antonioramosdet/new_pcps_acq

Merging @antonioramosdet pull request #106
This commit is contained in:
Javier Arribas 2018-01-10 11:21:24 +01:00 committed by GitHub
commit e28078afcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 151 additions and 262 deletions

View File

@ -127,13 +127,9 @@ pcps_acquisition_cc::pcps_acquisition_cc(
// For dumping samples into a file
d_dump = dump;
d_dump_filename = dump_filename;
d_gnss_synchro = 0;
d_grid_doppler_wipeoffs = 0;
d_done = false;
d_blocking = blocking;
d_new_data_available = false;
d_worker_active = false;
d_data_buffer = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
}
@ -160,19 +156,6 @@ pcps_acquisition_cc::~pcps_acquisition_cc()
{
d_dump_file.close();
}
// Let the worker thread know that we are done and then wait to join
if( d_worker_thread.joinable() )
{
{
std::lock_guard<std::mutex> lk( d_mutex );
d_done = true;
d_cond.notify_one();
}
d_worker_thread.join();
}
volk_gnsssdr_free( d_data_buffer );
}
@ -233,9 +216,6 @@ void pcps_acquisition_cc::init()
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);
}
d_new_data_available = false;
d_done = false;
d_worker_active = false;
}
@ -253,6 +233,7 @@ void pcps_acquisition_cc::set_state(int state)
d_mag = 0.0;
d_input_power = 0.0;
d_test_statistics = 0.0;
d_active = true;
}
else if (d_state == 0)
{}
@ -299,7 +280,7 @@ void pcps_acquisition_cc::send_negative_acquisition()
}
int pcps_acquisition_cc::general_work(int noutput_items,
int pcps_acquisition_cc::general_work(int noutput_items __attribute__((unused)),
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items __attribute__((unused)))
{
@ -314,11 +295,17 @@ int pcps_acquisition_cc::general_work(int noutput_items,
* 6. Declare positive or negative acquisition using a message port
*/
gr::thread::scoped_lock lk(d_setlock);
if(!d_active || d_worker_active)
{
d_sample_counter += d_fft_size * ninput_items[0];
consume_each(ninput_items[0]);
return 0;
}
switch(d_state)
{
case 0:
{
if (d_active)
{
//restart acquisition variables
d_gnss_synchro->Acq_delay_samples = 0.0;
@ -329,76 +316,37 @@ int pcps_acquisition_cc::general_work(int noutput_items,
d_input_power = 0.0;
d_test_statistics = 0.0;
d_state = 1;
}
d_sample_counter += d_fft_size * ninput_items[0]; // sample counter
consume_each(ninput_items[0]);
break;
}
case 1:
{
std::unique_lock<std::mutex> lk( d_mutex );
int num_items_consumed = 1;
if( d_worker_active )
{
if( d_blocking )
{
// Should never get here:
std::string msg = "pcps_acquisition_cc: Entered general work with worker active in blocking mode, should never happen";
LOG(WARNING) << msg;
std::cout << msg << std::endl;
d_cond.wait( lk, [&]{ return !this->d_worker_active; } );
}
else
{
num_items_consumed = ninput_items[0];
d_sample_counter += d_fft_size * num_items_consumed;
}
}
else
{
// Copy the data to the core and let it know that new data is available
memcpy(d_data_buffer, input_items[0], d_fft_size * sizeof(gr_complex));
d_new_data_available = true;
d_cond.notify_one();
if(d_blocking)
{
d_cond.wait( lk, [&]{ return !this->d_new_data_available; } );
}
}
consume_each(num_items_consumed);
break;
} // case 1, switch d_state
} // switch d_state
return noutput_items;
}
void pcps_acquisition_cc::acquisition_core( void )
{
d_worker_active = false;
while( 1 )
{
std::unique_lock<std::mutex> lk( d_mutex );
d_cond.wait( lk, [&]{ return this->d_new_data_available or this->d_done; } );
d_worker_active = !d_done;
unsigned long int sample_counter = d_sample_counter; // sample counter
lk.unlock();
if( d_done )
acquisition_core(d_sample_counter);
}
else
{
gr::thread::thread d_worker(&pcps_acquisition_cc::acquisition_core, this, d_sample_counter);
d_worker_active = true;
}
d_sample_counter += d_fft_size;
consume_each(1);
break;
}
}
return 0;
}
void pcps_acquisition_cc::acquisition_core( unsigned long int samp_count )
{
gr::thread::scoped_lock lk(d_setlock);
// initialize acquisition algorithm
int doppler;
@ -416,12 +364,13 @@ void pcps_acquisition_cc::acquisition_core( void )
DLOG(INFO) << "Channel: " << d_channel
<< " , doing acquisition of satellite: " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN
<< " ,sample stamp: " << sample_counter << ", threshold: "
<< " ,sample stamp: " << samp_count << ", threshold: "
<< d_threshold << ", doppler_max: " << d_doppler_max
<< ", doppler_step: " << d_doppler_step
<< ", use_CFAR_algorithm_flag: " << ( d_use_CFAR_algorithm_flag ? "true" : "false" );
if (d_use_CFAR_algorithm_flag == true)
lk.unlock();
if (d_use_CFAR_algorithm_flag)
{
// 1- (optional) Compute the input signal power estimation
volk_32fc_magnitude_squared_32f(d_magnitude, in, d_fft_size);
@ -434,8 +383,7 @@ void pcps_acquisition_cc::acquisition_core( void )
// doppler search steps
doppler = -static_cast<int>(d_doppler_max) + d_doppler_step * doppler_index;
volk_32fc_x2_multiply_32fc(d_fft_if->get_inbuf(), in,
d_grid_doppler_wipeoffs[doppler_index], d_fft_size);
volk_32fc_x2_multiply_32fc(d_fft_if->get_inbuf(), in, d_grid_doppler_wipeoffs[doppler_index], d_fft_size);
// 3- Perform the FFT-based convolution (parallel time search)
// Compute the FFT of the carrier wiped--off incoming signal
@ -443,8 +391,7 @@ void pcps_acquisition_cc::acquisition_core( void )
// Multiply carrier wiped--off, Fourier transformed incoming signal
// with the local FFT'd code reference using SIMD operations with VOLK library
volk_32fc_x2_multiply_32fc(d_ifft->get_inbuf(),
d_fft_if->get_outbuf(), d_fft_codes, d_fft_size);
volk_32fc_x2_multiply_32fc(d_ifft->get_inbuf(), d_fft_if->get_outbuf(), d_fft_codes, d_fft_size);
// compute the inverse FFT
d_ifft->execute();
@ -455,7 +402,7 @@ void pcps_acquisition_cc::acquisition_core( void )
volk_gnsssdr_32f_index_max_32u(&indext, d_magnitude, effective_fft_size);
magt = d_magnitude[indext];
if (d_use_CFAR_algorithm_flag == true)
if (d_use_CFAR_algorithm_flag)
{
// Normalize the maximum value to correct the scale factor introduced by FFTW
magt = d_magnitude[indext] / (fft_normalization_factor * fft_normalization_factor);
@ -465,7 +412,7 @@ void pcps_acquisition_cc::acquisition_core( void )
{
d_mag = magt;
if (d_use_CFAR_algorithm_flag == false)
if (!d_use_CFAR_algorithm_flag)
{
// Search grid noise floor approximation for this doppler line
volk_32f_accumulator_s32f(&d_input_power, d_magnitude, effective_fft_size);
@ -484,21 +431,19 @@ void pcps_acquisition_cc::acquisition_core( void )
{
d_gnss_synchro->Acq_delay_samples = static_cast<double>(indext % d_samples_per_code);
d_gnss_synchro->Acq_doppler_hz = static_cast<double>(doppler);
d_gnss_synchro->Acq_samplestamp_samples = sample_counter;
d_gnss_synchro->Acq_samplestamp_samples = samp_count;
// 5- Compute the test statistics and compare to the threshold
//d_test_statistics = 2 * d_fft_size * d_mag / d_input_power;
d_test_statistics = d_mag / d_input_power;
}
}
// Record results to file if required
if (d_dump)
{
std::stringstream filename;
std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write
filename.str("");
boost::filesystem::path p = d_dump_filename;
filename << p.parent_path().string()
<< boost::filesystem::path::preferred_separator
@ -516,7 +461,7 @@ void pcps_acquisition_cc::acquisition_core( void )
d_dump_file.close();
}
}
lk.lock();
if (!d_bit_transition_flag)
{
if (d_test_statistics > d_threshold)
@ -550,41 +495,5 @@ void pcps_acquisition_cc::acquisition_core( void )
}
}
}
lk.lock();
d_worker_active = false;
d_new_data_available = false;
lk.unlock();
d_cond.notify_one();
}
}
bool pcps_acquisition_cc::start( void )
{
d_worker_active = false;
d_done = false;
// Start the worker thread and wait for it to acknowledge:
d_worker_thread = std::move( std::thread( &pcps_acquisition_cc::acquisition_core, this ) );
return gr::block::start();
}
bool pcps_acquisition_cc::stop( void )
{
// Let the worker thread know that we are done and then wait to join
if( d_worker_thread.joinable() )
{
{
std::lock_guard<std::mutex> lk( d_mutex );
d_done = true;
d_cond.notify_one();
}
d_worker_thread.join();
}
return gr::block::stop();
}

View File

@ -21,6 +21,7 @@
* <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com
* <li> Marc Molina, 2013. marc.molina.pena@gmail.com
* <li> Cillian O'Driscoll, 2017. cillian(at)ieee.org
* <li> Antonio Ramos, 2017. antonio.ramos@cttc.es
* </ul>
*
* -------------------------------------------------------------------------
@ -53,9 +54,6 @@
#include <fstream>
#include <string>
#include <mutex>
#include <thread>
#include <condition_variable>
#include <gnuradio/block.h>
#include <gnuradio/gr_complex.h>
#include <gnuradio/fft/fft.h>
@ -99,7 +97,7 @@ private:
void update_local_carrier(gr_complex* carrier_vector, int correlator_length_samples, float freq);
void acquisition_core( void );
void acquisition_core( unsigned long int samp_count );
void send_negative_acquisition();
void send_positive_acquisition();
@ -109,7 +107,6 @@ private:
int d_samples_per_code;
//unsigned int d_doppler_resolution;
float d_threshold;
std::string d_satellite_str;
unsigned int d_doppler_max;
unsigned int d_doppler_step;
unsigned int d_sampled_ms;
@ -137,16 +134,8 @@ private:
bool d_dump;
unsigned int d_channel;
std::string d_dump_filename;
std::thread d_worker_thread;
std::mutex d_mutex;
std::condition_variable d_cond;
bool d_done;
bool d_new_data_available;
bool d_worker_active;
bool d_blocking;
gr_complex *d_data_buffer;
public:
@ -251,15 +240,6 @@ public:
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
/*!
* Called by the flowgraph when processing is about to start.
*/
bool start( void );
/*!
* Called by the flowgraph when processing is done.
*/
bool stop( void );
};
#endif /* GNSS_SDR_PCPS_ACQUISITION_CC_H_*/