M2X Ethernet demo using Seeed Ethernet W5200 Shield

Dependencies:   LM75B M2XStreamClient jsonlite mbed-rtos mbed Nucleo_Sensor_Shield

Fork of m2x-seeed_ethernet_demo by Sean Newton

Committer:
dangriffin
Date:
Wed Dec 17 20:45:13 2014 +0000
Revision:
11:40d8cfc941ed
Parent:
7:a94ba2e0cd04
Use the public Nucleo Sensor Shield library.

Who changed what in which revision?

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