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:
Thu Nov 23 23:51:30 2017 +0000
Revision:
7:08771e4906bb
Parent:
6:007cec5e96c0
fix socket 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 {RESP_MSG_CONNECT, &WizFi310::msgConnect},
jehoon 5:72212beb817c 217 {RESP_MSG_DISCONNECT, &WizFi310::msgDisconnect},
jehoon 5:72212beb817c 218 {RESP_MSG_LISTEN, &WizFi310::msgListen},
jehoon 5:72212beb817c 219 {RESP_MSG_MQTTCON, &WizFi310::msgMQTTConnect},
jehoon 5:72212beb817c 220 {RESP_MSG_MQTTDISCON, &WizFi310::msgMQTTDisconnect},
jehoon 0:df571f8f8c03 221 };
jehoon 0:df571f8f8c03 222 static const struct RES_TABLE{
jehoon 0:df571f8f8c03 223 const Response res;
jehoon 0:df571f8f8c03 224 void (WizFi310::*func)(const char *);
jehoon 0:df571f8f8c03 225 }res_table[RES_TABLE_NUM]={
jehoon 0:df571f8f8c03 226 {RES_NULL, NULL},
jehoon 0:df571f8f8c03 227 {RES_MACADDRESS, &WizFi310::resMacAddress},
jehoon 0:df571f8f8c03 228 // {RES_WJOIN, &WizFi310::resWJOIN},
jehoon 0:df571f8f8c03 229 {RES_CONNECT, &WizFi310::resConnect},
jehoon 0:df571f8f8c03 230 {RES_SSEND, &WizFi310::resSSEND},
jehoon 0:df571f8f8c03 231 {RES_FDNS, &WizFi310::resFDNS},
jehoon 0:df571f8f8c03 232 {RES_SMGMT, &WizFi310::resSMGMT},
jehoon 0:df571f8f8c03 233 {RES_WSTATUS, &WizFi310::resWSTATUS},
jehoon 0:df571f8f8c03 234 };
jehoon 0:df571f8f8c03 235
jehoon 0:df571f8f8c03 236
jehoon 0:df571f8f8c03 237 for( i=0; i<sizeof(buf); i++ )
jehoon 0:df571f8f8c03 238 {
jehoon 0:df571f8f8c03 239 if( _state.buf->dequeue(&buf[i]) == false ) break;
jehoon 0:df571f8f8c03 240 }
jehoon 0:df571f8f8c03 241
jehoon 0:df571f8f8c03 242 buf[i] = '\0';
jehoon 5:72212beb817c 243
jehoon 0:df571f8f8c03 244 if(_state.res != RES_NULL)
jehoon 0:df571f8f8c03 245 {
jehoon 0:df571f8f8c03 246 for( i=0; i<RES_TABLE_NUM; i++)
jehoon 0:df571f8f8c03 247 {
jehoon 0:df571f8f8c03 248 if(res_table[i].res == _state.res)
jehoon 0:df571f8f8c03 249 {
jehoon 0:df571f8f8c03 250 if(res_table[i].func != NULL)
jehoon 0:df571f8f8c03 251 {
jehoon 0:df571f8f8c03 252 (this->*(res_table[i].func))(buf);
jehoon 0:df571f8f8c03 253 }
jehoon 0:df571f8f8c03 254
jehoon 0:df571f8f8c03 255 if(res_table[i].res == RES_CONNECT && _state.n < 2)
jehoon 0:df571f8f8c03 256 return -1;
jehoon 0:df571f8f8c03 257 }
jehoon 0:df571f8f8c03 258 }
jehoon 0:df571f8f8c03 259 }
jehoon 0:df571f8f8c03 260
jehoon 0:df571f8f8c03 261 for( i=0; i<MSG_TABLE_NUM; i++)
jehoon 0:df571f8f8c03 262 {
jehoon 0:df571f8f8c03 263 if( strncmp(buf, msg_table[i].msg, strlen(msg_table[i].msg)) == 0 )
jehoon 0:df571f8f8c03 264 {
jehoon 0:df571f8f8c03 265 if(msg_table[i].func != NULL)
jehoon 0:df571f8f8c03 266 {
jehoon 0:df571f8f8c03 267 (this->*(msg_table[i].func))(buf);
jehoon 0:df571f8f8c03 268 }
jehoon 0:df571f8f8c03 269 return 0;
jehoon 0:df571f8f8c03 270 }
jehoon 0:df571f8f8c03 271 }
jehoon 0:df571f8f8c03 272
jehoon 0:df571f8f8c03 273 return -1;
jehoon 0:df571f8f8c03 274 }
jehoon 0:df571f8f8c03 275
jehoon 0:df571f8f8c03 276
jehoon 0:df571f8f8c03 277 void WizFi310::msgOk (const char *buf)
jehoon 0:df571f8f8c03 278 {
jehoon 0:df571f8f8c03 279 _state.ok = true;
jehoon 0:df571f8f8c03 280 }
jehoon 0:df571f8f8c03 281
jehoon 0:df571f8f8c03 282 void WizFi310::msgError (const char *buf)
jehoon 0:df571f8f8c03 283 {
jehoon 0:df571f8f8c03 284 _state.failure = true;
jehoon 0:df571f8f8c03 285 }
jehoon 0:df571f8f8c03 286
jehoon 0:df571f8f8c03 287 void WizFi310::msgConnect (const char *buf)
jehoon 0:df571f8f8c03 288 {
jehoon 0:df571f8f8c03 289 int cid;
jehoon 0:df571f8f8c03 290
jehoon 5:72212beb817c 291 //if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return;
jehoon 7:08771e4906bb 292 if( isdigit(buf[9]) == 0 ) return;
jehoon 0:df571f8f8c03 293
jehoon 0:df571f8f8c03 294 cid = x2i(buf[9]);
jehoon 5:72212beb817c 295
jehoon 0:df571f8f8c03 296 initCon(cid, true);
jehoon 0:df571f8f8c03 297 _state.cid = cid;
jehoon 0:df571f8f8c03 298 _con[cid].accept = true;
jehoon 0:df571f8f8c03 299 _con[cid].parent = cid;
jehoon 0:df571f8f8c03 300 }
jehoon 0:df571f8f8c03 301
jehoon 0:df571f8f8c03 302 void WizFi310::msgDisconnect (const char *buf)
jehoon 0:df571f8f8c03 303 {
jehoon 0:df571f8f8c03 304 int cid;
jehoon 0:df571f8f8c03 305
jehoon 5:72212beb817c 306 //if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']') return;
jehoon 7:08771e4906bb 307 if( isdigit(buf[12]) == 0 ) return;
jehoon 0:df571f8f8c03 308
jehoon 0:df571f8f8c03 309 cid = x2i(buf[12]);
jehoon 0:df571f8f8c03 310 _con[cid].connected = false;
jehoon 0:df571f8f8c03 311 }
jehoon 0:df571f8f8c03 312
jehoon 1:16e57103a7dd 313
jehoon 1:16e57103a7dd 314 void WizFi310::msgMQTTConnect (const char *buf)
jehoon 1:16e57103a7dd 315 {
jehoon 1:16e57103a7dd 316 int cid = 0;
jehoon 1:16e57103a7dd 317
jehoon 1:16e57103a7dd 318 initCon(cid, true);
jehoon 1:16e57103a7dd 319 _state.cid = cid;
jehoon 1:16e57103a7dd 320 _con[cid].accept = true;
jehoon 1:16e57103a7dd 321 _con[cid].parent = cid;
jehoon 1:16e57103a7dd 322
jehoon 1:16e57103a7dd 323 _con[cid].connected = true;
jehoon 1:16e57103a7dd 324 _state.res = RES_NULL;
jehoon 1:16e57103a7dd 325 _state.ok = true;
jehoon 1:16e57103a7dd 326 }
jehoon 1:16e57103a7dd 327
jehoon 1:16e57103a7dd 328 void WizFi310::msgMQTTDisconnect (const char *buf)
jehoon 1:16e57103a7dd 329 {
jehoon 1:16e57103a7dd 330 int cid = 0;
jehoon 1:16e57103a7dd 331 _con[cid].connected = false;
jehoon 1:16e57103a7dd 332 }
jehoon 1:16e57103a7dd 333
jehoon 1:16e57103a7dd 334
jehoon 0:df571f8f8c03 335 void WizFi310::msgListen (const char *buf)
jehoon 0:df571f8f8c03 336 {
jehoon 0:df571f8f8c03 337 int cid;
jehoon 0:df571f8f8c03 338
jehoon 5:72212beb817c 339 //if(buf[8] < '0' || buf[8] > '8' || buf[9] != ']') return;
jehoon 7:08771e4906bb 340 if( isdigit(buf[8]) == 0 ) return;
jehoon 0:df571f8f8c03 341
jehoon 0:df571f8f8c03 342 cid = x2i(buf[8]);
jehoon 0:df571f8f8c03 343 _state.cid = cid;
jehoon 0:df571f8f8c03 344 }
jehoon 0:df571f8f8c03 345
jehoon 0:df571f8f8c03 346 void WizFi310::resMacAddress (const char *buf)
jehoon 0:df571f8f8c03 347 {
jehoon 0:df571f8f8c03 348 if( buf[2] == ':' && buf[5] == ':')
jehoon 0:df571f8f8c03 349 {
jehoon 0:df571f8f8c03 350 strncpy(_state.mac, buf, sizeof(_state.mac));
jehoon 0:df571f8f8c03 351 _state.mac[17] = 0;
jehoon 0:df571f8f8c03 352 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 353
jehoon 5:72212beb817c 354 if(strncmp(_state.mac,CFG_DEFAULT_MAC,sizeof(CFG_DEFAULT_MAC)) == 0){
jehoon 0:df571f8f8c03 355 _state.ok = false;
jehoon 5:72212beb817c 356 }
jehoon 0:df571f8f8c03 357 _state.ok = true;
jehoon 0:df571f8f8c03 358 }
jehoon 0:df571f8f8c03 359 }
jehoon 0:df571f8f8c03 360
jehoon 0:df571f8f8c03 361 void WizFi310::resConnect (const char *buf)
jehoon 0:df571f8f8c03 362 {
jehoon 0:df571f8f8c03 363 int cid;
jehoon 0:df571f8f8c03 364
jehoon 5:72212beb817c 365 if( strstr((char*)buf, RESP_MSG_OK) != NULL){
jehoon 0:df571f8f8c03 366 _state.n++;
jehoon 0:df571f8f8c03 367 }
jehoon 5:72212beb817c 368 else if( strstr((char*)buf, RESP_MSG_CONNECT) != NULL){
jehoon 0:df571f8f8c03 369 cid = x2i(buf[9]);
jehoon 0:df571f8f8c03 370 _state.cid = cid;
jehoon 0:df571f8f8c03 371 _state.n++;
jehoon 0:df571f8f8c03 372 }
jehoon 0:df571f8f8c03 373
jehoon 0:df571f8f8c03 374 if(_state.n >= 2)
jehoon 0:df571f8f8c03 375 {
jehoon 0:df571f8f8c03 376 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 377 _state.ok = true;
jehoon 0:df571f8f8c03 378 }
jehoon 0:df571f8f8c03 379 }
jehoon 0:df571f8f8c03 380
jehoon 0:df571f8f8c03 381 void WizFi310::resSSEND (const char *buf)
jehoon 0:df571f8f8c03 382 {
jehoon 0:df571f8f8c03 383 if(_state.cid != -1)
jehoon 0:df571f8f8c03 384 {
jehoon 0:df571f8f8c03 385 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 386 _state.ok = true;
jehoon 0:df571f8f8c03 387 }
jehoon 0:df571f8f8c03 388 }
jehoon 0:df571f8f8c03 389
jehoon 0:df571f8f8c03 390 void WizFi310::resFDNS (const char *buf)
jehoon 0:df571f8f8c03 391 {
jehoon 0:df571f8f8c03 392 int i;
jehoon 0:df571f8f8c03 393
jehoon 0:df571f8f8c03 394 for(i=0; i<strlen(buf); i++)
jehoon 0:df571f8f8c03 395 {
jehoon 0:df571f8f8c03 396 if( (buf[i] < '0' || buf[i] > '9') && buf[i] != '.' )
jehoon 0:df571f8f8c03 397 {
jehoon 0:df571f8f8c03 398 return;
jehoon 0:df571f8f8c03 399 }
jehoon 0:df571f8f8c03 400 }
jehoon 0:df571f8f8c03 401
jehoon 0:df571f8f8c03 402 strncpy(_state.resolv, buf, sizeof(_state.resolv));
jehoon 0:df571f8f8c03 403 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 404 }
jehoon 0:df571f8f8c03 405
jehoon 0:df571f8f8c03 406 void WizFi310::resSMGMT (const char *buf)
jehoon 0:df571f8f8c03 407 {
jehoon 0:df571f8f8c03 408 int cid, i;
jehoon 0:df571f8f8c03 409 char *c;
jehoon 0:df571f8f8c03 410
jehoon 5:72212beb817c 411 // if( (buf[0] < '0' || buf[0] > '8') ) return;
jehoon 6:007cec5e96c0 412 if( isdigit (buf[0])) return;
jehoon 0:df571f8f8c03 413
jehoon 0:df571f8f8c03 414 cid = x2i(buf[0]);
jehoon 0:df571f8f8c03 415 if( cid != _state.cid ) return;
jehoon 0:df571f8f8c03 416
jehoon 0:df571f8f8c03 417 // IP
jehoon 0:df571f8f8c03 418 c = (char*)(buf+6);
jehoon 0:df571f8f8c03 419 for( i=0; i<16; i++ )
jehoon 0:df571f8f8c03 420 {
jehoon 0:df571f8f8c03 421 if( *(c+i) == ':')
jehoon 0:df571f8f8c03 422 {
jehoon 0:df571f8f8c03 423 _con[cid].ip[i] = '\0';
jehoon 0:df571f8f8c03 424 i++;
jehoon 0:df571f8f8c03 425 break;
jehoon 0:df571f8f8c03 426 }
jehoon 0:df571f8f8c03 427 if( ( *(c+i) < '0' || *(c+i) > '9') && *(c+i) != '.' ) return;
jehoon 0:df571f8f8c03 428 _con[cid].ip[i] = *(c+i);
jehoon 0:df571f8f8c03 429 }
jehoon 0:df571f8f8c03 430
jehoon 0:df571f8f8c03 431 // Port
jehoon 0:df571f8f8c03 432 c = (c+i);
jehoon 0:df571f8f8c03 433 _con[cid].port = 0;
jehoon 0:df571f8f8c03 434 for( i=0; i<5; i++ )
jehoon 0:df571f8f8c03 435 {
jehoon 0:df571f8f8c03 436 if( *(c+i) == '/') break;
jehoon 0:df571f8f8c03 437 if( *(c+i) < '0' || *(c+i) > '9' ) return;
jehoon 0:df571f8f8c03 438
jehoon 0:df571f8f8c03 439 _con[cid].port = (_con[cid].port * 10) + ( *(c+i) - '0' );
jehoon 0:df571f8f8c03 440 }
jehoon 0:df571f8f8c03 441
jehoon 0:df571f8f8c03 442 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 443 }
jehoon 0:df571f8f8c03 444
jehoon 0:df571f8f8c03 445 void WizFi310::resWSTATUS (const char *buf)
jehoon 0:df571f8f8c03 446 {
jehoon 5:72212beb817c 447 char* idx_ptr;
jehoon 5:72212beb817c 448
jehoon 0:df571f8f8c03 449 if(_state.n == 0)
jehoon 0:df571f8f8c03 450 {
jehoon 0:df571f8f8c03 451 _state.n++;
jehoon 0:df571f8f8c03 452 }
jehoon 0:df571f8f8c03 453 else if(_state.n == 1)
jehoon 0:df571f8f8c03 454 {
jehoon 5:72212beb817c 455 idx_ptr = strtok((char*)buf, "/"); // Interface STA or AP
jehoon 5:72212beb817c 456 idx_ptr = strtok( NULL, "/"); // SSID
jehoon 5:72212beb817c 457 idx_ptr = strtok( NULL, "/"); // IP Addr
jehoon 5:72212beb817c 458 memset(_state.ip, 0, sizeof(_state.ip));
jehoon 5:72212beb817c 459 memcpy(_state.ip, idx_ptr, strlen(idx_ptr)+1);
jehoon 5:72212beb817c 460
jehoon 5:72212beb817c 461 idx_ptr = strtok( NULL, "/"); // Gateway Addr
jehoon 5:72212beb817c 462 memset(_state.gateway, 0, sizeof(_state.gateway));
jehoon 5:72212beb817c 463 memcpy(_state.gateway, idx_ptr, strlen(idx_ptr)+1);
jehoon 0:df571f8f8c03 464
jehoon 0:df571f8f8c03 465 _state.res = RES_NULL;
jehoon 0:df571f8f8c03 466 }
jehoon 5:72212beb817c 467
jehoon 5:72212beb817c 468 }