Allow Portduino to set the TCP port

This commit is contained in:
GUVWAF 2022-10-01 12:02:29 +02:00
parent 31dc37150b
commit 2696b04138
3 changed files with 35 additions and 1 deletions

View File

@ -411,7 +411,7 @@ void setup()
#endif
#ifdef ARCH_PORTDUINO
initApiServer();
initApiServer(TCPPort);
#endif
// Start airtime logger thread.

View File

@ -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<meshtastic::PowerStatus> newPowerStatus; //TODO: move this to main-esp32.cpp somehow or a helper class

View File

@ -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);