fix for obd2 connected signal
authorKevron Rees <tripzero.kev@gmail.com>
Sat, 8 Jun 2013 16:55:02 +0000 (09:55 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Sat, 8 Jun 2013 16:55:02 +0000 (09:55 -0700)
plugins/bluemonkey/bluemonkey.cpp
plugins/obd2plugin/obd2source.cpp

index 727e15c..57ae00a 100644 (file)
@@ -235,6 +235,10 @@ void Property::setValue(QVariant v)
        request.value = mValue;
        request.completed = [&](AsyncPropertyReply* reply)
        {
+               if(reply->success)
+               {
+                       propertyChanged(reply->property,reply->value,reply->value->sourceUuid);
+               }
                delete reply;
        };
        routingEngine->setProperty(request);
index 1a37e88..b0c2c99 100644 (file)
@@ -193,6 +193,12 @@ void threadLoop(gpointer data)
                                        statusreq->statusStr = "connected";
                                        g_async_queue_push(privStatusQueue,statusreq);
                                }
+                               else
+                               {
+                                       StatusMessage *statusreq = new StatusMessage();
+                                       statusreq->statusStr = "disconnected";
+                                       g_async_queue_push(privStatusQueue,statusreq);
+                               }
                                
                        }
                        else if (req->req == "connectifnot")
@@ -217,6 +223,12 @@ void threadLoop(gpointer data)
                                                statusreq->statusStr = "connected";
                                                g_async_queue_push(privStatusQueue,statusreq);
                                        }
+                                       else
+                                       {
+                                               StatusMessage *statusreq = new StatusMessage();
+                                               statusreq->statusStr = "disconnected";
+                                               g_async_queue_push(privStatusQueue,statusreq);
+                                       }
                                }
                        }
                        else if (req->req == "setportandbaud")
@@ -464,6 +476,7 @@ void OBD2Source::updateProperty(VehicleProperty::Property property,AbstractPrope
        if (propertyReplyMap.find(property) != propertyReplyMap.end())
        {
                propertyReplyMap[property]->value = value;
+               propertyReplyMap[property]->success = true;
                propertyReplyMap[property]->completed(propertyReplyMap[property]);
                propertyReplyMap.erase(property);
        }
@@ -690,7 +703,7 @@ void OBD2Source::unsubscribeToPropertyChanges(VehicleProperty::Property property
 void OBD2Source::getPropertyAsync(AsyncPropertyReply *reply)
 {
        DebugOut(5) << __SMALLFILE__ <<":"<< __LINE__ << "getPropertyAsync requested for " << reply->property << endl;
-       propertyReplyMap[reply->property] = reply;
+
        VehicleProperty::Property property = reply->property;
 
 
@@ -700,6 +713,8 @@ void OBD2Source::getPropertyAsync(AsyncPropertyReply *reply)
                return;
        }
 
+       propertyReplyMap[reply->property] = reply;
+
        ObdPid* requ = obd2AmbInstance->createPidforProperty(property);
        g_async_queue_push(singleShotQueue,requ);
        CommandRequest *req = new CommandRequest();
@@ -711,8 +726,13 @@ AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request )
 {
        AsyncPropertyReply* reply = new AsyncPropertyReply (request);
 
+
+
        if(request.property == Obd2Connected)
        {
+               propertyReplyMap[reply->property] = reply;
+               reply->success = true;
+
                if(request.value->value<bool>() == true)
                {
                        CommandRequest *req = new CommandRequest();
@@ -726,23 +746,21 @@ AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request )
                        g_async_queue_push(commandQueue,req);
                }
 
-               reply->success = true;
        }
 
        else
        {
                reply->success = false;
-       }
+               try
+               {
+                       reply->completed(reply);
+               }
+               catch (...)
+               {
 
-       try
-       {
-               /// TODO: this doesn't seem right:
-               reply->value = request.value;
-               reply->completed(reply);
+               }
        }
-       catch (...)
-       {
 
-       }
+
        return reply;
 }