From d88e0b727043af65d3bdcb841ef001a22385af7d Mon Sep 17 00:00:00 2001 From: rechrtb Date: Fri, 14 Oct 2022 17:58:01 +0800 Subject: [PATCH] Support outgoing connection on M586 --- src/GCodes/GCodes2.cpp | 5 ++++- src/Networking/ESP8266WiFi/WiFiInterface.cpp | 12 ++++++------ src/Networking/ESP8266WiFi/WiFiInterface.h | 6 +++--- .../LwipEthernet/LwipEthernetInterface.cpp | 2 +- src/Networking/LwipEthernet/LwipEthernetInterface.h | 2 +- src/Networking/Network.cpp | 4 ++-- src/Networking/Network.h | 2 +- src/Networking/NetworkInterface.h | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index 11abc2493f..ca4c0b70ea 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -3787,7 +3787,10 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx { const int port = (gb.Seen('R')) ? gb.GetIValue() : -1; const int secure = (gb.Seen('T')) ? gb.GetIValue() : -1; - result = reprap.GetNetwork().EnableProtocol(interface, protocol, port, secure, reply); + + int localPort = 0; + int remoteIp = 4094339264; + result = reprap.GetNetwork().EnableProtocol(interface, protocol, port, localPort, remoteIp, secure, reply); } else { diff --git a/src/Networking/ESP8266WiFi/WiFiInterface.cpp b/src/Networking/ESP8266WiFi/WiFiInterface.cpp index 6d4ff32e61..1963b8a34f 100644 --- a/src/Networking/ESP8266WiFi/WiFiInterface.cpp +++ b/src/Networking/ESP8266WiFi/WiFiInterface.cpp @@ -300,7 +300,7 @@ WiFiInterface::WiFiInterface(Platform& p) noexcept for (size_t i = 0; i < NumProtocols; ++i) { portNumbers[i] = DefaultPortNumbers[i]; - protocolEnabled[i] = (i == HttpProtocol) || (i == HelloHiProtocol); + protocolEnabled[i] = (i == HttpProtocol); } strcpy(actualSsid, "(unknown)"); @@ -359,7 +359,7 @@ void WiFiInterface::Init() noexcept currentSocket = 0; } -GCodeResult WiFiInterface::EnableProtocol(NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept +GCodeResult WiFiInterface::EnableProtocol(NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept { if (secure != 0 && secure != -1) { @@ -382,7 +382,7 @@ GCodeResult WiFiInterface::EnableProtocol(NetworkProtocol protocol, int port, in protocolEnabled[protocol] = true; if (GetState() == NetworkState::active) { - StartProtocol(protocol); + StartProtocol(protocol, localPort, remoteIp); // mDNS announcement is done by the WiFi Server firmware } } @@ -413,7 +413,7 @@ GCodeResult WiFiInterface::DisableProtocol(NetworkProtocol protocol, const Strin return GCodeResult::error; } -void WiFiInterface::StartProtocol(NetworkProtocol protocol) noexcept +void WiFiInterface::StartProtocol(NetworkProtocol protocol, int localPort = -1, uint32_t remoteIp = 0) noexcept { MutexLocker lock(interfaceMutex); @@ -432,7 +432,7 @@ void WiFiInterface::StartProtocol(NetworkProtocol protocol) noexcept break; case HelloHiProtocol: - SendConnectCommand(portNumbers[protocol], protocol, 4094339264); + SendConnectCommand(portNumbers[protocol], protocol, localPort, remoteIp); break; default: @@ -2030,7 +2030,7 @@ void WiFiInterface::SendListenCommand(TcpPort port, NetworkProtocol protocol, un SendCommand(NetworkCommand::networkListen, 0, 0, 0, &lcb, sizeof(lcb), nullptr, 0); } -void WiFiInterface::SendConnectCommand(TcpPort port, NetworkProtocol protocol, uint32_t ip) noexcept +void WiFiInterface::SendConnectCommand(TcpPort port, NetworkProtocol protocol, int localPort, uint32_t ip) noexcept { ListenOrConnectData lcb; memset(&lcb, 0, sizeof(lcb)); diff --git a/src/Networking/ESP8266WiFi/WiFiInterface.h b/src/Networking/ESP8266WiFi/WiFiInterface.h index 7a03524ba6..411cdf16a9 100644 --- a/src/Networking/ESP8266WiFi/WiFiInterface.h +++ b/src/Networking/ESP8266WiFi/WiFiInterface.h @@ -61,7 +61,7 @@ class WiFiInterface : public NetworkInterface void Stop() noexcept; GCodeResult EnableInterface(int mode, const StringRef& ssid, const StringRef& reply) noexcept override; // enable or disable the network - GCodeResult EnableProtocol(NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept override; + GCodeResult EnableProtocol(NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept override; GCodeResult DisableProtocol(NetworkProtocol protocol, const StringRef& reply) noexcept override; GCodeResult ReportProtocols(const StringRef& reply) const noexcept override; @@ -103,7 +103,7 @@ class WiFiInterface : public NetworkInterface void TerminateSockets(TcpPort port) noexcept; void StopListening(TcpPort port) noexcept; - void StartProtocol(NetworkProtocol protocol) noexcept + void StartProtocol(NetworkProtocol protocol, int localPort, uint32_t remoteIp) noexcept pre(protocol < NumProtocols); void ShutdownProtocol(NetworkProtocol protocol) noexcept @@ -124,7 +124,7 @@ class WiFiInterface : public NetworkInterface } void SendListenCommand(TcpPort port, NetworkProtocol protocol, unsigned int maxConnections) noexcept; - void SendConnectCommand(TcpPort port, NetworkProtocol protocol, uint32_t ip) noexcept; + void SendConnectCommand(TcpPort port, NetworkProtocol protocol, int localPort, uint32_t remoteIp) noexcept; void GetNewStatus() noexcept; void spi_slave_dma_setup(uint32_t dataOutSize, uint32_t dataInSize) noexcept; diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp index 0430a81ce7..a4ad2fab49 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp @@ -155,7 +155,7 @@ void LwipEthernetInterface::Init() noexcept macAddress = platform.GetDefaultMacAddress(); } -GCodeResult LwipEthernetInterface::EnableProtocol(NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept +GCodeResult LwipEthernetInterface::EnableProtocol(NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept { if (secure != 0 && secure != -1) { diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.h b/src/Networking/LwipEthernet/LwipEthernetInterface.h index e1a34da562..bdfeadbe6c 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.h +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.h @@ -39,7 +39,7 @@ class LwipEthernetInterface : public NetworkInterface void Diagnostics(MessageType mtype) noexcept override; GCodeResult EnableInterface(int mode, const StringRef& ssid, const StringRef& reply) noexcept override; // enable or disable the network - GCodeResult EnableProtocol(NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept override; + GCodeResult EnableProtocol(NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept override; GCodeResult DisableProtocol(NetworkProtocol protocol, const StringRef& reply) noexcept override; GCodeResult ReportProtocols(const StringRef& reply) const noexcept override; diff --git a/src/Networking/Network.cpp b/src/Networking/Network.cpp index cc8e1dbb2f..b98048d6d0 100644 --- a/src/Networking/Network.cpp +++ b/src/Networking/Network.cpp @@ -216,12 +216,12 @@ void Network::CreateAdditionalInterface() noexcept #endif -GCodeResult Network::EnableProtocol(unsigned int interface, NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept +GCodeResult Network::EnableProtocol(unsigned int interface, NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept { #if HAS_NETWORKING if (interface < GetNumNetworkInterfaces()) { - return interfaces[interface]->EnableProtocol(protocol, port, secure, reply); + return interfaces[interface]->EnableProtocol(protocol, port, localPort, remoteIp, secure, reply); } reply.printf("Invalid network interface '%d'\n", interface); diff --git a/src/Networking/Network.h b/src/Networking/Network.h index c78babcd54..68a65fe7c2 100644 --- a/src/Networking/Network.h +++ b/src/Networking/Network.h @@ -85,7 +85,7 @@ class Network INHERIT_OBJECT_MODEL #endif GCodeResult EnableInterface(unsigned int interface, int mode, const StringRef& ssid, const StringRef& reply) noexcept; - GCodeResult EnableProtocol(unsigned int interface, NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept; + GCodeResult EnableProtocol(unsigned int interface, NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept; GCodeResult DisableProtocol(unsigned int interface, NetworkProtocol protocol, const StringRef& reply) noexcept; GCodeResult ReportProtocols(unsigned int interface, const StringRef& reply) const noexcept; diff --git a/src/Networking/NetworkInterface.h b/src/Networking/NetworkInterface.h index b6279eef3a..be71209922 100644 --- a/src/Networking/NetworkInterface.h +++ b/src/Networking/NetworkInterface.h @@ -28,7 +28,7 @@ class NetworkInterface INHERIT_OBJECT_MODEL virtual int EnableState() const noexcept = 0; virtual bool IsWiFiInterface() const noexcept = 0; - virtual GCodeResult EnableProtocol(NetworkProtocol protocol, int port, int secure, const StringRef& reply) noexcept = 0; + virtual GCodeResult EnableProtocol(NetworkProtocol protocol, int port, int localPort, uint32_t remoteIp, int secure, const StringRef& reply) noexcept = 0; virtual bool IsProtocolEnabled(NetworkProtocol protocol) noexcept { return protocolEnabled[protocol]; } virtual TcpPort GetProtocolPort(NetworkProtocol protocol) noexcept { return portNumbers[protocol]; } virtual GCodeResult DisableProtocol(NetworkProtocol protocol, const StringRef& reply) noexcept = 0;