-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path0002-jamming.patch
330 lines (328 loc) · 13 KB
/
0002-jamming.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
Index: gnss-sdrmod/src/algorithms/signal_source/libs/jamming_detection.cc
===================================================================
--- /dev/null
+++ gnss-sdrmod/src/algorithms/signal_source/libs/jamming_detection.cc
@@ -0,0 +1,125 @@
+/*!
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ * Satellite Systems receiver
+ *
+ * This file is part of GNSS-SDR.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#include "jamming_detection.h"
+#include <glog/logging.h> // for LOG
+#include <gnuradio/io_signature.h> // for io_signature
+#include <algorithm> // for min
+#include <cstring> // for memcpy
+#include <unistd.h> // for usleep
+#include <utility>
+#include <volk/volk.h>
+
+#pragma message("Jamming detection compile")
+
+#define MEMORY_LEN 5 // remember jamming even std rises suddendly
+
+Gnss_Jamming_Protect::Gnss_Jamming_Protect(float threshold, int averages) : gr::sync_block("jamming_detection",
+ gr::io_signature::make(1, 20, sizeof(gr_complex)),
+ gr::io_signature::make(1, 1, sizeof(gr_complex))),
+ d_threshold(threshold),
+ d_averages(averages)
+{
+ printf("Gnss_Jamming_Protect\n");
+/*
+Ron Economos (April 5, 2020 10:58 AM)
+To: [email protected]
+I would use set_output_multiple() instead. See my previous e-mail for an
+example.
+https://lists.gnu.org/archive/html/discuss-gnuradio/2019-08/msg00188.html
+*/
+ set_output_multiple(CHUNK_SIZE); // only trigger processing if that amount of samples was accumulated
+ avg_index_=0;
+ weight_={0.,0.};
+ jamming_memory_=0;
+}
+
+#if GNURADIO_USES_STD_POINTERS
+std::shared_ptr<Gnss_Jamming_Protect> gnss_sdr_make_jamm(float threshold, int averages)
+{
+ std::shared_ptr<Gnss_Jamming_Protect> jamming_detect_(new Gnss_Jamming_Protect(threshold, averages));
+ return jamming_detect_;
+}
+#else
+boost::shared_ptr<Gnss_Jamming_Protect> gnss_sdr_make_jamm(float threshold, int averages)
+{
+ boost::shared_ptr<Gnss_Jamming_Protect> jamming_detection(new Gnss_Jamming_Protect(threshold, averages));
+ printf("Jamming detection: variable created\n");
+ return jamming_detection;
+}
+#endif
+
+int Gnss_Jamming_Protect::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{ long unsigned int ch = 0;
+ unsigned int alignment = volk_get_alignment();
+ gr_complex *bufin; // ,*bufin;
+ gr_complex integral;
+ const gr_complex* in;
+ gr_complex* carre=(gr_complex*)volk_malloc(sizeof(gr_complex)*CHUNK_SIZE, alignment);
+// see https://github.com/gnss-sdr/gnss-sdr/blob/master/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.h for declaration of gr::fft
+ bufin=plan->get_inbuf();
+ // ibufin=iplan->get_inbuf();
+ for (ch = 0; ch < input_items.size(); ch++)
+ { // identity: output the same as 1st channel input
+ in= (const gr_complex*)input_items[ch]; // all channels
+ memcpy(bufin, in, CHUNK_SIZE * sizeof(gr_complex));
+ plan->execute();
+ if (ch==0)
+ {memcpy(bufout0,plan->get_outbuf(),CHUNK_SIZE * sizeof(gr_complex)); // save FFT(CH0)
+ }
+ if (ch==1)
+ {
+ // volk_32fc_x2_multiply_conjugate_32fc(bufout,plan->get_outbuf(),bufout0,CHUNK_SIZE);
+ volk_32fc_x2_divide_32fc(bufout,plan->get_outbuf(),bufout0,CHUNK_SIZE); // CH1/CH0
+ //memcpy(ibufin, bufout, CHUNK_SIZE * sizeof(gr_complex));
+ //iplan->execute(); // result in iplan->get_outbuf()
+ //weight_+=iplan->get_outbuf()[0];
+ integral={0.,0.};
+ for (int i=0;i<CHUNK_SIZE;i++) integral+=bufout[i];
+ integral/=CHUNK_SIZE;
+ weight_avg_+=integral;
+ avg_index_++;
+ }
+ }
+ if (avg_index_==d_averages) // restart averaging
+ {weight_=weight_avg_/(float)avg_index_;
+ weight_avg_={0.,0.};
+ avg_index_=0;
+ printf("xcorr: %f+i*%f -> %f ",weight_.real(),weight_.imag(),norm(weight_));
+ }
+ if ((norm(weight_)<d_threshold)&&(jamming_memory_==0)) // no jamming
+ {
+ memcpy(output_items[0], input_items[0], noutput_items * input_signature()->sizeof_stream_item(ch));
+ printf("\n");
+ }
+ else
+ {if (norm(weight_)>=d_threshold)
+ {printf(" /!\\\n");
+ jamming_memory_=MEMORY_LEN; // reinit memory
+ }
+ else
+ {printf(" \\!/\n");
+ jamming_memory_--; // |weight_| < NORM_THRESHOLD so jamming_memory_>0 and --
+ }
+ volk_32fc_s32fc_multiply_32fc(carre,(const gr_complex*)input_items[0],-weight_,CHUNK_SIZE);
+ volk_32fc_x2_add_32fc((gr_complex*)output_items[0], (const gr_complex*)input_items[1], carre, CHUNK_SIZE);
+ }
+// delete plan;
+ volk_free(carre);
+ return noutput_items;
+}
Index: gnss-sdrmod/src/algorithms/signal_source/libs/jamming_detection.h
===================================================================
--- /dev/null
+++ gnss-sdrmod/src/algorithms/signal_source/libs/jamming_detection.h
@@ -0,0 +1,91 @@
+/*!
+ * \file
+ * \brief Interface of a GNU Radio block that sends a STOP message to the
+ * control queue right after a specific number of samples have passed through it.
+ * \author Javier Arribas, 2018. jarribas(at)cttc.es
+ * \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ * Satellite Systems receiver
+ *
+ * This file is part of GNSS-SDR.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * -------------------------------------------------------------------------
+ */
+
+
+#ifndef GNSS_SDR_GNSS_SDR_JAM_H
+#define GNSS_SDR_GNSS_SDR_JAM_H
+
+#include "concurrent_queue.h"
+#if GNURADIO_USES_STD_POINTERS
+#include <memory>
+#else
+#include <boost/shared_ptr.hpp>
+#endif
+#include <gnuradio/sync_block.h> // for sync_block
+#include <gnuradio/types.h> // for gr_vector_const_void_star
+#include <pmt/pmt.h>
+#include <cstddef> // for size_t
+#include <cstdint>
+#include <memory>
+
+#include <gnuradio/fft/fft.h>
+#include <gnuradio/fft/fft_shift.h>
+
+// #define CHUNK_SIZE (2048*8*2) // ~1023 MS/s/32768=30~Hz/bin
+#define CHUNK_SIZE (8192*64) // cf Matlab
+#define NORM_THRESHOLD (0.08)
+
+class Gnss_Jamming_Protect;
+#if GNURADIO_USES_STD_POINTERS
+std::shared_ptr<Gnss_Jamming_Protect> gnss_sdr_make_jamm(
+ float threshold, int averages);
+#else
+boost::shared_ptr<Gnss_Jamming_Protect> gnss_sdr_make_jamm(
+ float threshold, int averages);
+#endif
+
+/*!
+ * \brief Implementation of a GNU Radio block that sends a STOP message to the
+ * control queue right after a specific number of samples have passed through it.
+ */
+class Gnss_Jamming_Protect : public gr::sync_block
+{
+public:
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+private:
+#if GNURADIO_USES_STD_POINTERS
+ friend std::shared_ptr<Gnss_Jamming_Protect> gnss_sdr_make_jamm(
+ float threshold, int averages);
+#else
+ friend boost::shared_ptr<Gnss_Jamming_Protect> gnss_sdr_make_jamm(
+ float threshold, int averages);
+#endif
+
+ Gnss_Jamming_Protect(float threshold, int averages);
+ gr::fft::fft_complex* plan = new gr::fft::fft_complex(CHUNK_SIZE, true);
+ gr::fft::fft_complex* iplan= new gr::fft::fft_complex(CHUNK_SIZE, false); // forward = false
+ gr_complex bufout0[CHUNK_SIZE];
+ gr_complex bufout[CHUNK_SIZE];
+ gr_complex processed_output[CHUNK_SIZE];
+ gr_complex weight_;
+ gr_complex weight_avg_;
+ float d_threshold;
+ int d_averages;
+ int jamming_memory_;
+ int avg_index_;
+ uint64_t d_ncopied_items;
+ Concurrent_Queue<pmt::pmt_t>* d_queue;
+};
+
+#endif // GNSS_SDR_GNSS_SDR_JAM_H
Index: gnss-sdrmod/src/algorithms/signal_source/adapters/uhd_signal_source.cc
===================================================================
--- gnss-sdrmod.orig/src/algorithms/signal_source/adapters/uhd_signal_source.cc
+++ gnss-sdrmod/src/algorithms/signal_source/adapters/uhd_signal_source.cc
@@ -21,6 +21,7 @@
#include "GPS_L1_CA.h"
#include "configuration_interface.h"
#include "gnss_sdr_valve.h"
+#include "jamming_detection.h"
#include "sgd.h"
#include <glog/logging.h>
#include <uhd/exception.hpp>
@@ -59,6 +60,7 @@ UhdSignalSource::UhdSignalSource(const C
clock_source_ = configuration->property(role + ".clock_source", std::string("internal"));
RF_channels_ = configuration->property(role + ".RF_channels", 1);
sgd_ = configuration->property(role + ".sgd", 0);
+ jamming_ = configuration->property(role + ".jamming_protection", 0);
if (sgd_ !=0)
{printf("SGD jamming protection %d\n",sgd_); fflush(stdout);
RF_channels_=sgd_; // SGD jamming protection: override RF_channels in this block only => N inputs and RF_chan=1 output
@@ -69,7 +71,15 @@ UhdSignalSource::UhdSignalSource(const C
int sgd_iter_count = configuration->property(role + ".sgd_iter_count", 10000);
jamming_sgd_=gnss_sdr_make_sgd(0, 5e-3, sgd_alpha, sgd_mean, sgd_mean_length, sgd_iter_count);
}
- if ((sgd_ == 0))
+ if (jamming_ !=0)
+ {printf("Inverse filter jamming protection %d\n",jamming_);
+ RF_channels_=jamming_; // jamming protection: override RF_channels in this block only => N inputs and RF_chan=1 output
+ subdevice_ = configuration->property(role + ".subdevice", std::string("A:A A:B"));
+ jamming_averages=configuration->property(role + ".jamming_averages", Navg);
+ jamming_threshold=configuration->property(role + ".jamming_threshold", NORM_THRESHOLD);
+ jamming_xcorr_=gnss_sdr_make_jamm(jamming_threshold, jamming_averages);
+ }
+ if ((sgd_ == 0) && (jamming_==0))
{subdevice_ = configuration->property(role + ".subdevice", empty);
}
sample_rate_ = configuration->property(role + ".sampling_frequency", 4.0e6);
@@ -267,6 +277,10 @@ void UhdSignalSource::connect(gr::top_bl
top_block->connect(uhd_source_, i, jamming_sgd_, i);
printf("UHD -> SGD connect: %d\n",i);fflush(stdout);
}
+ if (jamming_ != 0)
+ { top_block->connect(uhd_source_, i, jamming_xcorr_, i);
+ printf("UHD -> Jamming connect: %d\n",i);fflush(stdout);
+ }
}
}
@@ -321,5 +335,9 @@ gr::basic_block_sptr UhdSignalSource::ge
{
return jamming_sgd_;
}
+ if ( jamming_xcorr_ != 0ULL)
+ {
+ return jamming_xcorr_;
+ }
return uhd_source_;
}
Index: gnss-sdrmod/src/algorithms/signal_source/libs/CMakeLists.txt
===================================================================
--- gnss-sdrmod.orig/src/algorithms/signal_source/libs/CMakeLists.txt
+++ gnss-sdrmod/src/algorithms/signal_source/libs/CMakeLists.txt
@@ -26,6 +26,7 @@ set(SIGNAL_SOURCE_LIB_SOURCES
rtl_tcp_dongle_info.cc
gnss_sdr_valve.cc
sgd_impl.cc
+ jamming_detection.cc
${OPT_SIGNAL_SOURCE_LIB_SOURCES}
)
@@ -33,6 +34,7 @@ set(SIGNAL_SOURCE_LIB_HEADERS
rtl_tcp_commands.h
rtl_tcp_dongle_info.h
gnss_sdr_valve.h
+ jamming_detection.h
sgd.h
${OPT_SIGNAL_SOURCE_LIB_HEADERS}
)
Index: gnss-sdrmod/src/algorithms/signal_source/adapters/uhd_signal_source.h
===================================================================
--- gnss-sdrmod.orig/src/algorithms/signal_source/adapters/uhd_signal_source.h
+++ gnss-sdrmod/src/algorithms/signal_source/adapters/uhd_signal_source.h
@@ -79,9 +79,11 @@ private:
#if GNURADIO_USES_STD_POINTERS
std::vector<std::shared_ptr<gr::block>> valve_;
std::shared_ptr<gr::block> jamming_sgd_;
+ std::shared_ptr<gr::block> jamming_xcorr_;
#else
std::vector<boost::shared_ptr<gr::block>> valve_;
boost::shared_ptr<gr::block> jamming_sgd_;
+ boost::shared_ptr<gr::block> jamming_xcorr_;
#endif
std::vector<gr::blocks::file_sink::sptr> file_sink_;
std::vector<double> freq_;
@@ -103,6 +105,9 @@ private:
size_t item_size_;
int RF_channels_;
int sgd_;
+ int jamming_;
+ int jamming_averages;
+ double jamming_threshold;
unsigned int in_stream_;
unsigned int out_stream_;
};