From 08f0a3607549eadc09778e9c421ac75ea3771f9d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 3 Oct 2016 17:43:06 +0200 Subject: [PATCH] Improve queue management gnss-sdr and in TTFF tests. Always destroy queues when exiting --- .../PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc | 4 +- .../PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc | 4 +- .../PVT/gnuradio_blocks/hybrid_pvt_cc.cc | 4 +- src/core/receiver/control_thread.cc | 6 +- src/core/receiver/control_thread.h | 2 +- src/tests/system-tests/ttff_gps_l1.cc | 57 ++++++++++--------- 6 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc index 0b17a2b2a..32f543391 100644 --- a/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/galileo_e1_pvt_cc.cc @@ -213,7 +213,9 @@ galileo_e1_pvt_cc::galileo_e1_pvt_cc(unsigned int nchannels, bool dump, std::str galileo_e1_pvt_cc::~galileo_e1_pvt_cc() -{} +{ + msgctl(sysv_msqid, IPC_RMID, NULL); +} diff --git a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc index 8119fe986..d73c6deac 100644 --- a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc @@ -313,7 +313,9 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, gps_l1_ca_pvt_cc::~gps_l1_ca_pvt_cc() -{} +{ + msgctl(sysv_msqid, IPC_RMID, NULL); +} bool pseudoranges_pairCompare_min(const std::pair& a, const std::pair& b) diff --git a/src/algorithms/PVT/gnuradio_blocks/hybrid_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/hybrid_pvt_cc.cc index 9f4aabe13..6e8757641 100644 --- a/src/algorithms/PVT/gnuradio_blocks/hybrid_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/hybrid_pvt_cc.cc @@ -290,7 +290,9 @@ hybrid_pvt_cc::hybrid_pvt_cc(unsigned int nchannels, bool dump, std::string dump hybrid_pvt_cc::~hybrid_pvt_cc() -{} +{ + msgctl(sysv_msqid, IPC_RMID, NULL); +} diff --git a/src/core/receiver/control_thread.cc b/src/core/receiver/control_thread.cc index a0fe84d23..b6c976f93 100644 --- a/src/core/receiver/control_thread.cc +++ b/src/core/receiver/control_thread.cc @@ -90,6 +90,7 @@ ControlThread::~ControlThread() { // save navigation data to files // if (save_assistance_to_XML() == true) {} + if(msgiq != -1) msgctl(msqid, IPC_RMID, NULL);; } @@ -431,6 +432,7 @@ void ControlThread::init() supl_mns = 0; supl_lac = 0; supl_ci = 0; + msqid = -1; } @@ -528,7 +530,7 @@ void ControlThread::sysv_queue_listener() ttff_msgbuf msg; double ttff_msg = 0.0; int msgrcv_size = sizeof(msg.ttff); - int msqid; + key_t key = 1102; if((msqid = msgget(key, 0644 | IPC_CREAT )) == -1) @@ -552,9 +554,7 @@ void ControlThread::sysv_queue_listener() read_queue = false; } } - usleep(1000000); } - msgctl(msqid, IPC_RMID, NULL); } diff --git a/src/core/receiver/control_thread.h b/src/core/receiver/control_thread.h index b44a81894..1580695df 100644 --- a/src/core/receiver/control_thread.h +++ b/src/core/receiver/control_thread.h @@ -143,7 +143,6 @@ private: */ void assist_GNSS(); - void apply_action(unsigned int what); std::shared_ptr flowgraph_; std::shared_ptr configuration_; @@ -160,6 +159,7 @@ private: void keyboard_listener(); void sysv_queue_listener(); + int msqid; // default filename for assistance data const std::string eph_default_xml_filename = "./gps_ephemeris.xml"; diff --git a/src/tests/system-tests/ttff_gps_l1.cc b/src/tests/system-tests/ttff_gps_l1.cc index 50ce4553b..949f67037 100644 --- a/src/tests/system-tests/ttff_gps_l1.cc +++ b/src/tests/system-tests/ttff_gps_l1.cc @@ -255,26 +255,30 @@ void receive_msg() int msqid_stop = -1; key_t key = 1101; key_t key_stop = 1102; - // wait for the queue to be created - if((msqid = msgget(key, 0644)) == -1){} + bool leave = false; - if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1) + while(!leave) { - ttff_msg = msg.ttff; - if( (ttff_msg != 0) && (ttff_msg != -1)) - { - TTFF_v.push_back(ttff_msg / (1000.0 / decimation_factor) ); - LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (1000.0 / decimation_factor ) << "[s]"; - // Stop the receiver - //while(((msqid_stop = msgget(key_stop, 0644 | IPC_CREAT))) == -1){} - while(((msqid_stop = msgget(key_stop, 0644))) == -1){} - double msgsend_size = sizeof(msg_stop.ttff); - msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT); - } + // wait for the queue to be created + while((msqid = msgget(key, 0644)) == -1){} - if(ttff_msg != -1) + if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1) { - receive_msg(); + ttff_msg = msg.ttff; + if( (ttff_msg != 0) && (ttff_msg != -1)) + { + TTFF_v.push_back(ttff_msg / (1000.0 / decimation_factor) ); + LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (1000.0 / decimation_factor ) << "[s]"; + // Stop the receiver + while(((msqid_stop = msgget(key_stop, 0644))) == -1){} + double msgsend_size = sizeof(msg_stop.ttff); + msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT); + } + + if(ttff_msg == -1) + { + leave = true; + } } } return; @@ -586,17 +590,6 @@ int main(int argc, char **argv) google::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); - // Create SysV message queue to read TFFF measurements - key_t sysv_msg_key; - int sysv_msqid; - sysv_msg_key = 1101; - int msgflg = IPC_CREAT | 0666; - if ((sysv_msqid = msgget(sysv_msg_key, msgflg )) == -1) - { - std::cout<<"GNSS-SDR can not create message queues!" << std::endl; - throw new std::exception(); - } - // Start queue thread std::thread receive_msg_thread(receive_msg); @@ -611,6 +604,15 @@ int main(int argc, char **argv) } // Terminate the queue thread + key_t sysv_msg_key; + int sysv_msqid; + sysv_msg_key = 1101; + int msgflg = IPC_CREAT | 0666; + if ((sysv_msqid = msgget(sysv_msg_key, msgflg )) == -1) + { + std::cout<<"GNSS-SDR can not create message queues!" << std::endl; + throw new std::exception(); + } ttff_msgbuf msg; msg.mtype = 1; msg.ttff = -1; @@ -619,6 +621,7 @@ int main(int argc, char **argv) msgsnd(sysv_msqid, &msg, msgsend_size, IPC_NOWAIT); receive_msg_thread.join(); msgctl(sysv_msqid, IPC_RMID, NULL); + google::ShutDownCommandLineFlags(); return res; }