Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional fixes to rules and docs #133

Closed
wants to merge 10 commits into from
2 changes: 0 additions & 2 deletions HeishaMon/HeishaMon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ bool readSerial()
if (data_length == DATASIZE) { //receive a full data block
if (data[3] == 0x10) { //decode the normal data block
decode_heatpump_data(data, actData, mqtt_client, log_message, heishamonSettings.mqtt_topic_base, heishamonSettings.updateAllTime);
memcpy(actData, data, DATASIZE);
{
char mqtt_topic[256];
sprintf(mqtt_topic, "%s/raw/data", heishamonSettings.mqtt_topic_base);
Expand All @@ -370,7 +369,6 @@ bool readSerial()
} else if (data[3] == 0x21) { //decode the new model extra data block
extraDataBlockAvailable = true; //set the flag to true so we know we can request this data always
decode_heatpump_data_extra(data, actDataExtra, mqtt_client, log_message, heishamonSettings.mqtt_topic_base, heishamonSettings.updateAllTime);
memcpy(actDataExtra, data, DATASIZE);
{
char mqtt_topic[256];
sprintf(mqtt_topic, "%s/raw/dataextra", heishamonSettings.mqtt_topic_base);
Expand Down
36 changes: 29 additions & 7 deletions HeishaMon/decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,44 +285,66 @@ String getSecondByte(byte input) {

// Decode ////////////////////////////////////////////////////////////////////////////
void decode_heatpump_data(char* data, char* actData, PubSubClient &mqtt_client, void (*log_message)(char*), char* mqtt_topic_base, unsigned int updateAllTime) {
bool updatenow = false;
bool updateTime = false;
bool updateTopic[NUMBER_OF_TOPICS] = { false };

if ((lastalldatatime == 0) || ((unsigned long)(millis() - lastalldatatime) > (1000 * updateAllTime))) {
updatenow = true;
updateTime = true;
lastalldatatime = millis();
}
for (unsigned int Topic_Number = 0 ; Topic_Number < NUMBER_OF_TOPICS ; Topic_Number++) {
String Topic_Value;
Topic_Value = getDataValue(data, Topic_Number);

if ((updatenow) || ( getDataValue(actData, Topic_Number) != Topic_Value )) {
if(getDataValue(actData, Topic_Number) != Topic_Value) {
updateTopic[Topic_Number] = true;
}

if (updateTime || updateTopic[Topic_Number]) {
char log_msg[256];
char mqtt_topic[256];
sprintf_P(log_msg, PSTR("received TOP%d %s: %s"), Topic_Number, topics[Topic_Number], Topic_Value.c_str());
log_message(log_msg);
sprintf_P(mqtt_topic, PSTR("%s/%s/%s"), mqtt_topic_base, mqtt_topic_values, topics[Topic_Number]);
mqtt_client.publish(mqtt_topic, Topic_Value.c_str(), MQTT_RETAIN_VALUES);
}
}
memcpy(actData, data, DATASIZE);
for (unsigned int Topic_Number = 0 ; Topic_Number < NUMBER_OF_TOPICS ; Topic_Number++) {
if(updateTopic[Topic_Number]) {
rules_event_cb(_F("@"), topics[Topic_Number]);
}
}
}

void decode_heatpump_data_extra(char* data, char* actDataExtra, PubSubClient &mqtt_client, void (*log_message)(char*), char* mqtt_topic_base, unsigned int updateAllTime) {
bool updatenow = false;
bool updateTime = false;
bool updateTopic[NUMBER_OF_TOPICS_EXTRA] = { false };

if ((lastallextradatatime == 0) || ((unsigned long)(millis() - lastallextradatatime) > (1000 * updateAllTime))) {
updatenow = true;
updateTime = true;
lastallextradatatime = millis();
}
for (unsigned int Topic_Number = 0 ; Topic_Number < NUMBER_OF_TOPICS_EXTRA ; Topic_Number++) {
String Topic_Value;
Topic_Value = getDataValueExtra(data, Topic_Number);

if ((updatenow) || ( getDataValueExtra(actDataExtra, Topic_Number) != Topic_Value )) {

if(getDataValueExtra(actDataExtra, Topic_Number) != Topic_Value) {
updateTopic[Topic_Number] = true;
}

if (updateTime || updateTopic[Topic_Number]) {
char log_msg[256];
char mqtt_topic[256];
sprintf_P(log_msg, PSTR("received XTOP%d %s: %s"), Topic_Number, xtopics[Topic_Number], Topic_Value.c_str());
log_message(log_msg);
sprintf_P(mqtt_topic, PSTR("%s/%s/%s"), mqtt_topic_base, mqtt_topic_xvalues, xtopics[Topic_Number]);
mqtt_client.publish(mqtt_topic, Topic_Value.c_str(), MQTT_RETAIN_VALUES);
}
}
memcpy(actDataExtra, data, DATASIZE);
for (unsigned int Topic_Number = 0 ; Topic_Number < NUMBER_OF_TOPICS_EXTRA ; Topic_Number++) {
if(updateTopic[Topic_Number]) {
rules_event_cb(_F("@"), xtopics[Topic_Number]);
}
}
Expand Down
43 changes: 35 additions & 8 deletions HeishaMon/src/rules/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ int8_t rule_by_name(struct rules_t **rules, uint8_t nrrules, char *name) {

for(a=0;a<nrrules;a++) {
struct rules_t *obj = rules[a];
if(obj->name != NULL && strnicmp(name, obj->name, strlen(obj->name)) == 0) {
if(obj->name != NULL &&
strlen(name) == strlen(obj->name) &&
strnicmp(name, obj->name, strlen(obj->name)) == 0) {
return a;
}
}
Expand Down Expand Up @@ -1957,12 +1959,17 @@ static void bc_assign_slots(struct rules_t *obj) {
if((int8_t)getval(node->a) > 0 &&
gettype(obj->bc.buffer[a]) != OP_JMP &&
gettype(obj->bc.buffer[a]) != OP_SETVAL) {
max = MAX(max, (int8_t)getval(node->a));
if(!(gettype(obj->bc.buffer[a]) == OP_PUSH && getval(node->c) == 1)) {
max = MAX(max, (int8_t)getval(node->a));
} else {
max = 1;
}
start = a;
}
} else {
if(gettype(obj->bc.buffer[a]) != OP_JMP &&
gettype(obj->bc.buffer[a]) != OP_SETVAL
gettype(obj->bc.buffer[a]) != OP_SETVAL &&
!(gettype(obj->bc.buffer[a]) == OP_PUSH && getval(node->c) == 1)
) {
max = MAX(max, (int8_t)getval(node->a));
}
Expand All @@ -1971,12 +1978,23 @@ static void bc_assign_slots(struct rules_t *obj) {
end = bc_before(obj, a);
break;
}
if((bc_before(obj, a) >= 0) &&
if(((c = bc_before(obj, a)) >= 0) &&
((((int8_t)getval(node->a) < 0 && gettype(obj->bc.buffer[a]) != OP_PUSH)) ||
gettype(obj->bc.buffer[a]) == OP_JMP ||
gettype(obj->bc.buffer[a]) == OP_TEST ||
gettype(obj->bc.buffer[a]) == OP_RET)) {
end = bc_before(obj, a);
end = c;
break;
} else if((c = bc_next(obj, a)) >= 0 &&
gettype(obj->bc.buffer[a]) == OP_SETVAL &&
(gettype(obj->bc.buffer[c]) == OP_SETVAL ||
gettype(obj->bc.buffer[c]) == OP_GETVAL)
) {
end = a;
break;
} else if((c = bc_before(obj, a)) >= 0 &&
gettype(obj->bc.buffer[a]) == OP_SETVAL && gettype(obj->bc.buffer[c]) == OP_GETVAL) {
end = a;
break;
}
}
Expand Down Expand Up @@ -2017,7 +2035,8 @@ static void bc_assign_slots(struct rules_t *obj) {
if(z != NULL && gettype(x->type) == OP_CALL &&
gettype(z->type) == OP_PUSH &&
(int8_t)getval(z->a) >= min) {
} else if(((int8_t)getval(x->b) >= vars || (int8_t)getval(x->c) >= vars)) {
} else if(gettype(x->type) != OP_GETVAL &&
(((int8_t)getval(x->b) >= vars || (int8_t)getval(x->c) >= vars))) {
vars = MAX((int8_t)getval(x->c), (int8_t)getval(x->b));
} else {
vars--;
Expand Down Expand Up @@ -3169,7 +3188,11 @@ static int16_t rule_create(char **text, struct rules_t *obj) {
if(a == TEVENT && in_child == 0) {
if(type == TVAR) {
uint16_t c = varstack_add(text, start+1, len, 1);
bc_parent(obj, OP_SETVAL, c/sizeof(struct vm_vchar_t), 0, 0);
uint16_t d = bc_parent(obj, OP_SETVAL, c/sizeof(struct vm_vchar_t), 0, 0);
int32_t e = bc_before(obj, d);
if(e >= 0 && gettype(obj->bc.buffer[e]) != OP_GETVAL) {
mathcnt = 0;
}
} else {
/* LCOV_EXCL_START*/
logprintf_P(F("FATAL: Internal error in %s #%d"), __FUNCTION__, __LINE__);
Expand Down Expand Up @@ -3324,7 +3347,11 @@ static int16_t rule_create(char **text, struct rules_t *obj) {

uint16_t a = varstack_add(text, start+1, len, 1);

bc_parent(obj, OP_SETVAL, a/sizeof(struct vm_vchar_t), val, 0);
uint16_t b = bc_parent(obj, OP_SETVAL, a/sizeof(struct vm_vchar_t), val, 0);
int32_t c = bc_before(obj, b);
if(c >= 0 && gettype(obj->bc.buffer[c]) != OP_GETVAL) {
mathcnt = 0;
}
pos++;

if(lexer_peek(text, pos, &type, &start, &len) < 0) {
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ Sets a timer to trigger in X seconds. The first parameter is the timer number an
- `print`
Prints a value to the console.

- `concat`
Concatenates various values into a combined string. E.g.: `@SetCurves = concat('{zone1:{heat:{target:{high:', @Z1_Heat_Curve_Target_High_Temp, ',low:32}}}}');`

```
on System#Boot then
setTimer(3, 60);
Expand Down
Loading