Krolyxon
Commit bd12e09

Branches

Tags

Refs →

orion-rffirmwarenrf24.cpp

221 lines · 4.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
12const byte bleChannels[] = {2, 26, 80};
13
14const byte bluetoothChannels[] = {
15 32, 34, 46, 48, 50, 52,
16 0, 1, 2, 4, 6, 8,
17 22, 24, 26, 28, 30,
18 74, 76, 78, 80
19};
20
21const byte wifiChannels[] = {
22 12, 17, 22, 27, 32,
23 37, 42, 47, 52, 57,
24 62, 67, 72
25};
26
27void initNRF(RF24 &radio)
28{
29 if (!radio.begin(RADIO_SPI)) {
30 Serial.println("NRF not found");
31 return;
32 }
33
34 radio.setAutoAck(false);
35 radio.stopListening();
36 radio.setRetries(0, 0);
37 radio.setPALevel(RF24_PA_MAX);
38 radio.setDataRate(RF24_2MBPS);
39 radio.openWritingPipe(0xE7E7E7E7E7LL);
40 Serial.println("NRF Initialized");
41
42}
43
44
45
46//void startBleJammer() {
47// initNRF(radio1);
48// initNRF(radio2);
49//
50// Serial.println("NRF JAMMER STARTED");
51//
52// const char payload[] = "xxxxxxxxxxxxxxxx";
53//
54// u8g2.clearBuffer();
55// u8g2.drawStr(0, 10, "Jamming:");
56// u8g2.setCursor(60, 10);
57// u8g2.print("Bluetooth");
58// u8g2.sendBuffer();
59//
60// while(true) {
61//
62// // Channels (you can change this set)
63// const byte channels[] = {2, 26, 80};
64//
65//
66// for (int i = 0; i < sizeof(channels); i++) {
67// radio1.setChannel(channels[i]);
68// radio1.write(&payload, sizeof(payload));
69// //radio2.setChannel(channels[i]);
70// //radio2.write(&payload, sizeof(payload));
71// }
72//
73// if (btnBack())
74// {
75// Serial.println("Jammer stopped");
76// return;
77// }
78// }
79//
80//}
81//
82//void startBluetoothJammer()
83//{
84// initNRF(radio1);
85// initNRF(radio2);
86//
87// Serial.println("NRF JAMMER STARTED");
88//
89// const char payload[] = "xxxxxxxxxxxxxxxx";
90//
91// u8g2.clearBuffer();
92// u8g2.drawStr(0, 10, "Jamming:");
93// u8g2.setCursor(60, 10);
94// u8g2.print("Bluetooth");
95// u8g2.sendBuffer();
96//
97// while(true) {
98//
99// // Channels (you can change this set)
100// const byte channels[] = {32, 34, 46, 48, 50, 52, 0, 1, 2, 4, 6, 8, 22, 24, 26, 28, 30, 74, 76, 78, 80};
101//
102//
103// for (int i = 0; i < sizeof(channels); i++) {
104// radio1.setChannel(channels[i]);
105// radio1.write(&payload, sizeof(payload));
106// //radio2.setChannel(channels[i]);
107// //radio2.write(&payload, sizeof(payload));
108// }
109//
110// if (btnBack())
111// {
112// Serial.println("Jammer stopped");
113// return;
114// }
115// }
116//}
117
118void startJammer(const char* name, const byte* channels, size_t channelCount)
119{
120 initNRF(radio1);
121 initNRF(radio2);
122
123 Serial.println("NRF JAMMER STARTED");
124
125 const char payload[] = "xxxxxxxxxxxxxxxx";
126
127 u8g2.clearBuffer();
128 u8g2.setFont(u8g2_font_6x10_tr);
129 u8g2.drawStr(0, 15, "NRF24 Jammer");
130 u8g2.drawStr(0, 35, name);
131 u8g2.drawStr(0, 55, "BACK = Exit");
132 u8g2.sendBuffer();
133
134 while (true)
135 {
136 for (size_t i = 0; i < channelCount; i++)
137 {
138 //radio1.setChannel(channels[i]);
139 //radio1.write(&payload, sizeof(payload));
140
141 // Optional second NRF
142 // radio2.setChannel(channels[i]);
143 // radio2.write(&payload, sizeof(payload));
144
145
146 radio1.setChannel(channels[i]);
147 radio2.setChannel(channels[(i + 1) % channelCount]);
148
149 radio1.writeFast(&payload, sizeof(payload));
150 radio2.writeFast(&payload, sizeof(payload));
151 }
152
153 if (btnBack())
154 {
155 Serial.println("Jammer stopped");
156 radio1.powerDown();
157 radio2.powerDown();
158 return;
159 }
160 }
161
162 //while (true) {
163 //for (size_t i = 0; i < channelCount; i++)
164 //{
165 // radio1.setChannel(channels[i]);
166 // radio2.setChannel(channels[(i + 1) % channelCount]);
167
168 // radio1.writeFast(&payload, sizeof(payload));
169 // radio2.writeFast(&payload, sizeof(payload));
170
171 // radio1.txStandBy(1);
172 // radio2.txStandBy(1);
173
174 // delayMicroseconds(200);
175 //}
176
177
178 //if (btnBack())
179 //{
180 // Serial.println("Jammer stopped");
181
182 // radio1.powerDown();
183 // radio2.powerDown();
184
185 // return;
186 //}
187//}
188}
189
190void NRFToolsMenu(int index) {
191 switch (index) {
192 case 0:
193 // startBleJammer();
194 // BLE
195 startJammer(
196 "BLE",
197 bleChannels,
198 sizeof(bleChannels) / sizeof(bleChannels[0])
199 );
200
201 break;
202 case 1:
203 // startBluetoothJammer();
204 // Bluetooth
205 startJammer(
206 "Bluetooth",
207 bluetoothChannels,
208 sizeof(bluetoothChannels) / sizeof(bluetoothChannels[0])
209 );
210 break;
211
212 case 2:
213 startJammer(
214 "WiFi",
215 wifiChannels,
216 sizeof(wifiChannels) / sizeof(wifiChannels[0])
217 );
218 break;
219
220 }
221}