fix flash_64kb error. debugSerial in Item.cpp

This commit is contained in:
livello
2018-11-07 13:49:30 +03:00
parent 9ea9ad8698
commit 23f2e60079
3 changed files with 15 additions and 31 deletions

View File

@@ -81,20 +81,10 @@ void Item::Parse() {
for (int i = aJson.getArraySize(itemArr); i < 4; i++) for (int i = aJson.getArraySize(itemArr); i < 4; i++)
aJson.addItemToArray(itemArr, aJson.createItem( aJson.addItemToArray(itemArr, aJson.createItem(
int(defval[i]))); //Enlarge item to 4 elements. VAL=int if no other definition in conf int(defval[i]))); //Enlarge item to 4 elements. VAL=int if no other definition in conf
itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint; itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
itemArg = aJson.getArrayItem(itemArr, I_ARG); itemArg = aJson.getArrayItem(itemArr, I_ARG);
itemVal = aJson.getArrayItem(itemArr, I_VAL); itemVal = aJson.getArrayItem(itemArr, I_VAL);
debugSerial << (F(" Item:") << itemArr->name << F(" T:") << itemType << F(" =") << getArg() << eol;
/*
Serial.print(F(" Item:"));
Serial.print(itemArr->name);
Serial.print(F(" T:"));
Serial.print(itemType);
Serial.print(F(" ="));
Serial.println(getArg());
*/
} }
} }
@@ -117,13 +107,12 @@ uint8_t Item::getCmd(bool ext) {
} }
void Item::setCmd(uint8_t cmd) { void Item::setCmd(uint8_t cmdValue) {
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD); aJsonObject *itemCmd = aJson.getArrayItem(itemArr, I_CMD);
if (t) if (itemCmd)
{ {
t->valueint = cmd; itemCmd->valueint = cmdValue;
Serial.print(F("SetCmd:")); debugSerial<<F("SetCmd:")<<cmdValue<<eol;
Serial.println(cmd);
} }
} }
@@ -176,9 +165,7 @@ void Item::setVal(short n, int par) // Only store if VAL is array defined in c
void Item::setVal(long int par) // Only store if VAL is int (autogenerated or config-defined) void Item::setVal(long int par) // Only store if VAL is int (autogenerated or config-defined)
{ {
if (!itemVal || itemVal->type != aJson_Int) return; if (!itemVal || itemVal->type != aJson_Int) return;
// Serial.print(F(" Store ")); debugSerial<<F(" Store ")<<F(" Val=")<<par<<eol;
// Serial.print(F(" Val="));
// Serial.println(par);
itemVal->valueint = par; itemVal->valueint = par;
} }
@@ -262,7 +249,7 @@ int Item::Ctrl(char * payload, boolean send){
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) { int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
Serial.print(F("Cmd="));Serial.print(cmd);Serial.print(F(" MEM="));Serial.println(freeRam()); debugSerial<<F("Cmd=")<<cmd<<F(" MEM=")<<freeRam()<<eol;
int Par[MAXCTRLPAR] = {0, 0, 0}; int Par[MAXCTRLPAR] = {0, 0, 0};
if (Parameters) if (Parameters)
@@ -1238,7 +1225,7 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
int chancmd=getCmd(true); int chancmd=getCmd(true);
if (deffered) { if (deffered) {
setCmd(chancmd | CMD_REPORT); setCmd(chancmd | CMD_REPORT);
Serial.println(F("Status deffered")); debugSerial<<F("Status deffered\n");
// mqttClient.publish("/push", "1"); // mqttClient.publish("/push", "1");
return 0; return 0;
// Todo: Parameters? Now expected that parameters already stored by setVal() // Todo: Parameters? Now expected that parameters already stored by setVal()
@@ -1269,8 +1256,9 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
char num[4]; char num[4];
#ifndef FLASH_64KB #ifndef FLASH_64KB
snprintf(num, sizeof(num), "%d", Par[i]); snprintf(num, sizeof(num), "%d", Par[i]);
#endif #else
itoa(Par[i],num,10); itoa(Par[i],num,10);
#endif
strncat(valstr, num, sizeof(valstr)); strncat(valstr, num, sizeof(valstr));
if (i != n - 1) { if (i != n - 1) {
strcpy(num, ","); strcpy(num, ",");
@@ -1279,13 +1267,10 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
} }
break; break;
default: default:
Serial.println(F("Unknown cmd ")); debugSerial<<F("Unknown cmd \n");
return -1; return -1;
} }
Serial.print(F("Pub: ")); debugSerial<<F("Pub: ")<<addrstr<<F("->")<<valstr<<eol;
Serial.print(addrstr);
Serial.print(F("->"));
Serial.println(valstr);
mqttClient.publish(addrstr, valstr,true); mqttClient.publish(addrstr, valstr,true);
return 0; return 0;
} }

View File

@@ -112,7 +112,7 @@ class Item
//int getVal(short n); //From VAL array. Negative if no array //int getVal(short n); //From VAL array. Negative if no array
long int getVal(); //From int val OR array long int getVal(); //From int val OR array
uint8_t getCmd(bool ext = false); uint8_t getCmd(bool ext = false);
void setCmd(uint8_t cmd); void setCmd(uint8_t cmdValue);
//void setVal(uint8_t n, int par); //void setVal(uint8_t n, int par);
void setVal(long int par); void setVal(long int par);
//void copyPar (aJsonObject *itemV); //void copyPar (aJsonObject *itemV);

View File

@@ -246,7 +246,6 @@ lib_deps =
Streaming Streaming
https://github.com/livello/PrintEx#is-select-redecl https://github.com/livello/PrintEx#is-select-redecl
;TODO:STM32 compilation problems
[env:stm32] [env:stm32]
platform = ststm32 platform = ststm32
framework = arduino framework = arduino