From 2e5c7d8045bae551718d28fd9f0dda9f31478b22 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Sun, 19 Dec 2021 18:33:54 +0300 Subject: [PATCH] STABILITY when re-load, Artnet, RGBWW, ETAG, Logs --- lighthub/config.cpp | 1 + lighthub/dmx.cpp | 20 ++++++-- lighthub/dmx.h | 4 +- lighthub/item.cpp | 10 ++-- lighthub/itemCmd.cpp | 1 + lighthub/main.cpp | 88 ++++++++++++++++++++++++++---------- lighthub/main.h | 1 + lighthub/modules/out_ac.cpp | 2 +- lighthub/modules/out_dmx.cpp | 4 +- lighthub/modules/out_pwm.cpp | 16 +++++-- lighthub/streamlog.h | 2 +- platformio.ini | 3 +- 12 files changed, 109 insertions(+), 43 deletions(-) diff --git a/lighthub/config.cpp b/lighthub/config.cpp index a29c700..492fb2a 100644 --- a/lighthub/config.cpp +++ b/lighthub/config.cpp @@ -244,6 +244,7 @@ bool systemConfig::isValidSysConf() for (unsigned int i=0;iwrite(EEPROM_signature[i])); stream->close(); + setETAG(""); return true; } diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index e68f6eb..faa5ea8 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -51,6 +51,8 @@ volatile unsigned long D_checkT=0; #ifdef _artnet #include Artnet *artnet = NULL; +uint8_t artnetMinCh=1; +uint8_t artnetMaxCh=512; #endif @@ -216,8 +218,8 @@ debugSerial.println(); void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP) { -#ifdef _dmxout - for (unsigned int i = 0 ; i < length && itype == aJson_Int || itemCmd->type == aJson_NULL)) { itemCmd->type = aJson_Int; itemCmd->valueint = cmdValue & CMD_MASK | itemCmd->valueint & FLAG_MASK; // Preserve special bits @@ -290,7 +290,7 @@ void Item::setCmd(uint8_t cmdValue) { short Item::getFlag (short flag) { aJsonObject *itemCmd = aJson.getArrayItem(itemArr, I_CMD); - if (itemCmd) + if (itemCmd && (itemCmd->type == aJson_Int)) { return itemCmd->valueint & flag & FLAG_MASK; } @@ -300,7 +300,7 @@ return 0; void Item::setFlag (short flag) { aJsonObject *itemCmd = aJson.getArrayItem(itemArr, I_CMD); - if (itemCmd) + if (itemCmd && (itemCmd->type == aJson_Int || itemCmd->type == aJson_NULL)) { itemCmd->type = aJson_Int; itemCmd->valueint |= flag & FLAG_MASK; // Preserve CMD bits @@ -312,7 +312,7 @@ void Item::setFlag (short flag) void Item::clearFlag (short flag) { aJsonObject *itemCmd = aJson.getArrayItem(itemArr, I_CMD); - if (itemCmd) + if (itemCmd && (itemCmd->type == aJson_Int || itemCmd->type == aJson_NULL)) { itemCmd->valueint &= CMD_MASK | ~(flag & FLAG_MASK); // Preserve CMD bits // debugSerial<0) + if ((cmd.getInt()>0) && (timestampObj->type == aJson_Int || timestampObj->type == aJson_NULL)) { timestampObj->valueint = millis()+cmd.getInt(); timestampObj->type = aJson_Int; diff --git a/lighthub/itemCmd.cpp b/lighthub/itemCmd.cpp index 0c18a60..870fbdb 100644 --- a/lighthub/itemCmd.cpp +++ b/lighthub/itemCmd.cpp @@ -92,6 +92,7 @@ uint8_t itemCmd::getStoragetypeByChanType(short chanType) { case CH_RGB: case CH_RGBW: + case CH_RGBWW: case CH_SPILED: return ST_HSV255; break; diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 39a5746..6ceb095 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -189,7 +189,7 @@ aJsonObject * item = items->child; } pollingItem = NULL; debugSerial<=1 ) { - DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, numParams-1)->valueint); + maxChannels = aJson.getArrayItem(dmxoutArr, numParams-1)->valueint; + + #ifdef _artnet + aJsonObject *artnetArr = aJson.getObjectItem(root, "artnet"); + if (artnetArr) + { + uint8_t artnetMinCh = 1; + uint8_t artnetMaxCh = maxChannels; + short artnetNumParams; + + if (artnetNumParams=aJson.getArraySize(artnetArr)>=2) + { + artnetMinCh = aJson.getArrayItem(artnetArr, 0)->valueint; + if (artnetMinCh<1) artnetMinCh = 1; + artnetMaxCh = aJson.getArrayItem(artnetArr, 1)->valueint; + if (artnetMaxCh>maxChannels) artnetMaxCh=maxChannels; + } + infoSerial<1) size_t res = sysConfStream.write((byte*) outBuf,len); free (outBuf); - infoSerial<name); tStore.timestamp16=0; //Stop termostat thermostat.setExt(tStore.asint); - thermoRelay(thermoPin,false); + thermoRelay(thermoPin,ERROR); } else { // Not expired yet if (curTemp > THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", thermoItem->name); - if (!active) thermoRelay(thermoPin,false);//OFF - else if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) thermoRelay(thermoPin,true);//ON - else if (curTemp >= thermoSetting) thermoRelay(thermoPin,false);//OFF + if (!active) thermoRelay(thermoPin,OFF);//OFF + else if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) thermoRelay(thermoPin,HEAT);//ON + else if (curTemp >= thermoSetting) thermoRelay(thermoPin,OFF);//OFF else debugSerial< #include #include //#include diff --git a/lighthub/modules/out_ac.cpp b/lighthub/modules/out_ac.cpp index 1e688fd..3a8e5e9 100644 --- a/lighthub/modules/out_ac.cpp +++ b/lighthub/modules/out_ac.cpp @@ -188,7 +188,7 @@ byte getCRC(byte req[], size_t size){ void SendData(byte req[], size_t size){ AC_Serial.write(req, size - 1); AC_Serial.write(getCRC(req, size-1)); - AC_Serial.flush(); + //AC_Serial.flush(); /* Serial.print("<<"); for (int i=0; i < size-1; i++) diff --git a/lighthub/modules/out_dmx.cpp b/lighthub/modules/out_dmx.cpp index 0e53e04..3f6ccc4 100644 --- a/lighthub/modules/out_dmx.cpp +++ b/lighthub/modules/out_dmx.cpp @@ -14,14 +14,14 @@ static int driverStatus = CST_UNKNOWN; int out_dmx::Setup() { abstractOut::Setup(); -debugSerial<itemArr->name <itemArr->name << endl; driverStatus = CST_UNKNOWN; return 1; } diff --git a/lighthub/modules/out_pwm.cpp b/lighthub/modules/out_pwm.cpp index 655dfd3..4d9ecfa 100644 --- a/lighthub/modules/out_pwm.cpp +++ b/lighthub/modules/out_pwm.cpp @@ -20,7 +20,7 @@ void analogWrite(int pin, int val) int out_pwm::Setup() { abstractOut::Setup(); -debugSerial<itemType<itemType<itemType; } } diff --git a/lighthub/streamlog.h b/lighthub/streamlog.h index c16e5fc..918c790 100644 --- a/lighthub/streamlog.h +++ b/lighthub/streamlog.h @@ -49,8 +49,8 @@ class Streamlog : public Print private: uint8_t severity; SerialPortType *serialPort; + uint8_t ledPattern; #ifdef SYSLOG_ENABLE Syslog * syslog; - uint8_t ledPattern; #endif }; diff --git a/platformio.ini b/platformio.ini index d0e3ff7..6fd1022 100644 --- a/platformio.ini +++ b/platformio.ini @@ -402,6 +402,7 @@ lib_deps = https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DmxSimple https://github.com/anklimov/httpClient + ;ArduinoHttpClient https://github.com/anklimov/aJson https://github.com/anklimov/CmdArduino https://github.com/anklimov/ModbusMaster @@ -609,7 +610,7 @@ 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 ;sleep 6 +upload_command = /opt/local/sbin/arduinoOTA -address 192.168.11.172 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;sleep 6 ;upload_command = arduinoOTA -address 192.168.88.45 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE;sleep 6 upload_protocol = custom lib_ignore =