Fix all Wextra warnings

This commit is contained in:
Sara Damiano
2019-08-27 16:39:29 -04:00
parent 3a8a2ada1a
commit dac86a22cd
14 changed files with 252 additions and 85 deletions

View File

@@ -135,20 +135,38 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
if (waitResponse() != 1) {
return false;
}
sendAT(GF("+CMEE=0")); // Turn off verbose errors
#ifdef TINY_GSM_DEBUG
sendAT(GF("+CMEE=2")); // turn on verbose error codes
#else
sendAT(GF("+CMEE=0")); // turn off error codes
#endif
waitResponse();
sendAT(GF("+CMER=3,0,0,2")); // Set unsolicited result code output destination
waitResponse();
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -525,6 +543,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
}
chargeState = stream.readStringUntil(',').toInt();
percent = stream.readStringUntil('\n').toInt();
milliVolts = 0;
// Wait for final OK
waitResponse();
return true;

View File

@@ -158,16 +158,29 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
if (waitResponse() != 1) {
return false;
}
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -497,10 +510,10 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
bool ssl = false, int timeout_s = 20)
{
bool ssl = false, int timeout_s = 20) {
if (ssl) DBG("SSL not yet supported on this module!");
int rsp;
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
// <PDPcontextID>(1-16), <connectID>(0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE",
// "<IP_address>/<domain_name>",<remote_port>,<local_port>,<access_mode>(0-2 0=buffer)

View File

@@ -33,13 +33,12 @@ static unsigned TINY_GSM_TCP_KEEP_ALIVE = 120;
enum RegStatus {
REG_OK_IP = 2,
REG_OK_TCP = 3,
REG_UNREGISTERED = 4,
REG_OK_NO_TCP = 4,
REG_DENIED = 5,
REG_UNKNOWN = 6,
};
class TinyGsmESP8266
{
@@ -157,6 +156,9 @@ public:
if (!testAT()) {
return false;
}
if (pin != NULL) {
DBG("ESP8266 modules do not use an unlock pin!");
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
@@ -249,7 +251,8 @@ TINY_GSM_MODEM_MAINTAIN_LISTEN()
RegStatus getRegistrationStatus() {
sendAT(GF("+CIPSTATUS"));
if (waitResponse(3000, GF("STATUS:")) != 1) return REG_UNKNOWN;
int status = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
int status =
waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
waitResponse(); // Returns an OK after the status
return (RegStatus)status;
}

View File

@@ -133,20 +133,36 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
if (waitResponse() != 1) {
return false;
}
#ifdef TINY_GSM_DEBUG
sendAT(GF("+CMEE=2"));
waitResponse();
sendAT(GF("+CMEE=2")); // turn on verbose error codes
#else
sendAT(GF("+CMEE=0")); // turn off error codes
#endif
waitResponse();
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {

View File

@@ -157,20 +157,36 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
if (waitResponse() != 1) {
return false;
}
#ifdef TINY_GSM_DEBUG
sendAT(GF("+CMEE=2"));
waitResponse();
sendAT(GF("+CMEE=2")); // turn on verbose error codes
#else
sendAT(GF("+CMEE=0")); // turn off error codes
#endif
waitResponse();
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -557,9 +573,9 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
bool ssl = false, int timeout_s = 75)
{
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
bool ssl = false, int timeout_s = 75) {
if (ssl) DBG("SSL not yet supported on this module!");
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port);
int rsp = waitResponse(timeout_ms,
GF("CONNECT OK" GSM_NL),

View File

@@ -161,18 +161,32 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("&FZ")); // Factory + Reset
waitResponse();
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
}
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -563,9 +577,9 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
bool ssl = false, int timeout_s = 75)
{
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
bool ssl = false, int timeout_s = 75) {
if (ssl) DBG("SSL not yet supported on this module!");
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port);
int rsp = waitResponse(timeout_ms,
GF("CONNECT OK" GSM_NL),

View File

@@ -142,16 +142,29 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
}
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -640,17 +653,20 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
bool ssl = false, int timeout_s = 75) {
bool ssl = false, int timeout_s = 15) {
// Make sure we'll be getting data manually on this connection
sendAT(GF("+CIPRXGET=1"));
if (waitResponse() != 1) {
return false;
}
if (ssl) DBG("SSL not yet supported on this module!");
// Establish a connection in multi-socket mode
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
// The reply is +CIPOPEN: ## of socket created
if (waitResponse(15000L, GF(GSM_NL "+CIPOPEN:")) != 1) {
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPOPEN:")) != 1) {
return false;
}
return true;

View File

@@ -166,16 +166,29 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
}
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -801,8 +814,9 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
bool ssl = false, int timeout_s = 75)
{
bool ssl = false, int timeout_s = 75) {
if (ssl) DBG("SSL not yet supported on this module!");
int rsp;
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);

View File

