GNSS-SDR  0.0.19
An Open Source GNSS Software Defined Receiver
sbas_l1_telemetry_decoder_gs.h
Go to the documentation of this file.
1 /*!
2  * \file sbas_l1_telemetry_decoder_gs.h
3  * \brief Interface of a SBAS telemetry data decoder block
4  * \author Daniel Fehr 2013. daniel.co(at)bluewin.ch
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_SBAS_L1_TELEMETRY_DECODER_GS_H
18 #define GNSS_SDR_SBAS_L1_TELEMETRY_DECODER_GS_H
19 
20 #include "gnss_block_interface.h"
21 #include "gnss_satellite.h"
22 #include <boost/crc.hpp> // for crc_optimal
23 #include <gnuradio/block.h>
24 #include <gnuradio/types.h> // for gr_vector_const_void_star
25 #include <cstddef> // for size_t
26 #include <cstdint>
27 #include <deque>
28 #include <fstream>
29 #include <memory> // for std::shared_ptr
30 #include <string>
31 #include <utility> // for pair
32 #include <vector>
33 
34 /** \addtogroup Telemetry_Decoder
35  * \{ */
36 /** \addtogroup Telemetry_Decoder_gnuradio_blocks
37  * \{ */
38 
39 
41 
43 
44 using sbas_l1_telemetry_decoder_gs_sptr = gnss_shared_ptr<sbas_l1_telemetry_decoder_gs>;
45 
46 sbas_l1_telemetry_decoder_gs_sptr sbas_l1_make_telemetry_decoder_gs(
47  const Gnss_Satellite &satellite,
48  bool dump);
49 
50 /*!
51  * \brief This class implements a block that decodes the SBAS integrity and
52  * corrections data defined in RTCA MOPS DO-229
53  */
54 class sbas_l1_telemetry_decoder_gs : public gr::block
55 {
56 public:
57  ~sbas_l1_telemetry_decoder_gs() override;
58  void set_satellite(const Gnss_Satellite &satellite); //!< Set satellite PRN
59  void set_channel(int32_t channel); //!< Set receiver's channel
60  inline void reset(){};
61 
62  /*!
63  * \brief This is where all signal processing takes place
64  */
65  int general_work(int noutput_items, gr_vector_int &ninput_items,
66  gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override;
67 
68 private:
69  friend sbas_l1_telemetry_decoder_gs_sptr sbas_l1_make_telemetry_decoder_gs(
70  const Gnss_Satellite &satellite,
71  bool dump);
72 
73  sbas_l1_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
74 
75  void viterbi_decoder(double *page_part_symbols, int32_t *page_part_bits);
76  void align_samples();
77 
78  static const int32_t D_SAMPLES_PER_SYMBOL = 2;
79  static const int32_t D_SYMBOLS_PER_BIT = 2;
80  static const int32_t D_BLOCK_SIZE_IN_BITS = 30;
81 
82  bool d_dump;
83  Gnss_Satellite d_satellite;
84  int32_t d_channel;
85 
86  std::string d_dump_filename;
87  std::ofstream d_dump_file;
88 
89  size_t d_block_size; //!< number of samples which are processed during one invocation of the algorithms
90  std::vector<double> d_sample_buf; //!< input buffer holding the samples to be processed in one block
91 
92  typedef std::pair<int32_t, std::vector<int32_t>> msg_candiate_int_t;
93  typedef std::pair<int32_t, std::vector<uint8_t>> msg_candiate_char_t;
94 
95  // helper class for sample alignment
96  class Sample_Aligner
97  {
98  public:
99  Sample_Aligner();
100  void reset();
101  /*
102  * samples length must be a multiple of two
103  * for block operation
104  */
105  bool get_symbols(const std::vector<double> &samples, std::vector<double> &symbols);
106 
107  private:
108  int32_t d_n_smpls_in_history{3};
109  double d_iir_par{0.05};
110  double d_corr_paired{};
111  double d_corr_shifted{};
112  bool d_aligned{};
113  double d_past_sample{};
114  } d_sample_aligner;
115 
116  // helper class for symbol alignment and Viterbi decoding
117  class Symbol_Aligner_And_Decoder
118  {
119  public:
120  Symbol_Aligner_And_Decoder();
121  void reset();
122  bool get_bits(const std::vector<double> &symbols, std::vector<int32_t> &bits);
123 
124  private:
125  int32_t d_KK{7};
126  std::shared_ptr<Viterbi_Decoder_Sbas> d_vd1;
127  std::shared_ptr<Viterbi_Decoder_Sbas> d_vd2;
128  double d_past_symbol{0};
129  } d_symbol_aligner_and_decoder;
130 
131 
132  // helper class for detecting the preamble and collect the corresponding message candidates
133  class Frame_Detector
134  {
135  public:
136  void reset();
137  void get_frame_candidates(const std::vector<int32_t> &bits, std::vector<std::pair<int32_t, std::vector<int32_t>>> &msg_candidates);
138 
139  private:
140  std::deque<int32_t> d_buffer;
141  } d_frame_detector;
142 
143 
144  // helper class for checking the CRC of the message candidates
145  class Crc_Verifier
146  {
147  public:
148  void reset();
149  void get_valid_frames(const std::vector<msg_candiate_int_t> &msg_candidates, std::vector<msg_candiate_char_t> &valid_msgs);
150 
151  private:
152  typedef boost::crc_optimal<24, 0x1864CFBU, 0x0, 0x0, false, false> crc_24_q_type;
153  crc_24_q_type d_checksum_agent;
154  void zerropad_front_and_convert_to_bytes(const std::vector<int32_t> &msg_candidate, std::vector<uint8_t> &bytes);
155  void zerropad_back_and_convert_to_bytes(const std::vector<int32_t> &msg_candidate, std::vector<uint8_t> &bytes);
156  } d_crc_verifier;
157 };
158 
159 
160 /** \} */
161 /** \} */
162 #endif // GNSS_SDR_SBAS_L1_TELEMETRY_DECODER_GS_H
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
This is where all signal processing takes place.
Class that implements a Viterbi decoder.
void set_satellite(const Gnss_Satellite &satellite)
Set satellite PRN.
This interface represents a GNSS block.
Interface of the Gnss_Satellite class.
This class represents a GNSS satellite.
This class implements a block that decodes the SBAS integrity and corrections data defined in RTCA MO...
void set_channel(int32_t channel)
Set receiver&#39;s channel.