fixed obd2. added getSourcesForInterface
authorKevron Rees <tripzero.kev@gmail.com>
Fri, 14 Jun 2013 15:48:18 +0000 (08:48 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Fri, 14 Jun 2013 15:48:38 +0000 (08:48 -0700)
ambd/core.cpp
ambd/core.h
lib/abstractroutingengine.h
plugins/obd2plugin/obd2source.cpp
plugins/obd2plugin/obd2source.h

index e771561..d1c0ddb 100644 (file)
@@ -165,6 +165,25 @@ void Core::updateProperty(VehicleProperty::Property property, AbstractPropertyTy
        }
 }
 
+std::list<std::string> Core::sourcesForProperty(VehicleProperty::Property property)
+{
+       std::list<std::string> l;
+
+       for(auto itr = mSources.begin(); itr != mSources.end(); itr++)
+       {
+               AbstractSource* src = *itr;
+
+               PropertyList s = src->supported();
+
+               if(ListPlusPlus<VehicleProperty::Property>(&s).contains(property))
+               {
+                       l.push_back(src->uuid());
+               }
+       }
+
+       return l;
+}
+
 void Core::registerSink(AbstractSink *self)
 {
        if(!ListPlusPlus<AbstractSink*>(&mSinks).contains(self))
index bbbee72..af488a6 100644 (file)
@@ -39,6 +39,8 @@ public:
        void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, string uuid);
        
        /// sinks:
+
+       std::list<std::string> sourcesForProperty(VehicleProperty::Property property);
        
        void registerSink(AbstractSink *self);
        void unregisterSink(AbstractSink *self);
index 9099181..a29db6a 100644 (file)
@@ -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<std::string> 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;
index b0c2c99..92f2214 100644 (file)
@@ -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"<<endl;
+               return false;
        }
        else
        {
@@ -94,23 +95,29 @@ bool connect(obdLib* obd, std::string device, std::string strbaud)
        {
                //printf("Error sending echo\n");
                DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error setting auto protocol"<<endl;
+               return false;
        }
        if (!sendElmCommand(obd,"ATE0"))
        {
                //printf("Error sending echo\n");
                DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error turning off echo"<<endl;
+               return false;
        }
        if (!sendElmCommand(obd,"ATH0"))
        {
                //printf("Error sending headers off\n");
                DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error turning off headers"<<endl;
+               return false;
        }
        if (!sendElmCommand(obd,"ATL0"))
        {
                //printf("Error turning linefeeds off\n");
                DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error turning off linefeeds"<<endl;
+               return false;
        }
        obd->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 \""<<source->m_btDeviceAddress<<"\" bound to: "<<tempPort<<endl;
                                                        port = tempPort;
                                                }
+                                               else
+                                               {
+                                                       DebugOut(DebugOut::Error)<<"Error creating bluetooth device"<<endl;
+                                               }
                                        }
-                                       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 == "setportandbaud")
index 296ebd5..a2ead1f 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
 Copyright (C) 2012 Intel Corporation