ThingPlug Test

Dependents:   WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P

Fork of WizFi310Interface by WIZnet

Committer:
jehoon
Date:
Wed Oct 05 09:40:30 2016 +0000
Revision:
0:df571f8f8c03
Child:
1:16e57103a7dd
This is a WizFi310 Library. It supports new mbed5 features including NetworkInterfaceAPI.

Who changed what in which revision?

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