From 67c9340f0f7e909c82711856cab147667425b9e4 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 4 Nov 2022 16:42:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BD=D1=8F=D0=B5=D0=BC=20unsigned?= =?UTF-8?q?=20long=20=D0=BD=D0=B0=20long=20=D0=B4=D0=BB=D1=8F=20=5Finterva?= =?UTF-8?q?l,=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D1=86=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Global.h | 2 +- include/utils/JsonUtils.h | 2 +- src/Global.cpp | 2 +- src/modules/exec/ButtonIn/ButtonIn.cpp | 2 +- src/modules/virtual/Loging/Loging.cpp | 2 +- .../virtual/LogingDaily/LogingDaily.cpp | 2 +- src/utils/JsonUtils.cpp | 60 +++++++++++-------- src/utils/StringUtils.cpp | 2 +- 8 files changed, 41 insertions(+), 33 deletions(-) diff --git a/include/Global.h b/include/Global.h index a8ae38d9..fb0e535f 100644 --- a/include/Global.h +++ b/include/Global.h @@ -139,7 +139,7 @@ extern Time_t _time_local; extern Time_t _time_utc; extern bool _time_isTrust; -extern unsigned long loopPeriod; +//extern unsigned long loopPeriod; // extern DynamicJsonDocument settingsFlashJsonDoc; // extern DynamicJsonDocument paramsFlashJsonDoc; diff --git a/include/utils/JsonUtils.h b/include/utils/JsonUtils.h index 8418163f..a9810dc2 100644 --- a/include/utils/JsonUtils.h +++ b/include/utils/JsonUtils.h @@ -10,7 +10,7 @@ extern String jsonWriteInt(String& json, String name, int value, bool e = true); extern String jsonWriteFloat(String& json, String name, float value, bool e = true); extern String jsonWriteBool(String& json, String name, boolean value, bool e = true); -extern bool jsonRead(const String& json, String key, unsigned long& value, bool e = true); +extern bool jsonRead(const String& json, String key, long& value, bool e = true); extern bool jsonRead(const String& json, String key, float& value, bool e = true); extern bool jsonRead(const String& json, String key, String& value, bool e = true); extern bool jsonRead(const String& json, String key, bool& value, bool e = true); diff --git a/src/Global.cpp b/src/Global.cpp index 2be45040..309e379a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -70,7 +70,7 @@ String mqttRootDevice = ""; unsigned long unixTime = 0; unsigned long unixTimeShort = 0; -unsigned long loopPeriod; +//unsigned long loopPeriod; bool isTimeSynch = false; Time_t _time_local; diff --git a/src/modules/exec/ButtonIn/ButtonIn.cpp b/src/modules/exec/ButtonIn/ButtonIn.cpp index 18e8a87f..204fcbd4 100644 --- a/src/modules/exec/ButtonIn/ButtonIn.cpp +++ b/src/modules/exec/ButtonIn/ButtonIn.cpp @@ -12,7 +12,7 @@ class ButtonIn : public IoTItem { String _pinMode; int _lastButtonState = LOW; unsigned long _lastDebounceTime = 0; - unsigned long _debounceDelay = 50; + long _debounceDelay = 50; int _buttonState; int _reading; diff --git a/src/modules/virtual/Loging/Loging.cpp b/src/modules/virtual/Loging/Loging.cpp index a189d046..9fb21aec 100644 --- a/src/modules/virtual/Loging/Loging.cpp +++ b/src/modules/virtual/Loging/Loging.cpp @@ -22,7 +22,7 @@ class Loging : public IoTItem { String prevDate = ""; bool firstTimeDate = true; - unsigned long interval; + long interval; public: Loging(String parameters) : IoTItem(parameters) { diff --git a/src/modules/virtual/LogingDaily/LogingDaily.cpp b/src/modules/virtual/LogingDaily/LogingDaily.cpp index 05981d39..50ed724f 100644 --- a/src/modules/virtual/LogingDaily/LogingDaily.cpp +++ b/src/modules/virtual/LogingDaily/LogingDaily.cpp @@ -21,7 +21,7 @@ class LogingDaily : public IoTItem { String prevDate = ""; bool firstTimeDate = true; - unsigned long interval; + long interval; public: LogingDaily(String parameters) : IoTItem(parameters) { diff --git a/src/utils/JsonUtils.cpp b/src/utils/JsonUtils.cpp index ab362ac3..f04f910f 100644 --- a/src/utils/JsonUtils.cpp +++ b/src/utils/JsonUtils.cpp @@ -11,21 +11,23 @@ void jsonWriteStrDoc(DynamicJsonDocument& doc, String name, String value) { } // new============================================================================== -bool jsonRead(const String& json, String key, unsigned long& value, bool e) { +bool jsonRead(const String& json, String key, long& value, bool e) { DynamicJsonDocument doc(JSON_BUFFER_SIZE); DeserializationError error = deserializeJson(doc, json); if (error) { - SerialPrint("EE", F("jsonRead"), error.f_str()); - jsonErrorDetected(); + if (e) { + SerialPrint("E", F("jsonRead"), error.f_str()); + jsonErrorDetected(); + } return false; } else if (!doc.containsKey(key)) { if (e) { - SerialPrint("EE", F("jsonRead"), key + " missing"); + SerialPrint("E", F("jsonRead"), key + " missing"); jsonErrorDetected(); } return false; } - value = doc[key].as(); + value = doc[key].as(); return true; } @@ -33,12 +35,14 @@ bool jsonRead(const String& json, String key, float& value, bool e) { DynamicJsonDocument doc(JSON_BUFFER_SIZE); DeserializationError error = deserializeJson(doc, json); if (error) { - SerialPrint("EE", F("jsonRead"), error.f_str()); - jsonErrorDetected(); + if (e) { + SerialPrint("E", F("jsonRead"), error.f_str()); + jsonErrorDetected(); + } return false; } else if (!doc.containsKey(key)) { if (e) { - SerialPrint("EE", F("jsonRead"), key + " missing"); + SerialPrint("E", F("jsonRead"), key + " missing"); jsonErrorDetected(); } return false; @@ -51,12 +55,14 @@ bool jsonRead(const String& json, String key, String& value, bool e) { DynamicJsonDocument doc(JSON_BUFFER_SIZE); DeserializationError error = deserializeJson(doc, json); if (error) { - SerialPrint("EE", F("jsonRead"), error.f_str()); - jsonErrorDetected(); + if (e) { + SerialPrint("E", F("jsonRead"), error.f_str()); + jsonErrorDetected(); + } return false; } else if (!doc.containsKey(key)) { if (e) { - SerialPrint("EE", F("jsonRead"), key + " missing"); + SerialPrint("E", F("jsonRead"), key + " missing"); jsonErrorDetected(); } return false; @@ -76,12 +82,14 @@ bool jsonRead(const String& json, String key, int& value, bool e) { DynamicJsonDocument doc(JSON_BUFFER_SIZE); DeserializationError error = deserializeJson(doc, json); if (error) { - SerialPrint("EE", F("jsonRead"), error.f_str()); - jsonErrorDetected(); + if (e) { + SerialPrint("E", F("jsonRead"), error.f_str()); + jsonErrorDetected(); + } return false; } else if (!doc.containsKey(key)) { if (e) { - SerialPrint("EE", F("jsonRead"), key + " missing"); + SerialPrint("E", F("jsonRead"), key + " missing"); jsonErrorDetected(); } return false; @@ -97,7 +105,7 @@ bool jsonWriteStr_(String& json, const String& key, const String& value, bool e) DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } ret = false; @@ -114,7 +122,7 @@ bool jsonWriteBool_(String& json, const String& key, bool value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } ret = false; @@ -131,7 +139,7 @@ bool jsonWriteInt_(String& json, const String& key, int value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } ret = false; @@ -148,7 +156,7 @@ bool jsonWriteFloat_(String& json, const String &key, float value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } ret = false; @@ -177,7 +185,7 @@ bool jsonMergeObjects(String& json1, String& json2, bool e) { jsonMergeDocs(doc1.as(), doc2.as()); if (error1 || error2) { if (e) { - SerialPrint("EE", F("json"), "jsonMergeObjects error"); + SerialPrint("E", F("json"), "jsonMergeObjects error"); jsonErrorDetected(); } ret = false; @@ -199,7 +207,7 @@ String jsonReadStr(const String& json, String name, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonRead"), error.f_str()); + SerialPrint("E", F("jsonRead"), error.f_str()); jsonErrorDetected(); } } @@ -211,7 +219,7 @@ boolean jsonReadBool(const String& json, String name, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonRead"), error.f_str()); + SerialPrint("E", F("jsonRead"), error.f_str()); jsonErrorDetected(); } } @@ -223,7 +231,7 @@ int jsonReadInt(const String& json, String name, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonRead"), error.f_str()); + SerialPrint("E", F("jsonRead"), error.f_str()); jsonErrorDetected(); } } @@ -236,7 +244,7 @@ String jsonWriteStr(String& json, String name, String value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } } @@ -251,7 +259,7 @@ String jsonWriteBool(String& json, String name, boolean value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } } @@ -266,7 +274,7 @@ String jsonWriteInt(String& json, String name, int value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } } @@ -281,7 +289,7 @@ String jsonWriteFloat(String& json, String name, float value, bool e) { DeserializationError error = deserializeJson(doc, json); if (error) { if (e) { - SerialPrint("EE", F("jsonWrite"), error.f_str()); + SerialPrint("E", F("jsonWrite"), error.f_str()); jsonErrorDetected(); } } diff --git a/src/utils/StringUtils.cpp b/src/utils/StringUtils.cpp index a2a425d4..4234a68f 100644 --- a/src/utils/StringUtils.cpp +++ b/src/utils/StringUtils.cpp @@ -79,7 +79,7 @@ void hex2string(byte array[], unsigned int len, char buffer[]) { buffer[len * 2] = '\0'; } -inline unsigned char ChartoHex(char ch) { +unsigned char ChartoHex(char ch) { return ((ch >= 'A') ? (ch - 'A' + 0xA) : (ch - '0')) & 0x0F; }