Skip to content

Commit

Permalink
Support outgoing connection on M586
Browse files Browse the repository at this point in the history
  • Loading branch information
rechrtb committed Oct 25, 2022
1 parent 9992576 commit d88e0b7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions src/Networking/ESP8266WiFi/WiFiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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);

Expand All @@ -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:
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/Networking/ESP8266WiFi/WiFiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Networking/LwipEthernet/LwipEthernetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Networking/LwipEthernet/LwipEthernetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/Networking/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Networking/Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Networking/NetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d88e0b7

Please sign in to comment.