Krolyxon
Commit afeaa4f

Branches

Tags

Refs →

orion-rfsrcrfnrf24.cpp

217 lines · 5.7 KB · C++

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