A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
rework scan cmd and create autobaud for the old logic, closes #77
Geo8ca7a7bea584
diff --git a/src/Controllers/UartController.cpp b/src/Controllers/UartController.cppindex 5027c9f8..10fd53f0 100644--- a/src/Controllers/UartController.cpp+++ b/src/Controllers/UartController.cpp@@ -1,4 +1,5 @@#include "UartController.h"+#include <map>/*Constructor@@ -30,7 +31,8 @@ UartController::UartController(Entry point for command*/void UartController::handleCommand(const TerminalCommand& cmd) {- if (cmd.getRoot() == "scan") handleScan();+ if (cmd.getRoot() == "autobaud") handleAutoBaud();+ else if (cmd.getRoot() == "scan") handleScan();else if (cmd.getRoot() == "ping") handlePing();else if (cmd.getRoot() == "read") handleRead();else if (cmd.getRoot() == "write") handleWrite(cmd);@@ -184,15 +186,96 @@ void UartController::handlePing() {Scan*/void UartController::handleScan() {- terminalView.println("UART Scan: in progress... Press [ENTER] to cancel");+ // Default pins to scan+ std::vector<uint8_t> defaultPins = state.getJtagScanPins();++ // Protected pins to avoid+ const std::vector<uint8_t> protectedPins = state.getProtectedPins();++ // Ask user for pin group+ std::vector<uint8_t> selectedPins = userInputManager.readValidatedPinGroup(+ "GPIOs to scan for UART",+ defaultPins,+ protectedPins+ );++ // Limit selection to 8 pins max+ if (selectedPins.size() > 8) {+ terminalView.println("Too many pins selected, limiting to first 8.");+ selectedPins.resize(8);+ }++ // Accumulateur for activity+ std::map<uint8_t, UartService::PinActivity> accum;++ terminalView.println("UART Scan: Measuring edges on pins... Press [ENTER] to stop.\n");+ terminalView.println("[INFO]");+ terminalView.println(" The UART scan passively monitors GPIO pins to detect");+ terminalView.println(" UART-like electrical activity (edges and timings).");+ terminalView.println(" Pins showing activity are potential UART lines.");+ terminalView.println("");+ delay(300); // since the loop below is fast, the message above may not be seen without delay++ unsigned long lastPrint = millis();+ while (true) {++ // Stop if ENTER pressed+ char key = terminalInput.readChar();+ if (key == '\r' || key == '\n') {+ terminalView.println("UART Scan: Stopped by user.");+ break;+ }++ // Measure activity for selected pins+ auto results = uartService.scanUartActivity(selectedPins, 30, 10, true);++ // Accumulate+ for (auto& r : results) {+ auto& a = accum[r.pin];+ a.pin = r.pin;+ a.edges += r.edges;+ a.edgesPerSec += r.edgesPerSec; // rough sum+ if (r.approxBaud != 0)+ a.approxBaud = r.approxBaud; // keep last valid+ }++ // Periodic accumulated report+ unsigned long now = millis();+ if (now - lastPrint >= 1000) {+ lastPrint = now;++ terminalView.println("Active pins:");++ if (accum.empty()) {+ terminalView.println(" (none)");+ } else {+ for (auto& [pin, r] : accum) {+ terminalView.println(+ " GPIO " + std::to_string(pin) ++ " | edges=" + std::to_string(r.edges) ++ " | approxBaud=" + std::to_string(r.approxBaud)+ );+ }+ }++ terminalView.println("");+ accum.clear();+ }+ }+}++/*+Autobaud+*/+void UartController::handleAutoBaud() {+ terminalView.println("UART Autobaud: in progress... Press [ENTER] to cancel");terminalView.println("");terminalView.println("[INFO]");- terminalView.println(" The UART scanner attempts to detect the correct baudrate");+ terminalView.println(" The UART autobaud attempts to detect the correct baudrate");terminalView.println(" by iteratively switching speeds, sending predefined probes");terminalView.println("");uartService.clearUartBuffer();- scanCancelled = false;for (int baud : baudrates) {if (scanCancelled) return;@@ -200,15 +283,15 @@ void UartController::handleScan() {state.setUartBaudRate(baud);uartService.switchBaudrate(baud);terminalView.println("");- terminalView.println("UART Scan: Setting baudrate to UART config.");- terminalView.println("UART Scan: Baudrate detected " + std::to_string(baud));+ terminalView.println("UART Autobaud: Setting baudrate to UART config.");+ terminalView.println("UART Autobaud: Baudrate detected " + std::to_string(baud));terminalView.println("");return;}}uartService.switchBaudrate(state.getUartBaudRate()); // restore previous- terminalView.println("Uart Scan: No device detected.");+ terminalView.println("UART Autobaud: No device detected.");terminalView.println("");}@@ -224,7 +307,14 @@ bool UartController::scanAtBaudrate(int baud) {unsigned long start = millis();while (millis() - start < 1500) {- if (checkScanCancelled()) return false;+ char key = terminalInput.readChar();+ if (key == '\r' || key == '\n') {+ terminalView.println("\nUART Autobaud: Stopped by user.");+ uartService.switchBaudrate(state.getUartBaudRate()); // restore previous+ scanCancelled = true;+ break;+ }+sendNextProbe(probeIndex);updateResponse(response, asciiCount, maxResponseSize);@@ -242,17 +332,6 @@ bool UartController::scanAtBaudrate(int baud) {return false;}-bool UartController::checkScanCancelled() {- char key = terminalInput.readChar();- if (key == '\r' || key == '\n') {- terminalView.println("UART Scan: Cancelled by user.");- uartService.switchBaudrate(state.getUartBaudRate()); // restore previous- scanCancelled = true;- return true;- }- return false;-}-void UartController::sendNextProbe(size_t& probeIndex) {if (probeIndex < probes.size()) {uartService.write(probes[probeIndex]);@@ -547,6 +626,7 @@ void UartController::handleHelp() {terminalView.println("");terminalView.println("Unknown UART command. Usage:");terminalView.println(" scan");+ terminalView.println(" autobaud");terminalView.println(" ping");terminalView.println(" read");terminalView.println(" write <text>");diff --git a/src/Controllers/UartController.h b/src/Controllers/UartController.hindex b1986624..a1e5c7ee 100644--- a/src/Controllers/UartController.h+++ b/src/Controllers/UartController.h@@ -65,9 +65,12 @@ private:// Swap RX and TX pinsvoid handleSwap();- // Scan to find the right baudrate+ // Scan for active UART pinsvoid handleScan();+ // Find the right baudrate+ void handleAutoBaud();+// Spam given input every given msvoid handleSpam(const TerminalCommand& cmd);@@ -83,9 +86,6 @@ private:// Scan a baudratebool scanAtBaudrate(int baud);- // Check Enter press- bool checkScanCancelled();-// Send next probe to get a UART responsevoid sendNextProbe(size_t& probeIndex);diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cppindex 7f8241d0..22172cc4 100644--- a/src/Controllers/UtilityController.cpp+++ b/src/Controllers/UtilityController.cpp@@ -455,7 +455,8 @@ void UtilityController::handleHelp() {terminalView.println("");terminalView.println(" 3. UART:");- terminalView.println(" scan - Auto baud detect");+ terminalView.println(" scan - Scan UART lines activity");+ terminalView.println(" autobaud - Detect baud rate on RX");terminalView.println(" ping - Send and expect reply");terminalView.println(" read - Read at current baud");terminalView.println(" write <text> - Send at current baud");