GNSS-SDR  0.0.19
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 Galileo_HAS_data;
53 class Geohash;
54 class GeoJSON_Printer;
55 class Gps_Almanac;
56 class Gps_Ephemeris;
57 class Gpx_Printer;
58 class Kml_Printer;
61 class Nmea_Printer;
62 class Pvt_Conf;
63 class Rinex_Printer;
64 class Rtcm_Printer;
65 class An_Packet_Printer;
66 class Has_Simple_Printer;
67 class Rtklib_Solver;
68 class rtklib_pvt_gs;
69 
70 using rtklib_pvt_gs_sptr = gnss_shared_ptr<rtklib_pvt_gs>;
71 
72 rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
73  const Pvt_Conf& conf_,
74  const rtk_t& rtk);
75 
76 /*!
77  * \brief This class implements a block that computes the PVT solution using the RTKLIB integrated library
78  */
79 class rtklib_pvt_gs : public gr::sync_block
80 {
81 public:
82  ~rtklib_pvt_gs(); //!< Default destructor
83 
84  /*!
85  * \brief Get latest set of GPS ephemeris from PVT block
86  */
87  std::map<int, Gps_Ephemeris> get_gps_ephemeris_map() const;
88 
89  /*!
90  * \brief Get latest set of GPS almanac from PVT block
91  */
92  std::map<int, Gps_Almanac> get_gps_almanac_map() const;
93 
94  /*!
95  * \brief Get latest set of Galileo ephemeris from PVT block
96  */
97  std::map<int, Galileo_Ephemeris> get_galileo_ephemeris_map() const;
98 
99  /*!
100  * \brief Get latest set of Galileo almanac from PVT block
101  */
102  std::map<int, Galileo_Almanac> get_galileo_almanac_map() const;
103 
104  /*!
105  * \brief Get latest set of BeiDou DNAV ephemeris from PVT block
106  */
107  std::map<int, Beidou_Dnav_Ephemeris> get_beidou_dnav_ephemeris_map() const;
108 
109  /*!
110  * \brief Get latest set of BeiDou DNAV almanac from PVT block
111  */
112  std::map<int, Beidou_Dnav_Almanac> get_beidou_dnav_almanac_map() const;
113 
114  /*!
115  * \brief Clear all ephemeris information and the almanacs for GPS and Galileo
116  */
117  void clear_ephemeris();
118 
119  /*!
120  * \brief Get the latest Position WGS84 [deg], Ground Velocity, Course over Ground, and UTC Time, if available
121  */
122  bool get_latest_PVT(double* longitude_deg,
123  double* latitude_deg,
124  double* height_m,
125  double* ground_speed_kmh,
126  double* course_over_ground_deg,
127  time_t* UTC_time) const;
128 
129  int work(int noutput_items, gr_vector_const_void_star& input_items,
130  gr_vector_void_star& output_items); //!< PVT Signal Processing
131 
132 private:
133  friend rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
134  const Pvt_Conf& conf_,
135  const rtk_t& rtk);
136 
137  rtklib_pvt_gs(uint32_t nchannels,
138  const Pvt_Conf& conf_,
139  const rtk_t& rtk);
140 
141  void log_source_timetag_info(double RX_time_ns, double TAG_time_ns);
142 
143  void msg_handler_telemetry(const pmt::pmt_t& msg);
144 
145  void msg_handler_has_data(const pmt::pmt_t& msg);
146 
147  void initialize_and_apply_carrier_phase_offset();
148 
149  void apply_rx_clock_offset(std::map<int, Gnss_Synchro>& observables_map,
150  double rx_clock_offset_s);
151 
152  void update_HAS_corrections();
153 
154  std::map<int, Gnss_Synchro> interpolate_observables(const std::map<int, Gnss_Synchro>& observables_map_t0,
155  const std::map<int, Gnss_Synchro>& observables_map_t1,
156  double rx_time_s);
157 
158  inline std::time_t convert_to_time_t(const boost::posix_time::ptime pt) const
159  {
160  return (pt - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1))).total_seconds();
161  }
162 
163  std::vector<std::string> split_string(const std::string& s, char delim) const;
164 
165  typedef struct
166  {
167  long mtype; // NOLINT(google-runtime-int)
168  double ttff;
169  } d_ttff_msgbuf;
170  bool send_sys_v_ttff_msg(d_ttff_msgbuf ttff) const;
171 
172  bool save_gnss_synchro_map_xml(const std::string& file_name); // debug helper function
173  bool load_gnss_synchro_map_xml(const std::string& file_name); // debug helper function
174 
175  std::fstream d_log_timetag_file;
176 
177  std::shared_ptr<Rtklib_Solver> d_internal_pvt_solver;
178  std::shared_ptr<Rtklib_Solver> d_user_pvt_solver;
179 
180  std::unique_ptr<Rinex_Printer> d_rp;
181  std::unique_ptr<Kml_Printer> d_kml_dump;
182  std::unique_ptr<Gpx_Printer> d_gpx_dump;
183  std::unique_ptr<Nmea_Printer> d_nmea_printer;
184  std::unique_ptr<GeoJSON_Printer> d_geojson_printer;
185  std::unique_ptr<Rtcm_Printer> d_rtcm_printer;
186  std::unique_ptr<Monitor_Pvt_Udp_Sink> d_udp_sink_ptr;
187  std::unique_ptr<Monitor_Ephemeris_Udp_Sink> d_eph_udp_sink_ptr;
188  std::unique_ptr<Has_Simple_Printer> d_has_simple_printer;
189  std::unique_ptr<An_Packet_Printer> d_an_printer;
190 
191  std::chrono::time_point<std::chrono::system_clock> d_start;
192  std::chrono::time_point<std::chrono::system_clock> d_end;
193 
194  std::string d_dump_filename;
195  std::string d_xml_base_path;
196  std::string d_local_time_str;
197 
198  std::vector<bool> d_channel_initialized;
199  std::vector<double> d_initial_carrier_phase_offset_estimation_rads;
200 
201  std::map<int, Gnss_Synchro> d_gnss_observables_map;
202  std::map<int, Gnss_Synchro> d_gnss_observables_map_t0;
203  std::map<int, Gnss_Synchro> d_gnss_observables_map_t1;
204 
205  std::queue<GnssTime> d_TimeChannelTagTimestamps;
206 
207  boost::posix_time::time_duration d_utc_diff_time;
208  std::unique_ptr<Geohash> d_geohash;
209 
210  size_t d_gps_ephemeris_sptr_type_hash_code;
211  size_t d_gps_iono_sptr_type_hash_code;
212  size_t d_gps_utc_model_sptr_type_hash_code;
213  size_t d_gps_cnav_ephemeris_sptr_type_hash_code;
214  size_t d_gps_cnav_iono_sptr_type_hash_code;
215  size_t d_gps_cnav_utc_model_sptr_type_hash_code;
216  size_t d_gps_almanac_sptr_type_hash_code;
217  size_t d_galileo_ephemeris_sptr_type_hash_code;
218  size_t d_galileo_iono_sptr_type_hash_code;
219  size_t d_galileo_utc_model_sptr_type_hash_code;
220  size_t d_galileo_almanac_helper_sptr_type_hash_code;
221  size_t d_galileo_almanac_sptr_type_hash_code;
222  size_t d_glonass_gnav_ephemeris_sptr_type_hash_code;
223  size_t d_glonass_gnav_utc_model_sptr_type_hash_code;
224  size_t d_glonass_gnav_almanac_sptr_type_hash_code;
225  size_t d_beidou_dnav_ephemeris_sptr_type_hash_code;
226  size_t d_beidou_dnav_iono_sptr_type_hash_code;
227  size_t d_beidou_dnav_utc_model_sptr_type_hash_code;
228  size_t d_beidou_dnav_almanac_sptr_type_hash_code;
229  size_t d_galileo_has_data_sptr_type_hash_code;
230 
231  double d_rinex_version;
232  double d_rx_time;
233  uint64_t d_local_counter_ms;
234  uint64_t d_timestamp_rx_clock_offset_correction_msg_ms;
235 
236  key_t d_sysv_msg_key;
237  int d_sysv_msqid;
238 
239  int32_t d_rinexobs_rate_ms;
240  int32_t d_rtcm_MT1045_rate_ms; // Galileo Broadcast Ephemeris
241  int32_t d_rtcm_MT1019_rate_ms; // GPS Broadcast Ephemeris (orbits)
242  int32_t d_rtcm_MT1020_rate_ms; // GLONASS Broadcast Ephemeris (orbits)
243  int32_t d_rtcm_MT1077_rate_ms; // The type 7 Multiple Signal Message format for the USA’s GPS system, popular
244  int32_t d_rtcm_MT1087_rate_ms; // GLONASS MSM7. The type 7 Multiple Signal Message format for the Russian GLONASS system
245  int32_t d_rtcm_MT1097_rate_ms; // Galileo MSM7. The type 7 Multiple Signal Message format for Europe’s Galileo system
246  int32_t d_rtcm_MSM_rate_ms;
247  int32_t d_kml_rate_ms;
248  int32_t d_gpx_rate_ms;
249  int32_t d_geojson_rate_ms;
250  int32_t d_nmea_rate_ms;
251  int32_t d_an_rate_ms;
252  int32_t d_output_rate_ms;
253  int32_t d_display_rate_ms;
254  int32_t d_report_rate_ms;
255  int32_t d_max_obs_block_rx_clock_offset_ms;
256 
257  uint32_t d_nchannels;
258  uint32_t d_type_of_rx;
259  uint32_t d_observable_interval_ms;
260  uint32_t d_pvt_errors_counter;
261 
262  bool d_dump;
263  bool d_dump_mat;
264  bool d_rinex_output_enabled;
265  bool d_geojson_output_enabled;
266  bool d_gpx_output_enabled;
267  bool d_kml_output_enabled;
268  bool d_nmea_output_file_enabled;
269  bool d_rtcm_enabled;
270  bool d_first_fix;
271  bool d_xml_storage;
272  bool d_flag_monitor_pvt_enabled;
273  bool d_flag_monitor_ephemeris_enabled;
274  bool d_show_local_time_zone;
275  bool d_enable_rx_clock_correction;
276  bool d_enable_has_messages;
277  bool d_an_printer_enabled;
278  bool d_log_timetag;
279  bool d_use_has_corrections;
280  bool d_use_unhealthy_sats;
281 };
282 
283 
284 /** \} */
285 /** \} */
286 #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:83
This class is a storage for Galileo HAS message type 1, as defined in Galileo High Accuracy Service S...
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:48
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:79
This class implements a PVT solution based on RTKLIB.
Definition: rtklib_solver.h:81
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.
Class for geohash encoding / decoding See https://en.wikipedia.org/wiki/Geohash.
Definition: geohash.h:34
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:1066
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.