WIZ820io(W5200) network interface、EthernetNetIf compatible.
example
#include "WIZ820ioNetIf.h" #include "HTTPClient.h" #include "HTTPServer.h" #if defined(TARGET_KL25Z) WIZ820ioNetIf eth(PTD2,PTD3,PTD1,PTD0,PTD5); #endif HTTPClient http; HTTPStream stream; void callback(HTTPResult r){ printf("callback %d %s\n", r, HTTPClient::ResultStr(r)); } int main() { int err = eth.setup(); if (err < 0) { printf("setup error %d\n", err); exit(-1); } HTTPServer svr; svr.addHandler<SimpleHandler>("/"); svr.bind(80); const char* uri = "http://va009039-mbed.appspot.com/kl25z/"; http.get(uri, &stream, callback); uint8_t buf[256]; int total = 0; stream.readNext(buf, sizeof(buf)); while(1) { if(stream.readable()) { int len = stream.readLen(); total += len; printf("%d %d\n", total, len); stream.readNext(buf, sizeof(buf)); } Net::poll(); } }
Diff: W5200NetIf.h
- Revision:
- 0:bdeec5f86894
diff -r 000000000000 -r bdeec5f86894 W5200NetIf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/W5200NetIf.h Fri Mar 22 11:51:24 2013 +0000 @@ -0,0 +1,46 @@ +// W5200NetIf.h 2012/4/19 +/** \file +W5200 network interface header file +*/ +#ifndef W5200_NETIF_H +#define W5200_NETIF_H +#include "MyNetIf.h" + +///W5200 network interface return codes +enum W5200Err +{ + __W5200_MIN = -0xFFFF, + W5200_TIMEOUT, ///<Timeout during setup + W5200_SETUP_ERR, + W5200_OK = 0 ///<Success +}; + +///W5200 network interface +class W5200NetIf : public MyNetIf { +public: + ///Instantiates the Interface and register it against the stack, DHCP will be used + W5200NetIf(); //W/ DHCP + ///Instantiates the Interface and register it against the stack, DHCP will not be used + /** + IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address. + */ + W5200NetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP + W5200Err IPrenew(int timeout_ms = 15000); + W5200Err IPrelease(int timeout_ms = 15000); + ///Brings the interface up + /** + Uses DHCP if necessary + @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s + @return : W5200_OK on success or W5200_TIMEOUT on timeout + */ + W5200Err setup(int timeout_ms = 15000); + SPI* attachSPI(SPI* spi); + DigitalOut* attachCS(DigitalOut* cs); + IpAddr m_dns; +private: + bool m_useDhcp; + IpAddr m_netmask; + IpAddr m_gateway; + const char* m_hostname; +}; +#endif //W5200_NETIF_H