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