Condensed client functions into pre-processor macros
This commit is contained in:
@@ -58,10 +58,6 @@ public:
|
||||
this->mux = -1;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -75,23 +71,11 @@ public:
|
||||
if (sock_connected) {
|
||||
mux = newMux;
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socket after attempting connection or above at init?
|
||||
// Currently done inconsistently between modems
|
||||
}
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -101,67 +85,13 @@ public:
|
||||
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
|
||||
|
@@ -62,8 +62,6 @@ public:
|
||||
got_data = false;
|
||||
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socket here at init? Or later at connect?
|
||||
// Currently done inconsistently between modems
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -74,24 +72,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -112,70 +96,13 @@ public:
|
||||
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_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
|
||||
|
@@ -59,8 +59,6 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -71,24 +69,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -98,67 +82,13 @@ public:
|
||||
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
|
||||
|
@@ -59,8 +59,6 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -71,24 +69,11 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -98,67 +83,13 @@ public:
|
||||
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
|
||||
|
@@ -62,8 +62,6 @@ public:
|
||||
got_data = false;
|
||||
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socket here at init? Or later at connect?
|
||||
// Currently done inconsistently between modems
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -74,24 +72,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -112,70 +96,13 @@ public:
|
||||
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
|
||||
|
@@ -66,8 +66,6 @@ public:
|
||||
got_data = false;
|
||||
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socket here at init? Or later at connect?
|
||||
// Currently done inconsistently between modems
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -78,24 +76,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -116,70 +100,13 @@ public:
|
||||
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
|
||||
|
@@ -71,8 +71,6 @@ public:
|
||||
got_data = false;
|
||||
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socket here at init? Or later at connect?
|
||||
// Currently done inconsistently between modems
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -83,24 +81,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -121,86 +105,13 @@ public:
|
||||
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 size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
TINY_GSM_CLIENT_READ_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;
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -68,8 +68,6 @@ public:
|
||||
got_data = false;
|
||||
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socket here at init? Or later at connect?
|
||||
// Currently done inconsistently between modems
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -80,24 +78,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -118,84 +102,13 @@ public:
|
||||
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 size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -101,17 +101,7 @@ public:
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -130,84 +120,13 @@ public:
|
||||
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);
|
||||
}
|
||||
TINY_GSM_CLIENT_WRITE()
|
||||
|
||||
virtual size_t write(uint8_t c) {
|
||||
return write(&c, 1);
|
||||
}
|
||||
TINY_GSM_CLIENT_AVAILABLE_WITH_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_WITH_BUFFER_CHECK()
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -91,17 +91,7 @@ public:
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -122,76 +112,13 @@ public:
|
||||
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
|
||||
|
@@ -85,17 +85,7 @@ public:
|
||||
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() {
|
||||
TINY_GSM_YIELD();
|
||||
@@ -114,84 +104,13 @@ public:
|
||||
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);
|
||||
}
|
||||
TINY_GSM_CLIENT_WRITE() ;
|
||||
|
||||
virtual size_t write(uint8_t c) {
|
||||
return write(&c, 1);
|
||||
}
|
||||
TINY_GSM_CLIENT_AVAILABLE_WITH_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_WITH_BUFFER_CHECK() ;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -168,7 +168,7 @@ public:
|
||||
cnt += chunk;
|
||||
continue;
|
||||
}
|
||||
// TODO: Read directly into user buffer?
|
||||
/* TODO: Read directly into user buffer? */
|
||||
if (!rx.size() || at->stream.available()) {
|
||||
at->maintain();
|
||||
}
|
||||
|
@@ -202,4 +202,204 @@ String TinyGsmDecodeHex16bit(String &instr) {
|
||||
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
|
||||
|
Reference in New Issue
Block a user