WIZ820io(W5200) network interface、EthernetNetIf compatible.

/media/uploads/va009039/wiz820ionetif.jpg

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();
    }
}
Committer:
va009039
Date:
Fri Mar 22 11:51:24 2013 +0000
Revision:
0:bdeec5f86894
[mbed] converted /w5200NetIf/w5200NetIf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:bdeec5f86894 1 // dnsname.h 2012/4/13
va009039 0:bdeec5f86894 2 #ifndef DNSNAME_H
va009039 0:bdeec5f86894 3 #define DNSNAME_H
va009039 0:bdeec5f86894 4 class dnsname {
va009039 0:bdeec5f86894 5 public:
va009039 0:bdeec5f86894 6 uint8_t *buf;
va009039 0:bdeec5f86894 7 string str;
va009039 0:bdeec5f86894 8 dnsname(uint8_t *s) {
va009039 0:bdeec5f86894 9 buf = s;
va009039 0:bdeec5f86894 10 }
va009039 0:bdeec5f86894 11 int decode(int pos) {
va009039 0:bdeec5f86894 12 while(1) {
va009039 0:bdeec5f86894 13 int len = buf[pos++];
va009039 0:bdeec5f86894 14 if (len == 0x00) {
va009039 0:bdeec5f86894 15 break;
va009039 0:bdeec5f86894 16 }
va009039 0:bdeec5f86894 17 if ((len&0xc0) == 0xc0) { //compress
va009039 0:bdeec5f86894 18 int offset = (len&0x3f)<<8|buf[pos];
va009039 0:bdeec5f86894 19 decode(offset);
va009039 0:bdeec5f86894 20 return pos+1;
va009039 0:bdeec5f86894 21 }
va009039 0:bdeec5f86894 22 if (!str.empty()) {
va009039 0:bdeec5f86894 23 str.append(".");
va009039 0:bdeec5f86894 24 }
va009039 0:bdeec5f86894 25 str.append((const char*)(buf+pos), len);
va009039 0:bdeec5f86894 26 pos += len;
va009039 0:bdeec5f86894 27 }
va009039 0:bdeec5f86894 28 return pos;
va009039 0:bdeec5f86894 29 }
va009039 0:bdeec5f86894 30
va009039 0:bdeec5f86894 31 int encode(int pos, char* s) {
va009039 0:bdeec5f86894 32 while(*s) {
va009039 0:bdeec5f86894 33 char *f = strchr(s, '.');
va009039 0:bdeec5f86894 34 if (f == NULL) {
va009039 0:bdeec5f86894 35 int len = strlen(s);
va009039 0:bdeec5f86894 36 buf[pos++] = len;
va009039 0:bdeec5f86894 37 memcpy(buf+pos, s, len);
va009039 0:bdeec5f86894 38 pos += len;
va009039 0:bdeec5f86894 39 break;
va009039 0:bdeec5f86894 40 }
va009039 0:bdeec5f86894 41 int len = f - s;
va009039 0:bdeec5f86894 42 buf[pos++] = len;
va009039 0:bdeec5f86894 43 memcpy(buf+pos, s, len);
va009039 0:bdeec5f86894 44 s = f+1;
va009039 0:bdeec5f86894 45 pos += len;
va009039 0:bdeec5f86894 46 }
va009039 0:bdeec5f86894 47 buf[pos++] = 0x00;
va009039 0:bdeec5f86894 48 return pos;
va009039 0:bdeec5f86894 49 }
va009039 0:bdeec5f86894 50 };
va009039 0:bdeec5f86894 51 #endif //DNSNAME_H