mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 20:56:37 +00:00
New object parser
This commit is contained in:
parent
30f25813d4
commit
109991cd01
@ -91,37 +91,79 @@ void dispatch_json_error(uint8_t tag, DeserializationError & jsonError)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// p[x].b[y].attr=value
|
// p[x].b[y].attr=value
|
||||||
inline bool dispatch_process_button_attribute(const char * topic_p, const char * payload)
|
static inline bool dispatch_parse_button_attribute(const char * topic_p, const char * payload)
|
||||||
{
|
{
|
||||||
// Log.verbose(TAG_MSGR,F("BTN ATTR: %s = %s"), strTopic.c_str(), payload);
|
long num;
|
||||||
|
char * pEnd;
|
||||||
|
uint8_t pageid, objid;
|
||||||
|
|
||||||
unsigned int pageid, objid;
|
if(*topic_p != 'p' && *topic_p != 'P') return false; // obligated p
|
||||||
// const char * topic_p = strTopic.c_str();
|
topic_p++;
|
||||||
|
|
||||||
if(sscanf(topic_p, HASP_OBJECT_NOTATION ".", &pageid, &objid) == 2) { // Literal String
|
if(*topic_p == '[') { // optional brackets, TODO: remove
|
||||||
|
topic_p++;
|
||||||
// OK, continue below
|
num = strtol(topic_p, &pEnd, DEC);
|
||||||
|
if(*pEnd != ']') return false; // obligated closing bracket
|
||||||
} else if(sscanf(topic_p, "p[%u].b[%u].", &pageid, &objid) == 2) { // Literal String
|
pEnd++;
|
||||||
|
|
||||||
// TODO: obsolete old syntax p[x].b[y].
|
|
||||||
// OK, continue below
|
|
||||||
while(*topic_p++ != '.') {
|
|
||||||
// strip to '.' character
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
num = strtol(topic_p, &pEnd, DEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(*topic_p != '.') {
|
if(num < 0 || num > HASP_NUM_PAGES) return false; // page number must be valid
|
||||||
if(*topic_p == 0) return false; // strip to '.' character
|
|
||||||
|
pageid = (uint8_t)num;
|
||||||
|
topic_p = pEnd;
|
||||||
|
|
||||||
|
if(*topic_p == '.') topic_p++; // optional separator
|
||||||
|
|
||||||
|
if(*topic_p != 'b' && *topic_p != 'B') return false; // obligated b
|
||||||
|
topic_p++;
|
||||||
|
|
||||||
|
if(*topic_p == '[') { // optional brackets, TODO: remove
|
||||||
topic_p++;
|
topic_p++;
|
||||||
|
num = strtol(topic_p, &pEnd, DEC);
|
||||||
|
if(*pEnd != ']') return false; // obligated closing bracket
|
||||||
|
pEnd++;
|
||||||
|
} else {
|
||||||
|
num = strtol(topic_p, &pEnd, DEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasp_process_attribute((uint8_t)pageid, (uint8_t)objid, topic_p, payload);
|
if(num < 0 || num > 255) return false; // id must be valid
|
||||||
|
objid = (uint8_t)num;
|
||||||
|
topic_p = pEnd;
|
||||||
|
|
||||||
|
if(*topic_p != '.') return false; // obligated seperator
|
||||||
|
topic_p++;
|
||||||
|
|
||||||
|
hasp_process_attribute(pageid, objid, topic_p, payload);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(sscanf(topic_p, HASP_OBJECT_NOTATION ".", &pageid, &objid) == 2) { // Literal String
|
||||||
|
|
||||||
|
// OK, continue below
|
||||||
|
|
||||||
|
} else if(sscanf(topic_p, "p[%u].b[%u].", &pageid, &objid) == 2) { // Literal String
|
||||||
|
|
||||||
|
// TODO: obsolete old syntax p[x].b[y].
|
||||||
|
// OK, continue below
|
||||||
|
while(*topic_p++ != '.') {
|
||||||
|
// strip to '.' character
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(*topic_p != '.') {
|
||||||
|
if(*topic_p == 0) return false; // strip to '.' character
|
||||||
|
topic_p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasp_process_attribute((uint8_t)pageid, (uint8_t)objid, topic_p, payload);
|
||||||
|
return true; */
|
||||||
|
|
||||||
// String strPageId((char *)0);
|
// String strPageId((char *)0);
|
||||||
// String strTemp((char *)0);
|
// String strTemp((char *)0);
|
||||||
|
|
||||||
@ -168,7 +210,7 @@ void dispatch_command(const char * topic, const char * payload)
|
|||||||
// } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) {
|
// } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) {
|
||||||
// guiTakeScreenshot("/screenshot.bmp"); // Literal String
|
// guiTakeScreenshot("/screenshot.bmp"); // Literal String
|
||||||
|
|
||||||
} else if(topic[0] == 'p' && dispatch_process_button_attribute(topic, payload)) {
|
} else if((topic[0] == 'p' || topic[0] == 'P') && dispatch_parse_button_attribute(topic, payload)) {
|
||||||
return; // matched pxby.attr
|
return; // matched pxby.attr
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
@ -872,7 +914,6 @@ void dispatch_calibrate(const char * topic = NULL, const char * payload = NULL)
|
|||||||
|
|
||||||
void dispatch_wakeup(const char *, const char *)
|
void dispatch_wakeup(const char *, const char *)
|
||||||
{
|
{
|
||||||
// dispatch_calibrate();
|
|
||||||
lv_disp_trig_activity(NULL);
|
lv_disp_trig_activity(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -885,7 +926,7 @@ void dispatch_factory_reset(const char *, const char *)
|
|||||||
{
|
{
|
||||||
dispatch_factory_reset();
|
dispatch_factory_reset();
|
||||||
delay(500);
|
delay(500);
|
||||||
dispatch_reboot(false); // don't save config
|
dispatch_reboot(false); // don't save running config
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************* Commands builder *******************************************/
|
/******************************************* Commands builder *******************************************/
|
||||||
@ -906,7 +947,7 @@ static void dispatch_add_command(const char * p_cmdstr, void (*func)(const char
|
|||||||
void dispatchSetup()
|
void dispatchSetup()
|
||||||
{
|
{
|
||||||
// In order of importance : commands are NOT case-sensitive
|
// In order of importance : commands are NOT case-sensitive
|
||||||
// The command.func() call will receive the full payload as ONLY parameter!
|
// The command.func() call will receive the full topic and payload parameters!
|
||||||
|
|
||||||
/* WARNING: remember to expand the commands array when adding new commands */
|
/* WARNING: remember to expand the commands array when adding new commands */
|
||||||
dispatch_add_command(PSTR("json"), dispatch_parse_json);
|
dispatch_add_command(PSTR("json"), dispatch_parse_json);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user