Freedman v2
Fork of WizFi250Interface by
WizFi250/WizFi250_msg.cpp@9:12ecb377f63f, 2015-06-19 (annotated)
- Committer:
- kaizen8501
- Date:
- Fri Jun 19 15:34:40 2015 +0900
- Revision:
- 9:12ecb377f63f
- Parent:
- 8:431172d536ee
- Child:
- 12:bb8e979df6df
Fixed Bug when using TCP Server, TCP Client
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; |
kaizen8501 |
9:12ecb377f63f | 146 | _con[cid].recv_length = len; |
DongEun Koak | 8:431172d536ee | 147 | } |
DongEun Koak | 8:431172d536ee | 148 | else |
DongEun Koak | 8:431172d536ee | 149 | { |
DongEun Koak | 8:431172d536ee | 150 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 151 | } |
DongEun Koak | 8:431172d536ee | 152 | break; |
kaizen | 0:f2039204c8f6 | 153 | |
DongEun Koak | 8:431172d536ee | 154 | default: |
DongEun Koak | 8:431172d536ee | 155 | if(_con[cid].buf != NULL) |
DongEun Koak | 8:431172d536ee | 156 | { |
DongEun Koak | 8:431172d536ee | 157 | _con[cid].buf->queue(c); |
DongEun Koak | 8:431172d536ee | 158 | if(_con[cid].buf->available() > CFG_DATA_SIZE - 16 ) |
DongEun Koak | 8:431172d536ee | 159 | { |
DongEun Koak | 8:431172d536ee | 160 | setRts(false); // blcok |
DongEun Koak | 8:431172d536ee | 161 | _con[cid].received = true; |
kaizen8501 |
9:12ecb377f63f | 162 | WIZ_WARN("buf full"); |
DongEun Koak | 8:431172d536ee | 163 | } |
DongEun Koak | 8:431172d536ee | 164 | } |
kaizen8501 |
9:12ecb377f63f | 165 | _con[cid].recv_length--; |
kaizen8501 |
9:12ecb377f63f | 166 | if(_con[cid].recv_length == 0) |
DongEun Koak | 8:431172d536ee | 167 | { |
kaizen8501 |
9:12ecb377f63f | 168 | //WIZ_DBG("recv cid: %d, count : %d, len : %d",cid, count, len); |
DongEun Koak | 8:431172d536ee | 169 | _con[cid].received = true; |
DongEun Koak | 8:431172d536ee | 170 | _state.mode = MODE_COMMAND; |
DongEun Koak | 8:431172d536ee | 171 | } |
DongEun Koak | 8:431172d536ee | 172 | break; |
DongEun Koak | 8:431172d536ee | 173 | } |
DongEun Koak | 8:431172d536ee | 174 | break; |
DongEun Koak | 8:431172d536ee | 175 | } |
kaizen | 0:f2039204c8f6 | 176 | } |
kaizen | 0:f2039204c8f6 | 177 | |
kaizen | 0:f2039204c8f6 | 178 | |
kaizen | 0:f2039204c8f6 | 179 | #define MSG_TABLE_NUM 6 |
kaizen | 0:f2039204c8f6 | 180 | #define RES_TABLE_NUM 7 |
kaizen | 0:f2039204c8f6 | 181 | int WizFi250::parseMessage () { |
DongEun Koak | 8:431172d536ee | 182 | int i; |
kaizen8501 |
9:12ecb377f63f | 183 | char buf[128]; |
kaizen | 0:f2039204c8f6 | 184 | |
DongEun Koak | 8:431172d536ee | 185 | static const struct MSG_TABLE { |
DongEun Koak | 8:431172d536ee | 186 | const char msg[24]; |
DongEun Koak | 8:431172d536ee | 187 | void (WizFi250::*func)(const char *); |
DongEun Koak | 8:431172d536ee | 188 | } msg_table[MSG_TABLE_NUM] = { |
DongEun Koak | 8:431172d536ee | 189 | {"[OK]", &WizFi250::msgOk}, |
DongEun Koak | 8:431172d536ee | 190 | {"[ERROR]", &WizFi250::msgError}, |
DongEun Koak | 8:431172d536ee | 191 | {"[ERROR:INVALIDINPUT]", &WizFi250::msgError}, |
DongEun Koak | 8:431172d536ee | 192 | {"[CONNECT ", &WizFi250::msgConnect}, |
DongEun Koak | 8:431172d536ee | 193 | {"[DISCONNECT ", &WizFi250::msgDisconnect}, |
DongEun Koak | 8:431172d536ee | 194 | {"[LISTEN ", &WizFi250::msgListen}, |
kaizen | 0:f2039204c8f6 | 195 | }; |
DongEun Koak | 8:431172d536ee | 196 | static const struct RES_TABLE{ |
DongEun Koak | 8:431172d536ee | 197 | const Response res; |
DongEun Koak | 8:431172d536ee | 198 | void (WizFi250::*func)(const char *); |
DongEun Koak | 8:431172d536ee | 199 | }res_table[RES_TABLE_NUM]={ |
DongEun Koak | 8:431172d536ee | 200 | {RES_NULL, NULL}, |
DongEun Koak | 8:431172d536ee | 201 | {RES_MACADDRESS, &WizFi250::resMacAddress}, |
kaizen8501 |
9:12ecb377f63f | 202 | // {RES_WJOIN, &WizFi250::resWJOIN}, |
DongEun Koak | 8:431172d536ee | 203 | {RES_CONNECT, &WizFi250::resConnect}, |
DongEun Koak | 8:431172d536ee | 204 | {RES_SSEND, &WizFi250::resSSEND}, |
DongEun Koak | 8:431172d536ee | 205 | {RES_FDNS, &WizFi250::resFDNS}, |
DongEun Koak | 8:431172d536ee | 206 | {RES_SMGMT, &WizFi250::resSMGMT}, |
kaizen8501 |
9:12ecb377f63f | 207 | {RES_WSTATUS, &WizFi250::resWSTATUS}, |
DongEun Koak | 8:431172d536ee | 208 | }; |
kaizen | 0:f2039204c8f6 | 209 | |
kaizen | 0:f2039204c8f6 | 210 | |
DongEun Koak | 8:431172d536ee | 211 | for( i=0; i<sizeof(buf); i++ ) |
DongEun Koak | 8:431172d536ee | 212 | { |
DongEun Koak | 8:431172d536ee | 213 | if( _state.buf->dequeue(&buf[i]) == false ) break; |
DongEun Koak | 8:431172d536ee | 214 | } |
kaizen | 0:f2039204c8f6 | 215 | |
DongEun Koak | 8:431172d536ee | 216 | buf[i] = '\0'; |
DongEun Koak | 8:431172d536ee | 217 | //strncpy(_state.dbgRespBuf, buf, sizeof(buf) ); |
DongEun Koak | 8:431172d536ee | 218 | //WIZ_DBG("%s\r\n",_state.dbgRespBuf); |
kaizen | 0:f2039204c8f6 | 219 | |
DongEun Koak | 8:431172d536ee | 220 | if(_state.res != RES_NULL) |
DongEun Koak | 8:431172d536ee | 221 | { |
DongEun Koak | 8:431172d536ee | 222 | for( i=0; i<RES_TABLE_NUM; i++) |
DongEun Koak | 8:431172d536ee | 223 | { |
DongEun Koak | 8:431172d536ee | 224 | if(res_table[i].res == _state.res) |
DongEun Koak | 8:431172d536ee | 225 | { |
DongEun Koak | 8:431172d536ee | 226 | //WIZ_DBG("parse res %d '%s'\r\n", i, buf); |
DongEun Koak | 8:431172d536ee | 227 | if(res_table[i].func != NULL) |
DongEun Koak | 8:431172d536ee | 228 | { |
DongEun Koak | 8:431172d536ee | 229 | (this->*(res_table[i].func))(buf); |
DongEun Koak | 8:431172d536ee | 230 | } |
kaizen | 0:f2039204c8f6 | 231 | |
DongEun Koak | 8:431172d536ee | 232 | if(res_table[i].res == RES_CONNECT && _state.n < 2) |
DongEun Koak | 8:431172d536ee | 233 | return -1; |
DongEun Koak | 8:431172d536ee | 234 | } |
DongEun Koak | 8:431172d536ee | 235 | } |
DongEun Koak | 8:431172d536ee | 236 | } |
kaizen | 0:f2039204c8f6 | 237 | |
DongEun Koak | 8:431172d536ee | 238 | for( i=0; i<MSG_TABLE_NUM; i++) |
DongEun Koak | 8:431172d536ee | 239 | { |
DongEun Koak | 8:431172d536ee | 240 | if( strncmp(buf, msg_table[i].msg, strlen(msg_table[i].msg)) == 0 ) |
DongEun Koak | 8:431172d536ee | 241 | { |
DongEun Koak | 8:431172d536ee | 242 | //WIZ_DBG("parse msg '%s'\r\n", buf); |
DongEun Koak | 8:431172d536ee | 243 | if(msg_table[i].func != NULL) |
DongEun Koak | 8:431172d536ee | 244 | { |
DongEun Koak | 8:431172d536ee | 245 | (this->*(msg_table[i].func))(buf); |
DongEun Koak | 8:431172d536ee | 246 | } |
DongEun Koak | 8:431172d536ee | 247 | return 0; |
DongEun Koak | 8:431172d536ee | 248 | } |
DongEun Koak | 8:431172d536ee | 249 | } |
kaizen | 0:f2039204c8f6 | 250 | |
DongEun Koak | 8:431172d536ee | 251 | return -1; |
kaizen | 0:f2039204c8f6 | 252 | } |
kaizen | 0:f2039204c8f6 | 253 | |
kaizen | 0:f2039204c8f6 | 254 | |
kaizen | 0:f2039204c8f6 | 255 | void WizFi250::msgOk (const char *buf) |
kaizen | 0:f2039204c8f6 | 256 | { |
DongEun Koak | 8:431172d536ee | 257 | _state.ok = true; |
kaizen | 0:f2039204c8f6 | 258 | } |
kaizen | 0:f2039204c8f6 | 259 | |
kaizen | 0:f2039204c8f6 | 260 | void WizFi250::msgError (const char *buf) |
kaizen | 0:f2039204c8f6 | 261 | { |
DongEun Koak | 8:431172d536ee | 262 | _state.failure = true; |
kaizen | 0:f2039204c8f6 | 263 | } |
kaizen | 0:f2039204c8f6 | 264 | |
kaizen | 0:f2039204c8f6 | 265 | void WizFi250::msgConnect (const char *buf) |
kaizen | 0:f2039204c8f6 | 266 | { |
DongEun Koak | 8:431172d536ee | 267 | int cid; |
kaizen | 0:f2039204c8f6 | 268 | |
DongEun Koak | 8:431172d536ee | 269 | if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return; |
kaizen | 0:f2039204c8f6 | 270 | |
DongEun Koak | 8:431172d536ee | 271 | cid = x2i(buf[9]); |
kaizen | 0:f2039204c8f6 | 272 | |
DongEun Koak | 8:431172d536ee | 273 | initCon(cid, true); |
DongEun Koak | 8:431172d536ee | 274 | _state.cid = cid; |
DongEun Koak | 8:431172d536ee | 275 | _con[cid].accept = true; |
DongEun Koak | 8:431172d536ee | 276 | _con[cid].parent = cid; |
kaizen | 0:f2039204c8f6 | 277 | } |
kaizen | 0:f2039204c8f6 | 278 | |
kaizen | 0:f2039204c8f6 | 279 | void WizFi250::msgDisconnect (const char *buf) |
kaizen | 0:f2039204c8f6 | 280 | { |
DongEun Koak | 8:431172d536ee | 281 | int cid; |
kaizen | 0:f2039204c8f6 | 282 | |
DongEun Koak | 8:431172d536ee | 283 | if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']') return; |
kaizen | 0:f2039204c8f6 | 284 | |
DongEun Koak | 8:431172d536ee | 285 | cid = x2i(buf[12]); |
DongEun Koak | 8:431172d536ee | 286 | _con[cid].connected = false; |
kaizen | 0:f2039204c8f6 | 287 | } |
kaizen | 0:f2039204c8f6 | 288 | |
kaizen | 0:f2039204c8f6 | 289 | void WizFi250::msgListen (const char *buf) |
kaizen | 0:f2039204c8f6 | 290 | { |
DongEun Koak | 8:431172d536ee | 291 | int cid; |
kaizen | 0:f2039204c8f6 | 292 | |
DongEun Koak | 8:431172d536ee | 293 | if(buf[8] < '0' || buf[8] > '8' || buf[9] != ']') return; |
kaizen | 0:f2039204c8f6 | 294 | |
DongEun Koak | 8:431172d536ee | 295 | cid = x2i(buf[8]); |
DongEun Koak | 8:431172d536ee | 296 | _state.cid = cid; |
kaizen | 0:f2039204c8f6 | 297 | } |
kaizen | 0:f2039204c8f6 | 298 | |
kaizen | 0:f2039204c8f6 | 299 | void WizFi250::resMacAddress (const char *buf) |
kaizen | 0:f2039204c8f6 | 300 | { |
DongEun Koak | 8:431172d536ee | 301 | if( buf[2] == ':' && buf[5] == ':') |
DongEun Koak | 8:431172d536ee | 302 | { |
DongEun Koak | 8:431172d536ee | 303 | strncpy(_state.mac, buf, sizeof(_state.mac)); |
DongEun Koak | 8:431172d536ee | 304 | _state.mac[17] = 0; |
DongEun Koak | 8:431172d536ee | 305 | _state.res = RES_NULL; |
DongEun Koak | 7:ba28fe711055 | 306 | |
DongEun Koak | 8:431172d536ee | 307 | if(strncmp(_state.mac,CFG_DEFAULT_MAC,sizeof(CFG_DEFAULT_MAC)) == 0) |
DongEun Koak | 8:431172d536ee | 308 | _state.ok = false; |
DongEun Koak | 8:431172d536ee | 309 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 310 | } |
kaizen | 0:f2039204c8f6 | 311 | } |
kaizen | 0:f2039204c8f6 | 312 | |
kaizen | 0:f2039204c8f6 | 313 | void WizFi250::resConnect (const char *buf) |
kaizen | 0:f2039204c8f6 | 314 | { |
DongEun Koak | 8:431172d536ee | 315 | int cid; |
kaizen | 0:f2039204c8f6 | 316 | |
kaizen8501 |
9:12ecb377f63f | 317 | if (buf[0] == '[' && buf[1] == 'O' && buf[2] == 'K' && buf[3] == ']') |
kaizen8501 |
9:12ecb377f63f | 318 | { |
DongEun Koak | 8:431172d536ee | 319 | _state.n++; |
kaizen8501 |
9:12ecb377f63f | 320 | } |
kaizen8501 |
9:12ecb377f63f | 321 | else if( buf[0] == '[' && buf[1] == 'C' && buf[2] == 'O' && buf[3] == 'N' && |
kaizen8501 |
9:12ecb377f63f | 322 | buf[4] == 'N' && buf[5] == 'E' && buf[6] == 'C' && buf[7] == 'T') |
DongEun Koak | 8:431172d536ee | 323 | { |
DongEun Koak | 8:431172d536ee | 324 | cid = x2i(buf[9]); |
DongEun Koak | 8:431172d536ee | 325 | _state.cid = cid; |
DongEun Koak | 8:431172d536ee | 326 | _state.n++; |
DongEun Koak | 8:431172d536ee | 327 | } |
kaizen | 0:f2039204c8f6 | 328 | |
kaizen8501 |
9:12ecb377f63f | 329 | if(_state.n >= 2) |
DongEun Koak | 8:431172d536ee | 330 | { |
kaizen8501 |
9:12ecb377f63f | 331 | _state.res = RES_NULL; |
DongEun Koak | 8:431172d536ee | 332 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 333 | } |
kaizen | 0:f2039204c8f6 | 334 | } |
kaizen | 0:f2039204c8f6 | 335 | |
kaizen | 0:f2039204c8f6 | 336 | void WizFi250::resSSEND (const char *buf) |
kaizen | 0:f2039204c8f6 | 337 | { |
DongEun Koak | 8:431172d536ee | 338 | if(_state.cid != -1) |
DongEun Koak | 8:431172d536ee | 339 | { |
DongEun Koak | 8:431172d536ee | 340 | _state.res = RES_NULL; |
DongEun Koak | 8:431172d536ee | 341 | _state.ok = true; |
DongEun Koak | 8:431172d536ee | 342 | } |
kaizen | 0:f2039204c8f6 | 343 | } |
kaizen | 0:f2039204c8f6 | 344 | |
kaizen | 0:f2039204c8f6 | 345 | void WizFi250::resFDNS (const char *buf) |
kaizen | 0:f2039204c8f6 | 346 | { |
DongEun Koak | 8:431172d536ee | 347 | int i; |
kaizen | 0:f2039204c8f6 | 348 | |
DongEun Koak | 8:431172d536ee | 349 | for(i=0; i<strlen(buf); i++) |
DongEun Koak | 8:431172d536ee | 350 | { |
DongEun Koak | 8:431172d536ee | 351 | if( (buf[i] < '0' || buf[i] > '9') && buf[i] != '.' ) |
DongEun Koak | 8:431172d536ee | 352 | { |
DongEun Koak | 8:431172d536ee | 353 | return; |
DongEun Koak | 8:431172d536ee | 354 | } |
DongEun Koak | 8:431172d536ee | 355 | } |
kaizen | 0:f2039204c8f6 | 356 | |
DongEun Koak | 8:431172d536ee | 357 | strncpy(_state.resolv, buf, sizeof(_state.resolv)); |
DongEun Koak | 8:431172d536ee | 358 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 359 | } |
kaizen | 0:f2039204c8f6 | 360 | |
kaizen | 0:f2039204c8f6 | 361 | void WizFi250::resSMGMT (const char *buf) |
kaizen | 0:f2039204c8f6 | 362 | { |
DongEun Koak | 8:431172d536ee | 363 | int cid, i; |
DongEun Koak | 8:431172d536ee | 364 | char *c; |
kaizen | 0:f2039204c8f6 | 365 | |
DongEun Koak | 8:431172d536ee | 366 | if( (buf[0] < '0' || buf[0] > '8') ) return; |
kaizen | 0:f2039204c8f6 | 367 | |
DongEun Koak | 8:431172d536ee | 368 | cid = x2i(buf[0]); |
DongEun Koak | 8:431172d536ee | 369 | if( cid != _state.cid ) return; |
kaizen | 0:f2039204c8f6 | 370 | |
DongEun Koak | 8:431172d536ee | 371 | // IP |
DongEun Koak | 8:431172d536ee | 372 | c = (char*)(buf+6); |
DongEun Koak | 8:431172d536ee | 373 | for( i=0; i<16; i++ ) |
DongEun Koak | 8:431172d536ee | 374 | { |
DongEun Koak | 8:431172d536ee | 375 | if( *(c+i) == ':') |
DongEun Koak | 8:431172d536ee | 376 | { |
DongEun Koak | 8:431172d536ee | 377 | _con[cid].ip[i] = '\0'; |
DongEun Koak | 8:431172d536ee | 378 | i++; |
DongEun Koak | 8:431172d536ee | 379 | break; |
DongEun Koak | 8:431172d536ee | 380 | } |
DongEun Koak | 8:431172d536ee | 381 | if( ( *(c+i) < '0' || *(c+i) > '9') && *(c+i) != '.' ) return; |
DongEun Koak | 8:431172d536ee | 382 | _con[cid].ip[i] = *(c+i); |
DongEun Koak | 8:431172d536ee | 383 | } |
kaizen | 0:f2039204c8f6 | 384 | |
DongEun Koak | 8:431172d536ee | 385 | // Port |
DongEun Koak | 8:431172d536ee | 386 | c = (c+i); |
DongEun Koak | 8:431172d536ee | 387 | _con[cid].port = 0; |
DongEun Koak | 8:431172d536ee | 388 | for( i=0; i<5; i++ ) |
DongEun Koak | 8:431172d536ee | 389 | { |
DongEun Koak | 8:431172d536ee | 390 | if( *(c+i) == '/') break; |
DongEun Koak | 8:431172d536ee | 391 | if( *(c+i) < '0' || *(c+i) > '9' ) return; |
kaizen | 0:f2039204c8f6 | 392 | |
DongEun Koak | 8:431172d536ee | 393 | _con[cid].port = (_con[cid].port * 10) + ( *(c+i) - '0' ); |
DongEun Koak | 8:431172d536ee | 394 | } |
kaizen | 0:f2039204c8f6 | 395 | |
DongEun Koak | 8:431172d536ee | 396 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 397 | } |
kaizen8501 |
9:12ecb377f63f | 398 | |
kaizen8501 |
9:12ecb377f63f | 399 | void WizFi250::resWSTATUS (const char *buf) |
kaizen8501 |
9:12ecb377f63f | 400 | { |
kaizen8501 |
9:12ecb377f63f | 401 | int idx=0,sep_cnt=0; |
kaizen8501 |
9:12ecb377f63f | 402 | int ip_idx=0,gw_idx=0; |
kaizen8501 |
9:12ecb377f63f | 403 | |
kaizen8501 |
9:12ecb377f63f | 404 | if(_state.n == 0) |
kaizen8501 |
9:12ecb377f63f | 405 | { |
kaizen8501 |
9:12ecb377f63f | 406 | _state.n++; |
kaizen8501 |
9:12ecb377f63f | 407 | } |
kaizen8501 |
9:12ecb377f63f | 408 | else if(_state.n == 1) |
kaizen8501 |
9:12ecb377f63f | 409 | { |
kaizen8501 |
9:12ecb377f63f | 410 | for(idx=0;buf[idx]!='\r';idx++) |
kaizen8501 |
9:12ecb377f63f | 411 | { |
kaizen8501 |
9:12ecb377f63f | 412 | if(buf[idx] =='/') |
kaizen8501 |
9:12ecb377f63f | 413 | { |
kaizen8501 |
9:12ecb377f63f | 414 | sep_cnt++; |
kaizen8501 |
9:12ecb377f63f | 415 | continue; |
kaizen8501 |
9:12ecb377f63f | 416 | } |
kaizen8501 |
9:12ecb377f63f | 417 | |
kaizen8501 |
9:12ecb377f63f | 418 | if( sep_cnt == 2) // IP Address |
kaizen8501 |
9:12ecb377f63f | 419 | { |
kaizen8501 |
9:12ecb377f63f | 420 | _state.ip[ip_idx++] = buf[idx]; |
kaizen8501 |
9:12ecb377f63f | 421 | } |
kaizen8501 |
9:12ecb377f63f | 422 | else if(sep_cnt == 3) |
kaizen8501 |
9:12ecb377f63f | 423 | { |
kaizen8501 |
9:12ecb377f63f | 424 | _state.gateway[gw_idx++] = buf[idx]; |
kaizen8501 |
9:12ecb377f63f | 425 | } |
kaizen8501 |
9:12ecb377f63f | 426 | } |
kaizen8501 |
9:12ecb377f63f | 427 | _state.ip[ip_idx] = '\0'; |
kaizen8501 |
9:12ecb377f63f | 428 | _state.gateway[gw_idx] = '\0'; |
kaizen8501 |
9:12ecb377f63f | 429 | _state.res = RES_NULL; |
kaizen8501 |
9:12ecb377f63f | 430 | } |
kaizen8501 |
9:12ecb377f63f | 431 | } |