GNU Radio's LORA_SDR Package
helpers.h
Go to the documentation of this file.
1/**
2 * @file helpers.h
3 * @author Martyn van Dijke (martijnvdijke600@gmail.com)
4 * @brief
5 * @version 0.1
6 * @date 2021-03-23
7 * Header file for helper functions that make life a little bit easier :)
8 *
9 */
10#include <cstdint>
11#include <gnuradio/expj.h>
12#include <gnuradio/io_signature.h>
13#include <iomanip>
14#include <iostream>
15#include <numeric>
16#include <string.h>
17#include <volk/volk.h>
18
19extern "C" {
20#include "kiss_fft.h"
21}
22
23namespace gr {
24namespace lora_sdr {
25
26
27#define RESET "\033[0m"
28#define RED "\033[31m" /* Red */
29
30/**
31 * @brief Simple modulo the modulus a%b between 0 and (b-1)
32 *
33 * @param a
34 * @param b
35 * @return long modulo of a%b
36 */
37long mod(long a, long b);
38
39/**
40 * @brief Simple modulo the modulus a%b between 0 and (b-1) for doubles
41 *
42 * @param a
43 * @param b
44 * @return double
45 */
46double double_mod(double a, long b);
47
48/**
49 * @brief Convert an integer into a MSB first vector of bool
50 *
51 * @param integer The integer to convert
52 * @param n_bits The output number of bits
53 * @return std::vector<bool>
54 */
55std::vector<bool> int2bool(uint8_t integer, uint8_t n_bits);
56
57/**
58 * @brief Generates a random string of given length
59 *
60 * @param Nbytes : Number of bytes in the string
61 * @return std::string
62 */
63std::string random_string(int Nbytes);
64
65/**
66 * @brief Function that gets the symbol from the received samples
67 *
68 * @param samples : the complex samples
69 * @param ref_chirp : the reference chirp to use to dechirp the lora symbol.
70 * @param m_number_of_bins : number of bings
71 * @param m_samples_per_symbol : number of samples per LoRa symbol
72 * @param cx_in : fft in
73 * @param cx_out : fft out
74 * @return uint32_t
75 */
76uint32_t get_symbol_val(const gr_complex *samples, gr_complex *ref_chirp,
77 uint32_t m_number_of_bins,
78 uint32_t m_samples_per_symbol, kiss_fft_cpx *cx_in,
79 kiss_fft_cpx *cx_out);
80
81/**
82 * @brief Determine the energy of a symbol.
83 *
84 * @param samples The complex symbol to analyse.
85 * @param m_samples_per_symbol : number of samples per LoRa symbol
86 * @return float
87 */
88float determine_energy(const gr_complex *samples,
89 uint32_t m_samples_per_symbol);
90
91/**
92 * @brief Convert a MSB first vector of bool to a integer
93 *
94 * @param b The boolean vector to convert
95 * @return uint32_t
96 */
97uint32_t bool2int(std::vector<bool> b);
98
99/**
100 * @brief Return the reference chirps using s_f=bw
101 *
102 * @param upchirp : The pointer to the reference upchirp
103 * @param downchirp : The pointer to the reference downchirp
104 * @param sf : The spreading factor to use
105 */
106void build_ref_chirps(gr_complex *upchirp, gr_complex *downchirp, uint8_t sf);
107
108/**
109 * @brief Return an modulated upchirp using s_f=bw
110 *
111 * @param chirp : The pointer to the modulated upchirp
112 * @param id : The number used to modulate the chirp
113 * @param sf : The spreading factor to use
114 */
115void build_upchirp(gr_complex *chirp, uint32_t id, uint8_t sf);
116
117/**
118 * @brief Return an modulated upchirp using s_f=bw with over sampling factor
119 *
120 * @param chirp : The pointer to the modulated upchirp
121 * @param id : The number used to modulate the chirp
122 * @param sf : The spreading factor to use
123 * @param os_factor : oversmapling factor
124 */
125void build_upchirp_os_factor(gr_complex *chirp, uint32_t id, uint8_t sf,uint8_t os_factor);
126
127} // namespace lora_sdr
128} // namespace gr
void build_upchirp_os_factor(gr_complex *chirp, uint32_t id, uint8_t sf, uint8_t os_factor)
Return an modulated upchirp using s_f=bw with over sampling factor.
float determine_energy(const gr_complex *samples, uint32_t m_samples_per_symbol)
Determine the energy of a symbol.
uint32_t get_symbol_val(const gr_complex *samples, gr_complex *ref_chirp, uint32_t m_number_of_bins, uint32_t m_samples_per_symbol, kiss_fft_cpx *cx_in, kiss_fft_cpx *cx_out)
Function that gets the symbol from the received samples.
std::string random_string(int Nbytes)
Generates a random string of given length.
std::vector< bool > int2bool(uint8_t integer, uint8_t n_bits)
Convert an integer into a MSB first vector of bool.
void build_ref_chirps(gr_complex *upchirp, gr_complex *downchirp, uint8_t sf)
Return the reference chirps using s_f=bw.
long mod(long a, long b)
Simple modulo the modulus ab between 0 and (b-1)
void build_upchirp(gr_complex *chirp, uint32_t id, uint8_t sf)
Return an modulated upchirp using s_f=bw.
double double_mod(double a, long b)
Simple modulo the modulus ab between 0 and (b-1) for doubles.
uint32_t bool2int(std::vector< bool > b)
Convert a MSB first vector of bool to a integer.
Definition: add_crc.h:28
Definition: kiss_fft.h:67