Modbus v2 initialization fixed

This commit is contained in:
2020-07-26 14:20:04 +03:00
parent 3b8d085b29
commit 840d3d60eb
15 changed files with 21231 additions and 22796 deletions

View File

@@ -3,7 +3,7 @@
#-DAVR_DMXOUT_PIN=18
-DDMX_DISABLE
-DMODBUS_DISABLE
-DMBUS_DISABLE
#-DMBUS_DISABLE
#-DOWIRE_DISABLE
-DDHT_DISABLE
-DCOUNTER_DISABLE

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1002,7 +1002,7 @@ configLocked++;
if (cmd<1) it.setCmd(CMD_OFF);
pinMode(pin, OUTPUT);
digitalWrite(pin, false); //Initially, all thermostates are LOW (OFF for electho heaters, open for water NO)
debugSerial<<F("Thermo:")<<pin<<F("=LOW")<<F(",");
debugSerial<<F("Thermo:")<<pin<<F("=LOW")<<F(";");
break;
case CH_RELAY:
{
@@ -1012,7 +1012,7 @@ configLocked++;
digitalWrite(pin, k = ((cmd == CMD_ON) ? LOW : HIGH));
else
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(",");
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(";");
}
break;
} //switch
@@ -1022,6 +1022,7 @@ configLocked++;
} //if
pollingItem = items->child;
}
debugSerial<<endl;
inputs = aJson.getObjectItem(root, "in");
mqttArr = aJson.getObjectItem(root, "mqtt");
@@ -1039,8 +1040,12 @@ void printConfigSummary() {
printBool(items);
infoSerial<<F("\ninputs ");
printBool(inputs);
#ifdef _modbus
infoSerial<<F("\nmodbus ");
#ifndef MODBUS_DISABLE
infoSerial<<F("\nmodbus v1 (+)");
// printBool(modbusObj);
#endif
#ifndef MBUS_DISABLE
infoSerial<<F("\nmodbus v2");
printBool(modbusObj);
#endif
infoSerial<<F("\nmqtt ");

View File

@@ -66,6 +66,8 @@
#include "streamlog.h"
extern Streamlog debugSerial;
extern Streamlog infoSerial;
extern Streamlog errorSerial;
#if defined(__SAM3X8E__)
#define wdt_res() watchdogReset()

View File

@@ -96,15 +96,21 @@ int str2regSize(char * str)
bool out_Modbus::getConfig()
{
// Retrieve and store template values from global modbus settings
if (!store || !item || !item->itemArg || (item->itemArg->type != aJson_Array) || aJson.getArraySize(item->itemArg)<2) return false;
if (!store || !item || !item->itemArg || (item->itemArg->type != aJson_Array) || aJson.getArraySize(item->itemArg)<2)
{
errorSerial<<F("MBUS: config failed:")<<(bool)store<<F(",")<<(bool)item<<F(",")<<(bool)item->itemArg<<F(",")<<(item->itemArg->type != aJson_Array)<<F(",")<< (aJson.getArraySize(item->itemArg)<2)<<endl;
return false;
}
aJsonObject * templateIdObj = aJson.getArrayItem(item->itemArg, 1);
if (templateIdObj->type != aJson_String || !templateIdObj->valuestring) return false;
if (templateIdObj->type != aJson_String || !templateIdObj->valuestring)
{
errorSerial<<F("Invalid template.")<<endl;
return false;
}
aJsonObject * templateObj = aJson.getObjectItem(modbusObj, templateIdObj->valuestring);
if (! templateObj)
{
debugSerial<<F("Modbus template not found: ")<<templateIdObj->valuestring<<endl;
errorSerial<<F("Modbus template not found: ")<<templateIdObj->valuestring<<endl;
return false;
}
@@ -124,7 +130,7 @@ bool out_Modbus::getConfig()
else {store->pollingRegisters=NULL;store->pollingInterval = 1000;}
store->parameters=aJson.getObjectItem(templateObj, "par");
return true;
//store->addr=item->getArg(0);
}
@@ -132,18 +138,21 @@ bool out_Modbus::getConfig()
int out_Modbus::Setup()
{
if (!store) store= (mbPersistent *)item->setPersistent(new mbPersistent);
if (!store) return 0;
if (!store)
{ errorSerial<<F("MBUS: Out of memory")<<endl;
return 0;}
store->timestamp=millis();
if (getConfig())
{
//item->clearFlag(ACTION_NEEDED);
//item->clearFlag(ACTION_IN_PROCESS);
debugSerial<<F("Modbus config loaded ")<< item->itemArr->name<<endl;
infoSerial<<F("Modbus config loaded ")<< item->itemArr->name<<endl;
store->driverStatus = CST_INITIALIZED;
return 1;
}
else
{ debugSerial<<F("Modbus config error")<<endl;
{ errorSerial<<F("Modbus config error")<<endl;
store->driverStatus = CST_FAILED;
return 0;
}

View File

@@ -331,7 +331,7 @@ lib_deps =
platform = atmelavr
board = megaatmega2560
;upload_port = net:192.168.88.31:23
upload_port = net:192.168.88.2:23000
;upload_port = net:192.168.88.2:23000
framework = arduino
build_flags = !python get_build_flags.py mega2560slim-5100
lib_ignore =