diff --git a/src/Module.cpp b/src/Module.cpp index 4ff5cf79..00560460 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -49,10 +49,6 @@ void Module::ATemptyBuffer() { } } -bool Module::ATsendCommand(String& cmd) { - return(ATsendCommand(cmd.c_str())); -} - bool Module::ATsendCommand(const char* cmd) { ATemptyBuffer(); ModuleSerial->print(cmd); diff --git a/src/Module.h b/src/Module.h index 8f773734..fbbb6649 100644 --- a/src/Module.h +++ b/src/Module.h @@ -23,7 +23,6 @@ class Module { void ATemptyBuffer(); bool ATgetResponse(); - bool ATsendCommand(String& cmd); bool ATsendCommand(const char* cmd); bool ATsendData(uint8_t* data, uint32_t len); diff --git a/src/modules/ESP8266.cpp b/src/modules/ESP8266.cpp index f45012ff..2f802cd3 100644 --- a/src/modules/ESP8266.cpp +++ b/src/modules/ESP8266.cpp @@ -67,12 +67,12 @@ uint8_t ESP8266::join(const char* ssid, const char* password) { strcat(cmd, "\",\""); strcat(cmd, password); strcat(cmd, "\""); - - if(!_mod->ATsendCommand(cmd)) { - delete[] cmd; + + bool res = _mod->ATsendCommand(cmd); + delete[] cmd; + if(!res) { return(ERR_AT_FAILED); } - delete[] cmd; // disable multiple connection mode if(!_mod->ATsendCommand("AT+CIPMUX=0")) { @@ -392,13 +392,12 @@ uint8_t ESP8266::send(const char* data) { strcat(cmd, lenStr); // send data length in bytes - if(!_mod->ATsendCommand(cmd)) { - delete[] cmd; + bool res = _mod->ATsendCommand(cmd); + delete[] cmd; + if(!res) { return(ERR_AT_FAILED); } - delete[] cmd; - // send data if(!_mod->ATsendCommand(data)) { return(ERR_AT_FAILED); @@ -417,13 +416,12 @@ uint8_t ESP8266::send(uint8_t* data, uint32_t len) { strcat(cmd, lenStr); // send command and data length in bytes - if(!_mod->ATsendCommand(cmd)) { - delete[] cmd; + bool res = _mod->ATsendCommand(cmd); + delete[] cmd; + if(!res) { return(ERR_AT_FAILED); } - delete[] cmd; - // send data if(!_mod->ATsendData(data, len)) { return(ERR_AT_FAILED); @@ -472,12 +470,12 @@ uint8_t ESP8266::openTransportConnection(const char* host, const char* protocol, strcat(cmd, tcpKeepAliveStr); } - if(!_mod->ATsendCommand(cmd)) { - delete[] cmd; + bool res = _mod->ATsendCommand(cmd); + delete[] cmd; + if(!res) { return(ERR_AT_FAILED); } - delete[] cmd; return(ERR_NONE); } diff --git a/src/modules/XBee.cpp b/src/modules/XBee.cpp index 39497193..46096ab6 100644 --- a/src/modules/XBee.cpp +++ b/src/modules/XBee.cpp @@ -49,7 +49,7 @@ uint8_t XBee::begin(long speed) { return(ERR_NONE); } -uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const char destinationAddressLow[]) { +uint8_t XBee::setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow) { // enter command mode DEBUG_PRINTLN_STR("Entering command mode ..."); if(!enterCmdMode()) { @@ -58,17 +58,23 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c // set higher address bytes DEBUG_PRINTLN_STR("Setting address (high) ..."); - String addressHigh = "ATDH"; - addressHigh += destinationAddressHigh; - if(!_mod->ATsendCommand(addressHigh)) { + char* addressHigh = new char[strlen(destinationAddressHigh) + 4]; + strcpy(addressHigh, "ATDH"); + strcat(addressHigh, destinationAddressHigh); + bool res = _mod->ATsendCommand(addressHigh); + delete[] addressHigh; + if(!res) { return(ERR_AT_FAILED); } // set lower address bytes DEBUG_PRINTLN_STR("Setting address (low) ..."); - String addressLow = "ATDL"; - addressLow += destinationAddressLow; - if(!_mod->ATsendCommand(addressLow)) { + char* addressLow = new char[strlen(destinationAddressLow) + 4]; + strcpy(addressLow, "ATDL"); + strcat(addressLow, destinationAddressLow); + res = _mod->ATsendCommand(addressLow); + delete[] addressLow; + if(!res) { return(ERR_AT_FAILED); } @@ -81,7 +87,7 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c return(ERR_NONE); } -uint8_t XBee::setPanId(const char panId[]) { +uint8_t XBee::setPanId(const char* panId) { // enter command mode DEBUG_PRINTLN_STR("Entering command mode ..."); if(!enterCmdMode()) { @@ -90,9 +96,12 @@ uint8_t XBee::setPanId(const char panId[]) { // set PAN ID DEBUG_PRINTLN_STR("Setting PAN ID ..."); - String panIdCmd = "ATID"; - panIdCmd += panId; - if(!_mod->ATsendCommand(panIdCmd)) { + char* cmd = new char[strlen(panId) + 4]; + strcpy(cmd, "ATID"); + strcat(cmd, panId); + bool res = _mod->ATsendCommand(cmd); + delete[] cmd; + if(!res) { return(ERR_AT_FAILED); } diff --git a/src/modules/XBee.h b/src/modules/XBee.h index 9222bca5..8b63e0c4 100644 --- a/src/modules/XBee.h +++ b/src/modules/XBee.h @@ -54,8 +54,8 @@ class XBee: public ISerial { uint8_t begin(long speed); - uint8_t setDestinationAddress(const char destinationAddressHigh[], const char destinationAddressLow[]); - uint8_t setPanId(const char panId[]); + uint8_t setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow); + uint8_t setPanId(const char* panId); private: bool enterCmdMode();