From 264b61e7e65bf01d34f6d1fc08cae7cca6098ca6 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Sat, 15 May 2021 15:17:53 +0300 Subject: [PATCH] SpeedUp legacy modbus writes if busy --- lighthub/item.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++---- lighthub/item.h | 2 ++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index f5fb017..2a30bc6 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -51,6 +51,8 @@ e-mail anklimov@gmail.com #include "modules/out_multivent.h" short modbusBusy = 0; +bool isPendedModbusWrites = false; + extern aJsonObject *pollingItem; extern PubSubClient mqttClient; extern int8_t ethernetIdleCount; @@ -1095,8 +1097,40 @@ int Item::isActive() { if (val) return 1; else return 0; } +void Item::resumeModbus() +{ + // return; +if (modbusBusy) return; +configLocked++; +if (items) { + aJsonObject * item = items->child; + while (items && item) + if (item->type == aJson_Array && aJson.getArraySize(item)>1) { + Item it(item); + if (it.isValid()) { + switch (it.itemType){ + case CH_MODBUS: + checkModbusRetry(); + } + + } //isValid + yield(); + item = item->next; + } //if +} +configLocked--; +} + + int Item::Poll(int cause) { + #ifndef MODBUS_DISABLE + if (isPendedModbusWrites) + { + resumeModbus(); + isPendedModbusWrites=false; + } + #endif switch (cause) { case POLLING_SLOW: @@ -1134,7 +1168,7 @@ switch (cause) if (driver && driver->Status()) { return driver->Poll(cause); - } + } return 0; } @@ -1400,14 +1434,15 @@ int Item::modbusDimmerSet(itemCmd st) } return 0; } -#endif + void Item::mb_fail(int result) { debugSerial<")<<_HEX(_reg)<0) Off(); //Shut down /// modbusBusy=1; } else aJson.addNumberToObject(out, "flt", (long int)0); @@ -1666,6 +1706,7 @@ int Item::checkFM() { free(outch); aJson.deleteItem(out); modbusBusy = 0; + //resumeModbus(); return 1; } @@ -1779,6 +1820,7 @@ int Item::checkModbusDimmer() { } else debugSerial << F("Modbus polling error=") << _HEX(result) << endl; modbusBusy = 0; + //resumeModbus(); return 1; } diff --git a/lighthub/item.h b/lighthub/item.h index e7804b8..d211272 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -151,6 +151,8 @@ class Item boolean checkVCRetry(); boolean checkHeatRetry(); void sendDelayedStatus(); + void resumeModbus(); + int checkFM(); char defaultSubItem[10];