mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
modbus v1 retry optimisation
This commit is contained in:
@@ -67,7 +67,7 @@ e-mail anklimov@gmail.com
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
short modbusBusy = 0;
|
short modbusBusy = 0;
|
||||||
bool isPendedModbusWrites = false;
|
//bool isPendedModbusWrites = false;
|
||||||
|
|
||||||
extern aJsonObject *pollingItem;
|
extern aJsonObject *pollingItem;
|
||||||
extern PubSubClient mqttClient;
|
extern PubSubClient mqttClient;
|
||||||
@@ -1615,7 +1615,8 @@ int Item::isActive() {
|
|||||||
|
|
||||||
int Item::Poll(int cause) {
|
int Item::Poll(int cause) {
|
||||||
|
|
||||||
if (isPendedModbusWrites) resumeModbus();
|
//if (isPendedModbusWrites) resumeModbus();
|
||||||
|
checkRetry();
|
||||||
|
|
||||||
aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP);
|
aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP);
|
||||||
if (timestampObj)
|
if (timestampObj)
|
||||||
@@ -1937,7 +1938,7 @@ return itemType;
|
|||||||
void Item::mb_fail(int result) {
|
void Item::mb_fail(int result) {
|
||||||
debugSerial<<F("Modbus op failed:")<<_HEX(result)<<endl;
|
debugSerial<<F("Modbus op failed:")<<_HEX(result)<<endl;
|
||||||
setFlag(FLAG_SEND_RETRY);
|
setFlag(FLAG_SEND_RETRY);
|
||||||
isPendedModbusWrites=true;
|
// isPendedModbusWrites=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define M_SUCCESS 1
|
#define M_SUCCESS 1
|
||||||
@@ -1952,26 +1953,40 @@ void Item::mb_fail(int result) {
|
|||||||
//M_BUSY (-1) - Modbus busy
|
//M_BUSY (-1) - Modbus busy
|
||||||
//M_CLEAN (2) - Clean. Not needed to repeat
|
//M_CLEAN (2) - Clean. Not needed to repeat
|
||||||
|
|
||||||
int Item::checkModbusRetry() {
|
int Item::checkRetry() {
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (modbusBusy) return M_BUSY;
|
|
||||||
if (getFlag(FLAG_SEND_RETRY)) { // if last sending attempt of command was failed
|
if (getFlag(FLAG_SEND_RETRY))
|
||||||
|
{ // if last sending attempt of command was failed
|
||||||
itemCmd val(ST_VOID,CMD_VOID);
|
itemCmd val(ST_VOID,CMD_VOID);
|
||||||
val.loadItem(this, FLAG_COMMAND | FLAG_PARAMETERS);
|
val.loadItem(this, FLAG_COMMAND | FLAG_PARAMETERS);
|
||||||
debugSerial<<F("Retrying modbus CMD\n");
|
|
||||||
clearFlag(FLAG_SEND_RETRY); // Clean retry flag
|
if (driver)
|
||||||
if (driver) result=driver->Ctrl(val);
|
{
|
||||||
|
clearFlag(FLAG_SEND_RETRY); // Clean retry flag
|
||||||
|
debugSerial<<F("Retrying CMD\n");
|
||||||
|
result=driver->Ctrl(val);
|
||||||
|
}
|
||||||
#ifndef MODBUS_DISABLE
|
#ifndef MODBUS_DISABLE
|
||||||
else switch (itemType)
|
else switch (itemType)
|
||||||
{
|
{
|
||||||
|
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
|
if (modbusBusy) return M_BUSY;
|
||||||
|
clearFlag(FLAG_SEND_RETRY); // Clean retry flag
|
||||||
|
debugSerial<<F("Retrying modbus CMD\n");
|
||||||
result=modbusDimmerSet(val);
|
result=modbusDimmerSet(val);
|
||||||
break;
|
break;
|
||||||
case CH_VC:
|
case CH_VC:
|
||||||
|
if (modbusBusy) return M_BUSY;
|
||||||
|
clearFlag(FLAG_SEND_RETRY); // Clean retry flag
|
||||||
|
debugSerial<<F("Retrying VC CMD\n");
|
||||||
result=VacomSetFan(val);
|
result=VacomSetFan(val);
|
||||||
break;
|
break;
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
|
if (modbusBusy) return M_BUSY;
|
||||||
|
clearFlag(FLAG_SEND_RETRY); // Clean retry flag
|
||||||
|
debugSerial<<F("Retrying VCTEMP CMD\n");
|
||||||
result=VacomSetHeat(val);
|
result=VacomSetHeat(val);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1991,6 +2006,7 @@ int Item::checkModbusRetry() {
|
|||||||
return M_CLEAN;
|
return M_CLEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bool Item::resumeModbus()
|
bool Item::resumeModbus()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -2020,6 +2036,8 @@ configLocked--;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
//////////////////// Begin of legacy MODBUS code - to be moved in separate module /////////////////////
|
//////////////////// Begin of legacy MODBUS code - to be moved in separate module /////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -164,11 +164,11 @@ class Item
|
|||||||
int checkModbusDimmer();
|
int checkModbusDimmer();
|
||||||
int checkModbusDimmer(int data);
|
int checkModbusDimmer(int data);
|
||||||
|
|
||||||
int checkModbusRetry();
|
int checkRetry();
|
||||||
//boolean checkVCRetry();
|
//boolean checkVCRetry();
|
||||||
//boolean checkHeatRetry();
|
//boolean checkHeatRetry();
|
||||||
void sendDelayedStatus();
|
void sendDelayedStatus();
|
||||||
bool resumeModbus();
|
//bool resumeModbus();
|
||||||
|
|
||||||
|
|
||||||
int checkFM();
|
int checkFM();
|
||||||
|
|||||||
Reference in New Issue
Block a user