Browse Source

Condensed client functions into pre-processor macros

v_master
Sara Damiano 5 years ago
parent
commit
85d309621d
13 changed files with 258 additions and 897 deletions
  1. +5
    -75
      src/TinyGsmClientA6.h
  2. +5
    -78
      src/TinyGsmClientBG96.h
  3. +5
    -75
      src/TinyGsmClientESP8266.h
  4. +7
    -76
      src/TinyGsmClientM590.h
  5. +5
    -78
      src/TinyGsmClientM95.h
  6. +5
    -78
      src/TinyGsmClientMC60.h
  7. +5
    -94
      src/TinyGsmClientSIM7000.h
  8. +5
    -92
      src/TinyGsmClientSIM800.h
  9. +5
    -86
      src/TinyGsmClientSaraR4.h
  10. +5
    -78
      src/TinyGsmClientSequansMonarch.h
  11. +5
    -86
      src/TinyGsmClientUBLOX.h
  12. +1
    -1
      src/TinyGsmClientXBee.h
  13. +200
    -0
      src/TinyGsmCommon.h

+ 5
- 75
src/TinyGsmClientA6.h View File

@ -58,10 +58,6 @@ public:
this->mux = -1; this->mux = -1;
sock_connected = false; sock_connected = false;
// at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -75,23 +71,11 @@ public:
if (sock_connected) { if (sock_connected) {
mux = newMux; mux = newMux;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
} }
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -101,67 +85,13 @@ public:
rx.clear(); rx.clear();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
//at->maintain();
return at->modemSend(buf, size, mux);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
TINY_GSM_CLIENT_AVAILABLE_NO_MODEM_FIFO()
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
TINY_GSM_CLIENT_READ_NO_MODEM_FIFO()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size() && sock_connected) {
at->maintain();
}
return rx.size();
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
size_t cnt = 0;
uint32_t _startMillis = millis();
while (cnt < size && millis() - _startMillis < _timeout) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Read directly into user buffer?
if (!rx.size() && sock_connected) {
at->maintain();
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 78
src/TinyGsmClientBG96.h View File

@ -62,8 +62,6 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -74,24 +72,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -112,70 +96,13 @@ public:
at->waitResponse(); at->waitResponse();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
TINY_GSM_CLIENT_AVAILABLE_NO_BUFFER_CHECK()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
at->maintain();
}
return rx.size() + sock_available;
}
TINY_GSM_CLIENT_READ_NO_BUFFER_CHECK()
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 75
src/TinyGsmClientESP8266.h View File

@ -59,8 +59,6 @@ public:
sock_connected = false; sock_connected = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -71,24 +69,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -98,67 +82,13 @@ public:
rx.clear(); rx.clear();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
//at->maintain();
return at->modemSend(buf, size, mux);
}
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
TINY_GSM_CLIENT_AVAILABLE_NO_MODEM_FIFO()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size() && sock_connected) {
at->maintain();
}
return rx.size();
}
TINY_GSM_CLIENT_READ_NO_MODEM_FIFO()
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
size_t cnt = 0;
uint32_t _startMillis = millis();
while (cnt < size && millis() - _startMillis < _timeout) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Read directly into user buffer?
if (!rx.size() && sock_connected) {
at->maintain();
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 7
- 76
src/TinyGsmClientM590.h View File

@ -59,8 +59,6 @@ public:
sock_connected = false; sock_connected = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -71,24 +69,11 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -98,67 +83,13 @@ public:
rx.clear(); rx.clear();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
//at->maintain();
return at->modemSend(buf, size, mux);
}
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size() && sock_connected) {
at->maintain();
}
return rx.size();
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
size_t cnt = 0;
uint32_t _startMillis = millis();
while (cnt < size && millis() - _startMillis < _timeout) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Read directly into user buffer?
if (!rx.size() && sock_connected) {
at->maintain();
}
}
return cnt;
}
TINY_GSM_CLIENT_WRITE()
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
TINY_GSM_CLIENT_AVAILABLE_NO_MODEM_FIFO()
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
TINY_GSM_CLIENT_READ_NO_MODEM_FIFO()
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API
@ -167,7 +98,7 @@ public:
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED; String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
private: private:
TinyGsmM590* at;
TinyGsmM590* at;
uint8_t mux; uint8_t mux;
bool sock_connected; bool sock_connected;
RxFifo rx; RxFifo rx;


