mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
MBUS no write if prefetched value == target
Removed constrain 255 for mapping
This commit is contained in:
@@ -1454,7 +1454,8 @@ if (valMapping && valMapping->type == aJson_Array && aJson.getArraySize(valMappi
|
|||||||
|
|
||||||
if (getInt()<aJson.getArrayItem(valMapping,2)->valueint) return itemCmd().Int((uint32_t) 0);
|
if (getInt()<aJson.getArrayItem(valMapping,2)->valueint) return itemCmd().Int((uint32_t) 0);
|
||||||
int diff = ((b-a)/(d-c))/2;
|
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();
|
if (valMapping && valMapping->type == aJson_NULL) return itemCmd();
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ int out_Modbus::sendModbus(char * paramName, aJsonObject * outValue)
|
|||||||
if (prefetchObj && (prefetchObj->type == aJson_Boolean) && prefetchObj->valuebool)
|
if (prefetchObj && (prefetchObj->type == aJson_Boolean) && prefetchObj->valuebool)
|
||||||
{
|
{
|
||||||
int modbusRegType = (outValue->subtype == PAR_COIL) ? MODBUS_COIL_REG_TYPE:MODBUS_HOLDING_REG_TYPE;
|
int modbusRegType = (outValue->subtype == PAR_COIL) ? MODBUS_COIL_REG_TYPE:MODBUS_HOLDING_REG_TYPE;
|
||||||
debugSerial<<F("\nMBUS: prefetching ")<<paramName<<F(" #") <<regObj->valueint << " type:" << modbusRegType << " ";
|
debugSerial<<F(" prefetch ")<<paramName<<F(" #") <<regObj->valueint << " type:" << modbusRegType << " ";
|
||||||
|
|
||||||
/// to prevent CORRUPTIOIN if using same buffer
|
/// to prevent CORRUPTIOIN if using same buffer
|
||||||
uint16_t localBuffer;
|
uint16_t localBuffer;
|
||||||
@@ -608,6 +608,13 @@ if (prefetchObj && (prefetchObj->type == aJson_Boolean) && prefetchObj->valueboo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (outValue->valueint == localBuffer)
|
||||||
|
{
|
||||||
|
debugSerial << F("MBUS:")<<paramName<< F("=")<<localBuffer<<F(": equal targert.")<<endl;
|
||||||
|
node.setDefaultResponseBuffer();
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
debugSerial << F("MBUS:")<<paramName<< F(" val not changed. Continue")<<endl;
|
debugSerial << F("MBUS:")<<paramName<< F(" val not changed. Continue")<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -693,17 +700,21 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
|||||||
|
|
||||||
int sendRes;
|
int sendRes;
|
||||||
int savedValue;
|
int savedValue;
|
||||||
|
bool needResend;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
savedValue = outValue->valueint;
|
savedValue = outValue->valueint;
|
||||||
debugSerial<<"MBUS: SEND "<<item->itemArr->name<<" ";
|
debugSerial<<"MBUS: SEND "<<item->itemArr->name<<" ";
|
||||||
sendRes = sendModbus(execObj->name,outValue);
|
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)
|
switch (sendRes)
|
||||||
{
|
{
|
||||||
case 1: //success
|
case 1: //success
|
||||||
|
case -4: //equal tatget
|
||||||
//execObj->subtype&=~ MB_NEED_SEND;
|
//execObj->subtype&=~ MB_NEED_SEND;
|
||||||
execObj->subtype = 0;
|
execObj->subtype = 0;
|
||||||
onceSendOk=true;
|
onceSendOk=true;
|
||||||
|
|||||||
Reference in New Issue
Block a user