Fix for an issue where a NODATA response from an OBD2 tool would cause a disconnect 11/2511/1
authorMichael Carpenter <malcom2073@gmail.com>
Wed, 21 Nov 2012 19:06:26 +0000 (14:06 -0500)
committerMichael Carpenter <malcom2073@gmail.com>
Wed, 21 Nov 2012 22:34:59 +0000 (17:34 -0500)
examples/obdsourceconfig
plugins/obd2plugin/obd2source.cpp

index f7403bd..a76cdc6 100644 (file)
@@ -3,7 +3,7 @@
                {
                        "name" : "OBD2Source",
                        "path" : "/usr/lib/automotive-message-broker/obd2sourceplugin.so",
-                       "device" : "/dev/ttyUSB0",
+                       "device" : "/dev/pts/5",
                        "baud" : "115200",
                        "bluetoothAdapter" : ""
                }
index e05fa7b..d9c6790 100644 (file)
@@ -124,6 +124,7 @@ void threadLoop(gpointer data)
        std::string port;
        std::string baud;
        bool connected=false;
+       int emptycount = 0;
        while (source->m_threadLive)
        {
                //gpointer query = g_async_queue_pop(privCommandQueue);
@@ -162,7 +163,7 @@ void threadLoop(gpointer data)
                        {
                                if (!connected)
                                {
-                                       connect(obd,req->arglist[0],req->arglist[1]);
+                                       connect(obd,port,baud);
                                        connected = true;
                                }
                        }
@@ -206,6 +207,13 @@ void threadLoop(gpointer data)
                }
                else if (reqList.size() == 0 && connected)
                {
+                       emptycount++;
+                       if (emptycount < 1000)
+                       {
+                               usleep(10000);
+                               continue;
+                       }
+                       emptycount = 0;
                        CommandRequest *req = new CommandRequest();
                        req->req = "disconnect";
                        g_async_queue_push(privCommandQueue,req);
@@ -226,6 +234,14 @@ void threadLoop(gpointer data)
                        {
                                //This only happens during a error with the com port. Close it and re-open it later.
                                DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unable to send request:" << (*i)->pid << "!\n";
+                               if (obd->lastError() == obdLib::NODATA)
+                               {
+                                       continue;
+                               }
+                               else if (obd->lastError() == obdLib::TIMEOUT)
+                               {
+                                       continue;
+                               }
                                CommandRequest *req = new CommandRequest();
                                req->req = "disconnect";
                                g_async_queue_push(privCommandQueue,req);