Implement connect with timeout, XBee improvements

This commit is contained in:
Sara Damiano
2019-05-20 09:21:08 -04:00
parent 96c1fed3ef
commit 4ba8306880
14 changed files with 275 additions and 236 deletions

View File

@@ -72,7 +72,7 @@ public:
}
public:
virtual int connect(const char *host, uint16_t port) {
virtual int connect(const char *host, uint16_t port, int timeout) {
stop();
// If we're creating a new connection on the same client, we need to wait
// until the async close has finished on Cat-M modems.
@@ -94,7 +94,7 @@ public:
rx.clear();
uint8_t oldMux = mux;
sock_connected = at->modemConnect(host, port, &mux);
sock_connected = at->modemConnect(host, port, &mux, timeout);
if (mux != oldMux) {
DBG("WARNING: Mux number changed from", oldMux, "to", mux);
at->sockets[oldMux] = NULL;
@@ -105,7 +105,7 @@ public:
return sock_connected;
}
TINY_GSM_CLIENT_CONNECT_TO_IP()
TINY_GSM_CLIENT_CONNECT_OVERLOADS()
virtual void stop() {
TINY_GSM_YIELD();
@@ -159,12 +159,12 @@ public:
{}
public:
virtual int connect(const char *host, uint16_t port) {
virtual int connect(const char *host, uint16_t port, int timeout) {
stop();
TINY_GSM_YIELD();
rx.clear();
uint8_t oldMux = mux;
sock_connected = at->modemConnect(host, port, &mux, true);
sock_connected = at->modemConnect(host, port, &mux, true, timeout);
if (mux != oldMux) {
DBG("WARNING: Mux number changed from", oldMux, "to", mux);
at->sockets[oldMux] = NULL;
@@ -528,7 +528,9 @@ TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t* mux, bool ssl = false) {
bool modemConnect(const char* host, uint16_t port, uint8_t* mux,
bool ssl = false, int timeout = 120000L)
{
sendAT(GF("+USOCR=6")); // create a socket
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created
return false;
@@ -553,7 +555,7 @@ protected:
// TODO: Use faster "asynchronous" connection?
// We would have to wait for the +UUSOCO URC to verify connection
sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port);
int rsp = waitResponse(120000L);
int rsp = waitResponse(timeout);
return (1 == rsp);
}