mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-02-14 10:00:11 +00:00
Added keyboard response functionality: Now it is possible to stop GNSS-SDR from the keyboard order "q"+ENTER
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@186 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
parent
984b782660
commit
5340adad36
@ -41,6 +41,8 @@
|
||||
#include "gnss_flowgraph.h"
|
||||
#include "file_configuration.h"
|
||||
#include "control_message_factory.h"
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using google::LogMessage;
|
||||
|
||||
@ -102,6 +104,9 @@ void ControlThread::run()
|
||||
return;
|
||||
}
|
||||
|
||||
// start the keyboard_listener thread
|
||||
keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this);
|
||||
|
||||
// Main loop to read and process the control messages
|
||||
while (flowgraph_->running() && !stop_)
|
||||
{
|
||||
@ -110,8 +115,8 @@ void ControlThread::run()
|
||||
if (control_messages_ != 0) process_control_messages();
|
||||
}
|
||||
|
||||
keyboard_thread_.join();
|
||||
flowgraph_->stop();
|
||||
|
||||
LOG_AT_LEVEL(INFO) << "Flowgraph stopped";
|
||||
}
|
||||
|
||||
@ -199,3 +204,26 @@ void ControlThread::apply_action(unsigned int what)
|
||||
|
||||
}
|
||||
|
||||
void ControlThread::keyboard_listener()
|
||||
{
|
||||
bool read_keys=true;
|
||||
char c;
|
||||
//std::cout<<"Keystroke reader start!"<<std::endl;
|
||||
while(read_keys)
|
||||
{
|
||||
c= std::cin.get();
|
||||
//std::cout<<"Keystroke received: "<<c<<std::endl;
|
||||
if (c=='q')
|
||||
{
|
||||
std::cout<<"Quit keystroke order received, stopping GNSS-SDR !!"<<std::endl;
|
||||
ControlMessageFactory* cmf = new ControlMessageFactory();
|
||||
if (control_queue_ != gr_msg_queue_sptr()) {
|
||||
control_queue_->handle(cmf->GetQueueMessage(200, 0));
|
||||
}
|
||||
delete cmf;
|
||||
read_keys=false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#include <gnuradio/gr_msg_queue.h>
|
||||
#include "control_message_factory.h"
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
class GNSSFlowgraph;
|
||||
class ConfigurationInterface;
|
||||
@ -123,6 +124,8 @@ private:
|
||||
|
||||
unsigned int processed_control_messages_;
|
||||
unsigned int applied_actions_;
|
||||
boost::thread keyboard_thread_;
|
||||
void keyboard_listener();
|
||||
};
|
||||
|
||||
#endif /*GNSS_SDR_CONTROL_THREAD_H_*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user