GNSS-SDR  0.0.21
An Open Source GNSS Software Defined Receiver
galileo_inav_message.h
Go to the documentation of this file.
1 /*!
2  * \file galileo_inav_message.h
3  * \brief Implementation of a Galileo I/NAV Data message
4  * as described in Galileo OS SIS ICD Issue 2.0 (Jan. 2021)
5  * \author Mara Branzanti 2013. mara.branzanti(at)gmail.com
6  * \author Javier Arribas, 2013. jarribas(at)cttc.es
7  *
8  * -----------------------------------------------------------------------------
9  *
10  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
11  * This file is part of GNSS-SDR.
12  *
13  * Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
14  * SPDX-License-Identifier: GPL-3.0-or-later
15  *
16  * -----------------------------------------------------------------------------
17  */
18 
19 #ifndef GNSS_SDR_GALILEO_INAV_MESSAGE_H
20 #define GNSS_SDR_GALILEO_INAV_MESSAGE_H
21 
22 #include "Galileo_INAV.h"
23 #include "galileo_almanac_helper.h"
24 #include "galileo_ephemeris.h"
25 #include "galileo_iono.h"
26 #include "galileo_ism.h"
27 #include "galileo_utc_model.h"
28 #include "gnss_sdr_make_unique.h" // for std::unique_ptr in C++11
29 #include <array>
30 #include <bitset>
31 #include <cstdint>
32 #include <memory>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 class ReedSolomon; // Forward declaration of the ReedSolomon class
38 
39 /** \addtogroup Core
40  * \{ */
41 /** \addtogroup System_Parameters
42  * \{ */
43 /*!
44  * \brief This class fills the OSNMA_msg structure with the data received from the telemetry blocks.
45  */
46 class OSNMA_msg
47 {
48 public:
49  OSNMA_msg() = default;
50  std::array<uint32_t, 15> mack{};
51  std::array<uint8_t, 15> hkroot{};
52  uint32_t PRN{}; // PRN_a authentication data PRN
53  uint32_t WN_sf0{}; // Week number at the start of OSNMA subframe
54  uint32_t TOW_sf0{}; // TOW at the start of OSNMA subframe
55 };
56 
57 /*!
58  * \brief This class handles the Galileo I/NAV Data message, as described in the
59  * Galileo Open Service Signal in Space Interface Control Document (OS SIS ICD), Issue 2.0 (Jan. 2021).
60  * See https://www.gsc-europa.eu/sites/default/files/sites/all/files/Galileo_OS_SIS_ICD_v2.0.pdf
61  */
63 {
64 public:
66 
68 
69  /*
70  * \brief Takes in input a page (Odd or Even) of 120 bit, split it according ICD 4.3.2.3 and join Data_k with Data_j
71  */
72  void split_page(std::string page_string, int32_t flag_even_word);
73 
74  /*
75  * \brief Returns true if new Ephemeris has arrived. The flag is set to false when the function is executed
76  */
77  bool have_new_ephemeris();
78 
79  /*
80  * \brief Returns true if new Iono model has arrived. The flag is set to false when the function is executed
81  */
82  bool have_new_iono_and_GST();
83 
84  /*
85  * \brief Returns true if new UTC model has arrived. The flag is set to false when the function is executed
86  */
87  bool have_new_utc_model();
88 
89  /*
90  * \brief Returns true if new UTC model has arrived. The flag is set to false when the function is executed
91  */
92  bool have_new_almanac();
93 
94  /*
95  * \brief Returns true if new Reduced CED parameters have arrived. The flag is set to false when the function is executed
96  */
97  bool have_new_reduced_ced();
98 
99  /*
100  * \brief Returns true if new ISM data have arrived. The flag is set to false when the function is executed
101  */
102  bool have_new_ism();
103 
104  /*
105  * \brief Returns true if new NMA data have arrived. The flag is set to false when the function is executed
106  */
107  bool have_new_nma();
108 
109  /*
110  * \brief Returns a Galileo_Ephemeris object filled with the latest navigation data received
111  */
112  Galileo_Ephemeris get_ephemeris() const;
113 
114  /*
115  * \brief Returns a Galileo_Iono object filled with the latest navigation data received
116  */
117  Galileo_Iono get_iono() const;
118 
119  /*
120  * \brief Returns a Galileo_Utc_Model object filled with the latest navigation data received
121  */
122  Galileo_Utc_Model get_utc_model() const;
123 
124  /*
125  * \brief Returns a Galileo_Almanac_Helper object filled with the latest navigation data received
126  */
127  Galileo_Almanac_Helper get_almanac() const;
128 
129  /*
130  * \brief Returns a Galileo_Ephemeris object filled with the latest reduced CED received
131  */
132  Galileo_Ephemeris get_reduced_ced() const;
133 
134  /*
135  * \brief Returns a Galileo_ISMs object filled with the latest ISM data received
136  */
137  Galileo_ISM get_galileo_ism() const;
138 
139  /*
140  * \brief Returns an OSNMA_msg object filled with the latest NMA message received. Resets msg buffer.
141  */
142  OSNMA_msg get_osnma_msg();
143 
144  /*
145  * @brief Retrieves the OSNMA ADKD 4 NAV bits. Resets the string.
146  */
147  std::string get_osnma_adkd_4_nav_bits();
148 
149  /*
150  * @brief Resets the OSNMA ADKD 4 NAV bits.
151  */
152  void reset_osnma_nav_bits_adkd4();
153 
154  /*
155  * @brief Retrieves the OSNMA ADKD 0/12 NAV bits. Resets the string.
156  */
157  std::string get_osnma_adkd_0_12_nav_bits();
158 
159  /*
160  * @brief Resets the OSNMA ADKD 0/12 NAV bits.
161  */
162  void reset_osnma_nav_bits_adkd0_12();
163 
164  inline bool get_flag_CRC_test() const
165  {
166  return flag_CRC_test;
167  }
168 
169  inline bool get_flag_TOW_set() const
170  {
171  return flag_TOW_set;
172  }
173 
174  inline void set_flag_TOW_set(bool flag_tow)
175  {
176  flag_TOW_set = flag_tow;
177  }
178 
179  inline int32_t get_Galileo_week() const
180  {
181  return WN_0;
182  }
183 
184  inline int32_t get_TOW5() const
185  {
186  return TOW_5;
187  }
188 
189  inline int32_t get_TOW6() const
190  {
191  return TOW_6;
192  }
193 
194  inline bool is_TOW5_set() const
195  {
196  return flag_TOW_5;
197  }
198 
199  inline void set_TOW5_flag(bool flag_tow5)
200  {
201  flag_TOW_5 = flag_tow5;
202  }
203 
204  inline bool is_TOW6_set() const
205  {
206  return flag_TOW_6;
207  }
208 
209  inline void set_TOW6_flag(bool flag_tow6)
210  {
211  flag_TOW_6 = flag_tow6;
212  }
213 
214  inline int32_t get_TOW0() const
215  {
216  return TOW_0;
217  }
218 
219  inline bool is_TOW0_set() const
220  {
221  return flag_TOW_0;
222  }
223 
224  inline void set_TOW0_flag(bool flag_tow0)
225  {
226  flag_TOW_0 = flag_tow0;
227  }
228 
229  inline bool get_flag_GGTO() const
230  {
231  return (flag_GGTO_1 == true and flag_GGTO_2 == true and flag_GGTO_3 == true and flag_GGTO_4 == true);
232  }
233 
234  inline double get_A0G() const
235  {
236  return A_0G_10;
237  }
238 
239  inline double get_A1G() const
240  {
241  return A_1G_10;
242  }
243 
244  inline double get_t0G() const
245  {
246  return t_0G_10;
247  }
248 
249  inline double get_WN0G() const
250  {
251  return WN_0G_10;
252  }
253 
254  /*
255  * \brief Initialize PRN field so we do not need to wait for page 4.
256  */
257  inline void init_PRN(uint32_t prn)
258  {
259  SV_ID_PRN_4 = prn;
260  nma_msg.PRN = prn;
261  nma_msg.mack = std::array<uint32_t, 15>{};
262  nma_msg.hkroot = std::array<uint8_t, 15>{};
263  page_position_in_inav_subframe = 255;
264  nma_position_filled = std::array<int8_t, 15>{};
265  }
266 
267  /*
268  * \brief Enable Reed-Solomon in Galileo E1B
269  */
270  inline void enable_reed_solomon()
271  {
272  enable_rs = true;
273  }
274 
275 private:
276  bool CRC_test(const std::bitset<GALILEO_DATA_FRAME_BITS>& bits, uint32_t checksum) const;
277  bool read_navigation_bool(const std::bitset<GALILEO_DATA_JK_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
278  uint64_t read_navigation_unsigned(const std::bitset<GALILEO_DATA_JK_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
279  uint64_t read_page_type_unsigned(const std::bitset<GALILEO_PAGE_TYPE_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
280  int64_t read_navigation_signed(const std::bitset<GALILEO_DATA_JK_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
281  uint8_t read_octet_unsigned(const std::bitset<GALILEO_DATA_JK_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
282  void read_page_1(const std::bitset<GALILEO_DATA_JK_BITS>& data_bits);
283  void read_page_2(const std::bitset<GALILEO_DATA_JK_BITS>& data_bits);
284  void read_page_3(const std::bitset<GALILEO_DATA_JK_BITS>& data_bits);
285  void read_page_4(const std::bitset<GALILEO_DATA_JK_BITS>& data_bits);
286  std::bitset<GALILEO_DATA_JK_BITS> regenerate_page_1(const std::vector<uint8_t>& decoded) const;
287  std::bitset<GALILEO_DATA_JK_BITS> regenerate_page_2(const std::vector<uint8_t>& decoded) const;
288  std::bitset<GALILEO_DATA_JK_BITS> regenerate_page_3(const std::vector<uint8_t>& decoded) const;
289  std::bitset<GALILEO_DATA_JK_BITS> regenerate_page_4(const std::vector<uint8_t>& decoded) const;
290 
291  Galileo_ISM gal_ism{};
292  std::string page_Even{};
293 
294  std::vector<uint8_t> rs_buffer; // Reed-Solomon buffer
295  std::unique_ptr<ReedSolomon> rs; // The Reed-Solomon decoder
296  std::vector<int> inav_rs_pages; // Pages 1,2,3,4,17,18,19,20. Holds 1 if the page has arrived, 0 otherwise.
297 
298  int32_t page_jk_decoder(const char* data_jk);
299  int32_t IOD_ephemeris{};
300 
301  // Word type 1: Ephemeris (1/4)
302  int32_t IOD_nav_1{}; // IOD_nav page 1
303  int32_t t0e_1{}; // Ephemeris reference time [s]
304  double M0_1{}; // Mean anomaly at reference time [rad]
305  double e_1{}; // Eccentricity
306  double A_1{}; // Square root of the semi-major axis [meters^1/2]
307 
308  // Word type 2: Ephemeris (2/4)
309  int32_t IOD_nav_2{}; // IOD_nav page 2
310  double OMEGA_0_2{}; // Longitude of ascending node of orbital plane at weekly epoch [rad]
311  double i_0_2{}; // Inclination angle at reference time [rad]
312  double omega_2{}; // Argument of perigee [rad]
313  double iDot_2{}; // Rate of inclination angle [rad/sec]
314 
315  // Word type 3: Ephemeris (3/4) and SISA
316  int32_t IOD_nav_3{};
317  int32_t SISA_3{};
318  double OMEGA_dot_3{}; // Rate of right ascension [rad/sec]
319  double delta_n_3{}; // Mean motion difference from computed value [rad/sec]
320  double C_uc_3{}; // Amplitude of the cosine harmonic correction term to the argument of latitude [radians]
321  double C_us_3{}; // Amplitude of the sine harmonic correction term to the argument of latitude [radians]
322  double C_rc_3{}; // Amplitude of the cosine harmonic correction term to the orbit radius [meters]
323  double C_rs_3{}; // Amplitude of the sine harmonic correction term to the orbit radius [meters]
324 
325  // Word type 4: Ephemeris (4/4) and Clock correction parameters*/
326  int32_t IOD_nav_4{}; //
327  int32_t SV_ID_PRN_4{}; //
328  double C_ic_4{}; // Amplitude of the cosine harmonic correction term to the angle of inclination [radians]
329  double C_is_4{}; // Amplitude of the sine harmonic correction term to the angle of inclination [radians]
330 
331  // Clock correction parameters
332  int32_t t0c_4{}; // Clock correction data reference Time of Week [sec]
333  double af0_4{}; // SV clock bias correction coefficient [s]
334  double af1_4{}; // SV clock drift correction coefficient [s/s]
335  double af2_4{}; // clock drift rate correction coefficient [s/s^2]
336  double spare_4{};
337 
338  // Word type 5: Ionospheric correction, BGD, signal health and data validity status and GST*/
339  // Ionospheric correction
340  double ai0_5{}; // Effective Ionisation Level 1st order parameter [sfu]
341  double ai1_5{}; // Effective Ionisation Level 2st order parameter [sfu/degree]
342  double ai2_5{}; // Effective Ionisation Level 3st order parameter [sfu/degree]
343  double BGD_E1E5a_5{}; // E1-E5a Broadcast Group Delay [s]
344  double BGD_E1E5b_5{}; // E1-E5b Broadcast Group Delay [s]
345  int32_t E5b_HS_5{}; // E5b Signal Health Status
346  int32_t E1B_HS_5{}; // E1B Signal Health Status
347 
348  // Ionospheric disturbance flag
349  bool Region1_flag_5{}; // Ionospheric Disturbance Flag for region 1
350  bool Region2_flag_5{}; // Ionospheric Disturbance Flag for region 2
351  bool Region3_flag_5{}; // Ionospheric Disturbance Flag for region 3
352  bool Region4_flag_5{}; // Ionospheric Disturbance Flag for region 4
353  bool Region5_flag_5{}; // Ionospheric Disturbance Flag for region 5
354  bool E5b_DVS_5{}; // E5b Data Validity Status
355  bool E1B_DVS_5{}; // E1B Data Validity Status
356 
357  // GST
358  int32_t WN_5{};
359  int32_t TOW_5{};
360  double spare_5{};
361 
362  // Word type 6: GST-UTC conversion parameters
363  double A0_6{};
364  double A1_6{};
365  int32_t Delta_tLS_6{};
366  int32_t t0t_6{};
367  int32_t WNot_6{};
368  int32_t WN_LSF_6{};
369  int32_t DN_6{};
370  int32_t Delta_tLSF_6{};
371  int32_t TOW_6{};
372 
373  // Word type 7: Almanac for SVID1 (1/2), almanac reference time and almanac reference week number
374  int32_t IOD_a_7{};
375  int32_t WN_a_7{};
376  int32_t t0a_7{};
377  int32_t SVID1_7{};
378  double DELTA_A_7{};
379  double e_7{};
380  double omega_7{};
381  double delta_i_7{};
382  double Omega0_7{};
383  double Omega_dot_7{};
384  double M0_7{};
385 
386  // Word type 8: Almanac for SVID1 (2/2) and SVID2 (1/2)
387  int32_t IOD_a_8{};
388  int32_t E5b_HS_8{};
389  int32_t E1B_HS_8{};
390  int32_t SVID2_8{};
391  double af0_8{};
392  double af1_8{};
393  double DELTA_A_8{};
394  double e_8{};
395  double omega_8{};
396  double delta_i_8{};
397  double Omega0_8{};
398  double Omega_dot_8{};
399 
400  // Word type 9: Almanac for SVID2 (2/2) and SVID3 (1/2)
401  int32_t IOD_a_9{};
402  int32_t WN_a_9{};
403  int32_t t0a_9{};
404  double M0_9{};
405  double af0_9{};
406  double af1_9{};
407  int32_t E5b_HS_9{};
408  int32_t E1B_HS_9{};
409  int32_t SVID3_9{};
410  double DELTA_A_9{};
411  double e_9{};
412  double omega_9{};
413  double delta_i_9{};
414 
415  // Word type 10: Almanac for SVID3 (2/2) and GST-GPS conversion parameters
416  int32_t IOD_a_10{};
417  double Omega0_10{};
418  double Omega_dot_10{};
419  double M0_10{};
420  double af0_10{};
421  double af1_10{};
422  int32_t E5b_HS_10{};
423  int32_t E1B_HS_10{};
424 
425  // GST-GPS conversion
426  double A_0G_10{}; // Constant term of the offset Delta t systems
427  double A_1G_10{}; // Rate of change of the offset Delta t systems
428  int32_t t_0G_10{}; // Reference time for Galileo/GPS Time Offset (GGTO) data
429  int32_t WN_0G_10{}; // Week Number of Galileo/GPS Time Offset (GGTO) reference
430 
431  // Word type 0: I/NAV Spare Word
432  int32_t Time_0{};
433  int32_t WN_0{};
434  int32_t TOW_0{};
435 
436  // Word type 16: Reduced Clock and Ephemeris Data (CED) parameters
437  double ced_DeltaAred{};
438  double ced_exred{};
439  double ced_eyred{};
440  double ced_Deltai0red{};
441  double ced_Omega0red{};
442  double ced_lambda0red{};
443  double ced_af0red{};
444  double ced_af1red{};
445 
446  double Galileo_satClkDrift{};
447 
448  int32_t current_IODnav{};
449 
450  // OSNMA
451  uint32_t mack_sis{};
452  uint8_t hkroot_sis{};
453  uint8_t page_position_in_inav_subframe{255};
454  std::array<int8_t, 15> nma_position_filled{};
455  OSNMA_msg nma_msg{};
456  std::string nav_bits_adkd_4{};
457  std::string nav_bits_word_6{};
458  std::string nav_bits_word_10{};
459  std::string nav_bits_adkd_0_12{};
460  std::string nav_bits_word_1{};
461  std::string nav_bits_word_2{};
462  std::string nav_bits_word_3{};
463  std::string nav_bits_word_4{};
464  std::string nav_bits_word_5{};
465 
466  uint8_t IODnav_LSB17{};
467  uint8_t IODnav_LSB18{};
468  uint8_t IODnav_LSB19{};
469  uint8_t IODnav_LSB20{};
470 
471  uint8_t ism_constellation_id{};
472  uint8_t ism_service_level_id{};
473 
474  bool flag_CRC_test{};
475  bool flag_all_ephemeris{}; // Flag indicating that all words containing ephemeris have been received
476  bool flag_ephemeris_1{}; // Flag indicating that ephemeris 1/4 (word 1) have been received
477  bool flag_ephemeris_2{}; // Flag indicating that ephemeris 2/4 (word 2) have been received
478  bool flag_ephemeris_3{}; // Flag indicating that ephemeris 3/4 (word 3) have been received
479  bool flag_ephemeris_4{}; // Flag indicating that ephemeris 4/4 (word 4) have been received
480 
481  bool flag_iono_and_GST{}; // Flag indicating that ionospheric and GST parameters (word 5) have been received
482  bool flag_TOW_5{};
483  bool flag_TOW_6{};
484  bool flag_TOW_0{};
485  bool flag_TOW_set{}; // it is true when page 5 or page 6 arrives
486  bool flag_utc_model{}; // Flag indicating that utc model parameters (word 6) have been received
487 
488  bool flag_all_almanac{}; // Flag indicating that all Almanac data have been received
489  bool flag_almanac_1{}; // Flag indicating that almanac 1/4 (word 7) have been received
490  bool flag_almanac_2{}; // Flag indicating that almanac 2/4 (word 8) have been received
491  bool flag_almanac_3{}; // Flag indicating that almanac 3/4 (word 9) have been received
492  bool flag_almanac_4{}; // Flag indicating that almanac 4/4 (word 10) have been received
493 
494  bool flag_GGTO_1{};
495  bool flag_GGTO_2{};
496  bool flag_GGTO_3{};
497  bool flag_GGTO_4{};
498 
499  bool flag_CED{};
500  bool enable_rs{};
501  bool have_ISM{};
502 };
503 
504 
505 /** \} */
506 /** \} */
507 #endif // GNSS_SDR_GALILEO_INAV_MESSAGE_H
Class implementing a Reed-Solomon encoder and decoder RS(255,K,d) where k=255-nroots is the informati...
Definition: reed_solomon.h:40
This class fills the OSNMA_msg structure with the data received from the telemetry blocks...
This file implements std::make_unique for C++11.
This class is a storage for the GALILEO ALMANAC data as described in GALILEO ICD. ...
Interface of a Galileo Integrity Support Message.
This class handles the Galileo I/NAV Data message, as described in the Galileo Open Service Signal in...
This class is a storage for the GALILEO IONOSPHERIC data as described in Galileo ICD paragraph 5...
Definition: galileo_iono.h:37
Interface of a Galileo UTC MODEL storage.
Interface of a Galileo ALMANAC storage helper.
This class is a storage and orbital model functions for the Galileo SV ephemeris data as described in...
This class is a storage for the GALILEO UTC MODEL data as described in Galileo ICD https://www...
This class is a storage for the GALILEO Integrity Support Message as described in Galileo ICD paragra...
Definition: galileo_ism.h:40
Interface of a Galileo Ionospheric Model storage.
Interface of a Galileo EPHEMERIS storage.
Galileo INAV message constants.