@@ -46,20 +46,79 @@ typedef enum {
4646} wl_status_t ;
4747
4848class EthernetImpl {
49- public:
50- IPAddress& localIP () {
51- SocketImpl sock;
52- adress.fromString (sock.getIPAddress ());
53- return adress;
49+ public:
50+ EthernetImpl () {
51+ // Set some defaults
52+ _macAddress[0 ] = 0xDE ; _macAddress[1 ] = 0xAD ; _macAddress[2 ] = 0xBE ; _macAddress[3 ] = 0xEF ; _macAddress[4 ] = 0xFE ; _macAddress[5 ] = 0xED ;
53+ _localIP = IPAddress (192 ,168 ,1 ,177 );
54+ _subnetMask = IPAddress (255 ,255 ,255 ,0 );
55+ _gatewayIP = IPAddress (192 ,168 ,1 ,1 );
56+ _dnsServerIP = IPAddress (8 ,8 ,8 ,8 );
57+ _hardwareStatus = 1 ; // Assume present
58+ _linkStatus = 2 ; // Assume linkON
59+ _retransmissionCount = 8 ;
60+ _retransmissionTimeout = 2000 ;
5461 }
5562
56- // / To be compatible with Ethernet library: do nothing
57- bool begin (uint8_t macAddress[6 ] ) { return true ;}
58- // / To be compatible with Ethernet library: do nothing
59- bool begin (uint8_t macAddress[6 ], IPAddress staticIP, IPAddress staticDNS, IPAddress staticGateway, IPAddress staticSubnet) { return true ;}
63+ // Begin with MAC only
64+ bool begin (uint8_t macAddress[6 ]) {
65+ setMACAddress (macAddress);
66+ return true ;
67+ }
68+ // Begin with full config
69+ bool begin (uint8_t macAddress[6 ], IPAddress localIP, IPAddress dnsServerIP, IPAddress gateway, IPAddress subnet) {
70+ setMACAddress (macAddress);
71+ setLocalIP (localIP);
72+ setDnsServerIP (dnsServerIP);
73+ setGatewayIP (gateway);
74+ setSubnetMask (subnet);
75+ return true ;
76+ }
6077
61- protected:
62- IPAddress adress;
78+ // Returns the local IP address
79+ IPAddress localIP () { return _localIP; }
80+ // Returns the subnet mask
81+ IPAddress subnetMask () { return _subnetMask; }
82+ // Returns the gateway IP
83+ IPAddress gatewayIP () { return _gatewayIP; }
84+ // Returns the DNS server IP
85+ IPAddress dnsServerIP () { return _dnsServerIP; }
86+ // Returns the MAC address
87+ void MACAddress (uint8_t * mac) { for (int i=0 ; i<6 ; ++i) mac[i] = _macAddress[i]; }
88+ // Set the MAC address
89+ void setMACAddress (const uint8_t * mac) { for (int i=0 ; i<6 ; ++i) _macAddress[i] = mac[i]; }
90+ // Set the local IP
91+ void setLocalIP (const IPAddress& ip) { _localIP = ip; }
92+ // Set the subnet mask
93+ void setSubnetMask (const IPAddress& mask) { _subnetMask = mask; }
94+ // Set the gateway IP
95+ void setGatewayIP (const IPAddress& ip) { _gatewayIP = ip; }
96+ // Set the DNS server IP
97+ void setDnsServerIP (const IPAddress& ip) { _dnsServerIP = ip; }
98+ // Set retransmission count
99+ void setRetransmissionCount (uint8_t count) { _retransmissionCount = count; }
100+ // Set retransmission timeout
101+ void setRetransmissionTimeout (uint16_t timeout) { _retransmissionTimeout = timeout; }
102+
103+ // Returns hardware status (1 = present, 0 = absent)
104+ int hardwareStatus () { return _hardwareStatus; }
105+ // Returns link status (2 = linkON, 1 = linkOFF, 0 = unknown)
106+ int linkStatus () { return _linkStatus; }
107+ // Init (returns true for compatibility)
108+ bool init (uint8_t socketCount = 4 ) { _hardwareStatus = 1 ; return true ; }
109+ // Maintain (returns 0 for compatibility)
110+ int maintain () { return 0 ; }
111+
112+ protected:
113+ uint8_t _macAddress[6 ];
114+ IPAddress _localIP;
115+ IPAddress _subnetMask;
116+ IPAddress _gatewayIP;
117+ IPAddress _dnsServerIP;
118+ int _hardwareStatus = 1 ; // 1 = present, 0 = absent
119+ int _linkStatus = 2 ; // 2 = linkON, 1 = linkOFF, 0 = unknown
120+ uint8_t _retransmissionCount = 8 ;
121+ uint16_t _retransmissionTimeout = 2000 ;
63122};
64123
65124inline EthernetImpl Ethernet;
0 commit comments