1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 04:30:33 +00:00

Merge branch 'next' of https://github.com/gnss-sdr/gnss-sdr into next

This commit is contained in:
Carles Fernandez 2018-10-24 11:37:24 +02:00
commit 465013e574
6 changed files with 103 additions and 33 deletions

View File

@ -80,6 +80,7 @@ ControlThread::ControlThread()
configuration_ = std::make_shared<FileConfiguration>(FLAGS_c); configuration_ = std::make_shared<FileConfiguration>(FLAGS_c);
} }
delete_configuration_ = false; delete_configuration_ = false;
restart_ = false;
init(); init();
} }
@ -115,7 +116,7 @@ void ControlThread::telecommand_listener()
* while (flowgraph_->running() && !stop)_{ * while (flowgraph_->running() && !stop)_{
* 3- Read control messages and process them } * 3- Read control messages and process them }
*/ */
void ControlThread::run() int ControlThread::run()
{ {
// Connect the flowgraph // Connect the flowgraph
try try
@ -125,7 +126,7 @@ void ControlThread::run()
catch (const std::exception &e) catch (const std::exception &e)
{ {
LOG(ERROR) << e.what(); LOG(ERROR) << e.what();
return; return 0;
} }
if (flowgraph_->connected()) if (flowgraph_->connected())
{ {
@ -134,7 +135,7 @@ void ControlThread::run()
else else
{ {
LOG(ERROR) << "Unable to connect flowgraph"; LOG(ERROR) << "Unable to connect flowgraph";
return; return 0;
} }
// Start the flowgraph // Start the flowgraph
flowgraph_->start(); flowgraph_->start();
@ -145,7 +146,7 @@ void ControlThread::run()
else else
{ {
LOG(ERROR) << "Unable to start flowgraph"; LOG(ERROR) << "Unable to start flowgraph";
return; return 0;
} }
//launch GNSS assistance process AFTER the flowgraph is running because the GNURadio asynchronous queues must be already running to transport msgs //launch GNSS assistance process AFTER the flowgraph is running because the GNURadio asynchronous queues must be already running to transport msgs
@ -189,6 +190,15 @@ void ControlThread::run()
#endif #endif
LOG(INFO) << "Flowgraph stopped"; LOG(INFO) << "Flowgraph stopped";
if (restart_)
{
return 42; //signal the gnss-sdr-harness.sh to restart the receiver program
}
else
{
return 0; //normal shutdown
}
} }
@ -200,6 +210,7 @@ void ControlThread::set_control_queue(gr::msg_queue::sptr control_queue)
return; return;
} }
control_queue_ = control_queue; control_queue_ = control_queue;
cmd_interface_.set_msg_queue(control_queue_);
} }
@ -602,6 +613,7 @@ void ControlThread::init()
{ {
// Instantiates a control queue, a GNSS flowgraph, and a control message factory // Instantiates a control queue, a GNSS flowgraph, and a control message factory
control_queue_ = gr::msg_queue::make(0); control_queue_ = gr::msg_queue::make(0);
cmd_interface_.set_msg_queue(control_queue_); //set also the queue pointer for the telecommand thread
try try
{ {
flowgraph_ = std::make_shared<GNSSFlowgraph>(configuration_, control_queue_); flowgraph_ = std::make_shared<GNSSFlowgraph>(configuration_, control_queue_);
@ -668,6 +680,12 @@ void ControlThread::apply_action(unsigned int what)
stop_ = true; stop_ = true;
applied_actions_++; applied_actions_++;
break; break;
case 1:
DLOG(INFO) << "Received action RESTART";
stop_ = true;
restart_ = true;
applied_actions_++;
break;
default: default:
DLOG(INFO) << "Unrecognized action."; DLOG(INFO) << "Unrecognized action.";
break; break;

View File

@ -83,7 +83,7 @@ public:
* *
* - Read control messages and process them; } * - Read control messages and process them; }
*/ */
void run(); int run();
/*! /*!
* \brief Sets the control_queue * \brief Sets the control_queue
@ -155,6 +155,7 @@ private:
std::shared_ptr<ControlMessageFactory> control_message_factory_; std::shared_ptr<ControlMessageFactory> control_message_factory_;
std::shared_ptr<std::vector<std::shared_ptr<ControlMessage>>> control_messages_; std::shared_ptr<std::vector<std::shared_ptr<ControlMessage>>> control_messages_;
bool stop_; bool stop_;
bool restart_;
bool delete_configuration_; bool delete_configuration_;
unsigned int processed_control_messages_; unsigned int processed_control_messages_;
unsigned int applied_actions_; unsigned int applied_actions_;

View File

@ -30,8 +30,27 @@
*/ */
#include "tcp_cmd_interface.h" #include "tcp_cmd_interface.h"
#include "control_message_factory.h"
#include <functional>
std::string TcpCmdInterface::reset(const std::vector<std::string> &commandLine)
{
std::string response;
std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory());
if (control_queue_ != nullptr)
{
control_queue_->handle(cmf->GetQueueMessage(200, 1)); //send the restart message (who=200,what=1)
response = "OK\n";
}
else
{
response = "ERROR\n";
}
return response;
}
std::string TcpCmdInterface::stop(const std::vector<std::string> &commandLine) std::string TcpCmdInterface::stop(const std::vector<std::string> &commandLine)
{ {
std::string response; std::string response;
@ -78,21 +97,28 @@ std::string TcpCmdInterface::set_ch_satellite(const std::vector<std::string> &co
void TcpCmdInterface::register_functions() void TcpCmdInterface::register_functions()
{ {
functions["status"] = status; functions["status"] = std::bind(&TcpCmdInterface::status, this, std::placeholders::_1);
functions["stop"] = stop; functions["stop"] = std::bind(&TcpCmdInterface::stop, this, std::placeholders::_1);
functions["assistedstart"] = assistedstart; functions["reset"] = std::bind(&TcpCmdInterface::reset, this, std::placeholders::_1);
functions["warmstart"] = warmstart; functions["assistedstart"] = std::bind(&TcpCmdInterface::assistedstart, this, std::placeholders::_1);
functions["coldstart"] = coldstart; functions["warmstart"] = std::bind(&TcpCmdInterface::warmstart, this, std::placeholders::_1);
functions["set_ch_satellite"] = set_ch_satellite; functions["coldstart"] = std::bind(&TcpCmdInterface::coldstart, this, std::placeholders::_1);
functions["set_ch_satellite"] = std::bind(&TcpCmdInterface::set_ch_satellite, this, std::placeholders::_1);
} }
TcpCmdInterface::TcpCmdInterface() TcpCmdInterface::TcpCmdInterface()
{ {
register_functions(); register_functions();
keep_running_ = true;
control_queue_ = nullptr;
} }
void TcpCmdInterface::set_msg_queue(gr::msg_queue::sptr control_queue)
{
control_queue_ = control_queue;
}
void TcpCmdInterface::run_cmd_server(int tcp_port) void TcpCmdInterface::run_cmd_server(int tcp_port)
{ {
// Get the port from the parameters // Get the port from the parameters
@ -106,18 +132,18 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
try try
{ {
boost::asio::ip::tcp::acceptor acceptor(service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)); boost::asio::ip::tcp::acceptor acceptor(service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port));
bool keep_running = true;
while (keep_running) while (keep_running_)
{ {
try try
{ {
std::cout << "Telecommand TCP interface listening on port " << tcp_port << std::endl; std::cout << "TcpCmdInterface: Telecommand TCP interface listening on port " << tcp_port << std::endl;
boost::asio::ip::tcp::socket socket(service); boost::asio::ip::tcp::socket socket(service);
acceptor.accept(socket, not_throw); acceptor.accept(socket, not_throw);
if (not_throw) if (not_throw)
{ {
std::cerr << "Error when binding the port in the socket" << std::endl; std::cout << "TcpCmdInterface: Error when binding the port in the socket" << std::endl;
continue; continue;
} }
@ -127,12 +153,10 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
{ {
std::string response; std::string response;
boost::asio::streambuf b; boost::asio::streambuf b;
boost::asio::read_until(socket, b, '\n'); boost::asio::read_until(socket, b, '\n', error);
std::istream is(&b); std::istream is(&b);
std::string line; std::string line;
std::getline(is, line); std::getline(is, line);
std::cout << "received command: " << line << std::endl;
std::istringstream iss(line); std::istringstream iss(line);
std::vector<std::string> cmd_vector(std::istream_iterator<std::string>{iss}, std::vector<std::string> cmd_vector(std::istream_iterator<std::string>{iss},
std::istream_iterator<std::string>()); std::istream_iterator<std::string>());
@ -140,9 +164,16 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
if (cmd_vector.size() > 0) if (cmd_vector.size() > 0)
{ {
try try
{
if (cmd_vector.at(0).compare("exit") == 0)
{
error = boost::asio::error::eof;
}
else
{ {
response = functions[cmd_vector.at(0)](cmd_vector); response = functions[cmd_vector.at(0)](cmd_vector);
} }
}
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
response = "ERROR: command execution error: " + std::string(ex.what()) + "\n"; response = "ERROR: command execution error: " + std::string(ex.what()) + "\n";
@ -157,19 +188,19 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
socket.write_some(boost::asio::buffer(response), not_throw); socket.write_some(boost::asio::buffer(response), not_throw);
if (not_throw) if (not_throw)
{ {
std::cerr << "Error sending(" << not_throw.value() << "): " << not_throw.message() << std::endl; std::cout << "Error sending(" << not_throw.value() << "): " << not_throw.message() << std::endl;
break; break;
} }
} }
while (!error); // && error != boost::asio::error::eof); while (error != boost::asio::error::eof);
if (error == boost::asio::error::eof) if (error == boost::asio::error::eof)
{ {
std::cout << "EOF detected\n"; std::cout << "TcpCmdInterface: EOF detected\n";
} }
else else
{ {
std::cout << "error: " << error << std::endl; std::cout << "TcpCmdInterface unexpected error: " << error << std::endl;
} }
// Close socket // Close socket
@ -177,11 +208,11 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
} }
catch (const boost::exception &e) catch (const boost::exception &e)
{ {
std::cout << "Boost exception " << std::endl; std::cout << "TcpCmdInterface: Boost exception " << std::endl;
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
std::cout << "Exception " << ex.what() << std::endl; std::cout << "TcpCmdInterface: Exception " << ex.what() << std::endl;
} }
} }
} }

View File

@ -38,7 +38,10 @@
#include <unordered_map> #include <unordered_map>
#include <algorithm> #include <algorithm>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <glog/logging.h>
#include <cstdint> #include <cstdint>
#include <gnuradio/message.h>
#include <gnuradio/msg_queue.h>
class TcpCmdInterface class TcpCmdInterface
@ -47,18 +50,24 @@ public:
TcpCmdInterface(); TcpCmdInterface();
virtual ~TcpCmdInterface(); virtual ~TcpCmdInterface();
void run_cmd_server(int tcp_port); void run_cmd_server(int tcp_port);
void set_msg_queue(gr::msg_queue::sptr control_queue);
private: private:
std::unordered_map<std::string, std::function<std::string(const std::vector<std::string> &)>> std::unordered_map<std::string, std::function<std::string(const std::vector<std::string> &)>>
functions; functions;
static std::string status(const std::vector<std::string> &commandLine); std::string status(const std::vector<std::string> &commandLine);
static std::string stop(const std::vector<std::string> &commandLine); std::string reset(const std::vector<std::string> &commandLine);
static std::string assistedstart(const std::vector<std::string> &commandLine); std::string stop(const std::vector<std::string> &commandLine);
static std::string warmstart(const std::vector<std::string> &commandLine); std::string assistedstart(const std::vector<std::string> &commandLine);
static std::string coldstart(const std::vector<std::string> &commandLine); std::string warmstart(const std::vector<std::string> &commandLine);
static std::string set_ch_satellite(const std::vector<std::string> &commandLine); std::string coldstart(const std::vector<std::string> &commandLine);
std::string set_ch_satellite(const std::vector<std::string> &commandLine);
void register_functions(); void register_functions();
gr::msg_queue::sptr control_queue_;
bool keep_running_;
}; };
#endif /* GNSS_SDR_TCPCMDINTERFACE_H_ */ #endif /* GNSS_SDR_TCPCMDINTERFACE_H_ */

View File

@ -135,9 +135,10 @@ int main(int argc, char** argv)
std::chrono::time_point<std::chrono::system_clock> start, end; std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now(); start = std::chrono::system_clock::now();
int return_code;
try try
{ {
control_thread->run(); return_code = control_thread->run();
} }
catch (const boost::exception& e) catch (const boost::exception& e)
{ {
@ -189,5 +190,5 @@ int main(int argc, char** argv)
google::ShutDownCommandLineFlags(); google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR program ended." << std::endl; std::cout << "GNSS-SDR program ended." << std::endl;
return 0; return return_code;
} }

View File

@ -0,0 +1,10 @@
#!/bin/sh
# GNSS-SDR shell script that enables the remote GNSS-SDR restart telecommand
# usage: ./gnss-sdr-harness.sh ./gnss-sdr -c config_file.conf
echo $@
$@
while [ $? -eq 42 ]
do
echo "restarting GNSS-SDR..."
$@
done