Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit e0ea079

Browse files
authored
Update Ethernet Libraries', Packages' Patches and README.md
Update Ethernet Libraries', Packages' Patches and README.md
1 parent c066d08 commit e0ea079

File tree

12 files changed

+2357
-20
lines changed

12 files changed

+2357
-20
lines changed
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
/*
2+
modified 12 Aug 2013
3+
by Soohwan Kim (suhwan@wiznet.co.kr)
4+
5+
- 10 Apr. 2015
6+
Added support for Arduino Ethernet Shield 2
7+
by Arduino.org team
8+
9+
*/
10+
11+
#include "Ethernet2.h"
12+
#include "Dhcp.h"
13+
14+
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
15+
uint8_t EthernetClass::_state[MAX_SOCK_NUM] = { 0, };
16+
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, };
17+
18+
19+
20+
#if defined(WIZ550io_WITH_MACADDRESS)
21+
int EthernetClass::begin(void)
22+
{
23+
// KH mod to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
24+
// Now store to private var _mac_address
25+
//byte mac_address[6] ={0,};
26+
//////
27+
28+
if (_dhcp != NULL) {
29+
delete _dhcp;
30+
}
31+
_dhcp = new DhcpClass();
32+
33+
// Initialise the basic info
34+
w5500.init(w5500_cspin);
35+
w5500.setIPAddress(IPAddress(0,0,0,0).raw_address());
36+
37+
// KH mod
38+
w5500.getMACAddress(_mac_address);
39+
40+
// Now try to get our config info from a DHCP server
41+
int ret = _dhcp->beginWithDHCP(_mac_address);
42+
//////
43+
44+
if(ret == 1)
45+
{
46+
// We've successfully found a DHCP server and got our configuration info, so set things
47+
// accordingly
48+
w5500.setIPAddress(_dhcp->getLocalIp().raw_address());
49+
w5500.setGatewayIp(_dhcp->getGatewayIp().raw_address());
50+
w5500.setSubnetMask(_dhcp->getSubnetMask().raw_address());
51+
_dnsServerAddress = _dhcp->getDnsServerIp();
52+
_dnsDomainName = _dhcp->getDnsDomainName();
53+
_hostName = _dhcp->getHostName();
54+
}
55+
56+
return ret;
57+
}
58+
59+
void EthernetClass::begin(IPAddress local_ip)
60+
{
61+
// Assume the DNS server will be the machine on the same network as the local IP
62+
// but with last octet being '1'
63+
IPAddress dns_server = local_ip;
64+
dns_server[3] = 1;
65+
begin(local_ip, dns_server);
66+
}
67+
68+
void EthernetClass::begin(IPAddress local_ip, IPAddress dns_server)
69+
{
70+
// Assume the gateway will be the machine on the same network as the local IP
71+
// but with last octet being '1'
72+
IPAddress gateway = local_ip;
73+
gateway[3] = 1;
74+
begin(local_ip, dns_server, gateway);
75+
}
76+
77+
void EthernetClass::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
78+
{
79+
IPAddress subnet(255, 255, 255, 0);
80+
begin(local_ip, dns_server, gateway, subnet);
81+
}
82+
83+
void EthernetClass::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
84+
{
85+
w5500.init(w5500_cspin);
86+
w5500.setIPAddress(local_ip.raw_address());
87+
w5500.setGatewayIp(gateway.raw_address());
88+
w5500.setSubnetMask(subnet.raw_address());
89+
_dnsServerAddress = dns_server;
90+
}
91+
#else
92+
int EthernetClass::begin(uint8_t *mac_address)
93+
{
94+
// KH mod to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
95+
// Now store to private var
96+
//uint8_t _mac_address[6] ={0,};
97+
memcpy(_mac_address, mac_address, sizeof(_mac_address));
98+
//////
99+
100+
if (_dhcp != NULL) {
101+
delete _dhcp;
102+
}
103+
_dhcp = new DhcpClass();
104+
// Initialise the basic info
105+
w5500.init(w5500_cspin);
106+
w5500.setMACAddress(mac_address);
107+
w5500.setIPAddress(IPAddress(0,0,0,0).raw_address());
108+
109+
// Now try to get our config info from a DHCP server
110+
int ret = _dhcp->beginWithDHCP(mac_address);
111+
if(ret == 1)
112+
{
113+
// We've successfully found a DHCP server and got our configuration info, so set things
114+
// accordingly
115+
w5500.setIPAddress(_dhcp->getLocalIp().raw_address());
116+
w5500.setGatewayIp(_dhcp->getGatewayIp().raw_address());
117+
w5500.setSubnetMask(_dhcp->getSubnetMask().raw_address());
118+
_dnsServerAddress = _dhcp->getDnsServerIp();
119+
_dnsDomainName = _dhcp->getDnsDomainName();
120+
_hostName = _dhcp->getHostName();
121+
}
122+
123+
return ret;
124+
}
125+
126+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
127+
{
128+
// KH mod to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
129+
// Now store to private var
130+
//uint8_t _mac_address[6] ={0,};
131+
memcpy(_mac_address, mac_address, sizeof(_mac_address));
132+
//////
133+
134+
// Assume the DNS server will be the machine on the same network as the local IP
135+
// but with last octet being '1'
136+
IPAddress dns_server = local_ip;
137+
dns_server[3] = 1;
138+
begin(mac_address, local_ip, dns_server);
139+
}
140+
141+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
142+
{
143+
// KH mod to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
144+
// Now store to private var
145+
//uint8_t _mac_address[6] ={0,};
146+
memcpy(_mac_address, mac_address, sizeof(_mac_address));
147+
//////
148+
149+
// Assume the gateway will be the machine on the same network as the local IP
150+
// but with last octet being '1'
151+
IPAddress gateway = local_ip;
152+
gateway[3] = 1;
153+
begin(mac_address, local_ip, dns_server, gateway);
154+
}
155+
156+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
157+
{
158+
// KH mod to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
159+
// Now store to private var
160+
//uint8_t _mac_address[6] ={0,};
161+
memcpy(_mac_address, mac_address, sizeof(_mac_address));
162+
//////
163+
164+
IPAddress subnet(255, 255, 255, 0);
165+
begin(mac_address, local_ip, dns_server, gateway, subnet);
166+
}
167+
168+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
169+
{
170+
// KH mod to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
171+
// Now store to private var
172+
//uint8_t _mac_address[6] ={0,};
173+
memcpy(_mac_address, mac_address, sizeof(_mac_address));
174+
//////
175+
176+
w5500.init(w5500_cspin);
177+
w5500.setMACAddress(mac_address);
178+
w5500.setIPAddress(local_ip.raw_address());
179+
w5500.setGatewayIp(gateway.raw_address());
180+
w5500.setSubnetMask(subnet.raw_address());
181+
_dnsServerAddress = dns_server;
182+
}
183+
184+
#endif
185+
186+
int EthernetClass::maintain(){
187+
int rc = DHCP_CHECK_NONE;
188+
if(_dhcp != NULL){
189+
//we have a pointer to dhcp, use it
190+
rc = _dhcp->checkLease();
191+
switch ( rc ){
192+
case DHCP_CHECK_NONE:
193+
//nothing done
194+
break;
195+
case DHCP_CHECK_RENEW_OK:
196+
case DHCP_CHECK_REBIND_OK:
197+
//we might have got a new IP.
198+
w5500.setIPAddress(_dhcp->getLocalIp().raw_address());
199+
w5500.setGatewayIp(_dhcp->getGatewayIp().raw_address());
200+
w5500.setSubnetMask(_dhcp->getSubnetMask().raw_address());
201+
_dnsServerAddress = _dhcp->getDnsServerIp();
202+
_dnsDomainName = _dhcp->getDnsDomainName();
203+
_hostName = _dhcp->getHostName();
204+
break;
205+
default:
206+
//this is actually a error, it will retry though
207+
break;
208+
}
209+
}
210+
return rc;
211+
}
212+
213+
IPAddress EthernetClass::localIP()
214+
{
215+
IPAddress ret;
216+
w5500.getIPAddress(ret.raw_address());
217+
return ret;
218+
}
219+
220+
IPAddress EthernetClass::subnetMask()
221+
{
222+
IPAddress ret;
223+
w5500.getSubnetMask(ret.raw_address());
224+
return ret;
225+
}
226+
227+
IPAddress EthernetClass::gatewayIP()
228+
{
229+
IPAddress ret;
230+
w5500.getGatewayIp(ret.raw_address());
231+
return ret;
232+
}
233+
234+
IPAddress EthernetClass::dnsServerIP()
235+
{
236+
return _dnsServerAddress;
237+
}
238+
239+
char* EthernetClass::dnsDomainName(){
240+
return _dnsDomainName;
241+
}
242+
243+
char* EthernetClass::hostName(){
244+
return _hostName;
245+
}
246+
247+
EthernetClass Ethernet;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
modified 12 Aug 2013
3+
by Soohwan Kim (suhwan@wiznet.co.kr)
4+
5+
- 10 Apr. 2015
6+
Added support for Arduino Ethernet Shield 2
7+
by Arduino.org team
8+
9+
*/
10+
#ifndef ethernet_h
11+
#define ethernet_h
12+
13+
#include <inttypes.h>
14+
#include "utility/w5500.h"
15+
#include "IPAddress.h"
16+
#include "EthernetClient.h"
17+
#include "EthernetServer.h"
18+
#include "Dhcp.h"
19+
20+
21+
22+
class EthernetClass {
23+
private:
24+
IPAddress _dnsServerAddress;
25+
char* _dnsDomainName;
26+
char* _hostName;
27+
DhcpClass* _dhcp;
28+
29+
// KH add to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+
30+
uint8_t _mac_address[6] ={0,};
31+
//////
32+
33+
public:
34+
uint8_t w5500_cspin;
35+
36+
static uint8_t _state[MAX_SOCK_NUM];
37+
static uint16_t _server_port[MAX_SOCK_NUM];
38+
39+
EthernetClass() { _dhcp = NULL; w5500_cspin = 10; }
40+
void init(uint8_t _cspin = 10) { w5500_cspin = _cspin; }
41+
42+
#if defined(WIZ550io_WITH_MACADDRESS)
43+
// Initialize function when use the ioShield serise (included WIZ550io)
44+
// WIZ550io has a MAC address which is written after reset.
45+
// Default IP, Gateway and subnet address are also writen.
46+
// so, It needs some initial time. please refer WIZ550io Datasheet in details.
47+
int begin(void);
48+
void begin(IPAddress local_ip);
49+
void begin(IPAddress local_ip, IPAddress dns_server);
50+
void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
51+
void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
52+
#else
53+
// Initialize the Ethernet shield to use the provided MAC address and gain the rest of the
54+
// configuration through DHCP.
55+
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
56+
int begin(uint8_t *mac_address);
57+
void begin(uint8_t *mac_address, IPAddress local_ip);
58+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
59+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
60+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
61+
62+
#endif
63+
64+
int maintain();
65+
66+
// KH add to have similar function to Ethernet lib
67+
// Certainly we can use void macAddress(uint8_t mac[]) to read from W5x00.
68+
void MACAddress(uint8_t *mac_address)
69+
{
70+
memcpy(mac_address, _mac_address, sizeof(_mac_address));
71+
}
72+
//////
73+
74+
IPAddress localIP();
75+
IPAddress subnetMask();
76+
IPAddress gatewayIP();
77+
IPAddress dnsServerIP();
78+
char* dnsDomainName();
79+
char* hostName();
80+
81+
friend class EthernetClient;
82+
friend class EthernetServer;
83+
};
84+
85+
extern EthernetClass Ethernet;
86+
87+
#endif

0 commit comments

Comments
 (0)