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