mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Исправляем ошибки в логике работы сценария связанной с проверкой времени
This commit is contained in:
@@ -10,10 +10,14 @@ class Scenario {
|
|||||||
if (!jsonReadBool(configSetupJson, "scen")) {
|
if (!jsonReadBool(configSetupJson, "scen")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String allBlocks = scenario;
|
String allBlocks = scenario;
|
||||||
allBlocks += "\n";
|
allBlocks += "\n";
|
||||||
|
|
||||||
String incommingEvent = selectToMarker(eventBuf, ",");
|
String incommingEvent = selectToMarker(eventBuf, ",");
|
||||||
|
if (incommingEvent == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String incommingEventKey = selectToMarker(incommingEvent, " ");
|
String incommingEventKey = selectToMarker(incommingEvent, " ");
|
||||||
String incommingEventValue = selectToMarkerLast(incommingEvent, " ");
|
String incommingEventValue = selectToMarkerLast(incommingEvent, " ");
|
||||||
@@ -159,19 +163,20 @@ class Scenario {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool isScenarioNeedToDo(String &condition, String &incommingEventKey, String &incommingEventValue, int type) {
|
bool isScenarioNeedToDo(String &condition, String &incommingEventKey, String &incommingEventValue, int type) {
|
||||||
bool res = false;
|
if (condition == "") return false;
|
||||||
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
||||||
if (isEventExist(incommingEventKey, setEventKey)) {
|
if (isEventExist(incommingEventKey, setEventKey)) {
|
||||||
String setEventSign;
|
String setEventSign;
|
||||||
String setEventValue;
|
String setEventValue;
|
||||||
if (type == 1) preCalculation(condition, setEventSign, incommingEventValue, setEventValue);
|
String cloneOfIncommingEventValue = incommingEventValue; //клонируем для изменения в preCalculation и передачи для проверки по условиям
|
||||||
|
if (type == 1) preCalculation(condition, setEventSign, cloneOfIncommingEventValue, setEventValue);
|
||||||
if (type == 2) preCalculationGisteresis(condition, setEventSign, setEventValue);
|
if (type == 2) preCalculationGisteresis(condition, setEventSign, setEventValue);
|
||||||
if (isConditionMatch(setEventSign, incommingEventValue, setEventValue)) {
|
if (isConditionMatch(setEventSign, cloneOfIncommingEventValue, setEventValue)) {
|
||||||
res = true;
|
return true;
|
||||||
}
|
}
|
||||||
//SerialPrint("I", "incommingEventKey", incommingEventKey);
|
//SerialPrint("I", "incommingEventKey", incommingEventKey);
|
||||||
}
|
}
|
||||||
return res;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isScenarioNeedToDoJson(String &condition) {
|
bool isScenarioNeedToDoJson(String &condition) {
|
||||||
@@ -179,15 +184,9 @@ class Scenario {
|
|||||||
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
||||||
String setEventSign;
|
String setEventSign;
|
||||||
String setEventValue;
|
String setEventValue;
|
||||||
String jsonValue;
|
|
||||||
|
|
||||||
if (setEventKey == "timeNow") {
|
String jsonValue = getValue(setEventKey);
|
||||||
jsonValue = timeNow->getTimeWOsec();
|
preCalculation(condition, setEventSign, jsonValue, setEventValue);
|
||||||
} else {
|
|
||||||
jsonValue = getValue(setEventKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
preCalculation(condition, setEventSign, jsonValue, setEventValue); //warning тут не уверен что jsonValue можно использовать
|
|
||||||
if (isConditionMatch(setEventSign, jsonValue, setEventValue)) {
|
if (isConditionMatch(setEventSign, jsonValue, setEventValue)) {
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
@@ -211,14 +210,14 @@ class Scenario {
|
|||||||
void preCalculation(String &condition, String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
void preCalculation(String &condition, String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
||||||
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
||||||
setEventValue = selectFromMarkerToMarker(condition, " ", 2);
|
setEventValue = selectFromMarkerToMarker(condition, " ", 2);
|
||||||
|
|
||||||
if (!isDigitDotCommaStr(setEventValue)) {
|
if (!isDigitDotCommaStr(setEventValue)) {
|
||||||
if (selectToMarker(incommingEventValue, ":") != "") {
|
if (isTimeStr(incommingEventValue)) {
|
||||||
int hhLStr = selectToMarker(incommingEventValue, ":").toInt();
|
int hhLStr = selectToMarker(incommingEventValue, ":").toInt();
|
||||||
int mmLStr = selectToMarkerLast(incommingEventValue, ":").toInt();
|
int mmLStr = selectToMarkerLast(incommingEventValue, ":").toInt();
|
||||||
int hhRStr = selectToMarker(setEventValue, ":").toInt();
|
int hhRStr = selectToMarker(setEventValue, ":").toInt();
|
||||||
int mmRStr = selectToMarkerLast(setEventValue, ":").toInt();
|
int mmRStr = selectToMarkerLast(setEventValue, ":").toInt();
|
||||||
|
|
||||||
incommingEventValue = hhLStr*60 + mmLStr;
|
incommingEventValue = hhLStr*60 + mmLStr;
|
||||||
setEventValue = hhRStr*60 + mmRStr;
|
setEventValue = hhRStr*60 + mmRStr;
|
||||||
} else {
|
} else {
|
||||||
@@ -247,15 +246,20 @@ class Scenario {
|
|||||||
|
|
||||||
bool isEventExist(String &incommingEventKey, String &setEventKey) {
|
bool isEventExist(String &incommingEventKey, String &setEventKey) {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
if (incommingEventKey == setEventKey) {
|
if (incommingEventKey != "not found" && incommingEventKey == setEventKey) {
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
||||||
boolean flag = false;
|
if (setEventValue == "no value") return false;
|
||||||
|
|
||||||
|
boolean flag = false;
|
||||||
|
//SerialPrint("I", "setEventSign", setEventSign);
|
||||||
|
//SerialPrint("I", "incommingEventValue", incommingEventValue);
|
||||||
|
//SerialPrint("I", "setEventValue", setEventValue);
|
||||||
|
//SerialPrint("I", "==========", "===============");
|
||||||
if (setEventSign == "=") {
|
if (setEventSign == "=") {
|
||||||
flag = incommingEventValue == setEventValue;
|
flag = incommingEventValue == setEventValue;
|
||||||
} else if (setEventSign == "!=") {
|
} else if (setEventSign == "!=") {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ size_t itemsCount(String& str, const char* delim);
|
|||||||
|
|
||||||
boolean isDigitStr(const String& str);
|
boolean isDigitStr(const String& str);
|
||||||
|
|
||||||
|
boolean isTimeStr(const String& str);
|
||||||
|
|
||||||
boolean isDigitDotCommaStr(const String& str);
|
boolean isDigitDotCommaStr(const String& str);
|
||||||
|
|
||||||
String prettyBytes(size_t size);
|
String prettyBytes(size_t size);
|
||||||
|
|||||||
@@ -155,6 +155,18 @@ boolean isDigitStr(const String& str) {
|
|||||||
return str.length();
|
return str.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isTimeStr(const String& str) {
|
||||||
|
|
||||||
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
|
char latter = str.charAt(i);
|
||||||
|
if (!isDigit(latter) && latter != ':') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (str.charAt(2) != ':') return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isDigitDotCommaStr(const String& str) {
|
boolean isDigitDotCommaStr(const String& str) {
|
||||||
for (size_t i = 0; i < str.length(); i++) {
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
char latter = str.charAt(i);
|
char latter = str.charAt(i);
|
||||||
|
|||||||
Reference in New Issue
Block a user