Make sendAT(...) and waitResponce() public
This commit is contained in:
@@ -43,11 +43,6 @@ enum RegStatus {
|
|||||||
class TinyGsm
|
class TinyGsm
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
TinyGsm(Stream& stream)
|
|
||||||
: stream(stream)
|
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class GsmClient : public Client
|
class GsmClient : public Client
|
||||||
@@ -180,6 +175,12 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
TinyGsm(Stream& stream)
|
||||||
|
: stream(stream)
|
||||||
|
{
|
||||||
|
memset(sockets, 0, sizeof(sockets));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic functions
|
* Basic functions
|
||||||
*/
|
*/
|
||||||
@@ -191,7 +192,9 @@ public:
|
|||||||
if (!autoBaud()) {
|
if (!autoBaud()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
|
sendAT(GF("&FZ")); // Factory + Reset
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("E0")); // Echo Off
|
||||||
if (waitResponse() != 1) {
|
if (waitResponse() != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -344,9 +347,9 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int getSignalQuality() {
|
int getSignalQuality() {
|
||||||
sendAT(GF("+CSQ"));
|
sendAT(GF("+CSQ"));
|
||||||
@@ -474,6 +477,11 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void callRedial() {
|
||||||
|
sendAT(GF("DL"));
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
bool callHangup(const String& number) {
|
bool callHangup(const String& number) {
|
||||||
sendAT(GF("H"), number);
|
sendAT(GF("H"), number);
|
||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
@@ -483,9 +491,7 @@ public:
|
|||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO
|
void sendUSSD() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
void sendUSSD() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
@@ -654,7 +660,10 @@ private:
|
|||||||
return 1 == res;
|
return 1 == res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void streamWrite(T last) {
|
void streamWrite(T last) {
|
||||||
stream.print(last);
|
stream.print(last);
|
||||||
@@ -666,8 +675,6 @@ private:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
int streamRead() { return stream.read(); }
|
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) { //TODO: timeout
|
||||||
while (true) {
|
while (true) {
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
@@ -697,13 +704,12 @@ private:
|
|||||||
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 mux = -1;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
do {
|
do {
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
while (stream.available() > 0) {
|
while (stream.available() > 0) {
|
||||||
int a = streamRead();
|
int a = stream.read();
|
||||||
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
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)) {
|
||||||
@@ -724,20 +730,22 @@ private:
|
|||||||
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
||||||
String mode = stream.readStringUntil(',');
|
String mode = stream.readStringUntil(',');
|
||||||
if (mode.toInt() == 1) {
|
if (mode.toInt() == 1) {
|
||||||
mux = stream.readStringUntil('\n').toInt();
|
int mux = stream.readStringUntil('\n').toInt();
|
||||||
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
|
||||||
|
sockets[mux]->got_data = true;
|
||||||
|
}
|
||||||
data = "";
|
data = "";
|
||||||
sockets[mux]->got_data = true;
|
|
||||||
} else {
|
} else {
|
||||||
data += mode;
|
data += mode;
|
||||||
}
|
}
|
||||||
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
||||||
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
|
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
|
||||||
int coma = data.indexOf(',', nl+2);
|
int coma = data.indexOf(',', nl+2);
|
||||||
mux = data.substring(nl+2, coma).toInt();
|
int mux = data.substring(nl+2, coma).toInt();
|
||||||
if (mux) {
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout);
|
} while (millis() - startMillis < timeout);
|
||||||
|
|||||||
Reference in New Issue
Block a user