GNSS-SDR  0.0.19
An Open Source GNSS Software Defined Receiver
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 
54 class GNSSFlowgraph;
55 class 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 {
66 public:
67  static ControlThread *me;
68  /*!
69  * \brief Default constructor
70  */
71  ControlThread();
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 
126 private:
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 sysv_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 size_t channel_event_type_hash_code_ = typeid(channel_event_sptr).hash_code();
183  const size_t command_event_type_hash_code_ = typeid(command_event_sptr).hash_code();
184 
185  std::shared_ptr<ConfigurationInterface> configuration_;
186  std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue_;
187  std::shared_ptr<GNSSFlowgraph> flowgraph_;
188 
189  std::thread cmd_interface_thread_;
190  std::thread keyboard_thread_;
191  std::thread sysv_queue_thread_;
192  std::thread gps_acq_assist_data_collector_thread_;
193 
194 #ifdef ENABLE_FPGA
195  boost::thread fpga_helper_thread_;
196 #endif
197 
198  TcpCmdInterface cmd_interface_;
199 
200  // SUPL assistance classes
201  Gnss_Sdr_Supl_Client supl_client_acquisition_;
202  Gnss_Sdr_Supl_Client supl_client_ephemeris_;
203  int supl_mcc_; // Current network MCC (Mobile country code), 3 digits.
204  int supl_mns_; // Current network MNC (Mobile Network code), 2 or 3 digits.
205  int supl_lac_; // Current network LAC (Location area code),16 bits, 1-65520 are valid values.
206  int supl_ci_; // Cell Identity (16 bits, 0-65535 are valid values).
207 
208  Agnss_Ref_Location agnss_ref_location_;
209  Agnss_Ref_Time agnss_ref_time_;
210 
211  unsigned int processed_control_messages_;
212  unsigned int applied_actions_;
213  int msqid_;
214 
215  bool well_formatted_configuration_;
216  bool conf_file_has_section_;
217  bool conf_file_has_mandatory_globals_;
218  bool conf_has_signal_sources_;
219  bool conf_has_observables_;
220  bool conf_has_pvt_;
221  bool receiver_on_standby_;
222  bool stop_;
223  bool restart_;
224  bool telecommand_enabled_;
225  bool pre_2009_file_; // to override the system time to postprocess old gnss records and avoid wrong week rollover
226 };
227 
228 
229 /** \} */
230 /** \} */
231 #endif // GNSS_SDR_CONTROL_THREAD_H
Interface of a thread-safe std::queue.
class that implements a C++ interface to external Secure User Location Protocol (SUPL) client library...
This class represents a GNSS flow graph.
Interface of an Assisted GNSS REFERENCE TIME storage.
Class that implements a TCP/IP telecommand command line interface for GNSS-SDR.
Interface of an Assisted GNSS REFERENCE LOCATION storage.
Class that defines a receiver command event.
int run()
Runs the control thread.
ControlThread()
Default constructor.
This abstract class represents an interface to configuration parameters.
This class represents a GNSS satellite.
Class that defines a channel event.
Interface of an Assisted GNSS REFERENCE TIME storage.
Interface of an Assisted GNSS REFERENCE LOCATION storage.
class that implements a C++ interface to external Secure User Location Protocol (SUPL) client library...
~ControlThread()
Destructor.
std::shared_ptr< GNSSFlowgraph > flowgraph()
Instantiates a flowgraph.
void set_control_queue(std::shared_ptr< Concurrent_Queue< pmt::pmt_t >> control_queue)
Sets the control_queue.
This class represents the main thread of the application, so the name is ControlThread. This is the GNSS Receiver Control Plane: it connects the flowgraph, starts running it, and while it does not stop, reads the control messages generated by the blocks, processes them, and applies the corresponding actions.