W5200(WIZ820io) network interface
Embed:
(wiki syntax)
Show/hide line numbers
W5200NetIf.cpp
00001 // W5200NetIf.cpp 2012/4/13 00002 #include "W5200NetIf.h" 00003 #include "DHCPClient.h" 00004 #include "w5100.h" 00005 00006 W5200NetIf:: W5200NetIf():MyNetIf(), m_netmask(255,255,255,255), m_gateway(), m_hostname(NULL) { 00007 m_hostname = NULL; 00008 m_useDhcp = true; 00009 } 00010 00011 W5200NetIf::W5200NetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns) :MyNetIf(), m_hostname(NULL) { 00012 m_hostname = NULL; 00013 m_ip = ip; 00014 m_netmask = netmask; 00015 m_gateway = gateway; 00016 m_dns = dns; 00017 m_useDhcp = false; 00018 } 00019 00020 W5200Err W5200NetIf::IPrenew(int timeout_ms) { 00021 printf("DHCP Started, waiting for IP...\n"); 00022 DHCPClient dhcp; 00023 int err = dhcp.setup(timeout_ms); 00024 if (err == (-1)) { 00025 printf("Timeout.\n"); 00026 return W5200_TIMEOUT; 00027 } 00028 printf("Connected, IP: %d.%d.%d.%d\n", dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]); 00029 m_ip = IpAddr(dhcp.yiaddr[0], dhcp.yiaddr[1], dhcp.yiaddr[2], dhcp.yiaddr[3]); 00030 m_netmask = IpAddr(dhcp.netmask[0],dhcp.netmask[1],dhcp.netmask[2],dhcp.netmask[3]); 00031 m_gateway = IpAddr(dhcp.gateway[0],dhcp.gateway[1],dhcp.gateway[2],dhcp.gateway[3]); 00032 uint8_t t[4]; 00033 t[0] = m_ip[0]; 00034 t[1] = m_ip[1]; 00035 t[2] = m_ip[2]; 00036 t[3] = m_ip[3]; 00037 W5100.writeSIPR(t); 00038 t[0] = m_netmask[0]; 00039 t[1] = m_netmask[1]; 00040 t[2] = m_netmask[2]; 00041 t[3] = m_netmask[3]; 00042 W5100.writeSUBR(t); 00043 t[0] = m_gateway[0]; 00044 t[1] = m_gateway[1]; 00045 t[2] = m_gateway[2]; 00046 t[3] = m_gateway[3]; 00047 W5100.writeGAR(t); 00048 m_dns = IpAddr(dhcp.dnsaddr[0],dhcp.dnsaddr[1],dhcp.dnsaddr[2],dhcp.dnsaddr[3]); 00049 return W5200_OK; 00050 } 00051 00052 W5200Err W5200NetIf::IPrelease(int timeout_ms) { 00053 return W5200_OK; 00054 } 00055 00056 W5200Err W5200NetIf::setup(int timeout_ms) { 00057 MyNetIf::init(); 00058 uint8_t mac[6] = {0x00,0x00,0x5e,0x00,0x01,0x01}; 00059 W5100.setMACAddress(mac); 00060 printf("HW Addr is : %02x:%02x:%02x:%02x:%02x:%02x.\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); 00061 if(! m_useDhcp) { 00062 return W5200_OK; 00063 } 00064 return IPrenew(timeout_ms); 00065 }
Generated on Tue Jul 12 2022 19:58:52 by 1.7.2