From 18e5339ea11cf7b639b64fe5a1411389702b450b Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 19 Oct 2018 14:54:03 +0200 Subject: [PATCH 1/4] Adding a TCP telecommand squeleton to the control_thread --- src/core/receiver/CMakeLists.txt | 1 + src/core/receiver/control_thread.cc | 15 +++++++++++++-- src/core/receiver/control_thread.h | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/receiver/CMakeLists.txt b/src/core/receiver/CMakeLists.txt index decc866d9..e0246a06f 100644 --- a/src/core/receiver/CMakeLists.txt +++ b/src/core/receiver/CMakeLists.txt @@ -24,6 +24,7 @@ set(GNSS_RECEIVER_SOURCES gnss_block_factory.cc gnss_flowgraph.cc in_memory_configuration.cc + tcp_cmd_interface.cc ) set(GNSS_RECEIVER_HEADERS diff --git a/src/core/receiver/control_thread.cc b/src/core/receiver/control_thread.cc index de3dc893b..467ac3ade 100644 --- a/src/core/receiver/control_thread.cc +++ b/src/core/receiver/control_thread.cc @@ -98,6 +98,12 @@ ControlThread::~ControlThread() } +void ControlThread::telecommand_listener() +{ + int tcp_cmd_port = configuration_->property("Channel.telecontrol_tcp_port", 3333); + cmd_interface_.run_cmd_server(tcp_cmd_port); +} + /* * Runs the control thread that manages the receiver control plane * @@ -146,8 +152,11 @@ void ControlThread::run() keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this); sysv_queue_thread_ = boost::thread(&ControlThread::sysv_queue_listener, this); - bool enable_FPGA = configuration_->property("Channel.enable_FPGA", false); + //start the telecommand listener thread + cmd_interface_thread_ = boost::thread(&ControlThread::telecommand_listener, this); + + bool enable_FPGA = configuration_->property("Channel.enable_FPGA", false); if (enable_FPGA == true) { flowgraph_->start_acquisition_helper(); @@ -165,14 +174,16 @@ void ControlThread::run() stop_ = true; flowgraph_->disconnect(); - //Join keyboard thread +//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)); + cmd_interface_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)); + cmd_interface_thread_.try_join_until(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(1000)); #endif LOG(INFO) << "Flowgraph stopped"; diff --git a/src/core/receiver/control_thread.h b/src/core/receiver/control_thread.h index b978b7757..3b1fb2cda 100644 --- a/src/core/receiver/control_thread.h +++ b/src/core/receiver/control_thread.h @@ -37,6 +37,7 @@ #include "control_message_factory.h" #include "gnss_sdr_supl_client.h" +#include "tcp_cmd_interface.h" #include #include #include @@ -113,6 +114,10 @@ public: } private: + //Telecommand TCP interface + TcpCmdInterface cmd_interface_; + void telecommand_listener(); + boost::thread cmd_interface_thread_; //SUPL assistance classes gnss_sdr_supl_client supl_client_acquisition_; gnss_sdr_supl_client supl_client_ephemeris_; From 7d681a7e19868e2059bbf97512e680750401fb63 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 21 Oct 2018 18:27:23 +0200 Subject: [PATCH 2/4] Fix typos --- src/core/receiver/control_thread.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/receiver/control_thread.cc b/src/core/receiver/control_thread.cc index dbc433241..12da99748 100644 --- a/src/core/receiver/control_thread.cc +++ b/src/core/receiver/control_thread.cc @@ -201,32 +201,32 @@ bool ControlThread::read_assistance_from_XML() bool ret = false; // getting names from the config file, if available std::string eph_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_xml", eph_default_xml_filename); - std::string utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_utc_model.xml", utc_default_xml_filename); + std::string utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_utc_model_xml", utc_default_xml_filename); std::string iono_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_iono_xml", iono_default_xml_filename); std::string gal_iono_xml_filename = configuration_->property("GNSS-SDR.SUPL_gal_iono_xml", gal_iono_default_xml_filename); std::string ref_time_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_ref_time_xml", ref_time_default_xml_filename); std::string ref_location_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_ref_location_xml", ref_location_default_xml_filename); std::string eph_gal_xml_filename = configuration_->property("GNSS-SDR.SUPL_gal_ephemeris_xml", eph_gal_default_xml_filename); std::string eph_cnav_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_cnav_ephemeris_xml", eph_cnav_default_xml_filename); - std::string gal_utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_gal_utc_model.xml", gal_utc_default_xml_filename); - std::string cnav_utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_cnav_utc_model.xml", cnav_utc_default_xml_filename); + std::string gal_utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_gal_utc_model_xml", gal_utc_default_xml_filename); + std::string cnav_utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_cnav_utc_model_xml", cnav_utc_default_xml_filename); std::string eph_glo_xml_filename = configuration_->property("GNSS-SDR.SUPL_glo_ephemeris_xml", eph_glo_gnav_default_xml_filename); - std::string glo_utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_glo_utc_model.xml", glo_utc_default_xml_filename); + std::string glo_utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_glo_utc_model_xml", glo_utc_default_xml_filename); if (configuration_->property("GNSS-SDR.AGNSS_XML_enabled", false) == true) { eph_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_ephemeris_xml", eph_default_xml_filename); - utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_utc_model.xml", utc_default_xml_filename); + utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_utc_model_xml", utc_default_xml_filename); iono_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_iono_xml", iono_default_xml_filename); gal_iono_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gal_iono_xml", gal_iono_default_xml_filename); ref_time_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_ref_time_xml", ref_time_default_xml_filename); ref_location_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_ref_location_xml", ref_location_default_xml_filename); eph_gal_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gal_ephemeris_xml", eph_gal_default_xml_filename); eph_cnav_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gps_cnav_ephemeris_xml", eph_cnav_default_xml_filename); - gal_utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gal_utc_model.xml", gal_utc_default_xml_filename); - cnav_utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_cnav_utc_model.xml", cnav_utc_default_xml_filename); + gal_utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_gal_utc_model_xml", gal_utc_default_xml_filename); + cnav_utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_cnav_utc_model_xml", cnav_utc_default_xml_filename); eph_glo_xml_filename = configuration_->property("GNSS-SDR.AGNSS_glo_ephemeris_xml", eph_glo_gnav_default_xml_filename); - glo_utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_glo_utc_model.xml", glo_utc_default_xml_filename); + glo_utc_xml_filename = configuration_->property("GNSS-SDR.AGNSS_glo_utc_model_xml", glo_utc_default_xml_filename); } std::cout << "Trying to read GNSS ephemeris from XML file(s)..." << std::endl; @@ -511,7 +511,7 @@ void ControlThread::assist_GNSS() { std::cout << "SUPL: Failed to create Iono data file" << std::endl; } - std::string utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_utc_model.xml", utc_default_xml_filename); + std::string utc_xml_filename = configuration_->property("GNSS-SDR.SUPL_gps_utc_model_xml", utc_default_xml_filename); if (supl_client_ephemeris_.save_utc_xml(utc_xml_filename, supl_client_ephemeris_.gps_utc) == true) { std::cout << "SUPL: UTC model data file created" << std::endl; From 2acdbc31f2e7fa32c2e88747beb3a00537c63f29 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 21 Oct 2018 19:28:54 +0200 Subject: [PATCH 3/4] Store Galileo UTC data in xml file if leap second is not zero --- src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc index d7de9453c..f055915cc 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_cc.cc @@ -507,7 +507,7 @@ rtklib_pvt_cc::~rtklib_pvt_cc() // Save Galileo UTC model parameters file_name = "gal_utc_model.xml"; - if (d_ls_pvt->galileo_utc_model.A0_6 != 0.0) + if (d_ls_pvt->galileo_utc_model.Delta_tLS_6 != 0.0) { std::ofstream ofs; try From 146363920d892b23b0316c3ca22f08e0268a8cca Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 21 Oct 2018 19:33:02 +0200 Subject: [PATCH 4/4] Adding missing files --- src/core/receiver/tcp_cmd_interface.cc | 187 +++++++++++++++++++++++++ src/core/receiver/tcp_cmd_interface.h | 64 +++++++++ 2 files changed, 251 insertions(+) create mode 100644 src/core/receiver/tcp_cmd_interface.cc create mode 100644 src/core/receiver/tcp_cmd_interface.h diff --git a/src/core/receiver/tcp_cmd_interface.cc b/src/core/receiver/tcp_cmd_interface.cc new file mode 100644 index 000000000..6254f3ed9 --- /dev/null +++ b/src/core/receiver/tcp_cmd_interface.cc @@ -0,0 +1,187 @@ +/*! + * \file tcp_cmd_interface.cc + * + * \brief Class that implements a TCP telecontrol command line interface + * for GNSS-SDR + * \author Javier Arribas jarribas (at) cttc.es + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "tcp_cmd_interface.h" + + +std::string TcpCmdInterface::stop(const std::vector &commandLine) +{ + std::string response; + response = "Not implemented\n"; + return response; +} + +std::string TcpCmdInterface::status(const std::vector &commandLine) +{ + std::string response; + response = "Not implemented\n"; + return response; +} + +std::string TcpCmdInterface::assistedstart(const std::vector &commandLine) +{ + std::string response; + response = "Not implemented\n"; + return response; +} + +std::string TcpCmdInterface::warmstart(const std::vector &commandLine) +{ + std::string response; + response = "Not implemented\n"; + return response; +} + + +std::string TcpCmdInterface::coldstart(const std::vector &commandLine) +{ + std::string response; + response = "Not implemented\n"; + return response; +} + +std::string TcpCmdInterface::set_ch_satellite(const std::vector &commandLine) +{ + std::string response; + response = "Not implemented\n"; + return response; +} + + +void TcpCmdInterface::register_functions() +{ + functions["status"] = status; + functions["stop"] = stop; + functions["assistedstart"] = assistedstart; + functions["warmstart"] = warmstart; + functions["coldstart"] = coldstart; + functions["set_ch_satellite"] = set_ch_satellite; +} + + +TcpCmdInterface::TcpCmdInterface() +{ + register_functions(); +} + + +void TcpCmdInterface::run_cmd_server(int tcp_port) +{ + // Get the port from the parameters + uint16_t port = tcp_port; + + // Error to not throw exception + boost::system::error_code not_throw; + + // Socket and acceptor + boost::asio::io_service service; + 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) + { + try + { + std::cout << "Telecommand TCP interface listening on port " << tcp_port << std::endl; + boost::asio::ip::tcp::socket socket(service); + acceptor.accept(socket, not_throw); + if (not_throw) + { + std::cerr << "Error when binding the port in the socket" << std::endl; + continue; + } + + // Read a message + boost::system::error_code error = boost::asio::error::eof; + do + { + std::string response; + boost::asio::streambuf b; + boost::asio::read_until(socket, b, '\n'); + std::istream is(&b); + std::string line; + std::getline(is, line); + std::cout << "received command: " << line << std::endl; + + std::istringstream iss(line); + std::vector cmd_vector(std::istream_iterator{iss}, + std::istream_iterator()); + + if (cmd_vector.size() > 0) + { + try + { + response = functions[cmd_vector.at(0)](cmd_vector); + } + catch (const std::exception &ex) + { + response = "ERROR: command execution error: " + std::string(ex.what()) + "\n"; + } + } + else + { + response = "ERROR: empty command\n"; + } + + //send cmd response + socket.write_some(boost::asio::buffer(response), not_throw); + if (not_throw) + { + std::cerr << "Error sending(" << not_throw.value() << "): " << not_throw.message() << std::endl; + break; + } + } + while (error > 0); // && error != boost::asio::error::eof); + + if (error == boost::asio::error::eof) + { + std::cout << "EOF detected\n"; + } + else + { + std::cout << "error: " << error << std::endl; + } + + // Close socket + socket.close(); + } + catch (const std::exception &ex) + { + std::cout << "Exception " << ex.what() << std::endl; + } + } +} + + +TcpCmdInterface::~TcpCmdInterface() +{ + // TODO Auto-generated destructor stub +} diff --git a/src/core/receiver/tcp_cmd_interface.h b/src/core/receiver/tcp_cmd_interface.h new file mode 100644 index 000000000..ae366aad7 --- /dev/null +++ b/src/core/receiver/tcp_cmd_interface.h @@ -0,0 +1,64 @@ +/*! + * \file tcp_cmd_interface.h + * + * \brief Class that implements a TCP telecontrol command line interface + * for GNSS-SDR + * \author Javier Arribas jarribas (at) cttc.es + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ +#ifndef TCPCMDINTERFACE_H_ +#define TCPCMDINTERFACE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + + +class TcpCmdInterface +{ +public: + TcpCmdInterface(); + virtual ~TcpCmdInterface(); + void run_cmd_server(int tcp_port); + +private: + std::unordered_map &)>> + functions; + static std::string status(const std::vector &commandLine); + static std::string stop(const std::vector &commandLine); + static std::string assistedstart(const std::vector &commandLine); + static std::string warmstart(const std::vector &commandLine); + static std::string coldstart(const std::vector &commandLine); + static std::string set_ch_satellite(const std::vector &commandLine); + + void register_functions(); +}; + +#endif /* TCPCMDINTERFACE_H_ */