1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-13 19:50:34 +00:00

Replace <ctime> library by <chrono>

and also replace C-style casts by C++ casts. Added/removed some blank
lines here and there to match coding style of other tests.
This commit is contained in:
Carles Fernandez 2017-08-24 18:09:04 +02:00 committed by Damian Miralles
parent 1e59501cb5
commit 8bbe4edc64
2 changed files with 59 additions and 52 deletions

View File

@ -1,4 +1,4 @@
#include <ctime> #include <chrono>
#include <iostream> #include <iostream>
#include <gnuradio/top_block.h> #include <gnuradio/top_block.h>
#include <gnuradio/blocks/file_source.h> #include <gnuradio/blocks/file_source.h>
@ -72,6 +72,7 @@ GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx::GlonassL1CaPcpsAcquisitionGSoC201
rx_message = 0; rx_message = 0;
} }
GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx::~GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx() GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx::~GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx()
{} {}
@ -138,6 +139,7 @@ protected:
double Pfa_a; double Pfa_a;
}; };
void GlonassL1CaPcpsAcquisitionGSoC2017Test::init() void GlonassL1CaPcpsAcquisitionGSoC2017Test::init()
{ {
message = 0; message = 0;
@ -153,6 +155,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::init()
Pfa_a = 0; Pfa_a = 0;
} }
void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_1() void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_1()
{ {
gnss_synchro.Channel_ID = 0; gnss_synchro.Channel_ID = 0;
@ -222,6 +225,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_1()
config->set_property("Acquisition.dump", "false"); config->set_property("Acquisition.dump", "false");
} }
void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_2() void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_2()
{ {
gnss_synchro.Channel_ID = 0; gnss_synchro.Channel_ID = 0;
@ -309,12 +313,14 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_2()
config->set_property("Acquisition.dump", "false"); config->set_property("Acquisition.dump", "false");
} }
void GlonassL1CaPcpsAcquisitionGSoC2017Test::start_queue() void GlonassL1CaPcpsAcquisitionGSoC2017Test::start_queue()
{ {
stop = false; stop = false;
ch_thread = boost::thread(&GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message, this); ch_thread = boost::thread(&GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message, this);
} }
void GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message() void GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message()
{ {
struct timeval tv; struct timeval tv;
@ -339,6 +345,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message()
} }
} }
void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message() void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message()
{ {
if (message == 1) if (message == 1)
@ -347,7 +354,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message()
// The term -5 is here to correct the additional delay introduced by the FIR filter // The term -5 is here to correct the additional delay introduced by the FIR filter
// The value 511.0 must be a variable, chips/length // The value 511.0 must be a variable, chips/length
double delay_error_chips = std::abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*511.0/((double)fs_in*1e-3)); double delay_error_chips = std::abs(static_cast<double>(expected_delay_chips) - (static_cast<double>(gnss_synchro.Acq_delay_samples) - 5.0 ) * 511.0 / (static_cast<double>(fs_in) * 1e-3));
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);
mse_delay += std::pow(delay_error_chips, 2); mse_delay += std::pow(delay_error_chips, 2);
@ -361,16 +368,16 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message()
realization_counter++; realization_counter++;
std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; std::cout << "Progress: " << round(static_cast<float>(realization_counter) / static_cast<float>(num_of_realizations) * 100.0) << "% \r" << std::flush;
if (realization_counter == num_of_realizations) if (realization_counter == num_of_realizations)
{ {
mse_delay /= num_of_realizations; mse_delay /= num_of_realizations;
mse_doppler /= num_of_realizations; mse_doppler /= num_of_realizations;
Pd = (double)correct_estimation_counter / (double)num_of_realizations; Pd = static_cast<double>(correct_estimation_counter) / static_cast<double>(num_of_realizations);
Pfa_a = (double)detection_counter / (double)num_of_realizations; Pfa_a = static_cast<double>(detection_counter) / static_cast<double>(num_of_realizations);
Pfa_p = (double)(detection_counter - correct_estimation_counter) / (double)num_of_realizations; Pfa_p = (static_cast<double>(detection_counter) - static_cast<double>( correct_estimation_counter)) / static_cast<double>(num_of_realizations);
mean_acq_time_us /= num_of_realizations; mean_acq_time_us /= num_of_realizations;
@ -379,11 +386,13 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message()
} }
} }
void GlonassL1CaPcpsAcquisitionGSoC2017Test::stop_queue() void GlonassL1CaPcpsAcquisitionGSoC2017Test::stop_queue()
{ {
stop = true; stop = true;
} }
TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, Instantiate) TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, Instantiate)
{ {
config_1(); config_1();
@ -391,12 +400,12 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, Instantiate)
delete acquisition; delete acquisition;
} }
TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ConnectAndRun) TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ConnectAndRun)
{ {
int nsamples = floor(fs_in*integration_time_ms*1e-3); int nsamples = floor(fs_in * integration_time_ms * 1e-3);
struct timeval tv; std::chrono::time_point<std::chrono::system_clock> begin, end;
long long int begin = 0; std::chrono::duration<double> elapsed_seconds(0);
long long int end = 0;
queue = gr::msg_queue::make(0); queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Acquisition test"); top_block = gr::make_top_block("Acquisition test");
@ -414,18 +423,18 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ConnectAndRun)
}) << "Failure connecting the blocks of acquisition test."<< std::endl; }) << "Failure connecting the blocks of acquisition test."<< std::endl;
EXPECT_NO_THROW( { EXPECT_NO_THROW( {
gettimeofday(&tv, NULL); begin = std::chrono::system_clock::now();
begin = tv.tv_sec *1e6 + tv.tv_usec;
top_block->run(); // Start threads and wait top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL); end = std::chrono::system_clock::now();
end = tv.tv_sec *1e6 + tv.tv_usec; elapsed_seconds = end - begin;
}) << "Failure running the top_block."<< std::endl; }) << "Failure running the top_block."<< std::endl;
std::cout << "Processed " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl; std::cout << "Processed " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl;
delete acquisition; delete acquisition;
} }
TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults) TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults)
{ {
config_1(); config_1();
@ -495,18 +504,18 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults)
}) << "Failure running the top_block."<< std::endl; }) << "Failure running the top_block."<< std::endl;
if (i == 0) if (i == 0)
{ {
EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS.";
if (message == 1) if (message == 1)
{ {
EXPECT_EQ((unsigned int) 1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; EXPECT_EQ(static_cast<unsigned int>(1), correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation.";
} }
} }
else if (i == 1) else if (i == 1)
{ {
EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL.";
} }
#ifdef OLD_BOOST #ifdef OLD_BOOST
ASSERT_NO_THROW( { ASSERT_NO_THROW( {
ch_thread.timed_join(boost::posix_time::seconds(1)); ch_thread.timed_join(boost::posix_time::seconds(1));
@ -522,6 +531,7 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults)
delete acquisition; delete acquisition;
} }
TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResultsProbabilities) TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResultsProbabilities)
{ {
config_2(); config_2();
@ -592,15 +602,15 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResultsProbabilities)
}) << "Failure running the top_block."<< std::endl; }) << "Failure running the top_block."<< std::endl;
if (i == 0) if (i == 0)
{ {
std::cout << "Estimated probability of detection = " << Pd << std::endl; std::cout << "Estimated probability of detection = " << Pd << std::endl;
std::cout << "Estimated probability of false alarm (satellite present) = " << Pfa_p << std::endl; std::cout << "Estimated probability of false alarm (satellite present) = " << Pfa_p << std::endl;
std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; } std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; }
else if (i == 1) else if (i == 1)
{ {
std::cout << "Estimated probability of false alarm (satellite absent) = " << Pfa_a << std::endl; std::cout << "Estimated probability of false alarm (satellite absent) = " << Pfa_a << std::endl;
std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl;
} }
#ifdef OLD_BOOST #ifdef OLD_BOOST
ASSERT_NO_THROW( { ASSERT_NO_THROW( {
ch_thread.timed_join(boost::posix_time::seconds(1)); ch_thread.timed_join(boost::posix_time::seconds(1));

View File

@ -1,4 +1,4 @@
#include <ctime> #include <chrono>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
@ -119,20 +119,19 @@ void GlonassL1CaPcpsAcquisitionTest::init()
} }
TEST_F(GlonassL1CaPcpsAcquisitionTest, Instantiate) TEST_F(GlonassL1CaPcpsAcquisitionTest, Instantiate)
{ {
init(); init();
boost::shared_ptr<GlonassL1CaPcpsAcquisition> acquisition = boost::make_shared<GlonassL1CaPcpsAcquisition>(config.get(), "Acquisition", 1, 1); boost::shared_ptr<GlonassL1CaPcpsAcquisition> acquisition = boost::make_shared<GlonassL1CaPcpsAcquisition>(config.get(), "Acquisition", 1, 1);
} }
TEST_F(GlonassL1CaPcpsAcquisitionTest, ConnectAndRun) TEST_F(GlonassL1CaPcpsAcquisitionTest, ConnectAndRun)
{ {
int fs_in = 62314000; int fs_in = 62314000;
int nsamples = 62314; int nsamples = 62314;
struct timeval tv; std::chrono::time_point<std::chrono::system_clock> begin, end;
long long int begin = 0; std::chrono::duration<double> elapsed_seconds(0);
long long int end = 0;
gr::msg_queue::sptr queue = gr::msg_queue::make(0); gr::msg_queue::sptr queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Acquisition test"); top_block = gr::make_top_block("Acquisition test");
@ -151,21 +150,20 @@ TEST_F(GlonassL1CaPcpsAcquisitionTest, ConnectAndRun)
}) << "Failure connecting the blocks of acquisition test." << std::endl; }) << "Failure connecting the blocks of acquisition test." << std::endl;
EXPECT_NO_THROW( { EXPECT_NO_THROW( {
gettimeofday(&tv, NULL); begin = std::chrono::system_clock::now();
begin = tv.tv_sec * 1000000 + tv.tv_usec;
top_block->run(); // Start threads and wait top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL); end = std::chrono::system_clock::now();
end = tv.tv_sec * 1000000 + tv.tv_usec; elapsed_seconds = end - begin;
}) << "Failure running the top_block." << std::endl; }) << "Failure running the top_block." << std::endl;
std::cout << "Processed " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl; std::cout << "Processed " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl;
} }
TEST_F(GlonassL1CaPcpsAcquisitionTest, ValidationOfResults) TEST_F(GlonassL1CaPcpsAcquisitionTest, ValidationOfResults)
{ {
struct timeval tv; std::chrono::time_point<std::chrono::system_clock> begin, end;
long long int begin = 0; std::chrono::duration<double> elapsed_seconds(0);
long long int end = 0;
top_block = gr::make_top_block("Acquisition test"); top_block = gr::make_top_block("Acquisition test");
double expected_delay_samples = 31874; double expected_delay_samples = 31874;
@ -213,21 +211,20 @@ TEST_F(GlonassL1CaPcpsAcquisitionTest, ValidationOfResults)
acquisition->init(); acquisition->init();
EXPECT_NO_THROW( { EXPECT_NO_THROW( {
gettimeofday(&tv, NULL); begin = std::chrono::system_clock::now();
begin = tv.tv_sec * 1000000 + tv.tv_usec;
top_block->run(); // Start threads and wait top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL); end = std::chrono::system_clock::now();
end = tv.tv_sec * 1000000 + tv.tv_usec; elapsed_seconds = end - begin;
}) << "Failure running the top_block." << std::endl; }) << "Failure running the top_block." << std::endl;
unsigned long int nsamples = gnss_synchro.Acq_samplestamp_samples; unsigned long int nsamples = gnss_synchro.Acq_samplestamp_samples;
std::cout << "Acquired " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl; std::cout << "Acquired " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " 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 * 511 / 62316); float delay_error_chips = static_cast<float>(delay_error_samples) * 511.0 / 62316.0;
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) << "Doppler error exceeds the expected value: 666 Hz = 2/(3*integration period)";