diff --git a/CmdMessenger.cpp b/CmdMessenger.cpp index 8c3a454..71f843b 100644 --- a/CmdMessenger.cpp +++ b/CmdMessenger.cpp @@ -464,6 +464,7 @@ char *CmdMessenger::readStringArg() { if (next()) { dumped = true; ArgOk = true; + unescape(current); return current; } ArgOk = false; @@ -478,6 +479,7 @@ void CmdMessenger::copyStringArg(char *string, uint8_t size) { if (next()) { dumped = true; ArgOk = true; + unescape(current); strlcpy(string, current, size); } else { ArgOk = false; @@ -490,6 +492,7 @@ void CmdMessenger::copyStringArg(char *string, uint8_t size) { */ uint8_t CmdMessenger::compareStringArg(char *string) { if (next()) { + unescape(current); if (strcmp(string, current) == 0) { dumped = true; ArgOk = true; @@ -544,7 +547,8 @@ char *CmdMessenger::split_r(char *str, const char delim, char **nextp) { // Set start of return pointer to this position ret = str; // Find next delimiter - str += findNext(str, delim); + LastArgLength = findNext(str, delim); + str += LastArgLength; // and exchange this for a a \0 char. This will terminate the char if (*str) { *str++ = '\0'; @@ -596,18 +600,18 @@ void CmdMessenger::printEsc(char str) { void CmdMessenger::printSci(double f, unsigned int digits) { // handle sign if (f < 0.0) { - Serial.print('-'); + comms->print('-'); f = -f; } // handle infinite values if (isinf(f)) { - Serial.print("INF"); + comms->print("INF"); return; } // handle Not a Number if (isnan(f)) { - Serial.print("NaN"); + comms->print("NaN"); return; } diff --git a/CmdMessenger.h b/CmdMessenger.h index 082b44c..5217b39 100644 --- a/CmdMessenger.h +++ b/CmdMessenger.h @@ -63,6 +63,7 @@ class CmdMessenger { uint8_t bufferIndex; // Index where to write data in buffer uint8_t bufferLength; // Is set to MESSENGERBUFFERSIZE uint8_t bufferLastIndex; // The last index of the buffer + uint8_t LastArgLength; // The length of the last received argument char ArglastChar; // Bookkeeping of argument escape char char CmdlastChar; // Bookkeeping of command escape char bool pauseProcessing; // pauses processing of new commands, during sending @@ -134,7 +135,10 @@ class CmdMessenger { unescape(str); byte *bytePointer = (byte *) (const void *) &value; for (unsigned int i = 0; i < sizeof(value); i++) { - *bytePointer = str[i]; + *bytePointer = 0; + if (i < LastArgLength) { + *bytePointer = str[i]; + } bytePointer++; } return value; @@ -308,8 +312,10 @@ class CmdMessenger { template T readBinArg() { if (next()) { dumped = true; + ArgOk = true; return readBin(current); } else { + ArgOk = false; return empty(); } }