From: Michael Carpenter Date: Wed, 21 Nov 2012 18:55:31 +0000 (-0500) Subject: Addition of feature to disconnect from OBD port on failure, and reconnect only on... X-Git-Tag: 0.6.0~8^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F2510%2F1;p=profile%2Fivi%2Fautomotive-message-broker.git Addition of feature to disconnect from OBD port on failure, and reconnect only on new incoming subscriptions --- diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index 543b53d..e05fa7b 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -158,6 +158,14 @@ void threadLoop(gpointer data) connect(obd,req->arglist[0],req->arglist[1]); connected = true; } + else if (req->req == "connectifnot") + { + if (!connected) + { + connect(obd,req->arglist[0],req->arglist[1]); + connected = true; + } + } else if (req->req == "setportandbaud") { port = req->arglist[0]; @@ -189,12 +197,12 @@ void threadLoop(gpointer data) } if (reqList.size() > 0 && !connected) { - CommandRequest *req = new CommandRequest(); + /*CommandRequest *req = new CommandRequest(); req->req = "connect"; req->arglist.push_back(port); req->arglist.push_back(baud); g_async_queue_push(privCommandQueue,req); - continue; + continue;*/ } else if (reqList.size() == 0 && connected) { @@ -203,6 +211,11 @@ void threadLoop(gpointer data) g_async_queue_push(privCommandQueue,req); continue; } + if (!connected) + { + usleep(10000); + continue; + } for (std::list::iterator i=reqList.begin();i!= reqList.end();i++) { repeatReqList.push_back(*i); @@ -211,7 +224,11 @@ void threadLoop(gpointer data) { if (!obd->sendObdRequestString((*i)->pid.c_str(),(*i)->pid.length(),&replyVector)) { + //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"; + CommandRequest *req = new CommandRequest(); + req->req = "disconnect"; + g_async_queue_push(privCommandQueue,req); continue; } //ObdPid *pid = ObdPid::pidFromReply(replyVector); @@ -284,10 +301,6 @@ void threadLoop(gpointer data) //DebugOut()<<"Reply: "<createPidforProperty(property); g_async_queue_push(subscriptionAddQueue,pid); + CommandRequest *req = new CommandRequest(); + req->req = "connectifnot"; + g_async_queue_push(commandQueue,req); } } @@ -742,6 +758,9 @@ void OBD2Source::getPropertyAsync(AsyncPropertyReply *reply) ObdPid* requ = obd2AmbInstance->createPidforProperty(property); g_async_queue_push(singleShotQueue,requ); + CommandRequest *req = new CommandRequest(); + req->req = "connectifnot"; + g_async_queue_push(commandQueue,req); } AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request )