WIP: Made UDPInterface configurable

This commit is contained in:
attermann 2023-12-02 09:32:51 -07:00
parent 642486ac7e
commit 5443d30282
3 changed files with 25 additions and 26 deletions

View File

@ -39,13 +39,12 @@ 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), /*virtual*/ UDPInterface::~UDPInterface() {
_local_port(local_port) stop();
{ }
IN(true); bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int local_port /*= DEFAULT_UDP_PORT*/, const char* local_host /*=nullptr*/) {
OUT(true); online(false);
bitrate(BITRATE_GUESS);
if (wifi_ssid != nullptr) { if (wifi_ssid != nullptr) {
_wifi_ssid = wifi_ssid; _wifi_ssid = wifi_ssid;
@ -56,15 +55,12 @@ UDPInterface::UDPInterface(const char* wifi_ssid, const char* wifi_password, int
if (local_host != nullptr) { if (local_host != nullptr) {
_local_host = local_host; _local_host = local_host;
} }
} extreme("UDPInterface: wifi ssid: " + _wifi_ssid);
extreme("UDPInterface: wifi password: " + _wifi_password);
extreme("UDPInterface: local host: " + _local_host);
/*virtual*/ UDPInterface::~UDPInterface() { extreme("UDPInterface: local port: " + std::to_string(_remote_port));
stop(); extreme("UDPInterface: remote host: " + _local_host);
} extreme("UDPInterface: remote port: " + std::to_string(_remote_port));
bool UDPInterface::start() {
online(false);
#ifdef ARDUINO #ifdef ARDUINO
// Connect to the WiFi network // Connect to the WiFi network

View File

@ -14,6 +14,10 @@
#include <stdint.h> #include <stdint.h>
#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 { namespace RNS { namespace Interfaces {
class UDPInterface : public Interface { class UDPInterface : public Interface {
@ -27,10 +31,9 @@ namespace RNS { namespace Interfaces {
public: public:
//p def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None): //p def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None):
UDPInterface(const char* name = "UDPInterface"); 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(); 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 stop();
void loop(); void loop();
@ -46,16 +49,16 @@ namespace RNS { namespace Interfaces {
Bytes _buffer; Bytes _buffer;
// WiFi network name and password // WiFi network name and password
std::string _wifi_ssid = ""; std::string _wifi_ssid;
std::string _wifi_password = ""; std::string _wifi_password;
// IP address to send UDP data to. // IP address to send UDP data to.
// it can be ip address of the server or // it can be ip address of the server or
// broadcast // broadcast
std::string _local_host = "0.0.0.0"; std::string _local_host = DEFAULT_UDP_LOCAL_HOST;
int _local_port = 4242; int _local_port = DEFAULT_UDP_PORT;
std::string _remote_host = "255.255.255.255"; std::string _remote_host = DEFAULT_UDP_LOCAL_HOST;
int _remote_port = 4242; int _remote_port = DEFAULT_UDP_PORT;
// create UDP instance // create UDP instance
#ifdef ARDUINO #ifdef ARDUINO

View File

@ -267,7 +267,7 @@ void setup_reticulum() {
#ifdef UDP_INTERFACE #ifdef UDP_INTERFACE
RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME); RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME);
udp_interface.start(); udp_interface.start("some_ssid", "some_password");
#endif #endif
#ifdef LORA_INTERFACE #ifdef LORA_INTERFACE