+ 5
- 78
src/TinyGsmClientM95.h View File

@ -62,8 +62,6 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -74,24 +72,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -112,70 +96,13 @@ public:
at->waitResponse(60000L, GF("CLOSED"), GF("CLOSE OK"), GF("ERROR")); at->waitResponse(60000L, GF("CLOSED"), GF("CLOSE OK"), GF("ERROR"));
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
TINY_GSM_CLIENT_AVAILABLE_NO_BUFFER_CHECK()
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
TINY_GSM_CLIENT_READ_NO_BUFFER_CHECK()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
at->maintain();
}
return rx.size() + sock_available;
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 78
src/TinyGsmClientMC60.h View File

@ -66,8 +66,6 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -78,24 +76,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -116,70 +100,13 @@ public:
at->waitResponse(60000L, GF("CLOSED"), GF("CLOSE OK"), GF("ERROR")); at->waitResponse(60000L, GF("CLOSED"), GF("CLOSE OK"), GF("ERROR"));
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
TINY_GSM_CLIENT_AVAILABLE_NO_BUFFER_CHECK()
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
TINY_GSM_CLIENT_READ_NO_BUFFER_CHECK()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
at->maintain();
}
return rx.size() + sock_available;
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 94
src/TinyGsmClientSIM7000.h View File

@ -71,8 +71,6 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -83,24 +81,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -121,86 +105,13 @@ public:
at->waitResponse(); at->waitResponse();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
// TODO: Is this needed for SIM7000?
// Workaround: sometimes SIM7000 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
at->maintain();
}
return rx.size() + sock_available;
}
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// TODO: Is this needed for SIM7000?
// Workaround: sometimes SIM7000 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 92
src/TinyGsmClientSIM800.h View File

@ -68,8 +68,6 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@ -80,24 +78,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socket after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -118,84 +102,13 @@ public:
at->waitResponse(); at->waitResponse();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
// Workaround: sometimes SIM800 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
at->maintain();
}
return rx.size() + sock_available;
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// Workaround: sometimes SIM800 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
TINY_GSM_CLIENT_WRITE()
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK()
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 86
src/TinyGsmClientSaraR4.h View File

@ -101,17 +101,7 @@ public:
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -130,84 +120,13 @@ public:
at->modemDisconnect(mux); at->modemDisconnect(mux);
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
// Workaround: sometimes SARA R410 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
at->maintain();
}
return rx.size() + sock_available;
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// Workaround: sometimes SARA R410 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
TINY_GSM_CLIENT_WRITE()
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK()
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 78
src/TinyGsmClientSequansMonarch.h View File

@ -91,17 +91,7 @@ public:
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -122,76 +112,13 @@ public:
at->waitResponse(); at->waitResponse();
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
TINY_GSM_CLIENT_WRITE()
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK()
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
// Workaround: sometimes unsolicited SQNSSRING notifications do not arrive.
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
at->maintain();
}
return rx.size() + sock_available;
}
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// Workaround: sometimes unsolicited SQNSSRING notifications do not arrive.
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
int n = at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
if (n == 0) break;
} else {
break;
}
}
return cnt;
}
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 5
- 86
src/TinyGsmClientUBLOX.h View File

