Cleanup, again
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#ifndef TinyGsmClientG350_h
|
#ifndef TinyGsmClientG350_h
|
||||||
#define TinyGsmClientG350_h
|
#define TinyGsmClientG350_h
|
||||||
|
|
||||||
//#define TINY_GSM_DEBUG Serial
|
// #define TINY_GSM_DEBUG Serial
|
||||||
|
|
||||||
#if !defined(TINY_GSM_RX_BUFFER)
|
#if !defined(TINY_GSM_RX_BUFFER)
|
||||||
#define TINY_GSM_RX_BUFFER 64
|
#define TINY_GSM_RX_BUFFER 64
|
||||||
@@ -38,10 +38,22 @@ enum RegStatus {
|
|||||||
REG_UNKNOWN = 4,
|
REG_UNKNOWN = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// Declaration of the TinyGsmG350 Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
class TinyGsmG350
|
class TinyGsmG350
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The G350 Client Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class GsmClient : public Client
|
class GsmClient : public Client
|
||||||
@@ -160,14 +172,21 @@ public:
|
|||||||
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TinyGsmG350* at;
|
TinyGsmG350* at;
|
||||||
uint8_t mux;
|
uint8_t mux;
|
||||||
uint16_t sock_available;
|
uint16_t sock_available;
|
||||||
bool sock_connected;
|
bool sock_connected;
|
||||||
bool got_data;
|
bool got_data;
|
||||||
RxFifo rx;
|
RxFifo rx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The G350 Secure Client
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
class GsmClientSecure : public GsmClient
|
class GsmClientSecure : public GsmClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -187,6 +206,12 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The G350 Modem Functions
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#ifdef GSM_DEFAULT_STREAM
|
#ifdef GSM_DEFAULT_STREAM
|
||||||
@@ -321,26 +346,15 @@ public:
|
|||||||
int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"));
|
int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 2:
|
case 2:
|
||||||
case 3: return SIM_LOCKED;
|
case 3: return SIM_LOCKED;
|
||||||
case 1: return SIM_READY;
|
case 1: return SIM_READY;
|
||||||
default: return SIM_ERROR;
|
default: return SIM_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
|
||||||
sendAT(GF("+CGREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
String getOperator() {
|
||||||
sendAT(GF("+COPS?"));
|
sendAT(GF("+COPS?"));
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
||||||
@@ -356,6 +370,17 @@ public:
|
|||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
RegStatus getRegistrationStatus() {
|
||||||
|
sendAT(GF("+CGREG?"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
|
||||||
|
return REG_UNKNOWN;
|
||||||
|
}
|
||||||
|
streamSkipUntil(','); // Skip format (0)
|
||||||
|
int status = stream.readStringUntil('\n').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return (RegStatus)status;
|
||||||
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
int getSignalQuality() {
|
||||||
sendAT(GF("+CSQ"));
|
sendAT(GF("+CSQ"));
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
@@ -382,6 +407,24 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getLocalIP() {
|
||||||
|
sendAT(GF("+CIFSR;E0"));
|
||||||
|
String res;
|
||||||
|
if (waitResponse(10000L, res) != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
res.trim();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress localIP() {
|
||||||
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
@@ -446,32 +489,6 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLocalIP() {
|
|
||||||
sendAT(GF("+CIFSR;E0"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(10000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress localIP() {
|
|
||||||
return TinyGsmIpFromString(getLocalIP());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Phone Call functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
bool callAnswer() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
bool callNumber(const String& number) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
bool callHangup() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
@@ -625,9 +642,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -639,7 +660,7 @@ public:
|
|||||||
streamWrite("AT", cmd..., GSM_NL);
|
streamWrite("AT", cmd..., GSM_NL);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
//DBG("### AT:", cmd...);
|
DBG("### AT:", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
@@ -647,13 +668,12 @@ public:
|
|||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
String r1s(r1); r1s.trim();
|
String r1s(r1); r1s.trim();
|
||||||
String r2s(r2); r2s.trim();
|
String r2s(r2); r2s.trim();
|
||||||
String r3s(r3); r3s.trim();
|
String r3s(r3); r3s.trim();
|
||||||
String r4s(r4); r4s.trim();
|
String r4s(r4); r4s.trim();
|
||||||
String r5s(r5); r5s.trim();
|
String r5s(r5); r5s.trim();
|
||||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);
|
||||||
data.reserve(64);
|
data.reserve(64);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
@@ -661,7 +681,7 @@ public:
|
|||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
while (stream.available() > 0) {
|
while (stream.available() > 0) {
|
||||||
int a = stream.read();
|
int a = stream.read();
|
||||||
if (a < 0) continue;
|
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
||||||
data += (char)a;
|
data += (char)a;
|
||||||
if (r1 && data.endsWith(r1)) {
|
if (r1 && data.endsWith(r1)) {
|
||||||
index = 1;
|
index = 1;
|
||||||
@@ -702,6 +722,7 @@ finish:
|
|||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
|
DBG('<', index, '>');
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,8 +740,10 @@ finish:
|
|||||||
return waitResponse(1000, r1, r2, r3, r4, r5);
|
return waitResponse(1000, r1, r2, r3, r4, r5);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
|
protected:
|
||||||
GsmClient* sockets[TINY_GSM_MUX_COUNT];
|
GsmClient* sockets[TINY_GSM_MUX_COUNT];
|
||||||
};
|
};
|
||||||
|
|
Reference in New Issue
Block a user