Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
/* ⚠️ VAROVÁNÍ: Tento kód je pouze pro LEGÁLNÍ výzkum a testování vlastních zařízení v uzavřeném prostředí. Rušení komunikací je ILEGÁLNÍ. */ #include <RF24.h> #include <esp_bt.h> #include <esp_wifi.h> #include <esp_now.h> #include <BLEDevice.h> #include <BLEServer.h> #include <freertos/FreeRTOS.h> #include <freertos/task.h> #include <freertos/semphr.h> #include <math.h> #include <vector> #include <algorithm> // Pinout ESP32-S3 #define LED_PIN 21 #define NRF24_CE1 4 #define NRF24_CSN1 5 #define NRF24_CE2 15 #define NRF24_CSN2 16 // Módy systému podle bliknutí LED enum SystemMode { MODE_IDLE = 0, // 0 bliknutí - čistá logika bez RF MODE_BLUETOOTH = 1, // 1 bliknutí - Bluetooth Classic frekvence MODE_BLE = 2, // 2 bliknutí - BLE frekvence MODE_WIFI = 3, // 3 bliknutí - WiFi kanály MODE_RC = 4, // 4 bliknutí - RC/2.4GHz zařízení MODE_ADAPTIVE = 5, // 5 bliknutí - Adaptivní mód MODE_CHAOS = 6 // 6 bliknutí - Maximální chaos }; // Globální stav SystemMode currentMode = MODE_IDLE; SystemMode nextMode = MODE_IDLE; volatile bool modeChangeRequested = false; volatile int blinkCounter = 0; volatile bool ledActive = false; // NRF24 instance RF24 radio1(NRF24_CE1, NRF24_CSN1); RF24 radio2(NRF24_CE2, NRF24_CSN2); // ============================================= // JÁDRO LOGIKY - SPOLEČNÉ PRO VŠECHNY MÓDY // ============================================= class CoreLogic { private: // META-STATES pro anti-pattern enum MetaState { META_OBSERVE, // Pozorování META_PRESSURE, // Tlaková fáze META_DISRUPT, // Narušení META_FALSE_QUIET, // Falešný klid META_RESET // Reset adaptace }; MetaState metaState; float pressureLevel; // 0.0-1.0 float instabilityIndex; // 0.0-1.0 float adaptationScore; // 0.0-1.0 uint32_t lastChange; uint32_t metaTimer; // Chaos parameters float chaosX[2]; // Chaos proměnné pro každý NRF float chaosR[2]; // Chaos parametry // Anti-pattern memory uint8_t lastChannels[2][3]; // Poslední 3 kanály každého NRF uint32_t patternEntropy; float chaos_map(float x, float r, float noise = 0.0) { // Logistická mapa s šumem float val = r * x * (1 - x); val += noise * ((float)esp_random() / UINT32_MAX - 0.5); return fmod(fabs(val), 1.0); } void updateMetaState() { uint32_t now = millis(); uint32_t elapsed = now - metaTimer; // Nikdy neměň stav v pravidelných intervalech float changeProb = 0.001 * (1.0 + sin(now * 0.001)) * (1.0 - adaptationScore * 0.5); if(((float)esp_random() / UINT32_MAX) < changeProb || elapsed > 5000) { // Nepravidelná změna stavu MetaState newState; do { newState = (MetaState)(esp_random() % 5); } while(newState == metaState && (esp_random() % 3) != 0); metaState = newState; metaTimer = now; // Aktualizuj chaos parametry při změně chaosR[0] = 3.7 + ((float)esp_random() / UINT32_MAX) * 0.4; chaosR[1] = 3.7 + ((float)esp_random() / UINT32_MAX) * 0.4; } } public: CoreLogic() { metaState = META_OBSERVE; pressureLevel = 0.1; instabilityIndex = 0.3; adaptationScore = 0.0; lastChange = millis(); metaTimer = millis(); chaosX[0] = 0.5; chaosX[1] = 0.6; chaosR[0] = 3.75; chaosR[1] = 3.78; memset(lastChannels, 0, sizeof(lastChannels)); patternEntropy = 0; } // Hlavní rozhodovací funkce - VOLÁ SE Z KAŽDÉHO MÓDU void computeAction(SystemMode mode, uint8_t unit, uint8_t &channel, uint8_t &power, uint16_t &duration, uint8_t &patternType) { updateMetaState(); // Aktualizuj chaos proměnné chaosX[unit] = chaos_map(chaosX[unit], chaosR[unit], 0.01); // Frekvenční targeting podle módu uint8_t baseChannel = 0; uint8_t channelRange = 125; switch(mode) { case MODE_BLUETOOTH: // Bluetooth Classic: 2402-2480 MHz baseChannel = 2; // 2402 MHz channelRange = 78; // do 2480 MHz break; case MODE_BLE: // BLE: primárně advertising kanály 37,38,39 baseChannel = (unit == 0) ? 37 : 38; channelRange = 3; break; case MODE_WIFI: // WiFi kanály: 1,6,11 nebo 1-13 baseChannel = (unit == 0) ? 1 : 11; channelRange = 13; break; case MODE_RC: // RC zařízení: celé pásmo s hoppingem baseChannel = 0; channelRange = 125; break; case MODE_ADAPTIVE: // Adaptivní: kombinace všeho baseChannel = (millis() / 1000) % 50; channelRange = 75; break; case MODE_CHAOS: // Chaos: maximální rozsah baseChannel = 0; channelRange = 125; break; default: // IDLE channel = 0; power = 0; duration = 0; patternType = 0; return; } // Vypočti kanál s anti-pattern logikou uint8_t newChannel; do { float chaosVal = chaosX[unit]; // Aplikuj meta-state vliv switch(metaState) { case META_OBSERVE: chaosVal *= 0.3; // Nižší aktivita break; case META_PRESSURE: chaosVal = 0.5 + chaosVal * 0.5; // Vyšší aktivita break; case META_DISRUPT: chaosVal = fmod(chaosVal * 1.7, 1.0); // Maximální chaos break; case META_FALSE_QUIET: chaosVal *= 0.1; // Minimální aktivita break; case META_RESET: chaosVal = fmod(chaosVal + 0.5, 1.0); // Reset patternu break; } newChannel = baseChannel + (uint8_t)(chaosVal * channelRange); newChannel %= 126; // Anti-pattern: nikdy stejný kanál 2x za sebou } while(newChannel == lastChannels[unit][0] && channelRange > 1); // Ulož do historie lastChannels[unit][2] = lastChannels[unit][1]; lastChannels[unit][1] = lastChannels[unit][0]; lastChannels[unit][0] = newChannel; channel = newChannel; // Výkon podle meta-stavu a pressureLevel if(metaState == META_OBSERVE || metaState == META_FALSE_QUIET) { power = (esp_random() % 2); // Nízký výkon } else if(metaState == META_DISRUPT) { power = 3; // Maximální výkon } else { power = 1 + (esp_random() % 2); // Střední výkon } // Doba trvání - nikdy stejná float durationBase = 50.0; // ms if(metaState == META_DISRUPT) { durationBase *= (1.0 + chaosX[unit]); } else if(metaState == META_FALSE_QUIET) { durationBase *= 0.3; } duration = (uint16_t)(durationBase * (0.8 + 0.4 * chaosX[(unit + 1) % 2])); duration = constrain(duration, 10, 500); // Typ patternu (0=silent, 1=noise, 2=pattern, 3=sweep) uint32_t timeSeed = millis() / (duration + 1); patternType = (timeSeed + unit) % 4; // Někdy přeskoč úplně (anti-pattern) if((esp_random() % 1000) < 30) { patternType = 0; // Silent duration = 100; // Krátká pauza } // Aktualizuj globální metriky pressureLevel = 0.95 * pressureLevel + 0.05 * (power / 3.0); instabilityIndex = 0.9 * instabilityIndex + 0.1 * fabs(chaosX[0] - chaosX[1]); // Sleduj adaptaci prostředí static uint32_t lastActivity = 0; uint32_t now = millis(); if(patternType != 0 && power > 0) { uint32_t activityInterval = now - lastActivity; if(activityInterval < 1000) { // Častá aktivita = prostředí se možná adaptuje adaptationScore = fmin(1.0, adaptationScore + 0.01); } lastActivity = now; } // Pokud se prostředí adaptuje, změň meta-state if(adaptationScore > 0.7) { metaState = META_RESET; adaptationScore *= 0.5; // Resetuj skóre } lastChange = now; } float getPressure() { return pressureLevel; } float getInstability() { return instabilityIndex; } MetaState getMetaState() { return metaState; } }; // ============================================= // LED INDIKACE // ============================================= void blinkLED(int times, int delayMs = 200) { for(int i = 0; i < times; i++) { digitalWrite(LED_PIN, HIGH); delay(delayMs); digitalWrite(LED_PIN, LOW); if(i < times - 1) delay(delayMs); } } void indicateMode(SystemMode mode) { Serial.printf("\n=== MÓD %d ===", mode); switch(mode) { case MODE_IDLE: Serial.println(" IDLE - Čistá logika bez RF"); blinkLED(0); break; case MODE_BLUETOOTH: Serial.println(" BLUETOOTH CLASSIC frekvence"); blinkLED(1); break; case MODE_BLE: Serial.println(" BLE frekvence"); blinkLED(2); break; case MODE_WIFI: Serial.println(" WiFi kanály"); blinkLED(3); break; case MODE_RC: Serial.println(" RC/2.4GHz zařízení"); blinkLED(4); break; case MODE_ADAPTIVE: Serial.println(" ADAPTIVNÍ MÓD"); blinkLED(5); break; case MODE_CHAOS: Serial.println(" CHAOS MÓD - maximální anti-pattern"); blinkLED(6); break; } } // ============================================= // RF EXECUTOR - SPOLEČNÝ PRO VŠECHNY MÓDY // ============================================= class RFExecutor { private: RF24* radios[2]; CoreLogic core; SemaphoreHandle_t radioMutex[2]; TaskHandle_t taskHandles[2]; void executePattern(uint8_t unit, uint8_t channel, uint8_t power, uint16_t duration, uint8_t patternType) { if(patternType == 0 || power == 0) { // Silent mode - jen počkej delayMicroseconds(duration * 100); return; } xSemaphoreTake(radioMutex[unit], portMAX_DELAY); // Nastav rádio radios[unit]->stopListening(); radios[unit]->setChannel(channel); radios[unit]->setPALevel((rf24_pa_dbm_e)power); uint32_t start = micros(); switch(patternType) { case 1: // Noise burst for(uint16_t i = 0; i < duration / 2; i++) { uint8_t noise[32]; esp_fill_random(noise, 32); radios[unit]->writeFast(noise, 32); delayMicroseconds(100 + (esp_random() % 100)); } break; case 2: // Pattern (ale ne pravidelný) for(uint16_t i = 0; i < duration / 3; i++) { uint8_t pattern[32]; for(uint8_t j = 0; j < 32; j++) { pattern[j] = (i * j + channel + unit * 17) % 256; } radios[unit]->writeFast(pattern, 32); delayMicroseconds(150 + (i % 7) * 20); } break; case 3: // Frequency sweep for(uint8_t ch = channel; ch < channel + 5 && ch < 126; ch++) { radios[unit]->setChannel(ch); uint8_t data = ch; radios[unit]->writeFast(&data, 1); delayMicroseconds(80 + (esp_random() % 40)); } break; } xSemaphoreGive(radioMutex[unit]); // Mikro-pauza pro anti-pattern if((esp_random() % 10) < 3) { delayMicroseconds(500 + (esp_random() % 1500)); } } static void radioTask(void* arg) { RFExecutor* executor = (RFExecutor*)arg; uint8_t unit = (uintptr_t)arg & 0x01; while(true) { if(currentMode == MODE_IDLE) { vTaskDelay(pdMS_TO_TICKS(100)); continue; } uint8_t channel, power, patternType; uint16_t duration; // VYVOLÁNÍ JÁDROVÉ LOGIKY - SPOLEČNÉ PRO VŠECHNY MÓDY executor->core.computeAction(currentMode, unit, channel, power, duration, patternType); // Proveď akci executor->executePattern(unit, channel, power, duration, patternType); // Dynamický delay - KLÍČOVÝ PRO ANTI-PATTERN uint32_t delayTime = 50 + (esp_random() % 200); // Někdy dlouhá pauza (anti-pattern) if((esp_random() % 100) < 10) { delayTime += 300 + (esp_random() % 700); } vTaskDelay(pdMS_TO_TICKS(delayTime)); } } public: RFExecutor(RF24* r1, RF24* r2) { radios[0] = r1; radios[1] = r2; radioMutex[0] = xSemaphoreCreateMutex(); radioMutex[1] = xSemaphoreCreateMutex(); } void start() { // Inicializace NRF24 for(int i = 0; i < 2; i++) { radios[i]->begin(); radios[i]->setAutoAck(false); radios[i]->setDataRate(RF24_2MBPS); radios[i]->setCRCLength(RF24_CRC_DISABLED); radios[i]->setAddressWidth(3); radios[i]->setRetries(0, 0); uint8_t address[3] = {0xCE, 0xCE, (uint8_t)(0xCE + i)}; radios[i]->openWritingPipe(address); } // Spuštění úloh na různých jádrech xTaskCreatePinnedToCore(radioTask, "Radio0", 4096, (void*)0, 3, &taskHandles[0], 0); xTaskCreatePinnedToCore(radioTask, "Radio1", 4096, (void*)1, 3, &taskHandles[1], 1); } CoreLogic& getCoreLogic() { return core; } }; // ============================================= // MÓDOVÝ MANAGER // ============================================= class ModeManager { private: RFExecutor* executor; uint32_t modeStartTime; uint32_t modeDuration; void setModeDuration(SystemMode mode) { // Nepravidelné časy pro každý mód switch(mode) { case MODE_IDLE: modeDuration = 5000 + (esp_random() % 10000); break; case MODE_BLUETOOTH: modeDuration = 8000 + (esp_random() % 15000); break; case MODE_BLE: modeDuration = 6000 + (esp_random() % 12000); break; case MODE_WIFI: modeDuration = 10000 + (esp_random() % 20000); break; case MODE_RC: modeDuration = 12000 + (esp_random() % 18000); break; case MODE_ADAPTIVE: modeDuration = 15000 + (esp_random() % 25000); break; case MODE_CHAOS: modeDuration = 5000 + (esp_random() % 8000); break; } } public: ModeManager(RFExecutor* exec) : executor(exec) { modeStartTime = millis(); setModeDuration(currentMode); } void update() { uint32_t now = millis(); // Automatická rotace módů if(now - modeStartTime > modeDuration) { SystemMode newMode; do { newMode = (SystemMode)((currentMode + 1 + (esp_random() % 3)) % 7); } while(newMode == currentMode); changeMode(newMode); } // Ruční změna módu přes sériový port if(Serial.available()) { char cmd = Serial.read(); if(cmd >= '0' && cmd <= '6') { changeMode((SystemMode)(cmd - '0')); } } } void changeMode(SystemMode newMode) { Serial.printf("\n🔄 Změna módu: %d -> %d\n", currentMode, newMode); // Krátká pauza při změně módu delay(200); currentMode = newMode; indicateMode(currentMode); modeStartTime = millis(); setModeDuration(currentMode); // Resetuj část logiky při změně módu executor->getCoreLogic() = CoreLogic(); } void printStatus() { static uint32_t lastPrint = 0; uint32_t now = millis(); if(now - lastPrint > 2000) { CoreLogic& core = executor->getCoreLogic(); Serial.printf("\n📊 Stav: Mód=%d Tlak=%.2f Nestabilita=%.2f", currentMode, core.getPressure(), core.getInstability()); const char* metaStates[] = {"OBSERVE", "PRESSURE", "DISRUPT", "FALSE_QUIET", "RESET"}; Serial.printf(" Meta=%s\n", metaStates[core.getMetaState()]); lastPrint = now; } } }; // ============================================= // GLOBÁLNÍ INSTANCE // ============================================= RFExecutor* rfExecutor; ModeManager* modeManager; // ============================================= // SETUP A LOOP // ============================================= void setup() { Serial.begin(115200); pinMode(LED_PIN, OUTPUT); Serial.println("\n🚀 ESP32-S3 Anti-Adaptive System"); Serial.println("================================"); Serial.println("0: IDLE (0x blink)"); Serial.println("1: BLUETOOTH (1x blink)"); Serial.println("2: BLE (2x blink)"); Serial.println("3: WIFI (3x blink)"); Serial.println("4: RC (4x blink)"); Serial.println("5: ADAPTIVE (5x blink)"); Serial.println("6: CHAOS (6x blink)"); Serial.println("================================"); // Vypni Bluetooth Classic (šetří interference) esp_bt_controller_disable(); // Inicializace RF systému rfExecutor = new RFExecutor(&radio1, &radio2); rfExecutor->start(); // Inicializace módového manageru modeManager = new ModeManager(rfExecutor); // Start v IDLE módu indicateMode(MODE_IDLE); Serial.println("\n✅ Systém připraven. Posílaj '0'-'6' pro změnu módu."); } void loop() { // Hlavní smyčka jen řídí módy a zobrazuje status modeManager->update(); modeManager->printStatus(); delay(100); }
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English