-
Notifications
You must be signed in to change notification settings - Fork 7
/
jammer_app.c
676 lines (593 loc) · 21.1 KB
/
jammer_app.c
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
#include "jammer_app.h"
#include <furi_hal_region.h>
#include <furi.h>
#include <gui/gui.h>
#include <subghz/devices/devices.h>
#include <furi/core/log.h>
#include <furi_hal.h>
#include <lib/subghz/subghz_tx_rx_worker.h>
#include "helpers/radio_device_loader.h"
#define TAG "JammerApp"
#define SUBGHZ_FREQUENCY_MIN 300000000
#define SUBGHZ_FREQUENCY_MAX 928000000
#define MESSAGE_MAX_LEN 1024
static FuriHalRegion unlockedRegion = {
.country_code = "FTW",
.bands_count = 3,
.bands = {
{.start = 299999755, .end = 348000000, .power_limit = 20, .duty_cycle = 50},
{.start = 386999938, .end = 464000000, .power_limit = 20, .duty_cycle = 50},
{.start = 778999847, .end = 928000000, .power_limit = 20, .duty_cycle = 50},
},
};
typedef struct {
uint32_t min;
uint32_t max;
} FrequencyBand;
static const FrequencyBand valid_frequency_bands[] = {
{300000000, 348000000},
{387000000, 464000000},
{779000000, 928000000},
};
#define NUM_FREQUENCY_BANDS (sizeof(valid_frequency_bands) / sizeof(valid_frequency_bands[0]))
static const char* jamming_modes[] = {
"OOK 650kHz",
"2FSK 2.38kHz",
"2FSK 47.6kHz",
"MSK 99.97Kb/s",
"GFSK 9.99Kb/s",
"Bruteforce 0xFF",
"Sine Wave",
"Square Wave",
"Sawtooth Wave",
"White Noise",
"Triangle Wave",
"Chirp Signal",
"Gaussian Noise",
"Burst Mode"
};
static void jammer_show_splash_screen(JammerApp* app);
static bool jammer_init_subghz(JammerApp* app);
static void jammer_start_tx(JammerApp* app);
static void jammer_switch_mode(JammerApp* app);
static void jammer_update_view(JammerApp* app);
static void jammer_adjust_frequency(JammerApp* app, bool up);
static uint32_t adjust_frequency_to_valid(uint32_t frequency, bool up);
static bool is_frequency_valid(uint32_t frequency);
static int32_t jammer_tx_thread(void* context);
static void jammer_splash_screen_draw_callback(Canvas* canvas, void* context);
static void jammer_draw_callback(Canvas* canvas, void* context);
static void jammer_input_callback(InputEvent* input_event, void* context);
int32_t jammer_app(void* p) {
UNUSED(p);
FURI_LOG_I(TAG, "Starting JammerApp");
JammerApp* app = jammer_app_alloc();
if(!app) {
FURI_LOG_E(TAG, "Failed to allocate JammerApp");
return -1;
}
jammer_show_splash_screen(app);
if(!jammer_init_subghz(app)) {
jammer_app_free(app);
return -1;
}
jammer_start_tx(app);
FURI_LOG_I(TAG, "Entering main loop");
InputEvent event;
while(app->running) {
if(furi_message_queue_get(app->event_queue, &event, 10) == FuriStatusOk) {
if(event.type == InputTypeShort) {
switch(event.key) {
case InputKeyOk:
FURI_LOG_I(TAG, "OK button pressed");
jammer_switch_mode(app);
jammer_update_view(app);
break;
case InputKeyBack:
FURI_LOG_I(TAG, "Back button pressed");
app->running = false;
break;
case InputKeyRight:
FURI_LOG_I(TAG, "Right button pressed");
if(app->cursor_position < 4) {
app->cursor_position++;
jammer_update_view(app);
}
break;
case InputKeyLeft:
FURI_LOG_I(TAG, "Left button pressed");
if(app->cursor_position > 0) {
app->cursor_position--;
jammer_update_view(app);
}
break;
case InputKeyUp:
FURI_LOG_I(TAG, "Up button pressed");
jammer_adjust_frequency(app, true);
jammer_update_view(app);
break;
case InputKeyDown:
FURI_LOG_I(TAG, "Down button pressed");
jammer_adjust_frequency(app, false);
jammer_update_view(app);
break;
default:
break;
}
}
}
}
FURI_LOG_I(TAG, "Exiting JammerApp main loop");
jammer_app_free(app);
FURI_LOG_I(TAG, "JammerApp exited");
return 0;
}
JammerApp* jammer_app_alloc(void) {
JammerApp* app = malloc(sizeof(JammerApp));
if(!app) {
return NULL;
}
app->view_port = view_port_alloc();
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
app->frequency = 315000000;
app->cursor_position = 0;
app->running = true;
app->tx_running = false;
app->jamming_mode = JammerModeOok650Async;
app->gui = furi_record_open(RECORD_GUI);
furi_hal_region_set(&unlockedRegion);
view_port_draw_callback_set(app->view_port, jammer_draw_callback, app);
view_port_input_callback_set(app->view_port, jammer_input_callback, app);
gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
app->tx_thread = NULL;
app->subghz_txrx = NULL;
app->device = NULL;
subghz_devices_init();
app->subghz_txrx = subghz_tx_rx_worker_alloc();
furi_hal_power_suppress_charge_enter();
return app;
}
void jammer_app_free(JammerApp* app) {
furi_assert(app);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Enter jammer_app_free");
#endif
if(app->tx_running) {
app->tx_running = false;
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Set tx_running to false");
#endif
}
if(app->tx_thread) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Joining tx_thread");
#endif
furi_thread_join(app->tx_thread);
furi_thread_free(app->tx_thread);
app->tx_thread = NULL;
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "tx_thread joined and freed");
#endif
}
if(app->subghz_txrx) {
if(subghz_tx_rx_worker_is_running(app->subghz_txrx)) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subghz_txrx worker is running, stopping");
#endif
subghz_tx_rx_worker_stop(app->subghz_txrx);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subghz_txrx worker stopped");
#endif
}
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Freeing subghz_txrx worker");
#endif
subghz_tx_rx_worker_free(app->subghz_txrx);
app->subghz_txrx = NULL;
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subghz_txrx worker freed");
#endif
}
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Ending radio device");
#endif
if(app->device) {
#ifdef FURI_DEBUG
const char* device_name = app->device->name ? app->device->name : "Unknown";
FURI_LOG_D(TAG, "Device name: %s", device_name);
#endif
if(radio_device_loader_is_external(app->device)) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Device is external, performing manual cleanup");
#endif
if(furi_hal_power_is_otg_enabled()) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "OTG power is enabled, disabling");
#endif
furi_hal_power_disable_otg();
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "OTG power disabled");
#endif
}
} else {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Device is internal, calling radio_device_loader_end");
#endif
radio_device_loader_end(app->device);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "radio_device_loader_end completed");
#endif
}
app->device = NULL;
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Radio device ended");
#endif
}
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Calling subghz_devices_deinit");
#endif
subghz_devices_deinit();
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subghz_devices_deinit completed");
#endif
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exiting power suppression mode");
#endif
furi_hal_power_suppress_charge_exit();
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Removing view port from GUI");
#endif
gui_remove_view_port(app->gui, app->view_port);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "gui_remove_view_port completed");
#endif
view_port_free(app->view_port);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "view_port freed");
#endif
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Closing GUI record");
#endif
furi_record_close(RECORD_GUI);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "GUI record closed");
#endif
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Freeing event queue");
#endif
furi_message_queue_free(app->event_queue);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Event queue freed");
#endif
free(app);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exit jammer_app_free");
#endif
}
static bool jammer_init_subghz(JammerApp* app) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Enter jammer_init_subghz");
#endif
app->device = radio_device_loader_set(NULL, SubGhzRadioDeviceTypeExternalCC1101);
if(!app->device) {
FURI_LOG_W(TAG, "External CC1101 not found, trying internal CC1101.");
app->device = radio_device_loader_set(NULL, SubGhzRadioDeviceTypeInternal);
if(!app->device) {
FURI_LOG_E(TAG, "Failed to initialize internal CC1101.");
return false;
}
}
subghz_devices_reset(app->device);
subghz_devices_idle(app->device);
FURI_LOG_I(TAG, "Initialized device %s", app->device->name);
subghz_devices_load_preset(app->device, FuriHalSubGhzPresetOok650Async, NULL);
if(subghz_tx_rx_worker_start(app->subghz_txrx, app->device, app->frequency)) {
FURI_LOG_I(TAG, "Started SubGhz TX RX worker with device %s", app->device->name);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exit jammer_init_subghz");
#endif
return true;
} else {
FURI_LOG_E(TAG, "Failed to start TX RX worker with device %s", app->device->name);
subghz_tx_rx_worker_stop(app->subghz_txrx);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exit jammer_init_subghz");
#endif
return false;
}
}
static void jammer_show_splash_screen(JammerApp* app) {
view_port_draw_callback_set(app->view_port, jammer_splash_screen_draw_callback, app);
view_port_update(app->view_port);
furi_delay_ms(2000);
view_port_draw_callback_set(app->view_port, jammer_draw_callback, app);
}
static void jammer_splash_screen_draw_callback(Canvas* canvas, void* context) {
UNUSED(context);
canvas_clear(canvas);
for(int x = 0; x < 128; x += 8) {
for(int y = 0; y < 64; y += 8) {
canvas_draw_dot(canvas, x, y);
}
}
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "RF Jammer");
canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "by RocketGod");
canvas_draw_frame(canvas, 0, 0, 128, 64);
}
static void jammer_draw_callback(Canvas* canvas, void* context) {
JammerApp* app = (JammerApp*)context;
canvas_clear(canvas);
char freq_str[20];
snprintf(freq_str, sizeof(freq_str), "%3lu.%02lu",
app->frequency / 1000000,
(app->frequency % 1000000) / 10000);
int total_width = strlen(freq_str) * 12;
int start_x = (128 - total_width) / 2;
int digit_position = 0;
for(size_t i = 0; i < strlen(freq_str); i++) {
bool highlight = (digit_position == app->cursor_position);
if(freq_str[i] != '.') {
canvas_set_font(canvas, highlight ? FontBigNumbers : FontPrimary);
char temp[2] = {freq_str[i], '\0'};
canvas_draw_str_aligned(canvas, start_x + (i * 12), 10, AlignCenter, AlignTop, temp);
digit_position++;
} else {
canvas_set_font(canvas, FontPrimary);
char temp[2] = {freq_str[i], '\0'};
canvas_draw_str_aligned(canvas, start_x + (i * 12), 10, AlignCenter, AlignTop, temp);
}
}
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 64, 55, AlignCenter, AlignTop, jamming_modes[app->jamming_mode]);
}
static void jammer_input_callback(InputEvent* input_event, void* context) {
JammerApp* app = (JammerApp*)context;
furi_message_queue_put(app->event_queue, input_event, FuriWaitForever);
}
static void jammer_adjust_frequency(JammerApp* app, bool up) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Enter jammer_adjust_frequency");
#endif
uint32_t frequency = app->frequency;
uint32_t step;
switch(app->cursor_position) {
case 0: step = 100000000; break;
case 1: step = 10000000; break;
case 2: step = 1000000; break;
case 3: step = 100000; break;
case 4: step = 10000; break;
default: return;
}
frequency = up ? frequency + step : frequency - step;
if(frequency > SUBGHZ_FREQUENCY_MAX) {
frequency = SUBGHZ_FREQUENCY_MIN;
} else if(frequency < SUBGHZ_FREQUENCY_MIN) {
frequency = SUBGHZ_FREQUENCY_MAX;
}
frequency = adjust_frequency_to_valid(frequency, up);
app->frequency = frequency;
FURI_LOG_I(TAG, "Frequency adjusted to %lu Hz", app->frequency);
if(app->tx_running) {
if(app->subghz_txrx && app->device) {
subghz_tx_rx_worker_stop(app->subghz_txrx);
if(subghz_tx_rx_worker_start(app->subghz_txrx, app->device, app->frequency)) {
FURI_LOG_I(TAG, "Restarted SubGhz TX RX worker with new frequency %lu Hz", app->frequency);
} else {
FURI_LOG_E(TAG, "Failed to restart SubGhz TX RX worker");
}
} else {
FURI_LOG_E(TAG, "Cannot adjust frequency, subghz_txrx or device is NULL");
}
}
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exit jammer_adjust_frequency");
#endif
}
static void jammer_switch_mode(JammerApp* app) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Enter jammer_switch_mode");
#endif
if(app->tx_running) {
app->tx_running = false;
if(app->tx_thread) {
furi_thread_join(app->tx_thread);
furi_thread_free(app->tx_thread);
app->tx_thread = NULL;
}
}
if(app->subghz_txrx) {
if(subghz_tx_rx_worker_is_running(app->subghz_txrx)) {
subghz_tx_rx_worker_stop(app->subghz_txrx);
}
}
if(!app->device) {
app->device = radio_device_loader_set(NULL, SubGhzRadioDeviceTypeExternalCC1101);
if(!app->device) {
app->device = radio_device_loader_set(NULL, SubGhzRadioDeviceTypeInternal);
if(!app->device) {
return;
}
}
}
subghz_devices_begin(app->device);
subghz_devices_reset(app->device);
subghz_devices_idle(app->device);
app->jamming_mode = (app->jamming_mode + 1) % 14;
switch(app->jamming_mode) {
case JammerModeOok650Async:
subghz_devices_load_preset(app->device, FuriHalSubGhzPresetOok650Async, NULL);
break;
case JammerMode2FSKDev238Async:
subghz_devices_load_preset(app->device, FuriHalSubGhzPreset2FSKDev238Async, NULL);
break;
case JammerMode2FSKDev476Async:
subghz_devices_load_preset(app->device, FuriHalSubGhzPreset2FSKDev476Async, NULL);
break;
case JammerModeMSK99_97KbAsync:
subghz_devices_load_preset(app->device, FuriHalSubGhzPresetMSK99_97KbAsync, NULL);
break;
case JammerModeGFSK9_99KbAsync:
subghz_devices_load_preset(app->device, FuriHalSubGhzPresetGFSK9_99KbAsync, NULL);
break;
case JammerModeBruteforce:
subghz_devices_load_preset(app->device, FuriHalSubGhzPresetOok650Async, NULL);
break;
case JammerModeSineWave:
case JammerModeSquareWave:
case JammerModeSawtoothWave:
case JammerModeWhiteNoise:
case JammerModeTriangleWave:
case JammerModeChirp:
case JammerModeGaussianNoise:
case JammerModeBurst:
FURI_LOG_I(TAG, "Switched to waveform generation mode: %d", app->jamming_mode);
break;
default:
return;
}
if(app->subghz_txrx) {
if(subghz_tx_rx_worker_start(app->subghz_txrx, app->device, app->frequency)) {
jammer_start_tx(app);
}
} else {
app->subghz_txrx = subghz_tx_rx_worker_alloc();
if(app->subghz_txrx) {
if(subghz_tx_rx_worker_start(app->subghz_txrx, app->device, app->frequency)) {
jammer_start_tx(app);
}
}
}
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exit jammer_switch_mode");
#endif
}
static void jammer_start_tx(JammerApp* app) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Enter jammer_start_tx");
#endif
app->tx_running = true;
app->tx_thread = furi_thread_alloc();
furi_thread_set_name(app->tx_thread, "Jammer TX");
furi_thread_set_stack_size(app->tx_thread, 2048);
furi_thread_set_context(app->tx_thread, app);
furi_thread_set_callback(app->tx_thread, jammer_tx_thread);
furi_thread_start(app->tx_thread);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Exit jammer_start_tx");
#endif
}
static int32_t jammer_tx_thread(void* context) {
JammerApp* app = context;
uint8_t jam_data[MESSAGE_MAX_LEN];
const char* device_name = (app->device && app->device->name) ? app->device->name : "Unknown";
FURI_LOG_I(TAG, "TX Thread started with mode %d on device %s", app->jamming_mode, device_name);
switch(app->jamming_mode) {
case JammerModeOok650Async:
memset(jam_data, 0xFF, sizeof(jam_data));
break;
case JammerMode2FSKDev238Async:
case JammerMode2FSKDev476Async:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (i % 2 == 0) ? 0xAA : 0x55;
}
break;
case JammerModeMSK99_97KbAsync:
case JammerModeGFSK9_99KbAsync:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = rand() % 256;
}
break;
case JammerModeBruteforce:
memset(jam_data, 0xFF, sizeof(jam_data));
break;
case JammerModeSineWave:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (uint8_t)(127 * sinf(2 * M_PI * i / sizeof(jam_data)) + 128);
}
break;
case JammerModeSquareWave:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (i % 2 == 0) ? 0xFF : 0x00;
}
break;
case JammerModeSawtoothWave:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (uint8_t)(255 * i / sizeof(jam_data));
}
break;
case JammerModeWhiteNoise:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = rand() % 256;
}
break;
case JammerModeTriangleWave:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (i < sizeof(jam_data) / 2) ? (i * 255 / (sizeof(jam_data) / 2)) : (255 - (i * 255 / (sizeof(jam_data) / 2)));
}
break;
case JammerModeChirp:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (uint8_t)(127 * sinf(2 * M_PI * i * (1 + (float)i / sizeof(jam_data))));
}
break;
case JammerModeGaussianNoise:
for(size_t i = 0; i < sizeof(jam_data); i++) {
float u1 = (float)rand() / RAND_MAX;
float u2 = (float)rand() / RAND_MAX;
float gaussian_noise = sqrtf(-2.0f * logf(u1)) * cosf(2 * M_PI * u2);
jam_data[i] = (uint8_t)(127 * gaussian_noise + 128);
}
break;
case JammerModeBurst:
for(size_t i = 0; i < sizeof(jam_data); i++) {
jam_data[i] = (i % 10 == 0) ? 0xFF : 0x00;
}
break;
}
while(app->tx_running) {
if(app->subghz_txrx) {
bool write_result = subghz_tx_rx_worker_write(app->subghz_txrx, jam_data, sizeof(jam_data));
if(!write_result) {
furi_delay_ms(20);
}
} else {
break;
}
furi_delay_ms(10);
}
FURI_LOG_I(TAG, "TX Thread exiting");
return 0;
}
static void jammer_update_view(JammerApp* app) {
view_port_update(app->view_port);
}
static uint32_t adjust_frequency_to_valid(uint32_t frequency, bool up) {
if(is_frequency_valid(frequency)) {
return frequency;
} else {
if(up) {
for(size_t i = 0; i < NUM_FREQUENCY_BANDS; i++) {
if(frequency < valid_frequency_bands[i].min) {
return valid_frequency_bands[i].min;
}
}
return valid_frequency_bands[0].min;
} else {
for(int i = NUM_FREQUENCY_BANDS - 1; i >= 0; i--) {
if(frequency > valid_frequency_bands[i].max) {
return valid_frequency_bands[i].max;
}
}
return valid_frequency_bands[NUM_FREQUENCY_BANDS - 1].max;
}
}
}
static bool is_frequency_valid(uint32_t frequency) {
for(size_t i = 0; i < NUM_FREQUENCY_BANDS; i++) {
if(frequency >= valid_frequency_bands[i].min && frequency <= valid_frequency_bands[i].max) {
return true;
}
}
return false;
}