RC
Dependents: WizFi250_AP_HelloWorld
Fork of WizFi250Interface by
WizFi250/WizFi250_at.cpp@5:8a0702aa91e3, 2014-11-14 (annotated)
- Committer:
- DongEun Koak
- Date:
- Fri Nov 14 15:14:56 2014 +0900
- Revision:
- 5:8a0702aa91e3
- Parent:
- 4:085e7efeae47
- Child:
- 7:ba28fe711055
Change name of macro for debugging.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaizen | 0:f2039204c8f6 | 1 | /* |
DongEun Koak | 4:085e7efeae47 | 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 | |
kaizen | 0:f2039204c8f6 | 24 | #include "WizFi250.h" |
kaizen | 0:f2039204c8f6 | 25 | |
kaizen | 0:f2039204c8f6 | 26 | |
kaizen | 0:f2039204c8f6 | 27 | |
kaizen | 0:f2039204c8f6 | 28 | void WizFi250::clearFlags() |
kaizen | 0:f2039204c8f6 | 29 | { |
kaizen | 0:f2039204c8f6 | 30 | _state.ok = false; |
kaizen | 0:f2039204c8f6 | 31 | _state.failure = false; |
kaizen | 0:f2039204c8f6 | 32 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 33 | _state.n = 0; |
kaizen | 0:f2039204c8f6 | 34 | } |
kaizen | 0:f2039204c8f6 | 35 | |
kaizen | 0:f2039204c8f6 | 36 | int WizFi250::sendCommand(const char * cmd, const char *ACK, char *res , int timeout, int opt) |
kaizen | 0:f2039204c8f6 | 37 | { |
kaizen | 0:f2039204c8f6 | 38 | char read; |
kaizen | 0:f2039204c8f6 | 39 | int i; |
kaizen | 0:f2039204c8f6 | 40 | Timer t; |
kaizen | 0:f2039204c8f6 | 41 | string checking; |
kaizen | 0:f2039204c8f6 | 42 | size_t found = string::npos; |
kaizen | 0:f2039204c8f6 | 43 | |
kaizen | 0:f2039204c8f6 | 44 | |
kaizen | 0:f2039204c8f6 | 45 | //attach_rx(false); |
kaizen | 0:f2039204c8f6 | 46 | if (lockUart(timeout)) return -1; |
kaizen | 0:f2039204c8f6 | 47 | |
kaizen | 0:f2039204c8f6 | 48 | // flush the buffer |
kaizen | 0:f2039204c8f6 | 49 | while(_wizfi.readable()) |
kaizen | 0:f2039204c8f6 | 50 | { |
kaizen | 0:f2039204c8f6 | 51 | printf("%c",_wizfi.getc()); |
kaizen | 0:f2039204c8f6 | 52 | } |
kaizen | 0:f2039204c8f6 | 53 | |
kaizen | 0:f2039204c8f6 | 54 | clearFlags(); |
kaizen | 0:f2039204c8f6 | 55 | |
kaizen | 0:f2039204c8f6 | 56 | INFO("command: '%s'", cmd) |
kaizen | 0:f2039204c8f6 | 57 | for (i=0; i< strlen(cmd); i++) |
kaizen | 0:f2039204c8f6 | 58 | { |
kaizen | 0:f2039204c8f6 | 59 | putUart(cmd[i]); |
kaizen | 0:f2039204c8f6 | 60 | } |
kaizen | 0:f2039204c8f6 | 61 | |
kaizen | 0:f2039204c8f6 | 62 | if(opt == 0) |
kaizen | 0:f2039204c8f6 | 63 | { |
kaizen | 0:f2039204c8f6 | 64 | |
kaizen | 0:f2039204c8f6 | 65 | } |
kaizen | 0:f2039204c8f6 | 66 | else if(opt == 1) |
kaizen | 0:f2039204c8f6 | 67 | { |
kaizen | 0:f2039204c8f6 | 68 | putUart('\r'); |
kaizen | 0:f2039204c8f6 | 69 | } |
kaizen | 0:f2039204c8f6 | 70 | else |
kaizen | 0:f2039204c8f6 | 71 | { |
kaizen | 0:f2039204c8f6 | 72 | putUart('\r'); |
kaizen | 0:f2039204c8f6 | 73 | putUart('\n'); |
kaizen | 0:f2039204c8f6 | 74 | } |
kaizen | 0:f2039204c8f6 | 75 | unlockUart(); |
kaizen | 0:f2039204c8f6 | 76 | |
kaizen | 0:f2039204c8f6 | 77 | while(1) |
kaizen | 0:f2039204c8f6 | 78 | { |
kaizen | 0:f2039204c8f6 | 79 | if(t.read_ms() > timeout) |
kaizen | 0:f2039204c8f6 | 80 | { |
kaizen | 0:f2039204c8f6 | 81 | while(_wizfi.readable()) |
kaizen | 0:f2039204c8f6 | 82 | _wizfi.getc(); |
kaizen | 0:f2039204c8f6 | 83 | |
kaizen | 0:f2039204c8f6 | 84 | DBG("check: %s\r\n", checking.c_str()); |
kaizen | 0:f2039204c8f6 | 85 | return -1; |
kaizen | 0:f2039204c8f6 | 86 | } |
kaizen | 0:f2039204c8f6 | 87 | else if(_wizfi.readable()) |
kaizen | 0:f2039204c8f6 | 88 | { |
kaizen | 0:f2039204c8f6 | 89 | read = _wizfi.getc(); |
kaizen | 0:f2039204c8f6 | 90 | if(read != '\r' && read != '\n') |
kaizen | 0:f2039204c8f6 | 91 | { |
kaizen | 0:f2039204c8f6 | 92 | checking += read; |
kaizen | 0:f2039204c8f6 | 93 | found = checking.find(ACK); |
kaizen | 0:f2039204c8f6 | 94 | if (found != string::npos) |
kaizen | 0:f2039204c8f6 | 95 | { |
kaizen | 0:f2039204c8f6 | 96 | wait(0.01); |
kaizen | 0:f2039204c8f6 | 97 | |
kaizen | 0:f2039204c8f6 | 98 | while(_wizfi.readable()) |
kaizen | 0:f2039204c8f6 | 99 | _wizfi.getc(); |
kaizen | 0:f2039204c8f6 | 100 | |
kaizen | 0:f2039204c8f6 | 101 | break; |
kaizen | 0:f2039204c8f6 | 102 | } |
kaizen | 0:f2039204c8f6 | 103 | } |
kaizen | 0:f2039204c8f6 | 104 | } |
kaizen | 0:f2039204c8f6 | 105 | } |
kaizen | 0:f2039204c8f6 | 106 | DBG("check:%s\r\n", checking.c_str()); |
kaizen | 0:f2039204c8f6 | 107 | |
kaizen | 0:f2039204c8f6 | 108 | // attach_rx(true); |
kaizen | 0:f2039204c8f6 | 109 | |
kaizen | 0:f2039204c8f6 | 110 | return 0; |
kaizen | 0:f2039204c8f6 | 111 | } |
kaizen | 0:f2039204c8f6 | 112 | |
kaizen | 0:f2039204c8f6 | 113 | |
kaizen | 0:f2039204c8f6 | 114 | |
kaizen | 0:f2039204c8f6 | 115 | int WizFi250::sendCommand(const char * cmd, Response res, int timeout, int opt) |
kaizen | 0:f2039204c8f6 | 116 | { |
kaizen | 0:f2039204c8f6 | 117 | int i, cnt=0; |
kaizen | 0:f2039204c8f6 | 118 | Timer t; |
kaizen | 0:f2039204c8f6 | 119 | |
kaizen | 0:f2039204c8f6 | 120 | if (lockUart(timeout)) return -1; |
kaizen | 0:f2039204c8f6 | 121 | |
kaizen | 0:f2039204c8f6 | 122 | clearFlags(); |
kaizen | 0:f2039204c8f6 | 123 | _state.res = res; |
kaizen | 0:f2039204c8f6 | 124 | |
DongEun Koak | 5:8a0702aa91e3 | 125 | WIZ_INFO("%s", cmd) |
kaizen | 0:f2039204c8f6 | 126 | for (i=0; i< strlen(cmd); i++) |
kaizen | 0:f2039204c8f6 | 127 | { |
kaizen | 0:f2039204c8f6 | 128 | putUart(cmd[i]); |
kaizen | 0:f2039204c8f6 | 129 | } |
kaizen | 0:f2039204c8f6 | 130 | |
kaizen | 0:f2039204c8f6 | 131 | if(opt == 0) |
kaizen | 0:f2039204c8f6 | 132 | { |
kaizen | 0:f2039204c8f6 | 133 | |
kaizen | 0:f2039204c8f6 | 134 | } |
kaizen | 0:f2039204c8f6 | 135 | else if(opt == 1) |
kaizen | 0:f2039204c8f6 | 136 | { |
kaizen | 0:f2039204c8f6 | 137 | putUart('\r'); |
kaizen | 0:f2039204c8f6 | 138 | } |
kaizen | 0:f2039204c8f6 | 139 | else |
kaizen | 0:f2039204c8f6 | 140 | { |
kaizen | 0:f2039204c8f6 | 141 | putUart('\r'); |
kaizen | 0:f2039204c8f6 | 142 | putUart('\n'); |
kaizen | 0:f2039204c8f6 | 143 | } |
kaizen | 0:f2039204c8f6 | 144 | unlockUart(); |
kaizen | 0:f2039204c8f6 | 145 | |
kaizen | 0:f2039204c8f6 | 146 | if(timeout) |
kaizen | 0:f2039204c8f6 | 147 | { |
kaizen | 0:f2039204c8f6 | 148 | t.start(); |
kaizen | 0:f2039204c8f6 | 149 | for(;;) |
kaizen | 0:f2039204c8f6 | 150 | { |
kaizen | 0:f2039204c8f6 | 151 | if (_state.ok && _state.res == RES_NULL){ |
kaizen | 0:f2039204c8f6 | 152 | break; |
kaizen | 0:f2039204c8f6 | 153 | } |
kaizen | 0:f2039204c8f6 | 154 | if (_state.failure || t.read_ms() > timeout) |
kaizen | 0:f2039204c8f6 | 155 | { |
DongEun Koak | 5:8a0702aa91e3 | 156 | WIZ_WARN("failure of timeout[%d]ms\r\n",t.read_ms()); |
kaizen | 0:f2039204c8f6 | 157 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 158 | return -1; |
kaizen | 0:f2039204c8f6 | 159 | } |
kaizen | 0:f2039204c8f6 | 160 | } |
kaizen | 0:f2039204c8f6 | 161 | |
kaizen | 0:f2039204c8f6 | 162 | t.stop(); |
kaizen | 0:f2039204c8f6 | 163 | } |
kaizen | 0:f2039204c8f6 | 164 | |
DongEun Koak | 5:8a0702aa91e3 | 165 | WIZ_INFO("[OK]\r\n"); |
kaizen | 0:f2039204c8f6 | 166 | _state.res = RES_NULL; |
kaizen | 0:f2039204c8f6 | 167 | |
kaizen | 0:f2039204c8f6 | 168 | return 0; |
kaizen | 0:f2039204c8f6 | 169 | } |
kaizen | 0:f2039204c8f6 | 170 | |
kaizen | 0:f2039204c8f6 | 171 | int WizFi250::cmdAT() |
kaizen | 0:f2039204c8f6 | 172 | { |
kaizen | 0:f2039204c8f6 | 173 | int resp; |
kaizen | 0:f2039204c8f6 | 174 | |
kaizen | 0:f2039204c8f6 | 175 | resp = sendCommand("AT"); |
kaizen | 0:f2039204c8f6 | 176 | |
kaizen | 0:f2039204c8f6 | 177 | return resp; |
kaizen | 0:f2039204c8f6 | 178 | |
kaizen | 0:f2039204c8f6 | 179 | //return sendCommand("AT"); |
kaizen | 0:f2039204c8f6 | 180 | //sendCommand("AT","[OK]"); |
kaizen | 0:f2039204c8f6 | 181 | } |
kaizen | 0:f2039204c8f6 | 182 | |
kaizen | 0:f2039204c8f6 | 183 | int WizFi250::cmdMECHO(bool flg) |
kaizen | 0:f2039204c8f6 | 184 | { |
kaizen | 0:f2039204c8f6 | 185 | int status; |
kaizen | 0:f2039204c8f6 | 186 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 187 | |
kaizen | 0:f2039204c8f6 | 188 | sprintf(cmd,"AT+MECHO=%d",flg); |
kaizen | 0:f2039204c8f6 | 189 | status = sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 190 | |
kaizen | 0:f2039204c8f6 | 191 | return status; |
kaizen | 0:f2039204c8f6 | 192 | } |
kaizen | 0:f2039204c8f6 | 193 | |
kaizen | 0:f2039204c8f6 | 194 | int WizFi250::cmdUSET(int baud, char *flow) |
kaizen | 0:f2039204c8f6 | 195 | { |
kaizen | 0:f2039204c8f6 | 196 | int status; |
kaizen | 0:f2039204c8f6 | 197 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 198 | |
kaizen | 0:f2039204c8f6 | 199 | sprintf(cmd,"AT+USET=%d,N,8,1,%s",baud, flow); |
kaizen | 0:f2039204c8f6 | 200 | status = sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 201 | |
kaizen | 0:f2039204c8f6 | 202 | if(status == 0) |
kaizen | 0:f2039204c8f6 | 203 | { |
kaizen | 0:f2039204c8f6 | 204 | wait(1); |
kaizen | 0:f2039204c8f6 | 205 | _state.buf->flush(); |
kaizen | 0:f2039204c8f6 | 206 | } |
kaizen | 0:f2039204c8f6 | 207 | |
kaizen | 0:f2039204c8f6 | 208 | return status; |
kaizen | 0:f2039204c8f6 | 209 | } |
kaizen | 0:f2039204c8f6 | 210 | |
kaizen | 0:f2039204c8f6 | 211 | int WizFi250::cmdMMAC(const char *mac) |
kaizen | 0:f2039204c8f6 | 212 | { |
kaizen | 0:f2039204c8f6 | 213 | int resp; |
kaizen | 0:f2039204c8f6 | 214 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 215 | const char xmac[] = "00:08:DC:00:00:00"; |
kaizen | 0:f2039204c8f6 | 216 | |
kaizen | 0:f2039204c8f6 | 217 | if (mac) |
kaizen | 0:f2039204c8f6 | 218 | { |
kaizen | 0:f2039204c8f6 | 219 | sprintf(cmd, "AT+MMAC=%s",mac); |
kaizen | 0:f2039204c8f6 | 220 | resp = sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 221 | } |
kaizen | 0:f2039204c8f6 | 222 | else |
kaizen | 0:f2039204c8f6 | 223 | { |
kaizen | 0:f2039204c8f6 | 224 | sprintf(cmd, "AT+MMAC=?"); |
kaizen | 0:f2039204c8f6 | 225 | resp = sendCommand(cmd, RES_MACADDRESS); |
kaizen | 0:f2039204c8f6 | 226 | if (!resp && strncmp(_state.mac, xmac, 17) == 0) |
kaizen | 0:f2039204c8f6 | 227 | { |
kaizen | 0:f2039204c8f6 | 228 | resp = -1; |
kaizen | 0:f2039204c8f6 | 229 | } |
kaizen | 0:f2039204c8f6 | 230 | } |
kaizen | 0:f2039204c8f6 | 231 | |
kaizen | 0:f2039204c8f6 | 232 | return resp; |
kaizen | 0:f2039204c8f6 | 233 | } |
kaizen | 0:f2039204c8f6 | 234 | |
kaizen | 0:f2039204c8f6 | 235 | int WizFi250::cmdWSET(WiFiMode mode, const char *ssid, const char *bssid, int channel) |
kaizen | 0:f2039204c8f6 | 236 | { |
kaizen | 0:f2039204c8f6 | 237 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 238 | |
kaizen | 0:f2039204c8f6 | 239 | if(*bssid == NULL) |
kaizen | 0:f2039204c8f6 | 240 | { |
kaizen | 0:f2039204c8f6 | 241 | sprintf(cmd, "AT+WSET=%d,%s",mode, ssid); |
kaizen | 0:f2039204c8f6 | 242 | } |
kaizen | 0:f2039204c8f6 | 243 | else |
kaizen | 0:f2039204c8f6 | 244 | { |
kaizen | 0:f2039204c8f6 | 245 | sprintf(cmd, "AT+WSET=%d,%s,%s,%d",mode, ssid, bssid, channel); |
kaizen | 0:f2039204c8f6 | 246 | } |
kaizen | 0:f2039204c8f6 | 247 | |
kaizen | 0:f2039204c8f6 | 248 | return sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 249 | } |
kaizen | 0:f2039204c8f6 | 250 | |
kaizen | 0:f2039204c8f6 | 251 | int WizFi250::cmdWSEC(WiFiMode mode, const char *key, const char *sec) |
kaizen | 0:f2039204c8f6 | 252 | { |
kaizen | 0:f2039204c8f6 | 253 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 254 | |
kaizen | 0:f2039204c8f6 | 255 | if(*sec == NULL) |
kaizen | 0:f2039204c8f6 | 256 | { |
kaizen | 0:f2039204c8f6 | 257 | sprintf(cmd, "AT+WSEC=%d,,%s",mode, key); |
kaizen | 0:f2039204c8f6 | 258 | } |
kaizen | 0:f2039204c8f6 | 259 | else |
kaizen | 0:f2039204c8f6 | 260 | { |
kaizen | 0:f2039204c8f6 | 261 | sprintf(cmd, "AT+WSEC=%d,%s,%s",mode, sec, key); |
kaizen | 0:f2039204c8f6 | 262 | } |
kaizen | 0:f2039204c8f6 | 263 | |
kaizen | 0:f2039204c8f6 | 264 | return sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 265 | } |
kaizen | 0:f2039204c8f6 | 266 | |
kaizen | 0:f2039204c8f6 | 267 | int WizFi250::cmdWJOIN() |
kaizen | 0:f2039204c8f6 | 268 | { |
kaizen | 0:f2039204c8f6 | 269 | sendCommand("AT+WJOIN", RES_WJOIN, CFG_TIMEOUT); |
kaizen | 0:f2039204c8f6 | 270 | |
DongEun Koak | 5:8a0702aa91e3 | 271 | if( sendCommand("AT+WJOIN", RES_WJOIN, CFG_JOIN_TIMEOUT) ) return -1; |
DongEun Koak | 5:8a0702aa91e3 | 272 | |
DongEun Koak | 5:8a0702aa91e3 | 273 | WIZ_INFO("IP : %s",_state.ip); |
DongEun Koak | 5:8a0702aa91e3 | 274 | WIZ_INFO("Gateway : %s",_state.gateway); |
DongEun Koak | 5:8a0702aa91e3 | 275 | WIZ_INFO("WizFi250 is successfully join to AP"); |
kaizen | 0:f2039204c8f6 | 276 | |
kaizen | 0:f2039204c8f6 | 277 | return 0; |
kaizen | 0:f2039204c8f6 | 278 | } |
kaizen | 0:f2039204c8f6 | 279 | |
kaizen | 0:f2039204c8f6 | 280 | |
kaizen | 0:f2039204c8f6 | 281 | int WizFi250::cmdSCON ( const char *openType, const char *socketType, int localPort, const char *dataMode) |
kaizen | 0:f2039204c8f6 | 282 | { |
kaizen | 0:f2039204c8f6 | 283 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 284 | |
kaizen | 0:f2039204c8f6 | 285 | sprintf(cmd,"AT+SCON=%s,%s,,,%d,%s",openType, socketType, localPort, dataMode); |
kaizen | 0:f2039204c8f6 | 286 | return sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 287 | } |
kaizen | 0:f2039204c8f6 | 288 | |
kaizen | 0:f2039204c8f6 | 289 | int WizFi250::cmdSCON ( const char *openType, const char *socketType, const char *remoteIp, int remotePort, int localPort, const char *dataMode) |
kaizen | 0:f2039204c8f6 | 290 | { |
kaizen | 0:f2039204c8f6 | 291 | int resp; |
kaizen | 0:f2039204c8f6 | 292 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 293 | |
kaizen | 0:f2039204c8f6 | 294 | if(localPort == NULL) |
kaizen | 0:f2039204c8f6 | 295 | sprintf(cmd,"AT+SCON=%s,%s,%s,%d,%s,%s",openType, socketType, remoteIp, remotePort, "", dataMode); |
kaizen | 0:f2039204c8f6 | 296 | else |
kaizen | 0:f2039204c8f6 | 297 | sprintf(cmd,"AT+SCON=%s,%s,%s,%d,%d,%s",openType, socketType, remoteIp, remotePort, localPort, dataMode); |
kaizen | 0:f2039204c8f6 | 298 | |
kaizen | 0:f2039204c8f6 | 299 | resp = sendCommand(cmd, RES_CONNECT, 5000 ); |
DongEun Koak | 5:8a0702aa91e3 | 300 | WIZ_DBG("Create CID : %s",_state.dummyBuf); |
kaizen | 0:f2039204c8f6 | 301 | |
kaizen | 0:f2039204c8f6 | 302 | return resp; |
kaizen | 0:f2039204c8f6 | 303 | } |
kaizen | 0:f2039204c8f6 | 304 | |
kaizen | 0:f2039204c8f6 | 305 | int WizFi250::cmdSSEND ( const char *data, int cid, int sendSize, const char *remoteIp, int remotePort, int Timeout ) |
kaizen | 0:f2039204c8f6 | 306 | { |
kaizen | 0:f2039204c8f6 | 307 | int i, resp; |
kaizen | 0:f2039204c8f6 | 308 | Timer t; |
kaizen | 0:f2039204c8f6 | 309 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 310 | |
kaizen | 0:f2039204c8f6 | 311 | |
kaizen | 0:f2039204c8f6 | 312 | if (lockUart(Timeout)) return -1; |
kaizen | 0:f2039204c8f6 | 313 | |
kaizen | 0:f2039204c8f6 | 314 | clearFlags(); |
kaizen | 0:f2039204c8f6 | 315 | if(remotePort == NULL) |
kaizen | 0:f2039204c8f6 | 316 | { |
kaizen | 0:f2039204c8f6 | 317 | sprintf(cmd,"AT+SSEND=%d,%s,,%d",cid, remoteIp, sendSize); |
kaizen | 0:f2039204c8f6 | 318 | } |
kaizen | 0:f2039204c8f6 | 319 | else |
kaizen | 0:f2039204c8f6 | 320 | { |
kaizen | 0:f2039204c8f6 | 321 | sprintf(cmd,"AT+SSEND=%d,%s,%d,%d",cid, remoteIp, remotePort, sendSize); |
kaizen | 0:f2039204c8f6 | 322 | } |
kaizen | 0:f2039204c8f6 | 323 | |
kaizen | 0:f2039204c8f6 | 324 | _con[cid].send_length = sendSize; |
kaizen | 0:f2039204c8f6 | 325 | |
kaizen | 0:f2039204c8f6 | 326 | resp = sendCommand(cmd, RES_SSEND, 2000, 1); |
kaizen | 0:f2039204c8f6 | 327 | unlockUart(); |
kaizen | 0:f2039204c8f6 | 328 | if(resp){ |
DongEun Koak | 5:8a0702aa91e3 | 329 | WIZ_DBG("Fail cmdSSEND") |
kaizen | 0:f2039204c8f6 | 330 | return -1; |
kaizen | 0:f2039204c8f6 | 331 | } |
kaizen | 0:f2039204c8f6 | 332 | |
kaizen | 0:f2039204c8f6 | 333 | for(i=0; i<sendSize; i++) |
kaizen | 0:f2039204c8f6 | 334 | { |
kaizen | 0:f2039204c8f6 | 335 | putUart(data[i]); |
kaizen | 0:f2039204c8f6 | 336 | } |
kaizen | 0:f2039204c8f6 | 337 | unlockUart(); |
kaizen | 0:f2039204c8f6 | 338 | |
kaizen | 0:f2039204c8f6 | 339 | if(Timeout) |
kaizen | 0:f2039204c8f6 | 340 | { |
kaizen | 0:f2039204c8f6 | 341 | t.start(); |
kaizen | 0:f2039204c8f6 | 342 | for(;;) |
kaizen | 0:f2039204c8f6 | 343 | { |
kaizen | 0:f2039204c8f6 | 344 | if (_state.ok) break; |
kaizen | 0:f2039204c8f6 | 345 | if (_state.failure || t.read_ms() > Timeout) |
kaizen | 0:f2039204c8f6 | 346 | { |
DongEun Koak | 5:8a0702aa91e3 | 347 | WIZ_WARN("failure or timeout\r\n"); |
kaizen | 0:f2039204c8f6 | 348 | return -1; |
kaizen | 0:f2039204c8f6 | 349 | } |
kaizen | 0:f2039204c8f6 | 350 | } |
kaizen | 0:f2039204c8f6 | 351 | t.stop(); |
kaizen | 0:f2039204c8f6 | 352 | } |
kaizen | 0:f2039204c8f6 | 353 | |
DongEun Koak | 5:8a0702aa91e3 | 354 | //WIZ_INFO("data: '%s' size : %d\r\n",data, sendSize); |
kaizen | 0:f2039204c8f6 | 355 | |
kaizen | 0:f2039204c8f6 | 356 | return i; |
kaizen | 0:f2039204c8f6 | 357 | } |
kaizen | 0:f2039204c8f6 | 358 | |
kaizen | 0:f2039204c8f6 | 359 | |
kaizen | 0:f2039204c8f6 | 360 | int WizFi250::cmdCLOSE ( int cid ) |
kaizen | 0:f2039204c8f6 | 361 | { |
kaizen | 0:f2039204c8f6 | 362 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 363 | |
kaizen | 0:f2039204c8f6 | 364 | sprintf(cmd,"AT+SMGMT=%d",cid); |
kaizen | 0:f2039204c8f6 | 365 | return sendCommand(cmd); |
kaizen | 0:f2039204c8f6 | 366 | } |
kaizen | 0:f2039204c8f6 | 367 | |
kaizen | 0:f2039204c8f6 | 368 | |
kaizen | 0:f2039204c8f6 | 369 | int WizFi250::cmdFDNS (const char *host) |
kaizen | 0:f2039204c8f6 | 370 | { |
kaizen | 0:f2039204c8f6 | 371 | char cmd[CFG_CMD_SIZE]; |
kaizen | 0:f2039204c8f6 | 372 | int resp; |
kaizen | 0:f2039204c8f6 | 373 | |
kaizen | 0:f2039204c8f6 | 374 | sprintf(cmd,"AT+FDNS=%s,1000",host); |
kaizen | 0:f2039204c8f6 | 375 | resp = sendCommand(cmd, RES_FDNS, CFG_TIMEOUT); |
kaizen | 0:f2039204c8f6 | 376 | |
DongEun Koak | 5:8a0702aa91e3 | 377 | WIZ_DBG("%s",_state.resolv); |
kaizen | 0:f2039204c8f6 | 378 | return resp; |
kaizen | 0:f2039204c8f6 | 379 | } |
kaizen | 0:f2039204c8f6 | 380 | |
kaizen | 0:f2039204c8f6 | 381 | int WizFi250::cmdSMGMT ( int cid ) |
kaizen | 0:f2039204c8f6 | 382 | { |
kaizen | 0:f2039204c8f6 | 383 | int resp; |
kaizen | 0:f2039204c8f6 | 384 | |
kaizen | 0:f2039204c8f6 | 385 | resp = sendCommand("AT+SMGMT=?", RES_SMGMT); |
kaizen | 0:f2039204c8f6 | 386 | return resp; |
kaizen | 0:f2039204c8f6 | 387 | } |