GNSS-SDR  0.0.17
An Open Source GNSS Software Defined Receiver
rtklib_pvt_gs.h
Go to the documentation of this file.
1 /*!
2  * \file rtklib_pvt_gs.h
3  * \brief Interface of a Position Velocity and Time computation block
4  * \author Javier Arribas, 2017. jarribas(at)cttc.es
5  *
6  * -----------------------------------------------------------------------------
7  *
8  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
9  * This file is part of GNSS-SDR.
10  *
11  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
12  * SPDX-License-Identifier: GPL-3.0-or-later
13  *
14  * -----------------------------------------------------------------------------
15  */
16 
17 #ifndef GNSS_SDR_RTKLIB_PVT_GS_H
18 #define GNSS_SDR_RTKLIB_PVT_GS_H
19 
20 #include "gnss_block_interface.h"
21 #include "gnss_synchro.h"
22 #include "gnss_time.h"
23 #include "rtklib.h"
24 #include <boost/date_time/gregorian/gregorian.hpp>
25 #include <boost/date_time/posix_time/posix_time.hpp>
26 #include <gnuradio/sync_block.h> // for sync_block
27 #include <gnuradio/types.h> // for gr_vector_const_void_star
28 #include <pmt/pmt.h> // for pmt_t
29 #include <chrono> // for system_clock
30 #include <cstddef> // for size_t
31 #include <cstdint> // for int32_t
32 #include <ctime> // for time_t
33 #include <fstream> // for std::fstream
34 #include <map> // for map
35 #include <memory> // for shared_ptr, unique_ptr
36 #include <queue> // for std::queue
37 #include <string> // for string
38 #include <sys/types.h> // for key_t
39 #include <vector> // for vector
40 
41 /** \addtogroup PVT
42  * \{ */
43 /** \addtogroup PVT_gnuradio_blocks pvt_gr_blocks
44  * GNU Radio blocks for the computation of PVT solutions.
45  * \{ */
46 
47 
50 class Galileo_Almanac;
51 class Galileo_Ephemeris;
52 class GeoJSON_Printer;
53 class Gps_Almanac;
54 class Gps_Ephemeris;
55 class Gpx_Printer;
56 class Kml_Printer;
59 class Nmea_Printer;
60 class Pvt_Conf;
61 class Rinex_Printer;
62 class Rtcm_Printer;
63 class An_Packet_Printer;
64 class Has_Simple_Printer;
65 class Rtklib_Solver;
66 class rtklib_pvt_gs;
67 
68 using rtklib_pvt_gs_sptr = gnss_shared_ptr<rtklib_pvt_gs>;
69 
70 rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
71  const Pvt_Conf& conf_,
72  const rtk_t& rtk);
73 
74 /*!
75  * \brief This class implements a block that computes the PVT solution using the RTKLIB integrated library
76  */
77 class rtklib_pvt_gs : public gr::sync_block
78 {
79 public:
80  ~rtklib_pvt_gs(); //!< Default destructor
81 
82  /*!
83  * \brief Get latest set of GPS ephemeris from PVT block
84  */
85  std::map<int, Gps_Ephemeris> get_gps_ephemeris_map() const;
86 
87  /*!
88  * \brief Get latest set of GPS almanac from PVT block
89  */
90  std::map<int, Gps_Almanac> get_gps_almanac_map() const;
91 
92  /*!
93  * \brief Get latest set of Galileo ephemeris from PVT block
94  */
95  std::map<int, Galileo_Ephemeris> get_galileo_ephemeris_map() const;
96 
97  /*!
98  * \brief Get latest set of Galileo almanac from PVT block
99  */
100  std::map<int, Galileo_Almanac> get_galileo_almanac_map() const;
101 
102  /*!
103  * \brief Get latest set of BeiDou DNAV ephemeris from PVT block
104  */
105  std::map<int, Beidou_Dnav_Ephemeris> get_beidou_dnav_ephemeris_map() const;
106 
107  /*!
108  * \brief Get latest set of BeiDou DNAV almanac from PVT block
109  */
110  std::map<int, Beidou_Dnav_Almanac> get_beidou_dnav_almanac_map() const;
111 
112  /*!
113  * \brief Clear all ephemeris information and the almanacs for GPS and Galileo
114  */
115  void clear_ephemeris();
116 
117  /*!
118  * \brief Get the latest Position WGS84 [deg], Ground Velocity, Course over Ground, and UTC Time, if available
119  */
120  bool get_latest_PVT(double* longitude_deg,
121  double* latitude_deg,
122  double* height_m,
123  double* ground_speed_kmh,
124  double* course_over_ground_deg,
125  time_t* UTC_time) const;
126 
127  int work(int noutput_items, gr_vector_const_void_star& input_items,
128  gr_vector_void_star& output_items); //!< PVT Signal Processing
129 
130 private:
131  friend rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
132  const Pvt_Conf& conf_,
133  const rtk_t& rtk);
134 
135  rtklib_pvt_gs(uint32_t nchannels,
136  const Pvt_Conf& conf_,
137  const rtk_t& rtk);
138 
139  void log_source_timetag_info(double RX_time_ns, double TAG_time_ns);
140 
141  void msg_handler_telemetry(const pmt::pmt_t& msg);
142 
143  void msg_handler_has_data(const pmt::pmt_t& msg) const;
144 
145  void initialize_and_apply_carrier_phase_offset();
146 
147  void apply_rx_clock_offset(std::map<int, Gnss_Synchro>& observables_map,
148  double rx_clock_offset_s);
149 
150  std::map<int, Gnss_Synchro> interpolate_observables(const std::map<int, Gnss_Synchro>& observables_map_t0,
151  const std::map<int, Gnss_Synchro>& observables_map_t1,
152  double rx_time_s);
153 
154  inline std::time_t convert_to_time_t(const boost::posix_time::ptime pt) const
155  {
156  return (pt - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1))).total_seconds();
157  }
158 
159  std::vector<std::string> split_string(const std::string& s, char delim) const;
160 
161  typedef struct
162  {
163  long mtype; // NOLINT(google-runtime-int) required by SysV queue messaging
164  double ttff;
165  } d_ttff_msgbuf;
166  bool send_sys_v_ttff_msg(d_ttff_msgbuf ttff) const;
167 
168  bool save_gnss_synchro_map_xml(const std::string& file_name); // debug helper function
169  bool load_gnss_synchro_map_xml(const std::string& file_name); // debug helper function
170 
171  std::fstream d_log_timetag_file;
172 
173  std::shared_ptr<Rtklib_Solver> d_internal_pvt_solver;
174  std::shared_ptr<Rtklib_Solver> d_user_pvt_solver;
175 
176  std::unique_ptr<Rinex_Printer> d_rp;
177  std::unique_ptr<Kml_Printer> d_kml_dump;
178  std::unique_ptr<Gpx_Printer> d_gpx_dump;
179  std::unique_ptr<Nmea_Printer> d_nmea_printer;
180  std::unique_ptr<GeoJSON_Printer> d_geojson_printer;
181  std::unique_ptr<Rtcm_Printer> d_rtcm_printer;
182  std::unique_ptr<Monitor_Pvt_Udp_Sink> d_udp_sink_ptr;
183  std::unique_ptr<Monitor_Ephemeris_Udp_Sink> d_eph_udp_sink_ptr;
184  std::unique_ptr<Has_Simple_Printer> d_has_simple_printer;
185  std::unique_ptr<An_Packet_Printer> d_an_printer;
186 
187  std::chrono::time_point<std::chrono::system_clock> d_start;
188  std::chrono::time_point<std::chrono::system_clock> d_end;
189 
190  std::string d_dump_filename;
191  std::string d_xml_base_path;
192  std::string d_local_time_str;
193 
194  std::vector<bool> d_channel_initialized;
195  std::vector<double> d_initial_carrier_phase_offset_estimation_rads;
196 
197  enum StringValue_
198  {
199  evGPS_1C,
200  evGPS_2S,
201  evGPS_L5,
202  evSBAS_1C,
203  evGAL_1B,
204  evGAL_5X,
205  evGAL_E6,
206  evGAL_7X,
207  evGLO_1G,
208  evGLO_2G,
209  evBDS_B1,
210  evBDS_B2,
211  evBDS_B3
212  };
213  std::map<std::string, StringValue_> d_mapStringValues;
214  std::map<int, Gnss_Synchro> d_gnss_observables_map;
215  std::map<int, Gnss_Synchro> d_gnss_observables_map_t0;
216  std::map<int, Gnss_Synchro> d_gnss_observables_map_t1;
217 
218  std::queue<GnssTime> d_TimeChannelTagTimestamps;
219 
220  boost::posix_time::time_duration d_utc_diff_time;
221 
222  size_t d_gps_ephemeris_sptr_type_hash_code;
223  size_t d_gps_iono_sptr_type_hash_code;
224  size_t d_gps_utc_model_sptr_type_hash_code;
225  size_t d_gps_cnav_ephemeris_sptr_type_hash_code;
226  size_t d_gps_cnav_iono_sptr_type_hash_code;
227  size_t d_gps_cnav_utc_model_sptr_type_hash_code;
228  size_t d_gps_almanac_sptr_type_hash_code;
229  size_t d_galileo_ephemeris_sptr_type_hash_code;
230  size_t d_galileo_iono_sptr_type_hash_code;
231  size_t d_galileo_utc_model_sptr_type_hash_code;
232  size_t d_galileo_almanac_helper_sptr_type_hash_code;
233  size_t d_galileo_almanac_sptr_type_hash_code;
234  size_t d_glonass_gnav_ephemeris_sptr_type_hash_code;
235  size_t d_glonass_gnav_utc_model_sptr_type_hash_code;
236  size_t d_glonass_gnav_almanac_sptr_type_hash_code;
237  size_t d_beidou_dnav_ephemeris_sptr_type_hash_code;
238  size_t d_beidou_dnav_iono_sptr_type_hash_code;
239  size_t d_beidou_dnav_utc_model_sptr_type_hash_code;
240  size_t d_beidou_dnav_almanac_sptr_type_hash_code;
241  size_t d_galileo_has_data_sptr_type_hash_code;
242 
243  double d_rinex_version;
244  double d_rx_time;
245  uint64_t d_local_counter_ms;
246 
247  key_t d_sysv_msg_key;
248  int d_sysv_msqid;
249 
250  int32_t d_rinexobs_rate_ms;
251  int32_t d_rtcm_MT1045_rate_ms; // Galileo Broadcast Ephemeris
252  int32_t d_rtcm_MT1019_rate_ms; // GPS Broadcast Ephemeris (orbits)
253  int32_t d_rtcm_MT1020_rate_ms; // GLONASS Broadcast Ephemeris (orbits)
254  int32_t d_rtcm_MT1077_rate_ms; // The type 7 Multiple Signal Message format for the USA’s GPS system, popular
255  int32_t d_rtcm_MT1087_rate_ms; // GLONASS MSM7. The type 7 Multiple Signal Message format for the Russian GLONASS system
256  int32_t d_rtcm_MT1097_rate_ms; // Galileo MSM7. The type 7 Multiple Signal Message format for Europe’s Galileo system
257  int32_t d_rtcm_MSM_rate_ms;
258  int32_t d_kml_rate_ms;
259  int32_t d_gpx_rate_ms;
260  int32_t d_geojson_rate_ms;
261  int32_t d_nmea_rate_ms;
262  int32_t d_an_rate_ms;
263  int32_t d_output_rate_ms;
264  int32_t d_display_rate_ms;
265  int32_t d_report_rate_ms;
266  int32_t d_max_obs_block_rx_clock_offset_ms;
267 
268  uint32_t d_nchannels;
269  uint32_t d_type_of_rx;
270  uint32_t d_observable_interval_ms;
271 
272  bool d_dump;
273  bool d_dump_mat;
274  bool d_rinex_output_enabled;
275  bool d_geojson_output_enabled;
276  bool d_gpx_output_enabled;
277  bool d_kml_output_enabled;
278  bool d_nmea_output_file_enabled;
279  bool d_rtcm_enabled;
280  bool d_first_fix;
281  bool d_xml_storage;
282  bool d_flag_monitor_pvt_enabled;
283  bool d_flag_monitor_ephemeris_enabled;
284  bool d_show_local_time_zone;
285  bool d_waiting_obs_block_rx_clock_offset_correction_msg;
286  bool d_enable_rx_clock_correction;
287  bool d_enable_has_messages;
288  bool d_an_printer_enabled;
289  bool d_log_timetag;
290 };
291 
292 
293 /** \} */
294 /** \} */
295 #endif // GNSS_SDR_RTKLIB_PVT_GS_H
This class is a storage for the BeiDou D1 almanac.
class that stores both the receiver time, relative to the receiver start and the GNSS time (absolute)...
This class is a storage and orbital model functions for the GPS SV ephemeris data as described in IS-...
Definition: gps_ephemeris.h:40
bool get_latest_PVT(double *longitude_deg, double *latitude_deg, double *height_m, double *ground_speed_kmh, double *course_over_ground_deg, time_t *UTC_time) const
Get the latest Position WGS84 [deg], Ground Velocity, Course over Ground, and UTC Time...
Prints HAS messages content in a txt file. See HAS-SIS-ICD for a message description.
class that prints PVT solutions in a serial device following a custom version of the Advanced Navigat...
Class that handles the generation of Receiver INdependent EXchange format (RINEX) files...
Definition: rinex_printer.h:82
This class is a storage for the Galileo SV ALMANAC data.
This class provides a implementation of a subset of the RTCM Standard 10403.2 messages.
Definition: rtcm_printer.h:47
std::map< int, Galileo_Almanac > get_galileo_almanac_map() const
Get latest set of Galileo almanac from PVT block.
This class implements a block that computes the PVT solution using the RTKLIB integrated library...
Definition: rtklib_pvt_gs.h:77
This class implements a PVT solution based on RTKLIB.
Definition: rtklib_solver.h:75
This is a storage class for the Beidou SV ephemeris data as described in BeiDou Navigation Satellite ...
std::map< int, Beidou_Dnav_Almanac > get_beidou_dnav_almanac_map() const
Get latest set of BeiDou DNAV almanac from PVT block.
main header file for the rtklib library
This interface represents a GNSS block.
~rtklib_pvt_gs()
Default destructor.
This class provides a implementation of a subset of the NMEA-0183 standard for interfacing marine ele...
Definition: nmea_printer.h:44
std::map< int, Galileo_Ephemeris > get_galileo_ephemeris_map() const
Get latest set of Galileo ephemeris from PVT block.
Prints PVT solutions in GeoJSON format file.
This class is a storage and orbital model functions for the Galileo SV ephemeris data as described in...
std::map< int, Gps_Ephemeris > get_gps_ephemeris_map() const
Get latest set of GPS ephemeris from PVT block.
void clear_ephemeris()
Clear all ephemeris information and the almanacs for GPS and Galileo.
This class is a storage for the GPS SV ALMANAC data as described in IS-GPS-200M.
Definition: gps_almanac.h:35
Prints PVT information to GPX format file.
Definition: gpx_printer.h:39
Prints PVT information to OGC KML format file (can be viewed with Google Earth)
Definition: kml_printer.h:38
Definition: rtklib.h:1060
std::map< int, Beidou_Dnav_Ephemeris > get_beidou_dnav_ephemeris_map() const
Get latest set of BeiDou DNAV ephemeris from PVT block.
std::map< int, Gps_Almanac > get_gps_almanac_map() const
Get latest set of GPS almanac from PVT block.
Interface of the Gnss_Synchro class.
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
PVT Signal Processing.