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 // pico_string.h 2013/8/27
Bongjun 6:e2ab76b2be07 2 #pragma once
Bongjun 6:e2ab76b2be07 3 class pico_string {
Bongjun 6:e2ab76b2be07 4 public:
Bongjun 6:e2ab76b2be07 5 pico_string(){
Bongjun 6:e2ab76b2be07 6 _len = 0;
Bongjun 6:e2ab76b2be07 7 _buf = (char*)malloc(1);
Bongjun 6:e2ab76b2be07 8 if (_buf) {
Bongjun 6:e2ab76b2be07 9 _buf[0] = '\0';
Bongjun 6:e2ab76b2be07 10 }
Bongjun 6:e2ab76b2be07 11 }
Bongjun 6:e2ab76b2be07 12 ~pico_string() {
Bongjun 6:e2ab76b2be07 13 if (_buf) {
Bongjun 6:e2ab76b2be07 14 free(_buf);
Bongjun 6:e2ab76b2be07 15 }
Bongjun 6:e2ab76b2be07 16 }
Bongjun 6:e2ab76b2be07 17 bool empty() {
Bongjun 6:e2ab76b2be07 18 return _len == 0;
Bongjun 6:e2ab76b2be07 19 }
Bongjun 6:e2ab76b2be07 20 void append(const char* s, int len) {
Bongjun 6:e2ab76b2be07 21 if (_buf == NULL) {
Bongjun 6:e2ab76b2be07 22 return;
Bongjun 6:e2ab76b2be07 23 }
Bongjun 6:e2ab76b2be07 24 char* p = (char*)malloc(_len+len+1);
Bongjun 6:e2ab76b2be07 25 if (p == NULL) {
Bongjun 6:e2ab76b2be07 26 return;
Bongjun 6:e2ab76b2be07 27 }
Bongjun 6:e2ab76b2be07 28 memcpy(p, _buf, _len);
Bongjun 6:e2ab76b2be07 29 memcpy(p+_len, s, len);
Bongjun 6:e2ab76b2be07 30 p[_len+len] = '\0';
Bongjun 6:e2ab76b2be07 31 free(_buf);
Bongjun 6:e2ab76b2be07 32 _buf = p;
Bongjun 6:e2ab76b2be07 33 }
Bongjun 6:e2ab76b2be07 34 void append(const char* s) {
Bongjun 6:e2ab76b2be07 35 append(s, strlen(s));
Bongjun 6:e2ab76b2be07 36 }
Bongjun 6:e2ab76b2be07 37 char* c_str() {
Bongjun 6:e2ab76b2be07 38 if (_buf) {
Bongjun 6:e2ab76b2be07 39 return _buf;
Bongjun 6:e2ab76b2be07 40 }
Bongjun 6:e2ab76b2be07 41 return "";
Bongjun 6:e2ab76b2be07 42 }
Bongjun 6:e2ab76b2be07 43 private:
Bongjun 6:e2ab76b2be07 44 char* _buf;
Bongjun 6:e2ab76b2be07 45 int _len;
Bongjun 6:e2ab76b2be07 46 };