Continue modbus developing, DMXbuf corruption fix

This commit is contained in:
2020-12-17 01:35:13 +03:00
parent 54d22620b0
commit 43162cf0f0
8 changed files with 91 additions and 7 deletions

View File

@@ -260,12 +260,13 @@ dmxout.setTxMaxChannels(channels);
#ifndef DMX_DISABLE
for (int i=1;i<=channels;i++) DmxWrite(i,0);
#endif
debugSerial<<F("DMXOut. Free:")<<freeRam()<<endl;
#ifdef DMX_SMOOTH
if (DMXinterimBuf) delete DMXinterimBuf;
DMXinterimBuf = new uint8_t [channels];
DMXinterimBuf = new uint8_t [channels+1];
DMXOUT_Channels=channels;
for (int i=1;i<=channels;i++) DMXinterimBuf[i]=0;
debugSerial<<F("DMXInterim. Free:")<<freeRam()<<endl;
#endif
}

View File

@@ -822,6 +822,16 @@ return false;
}
int itemCmd::doMappingCmd(aJsonObject *mappingData)
{
}
int itemCmd::doReverseMappingCmd (aJsonObject *mappingData)
{
}
char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
{

View File

@@ -230,6 +230,8 @@ public:
int doMapping(aJsonObject *mappingData);
int doReverseMapping (aJsonObject *mappingData);
int doMappingCmd(aJsonObject *mappingData);
int doReverseMappingCmd (aJsonObject *mappingData);
};

View File

@@ -1033,6 +1033,7 @@ setupSyslog();
if (dmxoutArr && (numParams=aJson.getArraySize(dmxoutArr)) >=1 ) {
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, numParams-1)->valueint);
infoSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
debugSerial<<F("Free:")<<freeRam()<<endl;
}
#endif
#ifdef _modbus
@@ -1467,17 +1468,21 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
htclient.stop();
wdt_res();
infoSerial<<F("HTTP Status code: ")<<responseStatusCode<<endl;
//debugSerial<<"GET Response: ");
//delay(1000);
if (responseStatusCode == 200) {
debugSerial<<F("GET Response: ")<<response<<endl;
debugSerial<<F("Free:")<<freeRam()<<endl;
cleanConf();
debugSerial<<F("Configuration cleaned")<<endl;
debugSerial<<F("Free:")<<freeRam()<<endl;
root = aJson.parse((char *) response.c_str());
if (!root) {
errorSerial<<F("Config parsing failed\n");
return READ_RE_CONFIG;//-11; //Load from NVRAM
} else {
debugSerial<<F("Parsed. Free:")<<freeRam()<<endl;
//debugSerial<<response;
applyConfig();
infoSerial<<F("Done.\n");

View File

@@ -374,6 +374,11 @@ int out_Modbus::getChanType()
}
//!Control unified Modbus item
// Priority of selection sub-items control to:
// 1. if defined standard suffix Code inside cmd
// 2. custom textual subItem
// 3. non-standard numeric suffix Code equal param id
int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
{
@@ -381,6 +386,37 @@ int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
//bool toExecute = (chActive>0);
//itemCmd st(ST_UINT32,CMD_VOID);
int suffixCode = cmd.getSuffix();
aJsonObject *templateParamObj = NULL;
short mappedCmdVal = 0;
// trying to find parameter in template with name == subItem (NB!! standard suffixes dint working here)
if (subItem && strlen (subItem)) templateParamObj = aJson.getObjectItem(store->parameters, subItem);
if (!templateParamObj)
{
// Trying to find template parameter where id == suffixCode
templateParamObj = store->parameters->child;
while (templateParamObj)
{
//aJsonObject *regObj = aJson.getObjectItem(paramObj, "reg");
aJsonObject *idObj = aJson.getObjectItem(templateParamObj, "id");
if (idObj->type==aJson_Int && idObj->valueint == suffixCode) break;
aJsonObject *mapObj = aJson.getObjectItem(templateParamObj, "mapcmd");
if (mapObj && (mappedCmdVal = cmd.doReverseMappingCmd(mapObj))) break;
templateParamObj=templateParamObj->next;
}
}
// aJsonObject *typeObj = aJson.getObjectItem(paramObj, "type");
// aJsonObject *mapObj = aJson.getObjectItem(paramObj, "map");
// aJsonObject * itemParametersObj = aJson.getArrayItem(item->itemArg, 2);
// uint16_t data = node.getResponseBuffer(posInBuffer);
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it

View File

@@ -95,6 +95,7 @@ int owSetup(owChangedType owCh) {
if (oneWire) return true; // Already initialized
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
debugSerial<<F("Free:")<<freeRam()<<endl;
oneWire = new OneWire;
#else
debugSerial.print(F("One wire setup on PIN:"));
@@ -102,12 +103,25 @@ int owSetup(owChangedType owCh) {
oneWire = new OneWire (USE_1W_PIN);
#endif
if (!oneWire)
{
errorSerial<<F("Error 1-w init #1")<<endl;
return false;
}
// Pass our oneWire reference to Dallas Temperature.
// sensors = new DallasTemperature(oneWire);
term = new DeviceAddress[t_max];
debugSerial<<F("Term. Free:")<<freeRam()<<endl;
//regs = new int [t_max];
wstat = new uint16_t[t_max];
debugSerial<<F("wstat. Free:")<<freeRam()<<endl;
if (!term || ! wstat)
{
errorSerial<<F("Error 1-w init #2 Free:")<<freeRam()<<endl;
return false;
}
owChanged = owCh;
#ifdef DS2482_100_I2C_TO_1W_BRIDGE

View File

@@ -550,6 +550,9 @@ switch (cmd->type)
break;
case aJson_Object:
{
aJsonObject *act = aJson.getObjectItem(cmd, "act");
if (act) return executeCommand(act,toggle,_itemCmd);
aJsonObject *item = aJson.getObjectItem(cmd, "item");
aJsonObject *emit = aJson.getObjectItem(cmd, "emit");
aJsonObject *icmd = NULL;