GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
control_thread.h
Go to the documentation of this file.
1/*!
2 * \file control_thread.h
3 * \brief Interface of the receiver control plane
4 * \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
5 *
6 * GNSS Receiver Control Plane: connects the flowgraph, starts running it,
7 * and while it does not stop, reads the control messages generated by the blocks,
8 * processes them, and applies the corresponding actions.
9 *
10 * -----------------------------------------------------------------------------
11 *
12 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
13 * This file is part of GNSS-SDR.
14 *
15 * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
16 * SPDX-License-Identifier: GPL-3.0-or-later
17 *
18 * -----------------------------------------------------------------------------
19 */
20
21#ifndef GNSS_SDR_CONTROL_THREAD_H
22#define GNSS_SDR_CONTROL_THREAD_H
23
24#include "agnss_ref_location.h" // for Agnss_Ref_Location
25#include "agnss_ref_time.h" // for Agnss_Ref_Time
26#include "channel_event.h" // for channel_event_sptr
27#include "command_event.h" // for command_event_sptr
28#include "concurrent_queue.h" // for Concurrent_Queue
29#include "gnss_sdr_supl_client.h" // for Gnss_Sdr_Supl_Client
30#include "tcp_cmd_interface.h" // for TcpCmdInterface
31#include <pmt/pmt.h>
32#include <array> // for array
33#include <cstddef> // for size_t
34#include <memory> // for shared_ptr
35#include <string> // for string
36#include <thread> // for std::thread
37#include <typeinfo> // for std::type_info, typeid
38#include <utility> // for pair
39#include <vector> // for vector
40
41#ifdef ENABLE_FPGA
42#include <boost/thread.hpp> // for boost::thread
43#endif
44
45/** \addtogroup Core Core GNSS Receiver
46 * Core GNSS Receiver.
47 * \{ */
48/** \addtogroup Core_Receiver
49 * Classes for the core GNSS receiver.
50 * \{ */
51
52
54class GNSSFlowgraph;
55class Gnss_Satellite;
56
57
58/*!
59 * \brief This class represents the main thread of the application, so the name is ControlThread.
60 * This is the GNSS Receiver Control Plane: it connects the flowgraph, starts running it,
61 * and while it does not stop, reads the control messages generated by the blocks,
62 * processes them, and applies the corresponding actions.
63 */
65{
66public:
67 static ControlThread *me;
68 /*!
69 * \brief Default constructor
70 */
72
73 /*!
74 * \brief Constructor that initializes the class with parameters
75 *
76 * \param[in] configuration Pointer to a ConfigurationInterface
77 */
78 explicit ControlThread(std::shared_ptr<ConfigurationInterface> configuration);
79
80 /*!
81 * \brief Destructor
82 */
84
85 /*! \brief Runs the control thread
86 *
87 * This is the main loop that reads and process the control messages:
88 *
89 * - Connect the GNSS receiver flowgraph;
90 *
91 * - Start the GNSS receiver flowgraph;
92 *
93 * while (flowgraph_->running() && !stop_){
94 *
95 * - Read control messages and process them; }
96 */
97 int run();
98
99 /*!
100 * \brief Sets the control_queue
101 *
102 * \param[in] std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue
103 */
104 void set_control_queue(std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue);
105
106 unsigned int processed_control_messages() const
107 {
108 return processed_control_messages_;
109 }
110
111 unsigned int applied_actions() const
112 {
113 return applied_actions_;
114 }
115
116 /*!
117 * \brief Instantiates a flowgraph
118 *
119 * \return Returns a smart pointer to a flowgraph object
120 */
121 std::shared_ptr<GNSSFlowgraph> flowgraph()
122 {
123 return flowgraph_;
124 }
125
126private:
127 /*
128 * Callback function for handling signals.
129 * sig identifier of signal
130 */
131 static void handle_signal(int sig);
132
133 void init();
134
135 void apply_action(unsigned int what);
136
137 /*
138 * New receiver event dispatcher
139 */
140 void event_dispatcher(bool &valid_event, pmt::pmt_t &msg);
141
142 // Read {ephemeris, iono, utc, ref loc, ref time} assistance from a local XML file previously recorded
143 bool read_assistance_from_XML();
144
145 /*
146 * Blocking function that reads the GPS assistance queue
147 */
148 void gps_acq_assist_data_collector() const;
149
150 /*
151 * Compute elevations for the specified time and position for all the available satellites in ephemeris and almanac queues
152 * returns a vector filled with the available satellites ordered from high elevation to low elevation angle.
153 */
154 std::vector<std::pair<int, Gnss_Satellite>> get_visible_sats(time_t rx_utc_time, const std::array<float, 3> &LLH);
155
156 /*
157 * Read initial GNSS assistance from SUPL server or local XML files
158 */
159 void assist_GNSS();
160
161 void telecommand_listener();
162 void keyboard_listener();
163 void message_queue_listener();
164 void print_help_at_exit() const;
165
166 // default filename for assistance data
167 const std::string eph_default_xml_filename_ = "./gps_ephemeris.xml";
168 const std::string utc_default_xml_filename_ = "./gps_utc_model.xml";
169 const std::string iono_default_xml_filename_ = "./gps_iono.xml";
170 const std::string ref_time_default_xml_filename_ = "./gps_ref_time.xml";
171 const std::string ref_location_default_xml_filename_ = "./gps_ref_location.xml";
172 const std::string eph_gal_default_xml_filename_ = "./gal_ephemeris.xml";
173 const std::string eph_cnav_default_xml_filename_ = "./gps_cnav_ephemeris.xml";
174 const std::string gal_iono_default_xml_filename_ = "./gal_iono.xml";
175 const std::string gal_utc_default_xml_filename_ = "./gal_utc_model.xml";
176 const std::string cnav_utc_default_xml_filename_ = "./gps_cnav_utc_model.xml";
177 const std::string eph_glo_gnav_default_xml_filename_ = "./glo_gnav_ephemeris.xml";
178 const std::string glo_utc_default_xml_filename_ = "./glo_utc_model.xml";
179 const std::string gal_almanac_default_xml_filename_ = "./gal_almanac.xml";
180 const std::string gps_almanac_default_xml_filename_ = "./gps_almanac.xml";
181
182 const std::string control_message_queue_name_ = "receiver_control_queue";
183
184 const size_t channel_event_type_hash_code_ = typeid(channel_event_sptr).hash_code();
185 const size_t command_event_type_hash_code_ = typeid(command_event_sptr).hash_code();
186
187 std::shared_ptr<ConfigurationInterface> configuration_;
188 std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue_;
189 std::shared_ptr<GNSSFlowgraph> flowgraph_;
190
191 std::thread cmd_interface_thread_;
192 std::thread keyboard_thread_;
193 std::thread message_queue_thread_;
194 std::thread gps_acq_assist_data_collector_thread_;
195
196#ifdef ENABLE_FPGA
197 boost::thread fpga_helper_thread_;
198#endif
199
200 TcpCmdInterface cmd_interface_;
201
202 // SUPL assistance classes
203 Gnss_Sdr_Supl_Client supl_client_acquisition_;
204 Gnss_Sdr_Supl_Client supl_client_ephemeris_;
205 int supl_mcc_; // Current network MCC (Mobile country code), 3 digits.
206 int supl_mns_; // Current network MNC (Mobile Network code), 2 or 3 digits.
207 int supl_lac_; // Current network LAC (Location area code),16 bits, 1-65520 are valid values.
208 int supl_ci_; // Cell Identity (16 bits, 0-65535 are valid values).
209
210 Agnss_Ref_Location agnss_ref_location_;
211 Agnss_Ref_Time agnss_ref_time_;
212
213 unsigned int processed_control_messages_;
214 unsigned int applied_actions_;
215
216 bool well_formatted_configuration_;
217 bool conf_file_has_section_;
218 bool conf_file_has_mandatory_globals_;
219 bool conf_has_signal_sources_;
220 bool conf_has_observables_;
221 bool conf_has_pvt_;
222 bool receiver_on_standby_;
223 bool stop_;
224 bool restart_;
225 bool telecommand_enabled_;
226 bool pre_2009_file_; // to override the system time to postprocess old gnss records and avoid wrong week rollover
227};
228
229
230/** \} */
231/** \} */
232#endif // GNSS_SDR_CONTROL_THREAD_H
Interface of an Assisted GNSS REFERENCE LOCATION storage.
Interface of an Assisted GNSS REFERENCE TIME storage.
Class that defines a channel event.
Interface of an Assisted GNSS REFERENCE LOCATION storage.
Interface of an Assisted GNSS REFERENCE TIME storage.
This class implements a thread-safe std::queue.
This abstract class represents an interface to configuration parameters.
ControlThread()
Default constructor.
std::shared_ptr< GNSSFlowgraph > flowgraph()
Instantiates a flowgraph.
int run()
Runs the control thread.
void set_control_queue(std::shared_ptr< Concurrent_Queue< pmt::pmt_t > > control_queue)
Sets the control_queue.
ControlThread(std::shared_ptr< ConfigurationInterface > configuration)
Constructor that initializes the class with parameters.
~ControlThread()
Destructor.
This class represents a GNSS flow graph.
This class represents a GNSS satellite.
class that implements a C++ interface to external Secure User Location Protocol (SUPL) client library...
Class that defines a receiver command event.
Interface of a thread-safe std::queue.
class that implements a C++ interface to external Secure User Location Protocol (SUPL) client library...
Class that implements a TCP/IP telecommand command line interface for GNSS-SDR.