From 979349a38e17415421dfb235e5e21194d6132949 Mon Sep 17 00:00:00 2001 From: livello Date: Fri, 9 Nov 2018 02:12:53 +0300 Subject: [PATCH] freeRam stub removed. debugSerial + small refactoring and code format --- lighthub/item.cpp | 254 ++++++++++++++++----------------------------- lighthub/utils.cpp | 13 +-- 2 files changed, 93 insertions(+), 174 deletions(-) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 8e6859c..fd05477 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -84,7 +84,7 @@ void Item::Parse() { itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint; itemArg = aJson.getArrayItem(itemArr, I_ARG); itemVal = aJson.getArrayItem(itemArr, I_VAL); - debugSerial << (F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << eol; + debugSerial << F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << eol; } } @@ -154,7 +154,7 @@ long int Item::getVal() //Return Val if val is int or first elem of Value array void Item::setVal(short n, int par) // Only store if VAL is array defined in config to avoid waste of RAM { if (!itemVal || itemVal->type!=aJson_Array) return; - Serial.print(F(" Store p="));Serial.print(n);Serial.print(F(" Val="));Serial.println(par); + debugSerial<type == aJson_Array) { - Serial.println(F("Grp check: ")); + debugSerial<child; while (i) { Item it(i->valuestring); if (it.isValid() && it.isActive()) { - Serial.println(F("Active")); + debugSerial<next; @@ -723,8 +686,8 @@ int Item::isActive() { case CH_PWM: val = st.aslong; } //switch - //Serial.print(F(":=")); - //Serial.println(val); + //debugSerial<")); - Serial.print(_reg, HEX); - Serial.print(F("(T:")); - Serial.print(_regType); - Serial.print(F("):")); - Serial.println(value, HEX); - + debugSerial<")<<_HEX(_reg)<type == aJson_Array) - { aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1); - if (airGateObj) { - int val = 100; - Item item(airGateObj->valuestring); - if (item.isValid()) item.Ctrl(0,1,&val); - } - } - Serial.println(); - } else { - Serial.print(F("Modbus polling error=")); - Serial.println(result, HEX); - } + if (RPM && itemArg->type == aJson_Array) { + aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1); + if (airGateObj) { + int val = 100; + Item item(airGateObj->valuestring); + if (item.isValid()) + item.Ctrl(0, 1, &val); + } + } + } else + debugSerial << F("Modbus polling error=") << _HEX(result) << eol; if (node.getResponseBuffer(0) & 8) //Active fault { @@ -997,40 +932,33 @@ int Item::checkFM() { // do something with data if read is successful if (result == node.ku8MBSuccess) { - Serial.print(F(" PI Val :")); + debugSerial << F(" PI Val :"); for (j = 0; j < 4; j++) { data = node.getResponseBuffer(j); - Serial.print(data); - Serial.print(F("-")); - + debugSerial << data << F("-"); } - + debugSerial << eol; int set = node.getResponseBuffer(0); - float fset; - float ftemp; - if (set) aJson.addNumberToObject(out, "set", fset =set * a + b); - aJson.addNumberToObject(out, "t", ftemp =(int) node.getResponseBuffer(1) * a + b); + float ftemp, fset = set * a + b; + if (set) + aJson.addNumberToObject(out, "set", fset); + aJson.addNumberToObject(out, "t", ftemp = (int) node.getResponseBuffer(1) * a + b); // aJson.addNumberToObject(out,"d", (int) node.getResponseBuffer(2)*a+b); int pwr = node.getResponseBuffer(3); - if (pwr > 0) aJson.addNumberToObject(out, "pwr", pwr / 10.); else aJson.addNumberToObject(out, "pwr", 0); + if (pwr > 0) + aJson.addNumberToObject(out, "pwr", pwr / 10.); + else aJson.addNumberToObject(out, "pwr", 0); - if (ftemp>FM_OVERHEAT_CELSIUS && set) - { + if (ftemp > FM_OVERHEAT_CELSIUS && set) { mqttClient.publish("/alarm/ovrht", itemArr->name); Ctrl(CMD_OFF); //Shut down - } - Serial.println(); - } else { - Serial.print(F("Modbus polling error=")); - Serial.println(result, HEX); - } - - + } + } else + debugSerial << F("Modbus polling error=") << _HEX(result); outch = aJson.print(out); mqttClient.publish(addrstr, outch); free(outch); aJson.deleteItem(out); - modbusBusy = 0; } @@ -1038,7 +966,7 @@ boolean Item::checkModbusRetry() { int cmd = getCmd(true); if (cmd & CMD_RETRY) { // if last sending attempt of command was failed int val = getVal(); - Serial.println(F("Retrying CMD")); + debugSerial<type != aJson_Array) || ((numpar = aJson.getArraySize(itemArg)) < 2)) { - Serial.println(F("Illegal arguments")); + debugSerial<= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint; // short mask = getArg(2); - // Serial.print(F("Modbus polling ")); - // Serial.print(addr); - // Serial.print(F("=>")); - // Serial.print(reg, HEX); - // Serial.print(F("(T:")); - // Serial.print(_regType); - // Serial.println(F(")")); + // debugSerial<")); + // debugSerial<name); - Serial.print(F(" Val: ")); - Serial.println(data, HEX); + debugSerial << F("MB: ") << itemArr->name << F(" Val: ") << _HEX(data) << eol; checkModbusDimmer(data); - } else { - Serial.print(F("Modbus polling error=")); - Serial.println(result, HEX); - } - + } else + debugSerial << F("Modbus polling error=") << _HEX(result) << eol; modbusBusy = 0; // Looking 1 step ahead for modbus item, which uses same register @@ -1118,9 +1040,9 @@ int Item::checkModbusDimmer() { nextItem.getArg(1) == reg) { nextItem.checkModbusDimmer(data); pollingItem = pollingItem->next; - if (!pollingItem) pollingItem = items->child; + if (!pollingItem) + pollingItem = items->child; } - } @@ -1138,7 +1060,7 @@ int Item::checkModbusDimmer(int data) { if (maxVal) d = map(d, 0, maxVal, 0, 100); int cmd = getCmd(); - //Serial.println(d); + //debugSerial<> 4, HEX); - Serial.print(addr[i] & 0x0f, HEX); + debugSerial<<_HEX(addr[i] >> 4); + debugSerial<<_HEX(addr[i] & 0x0f); } if (newline) - Serial.println(); + debugSerial<