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 Oct 10 05:12:51 2016 +0000
Revision:
1:16e57103a7dd
Parent:
0:df571f8f8c03
Child:
5:72212beb817c
mqtt receive

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