This library can be used in mbed driver or mbed OS2. So If you want to use WizFi310 on mbed OS5, You have to use another WizFi310 library(wizfi310-driver). That is git repository for wizfi310-driver. - https://github.com/ARMmbed/wizfi310-driver

Dependents:   KT_IoTMakers_WizFi310_Example WizFi310_STATION_HelloWorld WizFi310_DNS_TCP_HelloWorld WizFi310_Ubidots ... more

This library can be used in mbed driver or mbed OS2. So If you want to use WizFi310 on mbed OS5, You have to use another WizFi310 library(wizfi310-driver).

That is git repository for wizfi310-driver. - https://github.com/ARMmbed/wizfi310-driver

Committer:
jehoon
Date:
Mon Jun 26 00:17:10 2017 +0000
Revision:
5:72212beb817c
Parent:
1:16e57103a7dd
Child:
6:007cec5e96c0
modify message parsing in isr

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 5:72212beb817c 30 #define RESP_MSG_OK "[OK]"
jehoon 5:72212beb817c 31 #define RESP_MSG_ERROR "[ERROR"
jehoon 5:72212beb817c 32 #define RESP_MSG_CONNECT "[CONNECT "
jehoon 5:72212beb817c 33 #define RESP_MSG_DISCONNECT "[DISCONNECT "
jehoon 5:72212beb817c 34 #define RESP_MSG_LISTEN "[LISTEN "
jehoon 5:72212beb817c 35 #define RESP_MSG_MQTTCON "[MQTT CONNECT]"
jehoon 5:72212beb817c 36 #define RESP_MSG_MQTTDISCON "[MQTT DISCONNECT]"
jehoon 5:72212beb817c 37
jehoon 1:16e57103a7dd 38
jehoon 0:df571f8f8c03 39 // This function is operating in ISR. So you can't use debug message.
jehoon 0:df571f8f8c03 40 void WizFi310::recvData ( char c )
jehoon 0:df571f8f8c03 41 {
jehoon 0:df571f8f8c03 42 static int cid, sub, len, count;
jehoon 5:72212beb817c 43 static int is_mqtt_data = 0;
jehoon 1:16e57103a7dd 44
jehoon 0:df571f8f8c03 45 switch(_state.mode)
jehoon 5:72212beb817c 46 {
jehoon 0:df571f8f8c03 47 case MODE_COMMAND:
jehoon 0:df571f8f8c03 48 switch(c)
jehoon 0:df571f8f8c03 49 {
jehoon 0:df571f8f8c03 50 case 0:
jehoon 0:df571f8f8c03 51 case 0x0a: // LF
jehoon 0:df571f8f8c03 52 case 0x0d: // CR
jehoon 0:df571f8f8c03 53 break;
jehoon 0:df571f8f8c03 54
jehoon 0:df571f8f8c03 55 case '{':
jehoon 0:df571f8f8c03 56 _state.buf->flush();
jehoon 0:df571f8f8c03 57 _state.mode = MODE_DATA_RX;
jehoon 0:df571f8f8c03 58 sub = 0;
jehoon 0:df571f8f8c03 59 break;
jehoon 0:df571f8f8c03 60
jehoon 0:df571f8f8c03 61 default:
jehoon 0:df571f8f8c03 62 _state.buf->flush();
jehoon 0:df571f8f8c03 63 _state.buf->queue(c);
jehoon 0:df571f8f8c03 64 _state.mode = MODE_CMDRESP;
jehoon 0:df571f8f8c03 65 break;
jehoon 0:df571f8f8c03 66 }
jehoon 0:df571f8f8c03 67 break;
jehoon 0:df571f8f8c03 68
jehoon 0:df571f8f8c03 69 case MODE_CMDRESP:
jehoon 0:df571f8f8c03 70 switch(c)
jehoon 0:df571f8f8c03 71 {
jehoon 0:df571f8f8c03 72 case 0:
jehoon 0:df571f8f8c03 73 break;
jehoon 0:df571f8f8c03 74 case 0x0a: // LF
jehoon 0:df571f8f8c03 75 break;
jehoon 0:df571f8f8c03 76 case 0x0d: // CR
jehoon 0:df571f8f8c03 77 if (_flow == 2) setRts(false); // block
jehoon 0:df571f8f8c03 78 _state.mode = MODE_COMMAND;
jehoon 0:df571f8f8c03 79 parseMessage();
jehoon 0:df571f8f8c03 80 if (_flow == 2) setRts(true); // release
jehoon 0:df571f8f8c03 81 break;
jehoon 0:df571f8f8c03 82 default:
jehoon 0:df571f8f8c03 83 _state.buf->queue(c);
jehoon 0:df571f8f8c03 84 break;
jehoon 0:df571f8f8c03 85 }
jehoon 0:df571f8f8c03 86 break;
jehoon 0:df571f8f8c03 87
jehoon 0:df571f8f8c03 88 case MODE_DATA_RX:
jehoon 1:16e57103a7dd 89
jehoon 0:df571f8f8c03 90 switch(sub)
jehoon 0:df571f8f8c03 91 {
jehoon 0:df571f8f8c03 92 case 0:
jehoon 5:72212beb817c 93 // cid
jehoon 5:72212beb817c 94 if( (c >= '0') && (c <= '9') )
jehoon 5:72212beb817c 95 {
jehoon 5:72212beb817c 96 cid = x2i(c);
jehoon 5:72212beb817c 97 }
jehoon 5:72212beb817c 98 else if ( c == ',' )
jehoon 5:72212beb817c 99 {
jehoon 5:72212beb817c 100 sub++;
jehoon 5:72212beb817c 101 count = 0;
jehoon 5:72212beb817c 102 len = 0;
jehoon 5:72212beb817c 103 }
jehoon 5:72212beb817c 104 //daniel add for mqtt
jehoon 5:72212beb817c 105 else if ( c == 'Q' )
jehoon 5:72212beb817c 106 {
jehoon 5:72212beb817c 107 cid = 0;
jehoon 5:72212beb817c 108 is_mqtt_data = 1;
jehoon 5:72212beb817c 109 }
jehoon 5:72212beb817c 110 //
jehoon 5:72212beb817c 111 else
jehoon 5:72212beb817c 112 {
jehoon 5:72212beb817c 113 _state.mode = MODE_COMMAND;
jehoon 5:72212beb817c 114 }
jehoon 5:72212beb817c 115 break;
jehoon 0:df571f8f8c03 116
jehoon 5:72212beb817c 117 case 1:
jehoon 5:72212beb817c 118 // ip
jehoon 5:72212beb817c 119 // if ((c >= '0' && c <= '9') || c == '.')
jehoon 5:72212beb817c 120 if (((c >= '0' && c <= '9') || c == '.') && is_mqtt_data == 0 )
jehoon 5:72212beb817c 121 {
jehoon 5:72212beb817c 122 _con[cid].ip[count] = c;
jehoon 5:72212beb817c 123 count++;
jehoon 5:72212beb817c 124 }
jehoon 5:72212beb817c 125 else if( c == ',' )
jehoon 5:72212beb817c 126 {
jehoon 5:72212beb817c 127 _con[cid].ip[count] = '\0';
jehoon 5:72212beb817c 128 _con[cid].port = 0;
jehoon 5:72212beb817c 129 sub++;
jehoon 5:72212beb817c 130 }
jehoon 5:72212beb817c 131 //daniel for mqtt
jehoon 5:72212beb817c 132 else if( is_mqtt_data == 1)
jehoon 5:72212beb817c 133 {
jehoon 5:72212beb817c 134 rcvd_mqtt_topic[count] = c;
jehoon 5:72212beb817c 135 count++;
jehoon 5:72212beb817c 136 }
jehoon 5:72212beb817c 137 // else
jehoon 5:72212beb817c 138 else if( is_mqtt_data == 0 )
jehoon 5:72212beb817c 139 {
jehoon 5:72212beb817c 140 _state.mode = MODE_COMMAND;
jehoon 5:72212beb817c 141 }
jehoon 5:72212beb817c 142 break;
jehoon 5:72212beb817c 143
jehoon 5:72212beb817c 144 case 2:
jehoon 5:72212beb817c 145 // port
jehoon 5:72212beb817c 146 if ( c >= '0' && c <= '9' )
jehoon 5:72212beb817c 147 {
jehoon 5:72212beb817c 148 _con[cid].port = (_con[cid].port * 10) + ( c - '0' );
jehoon 5:72212beb817c 149 }
jehoon 5:72212beb817c 150 else if( c == ',')
jehoon 5:72212beb817c 151 {
jehoon 5:72212beb817c 152 sub++;
jehoon 5:72212beb817c 153 count = 0;
jehoon 5:72212beb817c 154 }
jehoon 5:72212beb817c 155 else
jehoon 5:72212beb817c 156 {
jehoon 5:72212beb817c 157 _state.mode = MODE_COMMAND;
jehoon 5:72212beb817c 158 }
jehoon 5:72212beb817c 159 break;
jehoon 5:72212beb817c 160
jehoon 5:72212beb817c 161 case 3:
jehoon 5:72212beb817c 162 // data length
jehoon 5:72212beb817c 163 if ( c >= '0' && c <= '9' )
jehoon 5:72212beb817c 164 {
jehoon 5:72212beb817c 165 //_con[cid].recv_length = (_con[cid].recv_length * 10) + (c - '0');
jehoon 5:72212beb817c 166 len = (len * 10) + (c - '0');
jehoon 5:72212beb817c 167 }
jehoon 5:72212beb817c 168 else if( c == '}' )
jehoon 5:72212beb817c 169 {
jehoon 5:72212beb817c 170 sub++;
jehoon 5:72212beb817c 171 count = 0;
jehoon 5:72212beb817c 172 _con[cid].recv_length = len;
jehoon 5:72212beb817c 173 }
jehoon 5:72212beb817c 174 else
jehoon 5:72212beb817c 175 {
jehoon 5:72212beb817c 176 _state.mode = MODE_COMMAND;
jehoon 5:72212beb817c 177 }
jehoon 5:72212beb817c 178 break;
jehoon 5:72212beb817c 179
jehoon 5:72212beb817c 180 default:
jehoon 5:72212beb817c 181
jehoon 5:72212beb817c 182 if(_con[cid].buf != NULL)
jehoon 5:72212beb817c 183 {
jehoon 5:72212beb817c 184 _con[cid].buf->queue(c);
jehoon 5:72212beb817c 185 if(_con[cid].buf->available() > CFG_DATA_SIZE - 16 )
jehoon 5:72212beb817c 186 {
jehoon 5:72212beb817c 187 setRts(false); // blcok
jehoon 5:72212beb817c 188 _con[cid].received = true;
jehoon 5:72212beb817c 189 WIZ_WARN("buf full");
jehoon 5:72212beb817c 190 }
jehoon 5:72212beb817c 191 }
jehoon 5:72212beb817c 192 _con[cid].recv_length--;
jehoon 5:72212beb817c 193 if(_con[cid].recv_length == 0)
jehoon 5:72212beb817c 194 {
jehoon 5:72212beb817c 195 _con[cid].received = true;
jehoon 5:72212beb817c 196 _state.mode = MODE_COMMAND;
jehoon 5:72212beb817c 197 }
jehoon 5:72212beb817c 198 break;
jehoon 0:df571f8f8c03 199 }
jehoon 0:df571f8f8c03 200 break;
jehoon 0:df571f8f8c03 201 }
jehoon 0:df571f8f8c03 202 }
jehoon 0:df571f8f8c03 203
jehoon 5:72212beb817c 204 #define MSG_TABLE_NUM 7
jehoon 0:df571f8f8c03 205 #define RES_TABLE_NUM 7
jehoon 0:df571f8f8c03 206 int WizFi310::parseMessage () {
jehoon 0:df571f8f8c03 207 int i;
jehoon 0:df571f8f8c03 208 char buf[128];
jehoon 0:df571f8f8c03 209
jehoon 0:df571f8f8c03 210 static const struct MSG_TABLE {
jehoon 0:df571f8f8c03 211 const char msg[24];
jehoon 0:df571f8f8c03 212 void (WizFi310::*func)(const char *);
jehoon 0:df571f8f8c03 213 } msg_table[MSG_TABLE_NUM] = {
jehoon 5:72212beb817c 214 {RESP_MSG_OK, &WizFi310::msgOk},
jehoon 5:72212beb817c 215 {RESP_MSG_ERROR, &WizFi310::msgError},
jehoon 5:72212beb817c 216 // {"[ERROR:INVALIDINPUT]", &WizFi310::msgError},
jehoon 5:72212beb817c 217 {RESP_MSG_CONNECT, &WizFi310::msgConnect},
jehoon 5:72212beb817c 218 {RESP_MSG_DISCONNECT, &WizFi310::msgDisconnect},
jehoon 5:72212beb817c 219 {RESP_MSG_LISTEN, &WizFi310::msgListen},
jehoon 5:72212beb817c 220 {RESP_MSG_MQTTCON, &WizFi310::msgMQTTConnect},
jehoon 5:72212beb817c 221 {RESP_MSG_MQTTDISCON, &WizFi310::msgMQTTDisconnect},
jehoon 0:df571f8f8c03 222 };
jehoon 0:df571f8f8c03 223 static const struct RES_TABLE{
jehoon 0:df571f8f8c03 224 const Response res;
jehoon 0:df571f8f8c03 225 void (WizFi310::*func)(const char *);
jehoon 0:df571f8f8c03 226 }res_table[RES_TABLE_NUM]={
jehoon 0:df571f8f8c03 227 {RES_NULL, NULL},
jehoon 0:df571f8f8c03 228 {RES_MACADDRESS, &WizFi310::resMacAddress},
jehoon 0:df571f8f8c03 229 // {RES_WJOIN, &WizFi310::resWJOIN},
jehoon 0:df571f8f8c03 230 {RES_CONNECT, &WizFi310::resConnect},
jehoon 0:df571f8f8c03 231 {RES_SSEND, &WizFi310::resSSEND},
jehoon 0:df571f8f8c03 232 {RES_FDNS, &WizFi310::resFDNS},
jehoon 0:df571f8f8c03 233 {RES_SMGMT, &WizFi310::resSMGMT},
jehoon 0:df571f8f8c03 234 {RES_WSTATUS, &WizFi310::resWSTATUS},
jehoon 0:df571f8f8c03 235 };
jehoon 0:df571f8f8c03 236
jehoon 0:df571f8f8c03 237
jehoon 0:df571f8f8c03 238 for( i=0; i<sizeof(buf); i++ )
jehoon 0:df571f8f8c03 239 {
jehoon 0:df571f8f8c03 240 if( _state.buf->dequeue(&buf[i]) == false ) break;
jehoon 0:df571f8f8c03 241 }
jehoon 0:df571f8f8c03 242
jehoon 0:df571f8f8c03 243 buf[i] = '\0';
jehoon 5:72212beb817c 244
jehoon 0:df571f8f8c03 245 if(_state.res != RES_NULL)
jehoon 0:df571f8f8c03 246 {
jehoon 0:df571f8f8c03 247 for( i=0; i<RES_TABLE_NUM; i++)
jehoon 0:df571f8f8c03 248 {
jehoon 0:df571f8f8c03 249 if(res_table[i].res == _state.res)
jehoon 0:df571f8f8c03 250 {
jehoon 0:df571f8f8c03 251 if(res_table[i].func != NULL)
jehoon 0:df571f8f8c03 252 {
jehoon 0:df571f8f8c03 253 (this->*(res_table[i].func))(buf);
jehoon 0:df571f8f8c03 254 }
jehoon 0:df571f8f8c03 255
jehoon 0:df571f8f8c03 256 if(res_table[i].res == RES_CONNECT && _state.n < 2)
jehoon 0:df571f8f8c03 257 return -1;
jehoon 0:df571f8f8c03 258 }
jehoon 0:df571f8f8c03 259 }
jehoon 0:df571f8f8c03 260 }
jehoon 0:df571f8f8c03 261
jehoon 0:df571f8f8c03 262 for( i=0; i<MSG_TABLE_NUM; i++)
jehoon 0:df571f8f8c03 263 {
jehoon 0:df571f8f8c03 264 if( strncmp(buf, msg_table[i].msg, strlen(msg_table[i].msg)) == 0 )
jehoon 0:df571f8f8c03 265 {
jehoon 0:df571f8f8c03 266 if(msg_table[i].func != NULL)
jehoon 0:df571f8f8c03 267 {
jehoon 0:df571f8f8c03 268 (this->*(msg_table[i].func))(buf);
jehoon 0:df571f8f8c03 269 }
jehoon 0:df571f8f8c03 270 return 0;
jehoon 0:df571f8f8c03 271 }
jehoon 0:df571f8f8c03 272 }
jehoon 0:df571f8f8c03 273
jehoon 0:df571f8f8c03 274 return -1;
jehoon 0:df571f8f8c03 275 }
jehoon 0:df571f8f8c03 276
jehoon 0:df571f8f8c03 277
jehoon 0:df571f8f8c03 278 void WizFi310::msgOk (const char *buf)
jehoon 0:df571f8f8c03 279 {
jehoon 0:df571f8f8c03 280 _state.ok = true;
jehoon 0:df571f8f8c03 281 }
jehoon 0:df571f8f8c03 282
jehoon 0:df571f8f8c03 283 void WizFi310::msgError (const char *buf)
jehoon 0:df571f8f8c03 284 {
jehoon 0:df571f8f8c03 285 _state.failure = true;
jehoon 0:df571f8f8c03 286 }
jehoon 0:df571f8f8c03 287
jehoon 0:df571f8f8c03 288 void WizFi310::msgConnect (const char *buf)
jehoon 0:df571f8f8c03 289 {
jehoon 0:df571f8f8c03 290 int cid;
jehoon 0:df571f8f8c03 291
jehoon 5:72212beb817c 292 //if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return;
jehoon 5:72212beb817c 293 if( isdigit (buf[9])) return;
jehoon 0:df571f8f8c03 294
jehoon 0:df571f8f8c03 295 cid = x2i(buf[9]);
jehoon 5:72212beb817c 296
jehoon 0:df571f8f8c03 297 initCon(cid, true);
jehoon 0:df571f8f8c03 298 _state.cid = cid;
jehoon 0:df571f8f8c03 299 _con[cid].accept = true;
jehoon 0:df571f8f8c03 300 _con[cid].parent = cid;
jehoon 0:df571f8f8c03 301 }
jehoon 0:df571f8f8c03 302
jehoon 0:df571f8f8c03 303 void WizFi310::msgDisconnect (const char *buf)
jehoon 0:df571f8f8c03 304 {
jehoon 0:df571f8f8c03 305 int cid;
jehoon 0:df571f8f8c03 306
jehoon 5:72212beb817c 307 //if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']') return;
jehoon 5:72212beb817c 308 if( isdigit (buf[9])) return;
jehoon 0:df571f8f8c03 309
jehoon 0:df571f8f8c03 310 cid = x2i(buf[12]);
jehoon 0:df571f8f8c03 311 _con[cid].connected = false;
jehoon 0:df571f8f8c03 312 }
jehoon 0:df571f8f8c03 313
jehoon 1:16e57103a7dd 314
jehoon 1:16e57103a7dd 315 void WizFi310::msgMQTTConnect (const char *buf)
jehoon 1:16e57103a7dd 316 {
jehoon 1:16e57103a7dd 317 int cid = 0;
jehoon 1:16e57103a7dd 318
jehoon 1:16e57103a7dd 319 initCon(cid, true);
jehoon 1:16e57103a7dd 320 _state.cid = cid;
jehoon 1:16e57103a7dd 321 _con[cid].accept = true;
jehoon 1:16e57103a7dd 322 _con[cid].parent = cid;
jehoon 1:16e57103a7dd 323
jehoon 1:16e57103a7dd 324 _con[cid].connected = true;
jehoon 1:16e57103a7dd 325 _state.res = RES_NULL;
jehoon 1:16e57103a7dd 326 _state.ok = true;
jehoon 1:16e57103a7dd 327 }
jehoon 1:16e57103a7dd 328
jehoon 1:16e57103a7dd 329 void WizFi310::msgMQTTDisconnect (const char *buf)
jehoon 1:16e57103a7dd 330 {
jehoon 1:16e57103a7dd 331 int cid = 0;
jehoon 1:16e57103a7dd 332 _con[cid].connected = false;
jehoon 1:16e57103a7dd 333 }
jehoon 1:16e57103a7dd 334
jehoon 1:16e57103a7dd 335
jehoon 0:df571f8f8c03 336 void WizFi310::msgListen (const char *buf)
jehoon 0:df571f8f8c03 337 {
jehoon 0:df571f8f8c03 338 int cid;
jehoon 0:df571f8f8c03 339
jehoon 5:72212beb817c 340 //if(buf[8] < '0' || buf[8] > '8' || buf[9] != ']') return;
jehoon 5:72212beb817c 341 if( isdigit (buf[9])) return;
jehoon 0:df571f8f8c03 342
jehoon 0:df571f8f8c03 343 cid = x2i(buf[8]);
jehoon 0:df571f8f8c03 344 _state.cid = cid;
jehoon 0:df571f8f8c03 345 }
jehoon 0:df571f8f8c03 346
jehoon 0:df571f8f8c03 347 void WizFi310::resMacAddress (const char *buf)
jehoon 0:df571f8f8c03 348 {
jehoon 0:df571f8f8c03 349 if( buf[2] == ':' && buf[5] == ':')
jehoon 0:df571f8f8c03 350 {
jehoon 0:df571f8f8c03 351 strncpy(_state.mac, buf, sizeof(_state.mac));
jehoon 0:df571f8f8c03 352 _state.mac[17] = 0;
jehoon 0:df571f8f8c03 353 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 354
jehoon 5:72212beb817c 355 if(strncmp(_state.mac,CFG_DEFAULT_MAC,sizeof(CFG_DEFAULT_MAC)) == 0){
jehoon 0:df571f8f8c03 356 _state.ok = false;
jehoon 5:72212beb817c 357 }
jehoon 0:df571f8f8c03 358 _state.ok = true;
jehoon 0:df571f8f8c03 359 }
jehoon 0:df571f8f8c03 360 }
jehoon 0:df571f8f8c03 361
jehoon 0:df571f8f8c03 362 void WizFi310::resConnect (const char *buf)
jehoon 0:df571f8f8c03 363 {
jehoon 0:df571f8f8c03 364 int cid;
jehoon 0:df571f8f8c03 365
jehoon 5:72212beb817c 366 if( strstr((char*)buf, RESP_MSG_OK) != NULL){
jehoon 0:df571f8f8c03 367 _state.n++;
jehoon 0:df571f8f8c03 368 }
jehoon 5:72212beb817c 369 else if( strstr((char*)buf, RESP_MSG_CONNECT) != NULL){
jehoon 0:df571f8f8c03 370 cid = x2i(buf[9]);
jehoon 0:df571f8f8c03 371 _state.cid = cid;
jehoon 0:df571f8f8c03 372 _state.n++;
jehoon 0:df571f8f8c03 373 }
jehoon 0:df571f8f8c03 374
jehoon 0:df571f8f8c03 375 if(_state.n >= 2)
jehoon 0:df571f8f8c03 376 {
jehoon 0:df571f8f8c03 377 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 378 _state.ok = true;
jehoon 0:df571f8f8c03 379 }
jehoon 0:df571f8f8c03 380 }
jehoon 0:df571f8f8c03 381
jehoon 0:df571f8f8c03 382 void WizFi310::resSSEND (const char *buf)
jehoon 0:df571f8f8c03 383 {
jehoon 0:df571f8f8c03 384 if(_state.cid != -1)
jehoon 0:df571f8f8c03 385 {
jehoon 0:df571f8f8c03 386 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 387 _state.ok = true;
jehoon 0:df571f8f8c03 388 }
jehoon 0:df571f8f8c03 389 }
jehoon 0:df571f8f8c03 390
jehoon 0:df571f8f8c03 391 void WizFi310::resFDNS (const char *buf)
jehoon 0:df571f8f8c03 392 {
jehoon 0:df571f8f8c03 393 int i;
jehoon 0:df571f8f8c03 394
jehoon 0:df571f8f8c03 395 for(i=0; i<strlen(buf); i++)
jehoon 0:df571f8f8c03 396 {
jehoon 0:df571f8f8c03 397 if( (buf[i] < '0' || buf[i] > '9') && buf[i] != '.' )
jehoon 0:df571f8f8c03 398 {
jehoon 0:df571f8f8c03 399 return;
jehoon 0:df571f8f8c03 400 }
jehoon 0:df571f8f8c03 401 }
jehoon 0:df571f8f8c03 402
jehoon 0:df571f8f8c03 403 strncpy(_state.resolv, buf, sizeof(_state.resolv));
jehoon 0:df571f8f8c03 404 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 405 }
jehoon 0:df571f8f8c03 406
jehoon 0:df571f8f8c03 407 void WizFi310::resSMGMT (const char *buf)
jehoon 0:df571f8f8c03 408 {
jehoon 0:df571f8f8c03 409 int cid, i;
jehoon 0:df571f8f8c03 410 char *c;
jehoon 0:df571f8f8c03 411
jehoon 5:72212beb817c 412 // if( (buf[0] < '0' || buf[0] > '8') ) return;
jehoon 5:72212beb817c 413 if( isdigit (buf[9])) return;
jehoon 0:df571f8f8c03 414
jehoon 0:df571f8f8c03 415 cid = x2i(buf[0]);
jehoon 0:df571f8f8c03 416 if( cid != _state.cid ) return;
jehoon 0:df571f8f8c03 417
jehoon 0:df571f8f8c03 418 // IP
jehoon 0:df571f8f8c03 419 c = (char*)(buf+6);
jehoon 0:df571f8f8c03 420 for( i=0; i<16; i++ )
jehoon 0:df571f8f8c03 421 {
jehoon 0:df571f8f8c03 422 if( *(c+i) == ':')
jehoon 0:df571f8f8c03 423 {
jehoon 0:df571f8f8c03 424 _con[cid].ip[i] = '\0';
jehoon 0:df571f8f8c03 425 i++;
jehoon 0:df571f8f8c03 426 break;
jehoon 0:df571f8f8c03 427 }
jehoon 0:df571f8f8c03 428 if( ( *(c+i) < '0' || *(c+i) > '9') && *(c+i) != '.' ) return;
jehoon 0:df571f8f8c03 429 _con[cid].ip[i] = *(c+i);
jehoon 0:df571f8f8c03 430 }
jehoon 0:df571f8f8c03 431
jehoon 0:df571f8f8c03 432 // Port
jehoon 0:df571f8f8c03 433 c = (c+i);
jehoon 0:df571f8f8c03 434 _con[cid].port = 0;
jehoon 0:df571f8f8c03 435 for( i=0; i<5; i++ )
jehoon 0:df571f8f8c03 436 {
jehoon 0:df571f8f8c03 437 if( *(c+i) == '/') break;
jehoon 0:df571f8f8c03 438 if( *(c+i) < '0' || *(c+i) > '9' ) return;
jehoon 0:df571f8f8c03 439
jehoon 0:df571f8f8c03 440 _con[cid].port = (_con[cid].port * 10) + ( *(c+i) - '0' );
jehoon 0:df571f8f8c03 441 }
jehoon 0:df571f8f8c03 442
jehoon 0:df571f8f8c03 443 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 444 }
jehoon 0:df571f8f8c03 445
jehoon 0:df571f8f8c03 446 void WizFi310::resWSTATUS (const char *buf)
jehoon 0:df571f8f8c03 447 {
jehoon 5:72212beb817c 448 char* idx_ptr;
jehoon 5:72212beb817c 449
jehoon 0:df571f8f8c03 450 if(_state.n == 0)
jehoon 0:df571f8f8c03 451 {
jehoon 0:df571f8f8c03 452 _state.n++;
jehoon 0:df571f8f8c03 453 }
jehoon 0:df571f8f8c03 454 else if(_state.n == 1)
jehoon 0:df571f8f8c03 455 {
jehoon 5:72212beb817c 456 idx_ptr = strtok((char*)buf, "/"); // Interface STA or AP
jehoon 5:72212beb817c 457 idx_ptr = strtok( NULL, "/"); // SSID
jehoon 5:72212beb817c 458 idx_ptr = strtok( NULL, "/"); // IP Addr
jehoon 5:72212beb817c 459 memset(_state.ip, 0, sizeof(_state.ip));
jehoon 5:72212beb817c 460 memcpy(_state.ip, idx_ptr, strlen(idx_ptr)+1);
jehoon 5:72212beb817c 461
jehoon 5:72212beb817c 462 idx_ptr = strtok( NULL, "/"); // Gateway Addr
jehoon 5:72212beb817c 463 memset(_state.gateway, 0, sizeof(_state.gateway));
jehoon 5:72212beb817c 464 memcpy(_state.gateway, idx_ptr, strlen(idx_ptr)+1);
jehoon 0:df571f8f8c03 465
jehoon 0:df571f8f8c03 466 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 467 }
jehoon 5:72212beb817c 468
jehoon 5:72212beb817c 469 }