From 191e6895979f3ddf6a1a14dc50dc03df299ccf2d Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Fri, 14 Jun 2013 08:48:18 -0700 Subject: [PATCH] fixed obd2. added getSourcesForInterface --- ambd/core.cpp | 19 +++++++++++++++++++ ambd/core.h | 2 ++ lib/abstractroutingengine.h | 19 +++++++++++++++++++ plugins/obd2plugin/obd2source.cpp | 31 +++++++++++++++++++++++-------- plugins/obd2plugin/obd2source.h | 1 - 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/ambd/core.cpp b/ambd/core.cpp index e771561..d1c0ddb 100644 --- a/ambd/core.cpp +++ b/ambd/core.cpp @@ -165,6 +165,25 @@ void Core::updateProperty(VehicleProperty::Property property, AbstractPropertyTy } } +std::list Core::sourcesForProperty(VehicleProperty::Property property) +{ + std::list l; + + for(auto itr = mSources.begin(); itr != mSources.end(); itr++) + { + AbstractSource* src = *itr; + + PropertyList s = src->supported(); + + if(ListPlusPlus(&s).contains(property)) + { + l.push_back(src->uuid()); + } + } + + return l; +} + void Core::registerSink(AbstractSink *self) { if(!ListPlusPlus(&mSinks).contains(self)) diff --git a/ambd/core.h b/ambd/core.h index bbbee72..af488a6 100644 --- a/ambd/core.h +++ b/ambd/core.h @@ -39,6 +39,8 @@ public: void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, string uuid); /// sinks: + + std::list sourcesForProperty(VehicleProperty::Property property); void registerSink(AbstractSink *self); void unregisterSink(AbstractSink *self); diff --git a/lib/abstractroutingengine.h b/lib/abstractroutingengine.h index 9099181..a29db6a 100644 --- a/lib/abstractroutingengine.h +++ b/lib/abstractroutingengine.h @@ -206,6 +206,25 @@ public: /// sinks: virtual void registerSink(AbstractSink* self) = 0; virtual void unregisterSink(AbstractSink* self) = 0; + + /** + * @brief sourcesForProperty + * @param property + * @return list of source uuid's that support the "property" + */ + virtual std::list sourcesForProperty(VehicleProperty::Property property) = 0; + + /** + * @brief getPropertyAsync requests a property value from a source. This call has a timeout and will always return. + * @see AsyncPropertyRequest + * @see AsyncPropertyReply. + * @param request requested property. + * @return AsyncPropertyReply. The returned AsyncPropertyReply is owned by the caller of getPropertyAsync. + * @example AsyncPropertyRequest request; + * request.property = VehicleProperty::VehicleSpeed + * request.completed = [](AsyncPropertyReply* reply) { delete reply; }; + * routingEngine->getPropertyAsync(request); + */ virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0; virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0; virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0; diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index b0c2c99..92f2214 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -85,6 +85,7 @@ bool connect(obdLib* obd, std::string device, std::string strbaud) //No reply found //printf("Error!\n"); DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error resetting ELM"<sendObdRequestString("010C1\r",6,&replyVector,500,5); + + return true; } void threadLoop(gpointer data) @@ -167,9 +174,9 @@ void threadLoop(gpointer data) //commandMap[req->req] = req->arg; //printf("Command: %s\n",req->req.c_str()); DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Command:" << req->req << endl; - if (req->req == "connect") + if (req->req == "connect" ) { - + if (source->m_isBluetooth) { ObdBluetoothDevice bt; @@ -185,20 +192,22 @@ void threadLoop(gpointer data) port = req->arglist[0]; baud = req->arglist[1]; } - connected = connect(obd,port,baud); + bool isconnected = connect(obd,port,baud); - if(connected) + if(isconnected) { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "connected"; g_async_queue_push(privStatusQueue,statusreq); } - else + else if(!isconnected && connected) { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "disconnected"; g_async_queue_push(privStatusQueue,statusreq); } + + connected = isconnected; } else if (req->req == "connectifnot") @@ -214,21 +223,27 @@ void threadLoop(gpointer data) DebugOut(3)<<"Using bluetooth device \""<m_btDeviceAddress<<"\" bound to: "<statusStr = "connected"; g_async_queue_push(privStatusQueue,statusreq); } - else + else if(!isconnected && connected) { StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "disconnected"; g_async_queue_push(privStatusQueue,statusreq); } + + connected = isconnected; } } else if (req->req == "setportandbaud") diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h index 296ebd5..a2ead1f 100644 --- a/plugins/obd2plugin/obd2source.h +++ b/plugins/obd2plugin/obd2source.h @@ -1,4 +1,3 @@ - /* Copyright (C) 2012 Intel Corporation -- 2.7.4