1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-05-21 00:34:09 +00:00
This commit is contained in:
Carles Fernandez 2016-10-01 12:41:39 +02:00
parent 91c0fcc539
commit 35084f93cc

View File

@ -30,15 +30,17 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <ctime> #include <ctime>
#include <chrono> #include <chrono>
#include <numeric> #include <numeric>
#include <string> #include <string>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <thread> #include <thread>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
#include "in_memory_configuration.h" #include "in_memory_configuration.h"
#include "file_configuration.h" #include "file_configuration.h"
#include "concurrent_queue.h" #include "concurrent_queue.h"
@ -46,9 +48,6 @@
#include "control_thread.h" #include "control_thread.h"
#include "gnss_flowgraph.h" #include "gnss_flowgraph.h"
#include "gps_acq_assist.h" #include "gps_acq_assist.h"
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
DEFINE_int32(fs_in, 4000000, "Sampling rate, in Ms/s"); DEFINE_int32(fs_in, 4000000, "Sampling rate, in Ms/s");
@ -64,20 +63,11 @@ concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map;
std::vector<double> TTFF_v; std::vector<double> TTFF_v;
typedef struct { typedef struct {
long mtype;//required by sys v message long mtype; //required by sys v message
double ttff; double ttff;
} ttff_msgbuf; } ttff_msgbuf;
class TTFF_GPS_L1_CA_Test: public ::testing::Test
{
public:
std::shared_ptr<InMemoryConfiguration> config;
//std::thread receive_msg_thread(receive_msg);
//void receive_msg();
};
void receive_msg() void receive_msg()
{ {
ttff_msgbuf msg; ttff_msgbuf msg;
@ -85,25 +75,16 @@ void receive_msg()
int msgrcv_size = sizeof(msg.ttff); int msgrcv_size = sizeof(msg.ttff);
int msqid; int msqid;
key_t key = 1101; key_t key = 1101;
// wait for the queue to be created
while((msqid = msgget(key, 0644)) == -1){} while((msqid = msgget(key, 0644)) == -1){}
// if ((msqid = msgget(key, 0644)) == -1) { /* connect to the queue */
// perror("TTFF MSG QUEUE NOT AVAILABLE");
// exit(1);
// }
if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1) if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1)
{ {
ttff_msg = msg.ttff; ttff_msg = msg.ttff;
std::cout << "-----RECEIVED! " << ttff_msg << std::endl;
//struct tm tstruct;
//char buf[80];
//tstruct = *localtime(&jammer.timestamp);
//strftime(buf, sizeof(buf), "%d-%m-%Y-%H-%M-%S", &tstruct);
if( (ttff_msg != 0) && (ttff_msg != -1)) if( (ttff_msg != 0) && (ttff_msg != -1))
{ {
TTFF_v.push_back(ttff_msg / (100 * 10)); // Fix this ! averaging_depth * output_rate_ms TTFF_v.push_back(ttff_msg / (100 * 10)); // Fix this ! averaging_depth * output_rate_ms
std::cout << "Annotate: TTFF = " << ttff_msg / (100 * 10) << std::endl; LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (100 * 10) << "[s]";
} }
if(ttff_msg != -1) if(ttff_msg != -1)
@ -111,11 +92,6 @@ void receive_msg()
receive_msg(); receive_msg();
} }
} }
//}
std::cout << "--------RECEIVEr msg thread stops " << std::endl;
//std::cout<<"RECEIVER MSG THREAD STOP.\n";
return; return;
} }
@ -129,7 +105,7 @@ void print_TTFF_report(const std::vector<double> & ttff_v)
std::cout << "---------------------------" << std::endl; std::cout << "---------------------------" << std::endl;
std::cout << " Time-To-First FIX Report" << std::endl; std::cout << " Time-To-First FIX Report" << std::endl;
std::cout << "---------------------------" << std::endl; std::cout << "---------------------------" << std::endl;
std::cout << "Valid measurements (" << ttff.size() << "/" << FLAGS_num_measurements << "): " << std::endl; std::cout << "Valid measurements (" << ttff.size() << "/" << FLAGS_num_measurements << "): ";
for(double ttff_ : ttff) std::cout << ttff_ << " "; for(double ttff_ : ttff) std::cout << ttff_ << " ";
std::cout << std::endl; std::cout << std::endl;
std::cout << "TTFF mean: " << mean << " [s]" << std::endl; std::cout << "TTFF mean: " << mean << " [s]" << std::endl;
@ -150,15 +126,16 @@ TEST(TTFF_GPS_L1_CA_Test, ColdStart)
config2 = std::make_shared<FileConfiguration>(filename); config2 = std::make_shared<FileConfiguration>(filename);
config2->set_property("SignalSource.samples", std::to_string(FLAGS_fs_in * FLAGS_max_measurement_duration)); config2->set_property("SignalSource.samples", std::to_string(FLAGS_fs_in * FLAGS_max_measurement_duration));
//google::InitGoogleLogging("ttff"); double central_freq = 1575420000.0;
double gain_dB = 40.0;
// Set the Signal Source // Set the Signal Source
config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(FLAGS_fs_in)); config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(FLAGS_fs_in));
config->set_property("SignalSource.item_type", "cshort"); config->set_property("SignalSource.item_type", "cshort");
config->set_property("SignalSource.implementation", "UHD_Signal_Source"); config->set_property("SignalSource.implementation", "UHD_Signal_Source");
config->set_property("SignalSource.freq", std::to_string(1575420000)); config->set_property("SignalSource.freq", std::to_string(central_freq));
config->set_property("SignalSource.sampling_frequency", std::to_string(FLAGS_fs_in)); config->set_property("SignalSource.sampling_frequency", std::to_string(FLAGS_fs_in));
config->set_property("SignalSource.gain", std::to_string(40)); config->set_property("SignalSource.gain", std::to_string(gain_dB));
config->set_property("SignalSource.subdevice", FLAGS_subdevice); config->set_property("SignalSource.subdevice", FLAGS_subdevice);
config->set_property("SignalSource.samples", std::to_string(FLAGS_fs_in * FLAGS_max_measurement_duration)); config->set_property("SignalSource.samples", std::to_string(FLAGS_fs_in * FLAGS_max_measurement_duration));
config->set_property("SignalSource.device_address", FLAGS_device_address); config->set_property("SignalSource.device_address", FLAGS_device_address);
@ -250,14 +227,9 @@ TEST(TTFF_GPS_L1_CA_Test, ColdStart)
config->set_property("PVT.dump", "false"); config->set_property("PVT.dump", "false");
bool valid_pvt_received = false;
//std::thread receive_msg_thread(receive_msg);
int n; int n;
for(n = 0; n < FLAGS_num_measurements; n++) // for(n = 0; n < FLAGS_num_measurements; n++)
{ {
// reset start( hot /warm / cold ) // reset start( hot /warm / cold )
// COLD START // COLD START
config->set_property("GNSS-SDR.SUPL_gps_enabled", "false"); config->set_property("GNSS-SDR.SUPL_gps_enabled", "false");
@ -265,16 +237,14 @@ TEST(TTFF_GPS_L1_CA_Test, ColdStart)
config2->set_property("GNSS-SDR.SUPL_read_gps_assistance_xml", "false"); config2->set_property("GNSS-SDR.SUPL_read_gps_assistance_xml", "false");
config2->set_property("PVT.flag_rtcm_server", "false"); config2->set_property("PVT.flag_rtcm_server", "false");
std::shared_ptr<ControlThread> control_thread = std::make_shared<ControlThread>(config2); std::shared_ptr<ControlThread> control_thread = std::make_shared<ControlThread>(config2);
// - start clock
// record startup time // record startup time
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec; long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
// - start receiver // start receiver
try try
{ {
control_thread->run(); control_thread->run();
@ -288,8 +258,7 @@ TEST(TTFF_GPS_L1_CA_Test, ColdStart)
std::cout << "STD exception: " << ex.what(); std::cout << "STD exception: " << ex.what();
} }
// - if (pvt_fix | max_waiting_time) // stop clock
// - stop_clock
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long int end = tv.tv_sec * 1000000 + tv.tv_usec; long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
double ttff = static_cast<double>(end - begin) / 1000000.0; double ttff = static_cast<double>(end - begin) / 1000000.0;
@ -297,16 +266,11 @@ TEST(TTFF_GPS_L1_CA_Test, ColdStart)
std::shared_ptr<GNSSFlowgraph> flowgraph = control_thread->flowgraph(); std::shared_ptr<GNSSFlowgraph> flowgraph = control_thread->flowgraph();
EXPECT_FALSE(flowgraph->running()); EXPECT_FALSE(flowgraph->running());
num_measurements = num_measurements + 1; num_measurements = num_measurements + 1;
std::cout << "Measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl; std::cout << "Measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(5)); std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(5));
// if (pvt_fix) num_valid_measurements = num_valid_measurements + 1;
} }
std::cout << "BYE " << num_measurements << std::endl;
// Compute min, max, mean, stdev,
//receive_msg_thread.join();
// Print TTFF report // Print TTFF report
print_TTFF_report(TTFF_v); print_TTFF_report(TTFF_v);
@ -322,19 +286,22 @@ int main(int argc, char **argv)
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true); google::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]); google::InitGoogleLogging(argv[0]);
//Create Sys V message queue
// Create Sys V message queue to read TFFF measurements
key_t sysv_msg_key; key_t sysv_msg_key;
int sysv_msqid; int sysv_msqid;
sysv_msg_key = 1101; sysv_msg_key = 1101;
int msgflg = IPC_CREAT | 0666; int msgflg = IPC_CREAT | 0666;
if ((sysv_msqid = msgget(sysv_msg_key, msgflg )) == -1){} if ((sysv_msqid = msgget(sysv_msg_key, msgflg )) == -1)
//{ {
// std::cout<<"GNSS-SDR can not create message queues!\n"; std::cout<<"GNSS-SDR can not create message queues!" << std::endl;
// perror("msgget"); throw new std::exception();
// throw new std::exception(); }
//}
// Start queue thread
std::thread receive_msg_thread(receive_msg); std::thread receive_msg_thread(receive_msg);
// Run the Tests
try try
{ {
res = RUN_ALL_TESTS(); res = RUN_ALL_TESTS();
@ -343,6 +310,8 @@ int main(int argc, char **argv)
{ {
LOG(WARNING) << "Unexpected catch"; LOG(WARNING) << "Unexpected catch";
} }
// Terminate the queue thread
ttff_msgbuf msg; ttff_msgbuf msg;
msg.mtype = 1; msg.mtype = 1;
msg.ttff = -1; msg.ttff = -1;
@ -350,7 +319,7 @@ int main(int argc, char **argv)
msgsend_size = sizeof(msg.ttff); msgsend_size = sizeof(msg.ttff);
msgsnd(sysv_msqid, &msg, msgsend_size, IPC_NOWAIT); msgsnd(sysv_msqid, &msg, msgsend_size, IPC_NOWAIT);
receive_msg_thread.join(); receive_msg_thread.join();
std::cout << "-------------------TTFF:" << std::accumulate(TTFF_v.begin(), TTFF_v.end(), 0.0) / TTFF_v.size() << std::endl;
google::ShutDownCommandLineFlags(); google::ShutDownCommandLineFlags();
return res; return res;
} }