A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add replay cmd to infrared
Geo29b1faaaa0f6
diff --git a/src/Controllers/InfraredController.cpp b/src/Controllers/InfraredController.cppindex 0dd9060e..35363651 100644--- a/src/Controllers/InfraredController.cpp+++ b/src/Controllers/InfraredController.cpp@@ -28,6 +28,7 @@ void InfraredController::handleCommand(const TerminalCommand& command) {else if (command.getRoot() == "receive") handleReceive();else if (command.getRoot() == "devicebgone") handleDeviceBgone();else if (command.getRoot() == "remote") handleRemote();+ else if (command.getRoot() == "replay") handleReplay(command);else if (command.getRoot() == "setprotocol") handleSetProtocol();else handleHelp();}@@ -137,6 +138,114 @@ void InfraredController::handleRemote() {universalRemoteShell.run();}+/*+Replay+*/+void InfraredController::handleReplay(const TerminalCommand& command) {++ // Optional replay count+ uint32_t replayCount = 0; // 0 = infinite+ const std::string sub = command.getSubcommand();+ if (!sub.empty() && argTransformer.isValidNumber(sub)) {+ replayCount = argTransformer.toUint32(sub);+ }++ // Record frames+ std::vector<IRFrame> tape;+ if (!recordFrames(tape)) {+ return; // No frames captured+ }++ // Playback frames+ playbackFrames(tape, replayCount);+}++bool InfraredController::recordFrames(std::vector<IRFrame>& tape) {+ tape.clear();+ tape.reserve(MAX_IR_FRAMES);++ terminalView.println("INFRARED Replay: Recording raw IR frames (max 64)... Press [ENTER] to stop.\n");++ // Start the capture+ infraredService.startReceiver();+ uint32_t lastMillis = millis();+ while (true) {+ // Stop if Enter pressed+ char c = terminalInput.readChar();+ if (c == '\r' || c == '\n') break;++ // Max frames reached+ if (tape.size() >= MAX_IR_FRAMES) {+ terminalView.println("\nINFRARED Replay: Reached maximum of 64 frames, stopping recording...\n");+ break;+ }++ // Attempt to capture+ std::vector<uint16_t> timings;+ uint32_t khz = 0;+ if (infraredService.receiveRaw(timings, khz)) {+ const uint32_t now = millis();+ const uint32_t gap = tape.empty() ? 0u : (now - lastMillis);+ lastMillis = now;++ tape.push_back(IRFrame{ std::move(timings), khz, gap });+ terminalView.println(+ " 📥 Captured frame #" + std::to_string(tape.size()) ++ " (gap " + std::to_string(gap) + " ms, carrier " + std::to_string(khz) + " kHz)"+ );+ }+ }+ infraredService.stopReceiver();++ // Nothing+ if (tape.empty()) {+ terminalView.println("INFRARED Replay: No frames captured. Nothing to replay.");+ return false;+ }++ return true;+}++void InfraredController::playbackFrames(const std::vector<IRFrame>& tape, uint32_t replayCount) {+ if (replayCount == 0) {+ terminalView.println("\nINFRARED Replay: Playing back with original delays. Press [ENTER] to stop.\n");+ } else {+ terminalView.println("\nINFRARED Replay: Playing back " + std::to_string(replayCount) ++ " time(s) with original delays. Press [ENTER] to stop.\n");+ }++ // Loop through the frames and send them+ uint32_t playedLoops = 0;+ while (true) {+ if (replayCount > 0 && playedLoops >= replayCount) break;++ for (size_t i = 0; i < tape.size(); ++i) {+ const auto& f = tape[i];++ // Check for Enter press and wait for gap+ uint32_t start = millis();+ while (millis() - start < f.gapMs) {+ char c = terminalInput.readChar();+ if (c == '\r' || c == '\n') {+ terminalView.println("\nINFRARED Replay: Stopped by user.");+ return;+ }+ delay(1);+ }++ // Log and send frame+ terminalView.println(+ " 📤 Sending frame #" + std::to_string(i) ++ " (gap " + std::to_string(f.gapMs) + " ms, carrier " + std::to_string(f.khz) + " kHz)"+ );+ infraredService.sendRaw(f.timings, f.khz);+ }+ ++playedLoops;+ }++ terminalView.println("\nINFRARED Replay: Completed (" + std::to_string(playedLoops) + " loop(s)).");+}+/*Set protocol*/@@ -227,6 +336,7 @@ void InfraredController::handleHelp() {terminalView.println(" setprotocol");terminalView.println(" devicebgone");terminalView.println(" remote");+ terminalView.println(" replay");terminalView.println(" config");}diff --git a/src/Controllers/InfraredController.h b/src/Controllers/InfraredController.hindex c31b850f..585091c6 100644--- a/src/Controllers/InfraredController.h+++ b/src/Controllers/InfraredController.h@@ -37,6 +37,15 @@ private:UserInputManager& userInputManager;UniversalRemoteShell& universalRemoteShell;bool configured = false;+ uint8_t MAX_IR_FRAMES = 64; // Maximum frames to record+++ // Frames+ struct IRFrame {+ std::vector<uint16_t> timings; // raw ir timings+ uint32_t khz; // carrier frequency+ uint32_t gapMs; // delay from previous frame in milliseconds+ };// Configure IR settingsvoid handleConfig();@@ -56,6 +65,11 @@ private:// Universal remote shellvoid handleRemote();+ // Handle replay of IR commands+ void handleReplay(const TerminalCommand& command);+ bool recordFrames(std::vector<IRFrame>& tape);+ void playbackFrames(const std::vector<IRFrame>& tape, uint32_t replayCount);+// Show help textvoid handleHelp();};diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cppindex 07723f48..5e0dc48b 100644--- a/src/Controllers/UtilityController.cpp+++ b/src/Controllers/UtilityController.cpp@@ -377,6 +377,7 @@ void UtilityController::handleHelp() {terminalView.println(" setprotocol - Set IR protocol type");terminalView.println(" devicebgone - OFF devices blast");terminalView.println(" remote - Universal remote commands");+ terminalView.println(" replay - Replay recorded IR frames");terminalView.println(" config - Configure settings");terminalView.println("");