GNU Radio's LORA_SDR Package
frame_detector_sequence_impl.h
Go to the documentation of this file.
1 /**
2  * @file frame_detector_sequence_impl.h
3  * @author Martyn van Dijke (martijnvdijke600@gmail.com)
4  * @brief
5  * @version 0.1
6  * @date 2021-06-14
7  *
8  *
9  */
10 
11 #ifndef INCLUDED_LORA_SDR_FRAME_DETECTOR_SEQUENCE_IMPL_H
12 #define INCLUDED_LORA_SDR_FRAME_DETECTOR_SEQUENCE_IMPL_H
13 
15 extern "C" {
16 #include "kiss_fft.h"
17 }
18 #define GRLORA_DEBUGV
19 namespace gr {
20 namespace lora_sdr {
21 
23 private:
24  /**
25  * @brief State the frame finder can be in
26  * - FIND_PREAMLBE : find the preamble
27  * - SEND_BUFFER : send the buffered input
28  * - SEND_PREAMBLE : send the preamble
29  * - SEND_FRAME : send frame and serach for end of frame
30  * -SEND_END_FRAME : TODO: logic surrounding CRC check
31  */
32  enum State { FIND_PREAMBLE, SEND_BUFFER, SEND_PREAMBLE, SEND_FRAME, SEND_END_FRAME};
33 
34  /**
35  * @brief Current state of the frame finder
36  *
37  */
38  uint8_t m_state;
39 
40  /**
41  * @brief Spreading factor
42  *
43  */
44  uint8_t m_sf;
45 
46  /**
47  * @brief Number of samples per LoRa symbol
48  *
49  */
50  uint32_t m_samples_per_symbol;
51 
52  /**
53  * @brief 2^sf
54  *
55  */
56  uint32_t m_N;
57 
58  /**
59  * @brief the reference downchirp
60  *
61  */
62  std::vector<gr_complex> m_downchirp;
63 
64  /**
65  * @brief the dechirped symbols on which we need to perform the FFT.
66  *
67  */
68  std::vector<gr_complex> m_dechirped;
69 
70  /**
71  * @brief the output of the FFT
72  *
73  */
74  std::vector<gr_complex> cx_out;
75 
76  /**
77  * @brief the configuration of the FFT
78  *
79  */
80  kiss_fft_cfg fft_cfg;
81 
82  /**
83  * @briefiterator used to find max and argmax of FFT
84  *
85  */
86  std::vector<float>::iterator m_max_it;
87 
88  /**
89  * @brief vector containing the magnitude of the FFT.
90  *
91  */
92  std::vector<float> m_dfts_mag;
93 
94  /**
95  * @brief value of previous lora demodulated symbol
96  *
97  */
98  int32_t bin_idx;
99 
100  /**
101  * @brief value of newly demodulated symbol
102  *
103  */
104  int32_t bin_idx_new;
105 
106  /**
107  * @brief Number of consecutive upchirps in preamble
108  *
109  */
110  uint32_t n_up;
111 
112  /**
113  * @brief Temporary memory vector
114  *
115  */
116  std::vector<gr_complex> buffer;
117 
118  /**
119  * @brief LoRa symbol count
120  *
121  */
122  uint16_t symbol_cnt;
123 
124  /**
125  * @brief lora symbols per second
126  *
127  */
128  double m_symbols_per_second;
129 
130  /**
131  * @brief Transmission sampling rate
132  *
133  */
134  uint32_t m_samp_rate;
135 
136  /**
137  * @brief Transmission bandwidth (Works only for samp_rate=bw)
138  *
139  */
140  uint32_t m_bw;
141 
142  /**
143  * @brief The number of connective symbols form the end of the packet.
144  *
145  */
146  uint8_t m_n_seq;
147 
148  /**
149  * @brief Counter for counting if we are past the net identifier and
150  * downchirps once we have found the preamble
151  *
152  */
153  int m_cnt;
154 
155  /**
156  * @brief Get the symbol object value (aka decoded LoRa symbol value)
157  * Function consumes vectors of length m_N
158  *
159  * @param input : complex samples
160  * @return int32_t : LoRa symbol value
161  */
162  int32_t get_symbol_val(const gr_complex *input);
163 
164 public:
165 /**
166  * @brief Construct a new frame detector sequence impl object
167  *
168  * @param sf : spreading factor
169  * @param samp_rate : sampling rate
170  * @param bw : bandwith
171  * @param n_seq : number of consecitive symbols for the end
172  */
173  frame_detector_sequence_impl(uint8_t sf, uint32_t samp_rate, uint32_t bw,
174  uint8_t n_seq);
175 
176  /**
177  * @brief Destroy the frame detector sequence impl object
178  *
179  */
181 
182  /**
183  * @brief Function to tell scheduler how many items we need
184  *
185  * @param noutput_items : number of output items
186  * @param ninput_items_required : number of required input itens
187  */
188  void forecast(int noutput_items, gr_vector_int &ninput_items_required);
189 
190  /**
191  * @brief General function where all the stuff happens
192  *
193  * @param noutput_items : number of output items
194  * @param ninput_items : number of input items
195  * @param input_items : input items
196  * @param output_items : output items
197  * @return int
198  */
199  int general_work(int noutput_items, gr_vector_int &ninput_items,
200  gr_vector_const_void_star &input_items,
201  gr_vector_void_star &output_items);
202 };
203 
204 } // namespace lora_sdr
205 } // namespace gr
206 
207 #endif /* INCLUDED_LORA_SDR_FRAME_DETECTOR_SEQUENCE_IMPL_H */
gr::lora_sdr::frame_detector_sequence_impl::frame_detector_sequence_impl
frame_detector_sequence_impl(uint8_t sf, uint32_t samp_rate, uint32_t bw, uint8_t n_seq)
Construct a new frame detector sequence impl object.
kiss_fft.h
frame_detector_sequence.h
gr::lora_sdr::frame_detector_sequence
LoRa frame detector sequence, this block detects a LoRa frames using a preamble detection to find the...
Definition: frame_detector_sequence.h:27
gr::lora_sdr::frame_detector_sequence_impl::~frame_detector_sequence_impl
~frame_detector_sequence_impl()
Destroy the frame detector sequence impl object.
gr::lora_sdr::frame_detector_sequence_impl
Definition: frame_detector_sequence_impl.h:22
kiss_fft_state
Definition: _kiss_fft_guts.h:22
gr
Definition: add_crc.h:28
gr::lora_sdr::frame_detector_sequence_impl::general_work
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
General function where all the stuff happens.
gr::lora_sdr::frame_detector_sequence_impl::forecast
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
Function to tell scheduler how many items we need.