diff --git a/compiled/lighthub21/upload.sh b/compiled/lighthub21/upload.sh index 93e8a0a..4d3f7a3 100755 --- a/compiled/lighthub21/upload.sh +++ b/compiled/lighthub21/upload.sh @@ -1,3 +1,3 @@ -export PORT=cu.usbmodem14101 +export PORT=cu.usbmodem141101 echo . | stty -f /dev/$PORT speed 1200 -../tools/mac/tool-bossac/bossac -U false -p $PORT -i -e -w -v -b firmware.bin -R \ No newline at end of file +../tools/mac/tool-bossac/bossac -U false -p $PORT -i -w -v -b firmware.bin -R \ No newline at end of file diff --git a/lighthub/abstractch.h b/lighthub/abstractch.h index 80431a3..bfc8794 100644 --- a/lighthub/abstractch.h +++ b/lighthub/abstractch.h @@ -11,7 +11,7 @@ public: virtual ~abstractCh(){}; virtual int Poll(short cause) {return 0;} virtual int Setup() =0; //Should initialize hardware and reserve resources - virtual int Anounce () {return 0;}; + // virtual int Anounce () {return 0;}; virtual int Stop() {return 0;}; //Should free resources virtual int Status() {return CST_UNKNOWN;} virtual void setStatus(uint8_t status) {} diff --git a/lighthub/abstractout.h b/lighthub/abstractout.h index ae86136..7168a2f 100644 --- a/lighthub/abstractout.h +++ b/lighthub/abstractout.h @@ -13,7 +13,7 @@ public: virtual bool isAllowed(itemCmd cmd){return true;}; virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);}; virtual int getChanType(){return 0;} - virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead + // virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead virtual int Status() override; virtual void setStatus(uint8_t status) override; int Setup() override; diff --git a/lighthub/colorchannel.cpp b/lighthub/colorchannel.cpp index 7873626..818092a 100644 --- a/lighthub/colorchannel.cpp +++ b/lighthub/colorchannel.cpp @@ -16,7 +16,7 @@ short colorChannel::getChannelAddr(short n) return item->getArg(n); } - +/* int colorChannel::getDefaultStorageType() { @@ -33,7 +33,7 @@ int colorChannel::getDefaultStorageType() return ST_VOID; } -/* + int colorChannel::isActive() { itemCmd st; @@ -58,7 +58,6 @@ case S_NOTFOUND: // turn on and set toExecute = true; case S_SET: -//case S_ESET: case S_HSV: PixelCtrl(cmd, subItem, toExecute, authorized); return 1; diff --git a/lighthub/colorchannel.h b/lighthub/colorchannel.h index f6dae16..26807d1 100644 --- a/lighthub/colorchannel.h +++ b/lighthub/colorchannel.h @@ -15,7 +15,7 @@ public: numArgs = item->getArgCount(); // and how many addresses is configured }; int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override; - int getDefaultStorageType()override; + //int getDefaultStorageType()override; virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true, bool authorized = false ) =0; short getChannelAddr(short n =0); // int isActive() override; diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 4df658b..903582e 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -104,8 +104,15 @@ int subitem2cmd(char *payload) { } int txt2subItem(char *payload) { - int cmd = S_NOTFOUND; if (!payload || !strlen(payload)) return S_NOTFOUND; + for(uint8_t i=1; i")<")<child; - while (items && item) - if (item->type == aJson_Array && aJson.getArraySize(item)>1) { - Item it(item); - if (it.isValid()) { - - short res = it.checkModbusRetry(); - if (res<=0) success = false; - - } //isValid - yield(); - item = item->next; - } //if -debugSerial<= (MODBUS_CMD_ARG_REG_TYPE+1)) _regType = aJson.getArrayItem(itemArg, MODBUS_CMD_ARG_REG_TYPE)->valueint; - // short mask = getArg(2); - // debugSerial<")); - // debugSerial< +//#define KEYLEN 8 +extern aJsonObject * topics; + +class templateStream : public Stream +{ +public: + templateStream(char *s, short sfx=0) : str(s), pos(0), val(NULL), valpos(0), bucket(0),suffix(sfx) { } + + // Stream methods + virtual int available() { return str[pos]; } + virtual int read() { + if (bucket) + + { int ch = bucket; + bucket=0; + return ch; + }; + + if (str[pos]=='$') + { + if (str[pos+1]=='{') + { + unsigned int i = 0; + while (str[pos+2+i] && str[pos+2+i]!='}') i++; + if (i && (str[pos+2+i]=='}')) + { + str[pos+2+i]='\0'; + val=resolveKey(str+pos+2); + str[pos+2+i]='}'; + pos+=3+i; + } + } + } + + if (val) + { + char ch = val[valpos]; + if (ch) + { + valpos++; + return ch; + } + else val = NULL; + + } + + if (str) + { + char ch = str[pos]; + if (ch) + { + pos++; + return ch; + } + else + { + str=NULL; + return 0; + } + + } + else return -1; + + } + virtual int peek() + { + int bucket = read(); + return bucket; + } + + virtual void flush() { }; + // Print methods + virtual size_t write(uint8_t c) { return 0; }; + virtual char * resolveKey(char *key) + { + if (topics && topics->type == aJson_Object) + { + aJsonObject *valObj = aJson.getObjectItem(topics, key); + if (valObj->type == aJson_String) return valObj->valuestring; + + } + if (suffix && (suffix<=suffixNum) && !strcmp(key,"sfx")) + { + buffer[0]='/'; + strncpy_P(buffer+1,suffix_P[suffix],sizeof(buffer)-2); + return buffer; + } + + return NULL; + } + +private: + char *str; + unsigned int pos; + char *val; + unsigned int valpos; + int bucket; + short suffix; + char buffer[8]; +}; + +#endif // _TEMPLATE_STREAM_H_ \ No newline at end of file diff --git a/lighthub/textconst.h b/lighthub/textconst.h index f6e01e2..14e8d20 100644 --- a/lighthub/textconst.h +++ b/lighthub/textconst.h @@ -82,17 +82,29 @@ const char on_P[] PROGMEM = "on"; */ +#define ON_P commands_P[CMD_ON] +#define OFF_P commands_P[CMD_OFF] +#define REST_P commands_P[CMD_RESTORE] +#define TOGGLE_P commands_P[CMD_TOGGLE] +#define HALT_P commands_P[CMD_HALT] +#define XON_P commands_P[CMD_XON] +#define XOFF_P commands_P[CMD_XOFF] +#define HEAT_P commands_P[CMD_HEAT] +#define COOL_P commands_P[CMD_COOL] +#define AUTO_P commands_P[CMD_AUTO] +#define FAN_ONLY_P commands_P[CMD_FAN] +#define DRY_P commands_P[CMD_DRY] +#define HIGH_P commands_P[CMD_HIGH] +#define MED_P commands_P[CMD_MED] +#define LOW_P commands_P[CMD_LOW] +#define ENABLE_P commands_P[CMD_ENABLE] +#define DISABLE_P commands_P[CMD_DISABLE] +#define FREEZE_P commands_P[CMD_FREEZE] +#define UNFREEZE_P commands_P[CMD_UNFREEZE] +const char ERROR_P[] PROGMEM = "ERR"; //Commands - -const char ON_P[] PROGMEM = "ON"; -const char OFF_P[] PROGMEM = "OFF"; -const char REST_P[] PROGMEM = "REST"; -const char TOGGLE_P[] PROGMEM = "TOGGLE"; -const char HALT_P[] PROGMEM = "HALT"; -const char XON_P[] PROGMEM = "XON"; -const char XOFF_P[] PROGMEM = "XOFF"; /* const char INCREASE_P[] PROGMEM = "INCREASE"; const char DECREASE_P[] PROGMEM = "DECREASE"; @@ -102,6 +114,15 @@ const char FALSE_P[] PROGMEM = "FALSE"; const char ENABLED_P[] PROGMEM = "ENABLED"; const char DISABLED_P[] PROGMEM = "DISABLED"; */ + +/* +const char ON_P[] PROGMEM = "ON"; +const char OFF_P[] PROGMEM = "OFF"; +const char REST_P[] PROGMEM = "REST"; +const char TOGGLE_P[] PROGMEM = "TOGGLE"; +const char HALT_P[] PROGMEM = "HALT"; +const char XON_P[] PROGMEM = "XON"; +const char XOFF_P[] PROGMEM = "XOFF"; const char HEAT_P[] PROGMEM = "HEAT"; const char COOL_P[] PROGMEM = "COOL"; const static char AUTO_P[] PROGMEM = "AUTO"; @@ -112,13 +133,15 @@ const char DRY_P[] PROGMEM = "DRY"; const char HIGH_P[] PROGMEM = "HIGH"; const char MED_P[] PROGMEM = "MEDIUM"; const char LOW_P[] PROGMEM = "LOW"; -const char ERROR_P[] PROGMEM = "ERR"; + const char ENABLE_P[] PROGMEM = "ENABLE"; const char DISABLE_P[] PROGMEM = "DISABLE"; const char FREEZE_P[] PROGMEM = "FREEZE"; const char UNFREEZE_P[] PROGMEM = "UNFREEZE"; +*/ // SubTopics +/* const char SET_P[] PROGMEM = "set"; const char CMD_P[] PROGMEM = "cmd"; const char MODE_P[] PROGMEM = "mode"; @@ -132,7 +155,7 @@ const char VAL_P[] PROGMEM = "val"; const char DEL_P[] PROGMEM = "del"; const char _RAW_P[] PROGMEM = "raw"; const char CTRL_P[] PROGMEM = "ctrl"; - +*/ /* const char RPM_P[] PROGMEM = "rpm"; const char STATE_P[] PROGMEM = "state"; diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 62bbbe5..da64304 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -27,6 +27,7 @@ e-mail anklimov@gmail.com #include "item.h" #include #include +#include "templateStr.h" #ifdef CRYPT #include "SHA256.h" @@ -690,8 +691,17 @@ switch (cmdType) //else itemCommand = _itemCmd.toString(Buffer,sizeof(Buffer)); char * emitCommand; + short suffix=0; + // aJsonObject * dict=NULL; + if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring; - else emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer)); + else + { + emitCommand = _itemCmd.toString(Buffer,sizeof(Buffer)); + // dict = aJson.createObject(); + // aJson.addStringToObject(dict, "sfx", ) + suffix=_itemCmd.getSuffix(); + } //debugSerial << F("IN:") << (pin) << F(" : ") <type == aJson_String) { - debugSerial << F("Emit: ")<valuestring<< F(" -> ")<valuestring,suffix); + char addrstr[MQTT_TOPIC_LENGTH]; + //ts.setTimeout(0); + addrstr[ts.readBytesUntil('\0',addrstr,sizeof(addrstr))]='\0'; + debugSerial << F("Emit: ")<valuestring<<" "< ")<valuestring,sizeof(addrstr)); + + //strncpy(addrstr,emit->valuestring,sizeof(addrstr)); if (mqttClient.connected() && !ethernetIdleCount) { if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring); @@ -916,5 +931,8 @@ if (oneWire && oneWire->checkPresence()) return true; } + + + #pragma message(VAR_NAME_VALUE(debugSerial)) #pragma message(VAR_NAME_VALUE(SERIAL_BAUD))