Skip to content

Commit 8abf165

Browse files
fixed restart of the rover-cv
1 parent e0a991f commit 8abf165

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

trikControl/src/cameraLineDetectorSensorWorker.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ CameraLineDetectorSensorWorker::CameraLineDetectorSensorWorker(
3636
, mOutputFile(outputFile)
3737
, mReady(false)
3838
{
39-
qDebug() << "CameraLineDetectorSensorWorker::CameraLineDetectorSensorWorker";
40-
4139
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
40+
41+
connect(&mRoverCvProcess, SIGNAL(error(QProcess::ProcessError))
42+
, this, SLOT(onRoverCvError(QProcess::ProcessError)), Qt::QueuedConnection);
43+
44+
connect(&mRoverCvProcess, SIGNAL(readyReadStandardError())
45+
, this, SLOT(onRoverCvReadyReadStandardError()), Qt::QueuedConnection);
46+
47+
connect(&mRoverCvProcess, SIGNAL(readyReadStandardOutput())
48+
, this, SLOT(onRoverCvReadyReadStandardOutput()), Qt::QueuedConnection);
4249
}
4350

4451
CameraLineDetectorSensorWorker::~CameraLineDetectorSensorWorker()
@@ -49,29 +56,18 @@ CameraLineDetectorSensorWorker::~CameraLineDetectorSensorWorker()
4956
void CameraLineDetectorSensorWorker::moveChildrenToCorrectThread()
5057
{
5158
mRoverCvProcess.moveToThread(this->thread());
52-
53-
connect(&mRoverCvProcess, SIGNAL(error(QProcess::ProcessError))
54-
, this, SLOT(onRoverCvError(QProcess::ProcessError)), Qt::QueuedConnection);
55-
56-
connect(&mRoverCvProcess, SIGNAL(readyReadStandardError())
57-
, this, SLOT(onRoverCvReadyReadStandardError()), Qt::QueuedConnection);
58-
59-
connect(&mRoverCvProcess, SIGNAL(readyReadStandardOutput())
60-
, this, SLOT(onRoverCvReadyReadStandardOutput()), Qt::QueuedConnection);
6159
}
6260

6361
void CameraLineDetectorSensorWorker::init()
6462
{
65-
qDebug() << "CameraLineDetectorSensorWorker::init()";
66-
if (!mReady) {
63+
if (!mReady || !mInputFile.exists() || !mOutputFile.exists()) {
6764
initDetector();
6865
}
6966
}
7067

7168
void CameraLineDetectorSensorWorker::detect()
7269
{
73-
qDebug() << "CameraLineDetectorSensorWorker::detect()";
74-
if (!mReady) {
70+
if (!mReady || !mInputFile.exists() || !mOutputFile.exists()) {
7571
init();
7672
}
7773

@@ -86,8 +82,6 @@ int CameraLineDetectorSensorWorker::read()
8682

8783
void CameraLineDetectorSensorWorker::initDetector()
8884
{
89-
qDebug() << "initDetector()";
90-
9185
if (!mInputFile.exists() || !mOutputFile.exists()) {
9286
startRoverCv();
9387
} else {
@@ -105,15 +99,17 @@ void CameraLineDetectorSensorWorker::onRoverCvError(QProcess::ProcessError error
10599

106100
void CameraLineDetectorSensorWorker::onRoverCvReadyReadStandardOutput()
107101
{
108-
qDebug() << "onRoverCvReadyReadStandardOutput";
109-
110102
QString const data = mRoverCvProcess.readAllStandardOutput();
111103
QStringList const lines = data.split("\n");
112104
foreach (QString const line, lines) {
113105
qDebug() << "From rover-cv:" << line;
114106
if (line == "Entering video thread loop") {
115107
openFifos();
116108
}
109+
if (line == "Terminating") {
110+
mReady = false;
111+
deinitialize();
112+
}
117113
}
118114
}
119115

@@ -188,8 +184,12 @@ void CameraLineDetectorSensorWorker::startRoverCv()
188184

189185
qDebug() << "Starting rover-cv";
190186

187+
if (mRoverCvProcess.state() == QProcess::Running) {
188+
mRoverCvProcess.close();
189+
}
190+
191191
mRoverCvProcess.setWorkingDirectory(roverCvBinaryFileInfo.absolutePath());
192-
mRoverCvProcess.start(roverCvBinaryFileInfo.filePath());
192+
mRoverCvProcess.start(roverCvBinaryFileInfo.filePath(), QIODevice::ReadOnly | QIODevice::Unbuffered);
193193

194194
mRoverCvProcess.waitForStarted();
195195

@@ -228,7 +228,7 @@ void CameraLineDetectorSensorWorker::openFifos()
228228
mSocketNotifier.reset(new QSocketNotifier(mOutputFileDescriptor, QSocketNotifier::Read));
229229

230230
connect(mSocketNotifier.data(), SIGNAL(activated(int)), this, SLOT(readFile()));
231-
mSocketNotifier->setEnabled(true);
231+
mSocketNotifier->setEnabled(false);
232232

233233
qDebug() << "opening" << mInputFile.fileName();
234234

@@ -260,7 +260,7 @@ void CameraLineDetectorSensorWorker::tryToExecute()
260260

261261
void CameraLineDetectorSensorWorker::deinitialize()
262262
{
263-
disconnect(mSocketNotifier.data(), SIGNAL(activated(int)), this, SLOT(readFifo()));
263+
disconnect(mSocketNotifier.data(), SIGNAL(activated(int)), this, SLOT(readFile()));
264264
mSocketNotifier->setEnabled(false);
265265
if (::close(mOutputFileDescriptor) != 0) {
266266
qDebug() << mOutputFile.fileName() << ": fifo close failed: " << errno;

0 commit comments

Comments
 (0)