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(); } }
DHCPClient.h@1:22b9052d864d, 2013-03-24 (annotated)
- Committer:
- va009039
- Date:
- Sun Mar 24 11:25:31 2013 +0000
- Revision:
- 1:22b9052d864d
- Parent:
- 0:bdeec5f86894
WIZ820io(W8200) ethernet interface, EthernetNetIf compatible.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:bdeec5f86894 | 1 | // DHCPClient.h 2012/4/21 |
va009039 | 0:bdeec5f86894 | 2 | #ifndef DHCPCLIENT_H |
va009039 | 0:bdeec5f86894 | 3 | #define DHCPCLIENT_H |
va009039 | 0:bdeec5f86894 | 4 | #include "UDPSocket.h" |
va009039 | 0:bdeec5f86894 | 5 | |
va009039 | 0:bdeec5f86894 | 6 | |
va009039 | 0:bdeec5f86894 | 7 | #define DHCP_OFFSET_OP 0 |
va009039 | 0:bdeec5f86894 | 8 | #define DHCP_OFFSET_XID 4 |
va009039 | 0:bdeec5f86894 | 9 | #define DHCP_OFFSET_YIADDR 16 |
va009039 | 0:bdeec5f86894 | 10 | #define DHCP_OFFSET_CHADDR 28 |
va009039 | 0:bdeec5f86894 | 11 | #define DHCP_OFFSET_MAGIC_COOKIE 236 |
va009039 | 0:bdeec5f86894 | 12 | #define DHCP_OFFSET_OPTIONS 240 |
va009039 | 0:bdeec5f86894 | 13 | #define DHCP_MAX_PACKET_SIZE 600 |
va009039 | 0:bdeec5f86894 | 14 | |
va009039 | 0:bdeec5f86894 | 15 | class DHCPClient { |
va009039 | 0:bdeec5f86894 | 16 | int discover(uint8_t buf[], int size); |
va009039 | 0:bdeec5f86894 | 17 | int request(uint8_t buf[], int size); |
va009039 | 0:bdeec5f86894 | 18 | int offer_ack(uint8_t buf[], int size); |
va009039 | 0:bdeec5f86894 | 19 | bool verify(uint8_t buf[], int len); |
va009039 | 0:bdeec5f86894 | 20 | public: |
va009039 | 0:bdeec5f86894 | 21 | void callback(UDPSocketEvent e); |
va009039 | 0:bdeec5f86894 | 22 | int setup(int timeout_ms = 15000); |
va009039 | 0:bdeec5f86894 | 23 | DHCPClient(); |
va009039 | 0:bdeec5f86894 | 24 | uint8_t chaddr[6]; // MAC |
va009039 | 0:bdeec5f86894 | 25 | uint8_t yiaddr[4]; // IP |
va009039 | 0:bdeec5f86894 | 26 | uint8_t dnsaddr[4]; // DNS |
va009039 | 0:bdeec5f86894 | 27 | uint8_t gateway[4]; |
va009039 | 0:bdeec5f86894 | 28 | uint8_t netmask[4]; |
va009039 | 0:bdeec5f86894 | 29 | private: |
va009039 | 0:bdeec5f86894 | 30 | UDPSocket* m_udp; |
va009039 | 0:bdeec5f86894 | 31 | uint8_t xid[4]; |
va009039 | 0:bdeec5f86894 | 32 | bool exit_flag; |
va009039 | 0:bdeec5f86894 | 33 | Timer m_interval; |
va009039 | 0:bdeec5f86894 | 34 | int m_retry; |
va009039 | 0:bdeec5f86894 | 35 | }; |
va009039 | 0:bdeec5f86894 | 36 | #endif //DHCPCLIENT_H |