8#include <gnuradio/expj.h>
17#define print(message) std::cout<< message <<std::endl
23 #define RESET "\033[0m"
24 #define RED "\033[31m"
41 #define LDRO_MAX_DURATION_MS 16
50 inline long mod(
long a,
long b)
54 {
return fmod(fmod(a,b)+b,b);}
64 inline std::vector<bool>
int2bool(
unsigned int integer,uint8_t n_bits){
65 std::vector<bool> vec(n_bits,0);
67 for(
int i=0 ;i<n_bits;i++) {
68 vec[--j]=((integer>>i)& 1);
80 uint32_t integer = std::accumulate(b.begin(), b.end(), 0, [](
int x,
int y) { return (x << 1) + y; });
95 inline void build_upchirp(gr_complex* chirp, uint32_t
id, uint8_t sf, uint8_t os_factor = 1){
96 double N = (1 << sf) ;
97 int n_fold = N* os_factor -
id*os_factor;
98 for(
int n = 0; n < N* os_factor; n++){
100 chirp[n] = gr_complex(1.0,0.0)*gr_expj(2.0*M_PI *(n*n/(2*N)/pow(os_factor,2)+(
id/N-0.5)*n/os_factor));
102 chirp[n] = gr_complex(1.0,0.0)*gr_expj(2.0*M_PI *(n*n/(2*N)/pow(os_factor,2)+(
id/N-1.5)*n/os_factor));
117 inline void build_ref_chirps(gr_complex* upchirp, gr_complex* downchirp, uint8_t sf, uint8_t os_factor = 1){
118 double N = (1 << sf);
120 volk_32fc_conjugate_32fc(&downchirp[0], &upchirp[0], N*os_factor);
132 std::unordered_map<int, int> hash;
133 for (
int i = 0; i < n; i++)
137 int max_count = 0, res = -1;
138 for (
auto i : hash) {
139 if (max_count < i.second) {
141 max_count = i.second;
150 const char* charmap =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
151 const size_t charmapLength = strlen(charmap);
152 auto generator = [&](){
return charmap[rand()%charmapLength]; };
154 result.reserve(Nbytes);
155 std::generate_n(std::back_inserter(result), Nbytes, generator);
void build_ref_chirps(gr_complex *upchirp, gr_complex *downchirp, uint8_t sf, uint8_t os_factor=1)
Return the reference chirps using s_f=bw.
Definition utilities.h:117
ldro_mode
Definition utilities.h:42
@ DISABLE
Definition utilities.h:43
@ ENABLE
Definition utilities.h:44
@ AUTO
Definition utilities.h:45
Symbol_type
Definition utilities.h:32
@ SYNC_WORD
Definition utilities.h:35
@ DOWNCHIRP
Definition utilities.h:36
@ UNDETERMINED
Definition utilities.h:39
@ VOID
Definition utilities.h:33
@ QUARTER_DOWN
Definition utilities.h:37
@ PAYLOAD
Definition utilities.h:38
@ UPCHIRP
Definition utilities.h:34
std::string random_string(int Nbytes)
Definition utilities.h:149
void build_upchirp(gr_complex *chirp, uint32_t id, uint8_t sf, uint8_t os_factor=1)
Return an modulated upchirp using s_f=bw.
Definition utilities.h:95
std::vector< bool > int2bool(unsigned int integer, uint8_t n_bits)
Convert an integer into a MSB first vector of bool.
Definition utilities.h:64
int most_frequent(int arr[], int n)
Definition utilities.h:129
long mod(long a, long b)
return the modulus ab between 0 and (b-1)
Definition utilities.h:50
double double_mod(double a, long b)
Definition utilities.h:53
double LLR
Log-Likelihood Ratio type.
Definition utilities.h:29
uint32_t bool2int(std::vector< bool > b)
Convert a MSB first vector of bool to a integer.
Definition utilities.h:79