@ -85,17 +85,7 @@ public:
return sock_connected; return sock_connected;
} }
virtual int connect(IPAddress ip, uint16_t port) {
String host; host.reserve(16);
host += ip[0];
host += ".";
host += ip[1];
host += ".";
host += ip[2];
host += ".";
host += ip[3];
return connect(host.c_str(), port);
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
virtual void stop() { virtual void stop() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
@ -114,84 +104,13 @@ public:
at->modemDisconnect(mux); at->modemDisconnect(mux);
} }
virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
return at->modemSend(buf, size, mux);
}
virtual size_t write(uint8_t c) {
return write(&c, 1);
}
virtual size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual int available() {
TINY_GSM_YIELD();
if (!rx.size()) {
// Workaround: sometimes SARA R410 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
at->maintain();
}
return rx.size() + sock_available;
}
virtual int read(uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
at->maintain();
size_t cnt = 0;
while (cnt < size) {
size_t chunk = TinyGsmMin(size-cnt, rx.size());
if (chunk > 0) {
rx.get(buf, chunk);
buf += chunk;
cnt += chunk;
continue;
}
// Workaround: sometimes SARA R410 forgets to notify about data arrival.
// TODO: Currently we ping the module periodically,
// but maybe there's a better indicator that we need to poll
if (millis() - prev_check > 250) {
got_data = true;
prev_check = millis();
}
// TODO: Read directly into user buffer?
at->maintain();
if (sock_available > 0) {
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else {
break;
}
}
return cnt;
}
TINY_GSM_CLIENT_WRITE() ;
virtual int read() {
uint8_t c;
if (read(&c, 1) == 1) {
return c;
}
return -1;
}
TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK() ;
virtual int peek() { return -1; } //TODO
virtual void flush() { at->stream.flush(); }
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK() ;
virtual uint8_t connected() {
if (available()) {
return true;
}
return sock_connected;
}
virtual operator bool() { return connected(); }
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
/* /*
* Extended API * Extended API


+ 1
- 1
src/TinyGsmClientXBee.h View File

@ -168,7 +168,7 @@ public:
cnt += chunk; cnt += chunk;
continue; continue;
} }
// TODO: Read directly into user buffer?
/* TODO: Read directly into user buffer? */
if (!rx.size() || at->stream.available()) { if (!rx.size() || at->stream.available()) {
at->maintain(); at->maintain();
} }


+ 200
- 0
src/TinyGsmCommon.h View File

@ -202,4 +202,204 @@ String TinyGsmDecodeHex16bit(String &instr) {
return result; return result;
} }
// Connect to a IP address given as an IPAddress object by
// converting said IP address to text
#define TINY_GSM_CLIENT_CONNECT_TO_IP() \
virtual int connect(IPAddress ip, uint16_t port) { \
String host; host.reserve(16); \
host += ip[0]; \
host += "."; \
host += ip[1]; \
host += "."; \
host += ip[2]; \
host += "."; \
host += ip[3]; \
return connect(host.c_str(), port); \
}
// Writes data out on the client using the modem send functionality
#define TINY_GSM_CLIENT_WRITE() \
virtual size_t write(const uint8_t *buf, size_t size) { \
TINY_GSM_YIELD(); \
at->maintain(); \
return at->modemSend(buf, size, mux); \
} \
\
virtual size_t write(uint8_t c) {\
return write(&c, 1); \
}\
\
virtual size_t write(const char *str) { \
if (str == NULL) return 0; \
return write((const uint8_t *)str, strlen(str)); \
}
// Returns the combined number of characters available in the TinyGSM fifo
// and the modem chips internal fifo, doing an extra check-in with the
// modem to see if anything has arrived without a UURC.
#define TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK() \
virtual int available() { \
TINY_GSM_YIELD(); \
if (!rx.size()) { \
/* Workaround: sometimes module forgets to notify about data arrival.
TODO: Currently we ping the module periodically,
but maybe there's a better indicator that we need to poll */ \
if (millis() - prev_check > 250) { \
got_data = true; \
prev_check = millis(); \
} \
at->maintain(); \
} \
return rx.size() + sock_available; \
}
// Returns the combined number of characters available in the TinyGSM fifo and
// the modem chips internal fifo. Use this if you don't expect to miss any URC's.
#define TINY_GSM_CLIENT_AVAILABLE_NO_BUFFER_CHECK() \
virtual int available() { \
TINY_GSM_YIELD(); \
if (!rx.size()) { \
at->maintain(); \
} \
return rx.size() + sock_available; \
}
// Returns the number of characters avaialable in the TinyGSM fifo
// Assumes the modem chip has no internal fifo
#define TINY_GSM_CLIENT_AVAILABLE_NO_MODEM_FIFO() \
virtual int available() { \
TINY_GSM_YIELD(); \
if (!rx.size() && sock_connected) { \
at->maintain(); \
} \
return rx.size(); \
}
#define TINY_GSM_CLIENT_READ_OVERLOAD() \
virtual int read() { \
uint8_t c; \
if (read(&c, 1) == 1) { \
return c; \
} \
return -1; \
}
// Reads characters out of the TinyGSM fifo, and from the modem chips internal
// fifo if avaiable, also double checking with the modem if data has arrived
// without issuing a UURC.
#define TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK() \
virtual int read(uint8_t *buf, size_t size) { \
TINY_GSM_YIELD(); \
at->maintain(); \
size_t cnt = 0; \
while (cnt < size) { \
size_t chunk = TinyGsmMin(size-cnt, rx.size()); \
if (chunk > 0) { \
rx.get(buf, chunk); \
buf += chunk; \
cnt += chunk; \
continue; \
} \
/* Workaround: sometimes module forgets to notify about data arrival.
TODO: Currently we ping the module periodically,
but maybe there's a better indicator that we need to poll */ \
if (millis() - prev_check > 250) { \
got_data = true; \
prev_check = millis(); \
} \
/* TODO: Read directly into user buffer? */ \
at->maintain(); \
if (sock_available > 0) { \
int n = at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); \
if (n == 0) break; \
} else { \
break; \
} \
} \
return cnt; \
} \
TINY_GSM_CLIENT_READ_OVERLOAD()
// Reads characters out of the TinyGSM fifo, and from the modem chips internal
// fifo if avaiable. Use this if you don't expect to miss any URC's.
#define TINY_GSM_CLIENT_READ_NO_BUFFER_CHECK() \
virtual int read(uint8_t *buf, size_t size) { \
TINY_GSM_YIELD(); \
at->maintain(); \
size_t cnt = 0; \
while (cnt < size) { \
size_t chunk = TinyGsmMin(size-cnt, rx.size()); \
if (chunk > 0) { \
rx.get(buf, chunk); \
buf += chunk; \
cnt += chunk; \
continue; \
} \
/* TODO: Read directly into user buffer? */ \
at->maintain(); \
if (sock_available > 0) { \
int n = at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); \
if (n == 0) break; \
} else { \
break; \
} \
} \
return cnt; \
} \
TINY_GSM_CLIENT_READ_OVERLOAD()
// Reads characters out of the TinyGSM fifo, waiting for any URC's from the
// modem for new data if there's nothing in the fifo. This assumes the
//modem chip itself has no fifo.
#define TINY_GSM_CLIENT_READ_NO_MODEM_FIFO() \
virtual int read(uint8_t *buf, size_t size) { \
TINY_GSM_YIELD(); \
size_t cnt = 0; \
uint32_t _startMillis = millis(); \
while (cnt < size && millis() - _startMillis < _timeout) { \
size_t chunk = TinyGsmMin(size-cnt, rx.size()); \
if (chunk > 0) { \
rx.get(buf, chunk); \
buf += chunk; \
cnt += chunk; \
continue; \
} \
/* TODO: Read directly into user buffer? */ \
if (!rx.size() && sock_connected) { \
at->maintain(); \
} \
} \
return cnt; \
} \
\
virtual int read() { \
uint8_t c; \
if (read(&c, 1) == 1) { \
return c; \
} \
return -1; \
}
#define TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED() \
virtual int peek() { return -1; } /* TODO */ \
\
virtual void flush() { at->stream.flush(); } \
\
virtual uint8_t connected() { \
if (available()) { \
return true; \
} \
return sock_connected; \
} \
virtual operator bool() { return connected(); }
#endif #endif

Loading…
Cancel
Save