mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
Added save to SD card functions.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2833 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
5e501f3cae
commit
1bb5ed54ff
@ -30,10 +30,6 @@
|
|||||||
|
|
||||||
#include "utils/homelocationutil.h"
|
#include "utils/homelocationutil.h"
|
||||||
|
|
||||||
#include "extensionsystem/pluginmanager.h"
|
|
||||||
#include "uavobjectmanager.h"
|
|
||||||
#include "uavobject.h"
|
|
||||||
|
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -51,6 +47,64 @@ UAVObjectUtilManager::~UAVObjectUtilManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ******************************
|
||||||
|
// SD card saving
|
||||||
|
|
||||||
|
void UAVObjectUtilManager::saveObjectToSD(UAVObject *obj)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
|
|
||||||
|
if (!obj) return;
|
||||||
|
|
||||||
|
// Add to queue
|
||||||
|
queue.enqueue(obj);
|
||||||
|
|
||||||
|
// If queue length is one, then start sending (call sendNextObject)
|
||||||
|
// Otherwise, do nothing, it's sending anyway
|
||||||
|
if (queue.length() <= 1)
|
||||||
|
saveNextObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAVObjectUtilManager::saveNextObject()
|
||||||
|
{
|
||||||
|
if (queue.isEmpty()) return;
|
||||||
|
|
||||||
|
// Get next object from the queue
|
||||||
|
UAVObject *obj = queue.head();
|
||||||
|
if (!obj) return;
|
||||||
|
|
||||||
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
|
if (!pm) return;
|
||||||
|
|
||||||
|
UAVObjectManager *obm = pm->getObject<UAVObjectManager>();
|
||||||
|
if (!obm) return;
|
||||||
|
|
||||||
|
ObjectPersistence *objper = dynamic_cast<ObjectPersistence *>(obm->getObject(ObjectPersistence::NAME));
|
||||||
|
connect(objper, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transactionCompleted(UAVObject *, bool)));
|
||||||
|
|
||||||
|
ObjectPersistence::DataFields data;
|
||||||
|
data.Operation = ObjectPersistence::OPERATION_SAVE;
|
||||||
|
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
|
||||||
|
data.ObjectID = obj->getObjID();
|
||||||
|
data.InstanceID = obj->getInstID();
|
||||||
|
objper->setData(data);
|
||||||
|
objper->updated();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAVObjectUtilManager::transactionCompleted(UAVObject *obj, bool success)
|
||||||
|
{
|
||||||
|
Q_UNUSED(success);
|
||||||
|
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
|
|
||||||
|
if (!obj) return;
|
||||||
|
|
||||||
|
// Disconnect from sending object
|
||||||
|
obj->disconnect(this);
|
||||||
|
queue.dequeue(); // We can now remove the object, it's done.
|
||||||
|
saveNextObject();
|
||||||
|
}
|
||||||
|
|
||||||
// ******************************
|
// ******************************
|
||||||
// HomeLocation
|
// HomeLocation
|
||||||
|
|
||||||
@ -107,13 +161,11 @@ int UAVObjectUtilManager::setHomeLocation(double LLA[3], bool save_to_sdcard)
|
|||||||
// save the new location to SD card
|
// save the new location to SD card
|
||||||
|
|
||||||
if (save_to_sdcard)
|
if (save_to_sdcard)
|
||||||
{
|
saveObjectToSD(obj);
|
||||||
// saveObjectToSD(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ******************
|
// ******************
|
||||||
// debug
|
// debug
|
||||||
|
/*
|
||||||
qDebug() << "setting HomeLocation UAV Object .. " << endl;
|
qDebug() << "setting HomeLocation UAV Object .. " << endl;
|
||||||
QString s;
|
QString s;
|
||||||
s = " LAT:" + QString::number(LLA[0], 'f', 7) + " LON:" + QString::number(LLA[1], 'f', 7) + " ALT:" + QString::number(LLA[2], 'f', 1);
|
s = " LAT:" + QString::number(LLA[0], 'f', 7) + " LON:" + QString::number(LLA[1], 'f', 7) + " ALT:" + QString::number(LLA[2], 'f', 1);
|
||||||
@ -124,7 +176,7 @@ int UAVObjectUtilManager::setHomeLocation(double LLA[3], bool save_to_sdcard)
|
|||||||
qDebug() << s << endl;
|
qDebug() << s << endl;
|
||||||
s = " Be "; for (int i = 0; i < 3; i++) s += " " + QString::number(Be[i], 'f', 2);
|
s = " Be "; for (int i = 0; i < 3; i++) s += " " + QString::number(Be[i], 'f', 2);
|
||||||
qDebug() << s << endl;
|
qDebug() << s << endl;
|
||||||
|
*/
|
||||||
// ******************
|
// ******************
|
||||||
|
|
||||||
return 0; // OK
|
return 0; // OK
|
||||||
|
@ -31,9 +31,15 @@
|
|||||||
|
|
||||||
#include "uavobjectutil_global.h"
|
#include "uavobjectutil_global.h"
|
||||||
|
|
||||||
|
#include "extensionsystem/pluginmanager.h"
|
||||||
|
#include "uavobjectmanager.h"
|
||||||
|
#include "uavobject.h"
|
||||||
|
#include "objectpersistence.h"
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QQueue>
|
||||||
|
|
||||||
class UAVOBJECTUTIL_EXPORT UAVObjectUtilManager: public QObject
|
class UAVOBJECTUTIL_EXPORT UAVObjectUtilManager: public QObject
|
||||||
{
|
{
|
||||||
@ -52,6 +58,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
QMutex *mutex;
|
QMutex *mutex;
|
||||||
|
|
||||||
|
QQueue<UAVObject *> queue;
|
||||||
|
|
||||||
|
void saveNextObject();
|
||||||
|
void saveObjectToSD(UAVObject *obj);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void transactionCompleted(UAVObject *obj, bool success);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user