Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WIZ820ioInterface by
Revision 6:c466db1cd20b, committed 2013-12-01
- Comitter:
- ban4jp
- Date:
- Sun Dec 01 18:40:14 2013 +0000
- Parent:
- 5:fb15c35d1e28
- Child:
- 7:c0cd6680bcb7
- Commit message:
- Fix: connect() and disconnect() return value; Fix: Debug code disabled; Add: get IPAddress and MACAddress functions;
Changed in this revision
--- a/WIZ820ioInterface.cpp Tue Aug 27 12:50:11 2013 +0000
+++ b/WIZ820ioInterface.cpp Sun Dec 01 18:40:14 2013 +0000
@@ -41,33 +41,56 @@
return r;
}
}
- return join();
+ if (WIZ820io::join() == false) return -1;
+ return 0;
}
int WIZ820ioInterface::disconnect()
{
- return WIZ820io::disconnect();
+ if (WIZ820io::disconnect() == false) return -1;
+ return 0;
}
char* WIZ820ioInterface::getIPAddress()
{
uint32_t ip = reg_rd<uint32_t>(SIPR);
- snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", (ip>>24)&0xff,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff);
- ip_set = true;
+ snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff);
return ip_string;
}
+char* WIZ820ioInterface::getNetworkMask()
+{
+ uint32_t ip = reg_rd<uint32_t>(SUBR);
+ snprintf(mask_string, sizeof(mask_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff);
+ return mask_string;
+}
+
+char* WIZ820ioInterface::getGateway()
+{
+ uint32_t ip = reg_rd<uint32_t>(GAR);
+ snprintf(gw_string, sizeof(gw_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff);
+ return gw_string;
+}
+
+char* WIZ820ioInterface::getMACAddress()
+{
+ uint8_t mac[6];
+ reg_rd_mac(SHAR, mac);
+ snprintf(mac_string, sizeof(mac_string), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ return mac_string;
+}
+
int WIZ820ioInterface::IPrenew(int timeout_ms)
{
- printf("DHCP Started, waiting for IP...\n");
+// printf("DHCP Started, waiting for IP...\n");
DHCPClient dhcp;
int err = dhcp.setup(timeout_ms);
if (err == (-1)) {
- printf("Timeout.\n");
+// printf("Timeout.\n");
return -1;
}
- printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]);
- ip = (dhcp.yiaddr[0]<<24) | (dhcp.yiaddr[1]<<16) | (dhcp.yiaddr[2]<<8) | dhcp.yiaddr[3];
+// printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]);
+ 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];
--- a/WIZ820ioInterface.h Tue Aug 27 12:50:11 2013 +0000
+++ b/WIZ820ioInterface.h Sun Dec 01 18:40:14 2013 +0000
@@ -71,11 +71,17 @@
* @ returns ip address
*/
char* getIPAddress();
+ char* getNetworkMask();
+ char* getGateway();
+ char* getMACAddress();
int IPrenew(int timeout_ms = 15*1000);
private:
char ip_string[20];
+ char mask_string[20];
+ char gw_string[20];
+ char mac_string[20];
bool ip_set;
};
--- a/pico_string.h Tue Aug 27 12:50:11 2013 +0000
+++ b/pico_string.h Sun Dec 01 18:40:14 2013 +0000
@@ -1,4 +1,4 @@
-// pico_tring.h 2013/8/27
+// pico_string.h 2013/8/27
#pragma once
class pico_string {
public:
