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
7#include <fstream>
8#include <gnuradio/io_signature.h>
9#include <iostream>
10#include <lora_sdr/fft_demod.h>
11#include "helpers.h"
12#include <volk/volk.h>
13namespace gr {
14namespace lora_sdr {
15
16class fft_demod_impl : public fft_demod {
17private:
18 /**
19 * @brief Bandwidth
20 *
21 */
22 uint32_t m_bw;
23
24 /**
25 * @brief Sampling rate
26 *
27 */
28 uint32_t m_samp_rate;
29
30 /**
31 * @brief Spreading factor
32 *
33 */
34 uint8_t m_sf;
35
36 /**
37 * @brief Coding rate
38 *
39 */
40 uint8_t m_cr;
41
42 uint32_t m_number_of_bins; ///< Number of bins in each lora Symbol
43 uint32_t
44 m_samples_per_symbol; ///< Number of samples received per lora symbols
45 int CFOint; ///< integer part of the CFO
46
47 // variables used to perform the FFT demodulation
48 /**
49 * @brief Reference upchirp
50 *
51 */
52 std::vector<gr_complex> m_upchirp;
53
54 /**
55 * @brief Reference downchirp
56 *
57 */
58 std::vector<gr_complex> m_downchirp;
59 /**
60 * @brief Dechirped symbol
61 *
62 */
63 std::vector<gr_complex> m_dechirped;
64
65 /**
66 * @brief Result of the FFT
67 *
68 */
69 std::vector<gr_complex> m_fft;
70
71 /**
72 * @brief Stores the value to be outputted once a
73 full bloc has been received
74 *
75 */
76 std::vector<uint32_t> output;
77
78 /**
79 * @brief Indicate that the first block hasn't been fully received
80 *
81 */
82 bool is_header;
83
84 /**
85 * @brief The number of lora symbol in one block
86 *
87 */
88 uint8_t block_size;
89
90#ifdef GRLORA_MEASUREMENTS
91 std::ofstream energy_file;
92#endif
93#ifdef GRLORA_DEBUG
94 std::ofstream idx_file;
95#endif
96
97 /**
98 * @brief Recover the lora symbol value using argmax of the dechirped symbol
99 * FFT.
100 *
101 * @param samples The pointer to the symbol beginning.
102 * @return int32_t
103 */
104 int32_t get_symbol_val(const gr_complex *samples);
105
106 /**
107 * @brief Reset the block variables when a new lora packet needs to be
108 * decoded.
109 *
110 * @param id
111 */
112 void new_frame_handler(int cfo_int);
113
114 /**
115 * @brief Handles the reception of the coding rate received by the
116 * header_decoder block.
117 *
118 * @param cr
119 */
120 void header_cr_handler(pmt::pmt_t cr);
121
122public:
123 /**
124 * @brief Construct a new fft demod impl object
125 *
126 * @param samp_rate : sampling rate
127 * @param bandwidth : bandwith
128 * @param sf : spreading factor
129 * @param impl_head : impl_head mode
130 */
131 fft_demod_impl(float samp_rate, uint32_t bandwidth, uint8_t sf,
132 bool impl_head);
133
134 /**
135 * @brief Destroy the fft demod impl object
136 *
137 */
139
140 /**
141 * @brief Standard gnuradio function to tell the system how many input and
142 * output items are needed.
143 *
144 * @param noutput_items : number of output items
145 * @param ninput_items_required : number of output items required
146 */
147 void forecast(int noutput_items, gr_vector_int &ninput_items_required);
148
149 /**
150 * @brief Main function where the actual computation is done
151 *
152 * @param noutput_items : number of output items to produce
153 * @param ninput_items : number of input items
154 * @param input_items : input item (i.e. output of the frame sync stage)
155 * @param output_items : output data
156 * @return int
157 */
158 int general_work(int noutput_items, gr_vector_int &ninput_items,
159 gr_vector_const_void_star &input_items,
160 gr_vector_void_star &output_items);
161};
162
163} // namespace lora_sdr
164} // namespace gr
165
166#endif /* INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H */
Definition: fft_demod_impl.h:16
fft_demod_impl(float samp_rate, uint32_t bandwidth, uint8_t sf, bool impl_head)
Construct a new fft demod impl object.
~fft_demod_impl()
Destroy the fft demod impl object.
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
Standard gnuradio function to tell the system how many input and output items are needed.
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Main function where the actual computation is done.
FFT demodulation block ,for more information about the implementation visit fft_demod_impl.
Definition: fft_demod.h:37
Definition: add_crc.h:28