diff --git a/esp3d/src/core/commands.cpp b/esp3d/src/core/commands.cpp index 08684b3c..b485dd3c 100644 --- a/esp3d/src/core/commands.cpp +++ b/esp3d/src/core/commands.cpp @@ -36,14 +36,21 @@ Commands::~Commands() void Commands::process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_authenticate_type auth, ESP3DOutput * outputonly ) { if(is_esp_command(sbuf,len)) { - + size_t slen = len; + String tmpbuf = (const char*)sbuf; + if (tmpbuf.startsWith("echo: ")){ + tmpbuf.replace("echo: ", ""); + slen = tmpbuf.length(); + } + uint8_t cmd[4]; - cmd[0] = sbuf[4]; - cmd[1] = sbuf[5]; - cmd[2] = sbuf[6]; + cmd[0] = tmpbuf[4]; + cmd[1] = tmpbuf[5]; + cmd[2] = tmpbuf[6]; cmd[3] = 0x0; + //log_esp3d("Authentication = %d client %d", auth, output->client()); - execute_internal_command (String((const char *)cmd).toInt(), (len > 8)?(const char*)&sbuf[8]:"", auth, (outputonly == nullptr)?output:outputonly); + execute_internal_command (String((const char*)cmd).toInt(), (slen > 8)?(const char*)&tmpbuf[8]:"", auth, (outputonly == nullptr)?output:outputonly); } else { //Dispatch to all clients but current or to define output if ((output->client() == ESP_HTTP_CLIENT) && (outputonly == nullptr)) { @@ -73,6 +80,13 @@ bool Commands::is_esp_command(uint8_t * sbuf, size_t len) if ((char(sbuf[0]) == '[') && (char(sbuf[1]) == 'E') && (char(sbuf[2]) == 'S') && (char(sbuf[3]) == 'P') && (char(sbuf[7]) == ']')) { return true; } + if((char(sbuf[0]) == 'e') && (char(sbuf[1]) == 'c') && (char(sbuf[2]) == 'h') && (char(sbuf[3]) == 'o') && (char(sbuf[4]) == ':') && (char(sbuf[5]) == ' ') && (char(sbuf[6]) == '[') && (char(sbuf[7]) == 'E')) { + if (len >= 14){ + if ((char(sbuf[8]) == 'S') && (char(sbuf[9]) == 'P') && (char(sbuf[13]) == ']')){ + return true; + } + } + } return false; } diff --git a/esp3d/src/core/settings_esp3d.cpp b/esp3d/src/core/settings_esp3d.cpp index 369ad12d..db882ff9 100644 --- a/esp3d/src/core/settings_esp3d.cpp +++ b/esp3d/src/core/settings_esp3d.cpp @@ -842,7 +842,7 @@ bool Settings_ESP3D::write_string (int pos, const char * byte_buffer) String p = "P_" + String(pos); uint8_t r = prefs.putString(p.c_str(), byte_buffer); prefs.end(); - if (r == 0) { + if (r != size_buffer) { log_esp3d("Error commit %s", p.c_str()); return false; } diff --git a/esp3d/src/modules/filesystem/esp_filesystem.cpp b/esp3d/src/modules/filesystem/esp_filesystem.cpp index fb20523c..cebf4c14 100644 --- a/esp3d/src/modules/filesystem/esp_filesystem.cpp +++ b/esp3d/src/modules/filesystem/esp_filesystem.cpp @@ -54,17 +54,17 @@ ESP_FileSystem::~ESP_FileSystem() } //helper to format size to readable string -String & ESP_FileSystem::formatBytes (uint32_t bytes) +String & ESP_FileSystem::formatBytes (uint64_t bytes) { static String res; if (bytes < 1024) { - res = String (bytes) + " B"; + res = String ((uint16_t)bytes) + " B"; } else if (bytes < (1024 * 1024) ) { - res = String (bytes / 1024.0) + " KB"; + res = String ((float)(bytes / 1024.0),2) + " KB"; } else if (bytes < (1024 * 1024 * 1024) ) { - res = String (bytes / 1024.0 / 1024.0) + " MB"; + res = String ((float)(bytes / 1024.0 / 1024.0),2) + " MB"; } else { - res = String (bytes / 1024.0 / 1024.0 / 1024.0) + " GB"; + res = String ((float)(bytes / 1024.0 / 1024.0 / 1024.0),2) + " GB"; } return res; } diff --git a/esp3d/src/modules/filesystem/esp_filesystem.h b/esp3d/src/modules/filesystem/esp_filesystem.h index 59fb1322..dca6c265 100644 --- a/esp3d/src/modules/filesystem/esp_filesystem.h +++ b/esp3d/src/modules/filesystem/esp_filesystem.h @@ -69,7 +69,7 @@ private: class ESP_FileSystem { public: - static String & formatBytes (uint32_t bytes); + static String & formatBytes (uint64_t bytes); ESP_FileSystem(); ~ESP_FileSystem(); static bool begin();