1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-07 16:00:35 +00:00

Add a queue listener to the control thread

This commit is contained in:
Carles Fernandez 2016-10-01 17:32:38 +02:00
parent 35084f93cc
commit 32445c9864
2 changed files with 42 additions and 0 deletions

View File

@ -37,6 +37,9 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <string> #include <string>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
#include <gnuradio/message.h> #include <gnuradio/message.h>
@ -126,6 +129,7 @@ void ControlThread::run()
assist_GNSS(); assist_GNSS();
// start the keyboard_listener thread // start the keyboard_listener thread
keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this); 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 // Main loop to read and process the control messages
while (flowgraph_->running() && !stop_) while (flowgraph_->running() && !stop_)
@ -141,9 +145,11 @@ void ControlThread::run()
//Join keyboard thread //Join keyboard thread
#ifdef OLD_BOOST #ifdef OLD_BOOST
keyboard_thread_.timed_join(boost::posix_time::seconds(1)); keyboard_thread_.timed_join(boost::posix_time::seconds(1));
sysv_queue_thread_.timed_join(boost::posix_time::seconds(1));
#endif #endif
#ifndef OLD_BOOST #ifndef OLD_BOOST
keyboard_thread_.try_join_until(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(1000)); 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 #endif
LOG(INFO) << "Flowgraph stopped"; 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<ControlMessageFactory> cmf(new ControlMessageFactory());
if (control_queue_ != gr::msg_queue::sptr())
{
control_queue_->handle(cmf->GetQueueMessage(200, 0));
}
read_queue = false;
}
}
}
}
void ControlThread::keyboard_listener() void ControlThread::keyboard_listener()
{ {

View File

@ -155,9 +155,11 @@ private:
unsigned int processed_control_messages_; unsigned int processed_control_messages_;
unsigned int applied_actions_; unsigned int applied_actions_;
boost::thread keyboard_thread_; boost::thread keyboard_thread_;
boost::thread sysv_queue_thread_;
boost::thread gps_acq_assist_data_collector_thread_; boost::thread gps_acq_assist_data_collector_thread_;
void keyboard_listener(); void keyboard_listener();
void sysv_queue_listener();
// default filename for assistance data // default filename for assistance data
const std::string eph_default_xml_filename = "./gps_ephemeris.xml"; const std::string eph_default_xml_filename = "./gps_ephemeris.xml";