GNU Radio's LORA_SDR Package
mu_synchro_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2020 Joachim Tapparel TCL@EPFL.
4 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef INCLUDED_LORA_SDR_MU_SYNCHRO_IMPL_H
22#define INCLUDED_LORA_SDR_MU_SYNCHRO_IMPL_H
23// #define GRLORA_DEBUG // synchronisation infos will be printed in the
24// terminal(it is advised to transmitt only one frame)
25
26#include "helpers.h"
27#include <fstream>
28#include <iostream>
29#include <lora_sdr/mu_synchro.h>
30
31/**
32 * @brief Permitted symbol types
33 *
34 */
43};
44namespace gr {
45namespace lora_sdr {
46
48private:
49 enum Sync_state {
50 IDLE,
51 SINGLE_USER,
52 REALIGN_TO_NEW,
53 MULTI_USER,
54 REALIGN_TO_PREV
55
56 };
57 enum Detection_cases {
58 P1_LT_P2, ///< P1 less than P2
59 P1_GT_P2, ///< P1 greater than P2
60 P1_OR_P2, ///< only one user detected
61 };
62
63 struct user {
64 int32_t cnt;
65 double power;
66 long sto_int;
67 double sto_frac;
68 long cfo_int;
69 double cfo_frac;
70 };
71
72 uint8_t m_sf; ///< Spreading factor
73 uint8_t m_n_up; ///< number of upchirps in preamble
74 uint32_t m_len; ///< number of payload symbols
75 uint32_t
76 m_samples_per_symbol; ///< Number of samples received per lora symbols
77 uint32_t m_N; ///< 2^sf
78 uint8_t m_os_factor; ///< oversampling factor
79
80 user user_u;
81 user user_i;
82 double m_power1; ///< power of user 1 (not fixed to user u)
83 double m_power2; ///< power of user 2 (not fixed to user i)
84
85 bool two_users; ///< indicate that two users are present
86
87 double m_tau; ///< number of samples between the begin of a window and the
88 ///< start of the second symbol of the non synchronized user.
89
90 uint8_t m_sync_state; ///< synchronisation state
91
92 int m_item_to_consume; ///< number of items that should be consumed from th
93 ///< input buffer
94
95 /**
96 * @brief
97 *
98 * @param power1
99 * @param power2
100 * @param win_len
101 * @param Tu
102 * @param Ti1
103 * @param Ti2
104 * @param tau
105 * @param delta_cfo
106 * @param offset
107 */
108 void add_tag(double power1, double power2, long win_len, Symbol_type Tu,
109 Symbol_type Ti1, Symbol_type Ti2, double tau, double delta_cfo,
110 int offset);
111
112 /**
113 * @brief return the symbol type given the sample counter of a user
114 *
115 * @param cnt
116 * @return Symbol_type
117 */
118 Symbol_type get_type(int cnt);
119
120 /**
121 * @brief main function, responsible of the output buffer filling, window and
122 * tag creation
123 *
124 * @param in
125 * @param out
126 * @param state_out
127 * @param offset
128 * @param state_offset
129 * @return std::tuple<int, int, int>
130 */
131 std::tuple<int, int, int> sync_frame(const gr_complex *in, gr_complex *out,
132 uint32_t *state_out, int offset,
133 int state_offset);
134
135public:
136 /**
137 * @brief Construct a new mu synchro impl object
138 *
139 * @param sf
140 * @param os_factor
141 * @param len
142 */
143 mu_synchro_impl(uint8_t sf, uint8_t os_factor, uint32_t len);
144 /**
145 * @brief Destroy the mu synchro impl object
146 *
147 */
149
150 /**
151 * @brief
152 *
153 * @param noutput_items
154 * @param ninput_items_required
155 */
156 void forecast(int noutput_items, gr_vector_int &ninput_items_required);
157
158 /**
159 * @brief
160 *
161 * @param noutput_items
162 * @param ninput_items
163 * @param input_items
164 * @param output_items
165 * @return int
166 */
167 int general_work(int noutput_items, gr_vector_int &ninput_items,
168 gr_vector_const_void_star &input_items,
169 gr_vector_void_star &output_items);
170};
171
172} // namespace lora_sdr
173} // namespace gr
174
175#endif /* INCLUDED_LORA_SDR_MU_SYNCHRO_IMPL_H */
Definition: mu_synchro_impl.h:47
mu_synchro_impl(uint8_t sf, uint8_t os_factor, uint32_t len)
Construct a new mu synchro impl object.
~mu_synchro_impl()
Destroy the mu synchro impl object.
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Definition: mu_synchro.h:36
Symbol_type
Permitted symbol types.
Definition: mu_synchro_impl.h:35
@ PAYLOAD
Definition: mu_synchro_impl.h:41
@ QUARTER_DOWN
Definition: mu_synchro_impl.h:40
@ DOWNCHIRP
Definition: mu_synchro_impl.h:39
@ UPCHIRP
Definition: mu_synchro_impl.h:37
@ SYNC_WORD
Definition: mu_synchro_impl.h:38
@ VOID
Definition: mu_synchro_impl.h:36
@ UNDETERMINED
Definition: mu_synchro_impl.h:42
Definition: add_crc.h:28