resync U201
This commit is contained in:
@@ -40,9 +40,22 @@ enum RegStatus {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// Declaration of the TinyGsmU201 Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
class TinyGsmU201
|
class TinyGsmU201
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The U201 Client Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class GsmClient : public Client
|
class GsmClient : public Client
|
||||||
@@ -109,7 +122,7 @@ public:
|
|||||||
|
|
||||||
virtual int available() {
|
virtual int available() {
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
if (!rx.size()) {
|
if (!rx.size() && sock_connected) {
|
||||||
at->maintain();
|
at->maintain();
|
||||||
}
|
}
|
||||||
return rx.size() + sock_available;
|
return rx.size() + sock_available;
|
||||||
@@ -172,6 +185,13 @@ private:
|
|||||||
RxFifo rx;
|
RxFifo rx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The Secure U201 Client Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
class GsmClientSecure : public GsmClient
|
class GsmClientSecure : public GsmClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -192,6 +212,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The U201 Modem Functions
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#ifdef GSM_DEFAULT_STREAM
|
#ifdef GSM_DEFAULT_STREAM
|
||||||
@@ -305,6 +332,8 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
@@ -355,17 +384,6 @@ public:
|
|||||||
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) {
|
||||||
@@ -381,6 +399,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) {
|
||||||
@@ -406,6 +435,28 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getLocalIP() {
|
||||||
|
sendAT(GF("+UPSND=0,0"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
streamSkipUntil(','); // Skip PSD profile
|
||||||
|
streamSkipUntil('\"'); // Skip request type
|
||||||
|
String res = stream.readStringUntil('\"');
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress localIP() {
|
||||||
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
@@ -471,24 +522,6 @@ public:
|
|||||||
return localIP() != 0;
|
return localIP() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLocalIP() {
|
|
||||||
sendAT(GF("+UPSND=0,0"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip PSD profile
|
|
||||||
streamSkipUntil('\"'); // Skip request type
|
|
||||||
String res = stream.readStringUntil('\"');
|
|
||||||
if (waitResponse() != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress localIP() {
|
|
||||||
return TinyGsmIpFromString(getLocalIP());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Phone Call functions
|
* Phone Call functions
|
||||||
*/
|
*/
|
||||||
@@ -649,9 +682,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;
|
||||||
}
|
}
|
||||||
@@ -663,7 +700,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!
|
||||||
@@ -671,12 +708,12 @@ public:
|
|||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
GsmConstStr r3=GFP(GSM_CME_ERROR), 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();
|
||||||
@@ -727,6 +764,7 @@ finish:
|
|||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
|
DBG('<', index, '>');
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user