RC

Dependents:   WizFi250_AP_HelloWorld

Fork of WizFi250Interface by DongEun Koak

Committer:
DongEun Koak
Date:
Fri Nov 14 15:27:47 2014 +0900
Revision:
7:ba28fe711055
Parent:
5:8a0702aa91e3
Child:
8:431172d536ee
Fixed bug in init function of WizFi250.
Removed sendCommand for operating polling in order to wait response.
Fixed some bug.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kaizen 0:f2039204c8f6 1 /*
kaizen 0:f2039204c8f6 2 /* Copyright (C) 2013 gsfan, MIT License
kaizen 0:f2039204c8f6 3 *
kaizen 0:f2039204c8f6 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kaizen 0:f2039204c8f6 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kaizen 0:f2039204c8f6 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kaizen 0:f2039204c8f6 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kaizen 0:f2039204c8f6 8 * furnished to do so, subject to the following conditions:
kaizen 0:f2039204c8f6 9 *
kaizen 0:f2039204c8f6 10 * The above copyright notice and this permission notice shall be included in all copies or
kaizen 0:f2039204c8f6 11 * substantial portions of the Software.
kaizen 0:f2039204c8f6 12 *
kaizen 0:f2039204c8f6 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kaizen 0:f2039204c8f6 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kaizen 0:f2039204c8f6 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kaizen 0:f2039204c8f6 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kaizen 0:f2039204c8f6 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kaizen 0:f2039204c8f6 18 */
kaizen 0:f2039204c8f6 19 /* Copyright (C) 2014 Wiznet, MIT License
kaizen 0:f2039204c8f6 20 * port to the Wiznet Module WizFi250
kaizen 0:f2039204c8f6 21 */
kaizen 0:f2039204c8f6 22
kaizen 0:f2039204c8f6 23 #include "WizFi250.h"
kaizen 0:f2039204c8f6 24
kaizen 0:f2039204c8f6 25 #ifdef CFG_ENABLE_RTOS
DongEun Koak 5:8a0702aa91e3 26 #undef WIZ_DBG
DongEun Koak 5:8a0702aa91e3 27 #define WIZ_DBG(x, ...)
kaizen 0:f2039204c8f6 28 #endif
kaizen 0:f2039204c8f6 29
kaizen 0:f2039204c8f6 30 // This function is operating in ISR. So you can't use debug message.
kaizen 0:f2039204c8f6 31 void WizFi250::recvData ( char c )
kaizen 0:f2039204c8f6 32 {
kaizen 0:f2039204c8f6 33 static int cid, sub, len, count;
kaizen 0:f2039204c8f6 34
kaizen 0:f2039204c8f6 35 switch(_state.mode) {
kaizen 0:f2039204c8f6 36 case MODE_COMMAND:
kaizen 0:f2039204c8f6 37 switch(c) {
kaizen 0:f2039204c8f6 38 case 0:
kaizen 0:f2039204c8f6 39 case 0x0a: // LF
kaizen 0:f2039204c8f6 40 case 0x0d: // CR
kaizen 0:f2039204c8f6 41 break;
kaizen 0:f2039204c8f6 42
kaizen 0:f2039204c8f6 43 case '{':
kaizen 0:f2039204c8f6 44 _state.buf->flush();
kaizen 0:f2039204c8f6 45 _state.mode = MODE_DATA_RX;
kaizen 0:f2039204c8f6 46 sub = 0;
kaizen 0:f2039204c8f6 47 break;
kaizen 0:f2039204c8f6 48
kaizen 0:f2039204c8f6 49 default:
kaizen 0:f2039204c8f6 50 _state.buf->flush();
kaizen 0:f2039204c8f6 51 _state.buf->queue(c);
kaizen 0:f2039204c8f6 52 _state.mode = MODE_CMDRESP;
kaizen 0:f2039204c8f6 53 break;
kaizen 0:f2039204c8f6 54 }
kaizen 0:f2039204c8f6 55 break;
kaizen 0:f2039204c8f6 56
kaizen 0:f2039204c8f6 57 case MODE_CMDRESP:
kaizen 0:f2039204c8f6 58 switch(c){
kaizen 0:f2039204c8f6 59 case 0:
kaizen 0:f2039204c8f6 60 break;
kaizen 0:f2039204c8f6 61 case 0x0a: // LF
kaizen 0:f2039204c8f6 62 break;
kaizen 0:f2039204c8f6 63 case 0x0d: // CR
kaizen 0:f2039204c8f6 64
kaizen 0:f2039204c8f6 65 if (_flow == 2) setRts(false); // block
kaizen 0:f2039204c8f6 66 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 67 parseMessage();
kaizen 0:f2039204c8f6 68 if (_flow == 2) setRts(true); // release
kaizen 0:f2039204c8f6 69
kaizen 0:f2039204c8f6 70 break;
kaizen 0:f2039204c8f6 71 default:
kaizen 0:f2039204c8f6 72 _state.buf->queue(c);
kaizen 0:f2039204c8f6 73 break;
kaizen 0:f2039204c8f6 74 }
kaizen 0:f2039204c8f6 75 break;
kaizen 0:f2039204c8f6 76
kaizen 0:f2039204c8f6 77 case MODE_DATA_RX:
kaizen 0:f2039204c8f6 78 switch(sub){
kaizen 0:f2039204c8f6 79 case 0:
kaizen 0:f2039204c8f6 80 // cid
kaizen 0:f2039204c8f6 81 if( (c >= '0') && (c <= '9') )
kaizen 0:f2039204c8f6 82 {
kaizen 0:f2039204c8f6 83 cid = x2i(c);
kaizen 0:f2039204c8f6 84 }
kaizen 0:f2039204c8f6 85 else if ( c == ',' )
kaizen 0:f2039204c8f6 86 {
kaizen 0:f2039204c8f6 87 sub++;
kaizen 0:f2039204c8f6 88 count = 0;
kaizen 0:f2039204c8f6 89 len = 0;
kaizen 0:f2039204c8f6 90 }
kaizen 0:f2039204c8f6 91 else
kaizen 0:f2039204c8f6 92 {
kaizen 0:f2039204c8f6 93 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 94 }
kaizen 0:f2039204c8f6 95 break;
kaizen 0:f2039204c8f6 96
kaizen 0:f2039204c8f6 97 case 1:
kaizen 0:f2039204c8f6 98 // ip
kaizen 0:f2039204c8f6 99 if ((c >= '0' && c <= '9') || c == '.')
kaizen 0:f2039204c8f6 100 {
kaizen 0:f2039204c8f6 101 _con[cid].ip[count] = c;
kaizen 0:f2039204c8f6 102 count++;
kaizen 0:f2039204c8f6 103 }
kaizen 0:f2039204c8f6 104 else if( c == ',' )
kaizen 0:f2039204c8f6 105 {
kaizen 0:f2039204c8f6 106 _con[cid].ip[count] = '\0';
kaizen 0:f2039204c8f6 107 _con[cid].port = 0;
kaizen 0:f2039204c8f6 108 sub++;
kaizen 0:f2039204c8f6 109 }
kaizen 0:f2039204c8f6 110 else
kaizen 0:f2039204c8f6 111 {
kaizen 0:f2039204c8f6 112 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 113 }
kaizen 0:f2039204c8f6 114 break;
kaizen 0:f2039204c8f6 115
kaizen 0:f2039204c8f6 116 case 2:
kaizen 0:f2039204c8f6 117 // port
kaizen 0:f2039204c8f6 118 if ( c >= '0' && c <= '9' )
kaizen 0:f2039204c8f6 119 {
kaizen 0:f2039204c8f6 120 _con[cid].port = (_con[cid].port * 10) + ( c - '0' );
kaizen 0:f2039204c8f6 121 }
kaizen 0:f2039204c8f6 122 else if( c == ',')
kaizen 0:f2039204c8f6 123 {
kaizen 0:f2039204c8f6 124 sub++;
kaizen 0:f2039204c8f6 125 count = 0;
kaizen 0:f2039204c8f6 126 }
kaizen 0:f2039204c8f6 127 else
kaizen 0:f2039204c8f6 128 {
kaizen 0:f2039204c8f6 129 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 130 }
kaizen 0:f2039204c8f6 131 break;
kaizen 0:f2039204c8f6 132
kaizen 0:f2039204c8f6 133 case 3:
kaizen 0:f2039204c8f6 134 // data length
kaizen 0:f2039204c8f6 135 if ( c >= '0' && c <= '9' )
kaizen 0:f2039204c8f6 136 {
kaizen 0:f2039204c8f6 137 //_con[cid].recv_length = (_con[cid].recv_length * 10) + (c - '0');
kaizen 0:f2039204c8f6 138 len = (len * 10) + (c - '0');
kaizen 0:f2039204c8f6 139 }
kaizen 0:f2039204c8f6 140 else if( c == '}' )
kaizen 0:f2039204c8f6 141 {
kaizen 0:f2039204c8f6 142 sub++;
kaizen 0:f2039204c8f6 143 count = 0;
kaizen 0:f2039204c8f6 144 }
kaizen 0:f2039204c8f6 145 else
kaizen 0:f2039204c8f6 146 {
kaizen 0:f2039204c8f6 147 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 148 }
kaizen 0:f2039204c8f6 149 break;
kaizen 0:f2039204c8f6 150
kaizen 0:f2039204c8f6 151 default:
kaizen 0:f2039204c8f6 152 if(_con[cid].buf != NULL)
kaizen 0:f2039204c8f6 153 {
kaizen 0:f2039204c8f6 154 _con[cid].buf->queue(c);
kaizen 0:f2039204c8f6 155 if(_con[cid].buf->available() > CFG_DATA_SIZE - 16 )
kaizen 0:f2039204c8f6 156 {
kaizen 0:f2039204c8f6 157 setRts(false); // blcok
kaizen 0:f2039204c8f6 158 _con[cid].received = true;
DongEun Koak 5:8a0702aa91e3 159 //WIZ_WARN("buf full");
kaizen 0:f2039204c8f6 160 }
kaizen 0:f2039204c8f6 161 }
kaizen 0:f2039204c8f6 162 count++;
kaizen 0:f2039204c8f6 163 if(count >= len)
kaizen 0:f2039204c8f6 164 {
DongEun Koak 5:8a0702aa91e3 165 // WIZ_DBG("recv cid: %d, count : %d, len : %d",cid, count, len);
kaizen 0:f2039204c8f6 166 _con[cid].received = true;
kaizen 0:f2039204c8f6 167 _state.mode = MODE_COMMAND;
kaizen 0:f2039204c8f6 168 }
kaizen 0:f2039204c8f6 169 break;
kaizen 0:f2039204c8f6 170 }
kaizen 0:f2039204c8f6 171 break;
kaizen 0:f2039204c8f6 172 }
kaizen 0:f2039204c8f6 173 }
kaizen 0:f2039204c8f6 174
kaizen 0:f2039204c8f6 175
kaizen 0:f2039204c8f6 176 #define MSG_TABLE_NUM 6
kaizen 0:f2039204c8f6 177 #define RES_TABLE_NUM 7
kaizen 0:f2039204c8f6 178 int WizFi250::parseMessage () {
kaizen 0:f2039204c8f6 179 int i;
kaizen 0:f2039204c8f6 180 char buf[256];
kaizen 0:f2039204c8f6 181
kaizen 0:f2039204c8f6 182 static const struct MSG_TABLE {
kaizen 0:f2039204c8f6 183 const char msg[24];
kaizen 0:f2039204c8f6 184 void (WizFi250::*func)(const char *);
kaizen 0:f2039204c8f6 185 } msg_table[MSG_TABLE_NUM] = {
kaizen 0:f2039204c8f6 186 {"[OK]", &WizFi250::msgOk},
kaizen 0:f2039204c8f6 187 {"[ERROR]", &WizFi250::msgError},
kaizen 0:f2039204c8f6 188 {"[ERROR:INVALIDINPUT]", &WizFi250::msgError},
kaizen 0:f2039204c8f6 189 {"[CONNECT ", &WizFi250::msgConnect},
kaizen 0:f2039204c8f6 190 {"[DISCONNECT ", &WizFi250::msgDisconnect},
kaizen 0:f2039204c8f6 191 {"[LISTEN ", &WizFi250::msgListen},
kaizen 0:f2039204c8f6 192 };
kaizen 0:f2039204c8f6 193 static const struct RES_TABLE{
kaizen 0:f2039204c8f6 194 const Response res;
kaizen 0:f2039204c8f6 195 void (WizFi250::*func)(const char *);
kaizen 0:f2039204c8f6 196 }res_table[RES_TABLE_NUM]={
kaizen 0:f2039204c8f6 197 {RES_NULL, NULL},
kaizen 0:f2039204c8f6 198 {RES_MACADDRESS, &WizFi250::resMacAddress},
kaizen 0:f2039204c8f6 199 {RES_WJOIN, &WizFi250::resWJOIN},
kaizen 0:f2039204c8f6 200 {RES_CONNECT, &WizFi250::resConnect},
kaizen 0:f2039204c8f6 201 {RES_SSEND, &WizFi250::resSSEND},
kaizen 0:f2039204c8f6 202 {RES_FDNS, &WizFi250::resFDNS},
kaizen 0:f2039204c8f6 203 {RES_SMGMT, &WizFi250::resSMGMT},
kaizen 0:f2039204c8f6 204 };
kaizen 0:f2039204c8f6 205
kaizen 0:f2039204c8f6 206
kaizen 0:f2039204c8f6 207 for( i=0; i<sizeof(buf); i++ )
kaizen 0:f2039204c8f6 208 {
kaizen 0:f2039204c8f6 209 if( _state.buf->dequeue(&buf[i]) == false) break;
kaizen 0:f2039204c8f6 210 }
kaizen 0:f2039204c8f6 211
kaizen 0:f2039204c8f6 212 buf[i] = '\0';
kaizen 0:f2039204c8f6 213 //strncpy(_state.dbgRespBuf, buf, sizeof(buf));
DongEun Koak 5:8a0702aa91e3 214 //WIZ_DBG("%s\r\n",_state.dbgRespBuf);
kaizen 0:f2039204c8f6 215
kaizen 0:f2039204c8f6 216 if(_state.res != RES_NULL)
kaizen 0:f2039204c8f6 217 {
kaizen 0:f2039204c8f6 218 for( i=0; i<RES_TABLE_NUM; i++)
kaizen 0:f2039204c8f6 219 {
kaizen 0:f2039204c8f6 220 if(res_table[i].res == _state.res)
kaizen 0:f2039204c8f6 221 {
DongEun Koak 5:8a0702aa91e3 222 //WIZ_DBG("parse res %d '%s'\r\n", i, buf);
kaizen 0:f2039204c8f6 223 if(res_table[i].func != NULL)
kaizen 0:f2039204c8f6 224 {
kaizen 0:f2039204c8f6 225 (this->*(res_table[i].func))(buf);
kaizen 0:f2039204c8f6 226 }
kaizen 0:f2039204c8f6 227
kaizen 0:f2039204c8f6 228 if(res_table[i].res == RES_CONNECT && _state.n < 2)
kaizen 0:f2039204c8f6 229 return -1;
kaizen 0:f2039204c8f6 230 }
kaizen 0:f2039204c8f6 231 }
kaizen 0:f2039204c8f6 232 }
kaizen 0:f2039204c8f6 233
kaizen 0:f2039204c8f6 234 for( i=0; i<MSG_TABLE_NUM; i++)
kaizen 0:f2039204c8f6 235 {
kaizen 0:f2039204c8f6 236 if( strncmp(buf, msg_table[i].msg, strlen(msg_table[i].msg)) == 0 )
kaizen 0:f2039204c8f6 237 {
DongEun Koak 5:8a0702aa91e3 238 //WIZ_DBG("parse msg '%s'\r\n", buf);
kaizen 0:f2039204c8f6 239 if(msg_table[i].func != NULL)
kaizen 0:f2039204c8f6 240 {
kaizen 0:f2039204c8f6 241 (this->*(msg_table[i].func))(buf);
kaizen 0:f2039204c8f6 242 }
kaizen 0:f2039204c8f6 243 return 0;
kaizen 0:f2039204c8f6 244 }
kaizen 0:f2039204c8f6 245 }
kaizen 0:f2039204c8f6 246
kaizen 0:f2039204c8f6 247 return -1;
kaizen 0:f2039204c8f6 248 }
kaizen 0:f2039204c8f6 249
kaizen 0:f2039204c8f6 250
kaizen 0:f2039204c8f6 251 void WizFi250::msgOk (const char *buf)
kaizen 0:f2039204c8f6 252 {
kaizen 0:f2039204c8f6 253 _state.ok = true;
kaizen 0:f2039204c8f6 254 strncpy(_state.dummyBuf,buf,strlen(buf));
kaizen 0:f2039204c8f6 255 // if(_state.status == STAT_DEEPSLEEP){
kaizen 0:f2039204c8f6 256 // _state.status = STAT_READY;
kaizen 0:f2039204c8f6 257 // }
kaizen 0:f2039204c8f6 258 }
kaizen 0:f2039204c8f6 259
kaizen 0:f2039204c8f6 260 void WizFi250::msgError (const char *buf)
kaizen 0:f2039204c8f6 261 {
kaizen 0:f2039204c8f6 262 _state.failure = true;
kaizen 0:f2039204c8f6 263 }
kaizen 0:f2039204c8f6 264
kaizen 0:f2039204c8f6 265 void WizFi250::msgConnect (const char *buf)
kaizen 0:f2039204c8f6 266 {
kaizen 0:f2039204c8f6 267 int cid;
kaizen 0:f2039204c8f6 268
kaizen 0:f2039204c8f6 269 if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return;
kaizen 0:f2039204c8f6 270
kaizen 0:f2039204c8f6 271 cid = x2i(buf[9]);
kaizen 0:f2039204c8f6 272
kaizen 0:f2039204c8f6 273 initCon(cid, true);
kaizen 0:f2039204c8f6 274 _state.cid = cid;
kaizen 0:f2039204c8f6 275 _con[cid].accept = true;
kaizen 0:f2039204c8f6 276 _con[cid].parent = cid;
kaizen 0:f2039204c8f6 277 }
kaizen 0:f2039204c8f6 278
kaizen 0:f2039204c8f6 279 void WizFi250::msgDisconnect (const char *buf)
kaizen 0:f2039204c8f6 280 {
kaizen 0:f2039204c8f6 281 int cid;
kaizen 0:f2039204c8f6 282
kaizen 0:f2039204c8f6 283 if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']') return;
kaizen 0:f2039204c8f6 284
kaizen 0:f2039204c8f6 285 cid = x2i(buf[12]);
kaizen 0:f2039204c8f6 286 _con[cid].connected = false;
kaizen 0:f2039204c8f6 287 }
kaizen 0:f2039204c8f6 288
kaizen 0:f2039204c8f6 289 void WizFi250::msgListen (const char *buf)
kaizen 0:f2039204c8f6 290 {
kaizen 0:f2039204c8f6 291 int cid;
kaizen 0:f2039204c8f6 292
kaizen 0:f2039204c8f6 293 if(buf[8] < '0' || buf[8] > '8' || buf[9] != ']') return;
kaizen 0:f2039204c8f6 294
kaizen 0:f2039204c8f6 295 cid = x2i(buf[8]);
kaizen 0:f2039204c8f6 296 _state.cid = cid;
kaizen 0:f2039204c8f6 297 }
kaizen 0:f2039204c8f6 298
kaizen 0:f2039204c8f6 299 void WizFi250::resMacAddress (const char *buf)
kaizen 0:f2039204c8f6 300 {
kaizen 0:f2039204c8f6 301 if( buf[2] == ':' && buf[5] == ':')
kaizen 0:f2039204c8f6 302 {
kaizen 0:f2039204c8f6 303 strncpy(_state.mac, buf, sizeof(_state.mac));
kaizen 0:f2039204c8f6 304 _state.mac[17] = 0;
kaizen 0:f2039204c8f6 305 _state.res = RES_NULL;
DongEun Koak 7:ba28fe711055 306 if(strncmp(_state.mac,CFG_DEFAULT_MAC,sizeof(CFG_DEFAULT_MAC)) == 0)
DongEun Koak 7:ba28fe711055 307 _state.ok = false;
DongEun Koak 7:ba28fe711055 308
DongEun Koak 7:ba28fe711055 309 _state.ok = true;
kaizen 0:f2039204c8f6 310 }
kaizen 0:f2039204c8f6 311 }
kaizen 0:f2039204c8f6 312
kaizen 0:f2039204c8f6 313 void WizFi250::resWJOIN (const char *buf)
kaizen 0:f2039204c8f6 314 {
kaizen 0:f2039204c8f6 315 const char *tmp;
kaizen 0:f2039204c8f6 316 int i;
kaizen 0:f2039204c8f6 317
kaizen 0:f2039204c8f6 318
kaizen 0:f2039204c8f6 319 if(_state.n == 0 && strstr(buf, "IP Addr"))
kaizen 0:f2039204c8f6 320 {
kaizen 0:f2039204c8f6 321 tmp = strstr(buf, ":") + 2; // Because space
kaizen 0:f2039204c8f6 322 for(i=0; i<strlen(tmp); i++)
kaizen 0:f2039204c8f6 323 _state.ip[i] = tmp[i];
kaizen 0:f2039204c8f6 324
kaizen 0:f2039204c8f6 325 _state.ip[i] = '\0';
kaizen 0:f2039204c8f6 326 _state.n++;
kaizen 0:f2039204c8f6 327 }
kaizen 0:f2039204c8f6 328
kaizen 0:f2039204c8f6 329 if(_state.n == 1 && strstr(buf, "Gateway"))
kaizen 0:f2039204c8f6 330 {
kaizen 0:f2039204c8f6 331 tmp = strstr(buf, ":") + 2;
kaizen 0:f2039204c8f6 332 for(i=0; i<strlen(tmp); i++)
kaizen 0:f2039204c8f6 333 _state.gateway[i] = tmp[i];
kaizen 0:f2039204c8f6 334
kaizen 0:f2039204c8f6 335 _state.gateway[i] = '\0';
kaizen 0:f2039204c8f6 336 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 337 }
kaizen 0:f2039204c8f6 338 }
kaizen 0:f2039204c8f6 339
kaizen 0:f2039204c8f6 340 void WizFi250::resConnect (const char *buf)
kaizen 0:f2039204c8f6 341 {
kaizen 0:f2039204c8f6 342 int cid;
kaizen 0:f2039204c8f6 343
kaizen 0:f2039204c8f6 344 if (strncmp(buf,"[OK]",4) == 0)
kaizen 0:f2039204c8f6 345 _state.n++;
kaizen 0:f2039204c8f6 346 else if( strncmp(buf,"[CONNECT",8) == 0 )
kaizen 0:f2039204c8f6 347 {
kaizen 0:f2039204c8f6 348 cid = x2i(buf[9]);
kaizen 0:f2039204c8f6 349 initCon(cid, true);
kaizen 0:f2039204c8f6 350 _state.cid = cid;
kaizen 0:f2039204c8f6 351 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 352 _state.n++;
kaizen 0:f2039204c8f6 353
kaizen 0:f2039204c8f6 354 // for debuging
kaizen 0:f2039204c8f6 355 // _state.dummyBuf[0] = buf[9];
kaizen 0:f2039204c8f6 356 // _state.dummyBuf[1] = '\0';
kaizen 0:f2039204c8f6 357 }
kaizen 0:f2039204c8f6 358
kaizen 0:f2039204c8f6 359 if(_state.n == 2)
kaizen 0:f2039204c8f6 360 {
kaizen 0:f2039204c8f6 361 _state.ok = true;
kaizen 0:f2039204c8f6 362 }
kaizen 0:f2039204c8f6 363 }
kaizen 0:f2039204c8f6 364
kaizen 0:f2039204c8f6 365 void WizFi250::resSSEND (const char *buf)
kaizen 0:f2039204c8f6 366 {
kaizen 0:f2039204c8f6 367
kaizen 0:f2039204c8f6 368 if(_state.cid != -1)
kaizen 0:f2039204c8f6 369 {
kaizen 0:f2039204c8f6 370 // sprintf(dummyBuf,"[%d,,,%d]",_state.cid, _con[_state.cid].length);
kaizen 0:f2039204c8f6 371
kaizen 0:f2039204c8f6 372 // if (strncmp(buf,dummyBuf,strlen(dummyBuf)) == 0)
kaizen 0:f2039204c8f6 373 // {
kaizen 0:f2039204c8f6 374 // strncpy(_state.dummyBuf,dummyBuf,strlen(dummyBuf));
kaizen 0:f2039204c8f6 375 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 376 _state.ok = true;
kaizen 0:f2039204c8f6 377 // }
kaizen 0:f2039204c8f6 378 }
kaizen 0:f2039204c8f6 379 }
kaizen 0:f2039204c8f6 380
kaizen 0:f2039204c8f6 381 void WizFi250::resFDNS (const char *buf)
kaizen 0:f2039204c8f6 382 {
kaizen 0:f2039204c8f6 383 int i;
kaizen 0:f2039204c8f6 384
kaizen 0:f2039204c8f6 385 for(i=0; i<strlen(buf); i++)
kaizen 0:f2039204c8f6 386 {
kaizen 0:f2039204c8f6 387 if( (buf[i] < '0' || buf[i] > '9') && buf[i] != '.' )
kaizen 0:f2039204c8f6 388 {
kaizen 0:f2039204c8f6 389 return;
kaizen 0:f2039204c8f6 390 }
kaizen 0:f2039204c8f6 391 }
kaizen 0:f2039204c8f6 392
kaizen 0:f2039204c8f6 393 strncpy(_state.resolv, buf, sizeof(_state.resolv));
kaizen 0:f2039204c8f6 394 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 395 }
kaizen 0:f2039204c8f6 396
kaizen 0:f2039204c8f6 397 void WizFi250::resSMGMT (const char *buf)
kaizen 0:f2039204c8f6 398 {
kaizen 0:f2039204c8f6 399 int cid, i;
kaizen 0:f2039204c8f6 400 char *c;
kaizen 0:f2039204c8f6 401
kaizen 0:f2039204c8f6 402 if( (buf[0] < '0' || buf[0] > '8') ) return;
kaizen 0:f2039204c8f6 403
kaizen 0:f2039204c8f6 404 cid = x2i(buf[0]);
kaizen 0:f2039204c8f6 405 if( cid != _state.cid ) return;
kaizen 0:f2039204c8f6 406
kaizen 0:f2039204c8f6 407 // IP
kaizen 0:f2039204c8f6 408 c = (char*)(buf+6);
kaizen 0:f2039204c8f6 409 for( i=0; i<16; i++ )
kaizen 0:f2039204c8f6 410 {
kaizen 0:f2039204c8f6 411 if( *(c+i) == ':')
kaizen 0:f2039204c8f6 412 {
kaizen 0:f2039204c8f6 413 _con[cid].ip[i] = '\0';
kaizen 0:f2039204c8f6 414 i++;
kaizen 0:f2039204c8f6 415 break;
kaizen 0:f2039204c8f6 416 }
kaizen 0:f2039204c8f6 417 if( ( *(c+i) < '0' || *(c+i) > '9') && *(c+i) != '.' ) return;
kaizen 0:f2039204c8f6 418 _con[cid].ip[i] = *(c+i);
kaizen 0:f2039204c8f6 419 }
kaizen 0:f2039204c8f6 420
kaizen 0:f2039204c8f6 421 // Port
kaizen 0:f2039204c8f6 422 c = (c+i);
kaizen 0:f2039204c8f6 423 _con[cid].port = 0;
kaizen 0:f2039204c8f6 424 for( i=0; i<5; i++ )
kaizen 0:f2039204c8f6 425 {
kaizen 0:f2039204c8f6 426 if( *(c+i) == '/') break;
kaizen 0:f2039204c8f6 427 if( *(c+i) < '0' || *(c+i) > '9' ) return;
kaizen 0:f2039204c8f6 428
kaizen 0:f2039204c8f6 429 _con[cid].port = (_con[cid].port * 10) + ( *(c+i) - '0' );
kaizen 0:f2039204c8f6 430 }
kaizen 0:f2039204c8f6 431
kaizen 0:f2039204c8f6 432 _state.res = RES_NULL;
kaizen 0:f2039204c8f6 433 }