Make sendAT(...) and waitResponce() public

This commit is contained in:
Volodymyr Shymanskyy
2017-09-05 16:54:15 +03:00
parent ebb1633718
commit 7df8d17e25

View File

@@ -27,11 +27,6 @@ static unsigned TINY_GSM_TCP_KEEP_ALIVE = 120;
class TinyGsm class TinyGsm
{ {
public:
TinyGsm(Stream& stream)
: stream(stream)
{}
public: public:
class GsmClient : public Client class GsmClient : public Client
@@ -95,7 +90,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(); return rx.size();
@@ -148,6 +143,12 @@ private:
public: public:
TinyGsm(Stream& stream)
: stream(stream)
{
memset(sockets, 0, sizeof(sockets));
}
/* /*
* Basic functions * Basic functions
*/ */
@@ -237,6 +238,7 @@ public:
} }
private: private:
int modemConnect(const char* host, uint16_t port, uint8_t mux) { int modemConnect(const char* host, uint16_t port, uint8_t mux) {
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE); sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE);
int rsp = waitResponse(75000L, int rsp = waitResponse(75000L,
@@ -266,7 +268,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);
@@ -278,7 +283,14 @@ private:
streamWrite(tail...); streamWrite(tail...);
} }
int streamRead() { return stream.read(); } bool streamSkipUntil(char c) { //TODO: timeout
while (true) {
while (!stream.available()) { TINY_GSM_YIELD(); }
if (stream.read() == c)
return true;
}
return false;
}
template<typename... Args> template<typename... Args>
void sendAT(Args... cmd) { void sendAT(Args... cmd) {
@@ -305,7 +317,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)) {