Freedman v2
Fork of WizFi250Interface by
Diff: WizFi250/WizFi250_msg.cpp
- Revision:
- 9:12ecb377f63f
- Parent:
- 8:431172d536ee
- Child:
- 12:bb8e979df6df
diff -r 431172d536ee -r 12ecb377f63f WizFi250/WizFi250_msg.cpp --- a/WizFi250/WizFi250_msg.cpp Fri Nov 14 16:53:10 2014 +0900 +++ b/WizFi250/WizFi250_msg.cpp Fri Jun 19 15:34:40 2015 +0900 @@ -143,6 +143,7 @@ { sub++; count = 0; + _con[cid].recv_length = len; } else { @@ -158,13 +159,13 @@ { setRts(false); // blcok _con[cid].received = true; - //WIZ_WARN("buf full"); + WIZ_WARN("buf full"); } } - count++; - if(count >= len) + _con[cid].recv_length--; + if(_con[cid].recv_length == 0) { - // WIZ_DBG("recv cid: %d, count : %d, len : %d",cid, count, len); + //WIZ_DBG("recv cid: %d, count : %d, len : %d",cid, count, len); _con[cid].received = true; _state.mode = MODE_COMMAND; } @@ -179,7 +180,7 @@ #define RES_TABLE_NUM 7 int WizFi250::parseMessage () { int i; - char buf[256]; + char buf[128]; static const struct MSG_TABLE { const char msg[24]; @@ -198,11 +199,12 @@ }res_table[RES_TABLE_NUM]={ {RES_NULL, NULL}, {RES_MACADDRESS, &WizFi250::resMacAddress}, - {RES_WJOIN, &WizFi250::resWJOIN}, +// {RES_WJOIN, &WizFi250::resWJOIN}, {RES_CONNECT, &WizFi250::resConnect}, {RES_SSEND, &WizFi250::resSSEND}, {RES_FDNS, &WizFi250::resFDNS}, {RES_SMGMT, &WizFi250::resSMGMT}, + {RES_WSTATUS, &WizFi250::resWSTATUS}, }; @@ -253,9 +255,6 @@ void WizFi250::msgOk (const char *buf) { _state.ok = true; - - // kaizen 20141114 It have to check for debugging - strncpy(_state.dummyBuf,buf,strlen(buf)); } void WizFi250::msgError (const char *buf) @@ -311,53 +310,25 @@ } } -void WizFi250::resWJOIN (const char *buf) -{ - const char *tmp; - int i; - - if(_state.n == 0 && strstr(buf, "IP Addr")) - { - tmp = strstr(buf, ":") + 2; // Because space - for(i=0; i<strlen(tmp); i++) - _state.ip[i] = tmp[i]; - - _state.ip[i] = '\0'; - _state.n++; - } - - if(_state.n == 1 && strstr(buf, "Gateway")) - { - tmp = strstr(buf, ":") + 2; - for(i=0; i<strlen(tmp); i++) - _state.gateway[i] = tmp[i]; - - _state.gateway[i] = '\0'; - _state.res = RES_NULL; - } -} - void WizFi250::resConnect (const char *buf) { int cid; - if (strncmp(buf,"[OK]",4) == 0) + if (buf[0] == '[' && buf[1] == 'O' && buf[2] == 'K' && buf[3] == ']') + { _state.n++; - else if( strncmp(buf,"[CONNECT",8) == 0 ) + } + else if( buf[0] == '[' && buf[1] == 'C' && buf[2] == 'O' && buf[3] == 'N' && + buf[4] == 'N' && buf[5] == 'E' && buf[6] == 'C' && buf[7] == 'T') { cid = x2i(buf[9]); - initCon(cid, true); _state.cid = cid; - _state.res = RES_NULL; _state.n++; - - // for debuging - //_state.dummyBuf[0] = buf[9]; - //_state.dummyBuf[1] = '\0'; } - if(_state.n == 2) + if(_state.n >= 2) { + _state.res = RES_NULL; _state.ok = true; } } @@ -424,3 +395,37 @@ _state.res = RES_NULL; } + +void WizFi250::resWSTATUS (const char *buf) +{ + int idx=0,sep_cnt=0; + int ip_idx=0,gw_idx=0; + + if(_state.n == 0) + { + _state.n++; + } + else if(_state.n == 1) + { + for(idx=0;buf[idx]!='\r';idx++) + { + if(buf[idx] =='/') + { + sep_cnt++; + continue; + } + + if( sep_cnt == 2) // IP Address + { + _state.ip[ip_idx++] = buf[idx]; + } + else if(sep_cnt == 3) + { + _state.gateway[gw_idx++] = buf[idx]; + } + } + _state.ip[ip_idx] = '\0'; + _state.gateway[gw_idx] = '\0'; + _state.res = RES_NULL; + } +}