Welcome to mirror list, hosted at ThFree Co, Russian Federation.

W5500Interface.h « W5500Ethernet « Networking « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e01768917fa1b9caaa909dbce9565228adb9a33a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/****************************************************************************************************

RepRapFirmware - Network: RepRapPro Ormerod with Duet controller

Separated out from Platform.h by dc42 and extended by chrishamm

****************************************************************************************************/

#ifndef NETWORK_H
#define NETWORK_H

#include <Networking/NetworkInterface.h>
#include <Networking/NetworkDefs.h>

class NetworkResponder;
class HttpResponder;
class FtpResponder;
class TelnetResponder;
class MdnsResponder;
class W5500Socket;

// We have 8 sockets available on the W5500.
const size_t NumW5500TcpSockets = 6;

const SocketNumber MdnsSocketNumber = 6;
const SocketNumber DhcpSocketNumber = 7;

class Platform;

// The main network class that drives the network.
class W5500Interface : public NetworkInterface
{
public:
	W5500Interface(Platform& p) noexcept;

	void Init() noexcept override;
	void Activate() noexcept override;
	void Exit() noexcept override;
	void Spin() noexcept override;
	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;
	bool IsProtocolEnabled(NetworkProtocol protocol) noexcept override;
	GCodeResult DisableProtocol(NetworkProtocol protocol, const StringRef& reply) noexcept override;
	GCodeResult ReportProtocols(const StringRef& reply) const noexcept override;

	GCodeResult GetNetworkState(const StringRef& reply) noexcept override;
	int EnableState() const noexcept override;
	bool IsWiFiInterface() const noexcept override { return false; }

	void UpdateHostname(const char *name) noexcept override;
	IPAddress GetIPAddress() const noexcept override { return ipAddress; }
	void SetIPAddress(IPAddress p_ipAddress, IPAddress p_netmask, IPAddress p_gateway) noexcept override;
	GCodeResult SetMacAddress(const MacAddress& mac, const StringRef& reply) noexcept override;
	const MacAddress& GetMacAddress() const noexcept override { return macAddress; }

	void OpenDataPort(TcpPort port) noexcept override;
	void TerminateDataPort() noexcept override;

protected:
	DECLARE_OBJECT_MODEL

private:
	void Start() noexcept;
	void Stop() noexcept;
	void InitSockets() noexcept;
	void ResetSockets() noexcept;
	void TerminateSockets() noexcept;

	void ReportOneProtocol(NetworkProtocol protocol, const StringRef& reply) const noexcept
	pre(protocol < NumProtocols);

	Platform& platform;
	uint32_t lastTickMillis;

	W5500Socket *sockets[NumW5500TcpSockets];
	size_t ftpDataSocket;							// number of the port for FTP DATA connections
	size_t nextSocketToPoll;						// next TCP socket number to poll for read/write operations

	W5500Socket *mdnsSocket;
	MdnsResponder *mdnsResponder;

	TcpPort portNumbers[NumProtocols];					// port number used for each protocol
	bool protocolEnabled[NumProtocols];				// whether each protocol is enabled

	bool activated;
	bool usingDhcp;

	IPAddress ipAddress;
	IPAddress netmask;
	IPAddress gateway;
	MacAddress macAddress;
};

#endif