private fork
Fork of GSwifiInterface by
Diff: GSwifi/GSwifi_util.cpp
- Revision:
- 8:64184a968e3b
- Child:
- 11:71d67fea5ace
diff -r 6a6396b56405 -r 64184a968e3b GSwifi/GSwifi_util.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GSwifi/GSwifi_util.cpp Thu Oct 31 06:41:45 2013 +0000 @@ -0,0 +1,100 @@ +/* Copyright (C) 2013 gsfan, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "GSwifi.h" + +int GSwifi::x2i (char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } else + if (c >= 'A' && c <= 'F') { + return c - 'A' + 10; + } else + if (c >= 'a' && c <= 'f') { + return c - 'a' + 10; + } + return 0; +} + +char GSwifi::i2x (int i) { + if (i >= 0 && i <= 9) { + return i + '0'; + } else + if (i >= 10 && i <= 15) { + return i - 10 + 'A'; + } + return 0; +} + +int GSwifi::from_hex (int ch) { + return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; +} + +int GSwifi::to_hex (int code) { + static char hex[] = "0123456789abcdef"; + return hex[code & 15]; +} + + +int GSwifi::setRegion (int reg) { + return cmdWREGDOMAIN(reg); +} + +int GSwifi::getRssi () { + cmdWRSSI(); + return _state.rssi; +} + +int GSwifi::powerSave (int active, int save) { + cmdWRXACTIVE(active); + return cmdWRXPS(save); +} + +int GSwifi::setRfPower (int power) { + if (power < 0 || power > 7) return false; + return cmdWP(power); +} + +int GSwifi::setTime (time_t time) { + char dmy[16], hms[16]; + struct tm *t = localtime(&time); + + sprintf(dmy, "%d/%d/%d", t->tm_mday, t->tm_mon + 1, t->tm_year + 1900); + sprintf(hms, "%d:%d:%d", t->tm_hour, t->tm_min, t->tm_sec); + return cmdSETTIME(dmy, hms); +} + +time_t GSwifi::getTime () { + cmdGETTIME(); + return _state.time; +} + +int GSwifi::ntpdate (char *host, int sec) { + char ip[17]; + + if (getHostByName(host, ip)) return -1; + return cmdNTIMESYNC(true, ip, sec); +} + +int GSwifi::setGpio (int port, int out) { + return cmdDGPIO(port, out); +} + +int GSwifi::provisioning (char *user, char *pass) { + return cmdWEBPROV(user, pass); +}