diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 04fd6db092..28f4beeac9 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,6 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] -platform = https://github.com/meshtastic/platform-native.git#bcd02436cfca91f7d28ad0f7dab977c6aaa781af +platform = https://github.com/meshtastic/platform-native.git#c9d8072fca0fbd5fb630a261452d7057b571d1db framework = arduino build_src_filter = @@ -36,4 +36,4 @@ build_flags = -lstdc++fs -lbluetooth -lgpiod - -lyaml-cpp + -lyaml-cpp \ No newline at end of file diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 77680cc63f..663021af5d 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -160,4 +160,5 @@ Webserver: General: MaxNodes: 200 MaxMessageQueue: 100 - ConfigDirectory: /etc/meshtasticd/config.d/ \ No newline at end of file + ConfigDirectory: /etc/meshtasticd/config.d/ +# MACAddress: AA:BB:CC:DD:EE:FF \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index a4485e91ff..b6aa2e2590 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -69,6 +69,22 @@ void portduinoCustomInit() portduinoAddArguments(child, childArguments); } +void getMacAddr(uint8_t *dmac) +{ + if (settingsStrings[mac_address].length() > 11) { + dmac[0] = std::stoi(settingsStrings[mac_address].substr(0, 2), nullptr, 16); + dmac[1] = std::stoi(settingsStrings[mac_address].substr(2, 2), nullptr, 16); + dmac[2] = std::stoi(settingsStrings[mac_address].substr(4, 2), nullptr, 16); + dmac[3] = std::stoi(settingsStrings[mac_address].substr(6, 2), nullptr, 16); + dmac[4] = std::stoi(settingsStrings[mac_address].substr(8, 2), nullptr, 16); + dmac[5] = std::stoi(settingsStrings[mac_address].substr(10, 2), nullptr, 16); + std::cout << settingsStrings[mac_address] << std::endl; + exit; + } else { + _getMacAddr(dmac); + } +} + /** apps run under portduino can optionally define a portduinoSetup() to * use portduino specific init code (such as gpioBind) to setup portduino on their host machine, * before running 'arduino' code. @@ -412,7 +428,12 @@ bool loadConfig(const char *configPath) settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(200); settingsMap[maxtophone] = (yamlConfig["General"]["MaxMessageQueue"]).as(100); settingsStrings[config_directory] = (yamlConfig["General"]["ConfigDirectory"]).as(""); + settingsStrings[mac_address] = (yamlConfig["General"]["MACAddress"]).as(""); + // https://stackoverflow.com/a/20326454 + settingsStrings[mac_address].erase( + std::remove(settingsStrings[mac_address].begin(), settingsStrings[mac_address].end(), ':'), + settingsStrings[mac_address].end()); } catch (YAML::Exception &e) { std::cout << "*** Exception " << e.what() << std::endl; return false; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 1e0223c486..f372fb0ab3 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -59,7 +59,8 @@ enum configNames { maxtophone, maxnodes, ascii_logs, - config_directory + config_directory, + mac_address }; enum { no_screen, x11, st7789, st7735, st7735s, st7796, ili9341, ili9342, ili9488, hx8357d }; enum { no_touchscreen, xpt2046, stmpe610, gt911, ft5x06 }; @@ -71,3 +72,4 @@ extern std::ofstream traceFile; int initGPIOPin(int pinNum, std::string gpioChipname); bool loadConfig(const char *configPath); static bool ends_with(std::string_view str, std::string_view suffix); +void getMacAddr(uint8_t *dmac); \ No newline at end of file