PID out, less logs, GET cfg fix, mbus concurr wrte

This commit is contained in:
2024-01-28 12:05:10 +03:00
parent 5ec57f0414
commit 05ea031977
6 changed files with 40 additions and 22 deletions

View File

@@ -327,7 +327,7 @@ void Item::setCmd(uint8_t cmdValue) {
{
itemCmd->type = aJson_Int;
itemCmd->valueint = cmdValue & CMD_MASK | itemCmd->valueint & (FLAG_MASK); // Preserve special bits
debugSerial<<F("SetCmd:")<<cmdValue<<endl;
//debugSerial<<F("SetCmd:")<<cmdValue<<endl;
}
}

View File

@@ -1171,8 +1171,8 @@ bool itemCmd::saveItem(Item * item, uint16_t optionsFlag)
item->setVal(param.asInt32);
item->setSubtype(cmd.itemArgType);
}
debugSerial<<F("Saved:");
debugOut();
//debugSerial<<F("Saved:");
//debugOut();
return true;
}
return false;

View File

@@ -408,7 +408,7 @@ void mqttCallback(char *topic, byte *payload, unsigned int length)
int fr = freeRam();
debugSerial<<F("\n")<<fr<<F(":[")<<topic<<F("] ");
debugSerial<<fr<<F(":[")<<topic<<F("] ");
if (fr < 250+MQTT_TOPIC_LENGTH) {
errorSerial<<F("OutOfMemory!")<<endl;
@@ -780,7 +780,7 @@ lan_status lanLoop() {
case GET:
statusLED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0));
if (configLocked) return GET;
lanStatus = GET_IN_PROGRESS;
if (loadConfigFromHttp()==200) lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
else if (configLoaded) {
infoSerial<<F("Continue with previously loaded config")<<endl;
@@ -796,6 +796,7 @@ lan_status lanLoop() {
case DO_NOTHING:
case OPERATION_NO_MQTT:
case GET_IN_PROGRESS:
;
}

View File

@@ -220,7 +220,8 @@ enum lan_status {
DO_READ_RE_CONFIG = 15,
DO_NOTHING = -15,
DO_GET = -16,
GET = -17
GET = -17,
GET_IN_PROGRESS = 18
};
extern lan_status lanStatus;

View File

@@ -341,7 +341,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
switch (defMappingObj->type)
{
case aJson_Int: //register/coil/.. number
debugSerial<<F("Searching reg#")<<defMappingObj->valueint<<endl;
traceSerial<<F("Searching reg#")<<defMappingObj->valueint<<endl;
if ((defMappingObj->valueint>= registerFrom) && (defMappingObj->valueint<=registerTo))
{
mappedParam = findRegister(defMappingObj->valueint,defMappingObj->valueint-registerFrom,regType,registerFrom,registerTo,false,&submitRecurrentOut);
@@ -351,7 +351,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
break;
case aJson_String: // parameter name
debugSerial<<F("Searching reg: ")<<defMappingObj->valuestring<<endl;
traceSerial<<F("Searching reg: ")<<defMappingObj->valuestring<<endl;
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
{
//Searching item param for nested mapping
@@ -364,7 +364,7 @@ itemCmd out_Modbus::findRegister(uint16_t registerNum, uint16_t posInBuffer, uin
aJsonObject *lastMeasured = aJson.getObjectItem(itemParObj,"@S");
if (lastMeasured && lastMeasured->type ==aJson_Int)
{
debugSerial<<F("LastKnown value: ")<<lastMeasured->valueint<<endl;
traceSerial<<F("LastKnown value: ")<<lastMeasured->valueint<<endl;
//Searching template param for nested mapping
aJsonObject * templateParObj = aJson.getObjectItem(store->parameters,defMappingObj->valuestring);
if (templateParObj)
@@ -550,7 +550,7 @@ return itemCmd();
int registerTo=aJson.getArrayItem(reg, 1)->valueint;
if (readModbus(registerFrom,regType,registerTo-registerFrom+1))
{ debugSerial<<endl;
{ traceSerial<<endl;
for(int i=registerFrom;i<=registerTo;i++)
{
findRegister(i,i-registerFrom,regType,registerFrom,registerTo);
@@ -633,7 +633,7 @@ int out_Modbus::sendModbus(char * paramName, int32_t value, uint8_t regType)
break;
}
mbusSlenceTimer = millisNZ();
debugSerial<<F("Res: ")<<res<<F(" ")<<paramName<<" reg:"<<regObj->valueint<<F(" val:")<<value<<endl;
debugSerial<<F("MBUS res: ")<<res<<F(" ")<<paramName<<" reg:"<<regObj->valueint<<F(" val:")<<value<<endl;
return ( res == 0);
}
@@ -667,8 +667,18 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
lineInitialized=true;
initLine();
}
debugSerial<<"MBUS: SEND "<<item->itemArr->name<<" ";
switch (sendModbus(execObj->name,outValue->valueint,outValue->subtype))
int sendRes;
int savedValue;
do
{
savedValue = outValue->valueint;
debugSerial<<"MBUS: SEND "<<item->itemArr->name<<" ";
sendRes = sendModbus(execObj->name,outValue->valueint,outValue->subtype);
}
while (savedValue != outValue->valueint); //repeat sending if target value changed while we're waited for mbus responce
switch (sendRes)
{
case 1: //success
execObj->subtype&=~ MB_NEED_SEND;

View File

@@ -334,32 +334,38 @@ case S_CTRL:
switch (command)
{
case CMD_OFF:
//value.Percents255(0);
if (isNotRetainingStatus()) executeCommand(oCmd,-1,itemCmd().Cmd(CMD_DISABLE)); // Not actually disable, just inform depended systems, that no autoreg now (for pannels indication)
executeCommand(oCmd,-1,value);
item->SendStatus(FLAG_FLAGS);
return 1;
case CMD_ON:
case CMD_HEAT:
case CMD_COOL:
case CMD_AUTO:
case CMD_FAN:
case CMD_DRY:
executeCommand(oCmd,-1,value);
executeCommand(oCmd,-1,itemCmd().Cmd((item->getFlag(FLAG_DISABLED))?CMD_DISABLE:CMD_ENABLE));
executeCommand(oCmd,-1,value);
item->SendStatus(FLAG_FLAGS);
return 1;
case CMD_ENABLE:
//item->setCmd(CMD_ENABLE);
//item->SendStatus(FLAG_COMMAND);
if (isNotRetainingStatus())
{
item->setCmd(CMD_ON);
item->SendStatus(FLAG_COMMAND);
}
item->setFlag(FLAG_ACTION_NEEDED);
executeCommand(oCmd,-1,value);
if (isActive()) executeCommand(oCmd,-1,itemCmd().Cmd((CMD_ON)));
store->prevOut=-2.0;
return 1;
case CMD_DISABLE:
//item->setCmd(CMD_DISABLE);
//item->SendStatus(FLAG_COMMAND);
executeCommand(oCmd,-1,value);
if (!isActive()) executeCommand(oCmd,-1,itemCmd().Cmd((CMD_OFF)));
return 1;
/*
case CMD_OFF: