From 5771769acfe4f24477506168b5f97ee5df03226b Mon Sep 17 00:00:00 2001 From: peabody124 Date: Wed, 22 Sep 2010 01:04:24 +0000 Subject: [PATCH] Ground/Logging: Change replay state at end of replay file to stop lock up git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1715 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/logging/logfile.cpp | 36 +++++++++++++++---- ground/src/plugins/logging/logfile.h | 1 + ground/src/plugins/logging/loggingplugin.cpp | 38 ++++++++++++-------- ground/src/plugins/logging/loggingplugin.h | 2 +- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/ground/src/plugins/logging/logfile.cpp b/ground/src/plugins/logging/logfile.cpp index fe5817fcc..1cabc104d 100644 --- a/ground/src/plugins/logging/logfile.cpp +++ b/ground/src/plugins/logging/logfile.cpp @@ -63,14 +63,37 @@ void LogFile::timerFired() { qint64 dataSize; - // TODO: going back in time will be a problem - while ((myTime.elapsed() - timeOffset) * playbackSpeed > lastTimeStamp) { - file.read((char *) &dataSize, sizeof(dataSize)); - dataBuffer.append(file.read(dataSize)); - emit readyRead(); + if(file.bytesAvailable() > 4) + { + // TODO: going back in time will be a problem + while ((myTime.elapsed() - timeOffset) * playbackSpeed > lastTimeStamp) { - file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp)); + if(file.bytesAvailable() < 4) { + stopReplay(); + return; + } + + file.read((char *) &dataSize, sizeof(dataSize)); + + if(file.bytesAvailable() < dataSize) { + stopReplay(); + return; + } + + dataBuffer.append(file.read(dataSize)); + emit readyRead(); + + if(file.bytesAvailable() < 4) { + stopReplay(); + return; + } + + file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp)); + } + } else { + stopReplay(); } + } bool LogFile::startReplay() { @@ -86,6 +109,7 @@ bool LogFile::startReplay() { bool LogFile::stopReplay() { timer.stop(); + emit replayFinished(); return true; } diff --git a/ground/src/plugins/logging/logfile.h b/ground/src/plugins/logging/logfile.h index b6a0afbf7..6cd03a685 100644 --- a/ground/src/plugins/logging/logfile.h +++ b/ground/src/plugins/logging/logfile.h @@ -35,6 +35,7 @@ protected slots: signals: void readReady(); + void replayFinished(); protected: QByteArray dataBuffer; diff --git a/ground/src/plugins/logging/loggingplugin.cpp b/ground/src/plugins/logging/loggingplugin.cpp index b90ba7a0c..f2d76659f 100644 --- a/ground/src/plugins/logging/loggingplugin.cpp +++ b/ground/src/plugins/logging/loggingplugin.cpp @@ -171,6 +171,9 @@ bool LoggingPlugin::initialize(const QStringList& args, QString *errMsg) mf = new LoggingGadgetFactory(this); addAutoReleasedObject(mf); + // Map signal from end of replay to replay stopped + connect(&logFile,SIGNAL(replayFinished()), this, SLOT(replayStopped())); + return true; } @@ -210,7 +213,7 @@ void LoggingPlugin::toggleReplay() } else if(state == REPLAY) { - stopReplay(); + logFile.stopReplay(); } } @@ -269,20 +272,6 @@ void LoggingPlugin::stopLogging() } -/** - * Send the stop replay signal to the ReplayThread - */ -void LoggingPlugin::stopReplay() -{ - logFile.stopReplay(); - logFile.close(); - delete(uavTalk); - uavTalk = 0; - state = IDLE; - - emit stateChanged("IDLE"); -} - /** * Receive the logging stopped signal from the LoggingThread * and change status to not logging @@ -298,6 +287,25 @@ void LoggingPlugin::loggingStopped() loggingThread = NULL; } +/** + * Received the replay stoppedsignal from the LogFile + */ +void LoggingPlugin::replayStopped() +{ + Q_ASSERT(state == REPLAY); + + if(uavTalk) + delete(uavTalk); + + logFile.close(); + + uavTalk = 0; + state = IDLE; + + emit stateChanged("IDLE"); +} + + void LoggingPlugin::extensionsInitialized() { // Do nothing diff --git a/ground/src/plugins/logging/loggingplugin.h b/ground/src/plugins/logging/loggingplugin.h index abea393a8..7fdd16855 100644 --- a/ground/src/plugins/logging/loggingplugin.h +++ b/ground/src/plugins/logging/loggingplugin.h @@ -91,8 +91,8 @@ private slots: void startLogging(QString file); void startReplay(QString file); void stopLogging(); - void stopReplay(); void loggingStopped(); + void replayStopped(); private: LoggingGadgetFactory *mf;