Krolyxon
Commit a97b224

Branches

Tags

Refs →

orion-rffirmwarenrf24.cpp

99 lines · 1.9 KB · C++

1#include <Arduino.h>
2#include <RF24.h>
3#include "buttons.h"
4#include "nrf24.h"
5#include "display.h"
6#define JAM_DURATION 500
7
8extern SPIClass *RADIO_SPI;
9extern RF24 radio1;
10extern RF24 radio2;
11
12void initNRF(RF24 &radio)
13{
14 radio.begin(RADIO_SPI);
15
16 radio.setAutoAck(false);
17 radio.stopListening();
18
19 radio.setRetries(0, 0);
20 radio.setDataRate(RF24_2MBPS);
21radio.setPALevel(RF24_PA_MAX);
22
23 radio.openWritingPipe(0xE7E7E7E7E7LL);
24}
25
26
27void jamChannels(const char* label, int startCh, int endCh) {
28 byte data1[32], data2[32];
29 for (int i = 0; i < 32; i++) {
30 data1[i] = random(0, 256);
31 data2[i] = random(0, 256);
32 }
33
34 for (int ch = startCh; ch <= endCh; ch++) {
35 // Status screen
36 u8g2.clearBuffer();
37 u8g2.drawStr(0, 10, "Jamming:");
38 u8g2.setCursor(60, 10);
39 u8g2.print(label);
40 u8g2.setCursor(0, 30);
41 u8g2.print("Channel: ");
42 u8g2.print(ch);
43 u8g2.sendBuffer();
44
45 unsigned long startTime = millis();
46 while (millis() - startTime < JAM_DURATION) {
47 radio1.setChannel(ch);
48 radio1.stopListening();
49 radio1.write(data1, sizeof(data1));
50 delayMicroseconds(100);
51
52 radio2.setChannel(ch);
53 radio2.stopListening();
54 radio2.write(data2, sizeof(data2));
55 delayMicroseconds(100);
56
57 }
58}
59}
60
61
62void nrfJammerSweep()
63{
64 static uint8_t ch1 = 0;
65 static uint8_t ch2 = 124;
66
67 uint8_t payload[32] = {0xFF};
68
69 radio1.setChannel(ch1);
70 radio1.writeFast(payload, sizeof(payload));
71
72 radio2.setChannel(ch2);
73 radio2.writeFast(payload, sizeof(payload));
74
75 ch1++;
76 ch2--;
77
78 if (ch1 > 124) ch1 = 0;
79 if (ch2 > 124) ch2 = 124;
80}
81
82void startNRFJammer()
83{
84 initNRF(radio1);
85 initNRF(radio2);
86
87 Serial.println("NRF JAMMER STARTED");
88 // nrfJammerSweep();
89 jamChannels("Bluetooth", 0, 78);
90
91
92 if (btnBack())
93 {
94 Serial.println("Jammer stopped");
95 return;
96 }
97
98 delayMicroseconds(200);
99}