diff --git a/src/main.cpp b/src/main.cpp index c5e6e8b56..2305ca038 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -411,7 +411,7 @@ void setup() #endif #ifdef ARCH_PORTDUINO - initApiServer(); + initApiServer(TCPPort); #endif // Start airtime logger thread. diff --git a/src/main.h b/src/main.h index e1142d36c..c92379274 100644 --- a/src/main.h +++ b/src/main.h @@ -20,6 +20,8 @@ extern bool isUSBPowered; extern uint8_t nodeTelemetrySensorsMap[TelemetrySensorType_LPS22+1]; +extern int TCPPort; // set by Portduino + // Global Screen singleton. extern graphics::Screen *screen; // extern Observable newPowerStatus; //TODO: move this to main-esp32.cpp somehow or a helper class diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 893b92bbd..b041391f8 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -51,6 +51,35 @@ class PolledIrqPin : public GPIOPin static GPIOPin *loraIrq; +int TCPPort = 4403; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + switch (key) { + case 'p': + if (sscanf(arg, "%d", &TCPPort) < 1) + return ARGP_ERR_UNKNOWN; + else + printf("Using TCP port %d\n", TCPPort); + break; + case ARGP_KEY_ARG: + return 0; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +void portduinoCustomInit() { + static struct argp_option options[] = {{"port", 'p', "PORT", 0, "The TCP port to use."}, {0}}; + static void *childArguments; + static char doc[] = "Meshtastic native build."; + static char args_doc[] = "..."; + static struct argp argp = {options, parse_opt, args_doc, doc, 0, 0, 0}; + const struct argp_child child = {&argp, OPTION_ARG_OPTIONAL, 0, 0}; + portduinoAddArguments(child, childArguments); +} + + /** 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. @@ -86,6 +115,9 @@ void portduinoSetup() #endif { + // Set the random seed equal to TCPPort to have a different seed per instance + randomSeed(TCPPort); + auto fakeBusy = new SimGPIOPin(SX126X_BUSY, "fakeBusy"); fakeBusy->writePin(LOW); fakeBusy->setSilent(true);