Browse Source

Fix A6 <> Blynk operation

v_master
Volodymyr Shymanskyy 7 years ago
parent
commit
7213e25d35
1 changed files with 34 additions and 27 deletions
  1. +34
    -27
      TinyGsmClientA6.h

+ 34
- 27
TinyGsmClientA6.h View File

@ -42,11 +42,6 @@ enum RegStatus {
class TinyGsm class TinyGsm
{ {
public:
TinyGsm(Stream& stream)
: stream(stream)
{}
public: public:
class GsmClient : public Client class GsmClient : public Client
@ -166,6 +161,12 @@ private:
public: public:
TinyGsm(Stream& stream)
: stream(stream)
{
memset(sockets, 0, sizeof(sockets));
}
/* /*
* Basic functions * Basic functions
*/ */
@ -226,6 +227,11 @@ public:
return init(); return init();
} }
bool poweroff() {
sendAT(GF("+CPOF"));
return waitResponse() == 1;
}
/* /*
* SIM card functions * SIM card functions
*/ */
@ -298,9 +304,9 @@ public:
return res; return res;
} }
/*
* Generic network functions
*/
/*
* Generic network functions
*/
int getSignalQuality() { int getSignalQuality() {
sendAT(GF("+CSQ")); sendAT(GF("+CSQ"));
@ -351,12 +357,14 @@ public:
return false; return false;
} }
/*sendAT(GF("+CIFSR"));
/*
sendAT(GF("+CIFSR"));
String data; String data;
if (waitResponse(10000L, data) != 1) { if (waitResponse(10000L, data) != 1) {
data.replace(GSM_NL, ""); data.replace(GSM_NL, "");
return false; return false;
}*/
}
*/
return true; return true;
} }
@ -370,6 +378,8 @@ public:
* Phone Call functions * Phone Call functions
*/ */
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE;
bool callAnswer() { bool callAnswer() {
sendAT(GF("A")); sendAT(GF("A"));
return waitResponse() == 1; return waitResponse() == 1;
@ -380,6 +390,11 @@ public:
return waitResponse() == 1; return waitResponse() == 1;
} }
void callRedial() {
sendAT(GF("DLST"));
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;
@ -389,9 +404,7 @@ public:
* Messaging functions * Messaging functions
*/ */
// TODO
void sendUSSD() {
}
void sendUSSD() TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool sendSMS(const String& number, const String& text) { bool sendSMS(const String& number, const String& text) {
sendAT(GF("+CMGF=1")); sendAT(GF("+CMGF=1"));
@ -411,8 +424,7 @@ public:
* Location functions * Location functions
*/ */
void getGsmLocation() {
}
String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE;
/* /*
* Battery functions * Battery functions
@ -442,7 +454,7 @@ private:
int modemSend(const void* buff, size_t len, uint8_t mux) { int modemSend(const void* buff, size_t len, uint8_t mux) {
sendAT(GF("+CIPSEND="), mux, ',', len); sendAT(GF("+CIPSEND="), mux, ',', len);
if (waitResponse(10000L, GF(GSM_NL ">")) != 1) {
if (waitResponse(2000L, GF(GSM_NL ">")) != 1) {
return -1; return -1;
} }
stream.write((uint8_t*)buff, len); stream.write((uint8_t*)buff, len);
@ -460,7 +472,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);
@ -472,8 +487,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(); }
@ -508,7 +521,7 @@ private:
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)) {
@ -539,9 +552,8 @@ private:
sockets[mux]->rx.put(stream.read()); sockets[mux]->rx.put(stream.read());
} }
data = ""; data = "";
return index;
} else if (data.endsWith(GF("+TCPCLOSED:"))) { } else if (data.endsWith(GF("+TCPCLOSED:"))) {
int mux = stream.readStringUntil('\n').toInt(); // TODO: No comma?
int mux = stream.readStringUntil('\n').toInt();
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
data = ""; data = "";
} }
@ -551,12 +563,7 @@ finish:
if (!index) { if (!index) {
data.trim(); data.trim();
if (data.length()) { if (data.length()) {
if (data.endsWith(GF("+TCPCLOSED:"))) {
int mux = stream.readStringUntil('\n').toInt();
sockets[mux]->sock_connected = false;
} else {
DBG("### Unhandled:", data);
}
DBG("### Unhandled:", data);
} }
data = ""; data = "";
} }


Loading…
Cancel
Save