private fork
Fork of GSwifiInterface by
GSwifi/GSwifi_at.cpp@12:057089026a20, 2013-11-22 (annotated)
- Committer:
- gsfan
- Date:
- Fri Nov 22 14:03:07 2013 +0000
- Revision:
- 12:057089026a20
- Parent:
- 11:71d67fea5ace
- Child:
- 13:189e04ac70bd
add more function (smtp, http, httpd, websocket); fix some function;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 8:64184a968e3b | 1 | /* Copyright (C) 2013 gsfan, MIT License |
gsfan | 8:64184a968e3b | 2 | * |
gsfan | 8:64184a968e3b | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
gsfan | 8:64184a968e3b | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
gsfan | 8:64184a968e3b | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
gsfan | 8:64184a968e3b | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
gsfan | 8:64184a968e3b | 7 | * furnished to do so, subject to the following conditions: |
gsfan | 8:64184a968e3b | 8 | * |
gsfan | 8:64184a968e3b | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
gsfan | 8:64184a968e3b | 10 | * substantial portions of the Software. |
gsfan | 8:64184a968e3b | 11 | * |
gsfan | 8:64184a968e3b | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
gsfan | 8:64184a968e3b | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
gsfan | 8:64184a968e3b | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
gsfan | 8:64184a968e3b | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gsfan | 8:64184a968e3b | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
gsfan | 8:64184a968e3b | 17 | */ |
gsfan | 8:64184a968e3b | 18 | |
gsfan | 8:64184a968e3b | 19 | #include "GSwifi.h" |
gsfan | 8:64184a968e3b | 20 | |
gsfan | 8:64184a968e3b | 21 | void GSwifi::clearFlags () { |
gsfan | 8:64184a968e3b | 22 | _state.ok = false; |
gsfan | 8:64184a968e3b | 23 | _state.failure = false; |
gsfan | 8:64184a968e3b | 24 | _state.res = RES_NULL; |
gsfan | 10:7d8134e7df01 | 25 | _state.n = 0; |
gsfan | 8:64184a968e3b | 26 | } |
gsfan | 8:64184a968e3b | 27 | |
gsfan | 8:64184a968e3b | 28 | int GSwifi::sendCommand(const char * cmd, Response res, int timeout) { |
gsfan | 8:64184a968e3b | 29 | int i; |
gsfan | 8:64184a968e3b | 30 | Timer t; |
gsfan | 8:64184a968e3b | 31 | |
gsfan | 8:64184a968e3b | 32 | if (lockUart(timeout)) return -1; |
gsfan | 8:64184a968e3b | 33 | |
gsfan | 8:64184a968e3b | 34 | clearFlags(); |
gsfan | 8:64184a968e3b | 35 | _state.res = res; |
gsfan | 8:64184a968e3b | 36 | for (i = 0; i < strlen(cmd); i ++) { |
gsfan | 8:64184a968e3b | 37 | putUart(cmd[i]); |
gsfan | 8:64184a968e3b | 38 | } |
gsfan | 8:64184a968e3b | 39 | putUart('\r'); |
gsfan | 8:64184a968e3b | 40 | putUart('\n'); |
gsfan | 8:64184a968e3b | 41 | unlockUart(); |
gsfan | 8:64184a968e3b | 42 | INFO("command: '%s'\r\n", cmd); |
gsfan | 8:64184a968e3b | 43 | |
gsfan | 8:64184a968e3b | 44 | if (timeout) { |
gsfan | 8:64184a968e3b | 45 | t.start(); |
gsfan | 8:64184a968e3b | 46 | for (;;) { |
gsfan | 10:7d8134e7df01 | 47 | if (_state.ok && _state.res == RES_NULL) break; |
gsfan | 8:64184a968e3b | 48 | if (_state.failure || t.read_ms() > timeout) { |
gsfan | 8:64184a968e3b | 49 | WARN("failure or timeout\r\n"); |
gsfan | 8:64184a968e3b | 50 | _state.res = RES_NULL; |
gsfan | 8:64184a968e3b | 51 | return -1; |
gsfan | 8:64184a968e3b | 52 | } |
gsfan | 8:64184a968e3b | 53 | } |
gsfan | 8:64184a968e3b | 54 | t.stop(); |
gsfan | 8:64184a968e3b | 55 | } |
gsfan | 8:64184a968e3b | 56 | INFO("ok\r\n"); |
gsfan | 8:64184a968e3b | 57 | _state.res = RES_NULL; |
gsfan | 8:64184a968e3b | 58 | |
gsfan | 8:64184a968e3b | 59 | return 0; |
gsfan | 8:64184a968e3b | 60 | } |
gsfan | 8:64184a968e3b | 61 | |
gsfan | 8:64184a968e3b | 62 | int GSwifi::sendData(const char * data, int len, int timeout, const char * cmd) { |
gsfan | 8:64184a968e3b | 63 | int i; |
gsfan | 8:64184a968e3b | 64 | Timer t; |
gsfan | 8:64184a968e3b | 65 | |
gsfan | 8:64184a968e3b | 66 | if (lockUart(timeout)) return -1; |
gsfan | 8:64184a968e3b | 67 | |
gsfan | 8:64184a968e3b | 68 | clearFlags(); |
gsfan | 8:64184a968e3b | 69 | for (i = 0; i < strlen(cmd); i ++) { |
gsfan | 8:64184a968e3b | 70 | putUart(cmd[i]); |
gsfan | 8:64184a968e3b | 71 | } |
gsfan | 8:64184a968e3b | 72 | for (i = 0; i < len; i ++) { |
gsfan | 8:64184a968e3b | 73 | putUart(data[i]); |
gsfan | 8:64184a968e3b | 74 | } |
gsfan | 8:64184a968e3b | 75 | unlockUart(); |
gsfan | 8:64184a968e3b | 76 | INFO("data: '%s' %d\r\n", cmd, len); |
gsfan | 8:64184a968e3b | 77 | |
gsfan | 8:64184a968e3b | 78 | if (timeout) { |
gsfan | 8:64184a968e3b | 79 | t.start(); |
gsfan | 8:64184a968e3b | 80 | for (;;) { |
gsfan | 8:64184a968e3b | 81 | if (_state.ok) break; |
gsfan | 8:64184a968e3b | 82 | if (_state.failure || t.read_ms() > timeout) { |
gsfan | 8:64184a968e3b | 83 | WARN("failure or timeout\r\n"); |
gsfan | 8:64184a968e3b | 84 | return -1; |
gsfan | 8:64184a968e3b | 85 | } |
gsfan | 8:64184a968e3b | 86 | } |
gsfan | 8:64184a968e3b | 87 | t.stop(); |
gsfan | 8:64184a968e3b | 88 | } |
gsfan | 8:64184a968e3b | 89 | |
gsfan | 8:64184a968e3b | 90 | return i; |
gsfan | 8:64184a968e3b | 91 | } |
gsfan | 8:64184a968e3b | 92 | |
gsfan | 8:64184a968e3b | 93 | |
gsfan | 8:64184a968e3b | 94 | int GSwifi::cmdAT () { |
gsfan | 8:64184a968e3b | 95 | return sendCommand("AT"); |
gsfan | 8:64184a968e3b | 96 | } |
gsfan | 8:64184a968e3b | 97 | |
gsfan | 8:64184a968e3b | 98 | int GSwifi::cmdE (bool n) { |
gsfan | 8:64184a968e3b | 99 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 100 | sprintf(cmd, "ATE%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 101 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 102 | } |
gsfan | 8:64184a968e3b | 103 | |
gsfan | 8:64184a968e3b | 104 | int GSwifi::cmdR (bool n) { |
gsfan | 8:64184a968e3b | 105 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 106 | sprintf(cmd, "AT&R%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 107 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 108 | } |
gsfan | 8:64184a968e3b | 109 | |
gsfan | 8:64184a968e3b | 110 | int GSwifi::cmdNMAC (const char *s) { |
gsfan | 8:64184a968e3b | 111 | int r; |
gsfan | 8:64184a968e3b | 112 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 113 | const char xmac[] = "00:1D:C9:01:99:99"; |
gsfan | 8:64184a968e3b | 114 | if (s) { |
gsfan | 8:64184a968e3b | 115 | sprintf(cmd, "AT+NMAC2=%s", s); |
gsfan | 8:64184a968e3b | 116 | r = sendCommand(cmd); |
gsfan | 8:64184a968e3b | 117 | } else { |
gsfan | 8:64184a968e3b | 118 | sprintf(cmd, "AT+NMAC=?"); |
gsfan | 8:64184a968e3b | 119 | r = sendCommand(cmd, RES_MACADDRESS); |
gsfan | 8:64184a968e3b | 120 | if (!r && strncmp(_state.mac, xmac, 17) == 0) { |
gsfan | 8:64184a968e3b | 121 | r = -1; |
gsfan | 8:64184a968e3b | 122 | } |
gsfan | 8:64184a968e3b | 123 | } |
gsfan | 8:64184a968e3b | 124 | return r; |
gsfan | 8:64184a968e3b | 125 | } |
gsfan | 8:64184a968e3b | 126 | |
gsfan | 8:64184a968e3b | 127 | int GSwifi::cmdWREGDOMAIN (int n) { |
gsfan | 8:64184a968e3b | 128 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 129 | sprintf(cmd, "AT+WREGDOMAIN=%d", n); |
gsfan | 8:64184a968e3b | 130 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 131 | } |
gsfan | 8:64184a968e3b | 132 | |
gsfan | 8:64184a968e3b | 133 | int GSwifi::cmdWS () { |
gsfan | 8:64184a968e3b | 134 | return sendCommand("AT+WS"); |
gsfan | 8:64184a968e3b | 135 | } |
gsfan | 8:64184a968e3b | 136 | |
gsfan | 8:64184a968e3b | 137 | int GSwifi::cmdWM (int n) { |
gsfan | 8:64184a968e3b | 138 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 139 | sprintf(cmd, "AT+WM=%d", n); |
gsfan | 8:64184a968e3b | 140 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 141 | } |
gsfan | 8:64184a968e3b | 142 | |
gsfan | 8:64184a968e3b | 143 | int GSwifi::cmdWA (const char *s) { |
gsfan | 8:64184a968e3b | 144 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 145 | sprintf(cmd, "AT+WA=%s", s); |
gsfan | 8:64184a968e3b | 146 | return sendCommand(cmd, RES_DHCP, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 147 | } |
gsfan | 8:64184a968e3b | 148 | |
gsfan | 8:64184a968e3b | 149 | int GSwifi::cmdWD () { |
gsfan | 8:64184a968e3b | 150 | return sendCommand("AT+WD"); |
gsfan | 8:64184a968e3b | 151 | } |
gsfan | 8:64184a968e3b | 152 | |
gsfan | 8:64184a968e3b | 153 | int GSwifi::cmdWWPS (bool n, const char *p) { |
gsfan | 8:64184a968e3b | 154 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 155 | if (p) { |
gsfan | 8:64184a968e3b | 156 | sprintf(cmd, "AT+WWPS=2,%s", p); |
gsfan | 8:64184a968e3b | 157 | } else { |
gsfan | 8:64184a968e3b | 158 | sprintf(cmd, "AT+WWPS=%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 159 | } |
gsfan | 8:64184a968e3b | 160 | return sendCommand(cmd, RES_WPS, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 161 | } |
gsfan | 8:64184a968e3b | 162 | |
gsfan | 8:64184a968e3b | 163 | int GSwifi::cmdNSTAT () { |
gsfan | 8:64184a968e3b | 164 | return sendCommand("AT+NSTAT=?"); |
gsfan | 8:64184a968e3b | 165 | } |
gsfan | 8:64184a968e3b | 166 | |
gsfan | 8:64184a968e3b | 167 | int GSwifi::cmdWSTATUS () { |
gsfan | 8:64184a968e3b | 168 | return sendCommand("AT+WSTATUS", RES_STATUS); |
gsfan | 8:64184a968e3b | 169 | } |
gsfan | 8:64184a968e3b | 170 | |
gsfan | 8:64184a968e3b | 171 | int GSwifi::cmdWRSSI () { |
gsfan | 8:64184a968e3b | 172 | return sendCommand("AT+WRSSI=?", RES_RSSI); |
gsfan | 8:64184a968e3b | 173 | } |
gsfan | 8:64184a968e3b | 174 | |
gsfan | 8:64184a968e3b | 175 | int GSwifi::cmdWAUTH (int n) { |
gsfan | 8:64184a968e3b | 176 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 177 | sprintf(cmd, "AT+WAUTH=%d", n); |
gsfan | 8:64184a968e3b | 178 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 179 | } |
gsfan | 8:64184a968e3b | 180 | |
gsfan | 8:64184a968e3b | 181 | int GSwifi::cmdWWEP (int n, const char *s) { |
gsfan | 8:64184a968e3b | 182 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 183 | sprintf(cmd, "AT+WWEP%d=%s", n, s); |
gsfan | 8:64184a968e3b | 184 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 185 | } |
gsfan | 8:64184a968e3b | 186 | |
gsfan | 8:64184a968e3b | 187 | int GSwifi::cmdWPAPSK (const char *s, const char *p) { |
gsfan | 8:64184a968e3b | 188 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 189 | sprintf(cmd, "AT+WPAPSK=%s,%s", s, p); |
gsfan | 8:64184a968e3b | 190 | return sendCommand(cmd, RES_NULL, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 191 | } |
gsfan | 8:64184a968e3b | 192 | |
gsfan | 8:64184a968e3b | 193 | int GSwifi::cmdWRXACTIVE (bool n) { |
gsfan | 8:64184a968e3b | 194 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 195 | sprintf(cmd, "AT+WRXACTIVE=%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 196 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 197 | } |
gsfan | 8:64184a968e3b | 198 | |
gsfan | 8:64184a968e3b | 199 | int GSwifi::cmdWRXPS (bool n) { |
gsfan | 8:64184a968e3b | 200 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 201 | sprintf(cmd, "AT+WRXPS=%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 202 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 203 | } |
gsfan | 8:64184a968e3b | 204 | |
gsfan | 8:64184a968e3b | 205 | int GSwifi::cmdWP (int n) { |
gsfan | 8:64184a968e3b | 206 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 207 | sprintf(cmd, "AT+WP=%d", n); |
gsfan | 8:64184a968e3b | 208 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 209 | } |
gsfan | 8:64184a968e3b | 210 | |
gsfan | 8:64184a968e3b | 211 | int GSwifi::cmdNDHCP (bool n, const char *s, int m) { |
gsfan | 8:64184a968e3b | 212 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 213 | if (n) { |
gsfan | 8:64184a968e3b | 214 | if (s) { |
gsfan | 8:64184a968e3b | 215 | sprintf(cmd, "AT+NDHCP=1,%s", s); |
gsfan | 8:64184a968e3b | 216 | } else { |
gsfan | 8:64184a968e3b | 217 | sprintf(cmd, "AT+NDHCP=1"); |
gsfan | 8:64184a968e3b | 218 | } |
gsfan | 8:64184a968e3b | 219 | return sendCommand(cmd, RES_DHCP, m); |
gsfan | 8:64184a968e3b | 220 | } else { |
gsfan | 8:64184a968e3b | 221 | return sendCommand("AT+NDHCP=0"); |
gsfan | 8:64184a968e3b | 222 | } |
gsfan | 8:64184a968e3b | 223 | } |
gsfan | 8:64184a968e3b | 224 | |
gsfan | 8:64184a968e3b | 225 | int GSwifi::cmdDHCPSRVR (bool n) { |
gsfan | 8:64184a968e3b | 226 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 227 | sprintf(cmd, "AT+DHCPSRVR=%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 228 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 229 | } |
gsfan | 8:64184a968e3b | 230 | |
gsfan | 8:64184a968e3b | 231 | int GSwifi::cmdNSET (const char *s, const char *t, const char *u) { |
gsfan | 8:64184a968e3b | 232 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 233 | sprintf(cmd, "AT+NSET=%s,%s,%s", s, t, u); |
gsfan | 8:64184a968e3b | 234 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 235 | } |
gsfan | 8:64184a968e3b | 236 | |
gsfan | 8:64184a968e3b | 237 | int GSwifi::cmdDNS (bool n, const char *s) { |
gsfan | 8:64184a968e3b | 238 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 239 | if (n) { |
gsfan | 8:64184a968e3b | 240 | if (s) { |
gsfan | 8:64184a968e3b | 241 | sprintf(cmd, "AT+DNS=1,%s", s); |
gsfan | 8:64184a968e3b | 242 | } else { |
gsfan | 8:64184a968e3b | 243 | sprintf(cmd, "AT+DNS=1," CFG_DNSNAME); |
gsfan | 8:64184a968e3b | 244 | } |
gsfan | 8:64184a968e3b | 245 | } else { |
gsfan | 8:64184a968e3b | 246 | sprintf(cmd, "AT+DNS=0"); |
gsfan | 8:64184a968e3b | 247 | } |
gsfan | 8:64184a968e3b | 248 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 249 | } |
gsfan | 8:64184a968e3b | 250 | |
gsfan | 8:64184a968e3b | 251 | int GSwifi::cmdDNSLOOKUP (const char *s) { |
gsfan | 8:64184a968e3b | 252 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 253 | sprintf(cmd, "AT+DNSLOOKUP=%s", s); |
gsfan | 8:64184a968e3b | 254 | return sendCommand(cmd, RES_DNSLOOKUP, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 255 | } |
gsfan | 8:64184a968e3b | 256 | |
gsfan | 8:64184a968e3b | 257 | int GSwifi::cmdDNSSET (const char *s) { |
gsfan | 8:64184a968e3b | 258 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 259 | sprintf(cmd, "AT+DNSSET=%s", s); |
gsfan | 8:64184a968e3b | 260 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 261 | } |
gsfan | 8:64184a968e3b | 262 | |
gsfan | 8:64184a968e3b | 263 | int GSwifi::cmdSTORENWCONN () { |
gsfan | 8:64184a968e3b | 264 | return sendCommand("AT+STORENWCONN"); |
gsfan | 8:64184a968e3b | 265 | } |
gsfan | 8:64184a968e3b | 266 | |
gsfan | 8:64184a968e3b | 267 | int GSwifi::cmdRESTORENWCONN () { |
gsfan | 8:64184a968e3b | 268 | return sendCommand("AT+RESTORENWCONN"); |
gsfan | 8:64184a968e3b | 269 | } |
gsfan | 8:64184a968e3b | 270 | |
gsfan | 8:64184a968e3b | 271 | int GSwifi::cmdBDATA (bool n) { |
gsfan | 8:64184a968e3b | 272 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 273 | sprintf(cmd, "AT+BDATA=%d", n ? 1 : 0); |
gsfan | 8:64184a968e3b | 274 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 275 | } |
gsfan | 8:64184a968e3b | 276 | |
gsfan | 8:64184a968e3b | 277 | int GSwifi::cmdNCTCP (const char *s, int n) { |
gsfan | 8:64184a968e3b | 278 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 279 | sprintf(cmd, "AT+NCTCP=%s,%d", s, n); |
gsfan | 8:64184a968e3b | 280 | return sendCommand(cmd, RES_CONNECT, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 281 | } |
gsfan | 8:64184a968e3b | 282 | |
gsfan | 8:64184a968e3b | 283 | int GSwifi::cmdNCUDP (const char *s, int n, int m) { |
gsfan | 8:64184a968e3b | 284 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 285 | if (m) { |
gsfan | 8:64184a968e3b | 286 | sprintf(cmd, "AT+NCUDP=%s,%d,%d", s, n, m); |
gsfan | 8:64184a968e3b | 287 | } else { |
gsfan | 8:64184a968e3b | 288 | sprintf(cmd, "AT+NCUDP=%s,%d", s, n); |
gsfan | 8:64184a968e3b | 289 | } |
gsfan | 8:64184a968e3b | 290 | return sendCommand(cmd, RES_CONNECT, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 291 | } |
gsfan | 8:64184a968e3b | 292 | |
gsfan | 8:64184a968e3b | 293 | int GSwifi::cmdNSTCP (int n) { |
gsfan | 8:64184a968e3b | 294 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 295 | sprintf(cmd, "AT+NSTCP=%d", n); |
gsfan | 8:64184a968e3b | 296 | return sendCommand(cmd, RES_CONNECT); |
gsfan | 8:64184a968e3b | 297 | } |
gsfan | 8:64184a968e3b | 298 | |
gsfan | 8:64184a968e3b | 299 | int GSwifi::cmdNSUDP (int n) { |
gsfan | 8:64184a968e3b | 300 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 301 | sprintf(cmd, "AT+NSUDP=%d", n); |
gsfan | 8:64184a968e3b | 302 | return sendCommand(cmd, RES_CONNECT); |
gsfan | 8:64184a968e3b | 303 | } |
gsfan | 8:64184a968e3b | 304 | |
gsfan | 8:64184a968e3b | 305 | int GSwifi::cmdNCLOSE (int n) { |
gsfan | 8:64184a968e3b | 306 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 307 | sprintf(cmd, "AT+NCLOSE=%d", n); |
gsfan | 8:64184a968e3b | 308 | return sendCommand(cmd, RES_NULL, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 309 | } |
gsfan | 8:64184a968e3b | 310 | |
gsfan | 8:64184a968e3b | 311 | int GSwifi::cmdNCLOSEALL () { |
gsfan | 8:64184a968e3b | 312 | return sendCommand("AT+NCLOSEALL", RES_NULL, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 313 | } |
gsfan | 8:64184a968e3b | 314 | |
gsfan | 8:64184a968e3b | 315 | int GSwifi::cmdHTTPCONF (int n, const char *s) { |
gsfan | 8:64184a968e3b | 316 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 317 | sprintf(cmd, "AT+HTTPCONF=%d,%s", n, s); |
gsfan | 8:64184a968e3b | 318 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 319 | } |
gsfan | 8:64184a968e3b | 320 | |
gsfan | 8:64184a968e3b | 321 | int GSwifi::cmdHTTPCONFDEL (int n) { |
gsfan | 8:64184a968e3b | 322 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 323 | sprintf(cmd, "AT+HTTPCONFDEL=%d", n); |
gsfan | 8:64184a968e3b | 324 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 325 | } |
gsfan | 8:64184a968e3b | 326 | |
gsfan | 8:64184a968e3b | 327 | int GSwifi::cmdHTTPOPEN (const char *s, int n, bool m) { |
gsfan | 8:64184a968e3b | 328 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 329 | if (m) { |
gsfan | 8:64184a968e3b | 330 | sprintf(cmd, "AT+HTTPOPEN=%s,%d,1", s, n); |
gsfan | 8:64184a968e3b | 331 | } else { |
gsfan | 8:64184a968e3b | 332 | sprintf(cmd, "AT+HTTPOPEN=%s,%d", s, n); |
gsfan | 8:64184a968e3b | 333 | } |
gsfan | 12:057089026a20 | 334 | return sendCommand(cmd, RES_HTTP, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 335 | } |
gsfan | 8:64184a968e3b | 336 | |
gsfan | 8:64184a968e3b | 337 | int GSwifi::cmdHTTPSEND (int n, bool m, const char *s, int t) { |
gsfan | 8:64184a968e3b | 338 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 339 | if (m) { |
gsfan | 8:64184a968e3b | 340 | sprintf(cmd, "AT+HTTPSEND=%d,3,%d,%s,%d", n, CFG_TIMEOUT / 1000, s, t); |
gsfan | 8:64184a968e3b | 341 | } else { |
gsfan | 8:64184a968e3b | 342 | sprintf(cmd, "AT+HTTPSEND=%d,1,%d,%s", n, CFG_TIMEOUT / 1000, s); |
gsfan | 8:64184a968e3b | 343 | } |
gsfan | 12:057089026a20 | 344 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 345 | } |
gsfan | 8:64184a968e3b | 346 | |
gsfan | 8:64184a968e3b | 347 | int GSwifi::cmdHTTPCLOSE (int n) { |
gsfan | 8:64184a968e3b | 348 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 349 | sprintf(cmd, "AT+HTTPCLOSE=%d", n); |
gsfan | 8:64184a968e3b | 350 | return sendCommand(cmd, RES_NULL, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 351 | } |
gsfan | 8:64184a968e3b | 352 | |
gsfan | 8:64184a968e3b | 353 | int GSwifi::cmdPSDPSLEEP (int n) { |
gsfan | 8:64184a968e3b | 354 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 355 | if (n) { |
gsfan | 8:64184a968e3b | 356 | sprintf(cmd, "AT+PSDPSLEEP=%d", n); |
gsfan | 8:64184a968e3b | 357 | } else { |
gsfan | 8:64184a968e3b | 358 | sprintf(cmd, "AT+PSDPSLEEP"); |
gsfan | 8:64184a968e3b | 359 | } |
gsfan | 11:71d67fea5ace | 360 | return sendCommand(cmd, RES_NULL, 0); |
gsfan | 8:64184a968e3b | 361 | } |
gsfan | 8:64184a968e3b | 362 | |
gsfan | 8:64184a968e3b | 363 | int GSwifi::cmdPSSTBY (int n, int m) { |
gsfan | 8:64184a968e3b | 364 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 365 | sprintf(cmd, "AT+PSSTBY=%d,0,%d,%d", n, m, m); |
gsfan | 8:64184a968e3b | 366 | return sendCommand(cmd, RES_NULL, 0); |
gsfan | 8:64184a968e3b | 367 | } |
gsfan | 8:64184a968e3b | 368 | |
gsfan | 8:64184a968e3b | 369 | int GSwifi::cmdWEBPROV (const char *s, const char *p) { |
gsfan | 8:64184a968e3b | 370 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 371 | sprintf(cmd, "AT+WEBPROV=%s,%s", s, p); |
gsfan | 8:64184a968e3b | 372 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 373 | } |
gsfan | 8:64184a968e3b | 374 | |
gsfan | 8:64184a968e3b | 375 | int GSwifi::cmdSETTIME (const char *s, const char *t) { |
gsfan | 8:64184a968e3b | 376 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 377 | sprintf(cmd, "AT+SETTIME=%s,%s", s, t); |
gsfan | 8:64184a968e3b | 378 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 379 | } |
gsfan | 8:64184a968e3b | 380 | |
gsfan | 8:64184a968e3b | 381 | int GSwifi::cmdGETTIME () { |
gsfan | 8:64184a968e3b | 382 | return sendCommand("AT+GETTIME=?", RES_TIME); |
gsfan | 8:64184a968e3b | 383 | } |
gsfan | 8:64184a968e3b | 384 | |
gsfan | 8:64184a968e3b | 385 | int GSwifi::cmdNTIMESYNC (bool n, const char *s, int m) { |
gsfan | 8:64184a968e3b | 386 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 387 | if (n) { |
gsfan | 8:64184a968e3b | 388 | if (m) { |
gsfan | 8:64184a968e3b | 389 | sprintf(cmd, "AT+NTIMESYNC=1,%s,%d,1,%d", s, CFG_TIMEOUT / 1000, m); |
gsfan | 8:64184a968e3b | 390 | } else { |
gsfan | 8:64184a968e3b | 391 | sprintf(cmd, "AT+NTIMESYNC=1,%s,%d,0", s, CFG_TIMEOUT / 1000); |
gsfan | 8:64184a968e3b | 392 | } |
gsfan | 8:64184a968e3b | 393 | } else { |
gsfan | 8:64184a968e3b | 394 | sprintf(cmd, "AT+NTIMESYNC=0"); |
gsfan | 8:64184a968e3b | 395 | } |
gsfan | 8:64184a968e3b | 396 | return sendCommand(cmd, RES_NULL, CFG_TIMEOUT); |
gsfan | 8:64184a968e3b | 397 | } |
gsfan | 8:64184a968e3b | 398 | |
gsfan | 8:64184a968e3b | 399 | int GSwifi::cmdDGPIO (int n, int m) { |
gsfan | 8:64184a968e3b | 400 | char cmd[CFG_CMD_SIZE]; |
gsfan | 8:64184a968e3b | 401 | sprintf(cmd, "AT+DGPIO=%d,%d", n, m); |
gsfan | 8:64184a968e3b | 402 | return sendCommand(cmd); |
gsfan | 8:64184a968e3b | 403 | } |