From 3ba98c1fba53d7c86fc3e45cb7d371b818247b40 Mon Sep 17 00:00:00 2001 From: john30 Date: Thu, 11 Dec 2014 22:45:13 +0100 Subject: [PATCH] changed type definition to check first char for r/w, last char of type starting with r for priority digit, and last char of non r/w types (=update type) for "w" indicating update write --- src/lib/ebus/message.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 0a245af7..e77e4e80 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -74,7 +74,7 @@ result_t Message::create(vector::iterator& it, const vector::ite // [type],[class],name,[comment],[QQ],ZZ,id,fields... result_t result; bool isSet = false, isPassive = false; - char defaultsChar; + string defaultName; unsigned int pollPriority = 0; size_t defaultPos = 1; if (it == end) @@ -83,28 +83,31 @@ result_t Message::create(vector::iterator& it, const vector::ite const char* str = (*it++).c_str(); if (it == end) return RESULT_ERR_EOF; - if (str[0] == 0 || strncasecmp(str, "R", 1) == 0) { // default: active get - defaultsChar = 'r'; + size_t len = strlen(str); + if (len == 0) { // default: active get + defaultName = "r"; + } else if (strncasecmp(str, "R", 1) == 0) { // active get + char last = str[len-1]; + if (last >= '0' && last <= '9') { // poll priority (=active get) + pollPriority = last - '0'; + defaultName = string(str).substr(0, len-1); // cut off priority digit + } + else + defaultName = str; } else if (strncasecmp(str, "W", 1) == 0) { // active set isSet = true; - defaultsChar = 'w'; - } else if (str[0] >= '0' && str[0] <= '9') { // poll priority (=active get) - result_t result; - pollPriority = parseInt(str, 10, 0, 9, result); // priority is the same as "r" - if (result != RESULT_OK) - return result; - defaultsChar = 'r'; + defaultName = str; } else { // any other: passive set/get isPassive = true; - isSet = strcasecmp(str+strlen(str)-1, "W") == 0; // if type ends with "w" it is treated as passive set - defaultsChar = str[0]; // TODO better not case sensitive, also in defaults definition + isSet = strcasecmp(str+len-1, "W") == 0; // if type ends with "w" it is treated as passive set + defaultName = str; } vector* defaults = NULL; if (defaultsRows != NULL && defaultsRows->size() > 0) { for (vector< vector >::reverse_iterator it = defaultsRows->rbegin(); it != defaultsRows->rend(); it++) { string check = (*it)[0]; - if (check[0] == defaultsChar) { // TODO better not case sensitive + if (check == defaultName) { defaults = &(*it); break; }