RC
Dependents: WizFi250_AP_HelloWorld
Fork of WizFi250Interface by
WizFi250/WizFi250_msg.cpp@8:431172d536ee, 2014-11-14 (annotated)
- Committer:
- DongEun Koak
- Date:
- Fri Nov 14 16:53:10 2014 +0900
- Revision:
- 8:431172d536ee
- Parent:
- 7:ba28fe711055
- Child:
- 9:12ecb377f63f
Had some refactoring
Who changed what in which revision?
User | Revision | Line number | New 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 | { |
DongEun Koak | 8:431172d536ee | 33 | static int cid, sub, len, count; |
kaizen | 0:f2039204c8f6 | 34 | |
DongEun Koak | 8:431172d536ee | 35 | switch(_state.mode) |
DongEun Koak | 8:431172d536ee | 36 | { |
DongEun Koak | 8:431172d536ee | 37 | case MODE_COMMAND: |
DongEun Koak | 8:431172d536ee | 38 | switch(c) |
DongEun Koak | 8:431172d536ee | 39 | { |
DongEun Koak | 8:431172d536ee | 40 | case 0: |
DongEun Koak | 8:431172d536ee | 41 | case 0x0a: // LF |
DongEun Koak | 8:431172d536ee | 42 | case 0x0d: // CR |
DongEun Koak | 8:431172d536ee | 43 | break; |
kaizen | 0:f2039204c8f6 | 44 | |
DongEun Koak | 8:431172d536ee | 45 | case '{': |
DongEun Koak | 8:431172d536ee | 46 | _state.buf->flush(); |
DongEun Koak | 8:431172d536ee | 47 | _state.mode = MODE_DATA_RX; |
DongEun Koak | 8:431172d536ee | 48 | sub = 0; |
DongEun Koak | 8:431172d536ee | 49 | break; |
kaizen | 0:f2039204c8f6 | 50 | |
DongEun Koak | 8:431172d536ee | 51 | default: |
DongEun Koak | 8:431172d536ee | 52 | _state.buf->flush(); |
DongEun Koak | 8:431172d536ee | 53 | _state.buf->queue(c); |
DongEun Koak | 8:431172d536ee | 54 | _state.mode = MODE_CMDRESP; |
DongEun Koak | 8:431172d536ee | 55 | break; |
DongEun Koak | 8:431172d536ee | 56 | } |
DongEun Koak | 8:431172d536ee | 57 | break; |
kaizen | 0:f2039204c8f6 | 58 | |
DongEun Koak | 8:431172d536ee | 59 | case MODE_CMDRESP: |
DongEun Koak | 8:431172d536ee | 60 | switch(c) |
DongEun Koak | 8:431172d536ee | 61 | { |
DongEun Koak | 8:431172d536ee | 62 | case 0: |
DongEun Koak | 8:431172d536ee | 63 | break; |
DongEun Koak | 8:431172d536ee | 64 | case 0x0a: // LF |
DongEun Koak | 8:431172d536ee | 65 | break; |
DongEun Koak | 8:431172d536ee | 66 | case 0x0d: // CR |
DongEun Koak | 8:431172d536ee | 67 | if (_flow == 2) setRts(false); // block |
DongEun Koak | 8:431172d536ee | 68 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 69 | parseMessage(); |
DongEun Koak | 8:431172d536ee | 70 | if (_flow == 2) setRts(true); // release |
DongEun Koak | 8:431172d536ee | 71 | break; |
DongEun Koak | 8:431172d536ee | 72 | default: |
DongEun Koak | 8:431172d536ee | 73 | _state.buf->queue(c); |
DongEun Koak | 8:431172d536ee | 74 | break; |
DongEun Koak | 8:431172d536ee | 75 | } |
DongEun Koak | 8:431172d536ee | 76 | break; |
kaizen | 0:f2039204c8f6 | 77 | |
DongEun Koak | 8:431172d536ee | 78 | case MODE_DATA_RX: |
DongEun Koak | 8:431172d536ee | 79 | switch(sub) |
DongEun Koak | 8:431172d536ee | 80 | { |
DongEun Koak | 8:431172d536ee | 81 | case 0: |
DongEun Koak | 8:431172d536ee | 82 | // cid |
DongEun Koak | 8:431172d536ee | 83 | if( (c >= '0') && (c <= '9') ) |
DongEun Koak | 8:431172d536ee | 84 | { |
DongEun Koak | 8:431172d536ee | 85 | cid = x2i(c); |
DongEun Koak | 8:431172d536ee | 86 | } |
DongEun Koak | 8:431172d536ee | 87 | else if ( c == ',' ) |
DongEun Koak | 8:431172d536ee | 88 | { |
DongEun Koak | 8:431172d536ee | 89 | sub++; |
DongEun Koak | 8:431172d536ee | 90 | count = 0; |
DongEun Koak | 8:431172d536ee | 91 | len = 0; |
DongEun Koak | 8:431172d536ee | 92 | } |
DongEun Koak | 8:431172d536ee | 93 | else |
DongEun Koak | 8:431172d536ee | 94 | { |
DongEun Koak | 8:431172d536ee | 95 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 96 | } |
DongEun Koak | 8:431172d536ee | 97 | break; |
kaizen | 0:f2039204c8f6 | 98 | |
DongEun Koak | 8:431172d536ee | 99 | case 1: |
DongEun Koak | 8:431172d536ee | 100 | // ip |
DongEun Koak | 8:431172d536ee | 101 | if ((c >= '0' && c <= '9') || c == '.') |
DongEun Koak | 8:431172d536ee | 102 | { |
DongEun Koak | 8:431172d536ee | 103 | _con[cid].ip[count] = c; |
DongEun Koak | 8:431172d536ee | 104 | count++; |
DongEun Koak | 8:431172d536ee | 105 | } |
DongEun Koak | 8:431172d536ee | 106 | else if( c == ',' ) |
DongEun Koak | 8:431172d536ee | 107 | { |
DongEun Koak | 8:431172d536ee | 108 | _con[cid].ip[count] = '\0'; |
DongEun Koak | 8:431172d536ee | 109 | _con[cid].port = 0; |
DongEun Koak | 8:431172d536ee | 110 | sub++; |
DongEun Koak | 8:431172d536ee | 111 | } |
DongEun Koak | 8:431172d536ee | 112 | else |
DongEun Koak | 8:431172d536ee | 113 | { |
DongEun Koak | 8:431172d536ee | 114 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 115 | } |
DongEun Koak | 8:431172d536ee | 116 | break; |
kaizen | 0:f2039204c8f6 | 117 | |
DongEun Koak | 8:431172d536ee | 118 | case 2: |
DongEun Koak | 8:431172d536ee | 119 | // port |
DongEun Koak | 8:431172d536ee | 120 | if ( c >= '0' && c <= '9' ) |
DongEun Koak | 8:431172d536ee | 121 | { |
DongEun Koak | 8:431172d536ee | 122 | _con[cid].port = (_con[cid].port * 10) + ( c - '0' ); |
DongEun Koak | 8:431172d536ee | 123 | } |
DongEun Koak | 8:431172d536ee | 124 | else if( c == ',') |
DongEun Koak | 8:431172d536ee | 125 | { |
DongEun Koak | 8:431172d536ee | 126 | sub++; |
DongEun Koak | 8:431172d536ee | 127 | count = 0; |
DongEun Koak | 8:431172d536ee | 128 | } |
DongEun Koak | 8:431172d536ee | 129 | else |
DongEun Koak | 8:431172d536ee | 130 | { |
DongEun Koak | 8:431172d536ee | 131 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 132 | } |
DongEun Koak | 8:431172d536ee | 133 | break; |
kaizen | 0:f2039204c8f6 | 134 | |
DongEun Koak | 8:431172d536ee | 135 | case 3: |
DongEun Koak | 8:431172d536ee | 136 | // data length |
DongEun Koak | 8:431172d536ee | 137 | if ( c >= '0' && c <= '9' ) |
DongEun Koak | 8:431172d536ee | 138 | { |
DongEun Koak | 8:431172d536ee | 139 | //_con[cid].recv_length = (_con[cid].recv_length * 10) + (c - '0'); |
DongEun Koak | 8:431172d536ee | 140 | len = (len * 10) + (c - '0'); |
DongEun Koak | 8:431172d536ee | 141 | } |
DongEun Koak | 8:431172d536ee | 142 | else if( c == '}' ) |
DongEun Koak | 8:431172d536ee | 143 | { |
DongEun Koak | 8:431172d536ee | 144 | sub++; |
DongEun Koak | 8:431172d536ee | 145 | count = 0; |
DongEun Koak | 8:431172d536ee | 146 | } |
DongEun Koak | 8:431172d536ee | 147 | else |
DongEun Koak | 8:431172d536ee | 148 | { |
DongEun Koak | 8:431172d536ee | 149 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 150 | } |
DongEun Koak | 8:431172d536ee | 151 | break; |
kaizen | 0:f2039204c8f6 | 152 | |
DongEun Koak | 8:431172d536ee | 153 | default: |
DongEun Koak | 8:431172d536ee | 154 | if(_con[cid].buf != NULL) |
DongEun Koak | 8:431172d536ee | 155 | { |
DongEun Koak | 8:431172d536ee | 156 | _con[cid].buf->queue(c); |
DongEun Koak | 8:431172d536ee | 157 | if(_con[cid].buf->available() > CFG_DATA_SIZE - 16 ) |
DongEun Koak | 8:431172d536ee | 158 | { |
DongEun Koak | 8:431172d536ee | 159 | setRts(false); // blcok |
DongEun Koak | 8:431172d536ee | 160 | _con[cid].received = true; |
DongEun Koak | 8:431172d536ee | 161 | //WIZ_WARN("buf full"); |
DongEun Koak | 8:431172d536ee | 162 | } |
DongEun Koak | 8:431172d536ee | 163 | } |
DongEun Koak | 8:431172d536ee | 164 | count++; |
DongEun Koak | 8:431172d536ee | 165 | if(count >= len) |
DongEun Koak | 8:431172d536ee | 166 | { |
DongEun Koak | 8:431172d536ee | 167 | // WIZ_DBG("recv cid: %d, count : %d, len : %d",cid, count, len); |
DongEun Koak | 8:431172d536ee | 168 | _con[cid].received = true; |
DongEun Koak | 8:431172d536ee | 169 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 170 | } |
DongEun Koak | 8:431172d536ee | 171 | break; |
DongEun Koak | 8:431172d536ee | 172 | } |
DongEun Koak | 8:431172d536ee | 173 | break; |
DongEun Koak | 8:431172d536ee | 174 | } |
kaizen | 0:f2039204c8f6 | 175 | } |
kaizen | 0:f2039204c8f6 | 176 | |
kaizen | 0:f2039204c8f6 | 177 | |
kaizen | 0:f2039204c8f6 | 178 | #define MSG_TABLE_NUM 6 |
kaizen | 0:f2039204c8f6 | 179 | #define RES_TABLE_NUM 7 |
kaizen | 0:f2039204c8f6 | 180 | int WizFi250::parseMessage () { |
DongEun Koak | 8:431172d536ee | 181 | int i; |
DongEun Koak | 8:431172d536ee | 182 | char buf[256]; |
kaizen | 0:f2039204c8f6 | 183 | |
DongEun Koak | 8:431172d536ee | 184 | static const struct MSG_TABLE { |
DongEun Koak | 8:431172d536ee | 185 | const char msg[24]; |
DongEun Koak | 8:431172d536ee | 186 | void (WizFi250::*func)(const char *); |
DongEun Koak | 8:431172d536ee | 187 | } msg_table[MSG_TABLE_NUM] = { |
DongEun Koak | 8:431172d536ee | 188 | {"[OK]", &WizFi250::msgOk}, |
DongEun Koak | 8:431172d536ee | 189 | {"[ERROR]", &WizFi250::msgError}, |
DongEun Koak | 8:431172d536ee | 190 | {"[ERROR:INVALIDINPUT]", &WizFi250::msgError}, |
DongEun Koak | 8:431172d536ee | 191 | {"[CONNECT ", &WizFi250::msgConnect}, |
DongEun Koak | 8:431172d536ee | 192 | {"[DISCONNECT ", &WizFi250::msgDisconnect}, |
DongEun Koak | 8:431172d536ee | 193 | {"[LISTEN ", &WizFi250::msgListen}, |
kaizen | 0:f2039204c8f6 | 194 | }; |
DongEun Koak | 8:431172d536ee | 195 | static const struct RES_TABLE{ |
DongEun Koak | 8:431172d536ee | 196 | const Response res; |
DongEun Koak | 8:431172d536ee | 197 | void (WizFi250::*func)(const char *); |
DongEun Koak | 8:431172d536ee | 198 | }res_table[RES_TABLE_NUM]={ |
DongEun Koak | 8:431172d536ee | 199 | {RES_NULL, NULL}, |
DongEun Koak | 8:431172d536ee | 200 | {RES_MACADDRESS, &WizFi250::resMacAddress}, |
DongEun Koak | 8:431172d536ee | 201 | {RES_WJOIN, &WizFi250::resWJOIN}, |
DongEun Koak | 8:431172d536ee | 202 | {RES_CONNECT, &WizFi250::resConnect}, |
DongEun Koak | 8:431172d536ee | 203 | {RES_SSEND, &WizFi250::resSSEND}, |
DongEun Koak | 8:431172d536ee | 204 | {RES_FDNS, &WizFi250::resFDNS}, |
DongEun Koak | 8:431172d536ee | 205 | {RES_SMGMT, &WizFi250::resSMGMT}, |
DongEun Koak | 8:431172d536ee | 206 | }; |
kaizen | 0:f2039204c8f6 | 207 | |
kaizen | 0:f2039204c8f6 | 208 | |
DongEun Koak | 8:431172d536ee | 209 | for( i=0; i<sizeof(buf); i++ ) |
DongEun Koak | 8:431172d536ee | 210 | { |
DongEun Koak | 8:431172d536ee | 211 | if( _state.buf->dequeue(&buf[i]) == false ) break; |
DongEun Koak | 8:431172d536ee | 212 | } |
kaizen | 0:f2039204c8f6 | 213 | |
DongEun Koak | 8:431172d536ee | 214 | buf[i] = '\0'; |
DongEun Koak | 8:431172d536ee | 215 | //strncpy(_state.dbgRespBuf, buf, sizeof(buf) ); |
DongEun Koak | 8:431172d536ee | 216 | //WIZ_DBG("%s\r\n",_state.dbgRespBuf); |
kaizen | 0:f2039204c8f6 | 217 | |
DongEun Koak | 8:431172d536ee | 218 | if(_state.res != RES_NULL) |
DongEun Koak | 8:431172d536ee | 219 | { |
DongEun Koak | 8:431172d536ee | 220 | for( i=0; i<RES_TABLE_NUM; i++) |
DongEun Koak | 8:431172d536ee | 221 | { |
DongEun Koak | 8:431172d536ee | 222 | if(res_table[i].res == _state.res) |
DongEun Koak | 8:431172d536ee | 223 | { |
DongEun Koak | 8:431172d536ee | 224 | //WIZ_DBG("parse res %d '%s'\r\n", i, buf); |
DongEun Koak | 8:431172d536ee | 225 | if(res_table[i].func != NULL) |
DongEun Koak | 8:431172d536ee | 226 | { |
DongEun Koak | 8:431172d536ee | 227 | (this->*(res_table[i].func))(buf); |
DongEun Koak | 8:431172d536ee | 228 | } |
kaizen | 0:f2039204c8f6 | 229 | |
DongEun Koak | 8:431172d536ee | 230 | if(res_table[i].res == RES_CONNECT && _state.n < 2) |
DongEun Koak | 8:431172d536ee | 231 | return -1; |
DongEun Koak | 8:431172d536ee | 232 | } |
DongEun Koak | 8:431172d536ee | 233 | } |
DongEun Koak | 8:431172d536ee | 234 | } |
kaizen | 0:f2039204c8f6 | 235 | |
DongEun Koak | 8:431172d536ee | 236 | for( i=0; i<MSG_TABLE_NUM; i++) |
DongEun Koak | 8:431172d536ee | 237 | { |
DongEun Koak | 8:431172d536ee | 238 | if( strncmp(buf, msg_table[i].msg, strlen(msg_table[i].msg)) == 0 ) |
DongEun Koak | 8:431172d536ee | 239 | { |
DongEun Koak | 8:431172d536ee | 240 | //WIZ_DBG("parse msg '%s'\r\n", buf); |
DongEun Koak | 8:431172d536ee | 241 | if(msg_table[i].func != NULL) |
DongEun Koak | 8:431172d536ee | 242 | { |
DongEun Koak | 8:431172d536ee | 243 | (this->*(msg_table[i].func))(buf); |
DongEun Koak | 8:431172d536ee | 244 | } |
DongEun Koak | 8:431172d536ee | 245 | return 0; |
DongEun Koak | 8:431172d536ee | 246 | } |
DongEun Koak | 8:431172d536ee | 247 | } |
kaizen | 0:f2039204c8f6 | 248 | |
DongEun Koak | 8:431172d536ee | 249 | return -1; |
kaizen | 0:f2039204c8f6 | 250 | } |
kaizen | 0:f2039204c8f6 | 251 | |
kaizen | 0:f2039204c8f6 | 252 | |
kaizen | 0:f2039204c8f6 | 253 | void WizFi250::msgOk (const char *buf) |
kaizen | 0:f2039204c8f6 | 254 | { |
DongEun Koak | 8:431172d536ee | 255 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 256 | |
DongEun Koak | 8:431172d536ee | 257 | // kaizen 20141114 It have to check for debugging |
DongEun Koak | 8:431172d536ee | 258 | strncpy(_state.dummyBuf,buf,strlen(buf)); |
kaizen | 0:f2039204c8f6 | 259 | } |
kaizen | 0:f2039204c8f6 | 260 | |
kaizen | 0:f2039204c8f6 | 261 | void WizFi250::msgError (const char *buf) |
kaizen | 0:f2039204c8f6 | 262 | { |
DongEun Koak | 8:431172d536ee | 263 | _state.failure = true; |
kaizen | 0:f2039204c8f6 | 264 | } |
kaizen | 0:f2039204c8f6 | 265 | |
kaizen | 0:f2039204c8f6 | 266 | void WizFi250::msgConnect (const char *buf) |
kaizen | 0:f2039204c8f6 | 267 | { |
DongEun Koak | 8:431172d536ee | 268 | int cid; |
kaizen | 0:f2039204c8f6 | 269 | |
DongEun Koak | 8:431172d536ee | 270 | if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return; |
kaizen | 0:f2039204c8f6 | 271 | |
DongEun Koak | 8:431172d536ee | 272 | cid = x2i(buf[9]); |
kaizen | 0:f2039204c8f6 | 273 | |
DongEun Koak | 8:431172d536ee | 274 | initCon(cid, true); |
DongEun Koak | 8:431172d536ee | 275 | _state.cid = cid; |
DongEun Koak | 8:431172d536ee | 276 | _con[cid].accept = true; |
DongEun Koak | 8:431172d536ee | 277 | _con[cid].parent = cid; |
kaizen | 0:f2039204c8f6 | 278 | } |
kaizen | 0:f2039204c8f6 | 279 | |
kaizen | 0:f2039204c8f6 | 280 | void WizFi250::msgDisconnect (const char *buf) |
kaizen | 0:f2039204c8f6 | 281 | { |
DongEun Koak | 8:431172d536ee | 282 | int cid; |
kaizen | 0:f2039204c8f6 | 283 | |
DongEun Koak | 8:431172d536ee | 284 | if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']') return; |
kaizen | 0:f2039204c8f6 | 285 | |
DongEun Koak | 8:431172d536ee | 286 | cid = x2i(buf[12]); |
DongEun Koak | 8:431172d536ee | 287 | _con[cid].connected = false; |
kaizen | 0:f2039204c8f6 | 288 | } |
kaizen | 0:f2039204c8f6 | 289 | |
kaizen | 0:f2039204c8f6 | 290 | void WizFi250::msgListen (const char *buf) |
kaizen | 0:f2039204c8f6 | 291 | { |
DongEun Koak | 8:431172d536ee | 292 | int cid; |
kaizen | 0:f2039204c8f6 | 293 | |
DongEun Koak | 8:431172d536ee | 294 | if(buf[8] < '0' || buf[8] > '8' || buf[9] != ']') return; |
kaizen | 0:f2039204c8f6 | 295 | |
DongEun Koak | 8:431172d536ee | 296 | cid = x2i(buf[8]); |
DongEun Koak | 8:431172d536ee | 297 | _state.cid = cid; |
kaizen | 0:f2039204c8f6 | 298 | } |
kaizen | 0:f2039204c8f6 | 299 | |
kaizen | 0:f2039204c8f6 | 300 | void WizFi250::resMacAddress (const char *buf) |
kaizen | 0:f2039204c8f6 | 301 | { |
DongEun Koak | 8:431172d536ee | 302 | if( buf[2] == ':' && buf[5] == ':') |
DongEun Koak | 8:431172d536ee | 303 | { |
DongEun Koak | 8:431172d536ee | 304 | strncpy(_state.mac, buf, sizeof(_state.mac)); |
DongEun Koak | 8:431172d536ee | 305 | _state.mac[17] = 0; |
DongEun Koak | 8:431172d536ee | 306 | _state.res = RES_NULL; |
DongEun Koak | 7:ba28fe711055 | 307 | |
DongEun Koak | 8:431172d536ee | 308 | if(strncmp(_state.mac,CFG_DEFAULT_MAC,sizeof(CFG_DEFAULT_MAC)) == 0) |
DongEun Koak | 8:431172d536ee | 309 | _state.ok = false; |
DongEun Koak | 8:431172d536ee | 310 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 311 | } |
kaizen | 0:f2039204c8f6 | 312 | } |
kaizen | 0:f2039204c8f6 | 313 | |
kaizen | 0:f2039204c8f6 | 314 | void WizFi250::resWJOIN (const char *buf) |
kaizen | 0:f2039204c8f6 | 315 | { |
DongEun Koak | 8:431172d536ee | 316 | const char *tmp; |
DongEun Koak | 8:431172d536ee | 317 | int i; |
kaizen | 0:f2039204c8f6 | 318 | |
DongEun Koak | 8:431172d536ee | 319 | if(_state.n == 0 && strstr(buf, "IP Addr")) |
DongEun Koak | 8:431172d536ee | 320 | { |
DongEun Koak | 8:431172d536ee | 321 | tmp = strstr(buf, ":") + 2; // Because space |
DongEun Koak | 8:431172d536ee | 322 | for(i=0; i<strlen(tmp); i++) |
DongEun Koak | 8:431172d536ee | 323 | _state.ip[i] = tmp[i]; |
kaizen | 0:f2039204c8f6 | 324 | |
DongEun Koak | 8:431172d536ee | 325 | _state.ip[i] = '\0'; |
DongEun Koak | 8:431172d536ee | 326 | _state.n++; |
DongEun Koak | 8:431172d536ee | 327 | } |
kaizen | 0:f2039204c8f6 | 328 | |
DongEun Koak | 8:431172d536ee | 329 | if(_state.n == 1 && strstr(buf, "Gateway")) |
DongEun Koak | 8:431172d536ee | 330 | { |
DongEun Koak | 8:431172d536ee | 331 | tmp = strstr(buf, ":") + 2; |
DongEun Koak | 8:431172d536ee | 332 | for(i=0; i<strlen(tmp); i++) |
DongEun Koak | 8:431172d536ee | 333 | _state.gateway[i] = tmp[i]; |
kaizen | 0:f2039204c8f6 | 334 | |
DongEun Koak | 8:431172d536ee | 335 | _state.gateway[i] = '\0'; |
DongEun Koak | 8:431172d536ee | 336 | _state.res = RES_NULL; |
DongEun Koak | 8:431172d536ee | 337 | } |
kaizen | 0:f2039204c8f6 | 338 | } |
kaizen | 0:f2039204c8f6 | 339 | |
kaizen | 0:f2039204c8f6 | 340 | void WizFi250::resConnect (const char *buf) |
kaizen | 0:f2039204c8f6 | 341 | { |
DongEun Koak | 8:431172d536ee | 342 | int cid; |
kaizen | 0:f2039204c8f6 | 343 | |
DongEun Koak | 8:431172d536ee | 344 | if (strncmp(buf,"[OK]",4) == 0) |
DongEun Koak | 8:431172d536ee | 345 | _state.n++; |
DongEun Koak | 8:431172d536ee | 346 | else if( strncmp(buf,"[CONNECT",8) == 0 ) |
DongEun Koak | 8:431172d536ee | 347 | { |
DongEun Koak | 8:431172d536ee | 348 | cid = x2i(buf[9]); |
DongEun Koak | 8:431172d536ee | 349 | initCon(cid, true); |
DongEun Koak | 8:431172d536ee | 350 | _state.cid = cid; |
DongEun Koak | 8:431172d536ee | 351 | _state.res = RES_NULL; |
DongEun Koak | 8:431172d536ee | 352 | _state.n++; |
kaizen | 0:f2039204c8f6 | 353 | |
DongEun Koak | 8:431172d536ee | 354 | // for debuging |
DongEun Koak | 8:431172d536ee | 355 | //_state.dummyBuf[0] = buf[9]; |
DongEun Koak | 8:431172d536ee | 356 | //_state.dummyBuf[1] = '\0'; |
DongEun Koak | 8:431172d536ee | 357 | } |
kaizen | 0:f2039204c8f6 | 358 | |
DongEun Koak | 8:431172d536ee | 359 | if(_state.n == 2) |
DongEun Koak | 8:431172d536ee | 360 | { |
DongEun Koak | 8:431172d536ee | 361 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 362 | } |
kaizen | 0:f2039204c8f6 | 363 | } |
kaizen | 0:f2039204c8f6 | 364 | |
kaizen | 0:f2039204c8f6 | 365 | void WizFi250::resSSEND (const char *buf) |
kaizen | 0:f2039204c8f6 | 366 | { |
DongEun Koak | 8:431172d536ee | 367 | if(_state.cid != -1) |
DongEun Koak | 8:431172d536ee | 368 | { |
DongEun Koak | 8:431172d536ee | 369 | _state.res = RES_NULL; |
DongEun Koak | 8:431172d536ee | 370 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 371 | } |
kaizen | 0:f2039204c8f6 | 372 | } |
kaizen | 0:f2039204c8f6 | 373 | |
kaizen | 0:f2039204c8f6 | 374 | void WizFi250::resFDNS (const char *buf) |
kaizen | 0:f2039204c8f6 | 375 | { |
DongEun Koak | 8:431172d536ee | 376 | int i; |
kaizen | 0:f2039204c8f6 | 377 | |
DongEun Koak | 8:431172d536ee | 378 | for(i=0; i<strlen(buf); i++) |
DongEun Koak | 8:431172d536ee | 379 | { |
DongEun Koak | 8:431172d536ee | 380 | if( (buf[i] < '0' || buf[i] > '9') && buf[i] != '.' ) |
DongEun Koak | 8:431172d536ee | 381 | { |
DongEun Koak | 8:431172d536ee | 382 | return; |
DongEun Koak | 8:431172d536ee | 383 | } |
DongEun Koak | 8:431172d536ee | 384 | } |
kaizen | 0:f2039204c8f6 | 385 | |
DongEun Koak | 8:431172d536ee | 386 | strncpy(_state.resolv, buf, sizeof(_state.resolv)); |
DongEun Koak | 8:431172d536ee | 387 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 388 | } |
kaizen | 0:f2039204c8f6 | 389 | |
kaizen | 0:f2039204c8f6 | 390 | void WizFi250::resSMGMT (const char *buf) |
kaizen | 0:f2039204c8f6 | 391 | { |
DongEun Koak | 8:431172d536ee | 392 | int cid, i; |
DongEun Koak | 8:431172d536ee | 393 | char *c; |
kaizen | 0:f2039204c8f6 | 394 | |
DongEun Koak | 8:431172d536ee | 395 | if( (buf[0] < '0' || buf[0] > '8') ) return; |
kaizen | 0:f2039204c8f6 | 396 | |
DongEun Koak | 8:431172d536ee | 397 | cid = x2i(buf[0]); |
DongEun Koak | 8:431172d536ee | 398 | if( cid != _state.cid ) return; |
kaizen | 0:f2039204c8f6 | 399 | |
DongEun Koak | 8:431172d536ee | 400 | // IP |
DongEun Koak | 8:431172d536ee | 401 | c = (char*)(buf+6); |
DongEun Koak | 8:431172d536ee | 402 | for( i=0; i<16; i++ ) |
DongEun Koak | 8:431172d536ee | 403 | { |
DongEun Koak | 8:431172d536ee | 404 | if( *(c+i) == ':') |
DongEun Koak | 8:431172d536ee | 405 | { |
DongEun Koak | 8:431172d536ee | 406 | _con[cid].ip[i] = '\0'; |
DongEun Koak | 8:431172d536ee | 407 | i++; |
DongEun Koak | 8:431172d536ee | 408 | break; |
DongEun Koak | 8:431172d536ee | 409 | } |
DongEun Koak | 8:431172d536ee | 410 | if( ( *(c+i) < '0' || *(c+i) > '9') && *(c+i) != '.' ) return; |
DongEun Koak | 8:431172d536ee | 411 | _con[cid].ip[i] = *(c+i); |
DongEun Koak | 8:431172d536ee | 412 | } |
kaizen | 0:f2039204c8f6 | 413 | |
DongEun Koak | 8:431172d536ee | 414 | // Port |
DongEun Koak | 8:431172d536ee | 415 | c = (c+i); |
DongEun Koak | 8:431172d536ee | 416 | _con[cid].port = 0; |
DongEun Koak | 8:431172d536ee | 417 | for( i=0; i<5; i++ ) |
DongEun Koak | 8:431172d536ee | 418 | { |
DongEun Koak | 8:431172d536ee | 419 | if( *(c+i) == '/') break; |
DongEun Koak | 8:431172d536ee | 420 | if( *(c+i) < '0' || *(c+i) > '9' ) return; |
kaizen | 0:f2039204c8f6 | 421 | |
DongEun Koak | 8:431172d536ee | 422 | _con[cid].port = (_con[cid].port * 10) + ( *(c+i) - '0' ); |
DongEun Koak | 8:431172d536ee | 423 | } |
kaizen | 0:f2039204c8f6 | 424 | |
DongEun Koak | 8:431172d536ee | 425 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 426 | } |