Better support for Cellular XBEE3 modules

Also some minor documentation and naming changes for consistency.
This commit is contained in:
SRGDamia1
2018-05-16 12:54:57 -04:00
parent ffe4611f45
commit 2a08a828b1
10 changed files with 827 additions and 341 deletions

View File

@@ -39,24 +39,37 @@ enum RegStatus {
};
class TinyGsm
//============================================================================//
//============================================================================//
// Declaration of the TinyGsmM590 Class
//============================================================================//
//============================================================================//
class TinyGsmM590
{
//============================================================================//
//============================================================================//
// The M590 Internal Client Class
//============================================================================//
//============================================================================//
public:
class GsmClient : public Client
{
friend class TinyGsm;
friend class TinyGsmM590;
typedef TinyGsmFifo<uint8_t, TINY_GSM_RX_BUFFER> RxFifo;
public:
GsmClient() {}
GsmClient(TinyGsm& modem, uint8_t mux = 1) {
GsmClient(TinyGsmM590& modem, uint8_t mux = 1) {
init(&modem, mux);
}
bool init(TinyGsm* modem, uint8_t mux = 1) {
bool init(TinyGsmM590* modem, uint8_t mux = 1) {
this->at = modem;
this->mux = mux;
sock_connected = false;
@@ -159,15 +172,33 @@ public:
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
private:
TinyGsm* at;
TinyGsmM590* at;
uint8_t mux;
bool sock_connected;
RxFifo rx;
};
//============================================================================//
//============================================================================//
// The M590 Has no Secure client!
//============================================================================//
//============================================================================//
//============================================================================//
//============================================================================//
// The M590 Modem Functions
//============================================================================//
//============================================================================//
public:
TinyGsm(Stream& stream)
#ifdef GSM_DEFAULT_STREAM
TinyGsmM590(Stream& stream = GSM_DEFAULT_STREAM)
#else
TinyGsmM590(Stream& stream)
#endif
: stream(stream)
{
memset(sockets, 0, sizeof(sockets));
@@ -205,8 +236,8 @@ public:
for (unsigned long start = millis(); millis() - start < timeout; ) {
sendAT(GF(""));
if (waitResponse(200) == 1) {
delay(100);
return true;
delay(100);
return true;
}
delay(100);
}
@@ -318,10 +349,10 @@ public:
int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"));
waitResponse();
switch (status) {
case 2:
case 3: return SIM_LOCKED;
case 1: return SIM_READY;
default: return SIM_ERROR;
case 2:
case 3: return SIM_LOCKED;
case 1: return SIM_READY;
default: return SIM_ERROR;
}
}
return SIM_ERROR;
@@ -378,6 +409,10 @@ public:
return false;
}
/*
* WiFi functions
*/
/*
* GPRS functions
*/
@@ -408,12 +443,12 @@ public:
}
return false;
set_dns:
sendAT(GF("+DNSSERVER=1,8.8.8.8"));
waitResponse();
sendAT(GF("+DNSSERVER=2,8.8.4.4"));
waitResponse();
// set_dns: // TODO
// sendAT(GF("+DNSSERVER=1,8.8.8.8"));
// waitResponse();
//
// sendAT(GF("+DNSSERVER=2,8.8.4.4"));
// waitResponse();
return true;
}
@@ -595,9 +630,13 @@ public:
streamWrite(tail...);
}
bool streamSkipUntil(char c) { //TODO: timeout
while (true) {
while (!stream.available()) { TINY_GSM_YIELD(); }
bool streamSkipUntil(char c) {
const unsigned long timeout = 1000L;
unsigned long startMillis = millis();
while (millis() - startMillis < timeout) {
while (millis() - startMillis < timeout && !stream.available()) {
TINY_GSM_YIELD();
}
if (stream.read() == c)
return true;
}
@@ -683,6 +722,7 @@ finish:
}
data = "";
}
//DBG('<', index, '>');
return index;
}