A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
forward profile cmd from the new core
Geo0750030cecc9
diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cppindex 269a52d9..9cb7b4a9 100644--- a/src/Controllers/UtilityController.cpp+++ b/src/Controllers/UtilityController.cpp@@ -13,7 +13,8 @@ UtilityController::UtilityController(ArgTransformer& argTransformer,SysInfoShell& sysInfoShell,GuideShell& guideShell,- HelpShell& helpShell+ HelpShell& helpShell,+ ProfileShell& profileShell): terminalView(terminalView),deviceView(deviceView),@@ -24,7 +25,8 @@ UtilityController::UtilityController(argTransformer(argTransformer),sysInfoShell(sysInfoShell),guideShell(guideShell),- helpShell(helpShell)+ helpShell(helpShell),+ profileShell(profileShell){}/*@@ -40,6 +42,7 @@ void UtilityController::handleCommand(const TerminalCommand& cmd) {else if (cmd.getRoot() == "guide" || cmd.getRoot() == "man") handleGuide();else if (cmd.getRoot() == "hex" || cmd.getRoot() == "dec") handleHex(cmd);else if (cmd.getRoot() == "wizard") handleWizard(cmd);+ else if (cmd.getRoot() == "profile") handleProfile();else {helpShell.run(state.getCurrentMode(), false);}@@ -508,6 +511,13 @@ void UtilityController::handleHex(const TerminalCommand& cmd) {terminalView.println("");}+/*+Profile+*/+void UtilityController::handleProfile() {+ profileShell.run();+}+/*Help*/@@ -522,7 +532,7 @@ bool UtilityController::isGlobalCommand(const TerminalCommand& cmd) {root == "logic" || root == "analogic" || root == "P" || root == "p") ||root == "system" || root == "guide" || root == "man" || root == "wizard" ||root == "help" || root == "h" || root == "?" || root == "hex" || root == "dec" ||- root == "sys";+ root == "sys" || root == "profile";}bool UtilityController::isScreenCommand(const TerminalCommand& cmd) {diff --git a/src/Controllers/UtilityController.h b/src/Controllers/UtilityController.hindex 9415edeb..97554563 100644--- a/src/Controllers/UtilityController.h+++ b/src/Controllers/UtilityController.h@@ -18,6 +18,7 @@#include "Shells/SysInfoShell.h"#include "Shells/GuideShell.h"#include "Shells/HelpShell.h"+#include "Shells/ProfileShell.h"class UtilityController {public:@@ -32,7 +33,8 @@ public:ArgTransformer& argTransformer,SysInfoShell& sysInfoShell,GuideShell& guideShell,- HelpShell& helpShell+ HelpShell& helpShell,+ ProfileShell& profileShell);// Entry point for global utility commands@@ -47,6 +49,9 @@ public:// Analogic plotter on device screenvoid handleAnalogic(const TerminalCommand& cmd);+ // Save or load profile with pin states and settings+ void handleProfile();+// Check if a command is a global utility commandbool isGlobalCommand(const TerminalCommand& cmd);@@ -88,5 +93,6 @@ private:SysInfoShell& sysInfoShell;GuideShell& guideShell;HelpShell& helpShell;+ ProfileShell& profileShell;GlobalState& state = GlobalState::getInstance();};diff --git a/src/Data/AutoCompleteWords.h b/src/Data/AutoCompleteWords.hindex 551a5d69..6b3f3291 100644--- a/src/Data/AutoCompleteWords.h+++ b/src/Data/AutoCompleteWords.h@@ -1,7 +1,7 @@static const char* const autoCompleteWords[] = {// --- General ---- "help","mode","man","system","logic","analogic","wizard", "hex"+ "help","mode","man","system","logic","analogic","wizard", "hex", "profile",// --- 1WIRE ---"scan","ping","sniff","read","write","temp","ibutton","eeprom","config",diff --git a/src/Providers/DependencyProvider.cpp b/src/Providers/DependencyProvider.cppindex f6b74426..79de3101 100644--- a/src/Providers/DependencyProvider.cpp+++ b/src/Providers/DependencyProvider.cpp@@ -48,6 +48,7 @@ DependencyProvider::DependencyProvider(ITerminalView &terminalView, IDeviceViewjsonTransformer(),infraredTransformer(),subGhzTransformer(),+ profileTransformer(),// ManagerscommandHistoryManager(),@@ -72,6 +73,7 @@ DependencyProvider::DependencyProvider(ITerminalView &terminalView, IDeviceViewguideShell(terminalView, terminalInput, userInputManager),helpShell(terminalView, terminalInput, userInputManager),uartEmulationShell(terminalView, terminalInput, uartService, argTransformer, userInputManager),+ profileShell(terminalView, terminalInput, userInputManager, littleFsService, profileTransformer),// SelectorshorizontalSelector(deviceView, deviceInput),@@ -84,7 +86,7 @@ DependencyProvider::DependencyProvider(ITerminalView &terminalView, IDeviceViewi2cController(terminalView, terminalInput, i2cService, argTransformer, userInputManager, i2cEepromShell, helpShell),oneWireController(terminalView, terminalInput, oneWireService, argTransformer, userInputManager, ibuttonShell, oneWireEepromShell, helpShell),infraredController(terminalView, terminalInput, infraredService, littleFsService, argTransformer, infraredTransformer, userInputManager, universalRemoteShell, helpShell),- utilityController(terminalView, deviceView, terminalInput, pinService, userInputManager, pinAnalyzeManager, argTransformer, sysInfoShell, guideShell, helpShell),+ utilityController(terminalView, deviceView, terminalInput, pinService, userInputManager, pinAnalyzeManager, argTransformer, sysInfoShell, guideShell, helpShell, profileShell),hdUartController(terminalView, terminalInput, deviceInput, hdUartService, uartService, argTransformer, userInputManager, helpShell),spiController(terminalView, terminalInput, spiService, sdService, argTransformer, userInputManager, binaryAnalyzeManager, sdCardShell, spiFlashShell, spiEepromShell, helpShell),jtagController(terminalView, terminalInput, jtagService, userInputManager, helpShell),diff --git a/src/Providers/DependencyProvider.h b/src/Providers/DependencyProvider.hindex 709b76b5..f5901030 100644--- a/src/Providers/DependencyProvider.h+++ b/src/Providers/DependencyProvider.h@@ -86,6 +86,7 @@ and injecting shared instances of core components#include "Shells/GuideShell.h"#include "Shells/HelpShell.h"#include "Shells/UartEmulationShell.h"+#include "Shells/ProfileShell.h"#include "Config/TerminalTypeConfigurator.h"class DependencyProvider@@ -193,6 +194,7 @@ public:GuideShell &getGuideShell();HelpShell &getHelpShell();UartEmulationShell &getUartEmulationShell();+ ProfileShell &getProfileShell();// SelectorsHorizontalSelector &getHorizontalSelector();@@ -275,6 +277,7 @@ private:JsonTransformer jsonTransformer;InfraredRemoteTransformer infraredTransformer;SubGhzTransformer subGhzTransformer;+ ProfileTransformer profileTransformer;// ManagersCommandHistoryManager commandHistoryManager;@@ -299,6 +302,7 @@ private:GuideShell guideShell;HelpShell helpShell;UartEmulationShell uartEmulationShell;+ ProfileShell profileShell;// SelectorsHorizontalSelector horizontalSelector;diff --git a/src/Shells/HelpShell.cpp b/src/Shells/HelpShell.cppindex 356f86d6..910c99cb 100644--- a/src/Shells/HelpShell.cpp+++ b/src/Shells/HelpShell.cpp@@ -101,6 +101,7 @@ void HelpShell::cmdGeneral() {"mode [name] - Set active mode","man - Show firmware guide","system - Show system infos",+ "profile - Save/load pins state","hex [number] - Convert dec/hex/bin","logic <pin> - Logic analyzer","analogic <pin> - Analogic plotter",diff --git a/src/Shells/ProfileShell.cpp b/src/Shells/ProfileShell.cppnew file mode 100644index 00000000..c3083181--- /dev/null+++ b/src/Shells/ProfileShell.cpp@@ -0,0 +1,126 @@+#include "ProfileShell.h"+#include <algorithm>++ProfileShell::ProfileShell(ITerminalView& tv,+ IInput& in,+ UserInputManager& uim,+ LittleFsService& lfs,+ ProfileTransformer& pt)+ : terminalView(tv),+ terminalInput(in),+ userInputManager(uim),+ littleFsService(lfs),+ profileTransformer(pt) {}++void ProfileShell::run() {+ terminalView.println("\n=== Profiles ===");+ terminalView.println("Load and save your pin states.");++ while (true) {+ int choice = userInputManager.readValidatedChoiceIndex("Choose an action", actions, actionsCount, actionsCount-1);++ if (choice == 0) cmdLoad();+ else if (choice == 1) cmdSave();+ break;+ }++ terminalView.println("Exiting profile shell...\n");+}++void ProfileShell::cmdSave() {+ if (!ensureMounted()) return;++ constexpr size_t MIN_FREE_BYTES = 2 * 1024;+ size_t free = littleFsService.freeBytes();+ if (free < MIN_FREE_BYTES) {+ terminalView.println("\n❌ Not enough LittleFS space.");+ return;+ }++ std::string defName = "profile_" + std::to_string(millis() % 1000000);+ std::string base = userInputManager.readSanitizedString("Profile name", defName, false);+ if (base.empty()) base = defName;++ std::string path = buildProfilePath(base);+ std::string text = profileTransformer.toProfileText();++ if (!littleFsService.write(path, text)) {+ terminalView.println("\n❌ Failed to write: " + path);+ return;+ }++ terminalView.println("\n✅ Saved " + path);+}++void ProfileShell::cmdLoad() {+ if (!ensureMounted()) return;++ auto profiles = listProfiles();+ if (profiles.empty()) {+ terminalView.println("\n❌ No .profile files found.");+ return;+ }++ profiles.push_back("Cancel");+ terminalView.println("\n=== Load ===");+ int idx = userInputManager.readValidatedChoiceIndex("Choose the profile", profiles, profiles.size() - 1);++ if (idx < 0 || idx >= (int)profiles.size() - 1) {+ terminalView.println("\n❌ Load cancelled.");+ return;+ }++ std::string path = profiles[(size_t)idx];++ std::string content;+ if (!littleFsService.readAll(path, content)) {+ terminalView.println("\n❌ Failed to read: " + path);+ return;+ }++ std::string err;+ if (!profileTransformer.fromProfileText(content, err)) {+ terminalView.println("\n❌ Invalid profile: " + err);+ return;+ }++ terminalView.println("\n✅ Loaded " + path);+}++bool ProfileShell::ensureMounted() {+ if (!littleFsService.mounted()) {+ littleFsService.begin();+ if (!littleFsService.mounted()) {+ terminalView.println("\n ❌ LittleFS not mounted.");+ return false;+ }+ }+ return true;+}++std::vector<std::string> ProfileShell::listProfiles() {+ std::vector<std::string> out;+ std::vector<std::string> files = littleFsService.listFiles("/", ".profile");++ for (auto& f : files) {+ if (f.size() >= strlen(PROFILE_EXT) &&+ f.substr(f.size() - strlen(PROFILE_EXT)) == PROFILE_EXT) {+ out.push_back(f);+ }+ }++ std::sort(out.begin(), out.end());+ return out;+}++std::string ProfileShell::buildProfilePath(const std::string& baseName) {+ std::string name = baseName;+ if (name.empty()) name = "profile";++ std::string path = "/" + name;+ if (path.size() < strlen(PROFILE_EXT) + 1 ||+ path.substr(path.size() - strlen(PROFILE_EXT)) != PROFILE_EXT) {+ path += PROFILE_EXT;+ }+ return path;+}diff --git a/src/Shells/ProfileShell.h b/src/Shells/ProfileShell.hnew file mode 100644index 00000000..736c699c--- /dev/null+++ b/src/Shells/ProfileShell.h@@ -0,0 +1,44 @@+#pragma once+#include <string>+#include <vector>++#include "Interfaces/ITerminalView.h"+#include "Interfaces/IInput.h"+#include "Managers/UserInputManager.h"+#include "Services/LittleFsService.h"+#include "Transformers/ProfileTransformer.h"++class ProfileShell {+public:+ ProfileShell(ITerminalView& tv,+ IInput& in,+ UserInputManager& uim,+ LittleFsService& lfs,+ ProfileTransformer& profileTransformer);++ void run();++private:+ ITerminalView& terminalView;+ IInput& terminalInput;+ UserInputManager& userInputManager;+ LittleFsService& littleFsService;+ ProfileTransformer& profileTransformer;++ inline static constexpr const char* actions[] = {+ " 📥 Load profile",+ " 💾 Save profile",+ " 🚪 Exit"+ };+ inline static constexpr size_t actionsCount = sizeof(actions) / sizeof(actions[0]);++ inline static constexpr const char* PROFILE_EXT = ".profile";++ void cmdLoad();+ void cmdSave();++ // helpers+ bool ensureMounted();+ std::vector<std::string> listProfiles();+ std::string buildProfilePath(const std::string& baseName);+};diff --git a/src/Transformers/ProfileTransformer.cpp b/src/Transformers/ProfileTransformer.cppnew file mode 100644index 00000000..68c826c2--- /dev/null+++ b/src/Transformers/ProfileTransformer.cpp@@ -0,0 +1,386 @@+#include "ProfileTransformer.h"++std::string ProfileTransformer::toProfileText() {+ auto& gs = GlobalState::getInstance();+ std::ostringstream o;++ o << "# ESP32 Bus Pirate profile\n";+ o << "version=" << gs.getVersion() << "\n\n";++ o << "spi.cs=" << (int)gs.getSpiCSPin() << "\n";+ o << "spi.clk=" << (int)gs.getSpiCLKPin() << "\n";+ o << "spi.miso=" << (int)gs.getSpiMISOPin() << "\n";+ o << "spi.mosi=" << (int)gs.getSpiMOSIPin() << "\n";+ o << "spi.freq=" << gs.getSpiFrequency() << "\n\n";++ o << "i2c.sda=" << (int)gs.getI2cSdaPin() << "\n";+ o << "i2c.scl=" << (int)gs.getI2cSclPin() << "\n";+ o << "i2c.freq=" << gs.getI2cFrequency() << "\n\n";++ o << "uart.baud=" << gs.getUartBaudRate() << "\n";+ o << "uart.rx=" << (int)gs.getUartRxPin() << "\n";+ o << "uart.tx=" << (int)gs.getUartTxPin() << "\n";+ o << "uart.databits=" << (int)gs.getUartDataBits() << "\n";+ o << "uart.parity=" << gs.getUartParity() << "\n";+ o << "uart.stopbits=" << (int)gs.getUartStopBits() << "\n";+ o << "uart.inverted=" << (gs.isUartInverted() ? 1 : 0) << "\n\n";++ o << "ir.tx=" << (int)gs.getInfraredTxPin() << "\n";+ o << "ir.rx=" << (int)gs.getInfraredRxPin() << "\n";+ o << "ir.protocol=" << InfraredProtocolMapper::toString(gs.getInfraredProtocol()) << "\n\n";++ o << "led.data=" << (int)gs.getLedDataPin() << "\n";+ o << "led.clock=" << (int)gs.getLedClockPin() << "\n";+ o << "led.len=" << gs.getLedLength() << "\n";+ o << "led.proto=" << gs.getLedProtocol() << "\n";+ o << "led.brightness=" << (int)gs.getLedBrightness() << "\n";++ // HDUART+ o << "hduart.baud=" << gs.getHdUartBaudRate() << "\n";+ o << "hduart.pin=" << (int)gs.getHdUartPin() << "\n";+ o << "hduart.databits=" << (int)gs.getHdUartDataBits() << "\n";+ o << "hduart.parity=" << gs.getHdUartParity() << "\n";+ o << "hduart.stopbits=" << (int)gs.getHdUartStopBits() << "\n";+ o << "hduart.inverted=" << (gs.isHdUartInverted() ? 1 : 0) << "\n\n";++ // I2S+ o << "i2s.bclk=" << (int)gs.getI2sBclkPin() << "\n";+ o << "i2s.lrck=" << (int)gs.getI2sLrckPin() << "\n";+ o << "i2s.data=" << (int)gs.getI2sDataPin() << "\n";+ o << "i2s.rate=" << gs.getI2sSampleRate() << "\n";+ o << "i2s.bits=" << (int)gs.getI2sBitsPerSample() << "\n\n";++ // CAN+ o << "can.cs=" << (int)gs.getCanCspin() << "\n";+ o << "can.sck=" << (int)gs.getCanSckPin() << "\n";+ o << "can.si=" << (int)gs.getCanSiPin() << "\n";+ o << "can.so=" << (int)gs.getCanSoPin() << "\n";+ o << "can.kbps=" << gs.getCanKbps() << "\n\n";++ // SubGHz+ o << "subghz.sck=" << (int)gs.getSubGhzSckPin() << "\n";+ o << "subghz.miso=" << (int)gs.getSubGhzMisoPin() << "\n";+ o << "subghz.mosi=" << (int)gs.getSubGhzMosiPin() << "\n";+ o << "subghz.cs=" << (int)gs.getSubGhzCsPin() << "\n";+ o << "subghz.gdo=" << (int)gs.getSubGhzGdoPin() << "\n";+ o << "subghz.freq=" << gs.getSubGhzFrequency() << "\n";++ // NRF24+ o << "rf24.csn=" << (int)gs.getRf24CsnPin() << "\n";+ o << "rf24.ce=" << (int)gs.getRf24CePin() << "\n";+ o << "rf24.sck=" << (int)gs.getRf24SckPin() << "\n";+ o << "rf24.miso=" << (int)gs.getRf24MisoPin() << "\n";+ o << "rf24.mosi=" << (int)gs.getRf24MosiPin() << "\n\n";++ // RFID+ o << "rfid.sda=" << (int)gs.getRfidSdaPin() << "\n";+ o << "rfid.scl=" << (int)gs.getRfidSclPin() << "\n\n";++ // SD+ o << "sd.cs=" << (int)gs.getSdCardCsPin() << "\n";+ o << "sd.clk=" << (int)gs.getSdCardClkPin() << "\n";+ o << "sd.miso=" << (int)gs.getSdCardMisoPin() << "\n";+ o << "sd.mosi=" << (int)gs.getSdCardMosiPin() << "\n";+ o << "sd.freq=" << gs.getSdCardFrequency() << "\n";+++ return o.str();+}++static bool getStr(const std::map<std::string,std::string>& kv,+ const char* key,+ std::string& out) {+ auto it = kv.find(key);+ if (it == kv.end()) return false;+ out = it->second;+ return true;+}++static bool parseU32(const std::string& s, uint32_t& out) {+ if (s.empty()) return false;+ char* end = nullptr;+ unsigned long v = std::strtoul(s.c_str(), &end, 10);+ if (!end || *end != '\0') return false;+ out = (uint32_t)v;+ return true;+}++static bool parseU16(const std::string& s, uint16_t& out) {+ uint32_t v = 0;+ if (!parseU32(s, v) || v > 0xFFFF) return false;+ out = (uint16_t)v;+ return true;+}++static bool parseU8(const std::string& s, uint8_t& out) {+ uint32_t v = 0;+ if (!parseU32(s, v) || v > 0xFF) return false;+ out = (uint8_t)v;+ return true;+}++static bool parseBool01(const std::string& s, bool& out) {+ if (s == "1") { out = true; return true; }+ if (s == "0") { out = false; return true; }+ return false;+}++static bool parseF32(const std::string& s, float& out) {+ if (s.empty()) return false;+ char* end = nullptr;+ out = std::strtof(s.c_str(), &end);+ if (!end || *end != '\0') return false;+ return true;+}++bool ProfileTransformer::fromProfileText(+ const std::string& text,+ std::string& error+) {+ error.clear();++ auto& gs = GlobalState::getInstance();+ const auto kv = parse(text);++ // local+ std::string v;+ uint8_t u8 = 0;+ uint16_t u16 = 0;+ uint32_t u32 = 0;+ bool b = false;+ float f32 = 0.0f;++ // -----------------------------+ // SPI+ // -----------------------------+ if (getStr(kv, "spi.cs", v) && !parseU8(v, u8)) { error = "Invalid spi.cs"; return false; }+ else if (!v.empty()) gs.setSpiCSPin(u8);++ if (getStr(kv, "spi.clk", v) && !parseU8(v, u8)) { error = "Invalid spi.clk"; return false; }+ else if (!v.empty()) gs.setSpiCLKPin(u8);++ if (getStr(kv, "spi.miso", v) && !parseU8(v, u8)) { error = "Invalid spi.miso"; return false; }+ else if (!v.empty()) gs.setSpiMISOPin(u8);++ if (getStr(kv, "spi.mosi", v) && !parseU8(v, u8)) { error = "Invalid spi.mosi"; return false; }+ else if (!v.empty()) gs.setSpiMOSIPin(u8);++ if (getStr(kv, "spi.freq", v) && !parseU32(v, u32)) { error = "Invalid spi.freq"; return false; }+ else if (!v.empty()) gs.setSpiFrequency(u32);++ // -----------------------------+ // I2C+ // -----------------------------+ if (getStr(kv, "i2c.sda", v) && !parseU8(v, u8)) { error = "Invalid i2c.sda"; return false; }+ else if (!v.empty()) gs.setI2cSdaPin(u8);++ if (getStr(kv, "i2c.scl", v) && !parseU8(v, u8)) { error = "Invalid i2c.scl"; return false; }+ else if (!v.empty()) gs.setI2cSclPin(u8);++ if (getStr(kv, "i2c.freq", v) && !parseU32(v, u32)) { error = "Invalid i2c.freq"; return false; }+ else if (!v.empty()) gs.setI2cFrequency(u32);++ // -----------------------------+ // UART+ // -----------------------------+ if (getStr(kv, "uart.baud", v) && !parseU32(v, u32)) { error = "Invalid uart.baud"; return false; }+ else if (!v.empty()) gs.setUartBaudRate((unsigned long)u32);++ if (getStr(kv, "uart.rx", v) && !parseU8(v, u8)) { error = "Invalid uart.rx"; return false; }+ else if (!v.empty()) gs.setUartRxPin(u8);++ if (getStr(kv, "uart.tx", v) && !parseU8(v, u8)) { error = "Invalid uart.tx"; return false; }+ else if (!v.empty()) gs.setUartTxPin(u8);++ if (getStr(kv, "uart.databits", v) && !parseU8(v, u8)) { error = "Invalid uart.databits"; return false; }+ else if (!v.empty()) gs.setUartDataBits(u8);++ if (getStr(kv, "uart.parity", v)) {+ gs.setUartParity(v);+ }++ if (getStr(kv, "uart.stopbits", v) && !parseU8(v, u8)) { error = "Invalid uart.stopbits"; return false; }+ else if (!v.empty()) gs.setUartStopBits(u8);++ if (getStr(kv, "uart.inverted", v) && !parseBool01(v, b)) { error = "Invalid uart.inverted"; return false; }+ else if (!v.empty()) gs.setUartInverted(b);++ // -----------------------------+ // Infrared+ // -----------------------------+ if (getStr(kv, "ir.tx", v) && !parseU8(v, u8)) { error = "Invalid ir.tx"; return false; }+ else if (!v.empty()) gs.setInfraredTxPin(u8);++ if (getStr(kv, "ir.rx", v) && !parseU8(v, u8)) { error = "Invalid ir.rx"; return false; }+ else if (!v.empty()) gs.setInfraredRxPin(u8);++ if (getStr(kv, "ir.protocol", v)) {+ gs.setInfraredProtocol(InfraredProtocolMapper::toEnum(v));+ }++ // -----------------------------+ // LED+ // -----------------------------+ if (getStr(kv, "led.data", v) && !parseU8(v, u8)) { error = "Invalid led.data"; return false; }+ else if (!v.empty()) gs.setLedDataPin(u8);++ if (getStr(kv, "led.clock", v) && !parseU8(v, u8)) { error = "Invalid led.clock"; return false; }+ else if (!v.empty()) gs.setLedClockPin(u8);++ if (getStr(kv, "led.len", v) && !parseU16(v, u16)) { error = "Invalid led.len"; return false; }+ else if (!v.empty()) gs.setLedLength(u16);++ if (getStr(kv, "led.proto", v)) {+ gs.setLedProtocol(v);+ }++ if (getStr(kv, "led.brightness", v) && !parseU8(v, u8)) { error = "Invalid led.brightness"; return false; }+ else if (!v.empty()) gs.setLedBrightness(u8);++ // -----------------------------+ // HDUART+ // -----------------------------+ if (getStr(kv, "hduart.baud", v) && !parseU32(v, u32)) { error = "Invalid hduart.baud"; return false; }+ else if (!v.empty()) gs.setHdUartBaudRate((unsigned long)u32);++ if (getStr(kv, "hduart.pin", v) && !parseU8(v, u8)) { error = "Invalid hduart.pin"; return false; }+ else if (!v.empty()) gs.setHdUartPin(u8);++ if (getStr(kv, "hduart.databits", v) && !parseU8(v, u8)) { error = "Invalid hduart.databits"; return false; }+ else if (!v.empty()) gs.setHdUartDataBits(u8);++ if (getStr(kv, "hduart.parity", v)) {+ gs.setHdUartParity(v);+ }++ if (getStr(kv, "hduart.stopbits", v) && !parseU8(v, u8)) { error = "Invalid hduart.stopbits"; return false; }+ else if (!v.empty()) gs.setHdUartStopBits(u8);++ if (getStr(kv, "hduart.inverted", v) && !parseBool01(v, b)) { error = "Invalid hduart.inverted"; return false; }+ else if (!v.empty()) gs.setHdUartInverted(b);++ // -----------------------------+ // I2S+ // -----------------------------+ if (getStr(kv, "i2s.bclk", v) && !parseU8(v, u8)) { error = "Invalid i2s.bclk"; return false; }+ else if (!v.empty()) gs.setI2sBclkPin(u8);++ if (getStr(kv, "i2s.lrck", v) && !parseU8(v, u8)) { error = "Invalid i2s.lrck"; return false; }+ else if (!v.empty()) gs.setI2sLrckPin(u8);++ if (getStr(kv, "i2s.data", v) && !parseU8(v, u8)) { error = "Invalid i2s.data"; return false; }+ else if (!v.empty()) gs.setI2sDataPin(u8);++ if (getStr(kv, "i2s.rate", v) && !parseU32(v, u32)) { error = "Invalid i2s.rate"; return false; }+ else if (!v.empty()) gs.setI2sSampleRate(u32);++ if (getStr(kv, "i2s.bits", v) && !parseU8(v, u8)) { error = "Invalid i2s.bits"; return false; }+ else if (!v.empty()) gs.setI2sBitsPerSample(u8);++ // -----------------------------+ // CAN+ // -----------------------------+ if (getStr(kv, "can.cs", v) && !parseU8(v, u8)) { error = "Invalid can.cs"; return false; }+ else if (!v.empty()) gs.setCanCspin(u8);++ if (getStr(kv, "can.sck", v) && !parseU8(v, u8)) { error = "Invalid can.sck"; return false; }+ else if (!v.empty()) gs.setCanSckPin(u8);++ if (getStr(kv, "can.si", v) && !parseU8(v, u8)) { error = "Invalid can.si"; return false; }+ else if (!v.empty()) gs.setCanSiPin(u8);++ if (getStr(kv, "can.so", v) && !parseU8(v, u8)) { error = "Invalid can.so"; return false; }+ else if (!v.empty()) gs.setCanSoPin(u8);++ if (getStr(kv, "can.kbps", v) && !parseU32(v, u32)) { error = "Invalid can.kbps"; return false; }+ else if (!v.empty()) gs.setCanKbps(u32);++ // -----------------------------+ // SubGHz+ // -----------------------------+ if (getStr(kv, "subghz.sck", v) && !parseU8(v, u8)) { error = "Invalid subghz.sck"; return false; }+ else if (!v.empty()) gs.setSubGhzSckPin(u8);++ if (getStr(kv, "subghz.miso", v) && !parseU8(v, u8)) { error = "Invalid subghz.miso"; return false; }+ else if (!v.empty()) gs.setSubGhzMisoPin(u8);++ if (getStr(kv, "subghz.mosi", v) && !parseU8(v, u8)) { error = "Invalid subghz.mosi"; return false; }+ else if (!v.empty()) gs.setSubGhzMosiPin(u8);++ if (getStr(kv, "subghz.cs", v) && !parseU8(v, u8)) { error = "Invalid subghz.cs"; return false; }+ else if (!v.empty()) gs.setSubGhzCsPin(u8);++ if (getStr(kv, "subghz.gdo", v) && !parseU8(v, u8)) { error = "Invalid subghz.gdo"; return false; }+ else if (!v.empty()) gs.setSubGhzGdoPin(u8);++ if (getStr(kv, "subghz.freq", v) && !parseF32(v, f32)) { error = "Invalid subghz.freq"; return false; }+ else if (!v.empty()) gs.setSubGhzFrequency(f32);++ // -----------------------------+ // NRF24+ // -----------------------------+ if (getStr(kv, "rf24.csn", v) && !parseU8(v, u8)) { error = "Invalid rf24.csn"; return false; }+ else if (!v.empty()) gs.setRf24CsnPin(u8);++ if (getStr(kv, "rf24.ce", v) && !parseU8(v, u8)) { error = "Invalid rf24.ce"; return false; }+ else if (!v.empty()) gs.setRf24CePin(u8);++ if (getStr(kv, "rf24.sck", v) && !parseU8(v, u8)) { error = "Invalid rf24.sck"; return false; }+ else if (!v.empty()) gs.setRf24SckPin(u8);++ if (getStr(kv, "rf24.miso", v) && !parseU8(v, u8)) { error = "Invalid rf24.miso"; return false; }+ else if (!v.empty()) gs.setRf24MisoPin(u8);++ if (getStr(kv, "rf24.mosi", v) && !parseU8(v, u8)) { error = "Invalid rf24.mosi"; return false; }+ else if (!v.empty()) gs.setRf24MosiPin(u8);++ // -----------------------------+ // RFID+ // -----------------------------+ if (getStr(kv, "rfid.sda", v) && !parseU8(v, u8)) { error = "Invalid rfid.sda"; return false; }+ else if (!v.empty()) gs.setRfidSdaPin(u8);++ if (getStr(kv, "rfid.scl", v) && !parseU8(v, u8)) { error = "Invalid rfid.scl"; return false; }+ else if (!v.empty()) gs.setRfidSclPin(u8);++ // -----------------------------+ // SD Card+ // -----------------------------+ if (getStr(kv, "sd.cs", v) && !parseU8(v, u8)) { error = "Invalid sd.cs"; return false; }+ else if (!v.empty()) gs.setSdCardCsPin(u8);++ if (getStr(kv, "sd.clk", v) && !parseU8(v, u8)) { error = "Invalid sd.clk"; return false; }+ else if (!v.empty()) gs.setSdCardClkPin(u8);++ if (getStr(kv, "sd.miso", v) && !parseU8(v, u8)) { error = "Invalid sd.miso"; return false; }+ else if (!v.empty()) gs.setSdCardMisoPin(u8);++ if (getStr(kv, "sd.mosi", v) && !parseU8(v, u8)) { error = "Invalid sd.mosi"; return false; }+ else if (!v.empty()) gs.setSdCardMosiPin(u8);++ if (getStr(kv, "sd.freq", v) && !parseU32(v, u32)) { error = "Invalid sd.freq"; return false; }+ else if (!v.empty()) gs.setSdCardFrequency(u32);++ return true;+}++std::map<std::string, std::string>+ProfileTransformer::parse(const std::string& text) {+ std::map<std::string, std::string> kv;+ std::stringstream ss(text);+ std::string line;++ while (std::getline(ss, line)) {+ line.erase(0, line.find_first_not_of(" \t\r\n"));+ line.erase(line.find_last_not_of(" \t\r\n") + 1);++ if (line.empty() || line[0] == '#') continue;++ auto eq = line.find('=');+ if (eq == std::string::npos) continue;++ kv[line.substr(0, eq)] = line.substr(eq + 1);+ }+ return kv;+}+diff --git a/src/Transformers/ProfileTransformer.h b/src/Transformers/ProfileTransformer.hnew file mode 100644index 00000000..3fcca3e9--- /dev/null+++ b/src/Transformers/ProfileTransformer.h@@ -0,0 +1,15 @@+#pragma once+#include <string>+#include <map>+#include "States/GlobalState.h"+#include "Enums/InfraredProtocolEnum.h"+#include "Enums/TerminalTypeEnum.h"++class ProfileTransformer {+public:+ static std::string toProfileText();+ static bool fromProfileText(const std::string& text, std::string& error);++private:+ static std::map<std::string, std::string> parse(const std::string& text);+};