From bf1aeccc9db9e484b1505bc00a5b469e7334dfa6 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Tue, 20 Nov 2012 15:10:31 -0800 Subject: [PATCH] initial sequence and timestamp support --- ambd/core.cpp | 4 +- ambd/core.h | 2 +- lib/CMakeLists.txt | 2 +- lib/abstractroutingengine.h | 2 +- lib/abstractsink.h | 2 +- lib/timestamp.h | 19 ++++ plugins/database/databasesink.cpp | 78 ++++++++++++++++ plugins/database/databasesink.h | 105 ++++++++++++++++++++-- plugins/dbus/dbusplugin.cpp | 2 +- plugins/dbus/dbusplugin.h | 2 +- plugins/demosink/demosinkplugin.cpp | 2 +- plugins/demosink/demosinkplugin.h | 2 +- plugins/exampleplugin.cpp | 15 ++-- plugins/exampleplugin.h | 2 +- plugins/examplesink.cpp | 2 +- plugins/examplesink.h | 2 +- plugins/obd2plugin/obd2source.cpp | 12 +-- plugins/obd2plugin/obd2source.h | 2 +- plugins/tpms/tpmsplugin.cpp | 17 ++-- plugins/tpms/tpmsplugin.h | 2 +- plugins/websocketsink/websocketsink.cpp | 2 +- plugins/websocketsink/websocketsink.h | 2 +- plugins/websocketsourceplugin/websocketsource.cpp | 5 +- plugins/websocketsourceplugin/websocketsource.h | 2 +- plugins/wheel/wheelplugin.cpp | 37 ++++---- plugins/wheel/wheelplugin.h | 2 +- 26 files changed, 258 insertions(+), 68 deletions(-) create mode 100644 lib/timestamp.h diff --git a/ambd/core.cpp b/ambd/core.cpp index 78e4a84..c8e8e02 100644 --- a/ambd/core.cpp +++ b/ambd/core.cpp @@ -140,7 +140,7 @@ void Core::updateSupported(PropertyList added, PropertyList removed) } } -void Core::updateProperty(VehicleProperty::Property property, AbstractPropertyType *value) +void Core::updateProperty(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid, double timestamp, uint32_t sequence) { SinkList list = propertySinkMap[property]; @@ -150,7 +150,7 @@ void Core::updateProperty(VehicleProperty::Property property, AbstractPropertyTy for(SinkList::iterator itr = list.begin(); itr != list.end(); itr++) { - (*itr)->propertyChanged(property, value,(*itr)->uuid()); + (*itr)->propertyChanged(property, value, uuid, timestamp, sequence); } } diff --git a/ambd/core.h b/ambd/core.h index 61f3e90..5c245f6 100644 --- a/ambd/core.h +++ b/ambd/core.h @@ -36,7 +36,7 @@ public: void setSupported(PropertyList supported, AbstractSource* source); void updateSupported(PropertyList added, PropertyList removed); - void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value); + void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, string uuid, double timestamp, uint32_t sequence); /// sinks: diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 25ac747..e822f2d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,5 +1,5 @@ set(amb_sources abstractpropertytype.cpp abstractroutingengine.cpp listplusplus.cpp abstractsink.cpp vehicleproperty.cpp abstractsource.cpp debugout.cpp) -set(amb_headers_install abstractpropertytype.h nullptr.h abstractroutingengine.h listplusplus.h abstractsink.h vehicleproperty.h debugout.h abstractsource.h) +set(amb_headers_install abstractpropertytype.h nullptr.h abstractroutingengine.h listplusplus.h abstractsink.h vehicleproperty.h debugout.h abstractsource.h timestamp.h) include_directories( ${include_dirs} ) add_library(amb SHARED ${amb_sources}) diff --git a/lib/abstractroutingengine.h b/lib/abstractroutingengine.h index cca57b1..2f87662 100644 --- a/lib/abstractroutingengine.h +++ b/lib/abstractroutingengine.h @@ -159,7 +159,7 @@ class AbstractRoutingEngine public: virtual void setSupported(PropertyList supported, AbstractSource* source) = 0; virtual void updateSupported(PropertyList added, PropertyList removed) = 0; - virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value) = 0; + virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid, double timestamp, uint32_t sequence) = 0; /// sinks: virtual void registerSink(AbstractSink* self) = 0; diff --git a/lib/abstractsink.h b/lib/abstractsink.h index 110c72e..4a74691 100644 --- a/lib/abstractsink.h +++ b/lib/abstractsink.h @@ -57,7 +57,7 @@ public: * Do not destroy it. If you need to store the value use value.anyValue() or value.value() to copy. * @param uuid Unique identifier representing the source */ - virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) = 0; + virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid, double timestamp, uint32_t sequence) = 0; virtual void supportedChanged(PropertyList supportedProperties) = 0; diff --git a/lib/timestamp.h b/lib/timestamp.h new file mode 100644 index 0000000..08beb4a --- /dev/null +++ b/lib/timestamp.h @@ -0,0 +1,19 @@ +#ifndef _TIMESTAMP_H__ +#define _TIMESTAMP_H__ + +#include + +namespace amb { + +double currentTime() +{ + struct timespec tm; + + clock_gettime(CLOCK_REALTIME, &tm); + + double time = tm.tv_sec + (tm.tv_nsec / 1000000); +} + +} + +#endif diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp index e69de29..ac605a8 100644 --- a/plugins/database/databasesink.cpp +++ b/plugins/database/databasesink.cpp @@ -0,0 +1,78 @@ +#include "databasesink.h" + +DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map config) + :AbstractSink(engine,config) +{ + shared = new Shared; + shared->db->init("storage","data","CREATE TABLE IF NOT EXISTS vehicledata (key TEXT, value BLOB, time REAL, source TEXT"); + + auto cb = [](gpointer data) + { + Shared *shared = (Shared*)data; + + while(1) + { + DBObject* obj = shared->queue.pop(); + + if( obj->quit ) + { + break; + } + + DictionaryList dict; + + NameValuePair one("key", obj->key); + NameValuePair two("value", obj->value); + NameValuePair three("source", obj->source); + NameValuePair four("time", boost::lexical_cast(obj->time)); + NameValuePair five("sequence", boost::lexical_cast(obj->sequence)); + + dict.push_back(one); + dict.push_back(two); + dict.push_back(three); + dict.push_back(four); + dict.push_back(five); + + shared->db->insert(dict); + delete obj; + } + + void* ret = NULL; + return ret; + }; + + thread = g_thread_new("dbthread", cb, shared); + +} + +DatabaseSink::~DatabaseSink() +{ + +} + + +PropertyList DatabaseSink::subscriptions() +{ + +} + + +void DatabaseSink::supportedChanged(PropertyList supportedProperties) +{ + +} + + +void DatabaseSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid, double timestamp, uint32_t sequence) +{ + DBObject* obj = new DBObject; + obj->key = property; + obj->value = value->toString(); + obj->source = uuid; +} + + +std::string DatabaseSink::uuid() +{ + return "9f88156e-cb92-4472-8775-9c08addf50d3"; +} diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h index afac457..09f62c6 100644 --- a/plugins/database/databasesink.h +++ b/plugins/database/databasesink.h @@ -17,31 +17,118 @@ */ -#ifndef EXAMPLESINK_H -#define EXAMPLESINK_H +#ifndef DATABASESINK_H +#define DATABASESINK_H #include "abstractsink.h" +#include "basedb.hpp" +#include -class ExampleSink : public AbstractSink +template +class Queue { +public: + Queue() + { + mutex = g_mutex_new(); + } + + int count() + { + g_mutex_lock(mutex); + int ret = mQueue.count(); + g_mutex_unlock(mutex); + + return ret; + } + + T pop() + { + g_mutex_lock(mutex); + + while(!mQueue.size()) + { + g_cond_wait(&cond, mutex); + } + + auto itr = mQueue.begin(); + + T item = *itr; + + mQueue.erase(itr); + + g_mutex_unlock(mutex); + + return item; + } + + void append(T item) + { + g_mutex_lock(mutex); + + g_cond_signal(&cond); + mQueue.append(item); + + g_mutex_unlock(mutex); + } + +private: + GMutex * mutex; + GCond cond; + std::vector mQueue; +}; + +class DBObject { public: - ExampleSink(AbstractRoutingEngine* engine, map config); + DBObject(): time(0),quit(false) {} + std::string key; + std::string value; + std::string source; + double time; + uint32_t sequence; + bool quit; +}; + +class Shared +{ +public: + Shared() + { + db = new BaseDB; + } + + BaseDB * db; + Queue queue; +}; + +class DatabaseSink : public AbstractSink +{ + +public: + DatabaseSink(AbstractRoutingEngine* engine, map config); + ~DatabaseSink(); virtual PropertyList subscriptions(); virtual void supportedChanged(PropertyList supportedProperties); - virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid); + virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid, double timestamp, uint32_t sequence); virtual std::string uuid(); + +private: + PropertyList mSubscriptions; + Shared *shared; + GThread* thread; + }; -class ExampleSinkManager: public AbstractSinkManager +class DatabaseSinkManager: public AbstractSinkManager { public: - ExampleSinkManager(AbstractRoutingEngine* engine, map config) + DatabaseSinkManager(AbstractRoutingEngine* engine, map config) :AbstractSinkManager(engine, config) { - new ExampleSink(routingEngine, config); + new DatabaseSink(routingEngine, config); } }; -#endif // EXAMPLESINK_H +#endif // DATABASESINK_H diff --git a/plugins/dbus/dbusplugin.cpp b/plugins/dbus/dbusplugin.cpp index 682df0c..196d54d 100644 --- a/plugins/dbus/dbusplugin.cpp +++ b/plugins/dbus/dbusplugin.cpp @@ -54,7 +54,7 @@ void DBusSink::supportedChanged(PropertyList supportedProperties) registerObject(); } -void DBusSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid) +void DBusSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid, double, uint32_t) { if(!propertyDBusMap.count(property)) return; diff --git a/plugins/dbus/dbusplugin.h b/plugins/dbus/dbusplugin.h index 103cfaa..025fbd6 100644 --- a/plugins/dbus/dbusplugin.h +++ b/plugins/dbus/dbusplugin.h @@ -33,7 +33,7 @@ class DBusSink : public AbstractSink, public AbstractDBusInterface public: DBusSink(std::string interface, std::string path, AbstractRoutingEngine* engine, GDBusConnection* connection, map config); virtual void supportedChanged(PropertyList supportedProperties); - virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid); + virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid,double,uint32_t); virtual std::string uuid(); protected: diff --git a/plugins/demosink/demosinkplugin.cpp b/plugins/demosink/demosinkplugin.cpp index 9f7f6b3..af47696 100644 --- a/plugins/demosink/demosinkplugin.cpp +++ b/plugins/demosink/demosinkplugin.cpp @@ -75,7 +75,7 @@ string DemoSink::uuid() return "5b0e8a04-d6d7-43af-b827-1663627a25d9"; } -void DemoSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid) +void DemoSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid, double, uint32_t) { std::string app = configuration["script"]; std::string strValue = value->toString(); diff --git a/plugins/demosink/demosinkplugin.h b/plugins/demosink/demosinkplugin.h index ffd806c..2340a78 100644 --- a/plugins/demosink/demosinkplugin.h +++ b/plugins/demosink/demosinkplugin.h @@ -33,7 +33,7 @@ public: string uuid(); - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid); + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid, double, uint32_t); void supportedChanged(PropertyList); friend class WheelPrivate; diff --git a/plugins/exampleplugin.cpp b/plugins/exampleplugin.cpp index 3fc5e4b..44da9cd 100644 --- a/plugins/exampleplugin.cpp +++ b/plugins/exampleplugin.cpp @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "exampleplugin.h" +#include "timestamp.h" #include #include @@ -183,12 +184,12 @@ void ExampleSourcePlugin::randomizeProperties() machineGun = !machineGun; - routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel); - routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es); - routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac); - routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa); - routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp); - routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp); - routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec); + routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel, uuid(),amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es, uuid(),amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac, uuid(),amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa, uuid(),amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp, uuid(),amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp, uuid(),amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec, uuid(),amb::currentTime(), 0); //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt); } diff --git a/plugins/exampleplugin.h b/plugins/exampleplugin.h index 8f4327b..8cb2bf4 100644 --- a/plugins/exampleplugin.h +++ b/plugins/exampleplugin.h @@ -38,7 +38,7 @@ public: void unsubscribeToPropertyChanges(VehicleProperty::Property property); PropertyList supported(); - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {} + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid, double timestamp, uint32_t sequence) {} void supportedChanged(PropertyList) {} void randomizeProperties(); diff --git a/plugins/examplesink.cpp b/plugins/examplesink.cpp index 56d6c60..39a04be 100644 --- a/plugins/examplesink.cpp +++ b/plugins/examplesink.cpp @@ -93,7 +93,7 @@ void ExampleSink::supportedChanged(PropertyList supportedProperties) routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this); } -void ExampleSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) +void ExampleSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid, double timestamp, uint32_t sequence) { DebugOut()<toString()< config); virtual PropertyList subscriptions(); virtual void supportedChanged(PropertyList supportedProperties); - virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid); + virtual void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid, double timestamp, uint32_t sequence); virtual std::string uuid(); }; diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index 9c093d7..034c756 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -27,7 +27,7 @@ #include #include "debugout.h" #include "bluetooth.hpp" - +#include "timestamp.h" #define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1) AbstractRoutingEngine *m_re; @@ -365,7 +365,7 @@ static int updateProperties(/*gpointer retval,*/ gpointer data) void OBD2Source::updateProperty(VehicleProperty::Property property,AbstractPropertyType* value) { //m_re->updateProperty(property,&value); - m_re->updateProperty(property,value); + m_re->updateProperty(property,value,uuid(),amb::currentTime(),0); if (propertyReplyMap.find(property) != propertyReplyMap.end()) { propertyReplyMap[property]->value = value; @@ -376,22 +376,22 @@ void OBD2Source::updateProperty(VehicleProperty::Property property,AbstractPrope void OBD2Source::mafValue(double maf) { VehicleProperty::VehicleSpeedType emaf(maf); - m_re->updateProperty(VehicleProperty::MassAirFlow,&emaf); + m_re->updateProperty(VehicleProperty::MassAirFlow,&emaf,uuid(),amb::currentTime(),0); } void OBD2Source::engineCoolantTemp(int temp) { VehicleProperty::VehicleSpeedType etemp(temp); - m_re->updateProperty(VehicleProperty::EngineCoolantTemperature,&etemp); + m_re->updateProperty(VehicleProperty::EngineCoolantTemperature,&etemp,uuid(),amb::currentTime(),0); } void OBD2Source::engineSpeed(double speed) { VehicleProperty::VehicleSpeedType espeed(speed); - m_re->updateProperty(VehicleProperty::EngineSpeed,&espeed); + m_re->updateProperty(VehicleProperty::EngineSpeed,&espeed,uuid(),amb::currentTime(),0); } void OBD2Source::vehicleSpeed(int speed) { VehicleProperty::EngineSpeedType vspeed(speed); - m_re->updateProperty(VehicleProperty::VehicleSpeed,&vspeed); + m_re->updateProperty(VehicleProperty::VehicleSpeed,&vspeed,uuid(),amb::currentTime(),0); } void OBD2Source::setSupported(PropertyList list) { diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h index d8e66ee..3749cda 100644 --- a/plugins/obd2plugin/obd2source.h +++ b/plugins/obd2plugin/obd2source.h @@ -131,7 +131,7 @@ public: void engineCoolantTemp(int temp); PropertyList removeRequests; void setSupported(PropertyList list); - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {} + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid,double,uint32_t) {} void supportedChanged(PropertyList) {} GAsyncQueue* commandQueue; GAsyncQueue* subscriptionAddQueue; diff --git a/plugins/tpms/tpmsplugin.cpp b/plugins/tpms/tpmsplugin.cpp index 01cb444..836f0ed 100644 --- a/plugins/tpms/tpmsplugin.cpp +++ b/plugins/tpms/tpmsplugin.cpp @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA using namespace std; #include "debugout.h" +#include "timestamp.h" #define ENDPOINT_IN 0x81 #define ENDPOINT_OUT 0x01 @@ -298,14 +299,14 @@ int TpmsPlugin::readValues() VehicleProperty::TireTemperatureType lrTemp(lrTemperature); VehicleProperty::TireTemperatureType rrTemp(rrTemperature); - routingEngine->updateProperty(VehicleProperty::TirePressureLeftFront, &lfPres); - routingEngine->updateProperty(VehicleProperty::TirePressureRightFront, &rfPres); - routingEngine->updateProperty(VehicleProperty::TirePressureLeftRear, &lrPres); - routingEngine->updateProperty(VehicleProperty::TirePressureRightRear, &rrPres); - routingEngine->updateProperty(VehicleProperty::TireTemperatureLeftFront, &lfTemp); - routingEngine->updateProperty(VehicleProperty::TireTemperatureRightFront, &rfTemp); - routingEngine->updateProperty(VehicleProperty::TireTemperatureLeftRear, &lrTemp); - routingEngine->updateProperty(VehicleProperty::TireTemperatureRightRear, &rrTemp); + routingEngine->updateProperty(VehicleProperty::TirePressureLeftFront, &lfPres, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TirePressureRightFront, &rfPres, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TirePressureLeftRear, &lrPres, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TirePressureRightRear, &rrPres, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TireTemperatureLeftFront, &lfTemp, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TireTemperatureRightFront, &rfTemp, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TireTemperatureLeftRear, &lrTemp, uuid(), amb::currentTime(), 0); + routingEngine->updateProperty(VehicleProperty::TireTemperatureRightRear, &rrTemp, uuid(), amb::currentTime(), 0); return 0; } diff --git a/plugins/tpms/tpmsplugin.h b/plugins/tpms/tpmsplugin.h index 189c91b..b4e36da 100644 --- a/plugins/tpms/tpmsplugin.h +++ b/plugins/tpms/tpmsplugin.h @@ -38,7 +38,7 @@ public: void unsubscribeToPropertyChanges(VehicleProperty::Property property); PropertyList supported(); - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {} + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid,double,uint32_t) {} void supportedChanged(PropertyList) {} int readValues(); diff --git a/plugins/websocketsink/websocketsink.cpp b/plugins/websocketsink/websocketsink.cpp index 6f02294..31f98b5 100644 --- a/plugins/websocketsink/websocketsink.cpp +++ b/plugins/websocketsink/websocketsink.cpp @@ -45,7 +45,7 @@ string WebSocketSink::uuid() { return m_uuid; } -void WebSocketSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid) +void WebSocketSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid, double timestamp, uint32_t sequence) { //printf("Got property:%i\n",boost::any_cast(reply->value)); //uint16_t velocity = boost::any_cast(value); diff --git a/plugins/websocketsink/websocketsink.h b/plugins/websocketsink/websocketsink.h index c65ebff..09c76e2 100644 --- a/plugins/websocketsink/websocketsink.h +++ b/plugins/websocketsink/websocketsink.h @@ -30,7 +30,7 @@ public: WebSocketSink(AbstractRoutingEngine* re,libwebsocket *wsi,string uuid,VehicleProperty::Property property,std::string ambdproperty); ~WebSocketSink(); string uuid() ; - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid); + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid, double timestamp, uint32_t sequence); void supportedChanged(PropertyList supportedProperties); PropertyList subscriptions(); libwebsocket *socket() { return m_wsi; } diff --git a/plugins/websocketsourceplugin/websocketsource.cpp b/plugins/websocketsourceplugin/websocketsource.cpp index faec645..35a3078 100644 --- a/plugins/websocketsourceplugin/websocketsource.cpp +++ b/plugins/websocketsourceplugin/websocketsource.cpp @@ -25,6 +25,8 @@ #include #include #include +#include + #include "debugout.h" #define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1) libwebsocket_context *context; @@ -59,6 +61,7 @@ void WebSocketSource::checkSubscriptions() } activeRequests.push_back(prop); stringstream s; + ///TODO: fix transid here: s << "{\"type\":\"method\",\"name\":\"subscribe\",\"data\":[\"" << prop << "\"],\"transactionid\":\"" << "d293f670-f0b3-11e1-aff1-0800200c9a66" << "\"}"; string replystr = s.str(); @@ -249,7 +252,7 @@ static int callback_http_only(libwebsocket_context *context,struct libwebsocket try { AbstractPropertyType* type = VehicleProperty::getPropertyTypeForPropertyNameValue(name,data.front()); - m_re->updateProperty(name, type); + m_re->updateProperty(name, type, source->uuid(), amb::currentTime(), 0); delete type; } catch (exception ex) diff --git a/plugins/websocketsourceplugin/websocketsource.h b/plugins/websocketsourceplugin/websocketsource.h index 7854c80..bf05cd7 100644 --- a/plugins/websocketsourceplugin/websocketsource.h +++ b/plugins/websocketsourceplugin/websocketsource.h @@ -47,7 +47,7 @@ public: PropertyList activeRequests; PropertyList removeRequests; void setSupported(PropertyList list); - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {} + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid,double, uint32_t) {} void supportedChanged(PropertyList) {} void setConfiguration(map config); diff --git a/plugins/wheel/wheelplugin.cpp b/plugins/wheel/wheelplugin.cpp index 2e80906..b947546 100644 --- a/plugins/wheel/wheelplugin.cpp +++ b/plugins/wheel/wheelplugin.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA using namespace std; #include "debugout.h" - +#include "timestamp.h" #define JSNAMELEN 128 #define LG27 "G27 Racing Wheel" @@ -100,6 +100,7 @@ private: bool oldClutch; bool brake; bool oldBrake; + AbstractSource* mParent; }; @@ -189,7 +190,7 @@ WheelPrivate::WheelPrivate(WheelSourcePlugin *parent, AbstractRoutingEngine *rou :re(route), gis(nullptr), axis(nullptr), button(nullptr), oilPSI(10), coolantTemp(100), turnSignal(TurnSignals::Off), throttle(0), machineGuns(false), currentGear(Transmission::Neutral), steeringAngle(0), -clutch(false), oldClutch(false), brake(false), oldBrake(false) + clutch(false), oldClutch(false), brake(false), oldBrake(false), mParent(parent) { unsigned char numAxes = 0; @@ -448,7 +449,7 @@ void WheelPrivate::changeMachineGuns(bool val) { this->machineGuns = val; VehicleProperty::MachineGunTurretStatusType temp(this->machineGuns); - this->re->updateProperty(VehicleProperty::MachineGunTurretStatus, &temp); + this->re->updateProperty(VehicleProperty::MachineGunTurretStatus, &temp, mParent->uuid(), amb::currentTime(), 0); } void WheelPrivate::changeTurnSignal(TurnSignals::TurnSignalType dir, bool val) @@ -462,7 +463,7 @@ void WheelPrivate::changeTurnSignal(TurnSignals::TurnSignalType dir, bool val) } this->turnSignal = tsVal; VehicleProperty::TurnSignalType temp(this->turnSignal); - this->re->updateProperty(VehicleProperty::TurnSignal, &temp); + this->re->updateProperty(VehicleProperty::TurnSignal, &temp, mParent->uuid(), amb::currentTime(), 0); } void WheelPrivate::changeGear(int gear) @@ -470,20 +471,20 @@ void WheelPrivate::changeGear(int gear) this->currentGear = (Transmission::TransmissionPositions)gear; VehicleProperty::TransmissionShiftPositionType tempTrans(this->currentGear); VehicleProperty::VehicleSpeedType tempSpeed(this->calcCarSpeed()); - this->re->updateProperty(VehicleProperty::TransmissionShiftPosition, &tempTrans); - this->re->updateProperty(VehicleProperty::VehicleSpeed, &tempSpeed); + this->re->updateProperty(VehicleProperty::TransmissionShiftPosition, &tempTrans, mParent->uuid(), amb::currentTime(), 0); + this->re->updateProperty(VehicleProperty::VehicleSpeed, &tempSpeed, mParent->uuid(), amb::currentTime(), 0); } void WheelPrivate::changeOilPressure(bool increase) { VehicleProperty::EngineOilPressureType temp(increase ? ++this->oilPSI : --this->oilPSI); - this->re->updateProperty(VehicleProperty::EngineOilPressure, &temp); + this->re->updateProperty(VehicleProperty::EngineOilPressure, &temp, mParent->uuid(), amb::currentTime(), 0); } void WheelPrivate::changeCoolantTemp(bool increase) { VehicleProperty::EngineCoolantTemperatureType temp(increase ? ++this->coolantTemp : --this->coolantTemp); - this->re->updateProperty(VehicleProperty::EngineCoolantTemperature, &temp); + this->re->updateProperty(VehicleProperty::EngineCoolantTemperature, &temp, mParent->uuid(), amb::currentTime(), 0); } @@ -491,7 +492,7 @@ void WheelPrivate::changeSteeringAngle(int val) { this->steeringAngle = (((double)val/(double)32767.0) + (double)1.0) * (double)180.0; VehicleProperty::SteeringWheelAngleType temp(this->steeringAngle); - this->re->updateProperty(VehicleProperty::SteeringWheelAngle, &temp); + this->re->updateProperty(VehicleProperty::SteeringWheelAngle, &temp, mParent->uuid(), amb::currentTime(), 0); } void WheelPrivate::changeClutch(int val) @@ -501,7 +502,7 @@ void WheelPrivate::changeClutch(int val) if (this->oldClutch != this->clutch) { VehicleProperty::ClutchStatusType temp(this->clutch); - this->re->updateProperty(VehicleProperty::ClutchStatus, &temp); + this->re->updateProperty(VehicleProperty::ClutchStatus, &temp, mParent->uuid(), amb::currentTime(), 0); } } @@ -513,9 +514,9 @@ void WheelPrivate::changeThrottle(int val) VehicleProperty::EngineSpeedType tempRpm(this->calcRPM()); VehicleProperty::VehicleSpeedType tempSpeed(this->calcCarSpeed()); - this->re->updateProperty(VehicleProperty::ThrottlePosition, &tempThrottle); - this->re->updateProperty(VehicleProperty::EngineSpeed, &tempRpm); - this->re->updateProperty(VehicleProperty::VehicleSpeed, &tempSpeed); + this->re->updateProperty(VehicleProperty::ThrottlePosition, &tempThrottle, mParent->uuid(), amb::currentTime(), 0); + this->re->updateProperty(VehicleProperty::EngineSpeed, &tempRpm, mParent->uuid(), amb::currentTime(), 0); + this->re->updateProperty(VehicleProperty::VehicleSpeed, &tempSpeed, mParent->uuid(), amb::currentTime(), 0); } void WheelPrivate::changeBrake(int val) @@ -525,7 +526,7 @@ void WheelPrivate::changeBrake(int val) if (this->oldBrake != this->brake) { VehicleProperty::WheelBrakeType temp(this->brake); - this->re->updateProperty(VehicleProperty::WheelBrake, &temp); + this->re->updateProperty(VehicleProperty::WheelBrake, &temp, mParent->uuid(), amb::currentTime(), 0); } } @@ -550,22 +551,22 @@ void WheelPrivate::checkButtonEvents() if (this->button[11]) { // cout << "Inside button 11!" << endl; VehicleProperty::ButtonEventType tempButton(ButtonEvents::Preset1Button); - this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton); + this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton, mParent->uuid(), amb::currentTime(), 0); } if (this->button[8]) { // cout << "Inside button 8!" << endl; VehicleProperty::ButtonEventType tempButton(ButtonEvents::Preset2Button); - this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton); + this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton, mParent->uuid(), amb::currentTime(), 0); } if (this->button[9]) { // cout << "Inside button 9!" << endl; VehicleProperty::ButtonEventType tempButton(ButtonEvents::Preset3Button); - this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton); + this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton, mParent->uuid(), amb::currentTime(), 0); } if (this->button[10]) { // cout << "Inside button 10!" << endl; VehicleProperty::ButtonEventType tempButton(ButtonEvents::Preset4Button); - this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton); + this->re->updateProperty(VehicleProperty::ButtonEvent, &tempButton, mParent->uuid(), amb::currentTime(), 0); } } } diff --git a/plugins/wheel/wheelplugin.h b/plugins/wheel/wheelplugin.h index ab7e662..5c7f45d 100644 --- a/plugins/wheel/wheelplugin.h +++ b/plugins/wheel/wheelplugin.h @@ -41,7 +41,7 @@ public: void unsubscribeToPropertyChanges(VehicleProperty::Property property); PropertyList supported(); - void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {} + void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid, double, uint32_t) {} void supportedChanged(PropertyList) {} map getConfiguration() { return configuration; } -- 2.7.4