This commit is contained in:
Volodymyr Shymanskyy
2018-06-11 00:56:41 +03:00
10 changed files with 826 additions and 340 deletions

View File

@@ -39,15 +39,28 @@ enum RegStatus {
REG_UNKNOWN = 4,
};
enum DateTime {
enum TinyGSMDateTimeFormat {
DATE_FULL = 0,
DATE_TIME = 1,
DATE_DATE = 2
};
//============================================================================//
//============================================================================//
// Declaration of the TinyGsmSim800 Class
//============================================================================//
//============================================================================//
class TinyGsmSim800
{
//============================================================================//
//============================================================================//
// The Sim800 Internal Client Class
//============================================================================//
//============================================================================//
public:
class GsmClient : public Client
@@ -184,14 +197,21 @@ public:
private:
TinyGsmSim800* at;
uint8_t mux;
uint16_t sock_available;
uint32_t prev_check;
bool sock_connected;
bool got_data;
RxFifo rx;
uint8_t mux;
uint16_t sock_available;
uint32_t prev_check;
bool sock_connected;
bool got_data;
RxFifo rx;
};
//============================================================================//
//============================================================================//
// The SIM800 Secure Client
//============================================================================//
//============================================================================//
class GsmClientSecure : public GsmClient
{
public:
@@ -211,9 +231,19 @@ public:
}
};
//============================================================================//
//============================================================================//
// The SIM800 Modem Functions
//============================================================================//
//============================================================================//
public:
#ifdef GSM_DEFAULT_STREAM
TinyGsmSim800(Stream& stream = GSM_DEFAULT_STREAM)
#else
TinyGsmSim800(Stream& stream)
#endif
: stream(stream)
{
memset(sockets, 0, sizeof(sockets));
@@ -402,10 +432,10 @@ public:
int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"));
waitResponse();
switch (status) {
case 2:
case 3: return SIM_LOCKED;
case 1: return SIM_READY;
default: return SIM_ERROR;
case 2:
case 3: return SIM_LOCKED;
case 1: return SIM_READY;
default: return SIM_ERROR;
}
}
return SIM_ERROR;
@@ -462,6 +492,10 @@ public:
return false;
}
/*
* WiFi functions
*/
/*
* GPRS functions
*/
@@ -740,12 +774,12 @@ public:
/*
* Time functions
*/
String getGSMDateTime(DateTime format) {
String getGSMDateTime(TinyGSMDateTimeFormat format) {
sendAT(GF("+CCLK?"));
if (waitResponse(2000L, GF(GSM_NL "+CCLK: \"")) != 1) {
return "";
}
String res;
switch(format) {
@@ -898,9 +932,13 @@ public:
streamWrite(tail...);
}
bool streamSkipUntil(char c) { //TODO: timeout
while (true) {
while (!stream.available()) { TINY_GSM_YIELD(); }
bool streamSkipUntil(char c) {
const unsigned long timeout = 1000L;
unsigned long startMillis = millis();
while (millis() - startMillis < timeout) {
while (millis() - startMillis < timeout && !stream.available()) {
TINY_GSM_YIELD();
}
if (stream.read() == c)
return true;
}
@@ -981,6 +1019,7 @@ finish:
}
data = "";
}
//DBG('<', index, '>');
return index;
}