@@ -142,16 +142,29 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
}
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {
@@ -555,7 +568,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
}
// get GPS informations
bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0) {
bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0) {
//String buffer = "";
bool fix = false;
@@ -582,8 +595,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
stream.readStringUntil(',');//PDOP
stream.readStringUntil(',');//HDOP
stream.readStringUntil(',');//VDOP
//if (vsat != NULL) *vsat = stream.readStringUntil(',').toInt(); //viewed satelites
//if (usat != NULL) *usat = stream.readStringUntil(',').toInt(); //used satelites
stream.readStringUntil('\n');
waitResponse();
@@ -618,16 +629,11 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE;
bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) {
sendAT(GF("+CBC?"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
return false;
}
// get voltage in VOLTS
float voltage = stream.readStringUntil('\n').toFloat();
milliVolts = voltage*1000;
// Wait for final OK
waitResponse();
bool getBattStats(uint8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) {
chargeState = 0;
percent = 0;
milliVolts = getBattVoltage();
return true;
}
@@ -649,9 +655,9 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
*/
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
bool ssl = false, int timeout_s = 75) {
bool ssl = false, int timeout_s = 15) {
if (ssl) DBG("SSL not yet supported on this module!");
// Make sure we'll be getting data manually on this connection
sendAT(GF("+CIPRXGET=1"));
if (waitResponse() != 1) {
@@ -659,9 +665,11 @@ protected:
}
// Establish a connection in multi-socket mode
sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","),
port);
// The reply is +CIPOPEN: ## of socket created
if (waitResponse(15000L, GF(GSM_NL "+CIPOPEN:")) != 1) {
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPOPEN:")) != 1) {
return false;
}
return true;

View File

@@ -165,6 +165,7 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
@@ -174,9 +175,19 @@ public:
if (waitResponse() != 1) {
return false;
}
DBG(GF("### Modem:"), getModemName());
getSimStatus();
return true;
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {

View File

@@ -176,9 +176,11 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
@@ -191,7 +193,7 @@ public:
#endif
waitResponse();
getModemName();
DBG(GF("### Modem:"), getModemName());
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
@@ -509,6 +511,8 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) {
percent = getBattPercent();
chargeState = 0;
milliVolts = 0;
return true;
}
@@ -525,7 +529,7 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
streamSkipUntil(','); // Skip units (C/F)
int16_t res = stream.readStringUntil('\n').toInt();
float temp = -9999;
if (res != 65535) {
if (res != -1) {
temp = ((float)res)/10;
}
return temp;

View File

@@ -195,15 +195,29 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
}
getSimStatus();
return true;
DBG(GF("### Modem:"), getModemName());
int ret = getSimStatus();
// if the sim isn't ready and a pin has been provided, try to unlock the sim
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
simUnlock(pin);
return (getSimStatus() == SIM_READY);
}
// if the sim is ready, or it's locked but no pin has been provided, return
// true
else {
return (ret == SIM_READY || ret == SIM_LOCKED);
}
}
String getModemName() {

View File

@@ -176,9 +176,11 @@ public:
bool init(const char* pin = NULL) {
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
if (!testAT()) {
return false;
}
sendAT(GF("E0")); // Echo Off
if (waitResponse() != 1) {
return false;
@@ -535,7 +537,9 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE;
bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) {
chargeState = 0;
percent = getBattPercent();
milliVolts = 0;
return true;
}

View File

@@ -305,6 +305,10 @@ public:
digitalWrite(resetPin, HIGH);
}
if (pin != NULL) {
DBG("XBee's do not support SIMs that require an unlock pin!");
}
XBEE_COMMAND_START_DECORATOR(10, false)
sendAT(GF("AP0")); // Put in transparent mode
@@ -524,6 +528,9 @@ public:
*/
bool simUnlock(const char *pin) { // Not supported
if (pin != NULL) {
DBG("XBee's do not support SIMs that require an unlock pin!");
}
return false;
}
@@ -535,7 +542,7 @@ public:
return sendATGetString(GF("IM"));
}
SimStatus getSimStatus(unsigned long timeout_ms = 10000L) {
SimStatus getSimStatus() {
return SIM_READY; // unsupported
}
@@ -734,7 +741,14 @@ public:
* GPRS functions
*/
bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) {
bool gprsConnect(const char* apn, const char* user = NULL,
const char* pwd = NULL) {
if (user != NULL) {
DBG("XBee's do not support SIMs that a user name/password!");
}
if (pwd != NULL) {
DBG("XBee's do not support SIMs that a user name/password!");
}
XBEE_COMMAND_START_DECORATOR(5, false)
sendAT(GF("AN"), apn); // Set the APN
bool success = waitResponse() == 1;
@@ -922,6 +936,7 @@ protected:
}
int16_t modemSend(const void* buff, size_t len, uint8_t mux = 0) {
if (mux != 0) DBG("XBee only supports 1 IP channel in transparent mode!");
stream.write((uint8_t*)buff, len);
stream.flush();
return len;