From 5443d3028217965243de708772d9f81f05c75772 Mon Sep 17 00:00:00 2001 From: attermann Date: Sat, 2 Dec 2023 09:32:51 -0700 Subject: [PATCH] WIP: Made UDPInterface configurable --- src/Interfaces/UDPInterface.cpp | 30 +++++++++++++----------------- src/Interfaces/UDPInterface.h | 19 +++++++++++-------- src/main.cpp | 2 +- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/Interfaces/UDPInterface.cpp b/src/Interfaces/UDPInterface.cpp index e9877c1..289eaa1 100644 --- a/src/Interfaces/UDPInterface.cpp +++ b/src/Interfaces/UDPInterface.cpp @@ -39,14 +39,13 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : Interface(na } -UDPInterface::UDPInterface(const char* wifi_ssid, const char* wifi_password, int local_port, const char* local_host /*=nullptr*/, const char* name /*= "UDPInterface"*/) : Interface(name), - _local_port(local_port) -{ - - IN(true); - OUT(true); - bitrate(BITRATE_GUESS); +/*virtual*/ UDPInterface::~UDPInterface() { + stop(); +} +bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int local_port /*= DEFAULT_UDP_PORT*/, const char* local_host /*=nullptr*/) { + online(false); + if (wifi_ssid != nullptr) { _wifi_ssid = wifi_ssid; } @@ -56,16 +55,13 @@ UDPInterface::UDPInterface(const char* wifi_ssid, const char* wifi_password, int if (local_host != nullptr) { _local_host = local_host; } -} - - -/*virtual*/ UDPInterface::~UDPInterface() { - stop(); -} - -bool UDPInterface::start() { - online(false); - + extreme("UDPInterface: wifi ssid: " + _wifi_ssid); + extreme("UDPInterface: wifi password: " + _wifi_password); + extreme("UDPInterface: local host: " + _local_host); + extreme("UDPInterface: local port: " + std::to_string(_remote_port)); + extreme("UDPInterface: remote host: " + _local_host); + extreme("UDPInterface: remote port: " + std::to_string(_remote_port)); + #ifdef ARDUINO // Connect to the WiFi network WiFi.begin(_wifi_ssid.c_str(), _wifi_password.c_str()); diff --git a/src/Interfaces/UDPInterface.h b/src/Interfaces/UDPInterface.h index 817c543..7d71f7a 100644 --- a/src/Interfaces/UDPInterface.h +++ b/src/Interfaces/UDPInterface.h @@ -14,6 +14,10 @@ #include +#define DEFAULT_UDP_PORT 4242 +#define DEFAULT_UDP_LOCAL_HOST "0.0.0.0" +#define DEFAULT_UDP_REMOTE_HOST "255.255.255.255" + namespace RNS { namespace Interfaces { class UDPInterface : public Interface { @@ -27,10 +31,9 @@ namespace RNS { namespace Interfaces { public: //p def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None): UDPInterface(const char* name = "UDPInterface"); - UDPInterface(const char* wifi_ssid, const char* wifi_password, int local_port, const char* local_host = nullptr, const char* name = "UDPInterface"); virtual ~UDPInterface(); - bool start(); + bool start(const char* wifi_ssid, const char* wifi_password, int local_port = DEFAULT_UDP_PORT, const char* local_host = nullptr); void stop(); void loop(); @@ -46,16 +49,16 @@ namespace RNS { namespace Interfaces { Bytes _buffer; // WiFi network name and password - std::string _wifi_ssid = ""; - std::string _wifi_password = ""; + std::string _wifi_ssid; + std::string _wifi_password; // IP address to send UDP data to. // it can be ip address of the server or // broadcast - std::string _local_host = "0.0.0.0"; - int _local_port = 4242; - std::string _remote_host = "255.255.255.255"; - int _remote_port = 4242; + std::string _local_host = DEFAULT_UDP_LOCAL_HOST; + int _local_port = DEFAULT_UDP_PORT; + std::string _remote_host = DEFAULT_UDP_LOCAL_HOST; + int _remote_port = DEFAULT_UDP_PORT; // create UDP instance #ifdef ARDUINO diff --git a/src/main.cpp b/src/main.cpp index 5cdf41d..bc601a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -267,7 +267,7 @@ void setup_reticulum() { #ifdef UDP_INTERFACE RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME); - udp_interface.start(); + udp_interface.start("some_ssid", "some_password"); #endif #ifdef LORA_INTERFACE