W5500 driver for mbed OS 5

Dependents:   http-webserver-example mbed-os-example-sockets

Fork of W5500Interface by Sergei G

Committer:
Bongjun
Date:
Thu Aug 16 07:33:40 2018 +0000
Revision:
18:afec30f0922a
Parent:
6:e2ab76b2be07
change spi frame bits : 32->8

Who changed what in which revision?

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