GNU Radio's LORA_SDR Package
fft_demod_impl.h
Go to the documentation of this file.
1 
2 #ifndef INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H
3 #define INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H
4 // #define GRLORA_DEBUG
5 // #define GRLORA_MEASUREMENTS
6 //#define GRLORA_SNR_MEASUREMENTS_SAVE
7 //#define GRLORA_BESSEL_MEASUREMENTS_SAVE
8 //#define GRLORA_LLR_MEASUREMENTS_SAVE
9 
10 #include <lora_sdr/fft_demod.h>
11 #include <iostream>
12 #include <fstream>
13 #include <volk/volk.h>
14 #include <gnuradio/io_signature.h>
15 #include <lora_sdr/utilities.h>
16 #include <lora_sdr/fft_demod.h>
17 #include<lora_sdr/utilities.h>
18 
19 namespace gr {
20  namespace lora_sdr {
21 
22  class fft_demod_impl : public fft_demod
23  {
24  private:
25  uint8_t m_sf; ///< Spreading factor
26  uint8_t m_cr; ///< Coding rate
27  bool m_soft_decoding; ///< Hard/Soft decoding
28  bool max_log_approx; ///< use Max-log approximation in LLR formula
29  bool m_new_frame; ///< To be notify when receive a new frame to estimate SNR
30 
31  uint32_t m_samples_per_symbol; ///< Number of samples received per lora symbols
32  int CFOint; ///< integer part of the CFO
33 
34  // variable used to perform the FFT demodulation
35  std::vector<gr_complex> m_upchirp; ///< Reference upchirp
36  std::vector<gr_complex> m_downchirp; ///< Reference downchirp
37  std::vector<gr_complex> m_dechirped; ///< Dechirped symbol
38  std::vector<gr_complex> m_fft; ///< Result of the FFT
39 
40  std::vector<uint32_t> output; ///< Stores the value to be outputted once a full bloc has been received
41  std::vector< std::vector<LLR> > LLRs_block; ///< Stores the LLRs to be outputted once a full bloc has been received
42  bool is_header; ///< Indicate that the first block hasn't been fully received
43  uint8_t block_size; ///< The number of lora symbol in one block
44 
45  #ifdef GRLORA_MEASUREMENTS
46  std::ofstream energy_file;
47  #endif
48  #ifdef GRLORA_DEBUG
49  std::ofstream idx_file;
50  #endif
51  #ifdef GRLORA_SNR_MEASUREMENTS_SAVE
52  std::ofstream SNRestim_file;
53  #endif
54  #ifdef GRLORA_BESSEL_MEASUREMENTS_SAVE
55  std::ofstream bessel_file;
56  #endif
57 
58  /**
59  * \brief Recover the lora symbol value using argmax of the dechirped symbol FFT.
60  *
61  * \param samples
62  * The pointer to the symbol beginning.
63  */
64  int32_t get_symbol_val(const gr_complex *samples);
65 
66  /**
67  * \brief Reset the block variables when a new lora packet needs to be decoded.
68  */
69  void new_frame_handler(int cfo_int);
70 
71  /**
72  * \brief Handles the reception of the coding rate received by the header_decoder block.
73  */
74  void header_cr_handler(pmt::pmt_t cr);
75 
76  /**
77  * \brief Compute the FFT and fill the class attributes
78  */
79  float* compute_fft_mag(const gr_complex *samples);
80 
81  /**
82  * \brief Compute the Log-Likelihood Ratios of the SF nbr of bits
83  */
84  std::vector<LLR> get_LLRs(const gr_complex *samples);
85 
86  public:
87  fft_demod_impl( uint8_t sf, bool impl_head, bool soft_decoding, bool max_log_approx);
89 
90  // Where all the action really happens
91  void forecast (int noutput_items, gr_vector_int &ninput_items_required);
92 
93  int general_work(int noutput_items,
94  gr_vector_int &ninput_items,
95  gr_vector_const_void_star &input_items,
96  gr_vector_void_star &output_items);
97  };
98 
99  } // namespace lora_sdr
100 } // namespace gr
101 
102 #endif /* INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H */
<+description of block+>
Definition: fft_demod.h:36
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
Definition: add_crc.h:28
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
fft_demod_impl(uint8_t sf, bool impl_head, bool soft_decoding, bool max_log_approx)
Definition: fft_demod_impl.h:22