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.
Dependents: HTTPClient_HelloWorld_WIZ550io NTPClient_HelloWorld_WIZ550io
Fork of WIZ820ioInterface by
WIZ550ioInterface.cpp
00001 // WIZ550ioInterface.cpp 2013/4/5 00002 #include "WIZ550ioInterface.h" 00003 #include "DHCPClient.h" 00004 00005 WIZ550ioInterface::WIZ550ioInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) : 00006 WIZ820io(mosi, miso, sclk, cs, reset) 00007 { 00008 ip_set = false; 00009 } 00010 00011 WIZ550ioInterface::WIZ550ioInterface(SPI* spi, PinName cs, PinName reset) : 00012 WIZ820io(spi, cs, reset) 00013 { 00014 ip_set = false; 00015 } 00016 00017 int WIZ550ioInterface::init() 00018 { 00019 dhcp = true; 00020 reset(); 00021 return 0; 00022 } 00023 00024 int WIZ550ioInterface::init(const char* ip, const char* mask, const char* gateway) 00025 { 00026 dhcp = false; 00027 this->ip = str_to_ip(ip); 00028 strcpy(ip_string, ip); 00029 ip_set = true; 00030 this->netmask = str_to_ip(mask); 00031 this->gateway = str_to_ip(gateway); 00032 reset(); 00033 return 0; 00034 } 00035 00036 int WIZ550ioInterface::connect() 00037 { 00038 if (dhcp) { 00039 int r = IPrenew(); 00040 if (r < 0) { 00041 return r; 00042 } 00043 } 00044 if (WIZ820io::join() == false) return -1; 00045 return 0; 00046 } 00047 00048 int WIZ550ioInterface::disconnect() 00049 { 00050 if (WIZ820io::disconnect() == false) return -1; 00051 return 0; 00052 } 00053 00054 char* WIZ550ioInterface::getIPAddress() 00055 { 00056 uint32_t ip = reg_rd<uint32_t>(SIPR); 00057 snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); 00058 return ip_string; 00059 } 00060 00061 char* WIZ550ioInterface::getNetworkMask() 00062 { 00063 uint32_t ip = reg_rd<uint32_t>(SUBR); 00064 snprintf(mask_string, sizeof(mask_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); 00065 return mask_string; 00066 } 00067 00068 char* WIZ550ioInterface::getGateway() 00069 { 00070 uint32_t ip = reg_rd<uint32_t>(GAR); 00071 snprintf(gw_string, sizeof(gw_string), "%d.%d.%d.%d", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff); 00072 return gw_string; 00073 } 00074 00075 char* WIZ550ioInterface::getMACAddress() 00076 { 00077 uint8_t mac[6]; 00078 reg_rd_mac(SHAR, mac); 00079 snprintf(mac_string, sizeof(mac_string), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 00080 return mac_string; 00081 } 00082 00083 int WIZ550ioInterface::IPrenew(int timeout_ms) 00084 { 00085 // printf("DHCP Started, waiting for IP...\n"); 00086 DHCPClient dhcp; 00087 int err = dhcp.setup(timeout_ms); 00088 if (err == (-1)) { 00089 // printf("Timeout.\n"); 00090 return -1; 00091 } 00092 // printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]); 00093 ip = (dhcp.yiaddr[0] <<24) | (dhcp.yiaddr[1] <<16) | (dhcp.yiaddr[2] <<8) | dhcp.yiaddr[3]; 00094 gateway = (dhcp.gateway[0]<<24) | (dhcp.gateway[1]<<16) | (dhcp.gateway[2]<<8) | dhcp.gateway[3]; 00095 netmask = (dhcp.netmask[0]<<24) | (dhcp.netmask[1]<<16) | (dhcp.netmask[2]<<8) | dhcp.netmask[3]; 00096 dnsaddr = (dhcp.dnsaddr[0]<<24) | (dhcp.dnsaddr[1]<<16) | (dhcp.dnsaddr[2]<<8) | dhcp.dnsaddr[3]; 00097 return 0; 00098 }
Generated on Wed Jul 13 2022 06:19:25 by
1.7.2
