1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

OP-24 Ground/Logging: Made logging module use QIODevice passed to UAVTalk which inserts timestamps and object sizes. Should be trivial to implement read functionality. Need to confirm that QIODevice writes the data in the correct size though so timestamps are in the write place for sure.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1700 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2010-09-21 07:07:39 +00:00 committed by peabody124
parent 0634f8ec53
commit 5c9701753b
5 changed files with 98 additions and 35 deletions

View File

@ -0,0 +1,49 @@
#include "logfile.h"
#include <QDebug>
LogFile::LogFile(QObject *parent) :
QIODevice(parent)
{
}
bool LogFile::open(OpenMode mode) {
// start a timer for playback
myTime.restart();
// TODO: support openning for read or write to determine playback or not
Q_ASSERT(mode == QIODevice::WriteOnly);
if(file.open(mode) == FALSE)
{
qDebug() << "Unable to open " << file.fileName() << " for logging";
return false;
}
// TODO: Write a header at the beginng describing objects so that in future
// they can be read back if ID's change
// Must call parent function for QIODevice to pass calls to writeData
QIODevice::open(mode);
return true;
}
void LogFile::close()
{
file.close();
QIODevice::close();
}
qint64 LogFile::writeData(const char * data, qint64 dataSize) {
quint32 timeStamp = myTime.elapsed();
file.write((char *) &timeStamp,sizeof(timeStamp));
file.write((char *) &dataSize, sizeof(dataSize));
qint64 written = file.write(data, dataSize);
if(written != -1)
emit bytesWritten(written);
//qDebug() << "Wrote " << dataSize << " bytes at " << timeStamp << " ms";
return dataSize;
}

View File

@ -0,0 +1,30 @@
#ifndef LOGFILE_H
#define LOGFILE_H
#include <QIODevice>
#include <QTime>
#include <QDebug>
#include <uavobjects/uavobjectmanager.h>
class LogFile : public QIODevice
{
Q_OBJECT
public:
explicit LogFile(QObject *parent = 0);
qint64 bytesAvailable() { return 0; };
qint64 bytesToWrite() { return file.bytesToWrite(); };
bool open(OpenMode mode);
void setFileName(QString name) { file.setFileName(name); };
void close();
qint64 writeData(const char * data, qint64 dataSize);
qint64 readData(char * /*data*/, qint64 /*maxlen*/) {return 0; }
signals:
public slots:
private:
protected:
QTime myTime;
QFile file;
};
#endif // LOGFILE_H

View File

@ -4,8 +4,10 @@ DEFINES += LOGGING_LIBRARY
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/uavtalk/uavtalk.pri)
include(logging_dependencies.pri)
HEADERS += loggingplugin.h
HEADERS += loggingplugin.h \
logfile.h
# logginggadgetwidget.h \
# loggingdialog.h \
# logginggadget.h \
@ -13,7 +15,8 @@ HEADERS += loggingplugin.h
# logginggadgetconfiguration.h
# logginggadgetoptionspage.h
SOURCES += loggingplugin.cpp
SOURCES += loggingplugin.cpp \
logfile.cpp
# logginggadgetwidget.cpp \
# loggingdialog.cpp \
# logginggadget.cpp \

View File

@ -43,6 +43,7 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
#include <QKeySequence>
#include <uavobjects/uavobjectmanager.h>
/**
* Sets the file to use for logging and takes the parent plugin
@ -52,15 +53,13 @@
*/
bool LoggingThread::openFile(QString file, LoggingPlugin * parent)
{
// TODO: Write a header at the beginng describing objects so that in future
// they can be read back if ID's change
logFile.setFileName(file);
if(logFile.open(QIODevice::WriteOnly) == FALSE)
{
qDebug() << "Unable to open " << file << " for logging";
return false;
}
logFile.open(QIODevice::WriteOnly);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
uavTalk = new UAVTalk(&logFile, objManager);
connect(parent,SIGNAL(stopLoggingSignal()),this,SLOT(stopLogging()));
return true;
@ -74,28 +73,9 @@ bool LoggingThread::openFile(QString file, LoggingPlugin * parent)
*/
void LoggingThread::objectUpdated(UAVObject * obj)
{
quint32 timeStamp = myTime.elapsed();
quint32 objSize = obj->getNumBytes();
quint32 objId = obj->getObjID();
quint32 objInst = obj->getInstID();
quint8 * buffer = new quint8[objSize+16];
if(buffer == NULL)
return;
obj->pack(&buffer[16]);
memcpy(buffer,&timeStamp,4);
memcpy(&buffer[4],&objSize,4);
memcpy(&buffer[8],&objId,4);
memcpy(&buffer[12],&objInst,4);
QWriteLocker locker(&lock);
qint64 written = logFile.write((char *) buffer,objSize+8);
delete(buffer);
//qDebug() << obj->getName() << " logged at " << timeStamp << " size: " << objSize << " written " << written;
if(!uavTalk->sendObject(obj,false,false) )
qDebug() << "Error logging " << obj->getName();
};
/**
@ -123,7 +103,6 @@ void LoggingThread::run()
}
}
myTime.restart();
exec();
}
@ -135,7 +114,7 @@ void LoggingThread::stopLogging()
{
QWriteLocker locker(&lock);
logFile.close();
qDebug() << "File " << logFile.fileName() << " closed";
qDebug() << "File closed";
quit();
}

View File

@ -29,8 +29,10 @@
#include <extensionsystem/iplugin.h>
#include <uavobjects/uavobjectmanager.h>
#include <uavtalk/uavtalk.h>
#include <logfile.h>
#include <QThread>
#include <QTime>
#include <QReadWriteLock>
class LoggingPlugin;
@ -49,9 +51,9 @@ public slots:
protected:
void run();
QFile logFile;
QTime myTime;
QReadWriteLock lock;
LogFile logFile;
UAVTalk * uavTalk;
};
class LoggingPlugin : public ExtensionSystem::IPlugin