mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
GCS:Logging: Correctly adhere to replay speed, and check logfile for plausibility/corruption
This commit is contained in:
parent
856f8a9b6c
commit
6913d14e82
@ -88,9 +88,12 @@ void LogFile::timerFired()
|
|||||||
if(file.bytesAvailable() > 4)
|
if(file.bytesAvailable() > 4)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO: going back in time will be a problem
|
int time;
|
||||||
while ((myTime.elapsed() - timeOffset) * playbackSpeed > lastTimeStamp) {
|
time = myTime.elapsed();
|
||||||
|
|
||||||
|
// TODO: going back in time will be a problem
|
||||||
|
while ((lastPlayed + ((time - timeOffset)* playbackSpeed) > lastTimeStamp)) {
|
||||||
|
lastPlayed += ((time - timeOffset)* playbackSpeed);
|
||||||
if(file.bytesAvailable() < 4) {
|
if(file.bytesAvailable() < 4) {
|
||||||
stopReplay();
|
stopReplay();
|
||||||
return;
|
return;
|
||||||
@ -98,6 +101,11 @@ void LogFile::timerFired()
|
|||||||
|
|
||||||
file.read((char *) &dataSize, sizeof(dataSize));
|
file.read((char *) &dataSize, sizeof(dataSize));
|
||||||
|
|
||||||
|
if (dataSize<1 || dataSize>(1024*1024)) {
|
||||||
|
qDebug() << "Error: Logfile corrupted! Unlikely packet size: " << dataSize << "\n";
|
||||||
|
stopReplay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(file.bytesAvailable() < dataSize) {
|
if(file.bytesAvailable() < dataSize) {
|
||||||
stopReplay();
|
stopReplay();
|
||||||
return;
|
return;
|
||||||
@ -113,7 +121,19 @@ void LogFile::timerFired()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int save=lastTimeStamp;
|
||||||
file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp));
|
file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp));
|
||||||
|
// some validity checks
|
||||||
|
if (lastTimeStamp<save // logfile goies back in time
|
||||||
|
|| (lastTimeStamp-save) > (60*60*1000)) { // gap of more than 60 minutes)
|
||||||
|
qDebug() << "Error: Logfile corrupted! Unlikely timestamp " << lastTimeStamp << " after "<< save << "\n";
|
||||||
|
stopReplay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeOffset = time;
|
||||||
|
time = myTime.elapsed();
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stopReplay();
|
stopReplay();
|
||||||
@ -125,6 +145,7 @@ bool LogFile::startReplay() {
|
|||||||
dataBuffer.clear();
|
dataBuffer.clear();
|
||||||
myTime.restart();
|
myTime.restart();
|
||||||
timeOffset = 0;
|
timeOffset = 0;
|
||||||
|
lastPlayed = 0;
|
||||||
playbackSpeed = 1;
|
playbackSpeed = 1;
|
||||||
file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp));
|
file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp));
|
||||||
timer.setInterval(10);
|
timer.setInterval(10);
|
||||||
@ -142,12 +163,11 @@ bool LogFile::stopReplay() {
|
|||||||
void LogFile::pauseReplay()
|
void LogFile::pauseReplay()
|
||||||
{
|
{
|
||||||
timer.stop();
|
timer.stop();
|
||||||
pausedTime = myTime.elapsed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogFile::resumeReplay()
|
void LogFile::resumeReplay()
|
||||||
{
|
{
|
||||||
timeOffset += myTime.elapsed() - pausedTime;
|
timeOffset = myTime.elapsed();
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
bool stopReplay();
|
bool stopReplay();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setReplaySpeed(double val) { playbackSpeed = pow(10,(val)/100); qDebug() << playbackSpeed; };
|
void setReplaySpeed(double val) { playbackSpeed = val; qDebug() << playbackSpeed; };
|
||||||
void pauseReplay();
|
void pauseReplay();
|
||||||
void resumeReplay();
|
void resumeReplay();
|
||||||
|
|
||||||
@ -45,11 +45,11 @@ protected:
|
|||||||
QTime myTime;
|
QTime myTime;
|
||||||
QFile file;
|
QFile file;
|
||||||
qint32 lastTimeStamp;
|
qint32 lastTimeStamp;
|
||||||
|
qint32 lastPlayed;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
|
|
||||||
int timeOffset;
|
int timeOffset;
|
||||||
int pausedTime;
|
|
||||||
double playbackSpeed;
|
double playbackSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user