From 7bee09b838946df1490c4dbb9d5c93ef8f1eaa9d Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Fri, 2 Feb 2024 11:03:55 +0800 Subject: [PATCH] Sync with ESP3D latest code (227) --- src/core/commands/ESP170.cpp | 58 ++++++++++--------- src/core/commands/ESP999.cpp | 4 +- src/core/esp3d_commands.cpp | 4 +- src/core/esp3d_settings.cpp | 7 ++- src/core/esp3d_string.cpp | 10 +++- src/core/esp3d_string.h | 1 + src/include/esp3d_version.h | 2 +- src/modules/bluetooth/BT_service.cpp | 3 +- .../notifications/notifications_service.cpp | 2 +- src/modules/sensor/bmx280.cpp | 4 +- src/modules/serial/serial_service.cpp | 6 +- src/modules/telnet/telnet_server.cpp | 3 +- src/modules/websocket/websocket_server.cpp | 3 +- 13 files changed, 63 insertions(+), 44 deletions(-) diff --git a/src/core/commands/ESP170.cpp b/src/core/commands/ESP170.cpp index afba208..29bca10 100644 --- a/src/core/commands/ESP170.cpp +++ b/src/core/commands/ESP170.cpp @@ -33,7 +33,7 @@ // /awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc // /raw_gma/lenc/special_effect/wb_mode/ae_level void ESP3DCommands::ESP170(int cmd_params_pos, ESP3DMessage* msg) { - const char* camcmd = [] = { + const char* camcmd[] = { "framesize", "quality", "contrast", @@ -63,13 +63,17 @@ void ESP3DCommands::ESP170(int cmd_params_pos, ESP3DMessage* msg) { "light", #endif // CAM_LED_PIN }; + bool hasError = false; + String ok_msg; + String error_msg; ESP3DClientType target = msg->origin; ESP3DRequest requestId = msg->request_id; msg->target = target; msg->origin = ESP3DClientType::command; bool json = hasTag(msg, cmd_params_pos, "json"); String tmpstr; -#if AUTHENTICATION_FEATURE + +#ifdef AUTHENTICATION_FEATURE if (msg->authentication_level == ESP3DAuthenticationLevel::guest) { dispatchAuthenticationError(msg, COMMAND_ID, json); return; @@ -102,146 +106,146 @@ void ESP3DCommands::ESP170(int cmd_params_pos, ESP3DMessage* msg) { // now send all settings one by one // framesize if (!dispatchIdValue(json, "framesize", - String(status.framesize).c_str(), target, + String(s->status.framesize).c_str(), target, requestId, true)) { return; } // quality - if (!dispatchIdValue(json, "quality", String(status.quality).c_str(), + if (!dispatchIdValue(json, "quality", String(s->status.quality).c_str(), target, requestId)) { return; } // brightness if (!dispatchIdValue(json, "brightness", - String(status.brightness).c_str(), target, + String(s->status.brightness).c_str(), target, requestId)) { return; } // contrast - if (!dispatchIdValue(json, "contrast", String(status.contrast).c_str(), + if (!dispatchIdValue(json, "contrast", String(s->status.contrast).c_str(), target, requestId)) { return; } // saturation if (!dispatchIdValue(json, "saturation", - String(status.saturation).c_str(), target, + String(s->status.saturation).c_str(), target, requestId)) { return; // sharpness if (!dispatchIdValue(json, "sharpness", - String(status.sharpness).c_str(), target, + String(s->status.sharpness).c_str(), target, requestId)) { return; } // special_effect if (!dispatchIdValue(json, "special_effect", - String(status.special_effect).c_str(), target, + String(s->status.special_effect).c_str(), target, requestId)) { return; } // wb_mode - if (!dispatchIdValue(json, "wb_mode", String(status.wb_mode).c_str(), + if (!dispatchIdValue(json, "wb_mode", String(s->status.wb_mode).c_str(), target, requestId)) { return; } // awb - if (!dispatchIdValue(json, "awb", String(status.awb).c_str(), target, + if (!dispatchIdValue(json, "awb", String(s->status.awb).c_str(), target, requestId)) { return; } // awb_gain if (!dispatchIdValue(json, "awb_gain", - String(status.awb_gain).c_str(), target, + String(s->status.awb_gain).c_str(), target, requestId)) { return; } // aec - if (!dispatchIdValue(json, "aec", String(status.aec).c_str(), target, + if (!dispatchIdValue(json, "aec", String(s->status.aec).c_str(), target, requestId)) { return; } // aec2 - if (!dispatchIdValue(json, "aec2", String(status.aec2).c_str(), + if (!dispatchIdValue(json, "aec2", String(s->status.aec2).c_str(), target, requestId)) { return; } // ae_level if (!dispatchIdValue(json, "ae_level", - String(status.ae_level).c_str(), target, + String(s->status.ae_level).c_str(), target, requestId)) { return; } // aec_value if (!dispatchIdValue(json, "aec_value", - String(status.aec_value).c_str(), target, + String(s->status.aec_value).c_str(), target, requestId)) { return; } // agc - if (!dispatchIdValue(json, "agc", String(status.agc).c_str(), target, + if (!dispatchIdValue(json, "agc", String(s->status.agc).c_str(), target, requestId)) { return; } // agc_gain if (!dispatchIdValue(json, "agc_gain", - String(status.agc_gain).c_str(), target, + String(s->status.agc_gain).c_str(), target, requestId)) { return; } // gainceiling if (!dispatchIdValue(json, "gainceiling", - String(status.gainceiling).c_str(), target, + String(s->status.gainceiling).c_str(), target, requestId)) { return; } // bpc - if (!dispatchIdValue(json, "bpc", String(status.bpc).c_str(), target, + if (!dispatchIdValue(json, "bpc", String(s->status.bpc).c_str(), target, requestId)) { return; } // wpc - if (!dispatchIdValue(json, "wpc", String(status.wpc).c_str(), target, + if (!dispatchIdValue(json, "wpc", String(s->status.wpc).c_str(), target, requestId)) { return; } // raw_gma - if (!dispatchIdValue(json, "raw_gma", String(status.raw_gma).c_str(), + if (!dispatchIdValue(json, "raw_gma", String(s->status.raw_gma).c_str(), target, requestId)) { return; } // lenc - if (!dispatchIdValue(json, "lenc", String(status.lenc).c_str(), + if (!dispatchIdValue(json, "lenc", String(s->status.lenc).c_str(), target, requestId)) { return; } // vflip - if (!dispatchIdValue(json, "vflip", String(status.vflip).c_str(), + if (!dispatchIdValue(json, "vflip", String(s->status.vflip).c_str(), target, requestId)) { return; } // hmirror - if (!dispatchIdValue(json, "hmirror", String(status.hmirror).c_str(), + if (!dispatchIdValue(json, "hmirror", String(s->status.hmirror).c_str(), target, requestId)) { return; } // dcw - if (!dispatchIdValue(json, "dcw", String(status.dcw).c_str(), target, + if (!dispatchIdValue(json, "dcw", String(s->status.dcw).c_str(), target, requestId)) { return; } // colorbar if (!dispatchIdValue(json, "colorbar", - String(status.colorbar).c_str(), target, + String(s->status.colorbar).c_str(), target, requestId)) { return; } diff --git a/src/core/commands/ESP999.cpp b/src/core/commands/ESP999.cpp index 59e5409..c34e076 100644 --- a/src/core/commands/ESP999.cpp +++ b/src/core/commands/ESP999.cpp @@ -51,7 +51,7 @@ void ESP3DCommands::ESP999(int cmd_params_pos, ESP3DMessage* msg) { tmpstr = get_clean_param(msg, cmd_params_pos); if (tmpstr.length() == 0) { hasError = true; - error_msg = "Missing parameter" + error_msg = "Missing parameter"; } else { if (quietboot) { if (esp_efuse_set_rom_log_scheme(ESP_EFUSE_ROM_LOG_ON_GPIO_HIGH) != @@ -70,4 +70,4 @@ void ESP3DCommands::ESP999(int cmd_params_pos, ESP3DMessage* msg) { } #endif // defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || - // CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3) \ No newline at end of file + // CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3) diff --git a/src/core/esp3d_commands.cpp b/src/core/esp3d_commands.cpp index bf03222..b9f6333 100644 --- a/src/core/esp3d_commands.cpp +++ b/src/core/esp3d_commands.cpp @@ -609,6 +609,7 @@ void ESP3DCommands::execute_internal_command(int cmd, int cmd_params_pos, ESP215(cmd_params_pos, msg); break; #endif // DISPLAY_TOUCH_DRIVER +#endif // DISPLAY_DEVICE #ifdef BUZZER_DEVICE // Play sound //[ESP250]F= D= [pwd=] @@ -616,7 +617,6 @@ void ESP3DCommands::execute_internal_command(int cmd, int cmd_params_pos, ESP250(cmd_params_pos, msg); break; #endif // BUZZER_DEVICE -#endif // DISPLAY_DEVICE // Show pins //[ESP220][pwd=] case 220: @@ -880,7 +880,7 @@ bool ESP3DCommands::dispatchSetting(bool json, const char *filter, break; default: // String if (index == ESP_STA_PASSWORD || index == ESP_AP_PASSWORD || -#if ESP3D_NOTIFICATIONS_FEATURE +#if defined (ESP3D_NOTIFICATIONS_FEATURE) index == ESP_NOTIFICATION_TOKEN1 || index == ESP_NOTIFICATION_TOKEN2 || #endif // ESP3D_NOTIFICATIONS_FEATURE diff --git a/src/core/esp3d_settings.cpp b/src/core/esp3d_settings.cpp index 09691b7..555fe2d 100644 --- a/src/core/esp3d_settings.cpp +++ b/src/core/esp3d_settings.cpp @@ -26,6 +26,7 @@ #if defined(ESP_SAVE_SETTINGS) #include "esp3d_message.h" #include "esp3d_settings.h" +#include "esp3d_string.h" #if ESP_SAVE_SETTINGS == SETTINGS_IN_EEPROM #include @@ -386,7 +387,7 @@ bool ESP3DSettings::writeByte(int pos, const uint8_t value) { bool ESP3DSettings::is_string(const char *s, uint len) { for (uint p = 0; p < len; p++) { - if (!isPrintable(char(s[p]))) { + if (!esp3d_string::isPrintableChar(char(s[p]))) { return false; } } @@ -431,7 +432,7 @@ const char *ESP3DSettings::readString(int pos, bool *haserror) { // read until max size is reached or \0 is found while (i < size_max && b != 0) { b = EEPROM.read(pos + i); - byte_buffer[i] = isPrintable(char(b)) ? b : 0; + byte_buffer[i] = esp3d_string::isPrintableChar(char(b)) ? b : 0; i++; } @@ -778,7 +779,7 @@ bool ESP3DSettings::isValidStringSetting(const char *value, } // only printable char allowed for (size_t i = 0; i < strlen(value); i++) { - if (!isPrintable(value[i])) { + if (!esp3d_string::isPrintableChar(value[i])) { return false; } } diff --git a/src/core/esp3d_string.cpp b/src/core/esp3d_string.cpp index 8f8e888..ec6da12 100644 --- a/src/core/esp3d_string.cpp +++ b/src/core/esp3d_string.cpp @@ -178,4 +178,12 @@ const char* esp3d_string::formatBytes(uint64_t bytes) { res = String((float)(bytes / 1024.0 / 1024.0 / 1024.0), 2) + " GB"; } return res.c_str(); -} \ No newline at end of file +} + +bool esp3d_string::isPrintableChar(char ch){ + int c = static_cast(ch); +if (c==9 || (c >= 32 && c <= 126) || c>=128) { + return true; + } + return false; +} diff --git a/src/core/esp3d_string.h b/src/core/esp3d_string.h index 2426adf..f94668d 100644 --- a/src/core/esp3d_string.h +++ b/src/core/esp3d_string.h @@ -27,6 +27,7 @@ const char* generateUUID(const char* seed); const char* getContentType(const char* filename); const char* encodeString(const char* s); const char* formatBytes(uint64_t bytes); +bool isPrintableChar(char c); } // namespace esp3d_string #endif //_ESP3D_STRING_H diff --git a/src/include/esp3d_version.h b/src/include/esp3d_version.h index b7e485f..aeb0261 100644 --- a/src/include/esp3d_version.h +++ b/src/include/esp3d_version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H // version and sources location -#define FW_VERSION "3.0.0.a226" +#define FW_VERSION "3.0.0.a227" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/src/modules/bluetooth/BT_service.cpp b/src/modules/bluetooth/BT_service.cpp index 171844b..a7b0796 100644 --- a/src/modules/bluetooth/BT_service.cpp +++ b/src/modules/bluetooth/BT_service.cpp @@ -25,6 +25,7 @@ #ifdef BLUETOOTH_FEATURE #include "../../core/esp3d_commands.h" #include "../../core/esp3d_settings.h" +#include "../../esp3d_string.h" #include "../network/netconfig.h" #include "BT_service.h" #include "BluetoothSerial.h" @@ -215,7 +216,7 @@ void BTService::push2buffer(uint8_t *sbuf, size_t len) { _buffer_size++; } flushbuffer(); - } else if (isPrintable(char(sbuf[i]))) { + } else if (esp3d_string::isPrintableChar(char(sbuf[i]))) { if (_buffer_size < ESP3D_BT_BUFFER_SIZE) { _buffer[_buffer_size] = sbuf[i]; _buffer_size++; diff --git a/src/modules/notifications/notifications_service.cpp b/src/modules/notifications/notifications_service.cpp index 242da43..293da0b 100644 --- a/src/modules/notifications/notifications_service.cpp +++ b/src/modules/notifications/notifications_service.cpp @@ -158,7 +158,7 @@ NotificationsService::NotificationsService() { _started = false; _notificationType = 0; _token1 = ""; - _token1 = ""; + _token2 = ""; _settings = ""; } NotificationsService::~NotificationsService() { end(); } diff --git a/src/modules/sensor/bmx280.cpp b/src/modules/sensor/bmx280.cpp index 01a0ac5..259764f 100644 --- a/src/modules/sensor/bmx280.cpp +++ b/src/modules/sensor/bmx280.cpp @@ -117,7 +117,7 @@ uint8_t BMX280SensorDevice::GetModel(uint8_t i) { const char *BMX280SensorDevice::GetCurrentModelString() { uint8_t sensortype = ESP3DSettings::readByte(ESP_SENSOR_TYPE); for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) { - if ((sensortype == SENSOR_TYPE[i]) { + if (sensortype == SENSOR_ID[i]) { return SENSOR_NAME[i]; } } @@ -173,7 +173,7 @@ const char *BMX280SensorDevice::GetData() { } } else { s = "DISCONNECTED"; - log_esp3_ed("No valid data"); + esp3d_log_e("No valid data"); } } } else { diff --git a/src/modules/serial/serial_service.cpp b/src/modules/serial/serial_service.cpp index eef6c51..049ce69 100644 --- a/src/modules/serial/serial_service.cpp +++ b/src/modules/serial/serial_service.cpp @@ -23,6 +23,8 @@ COMMUNICATION_PROTOCOL == RAW_SERIAL || defined(ESP_SERIAL_BRIDGE_OUTPUT) #include "../../core/esp3d_commands.h" #include "../../core/esp3d_settings.h" +#include "../../core/esp3d_string.h" + #include "serial_service.h" #if COMMUNICATION_PROTOCOL == MKS_SERIAL @@ -36,7 +38,7 @@ HardwareSerial *Serials[MAX_SERIAL] = {&Serial, &Serial1}; #if defined(ARDUINO_ARCH_ESP32) -#if defined(CONFIG_IDF_TARGET_ESP32C3) +#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) #define MAX_SERIAL 2 HardwareSerial *Serials[MAX_SERIAL] = {&Serial, &Serial1}; #else @@ -406,7 +408,7 @@ void ESP3DSerialService::push2buffer(uint8_t *sbuf, size_t len) { _buffer_size++; } flushbuffer(); - } else if (isPrintable(char(sbuf[i]))) { + } else if (esp3d_string::isPrintableChar(char(sbuf[i]))) { if (_buffer_size < ESP3D_SERIAL_BUFFER_SIZE) { _buffer[_buffer_size] = sbuf[i]; _buffer_size++; diff --git a/src/modules/telnet/telnet_server.cpp b/src/modules/telnet/telnet_server.cpp index 60536ea..73a8863 100644 --- a/src/modules/telnet/telnet_server.cpp +++ b/src/modules/telnet/telnet_server.cpp @@ -28,6 +28,7 @@ #include "../../core/esp3d_commands.h" #include "../../core/esp3d_message.h" #include "../../core/esp3d_settings.h" +#include "../../core/esp3d_string.h" #include "../../include/esp3d_version.h" #include "telnet_server.h" @@ -245,7 +246,7 @@ void Telnet_Server::push2buffer(uint8_t *sbuf, size_t len) { _buffer_size++; } flushbuffer(); - } else if (isPrintable(char(sbuf[i]))) { + } else if (esp3d_string::isPrintableChar(char(sbuf[i]))) { if (_buffer_size < ESP3D_TELNET_BUFFER_SIZE) { _buffer[_buffer_size] = sbuf[i]; _buffer_size++; diff --git a/src/modules/websocket/websocket_server.cpp b/src/modules/websocket/websocket_server.cpp index 55dbc2e..591bc0e 100644 --- a/src/modules/websocket/websocket_server.cpp +++ b/src/modules/websocket/websocket_server.cpp @@ -28,6 +28,7 @@ #include "../../core/esp3d_commands.h" #include "../../core/esp3d_message.h" #include "../../core/esp3d_settings.h" +#include "../../core/esp3d_string.h" #include "../authentication/authentication_service.h" #include "websocket_server.h" @@ -288,7 +289,7 @@ void WebSocket_Server::push2RXbuffer(uint8_t *sbuf, size_t len) { _RXbufferSize++; } flushRXbuffer(); - } else if (isPrintable(char(sbuf[i]))) { + } else if (esp3d_string::isPrintableChar(char(sbuf[i]))) { if (_RXbufferSize < RXBUFFERSIZE) { _RXbuffer[_RXbufferSize] = sbuf[i]; _RXbufferSize++;