From bf9c7bbc2a53c0fbcc4d41afa2567bc8d257e5ac Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Sat, 9 Feb 2013 18:41:17 -0800 Subject: [PATCH] obd2 will only update when changed --- lib/abstractpropertytype.h | 7 +++++++ lib/debugout.h | 2 ++ plugins/obd2plugin/obd2source.cpp | 16 +++++++++++++++- plugins/obd2plugin/obd2source.h | 3 ++- plugins/obd2plugin/obdpid.h | 5 ++++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h index df32308..d17cb37 100644 --- a/lib/abstractpropertytype.h +++ b/lib/abstractpropertytype.h @@ -47,6 +47,13 @@ public: virtual AbstractPropertyType* copy() = 0; + bool operator == (AbstractPropertyType &other) + { + std::string one = toString(); + std::string two = other.toString(); + return one == two; + } + double timestamp; int32_t sequence; diff --git a/lib/debugout.h b/lib/debugout.h index b25f1a3..6c7ed32 100644 --- a/lib/debugout.h +++ b/lib/debugout.h @@ -101,7 +101,9 @@ private: std::string bufferTime(double time) { ostringstream f; + f.precision(15); + f<updateProperty(property,&value); + if (propertyReplyMap.find(property) != propertyReplyMap.end()) { @@ -414,6 +414,20 @@ void OBD2Source::updateProperty(VehicleProperty::Property property,AbstractPrope } else { + if(oldValueMap.find(property) != oldValueMap.end()) + { + AbstractPropertyType* old = oldValueMap[property]; + + if((*old) == (*value)) + { + return; + } + + delete old; + } + + oldValueMap[property] = value->copy(); + m_re->updateProperty(property,value,uuid()); } } diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h index a224dab..685a7f8 100644 --- a/plugins/obd2plugin/obd2source.h +++ b/plugins/obd2plugin/obd2source.h @@ -104,7 +104,7 @@ public: } ObdPid* pid = (*itr)->create(); - pid->tryParse(replyVector); + //pid->tryParse(replyVector); return pid; } return 0; @@ -177,6 +177,7 @@ public: private: PropertyList m_supportedProperties; + std::map oldValueMap; GMutex *threadQueueMutex; typedef BasicPropertyType Obd2ConnectType; diff --git a/plugins/obd2plugin/obdpid.h b/plugins/obd2plugin/obdpid.h index 2625175..5f0f05d 100644 --- a/plugins/obd2plugin/obdpid.h +++ b/plugins/obd2plugin/obdpid.h @@ -73,7 +73,10 @@ public: ObdPid* create() { - return new T(); + T* t = new T(); + t->value = value; + t->isValidVal = isValidVal; + return t; } }; -- 2.7.4