Replaced all remaining internal Arduino Strings

pull/1/head
Jan Gromeš 2018-06-29 11:05:53 +02:00
rodzic 15e72f825c
commit c2b1826410
5 zmienionych plików z 35 dodań i 33 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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();