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) {
|
bool Module::ATsendCommand(const char* cmd) {
|
||||||
ATemptyBuffer();
|
ATemptyBuffer();
|
||||||
ModuleSerial->print(cmd);
|
ModuleSerial->print(cmd);
|
||||||
|
|
|
@ -23,7 +23,6 @@ class Module {
|
||||||
|
|
||||||
void ATemptyBuffer();
|
void ATemptyBuffer();
|
||||||
bool ATgetResponse();
|
bool ATgetResponse();
|
||||||
bool ATsendCommand(String& cmd);
|
|
||||||
bool ATsendCommand(const char* cmd);
|
bool ATsendCommand(const char* cmd);
|
||||||
bool ATsendData(uint8_t* data, uint32_t len);
|
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, password);
|
||||||
strcat(cmd, "\"");
|
strcat(cmd, "\"");
|
||||||
|
|
||||||
if(!_mod->ATsendCommand(cmd)) {
|
bool res = _mod->ATsendCommand(cmd);
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
delete[] cmd;
|
|
||||||
|
|
||||||
// disable multiple connection mode
|
// disable multiple connection mode
|
||||||
if(!_mod->ATsendCommand("AT+CIPMUX=0")) {
|
if(!_mod->ATsendCommand("AT+CIPMUX=0")) {
|
||||||
|
@ -392,13 +392,12 @@ uint8_t ESP8266::send(const char* data) {
|
||||||
strcat(cmd, lenStr);
|
strcat(cmd, lenStr);
|
||||||
|
|
||||||
// send data length in bytes
|
// send data length in bytes
|
||||||
if(!_mod->ATsendCommand(cmd)) {
|
bool res = _mod->ATsendCommand(cmd);
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] cmd;
|
|
||||||
|
|
||||||
// send data
|
// send data
|
||||||
if(!_mod->ATsendCommand(data)) {
|
if(!_mod->ATsendCommand(data)) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
|
@ -417,13 +416,12 @@ uint8_t ESP8266::send(uint8_t* data, uint32_t len) {
|
||||||
strcat(cmd, lenStr);
|
strcat(cmd, lenStr);
|
||||||
|
|
||||||
// send command and data length in bytes
|
// send command and data length in bytes
|
||||||
if(!_mod->ATsendCommand(cmd)) {
|
bool res = _mod->ATsendCommand(cmd);
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] cmd;
|
|
||||||
|
|
||||||
// send data
|
// send data
|
||||||
if(!_mod->ATsendData(data, len)) {
|
if(!_mod->ATsendData(data, len)) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
|
@ -472,12 +470,12 @@ uint8_t ESP8266::openTransportConnection(const char* host, const char* protocol,
|
||||||
strcat(cmd, tcpKeepAliveStr);
|
strcat(cmd, tcpKeepAliveStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_mod->ATsendCommand(cmd)) {
|
bool res = _mod->ATsendCommand(cmd);
|
||||||
delete[] cmd;
|
delete[] cmd;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] cmd;
|
|
||||||
return(ERR_NONE);
|
return(ERR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ uint8_t XBee::begin(long speed) {
|
||||||
return(ERR_NONE);
|
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
|
// enter command mode
|
||||||
DEBUG_PRINTLN_STR("Entering command mode ...");
|
DEBUG_PRINTLN_STR("Entering command mode ...");
|
||||||
if(!enterCmdMode()) {
|
if(!enterCmdMode()) {
|
||||||
|
@ -58,17 +58,23 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c
|
||||||
|
|
||||||
// set higher address bytes
|
// set higher address bytes
|
||||||
DEBUG_PRINTLN_STR("Setting address (high) ...");
|
DEBUG_PRINTLN_STR("Setting address (high) ...");
|
||||||
String addressHigh = "ATDH";
|
char* addressHigh = new char[strlen(destinationAddressHigh) + 4];
|
||||||
addressHigh += destinationAddressHigh;
|
strcpy(addressHigh, "ATDH");
|
||||||
if(!_mod->ATsendCommand(addressHigh)) {
|
strcat(addressHigh, destinationAddressHigh);
|
||||||
|
bool res = _mod->ATsendCommand(addressHigh);
|
||||||
|
delete[] addressHigh;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set lower address bytes
|
// set lower address bytes
|
||||||
DEBUG_PRINTLN_STR("Setting address (low) ...");
|
DEBUG_PRINTLN_STR("Setting address (low) ...");
|
||||||
String addressLow = "ATDL";
|
char* addressLow = new char[strlen(destinationAddressLow) + 4];
|
||||||
addressLow += destinationAddressLow;
|
strcpy(addressLow, "ATDL");
|
||||||
if(!_mod->ATsendCommand(addressLow)) {
|
strcat(addressLow, destinationAddressLow);
|
||||||
|
res = _mod->ATsendCommand(addressLow);
|
||||||
|
delete[] addressLow;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +87,7 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c
|
||||||
return(ERR_NONE);
|
return(ERR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t XBee::setPanId(const char panId[]) {
|
uint8_t XBee::setPanId(const char* panId) {
|
||||||
// enter command mode
|
// enter command mode
|
||||||
DEBUG_PRINTLN_STR("Entering command mode ...");
|
DEBUG_PRINTLN_STR("Entering command mode ...");
|
||||||
if(!enterCmdMode()) {
|
if(!enterCmdMode()) {
|
||||||
|
@ -90,9 +96,12 @@ uint8_t XBee::setPanId(const char panId[]) {
|
||||||
|
|
||||||
// set PAN ID
|
// set PAN ID
|
||||||
DEBUG_PRINTLN_STR("Setting PAN ID ...");
|
DEBUG_PRINTLN_STR("Setting PAN ID ...");
|
||||||
String panIdCmd = "ATID";
|
char* cmd = new char[strlen(panId) + 4];
|
||||||
panIdCmd += panId;
|
strcpy(cmd, "ATID");
|
||||||
if(!_mod->ATsendCommand(panIdCmd)) {
|
strcat(cmd, panId);
|
||||||
|
bool res = _mod->ATsendCommand(cmd);
|
||||||
|
delete[] cmd;
|
||||||
|
if(!res) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ class XBee: public ISerial {
|
||||||
|
|
||||||
uint8_t begin(long speed);
|
uint8_t begin(long speed);
|
||||||
|
|
||||||
uint8_t setDestinationAddress(const char destinationAddressHigh[], const char destinationAddressLow[]);
|
uint8_t setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow);
|
||||||
uint8_t setPanId(const char panId[]);
|
uint8_t setPanId(const char* panId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool enterCmdMode();
|
bool enterCmdMode();
|
||||||
|
|
Loading…
Add table
Reference in a new issue