From dc6e310b100d9130567c26da3c71b01be1a9c933 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 15 Aug 2024 00:36:14 +0300 Subject: [PATCH] MBUS fix for requrent def# reg less main reg Now it can working for empty action for def# reg --- lighthub/modules/out_modbus.cpp | 76 ++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/lighthub/modules/out_modbus.cpp b/lighthub/modules/out_modbus.cpp index 1aa8981..1df7a42 100644 --- a/lighthub/modules/out_modbus.cpp +++ b/lighthub/modules/out_modbus.cpp @@ -303,11 +303,12 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin switch (defMappingObj->type) { case aJson_Int: //register/coil/.. number - traceSerial<valueint<valueint<valueint>= registerFrom) && (defMappingObj->valueint<=registerTo)) { mappedParam = findRegister(defMappingObj->valueint,defMappingObj->valueint-registerFrom,regType,registerFrom,registerTo,false,&submitRecurrentOut); executeWithoutCheck=true; + debugSerial<<"MBUSD: recurrent check res: "<<"SRO:"<name); if (execObj) { - aJsonObject * markObj = execObj; - if (execObj->type == aJson_Array) markObj = execObj->child; - //Retrive previous data - aJsonObject *lastMeasured = aJson.getObjectItem(markObj,"@S"); - if (lastMeasured) - { - if (lastMeasured->type == aJson_Int) - { - if (lastMeasured->valueint == param) - *submitParam=false; //supress repeating execution for same val - else - { - lastMeasured->valueint=param; - traceSerial<<"MBUS: Stored "<name<subtype&=~MB_VALUE_OUTDATED; - } - } - } - else //No container to store value yet - { - debugSerial<name<child; + while (i && !storeLastValue) + { + if (i->name && *i->name && (*i->name != '@')) storeLastValue = true; + i=i->next; + } + } + + aJsonObject * markObj = execObj; + if (execObj->type == aJson_Array) + { + markObj = execObj->child; + storeLastValue = true; + } + + if (storeLastValue) + { + //Retrive previous data + aJsonObject *lastMeasured = aJson.getObjectItem(markObj,"@S"); + if (lastMeasured) + { + if (lastMeasured->type == aJson_Int) + { + if (lastMeasured->valueint == param) + *submitParam=false; //supress repeating execution for same val + else + { + lastMeasured->valueint=param; + traceSerial<<"MBUS: Stored "<name<subtype&=~MB_VALUE_OUTDATED; + } + } + } + else //No container to store value yet + { + debugSerial<name<type ==aJson_Object) debugSerial<<"MBUS: SEND "<itemArr->name<<" "; sendRes = sendModbus(execObj->name,outValue); needResend = (savedValue != outValue->valueint); - while(needResend && mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100)) modbusIdle(); + //while(needResend && mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100)) modbusIdle(); } while (needResend); //repeat sending if target value changed while we're waited for mbus responce