GNSS-SDR  0.0.17
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  * \brief This class represents the main thread of the application, so the name is ControlThread.
59  * This is the GNSS Receiver Control Plane: it connects the flowgraph, starts running it,
60  * and while it does not stop, reads the control messages generated by the blocks,
61  * processes them, and applies the corresponding actions.
62  */
64 {
65 public:
66  /*!
67  * \brief Default constructor
68  */
69  ControlThread();
70 
71  /*!
72  * \brief Constructor that initializes the class with parameters
73  *
74  * \param[in] configuration Pointer to a ConfigurationInterface
75  */
76  explicit ControlThread(std::shared_ptr<ConfigurationInterface> configuration);
77 
78  /*!
79  * \brief Destructor
80  */
82 
83  /*! \brief Runs the control thread
84  *
85  * This is the main loop that reads and process the control messages:
86  *
87  * - Connect the GNSS receiver flowgraph;
88  *
89  * - Start the GNSS receiver flowgraph;
90  *
91  * while (flowgraph_->running() && !stop_){
92  *
93  * - Read control messages and process them; }
94  */
95  int run();
96 
97  /*!
98  * \brief Sets the control_queue
99  *
100  * \param[in] std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue
101  */
102  void set_control_queue(std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue);
103 
104  unsigned int processed_control_messages() const
105  {
106  return processed_control_messages_;
107  }
108 
109  unsigned int applied_actions() const
110  {
111  return applied_actions_;
112  }
113 
114  /*!
115  * \brief Instantiates a flowgraph
116  *
117  * \return Returns a smart pointer to a flowgraph object
118  */
119  std::shared_ptr<GNSSFlowgraph> flowgraph()
120  {
121  return flowgraph_;
122  }
123 
124 private:
125  void init();
126 
127  void apply_action(unsigned int what);
128 
129  /*
130  * New receiver event dispatcher
131  */
132  void event_dispatcher(bool &valid_event, pmt::pmt_t &msg);
133 
134  // Read {ephemeris, iono, utc, ref loc, ref time} assistance from a local XML file previously recorded
135  bool read_assistance_from_XML();
136 
137  /*
138  * Blocking function that reads the GPS assistance queue
139  */
140  void gps_acq_assist_data_collector() const;
141 
142  /*
143  * Compute elevations for the specified time and position for all the available satellites in ephemeris and almanac queues
144  * returns a vector filled with the available satellites ordered from high elevation to low elevation angle.
145  */
146  std::vector<std::pair<int, Gnss_Satellite>> get_visible_sats(time_t rx_utc_time, const std::array<float, 3> &LLH);
147 
148  /*
149  * Read initial GNSS assistance from SUPL server or local XML files
150  */
151  void assist_GNSS();
152 
153  void telecommand_listener();
154  void keyboard_listener();
155  void sysv_queue_listener();
156  void print_help_at_exit() const;
157 
158  // default filename for assistance data
159  const std::string eph_default_xml_filename_ = "./gps_ephemeris.xml";
160  const std::string utc_default_xml_filename_ = "./gps_utc_model.xml";
161  const std::string iono_default_xml_filename_ = "./gps_iono.xml";
162  const std::string ref_time_default_xml_filename_ = "./gps_ref_time.xml";
163  const std::string ref_location_default_xml_filename_ = "./gps_ref_location.xml";
164  const std::string eph_gal_default_xml_filename_ = "./gal_ephemeris.xml";
165  const std::string eph_cnav_default_xml_filename_ = "./gps_cnav_ephemeris.xml";
166  const std::string gal_iono_default_xml_filename_ = "./gal_iono.xml";
167  const std::string gal_utc_default_xml_filename_ = "./gal_utc_model.xml";
168  const std::string cnav_utc_default_xml_filename_ = "./gps_cnav_utc_model.xml";
169  const std::string eph_glo_gnav_default_xml_filename_ = "./glo_gnav_ephemeris.xml";
170  const std::string glo_utc_default_xml_filename_ = "./glo_utc_model.xml";
171  const std::string gal_almanac_default_xml_filename_ = "./gal_almanac.xml";
172  const std::string gps_almanac_default_xml_filename_ = "./gps_almanac.xml";
173 
174  const size_t channel_event_type_hash_code_ = typeid(channel_event_sptr).hash_code();
175  const size_t command_event_type_hash_code_ = typeid(command_event_sptr).hash_code();
176 
177  std::shared_ptr<ConfigurationInterface> configuration_;
178  std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue_;
179  std::shared_ptr<GNSSFlowgraph> flowgraph_;
180 
181  std::thread cmd_interface_thread_;
182  std::thread keyboard_thread_;
183  std::thread sysv_queue_thread_;
184  std::thread gps_acq_assist_data_collector_thread_;
185 
186 #ifdef ENABLE_FPGA
187  boost::thread fpga_helper_thread_;
188 #endif
189 
190  TcpCmdInterface cmd_interface_;
191 
192  // SUPL assistance classes
193  Gnss_Sdr_Supl_Client supl_client_acquisition_;
194  Gnss_Sdr_Supl_Client supl_client_ephemeris_;
195  int supl_mcc_; // Current network MCC (Mobile country code), 3 digits.
196  int supl_mns_; // Current network MNC (Mobile Network code), 2 or 3 digits.
197  int supl_lac_; // Current network LAC (Location area code),16 bits, 1-65520 are valid values.
198  int supl_ci_; // Cell Identity (16 bits, 0-65535 are valid values).
199 
200  Agnss_Ref_Location agnss_ref_location_;
201  Agnss_Ref_Time agnss_ref_time_;
202 
203  unsigned int processed_control_messages_;
204  unsigned int applied_actions_;
205  int msqid_;
206 
207  bool well_formatted_configuration_;
208  bool conf_file_has_section_;
209  bool conf_file_has_mandatory_globals_;
210  bool conf_has_signal_sources_;
211  bool conf_has_observables_;
212  bool conf_has_pvt_;
213  bool receiver_on_standby_;
214  bool stop_;
215  bool restart_;
216  bool telecommand_enabled_;
217  bool pre_2009_file_; // to override the system time to postprocess old gnss records and avoid wrong week rollover
218 };
219 
220 
221 /** \} */
222 /** \} */
223 #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.