From 87191fa81bc5037e212951fc179ca042fd15aa20 Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 19 Dec 2021 23:08:14 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=B8=D1=81=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20timenow=20?= =?UTF-8?q?=D0=B2=20=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D1=8F=D1=85?= =?UTF-8?q?.=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B4=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=83=D0=BF=D0=BD=D1=8B=20=D0=B2=D1=8B=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=D0=B8=D0=B4=D0=B0=20"timenow?= =?UTF-8?q?=20>=2022:48=20&&=20timenow=20<=2023:55=20&&=20btn=20=3D=201"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Class/ScenarioClass3.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/include/Class/ScenarioClass3.h b/include/Class/ScenarioClass3.h index 177fcdce..455b4615 100644 --- a/include/Class/ScenarioClass3.h +++ b/include/Class/ScenarioClass3.h @@ -12,7 +12,7 @@ class Scenario { } String allBlocks = scenario; allBlocks += "\n"; - + String incommingEvent = selectToMarker(eventBuf, ","); String incommingEventKey = selectToMarker(incommingEvent, " "); @@ -164,11 +164,12 @@ class Scenario { if (isEventExist(incommingEventKey, setEventKey)) { String setEventSign; 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 (isConditionMatch(setEventSign, incommingEventValue, setEventValue)) { res = true; } + //SerialPrint("I", "incommingEventKey", incommingEventKey); } return res; } @@ -178,8 +179,15 @@ class Scenario { String setEventKey = selectFromMarkerToMarker(condition, " ", 0); String setEventSign; String setEventValue; - preCalculation(condition, setEventSign, setEventValue); - String jsonValue = getValue(setEventKey); + String jsonValue; + + if (setEventKey == "timeNow") { + jsonValue = timeNow->getTimeWOsec(); + } else { + jsonValue = getValue(setEventKey); + } + + preCalculation(condition, setEventSign, jsonValue, setEventValue); //warning тут не уверен что jsonValue можно использовать if (isConditionMatch(setEventSign, jsonValue, setEventValue)) { res = true; } @@ -200,11 +208,22 @@ class Scenario { // return res; //} - void preCalculation(String &condition, String &setEventSign, String &setEventValue) { + void preCalculation(String &condition, String &setEventSign, String &incommingEventValue, String &setEventValue) { setEventSign = selectFromMarkerToMarker(condition, " ", 1); setEventValue = selectFromMarkerToMarker(condition, " ", 2); + if (!isDigitDotCommaStr(setEventValue)) { - setEventValue = getValue(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); + } } } @@ -236,6 +255,7 @@ class Scenario { bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) { boolean flag = false; + if (setEventSign == "=") { flag = incommingEventValue == setEventValue; } else if (setEventSign == "!=") { @@ -249,6 +269,7 @@ class Scenario { } else if (setEventSign == "<=") { flag = incommingEventValue.toFloat() <= setEventValue.toFloat(); } + return flag; } }; From 203ceafb1953ed732915ece0bc56e80527df9352 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 20 Dec 2021 09:42:07 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B2=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=BB=D0=B0=D1=81=D0=B0,=20=D0=B2=D0=BE=D0=B7=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=D1=8E=D1=89=D1=83=D1=8E=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BA=D0=B8=D1=85=20=D1=88=D0=B8=D0=BD=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20=D0=B4=D0=B0=D1=82=D1=87?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/items/vSensorDallas.h | 4 ++++ src/items/vSensorDallas.cpp | 29 ++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/items/vSensorDallas.h b/include/items/vSensorDallas.h index 23704f3e..a30677cc 100644 --- a/include/items/vSensorDallas.h +++ b/include/items/vSensorDallas.h @@ -32,6 +32,10 @@ class SensorDallas { String _addr; unsigned int _pin; unsigned int _index; + + //для работы библиотеки с несколькими линиями необходимо обеспечить каждый экземпляр класса ссылками на объекты настроенные на эти линии + OneWire* oneWire; + DallasTemperature* sensors; }; extern MySensorDallasVector* mySensorDallas2; diff --git a/src/items/vSensorDallas.cpp b/src/items/vSensorDallas.cpp index 3e621bd4..4c53a50b 100644 --- a/src/items/vSensorDallas.cpp +++ b/src/items/vSensorDallas.cpp @@ -6,12 +6,13 @@ #include "Global.h" #include "DallasTemperature.h" #include "Utils/StringUtils.h" +#include #include //ИНТЕГРИРУЮ: переменные необходимые для работы интегрируемой библиотеки. Аналог Arduino -OneWire* oneWire; -DallasTemperature sensors; +std::map oneWireTemperatureArray; +std::map sensorsTemperatureArray; //ИНТЕГРИРУЮ: //Для каждого датчика указанного в конфигурации вызывается конструктор для настройки перед запуском. Аналог функции setup() в Arduino. @@ -26,10 +27,20 @@ SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned in //ИНТЕГРИРУЮ: //вызываем необходимые инициирующие функции интегрируемой библиотеки - oneWire = new OneWire((uint8_t)_pin); - sensors.setOneWire(oneWire); - sensors.begin(); - sensors.setResolution(12); + //учитываем, что библиотека может работать с несколькими линиями на разных пинах, поэтому инициируем библиотеку, если линия ранее не использовалась + if (oneWireTemperatureArray.find(_pin) == oneWireTemperatureArray.end()) { + oneWire = new OneWire((uint8_t)_pin); + sensors = new DallasTemperature(); + sensors->setOneWire(oneWire); + sensors->begin(); + sensors->setResolution(12); + + oneWireTemperatureArray[_pin] = oneWire; + sensorsTemperatureArray[_pin] = sensors; + } else { + oneWire = oneWireTemperatureArray[_pin]; + sensors = sensorsTemperatureArray[_pin]; + } } //ИНТЕГРИРУЮ: оставляем как есть или развиваем, если нужно правильно завершить работу с интегрируемой библиотекой после отключения датчика @@ -48,18 +59,18 @@ void SensorDallas::loop() { //ИНТЕГРИРУЮ: вызывается из цикла loop каждый установленный временно интервал в параметрах датчика. Необходимо изменить для чтения данных из датчика. void SensorDallas::readDallas() { //запускаем опрос измерений у всех датчиков на линии - sensors.requestTemperatures(); + sensors->requestTemperatures(); //Определяем адрес. Если парамтер addr не установлен, то узнаем адрес по индексу DeviceAddress deviceAddress; if (_addr == "") { - sensors.getAddress(deviceAddress, _index); + sensors->getAddress(deviceAddress, _index); } else { string2hex(_addr.c_str(), deviceAddress); } //получаем температуру по адресу - float value = sensors.getTempC(deviceAddress); + float value = sensors->getTempC(deviceAddress); //ИНТЕГРИРУЮ: блок генерации уведомлений в ядре системы. Стоит обратить внимание только на формат выводимого сообщения в консоли. eventGen2(_key, String(value)); From 7e92d57d4df62c5c279b7b11f8b3c999e62af448 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 21 Dec 2021 15:40:23 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=81=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Class/ScenarioClass3.h | 40 +++++++++++++++++++--------------- include/Utils/StringUtils.h | 2 ++ src/Utils/StringUtils.cpp | 12 ++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/Class/ScenarioClass3.h b/include/Class/ScenarioClass3.h index 455b4615..ca09d7e1 100644 --- a/include/Class/ScenarioClass3.h +++ b/include/Class/ScenarioClass3.h @@ -10,10 +10,14 @@ class Scenario { if (!jsonReadBool(configSetupJson, "scen")) { return; } + String allBlocks = scenario; allBlocks += "\n"; String incommingEvent = selectToMarker(eventBuf, ","); + if (incommingEvent == "") { + return; + } String incommingEventKey = selectToMarker(incommingEvent, " "); String incommingEventValue = selectToMarkerLast(incommingEvent, " "); @@ -159,19 +163,20 @@ class Scenario { private: bool isScenarioNeedToDo(String &condition, String &incommingEventKey, String &incommingEventValue, int type) { - bool res = false; + if (condition == "") return false; String setEventKey = selectFromMarkerToMarker(condition, " ", 0); if (isEventExist(incommingEventKey, setEventKey)) { String setEventSign; 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 (isConditionMatch(setEventSign, incommingEventValue, setEventValue)) { - res = true; + if (isConditionMatch(setEventSign, cloneOfIncommingEventValue, setEventValue)) { + return true; } //SerialPrint("I", "incommingEventKey", incommingEventKey); } - return res; + return false; } bool isScenarioNeedToDoJson(String &condition) { @@ -179,15 +184,9 @@ class Scenario { String setEventKey = selectFromMarkerToMarker(condition, " ", 0); String setEventSign; String setEventValue; - String jsonValue; - if (setEventKey == "timeNow") { - jsonValue = timeNow->getTimeWOsec(); - } else { - jsonValue = getValue(setEventKey); - } - - preCalculation(condition, setEventSign, jsonValue, setEventValue); //warning тут не уверен что jsonValue можно использовать + String jsonValue = getValue(setEventKey); + preCalculation(condition, setEventSign, jsonValue, setEventValue); if (isConditionMatch(setEventSign, jsonValue, setEventValue)) { res = true; } @@ -211,14 +210,14 @@ class Scenario { void preCalculation(String &condition, String &setEventSign, String &incommingEventValue, String &setEventValue) { setEventSign = selectFromMarkerToMarker(condition, " ", 1); setEventValue = selectFromMarkerToMarker(condition, " ", 2); - + if (!isDigitDotCommaStr(setEventValue)) { - if (selectToMarker(incommingEventValue, ":") != "") { + if (isTimeStr(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 { @@ -247,15 +246,20 @@ class Scenario { bool isEventExist(String &incommingEventKey, String &setEventKey) { bool res = false; - if (incommingEventKey == setEventKey) { + if (incommingEventKey != "not found" && incommingEventKey == setEventKey) { res = true; } return res; } 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 == "=") { flag = incommingEventValue == setEventValue; } else if (setEventSign == "!=") { diff --git a/include/Utils/StringUtils.h b/include/Utils/StringUtils.h index 36784ad5..02520618 100644 --- a/include/Utils/StringUtils.h +++ b/include/Utils/StringUtils.h @@ -34,6 +34,8 @@ size_t itemsCount(String& str, const char* delim); boolean isDigitStr(const String& str); +boolean isTimeStr(const String& str); + boolean isDigitDotCommaStr(const String& str); String prettyBytes(size_t size); diff --git a/src/Utils/StringUtils.cpp b/src/Utils/StringUtils.cpp index cf67f1ab..ac78ab04 100644 --- a/src/Utils/StringUtils.cpp +++ b/src/Utils/StringUtils.cpp @@ -155,6 +155,18 @@ boolean isDigitStr(const String& str) { 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) { for (size_t i = 0; i < str.length(); i++) { char latter = str.charAt(i);