From 32445c986479bc39dd0366f2e44d98b67f83cb06 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 1 Oct 2016 17:32:38 +0200 Subject: [PATCH] Add a queue listener to the control thread --- src/core/receiver/control_thread.cc | 40 +++++++++++++++++++++++++++++ src/core/receiver/control_thread.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/src/core/receiver/control_thread.cc b/src/core/receiver/control_thread.cc index ac7f9dee2..c69168824 100644 --- a/src/core/receiver/control_thread.cc +++ b/src/core/receiver/control_thread.cc @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -126,6 +129,7 @@ void ControlThread::run() assist_GNSS(); // start the keyboard_listener thread keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this); + sysv_queue_thread_ = boost::thread(&ControlThread::sysv_queue_listener, this); // Main loop to read and process the control messages while (flowgraph_->running() && !stop_) @@ -141,9 +145,11 @@ void ControlThread::run() //Join keyboard thread #ifdef OLD_BOOST keyboard_thread_.timed_join(boost::posix_time::seconds(1)); + sysv_queue_thread_.timed_join(boost::posix_time::seconds(1)); #endif #ifndef OLD_BOOST keyboard_thread_.try_join_until(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(1000)); + sysv_queue_thread_.try_join_until(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(1000)); #endif LOG(INFO) << "Flowgraph stopped"; @@ -510,6 +516,40 @@ void ControlThread::gps_acq_assist_data_collector() } } +void ControlThread::sysv_queue_listener() +{ + typedef struct { + long mtype; //required by sys v message + double ttff; + } ttff_msgbuf; + bool read_queue = true; + ttff_msgbuf msg; + double ttff_msg = 0.0; + int msgrcv_size = sizeof(msg.ttff); + int msqid; + key_t key = 1102; + // wait for the queue to be created + while((msqid = msgget(key, 0644)) == -1){} + while(read_queue) + { + if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1) + { + + ttff_msg = msg.ttff; + if(ttff_msg == 200) + { + std::cout << "Quit order received, stopping GNSS-SDR !!" << std::endl; + std::unique_ptr cmf(new ControlMessageFactory()); + if (control_queue_ != gr::msg_queue::sptr()) + { + control_queue_->handle(cmf->GetQueueMessage(200, 0)); + } + read_queue = false; + } + } + } +} + void ControlThread::keyboard_listener() { diff --git a/src/core/receiver/control_thread.h b/src/core/receiver/control_thread.h index 5d893c911..b44a81894 100644 --- a/src/core/receiver/control_thread.h +++ b/src/core/receiver/control_thread.h @@ -155,9 +155,11 @@ private: unsigned int processed_control_messages_; unsigned int applied_actions_; boost::thread keyboard_thread_; + boost::thread sysv_queue_thread_; boost::thread gps_acq_assist_data_collector_thread_; void keyboard_listener(); + void sysv_queue_listener(); // default filename for assistance data const std::string eph_default_xml_filename = "./gps_ephemeris.xml";