mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
глобальное изменение системы обновления прошивки
This commit is contained in:
@@ -2,34 +2,26 @@
|
||||
#include "utils/FileUtils.h"
|
||||
|
||||
// new================================================================================
|
||||
String jsonReadStrDoc(DynamicJsonDocument &doc, String name)
|
||||
{
|
||||
String jsonReadStrDoc(DynamicJsonDocument &doc, String name) {
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
void jsonWriteStrDoc(DynamicJsonDocument &doc, String name, String value)
|
||||
{
|
||||
void jsonWriteStrDoc(DynamicJsonDocument &doc, String name, String value) {
|
||||
doc[name] = value;
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonRead(const String &json, String key, 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)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!doc.containsKey(key))
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
} else if (!doc.containsKey(key)) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -39,23 +31,17 @@ bool jsonRead(const String &json, String key, long &value, bool e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jsonRead(const String &json, String key, float &value, bool e)
|
||||
{
|
||||
bool jsonRead(const String &json, String key, float &value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!doc.containsKey(key))
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
} else if (!doc.containsKey(key)) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -65,23 +51,17 @@ bool jsonRead(const String &json, String key, float &value, bool e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jsonRead(const String &json, String key, String &value, bool e)
|
||||
{
|
||||
bool jsonRead(const String &json, String key, String &value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!doc.containsKey(key))
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
} else if (!doc.containsKey(key)) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -91,31 +71,24 @@ bool jsonRead(const String &json, String key, String &value, bool e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jsonRead(const String &json, String key, bool &value, bool e)
|
||||
{
|
||||
bool jsonRead(const String &json, String key, bool &value, bool e) {
|
||||
int lvalue = value;
|
||||
bool ret = jsonRead(json, key, lvalue, e);
|
||||
value = lvalue;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonRead(const String &json, String key, int &value, bool e)
|
||||
{
|
||||
bool jsonRead(const String &json, String key, int &value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!doc.containsKey(key))
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
} else if (!doc.containsKey(key)) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -125,37 +98,28 @@ bool jsonRead(const String &json, String key, int &value, bool e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jsonReadArray(const String &json, String key, std::vector<String> &jArray, bool e)
|
||||
{
|
||||
bool jsonReadArray(const String &json, String key, std::vector<String> &jArray, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonReadArray"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!doc.containsKey(key))
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
} else if (!doc.containsKey(key)) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonReadArray"), key + " missing in " + json);
|
||||
jsonErrorDetected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// SerialPrint("E", F("jsonReadArray"), key + " doc " + doc[key].as<String>());
|
||||
if (doc[key].is<JsonArray>())
|
||||
{
|
||||
if (doc[key].is<JsonArray>()) {
|
||||
for (int8_t i = 0; i < doc[key].size(); i++)
|
||||
jArray.push_back(doc[key][i].as<String>());
|
||||
// SerialPrint("E", F("jsonReadArray"), "isArray"+key + " doc " + doc[key].as<String>());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
jArray.push_back(doc[key].as<String>());
|
||||
// DynamicJsonDocument docArr(JSON_BUFFER_SIZE/5);
|
||||
// jArray = doc[key].as<JsonArray>();
|
||||
@@ -169,15 +133,12 @@ bool jsonReadArray(const String &json, String key, std::vector<String> &jArray,
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonWriteStr_(String &json, const String &key, const String &value, bool e)
|
||||
{
|
||||
bool jsonWriteStr_(String &json, const String &key, const String &value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -189,15 +150,12 @@ bool jsonWriteStr_(String &json, const String &key, const String &value, bool e)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteBool_(String &json, const String &key, bool value, bool e)
|
||||
{
|
||||
bool jsonWriteBool_(String &json, const String &key, bool value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -209,15 +167,12 @@ bool jsonWriteBool_(String &json, const String &key, bool value, bool e)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteInt_(String &json, const String &key, int value, bool e)
|
||||
{
|
||||
bool jsonWriteInt_(String &json, const String &key, int value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -229,15 +184,12 @@ bool jsonWriteInt_(String &json, const String &key, int value, bool e)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteFloat_(String &json, const String &key, float value, bool e)
|
||||
{
|
||||
bool jsonWriteFloat_(String &json, const String &key, float value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -249,29 +201,24 @@ bool jsonWriteFloat_(String &json, const String &key, float value, bool e)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void writeUint8tValueToJsonString(uint8_t *payload, size_t length, size_t headerLenth, String &json)
|
||||
{
|
||||
void writeUint8tValueToJsonString(uint8_t *payload, size_t length, size_t headerLenth, String &json) {
|
||||
String payloadStr;
|
||||
payloadStr.reserve(length + 1);
|
||||
for (size_t i = headerLenth; i < length; i++)
|
||||
{
|
||||
for (size_t i = headerLenth; i < length; i++) {
|
||||
payloadStr += (char)payload[i];
|
||||
}
|
||||
jsonMergeObjects(json, payloadStr);
|
||||
}
|
||||
|
||||
bool jsonMergeObjects(String &json1, String &json2, bool e)
|
||||
{
|
||||
bool jsonMergeObjects(String &json1, String &json2, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc1(JSON_BUFFER_SIZE);
|
||||
DeserializationError error1 = deserializeJson(doc1, json1);
|
||||
DynamicJsonDocument doc2(JSON_BUFFER_SIZE);
|
||||
DeserializationError error2 = deserializeJson(doc2, json2);
|
||||
jsonMergeDocs(doc1.as<JsonObject>(), doc2.as<JsonObject>());
|
||||
if (error1 || error2)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error1 || error2) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("json"), "jsonMergeObjects error");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -282,23 +229,18 @@ bool jsonMergeObjects(String &json1, String &json2, bool e)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void jsonMergeDocs(JsonObject dest, JsonObjectConst src)
|
||||
{
|
||||
for (auto kvp : src)
|
||||
{
|
||||
void jsonMergeDocs(JsonObject dest, JsonObjectConst src) {
|
||||
for (auto kvp : src) {
|
||||
dest[kvp.key()] = kvp.value();
|
||||
}
|
||||
}
|
||||
|
||||
// depricated======================================================================
|
||||
String jsonReadStr(const String &json, String name, bool e)
|
||||
{
|
||||
String jsonReadStr(const String &json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -306,14 +248,11 @@ String jsonReadStr(const String &json, String name, bool e)
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
boolean jsonReadBool(const String &json, String name, bool e)
|
||||
{
|
||||
boolean jsonReadBool(const String &json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -321,14 +260,11 @@ boolean jsonReadBool(const String &json, String name, bool e)
|
||||
return doc[name].as<bool>();
|
||||
}
|
||||
|
||||
int jsonReadInt(const String &json, String name, bool e)
|
||||
{
|
||||
int jsonReadInt(const String &json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -336,14 +272,11 @@ int jsonReadInt(const String &json, String name, bool e)
|
||||
return doc[name].as<int>();
|
||||
}
|
||||
|
||||
long int jsonReadLInt(const String &json, String name, bool e)
|
||||
{
|
||||
long int jsonReadLInt(const String &json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -352,14 +285,11 @@ long int jsonReadLInt(const String &json, String name, bool e)
|
||||
}
|
||||
|
||||
// depricated========================================================================
|
||||
String jsonWriteStr(String &json, String name, String value, bool e)
|
||||
{
|
||||
String jsonWriteStr(String &json, String name, String value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -370,14 +300,11 @@ String jsonWriteStr(String &json, String name, String value, bool e)
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteBool(String &json, String name, boolean value, bool e)
|
||||
{
|
||||
String jsonWriteBool(String &json, String name, boolean value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -388,14 +315,11 @@ String jsonWriteBool(String &json, String name, boolean value, bool e)
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteInt(String &json, String name, int value, bool e)
|
||||
{
|
||||
String jsonWriteInt(String &json, String name, int value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -406,14 +330,11 @@ String jsonWriteInt(String &json, String name, int value, bool e)
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteFloat(String &json, String name, float value, bool e)
|
||||
{
|
||||
String jsonWriteFloat(String &json, String name, float value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
if (error) {
|
||||
if (e) {
|
||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
@@ -424,8 +345,7 @@ String jsonWriteFloat(String &json, String name, float value, bool e)
|
||||
return json;
|
||||
}
|
||||
|
||||
void jsonErrorDetected()
|
||||
{
|
||||
void jsonErrorDetected() {
|
||||
// пример как отправить ошибку с количеством
|
||||
// jsonWriteInt(errorsHeapJson, F("jse2"), 1);
|
||||
// int number = jsonReadInt(errorsHeapJson, F("jse2n"));
|
||||
|
||||
Reference in New Issue
Block a user