aboutsummaryrefslogtreecommitdiff
path: root/firmware/nrf24.cpp
blob: 7d120518a96254971e53778fc4abefe75d1417ae (plain)
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
#include <Arduino.h>
#include <RF24.h>
#include "buttons.h"
#include "nrf24.h"
#include "display.h"
#define JAM_DURATION 500

extern SPIClass *RADIO_SPI;
extern RF24 radio1;
extern RF24 radio2;

// ============ CHANNELS =============
const byte bleChannels[] = {2, 26, 80};
const byte bluetoothChannels[] = {
    32, 34, 46, 48, 50, 52,
    0, 1, 2, 4, 6, 8,
    22, 24, 26, 28, 30,
    74, 76, 78, 80
};
const byte wifiChannels[] = {
    12, 17, 22, 27, 32,
    37, 42, 47, 52, 57,
    62, 67, 72
};
const byte usbWireless_channels[] =      {40, 50, 60};
const byte videoTransmitter_channels[] = {70, 75, 80};
const byte zigbee_channels[]    =        {11, 15, 20, 25};
const byte rc_channels[]        =        {1, 3, 5, 7};

void initNRF(RF24 &radio)
{
    if (!radio.begin(RADIO_SPI)) {
        Serial.println("NRF not found");
        return;
    }

    radio.setAutoAck(false);
    radio.stopListening();
    radio.setRetries(0, 0);
    radio.setPALevel(RF24_PA_MAX, true);
    radio.setDataRate(RF24_2MBPS);
    radio.openWritingPipe(0xE7E7E7E7E7LL);
    radio.setCRCLength(RF24_CRC_DISABLED);
    Serial.println("NRF Initialized");

}



//void startBleJammer() {
//    initNRF(radio1);
//    initNRF(radio2);
//
//    Serial.println("NRF JAMMER STARTED");
//
//    const char payload[] = "xxxxxxxxxxxxxxxx";
//
//    u8g2.clearBuffer();
//    u8g2.drawStr(0, 10, "Jamming:");
//    u8g2.setCursor(60, 10);
//    u8g2.print("Bluetooth");
//    u8g2.sendBuffer();
//
//    while(true) {
//
//    // Channels (you can change this set)
//    const byte channels[] = {2, 26, 80};
//
//
//    for (int i = 0; i < sizeof(channels); i++) {
//        radio1.setChannel(channels[i]);
//        radio1.write(&payload, sizeof(payload));
//        //radio2.setChannel(channels[i]);
//        //radio2.write(&payload, sizeof(payload));
//    }
//
//     if (btnBack())
//    {
//        Serial.println("Jammer stopped");
//        return;
//    }
//    }
//
//}
//
//void startBluetoothJammer()
//{
//    initNRF(radio1);
//    initNRF(radio2);
//
//    Serial.println("NRF JAMMER STARTED");
//
//    const char payload[] = "xxxxxxxxxxxxxxxx";
//
//    u8g2.clearBuffer();
//    u8g2.drawStr(0, 10, "Jamming:");
//    u8g2.setCursor(60, 10);
//    u8g2.print("Bluetooth");
//    u8g2.sendBuffer();
//
//    while(true) {
//
//    // Channels (you can change this set)
//    const byte channels[] = {32, 34, 46, 48, 50, 52, 0, 1, 2, 4, 6, 8, 22, 24, 26, 28, 30, 74, 76, 78, 80};
//
//
//    for (int i = 0; i < sizeof(channels); i++) {
//        radio1.setChannel(channels[i]);
//        radio1.write(&payload, sizeof(payload));
//        //radio2.setChannel(channels[i]);
//        //radio2.write(&payload, sizeof(payload));
//    }
//
//     if (btnBack())
//    {
//        Serial.println("Jammer stopped");
//        return;
//    }
//    }
//}

void startJammer(const char* name, const byte* channels, size_t channelCount)
{
    initNRF(radio1);
    initNRF(radio2);

    Serial.println("NRF JAMMER STARTED");

    const char payload[] = "xxxxxxxxxxxxxxxx";

    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_6x10_tr);
    u8g2.drawStr(0, 15, "NRF24 Jammer");
    u8g2.drawStr(0, 35, name);
    u8g2.drawStr(0, 55, "BACK = Exit");
    u8g2.sendBuffer();

   while (true)
   {
       for (size_t i = 0; i < channelCount; i++)
       {
           //radio1.setChannel(channels[i]);
           //radio1.write(&payload, sizeof(payload));

           // Optional second NRF
           // radio2.setChannel(channels[i]);
           // radio2.write(&payload, sizeof(payload));


           radio1.setChannel(channels[i]);
           radio2.setChannel(channels[(i + 1) % channelCount]);

           radio1.writeFast(&payload, sizeof(payload));
           radio2.writeFast(&payload, sizeof(payload));
       }

       if (btnBack())
       {
           Serial.println("Jammer stopped");
           radio1.powerDown();
           radio2.powerDown();
           return;
       }
   }

    //while (true) {
    //for (size_t i = 0; i < channelCount; i++)
    //{
    //    radio1.setChannel(channels[i]);
    //    radio2.setChannel(channels[(i + 1) % channelCount]);

    //    radio1.writeFast(&payload, sizeof(payload));
    //    radio2.writeFast(&payload, sizeof(payload));

    //    radio1.txStandBy(1);
    //    radio2.txStandBy(1);

    //    delayMicroseconds(200);
    //}


    //if (btnBack())
    //{
    //    Serial.println("Jammer stopped");

    //    radio1.powerDown();
    //    radio2.powerDown();

    //    return;
    //}
//}
}

void NRFToolsMenu(int index) {
    switch (index) {
        case 0:
            // startBleJammer();
            // BLE
            startJammer(
                "BLE",
                bleChannels,
                sizeof(bleChannels) / sizeof(bleChannels[0])
            );

            break;
        case 1:
            // startBluetoothJammer();
            // Bluetooth
            startJammer(
                "Bluetooth",
                bluetoothChannels,
                sizeof(bluetoothChannels) / sizeof(bluetoothChannels[0])
            );
            break;

        case 2:
            startJammer(
                "WiFi",
                wifiChannels,
                sizeof(wifiChannels) / sizeof(wifiChannels[0])
            );
            break;
        case 3:
            startJammer(
                "USB Wireless",
                usbWireless_channels,
                sizeof(usbWireless_channels) / sizeof(usbWireless_channels[0])
            );
            break;
        case 4:
            startJammer(
                "Video TX",
                videoTransmitter_channels,
                sizeof(videoTransmitter_channels) / sizeof(videoTransmitter_channels[0])
            );
            break;
        case 5:
            break;
            startJammer(
                "RC",
                rc_channels,
                sizeof(rc_channels) / sizeof(rc_channels[0])
            );
            break;
        case 6:

            break;
}
    }