2222#include < regex>
2323#include < mutex>
2424
25- #define RSCP2MQTT_VERSION " 3.34 "
25+ #define RSCP2MQTT_VERSION " 3.35 "
2626
2727#define AES_KEY_SIZE 32
2828#define AES_BLOCK_SIZE 32
@@ -354,7 +354,7 @@ void addTemplTopicsIdx(int index, char *seg, int start, int n, int inc, bool fin
354354 for (int c = start; c < n; c++) {
355355 for (std::vector<RSCP_MQTT::cache_t >::iterator it = RSCP_MQTT::RscpMqttCacheTempl.begin (); it != RSCP_MQTT::RscpMqttCacheTempl.end (); ++it) {
356356 if (it->index == index) {
357- RSCP_MQTT::cache_t cache = { it->container , it->tag , index + c, " " , " " , it->format , " " , it->divisor , it->bit_to_bool , it->history_log , it->changed , it->influx , it->forced };
357+ RSCP_MQTT::cache_t cache = { it->container , it->tag , index + c, " " , " " , it->format , " " , it->divisor , it->bit_to_bool , it->history_log , it->handled , it-> changed , it->influx , it->forced };
358358 if (n == 1 ) {
359359 snprintf (cache.topic , TOPIC_SIZE, it->topic , seg);
360360 } else if (seg == NULL ) {
@@ -380,7 +380,7 @@ void addTemplTopics(uint32_t container, int index, char *seg, int start, int n,
380380 for (int c = start; c < n; c++) {
381381 for (std::vector<RSCP_MQTT::cache_t >::iterator it = RSCP_MQTT::RscpMqttCacheTempl.begin (); it != RSCP_MQTT::RscpMqttCacheTempl.end (); ++it) {
382382 if (it->container == container) {
383- RSCP_MQTT::cache_t cache = { it->container , it->tag , c, " " , " " , it->format , " " , it->divisor , it->bit_to_bool , it->history_log , it->changed , it->influx , it->forced };
383+ RSCP_MQTT::cache_t cache = { it->container , it->tag , c, " " , " " , it->format , " " , it->divisor , it->bit_to_bool , it->history_log , it->handled , it-> changed , it->influx , it->forced };
384384 if (it->index > 1 ) cache.index = it->index + c * 10 ;
385385 if ((seg == NULL ) && (index == 0 )) { // no args
386386 cache.index = it->index ;
@@ -407,7 +407,7 @@ void addTemplTopics(uint32_t container, int index, char *seg, int start, int n,
407407}
408408
409409void addTopic (uint32_t container, uint32_t tag, char *topic, char *unit, int format, int divisor, int bit_to_bool, bool finalize) {
410- RSCP_MQTT::cache_t cache = { container, tag, 0 , " " , " " , format, " " , divisor, bit_to_bool, false , false , false , false };
410+ RSCP_MQTT::cache_t cache = { container, tag, 0 , " " , " " , format, " " , divisor, bit_to_bool, false , false , false , false , false };
411411 strcpy (cache.topic , topic);
412412 strcpy (cache.unit , unit);
413413 RSCP_MQTT::RscpMqttCache.push_back (cache);
@@ -692,35 +692,6 @@ void logTopics(std::vector<RSCP_MQTT::cache_t> & v, char *file, bool check_paylo
692692 return ;
693693}
694694
695- bool checkTopicOrder (std::vector<RSCP_MQTT::cache_t > & v) {
696- uint32_t container = 0 ;
697- uint32_t tag = 0 ;
698- int index = 0 ;
699- bool sorted = true ;
700- for (std::vector<RSCP_MQTT::cache_t >::iterator it = v.begin (); it != v.end (); ++it) {
701- if ((it->container < container) && (it->tag < tag) && (it->index < index)) {
702- sorted = false ;
703- break ;
704- }
705- container = it->container ;
706- tag = it->tag ;
707- index = it->index ;
708- }
709- return (sorted);
710- }
711-
712- bool checkTopicUniqueness (std::vector<RSCP_MQTT::cache_t > & v) {
713- int j;
714- for (std::vector<RSCP_MQTT::cache_t >::iterator i = v.begin (); i != v.end (); ++i) {
715- j = 0 ;
716- for (std::vector<RSCP_MQTT::cache_t >::iterator it = v.begin (); it != v.end (); ++it) {
717- if ((i->container == it->container ) && (i->tag == it->tag ) && (i->index == it->index ) && (i->bit_to_bool == it->bit_to_bool )) j++;
718- }
719- if (j > 1 ) return (false );
720- }
721- return (true );
722- }
723-
724695void logHealth (char *file) {
725696 logMessage (file, (char *)__FILE__, __LINE__, (char *)" [%s] PVI %s | PM %s | DCB %s (%d) | Wallbox %s | Autorefresh %s | Raw data %s | Interval %d\n " , RSCP2MQTT, cfg.pvi_requests ?" ✓" :" ✗" , cfg.pm_requests ?" ✓" :" ✗" , cfg.dcb_requests ?" ✓" :" ✗" , cfg.battery_strings , cfg.wallbox ?" ✓" :" ✗" , cfg.auto_refresh ?" ✓" :" ✗" , cfg.raw_mode ?" ✓" :" ✗" , cfg.interval );
726697 for (uint8_t i = 0 ; i < cfg.pm_number ; i++) {
@@ -733,8 +704,6 @@ void logHealth(char *file) {
733704 for (std::vector<RSCP_MQTT::additional_tags_t >::iterator it = RSCP_MQTT::AdditionalTags.begin (); it != RSCP_MQTT::AdditionalTags.end (); ++it) {
734705 logMessage (file, (char *)__FILE__, __LINE__, (char *)" Container >%s< Tag >%s< added (one shot: %s).\n " , tagName (RSCP_TAGS::RscpTagsOverview, it->req_container ), tagName (RSCP_TAGS::RscpTagsOverview, it->req_tag ), it->one_shot ?" true" :" false" );
735706 }
736- logMessage (file, (char *)__FILE__, __LINE__, (char *)" Topics sorted >%s<\n " , checkTopicOrder (RSCP_MQTT::RscpMqttCache)?" true" :" false" );
737- logMessage (file, (char *)__FILE__, __LINE__, (char *)" Topics unique >%s<\n " , checkTopicUniqueness (RSCP_MQTT::RscpMqttCache)?" true" :" false" );
738707 for (std::vector<RSCP_MQTT::not_supported_tags_t >::iterator it = RSCP_MQTT::NotSupportedTags.begin (); it != RSCP_MQTT::NotSupportedTags.end (); ++it) {
739708 logMessage (file, (char *)__FILE__, __LINE__, (char *)" Container >%s< Tag >%s< not supported.\n " , tagName (RSCP_TAGS::RscpTagsOverview, it->container ), tagName (RSCP_TAGS::RscpTagsOverview, it->tag ));
740709 }
@@ -782,7 +751,7 @@ void logMessage(char *file, char *srcfile, int line, char *format, ...) {
782751void copyCache (std::vector<RSCP_MQTT::cache_t > & to, std::vector<RSCP_MQTT::cache_t > & from, uint32_t container) {
783752 for (std::vector<RSCP_MQTT::cache_t >::iterator it = from.begin (); it != from.end (); ++it) {
784753 if (it->container == container) {
785- RSCP_MQTT::cache_t cache = { it->container , it->tag , it->index , " " , " " , it->format , " " , it->divisor , it->bit_to_bool , it->history_log , it->changed , it->influx , it->forced };
754+ RSCP_MQTT::cache_t cache = { it->container , it->tag , it->index , " " , " " , it->format , " " , it->divisor , it->bit_to_bool , it->history_log , it->handled , it-> changed , it->influx , it->forced };
786755 strcpy (cache.topic , it->topic );
787756 strcpy (cache.payload , it->payload );
788757 strcpy (cache.unit , it->unit );
@@ -1151,7 +1120,13 @@ int storeResponseValue(std::vector<RSCP_MQTT::cache_t> & c, RscpProtocol *protoc
11511120 static int battery_soc = -1 ;
11521121 int rc = -1 ;
11531122
1123+ // Issue #102
1124+ uint32_t old_container = 0 ;
1125+ uint32_t old_tag = 0 ;
1126+ int old_index = -1 ;
1127+
11541128 for (std::vector<RSCP_MQTT::cache_t >::iterator it = c.begin (); it != c.end (); ++it) {
1129+ if ((it->container > container) || ((old_container == it->container ) && (old_tag == it->tag ) && (old_index == it->index ) && (it->bit_to_bool == 0 ))) break ;
11551130 if ((!it->container || (it->container == container)) && (it->tag == response->tag ) && (it->index == index) && !it->handled ) {
11561131 switch (response->dataType ) {
11571132 case RSCP::eTypeBool: {
@@ -1296,7 +1271,9 @@ int storeResponseValue(std::vector<RSCP_MQTT::cache_t> & c, RscpProtocol *protoc
12961271 else battery_soc = atoi (it->payload );
12971272 }
12981273 it->handled = true ;
1299- break ;
1274+ old_container = it->container ;
1275+ old_tag = it->tag ;
1276+ old_index = it->index ;
13001277 }
13011278 }
13021279 return (rc);
@@ -2365,7 +2342,6 @@ int handleResponseValue(RscpProtocol *protocol, SRscpValue *response) {
23652342 uint32_t uiErrorCode = protocol->getValueAsUInt32 (&containerData[i]);
23662343 if (uiErrorCode == 6 ) {
23672344 pushNotSupportedTag (response->tag , containerData[i].tag );
2368- logMessageByTag (response->tag , containerData[i].tag , uiErrorCode, __LINE__, (char *)" Not supported by the device: Container >%s< Tag >%s< received >%s< [%d]\n " );
23692345 } else logMessageByTag (response->tag , containerData[i].tag , uiErrorCode, __LINE__, (char *)" Error: Container >%s< Tag >%s< received >%s< [%d]\n " );
23702346 } else {
23712347 switch (containerData[i].tag ) {
@@ -3117,6 +3093,8 @@ int main(int argc, char *argv[]) {
31173093 cfg.historyfile = strdup (value);
31183094 } else if (strcasecmp (key, " INTERVAL" ) == 0 )
31193095 cfg.interval = atoi (value);
3096+ else if ((strcasecmp (key, " VERBOSE" ) == 0 ) && (strcasecmp (value, " true" ) == 0 ))
3097+ cfg.verbose = true ;
31203098 else if ((strcasecmp (key, " PVI_REQUESTS" ) == 0 ) && (strcasecmp (value, " false" ) == 0 ))
31213099 cfg.pvi_requests = false ;
31223100 else if (strcasecmp (key, " PVI_TRACKER" ) == 0 )
@@ -3276,6 +3254,8 @@ int main(int argc, char *argv[]) {
32763254 if (env && (strcasecmp (env, " true" ) == 0 )) cfg.raw_mode = true ;
32773255 env = getenv (" WALLBOX" );
32783256 if (env && (strcasecmp (env, " true" ) == 0 )) cfg.wallbox = true ;
3257+ env = getenv (" VERBOSE" );
3258+ if (env && (strcasecmp (env, " true" ) == 0 )) cfg.verbose = true ;
32793259 env = getenv (" PVI_TRACKER" );
32803260 if (env) cfg.pvi_tracker = atoi (env);
32813261 env = getenv (" BATTERY_STRINGS" );
0 commit comments