From 7040d9bf93f0a34c81acd0153c361d08eaa473b3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 14 Aug 2024 19:43:24 +0300 Subject: [PATCH] MBUS no write if prefetched value == target Removed constrain 255 for mapping --- lighthub/itemCmd.cpp | 3 ++- lighthub/modules/out_modbus.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lighthub/itemCmd.cpp b/lighthub/itemCmd.cpp index 4a4d757..7db7d71 100644 --- a/lighthub/itemCmd.cpp +++ b/lighthub/itemCmd.cpp @@ -1454,7 +1454,8 @@ if (valMapping && valMapping->type == aJson_Array && aJson.getArraySize(valMappi if (getInt()valueint) return itemCmd().Int((uint32_t) 0); int diff = ((b-a)/(d-c))/2; - return itemCmd().Int((uint32_t) constrain(map(getInt(),c,d,a,b)+diff,0,255)); + //return itemCmd().Int((uint32_t) constrain(map(getInt(),c,d,a,b)+diff,0,255)); + return itemCmd().Int((uint32_t) map(getInt(),c,d,a,b)+diff); } if (valMapping && valMapping->type == aJson_NULL) return itemCmd(); return *this; diff --git a/lighthub/modules/out_modbus.cpp b/lighthub/modules/out_modbus.cpp index eeebb83..1aa8981 100644 --- a/lighthub/modules/out_modbus.cpp +++ b/lighthub/modules/out_modbus.cpp @@ -556,7 +556,7 @@ int out_Modbus::sendModbus(char * paramName, aJsonObject * outValue) if (prefetchObj && (prefetchObj->type == aJson_Boolean) && prefetchObj->valuebool) { int modbusRegType = (outValue->subtype == PAR_COIL) ? MODBUS_COIL_REG_TYPE:MODBUS_HOLDING_REG_TYPE; - debugSerial<valueint << " type:" << modbusRegType << " "; + debugSerial<valueint << " type:" << modbusRegType << " "; /// to prevent CORRUPTIOIN if using same buffer uint16_t localBuffer; @@ -608,6 +608,13 @@ if (prefetchObj && (prefetchObj->type == aJson_Boolean) && prefetchObj->valueboo } else { + if (outValue->valueint == localBuffer) + { + debugSerial << F("MBUS:")<type ==aJson_Object) int sendRes; int savedValue; + bool needResend; do { savedValue = outValue->valueint; debugSerial<<"MBUS: SEND "<itemArr->name<<" "; sendRes = sendModbus(execObj->name,outValue); + needResend = (savedValue != outValue->valueint); + while(needResend && mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100)) modbusIdle(); } - while (savedValue != outValue->valueint); //repeat sending if target value changed while we're waited for mbus responce + while (needResend); //repeat sending if target value changed while we're waited for mbus responce switch (sendRes) { case 1: //success + case -4: //equal tatget //execObj->subtype&=~ MB_NEED_SEND; execObj->subtype = 0; onceSendOk=true;