-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
130 lines (111 loc) · 4.25 KB
/
main.cpp
File metadata and controls
130 lines (111 loc) · 4.25 KB
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
#include <Arduino.h>
#include <RF24.h>
#include <SPI.h>
#include "esp_bt.h"
#include "esp_wifi.h"
// ToDo: Add Bluetooth, BLE, and RC module channels
// ToDo: Use the Inbuilt LED to indicate the jamming status
// Define SPI speed for the NRF24L01+ module
// 10 MHz is a safe and recommended speed for most modules
constexpr uint32_t SPI_SPEED = 10000000; // 16 MHz
// HSPI
SPIClass *spiHSPI = nullptr;
constexpr uint8_t CE_PIN_HSPI = 16;
constexpr uint8_t CSN_PIN_HSPI = 15;
constexpr uint8_t SCK_PIN_HSPI = 14;
constexpr uint8_t MOSI_PIN_HSPI = 13;
constexpr uint8_t MISO_PIN_HSPI = 12;
// VSPI
SPIClass *spiVSPI = nullptr;
constexpr uint8_t CE_PIN_VSPI = 22;
constexpr uint8_t CSN_PIN_VSPI = 21;
constexpr uint8_t SCK_PIN_VSPI = 18;
constexpr uint8_t MOSI_PIN_VSPI = 23;
constexpr uint8_t MISO_PIN_VSPI = 19;
// ESP32 Inbuilt LED
constexpr uint8_t LED_PIN = 2;
// Channels for Wi-Fi, Bluetooth, BLE, and RC
constexpr uint8_t WiFi_Channels[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
constexpr uint8_t BT_Channels[] = {32, 34, 46, 48, 50, 52, 0, 1, 2, 4, 6, 8, 22, 24, 26, 28, 30, 74, 76, 78, 80};
constexpr uint8_t BLE_Channels[] = {};
constexpr uint8_t RC_Channels[] = {};
// Current module
auto currentModule = "bt";
// RF24 Modules
RF24 radioVSPI(CE_PIN_VSPI, CSN_PIN_VSPI);
RF24 radioHSPI(CE_PIN_HSPI, CSN_PIN_HSPI);
void disableBluetoothAndWiFi() {
esp_bt_controller_deinit(); // Deinitialize the Bluetooth controller
esp_wifi_stop(); // Stop Wi-Fi
esp_wifi_deinit(); // Deinitialize Wi-Fi
esp_wifi_disconnect(); // Disconnect from any active Wi-Fi network
}
void configureModule(RF24 &radio, uint8_t channel, SPIClass *spi = nullptr) {
if (radio.begin(spi)) {
radio.setAutoAck(false);
radio.setRetries(0, 0);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.setAddressWidth(3);
radio.setCRCLength(RF24_CRC_DISABLED);
radio.setChannel(channel);
radio.stopListening();
radio.printPrettyDetails();
} else {
Serial.println("Radio hardware not responding!");
while(1) {} // Halt on failure
}
}
void jamChannel(RF24 &radio, const uint8_t *channels, const size_t numChannels) {
static uint32_t lastChange = 0;
static uint8_t currentChannel = 0;
if (millis() - lastChange > 100) { // Change channel every 100ms
currentChannel = channels[random(numChannels)];
radio.stopConstCarrier(); // Stop previous carrier
radio.startConstCarrier(RF24_PA_MAX, currentChannel);
Serial.print("Jamming channel: ");
Serial.println(currentChannel);
lastChange = millis();
}
}
void ToggleLED(const bool state) {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, state);
}
void setup() {
Serial.begin(9600); // Default baud rate for the Serial Monitor (PlatformIO)
disableBluetoothAndWiFi();
ToggleLED(true);
spiVSPI = new SPIClass(VSPI);
spiVSPI->begin();
spiHSPI = new SPIClass(HSPI);
spiHSPI->begin();
if (strcmp(currentModule, "wifi") == 0) {
configureModule(radioVSPI, WiFi_Channels[0], spiVSPI);
configureModule(radioHSPI, WiFi_Channels[0], spiHSPI);
} else if (strcmp(currentModule, "bt") == 0) {
configureModule(radioVSPI, BT_Channels[0], spiVSPI);
configureModule(radioHSPI, BT_Channels[0], spiHSPI);
} else if (strcmp(currentModule, "ble") == 0) {
configureModule(radioVSPI, BLE_Channels[0], spiVSPI);
configureModule(radioHSPI, BLE_Channels[0], spiHSPI);
} else if (strcmp(currentModule, "rc") == 0) {
configureModule(radioVSPI, RC_Channels[0], spiVSPI);
configureModule(radioHSPI, RC_Channels[0], spiHSPI);
}
}
void loop() {
if (strcmp(currentModule, "wifi") == 0) {
jamChannel(radioVSPI, WiFi_Channels, sizeof(WiFi_Channels));
jamChannel(radioHSPI, WiFi_Channels, sizeof(WiFi_Channels));
} else if (strcmp(currentModule, "bt") == 0) {
jamChannel(radioVSPI, BT_Channels, sizeof(BT_Channels));
jamChannel(radioHSPI, BT_Channels, sizeof(BT_Channels));
} else if (strcmp(currentModule, "ble") == 0) {
jamChannel(radioVSPI, BLE_Channels, sizeof(BLE_Channels));
jamChannel(radioHSPI, BLE_Channels, sizeof(BLE_Channels));
} else if (strcmp(currentModule, "rc") == 0) {
jamChannel(radioVSPI, RC_Channels, sizeof(RC_Channels));
jamChannel(radioHSPI, RC_Channels, sizeof(RC_Channels));
}
}