WIZNet W5500 with additional enhancements
Fork of WIZnetInterface by
Diff: EthernetInterface.cpp
- Revision:
- 35:fe3028eda085
- Parent:
- 34:7d44648ec5f2
- Child:
- 36:0ba2e8d5274a
--- a/EthernetInterface.cpp Mon Oct 09 19:58:19 2017 +0200
+++ b/EthernetInterface.cpp Tue Oct 10 20:56:13 2017 +0200
@@ -24,15 +24,25 @@
WIZnet_Chip(mosi, miso, sclk, cs, reset)
{
ip_set = false;
+ domainName = NULL;
+ leaseStart = 0;
}
EthernetInterface::EthernetInterface(SPI* spi, PinName cs, PinName reset) :
WIZnet_Chip(spi, cs, reset)
{
ip_set = false;
+ domainName = NULL;
+ leaseStart = 0;
}
#endif
+EthernetInterface::~EthernetInterface()
+{
+ if (domainName)
+ free(domainName);
+}
+
int EthernetInterface::init()
{
dhcp = true;
@@ -83,7 +93,6 @@
return r;
}
}
-
if (WIZnet_Chip::setip() == false) return -1;
return 0;
}
@@ -151,6 +160,7 @@
}
+
int EthernetInterface::IPrenew(int timeout_ms)
{
DHCPClient dhcp;
@@ -159,10 +169,24 @@
return -1;
}
// printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]);
+ /*
+ * Sync DHCP response variables
+ */
ip = (dhcp.yiaddr[0] <<24) | (dhcp.yiaddr[1] <<16) | (dhcp.yiaddr[2] <<8) | dhcp.yiaddr[3];
gateway = (dhcp.gateway[0]<<24) | (dhcp.gateway[1]<<16) | (dhcp.gateway[2]<<8) | dhcp.gateway[3];
netmask = (dhcp.netmask[0]<<24) | (dhcp.netmask[1]<<16) | (dhcp.netmask[2]<<8) | dhcp.netmask[3];
dnsaddr = (dhcp.dnsaddr[0]<<24) | (dhcp.dnsaddr[1]<<16) | (dhcp.dnsaddr[2]<<8) | dhcp.dnsaddr[3];
+ timesrv = (dhcp.timesrv[0]<<24) | (dhcp.timesrv[1]<<16) | (dhcp.timesrv[2]<<8) | dhcp.timesrv[3];
+ leaseTime = (dhcp.leaseTime[0]<<24) | (dhcp.leaseTime[1]<<16) | (dhcp.leaseTime[2]<<8) | dhcp.leaseTime[3];
+ leaseStart = time(NULL);
+ if (domainName) {
+ free(domainName);
+ domainName = NULL;
+ }
+ if (dhcp.domainName) {
+ domainName = dhcp.domainName;
+ dhcp.domainName = NULL;
+ }
return 0;
}
Helmut Tschemernjak
