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;

View File

@@ -23,13 +23,13 @@ default_envs =
; mega2560-5500
; LightHub controller HW revision 2.1 and above (Wiznet 5500 CS on pin 53)
; lighthub21
lighthub21
; Arduino DUE + Ethernet shield Wiznet 5100
; due-5100
; Generic DUE
due
; due
; Arduino DUE + Ethernet shield Wiznet 5500
; due-5500
@@ -56,6 +56,7 @@ default_envs =
[env:nrf52840-5500]
platform = nordicnrf52
board = nrf52840_dk
monitor_baud = 115200
;board_build.variant = breakout
;upload_protocol = mbed
;upload_port = /dev/cu.SLAB_USBtoUART
@@ -118,6 +119,7 @@ lib_deps =
[env:m5stack]
platform = espressif32
board = m5stack-core-esp32
monitor_baud = 115200
framework = arduino
upload_speed = 921600
build_flags = !python get_build_flags.py m5stack
@@ -170,6 +172,7 @@ lib_deps =
[env:esp32-wifi]
platform = espressif32
framework = arduino
monitor_baud = 115200
monitor_filters = esp32_exception_decoder
build_type = debug
;board = pico32
@@ -227,6 +230,7 @@ lib_deps =
platform = atmelsam
framework = arduino
board = due
monitor_baud = 115200
build_flags = !python get_build_flags.py due-5100
lib_ignore =
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
@@ -276,6 +280,7 @@ lib_deps =
platform = atmelsam
framework = arduino
board = due
monitor_baud = 115200
build_flags = !python get_build_flags.py due
; Need to place arduinoOTA utility from Arduino IDE distribution to folder in your PATH
;fix address and password
@@ -330,6 +335,7 @@ lib_deps =
[env:mega2560slim-5100]
platform = atmelavr
board = megaatmega2560
monitor_baud = 115200
;upload_port = net:192.168.88.31:23
upload_port = net:192.168.88.2:23000
framework = arduino
@@ -376,6 +382,7 @@ lib_deps =
[env:mega2560-5500]
platform = atmelavr
board = megaatmega2560
monitor_baud = 115200
framework = arduino
build_flags = !python get_build_flags.py mega2560-5500
lib_ignore =
@@ -421,6 +428,7 @@ lib_deps =
platform = espressif8266
framework = arduino
board = nodemcuv2
monitor_baud = 115200
upload_protocol = esptool
;upload_protocol = espota
@@ -482,6 +490,7 @@ lib_deps =
[env:mega2560-5100]
platform = atmelavr
board = megaatmega2560
monitor_baud = 115200
framework = arduino
upload_port = net:192.168.88.2:23000
build_flags = !python get_build_flags.py mega2560-5100
@@ -528,6 +537,7 @@ lib_deps =
platform = atmelsam
framework = arduino
board = due
monitor_baud = 115200
;build_flags = !bash check_custom_build_flags_due-5500.sh
build_flags = !python get_build_flags.py due-5500
lib_ignore =
@@ -579,10 +589,11 @@ lib_deps =
platform = atmelsam
framework = arduino
board = due
monitor_baud = 115200
build_flags = !python get_build_flags.py lighthub21
;upload_command = arduinoOTA -address 192.168.11.172 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
upload_command = arduinoOTA -address 192.168.88.28 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
upload_protocol = custom
;upload_command = arduinoOTA -address 192.168.88.28 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
;upload_protocol = custom
lib_ignore =
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
DHT sensor library for ESPx
@@ -634,6 +645,7 @@ lib_deps =
[env:controllino]
platform = atmelavr
board = megaatmega2560
monitor_baud = 115200
framework = arduino
build_flags = !python get_build_flags.py controllino
lib_ignore =
@@ -680,6 +692,7 @@ lib_deps =
platform = ststm32
framework = arduino
board = nucleo_f103rb
monitor_baud = 115200
upload_protocol = stlink
debug_tool = stlink
build_flags = !python get_build_flags.py stm32-enc2860