Replaced all remaining internal Arduino Strings
This commit is contained in:
parent
15e72f825c
commit
c2b1826410
5 changed files with 35 additions and 33 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -68,11 +68,11 @@ uint8_t ESP8266::join(const char* ssid, const char* password) {
|
|||
strcat(cmd, password);
|
||||
strcat(cmd, "\"");
|
||||
|
||||
if(!_mod->ATsendCommand(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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
bool res = _mod->ATsendCommand(cmd);
|
||||
delete[] cmd;
|
||||
if(!res) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
delete[] cmd;
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue