summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Carpenter <malcom2073@gmail.com>2012-11-13 21:30:56 -0500
committerMichael Carpenter <malcom2073@gmail.com>2012-11-13 21:30:56 -0500
commit250035b8916580d198760b9e068ee39dce8bcece (patch)
tree263b732f7a3f5fc73a774d533ac3243d2626a62f
parent686444bad3a1af88d0fec8bb715a4fb1985b35d5 (diff)
downloadautomotive-message-broker-250035b8916580d198760b9e068ee39dce8bcece.tar.gz
Addition of disconnect on last unsubscribe and extra debugging
-rw-r--r--plugins/obd2plugin/obd2source.cpp12
-rw-r--r--plugins/obd2plugin/obdlib.cpp20
2 files changed, 28 insertions, 4 deletions
diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp
index c46c3ac3..3fe54b03 100644
--- a/plugins/obd2plugin/obd2source.cpp
+++ b/plugins/obd2plugin/obd2source.cpp
@@ -195,6 +195,13 @@ void threadLoop(gpointer data)
g_async_queue_push(privCommandQueue,req);
continue;
}
+ else if (reqList.size() == 0 && connected)
+ {
+ CommandRequest *req = new CommandRequest();
+ req->req = "disconnect";
+ g_async_queue_push(privCommandQueue,req);
+ continue;
+ }
for (std::list<ObdPid*>::iterator i=reqList.begin();i!= reqList.end();i++)
{
repeatReqList.push_back(*i);
@@ -276,7 +283,10 @@ void threadLoop(gpointer data)
//DebugOut()<<"Reply: "<<replyVector[2]<<" "<<replyVector[3]<<endl;
}
- if(!reqList.size()) usleep(10000);
+ if (!connected)
+ {
+ usleep(10000);
+ }
repeatReqList.clear();
}
diff --git a/plugins/obd2plugin/obdlib.cpp b/plugins/obd2plugin/obdlib.cpp
index 9939cd7f..489d425b 100644
--- a/plugins/obd2plugin/obdlib.cpp
+++ b/plugins/obd2plugin/obdlib.cpp
@@ -160,18 +160,30 @@ int obdLib::openPort(const char *portName,int baudrate)
{
}
- newtio.c_cflag |= (CLOCAL | CREAD);
+ newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS8;
+ newtio.c_cflag |= CLOCAL | CREAD;
+ newtio.c_cflag &= ~CRTSCTS;
+ newtio.c_cflag &= ~CSTOPB;
+ newtio.c_iflag=IGNBRK;
+ newtio.c_iflag &= ~(IXON|IXOFF|IXANY);
+ newtio.c_lflag=0;
+ newtio.c_oflag=0;
+ newtio.c_cc[VTIME]=1; //1/10th second timeout, reduces CPU usage but still allows for timeouts
+ newtio.c_cc[VMIN]=1; //We want a pure timer timeout
+
+
+ /*newtio.c_cflag |= (CLOCAL | CREAD);
newtio.c_lflag &= !(ICANON | ECHO | ECHOE | ISIG);
newtio.c_oflag &= !(OPOST);
newtio.c_cc[VMIN] = 0;
- newtio.c_cc[VTIME] = 100;
+ newtio.c_cc[VTIME] = 100;*/
/*
newtio.c_cflag &= ~CSIZE; //Disable byte size
newtio.c_cflag &= ~PARENB; //Disable parity
newtio.c_cflag &= ~CSTOPB; //Disable stop bits
newtio.c_cflag |= (CLOCAL | CREAD | CS8); //Set local mode, reader, and 8N1.
- newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //Disable CANON, echo, and signals
+ newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //Disausleep(10000);ble CANON, echo, and signals
newtio.c_oflag &= ~(OPOST); //Disable post processing
*/
@@ -188,6 +200,7 @@ int obdLib::openPort(const char *portName,int baudrate)
}
debug(obdLib::DEBUG_VERBOSE,"Setting baud rate to %i on port %s\n",baudrate,portName);
}
+ fcntl(portHandle, F_SETFL, 0); //Set to blocking
tcsetattr(portHandle,TCSANOW,&newtio);
//newtio.c_cc[VMIN] = 0; //Minimum number of bytes to read
//newtio.c_cc[VTIME] = 100; //Read Timeout (10.0 seconds)
@@ -426,6 +439,7 @@ bool obdLib::sendObdRequestString(const char *req,int length,std::vector<byte> *
#ifdef WINVER
Sleep(10);
#else
+ printf("Timeout\n");
usleep(10000);
#endif
}