mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Дописываем логику работы с переменной timenow в сценариях. Теперь доступны выражения вида "timenow > 22:48 && timenow < 23:55 && btn = 1"
This commit is contained in:
@@ -164,11 +164,12 @@ class Scenario {
|
|||||||
if (isEventExist(incommingEventKey, setEventKey)) {
|
if (isEventExist(incommingEventKey, setEventKey)) {
|
||||||
String setEventSign;
|
String setEventSign;
|
||||||
String setEventValue;
|
String setEventValue;
|
||||||
if (type == 1) preCalculation(condition, setEventSign, setEventValue);
|
if (type == 1) preCalculation(condition, setEventSign, incommingEventValue, setEventValue);
|
||||||
if (type == 2) preCalculationGisteresis(condition, setEventSign, setEventValue);
|
if (type == 2) preCalculationGisteresis(condition, setEventSign, setEventValue);
|
||||||
if (isConditionMatch(setEventSign, incommingEventValue, setEventValue)) {
|
if (isConditionMatch(setEventSign, incommingEventValue, setEventValue)) {
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
|
//SerialPrint("I", "incommingEventKey", incommingEventKey);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -178,8 +179,15 @@ class Scenario {
|
|||||||
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
||||||
String setEventSign;
|
String setEventSign;
|
||||||
String setEventValue;
|
String setEventValue;
|
||||||
preCalculation(condition, setEventSign, setEventValue);
|
String jsonValue;
|
||||||
String jsonValue = getValue(setEventKey);
|
|
||||||
|
if (setEventKey == "timeNow") {
|
||||||
|
jsonValue = timeNow->getTimeWOsec();
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
@@ -200,13 +208,24 @@ class Scenario {
|
|||||||
// return res;
|
// return res;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void preCalculation(String &condition, String &setEventSign, 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, ":") != "") {
|
||||||
|
int hhLStr = selectToMarker(incommingEventValue, ":").toInt();
|
||||||
|
int mmLStr = selectToMarkerLast(incommingEventValue, ":").toInt();
|
||||||
|
int hhRStr = selectToMarker(setEventValue, ":").toInt();
|
||||||
|
int mmRStr = selectToMarkerLast(setEventValue, ":").toInt();
|
||||||
|
|
||||||
|
incommingEventValue = hhLStr*60 + mmLStr;
|
||||||
|
setEventValue = hhRStr*60 + mmRStr;
|
||||||
|
} else {
|
||||||
setEventValue = getValue(setEventValue);
|
setEventValue = getValue(setEventValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void preCalculationGisteresis(String &condition, String &setEventSign, String &setEventValue) {
|
void preCalculationGisteresis(String &condition, String &setEventSign, String &setEventValue) {
|
||||||
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
||||||
@@ -236,6 +255,7 @@ class Scenario {
|
|||||||
|
|
||||||
bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
|
|
||||||
if (setEventSign == "=") {
|
if (setEventSign == "=") {
|
||||||
flag = incommingEventValue == setEventValue;
|
flag = incommingEventValue == setEventValue;
|
||||||
} else if (setEventSign == "!=") {
|
} else if (setEventSign == "!=") {
|
||||||
@@ -249,6 +269,7 @@ class Scenario {
|
|||||||
} else if (setEventSign == "<=") {
|
} else if (setEventSign == "<=") {
|
||||||
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
|
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user