1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

While change the util manager make a few other methods use static accessors.

This commit is contained in:
James Cotton 2012-06-03 18:00:16 -05:00
parent 2d80d59e93
commit 4d75718347
2 changed files with 46 additions and 79 deletions

View File

@ -35,6 +35,7 @@
#include <QEventLoop> #include <QEventLoop>
#include <QTimer> #include <QTimer>
#include <objectpersistence.h> #include <objectpersistence.h>
#include <firmwareiapobj.h>
// ****************************** // ******************************
// constructor/destructor // constructor/destructor
@ -225,6 +226,37 @@ void UAVObjectUtilManager::objectPersistenceUpdated(UAVObject * obj)
} }
} }
/**
* Helper function that makes sure FirmwareIAP is updated and then returns the data
*/
FirmwareIAPObj::DataFields UAVObjectUtilManager::getFirmwareIap()
{
FirmwareIAPObj::DataFields dummy;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm);
if (!pm)
return dummy;
UAVObjectManager *om = pm->getObject<UAVObjectManager>();
Q_ASSERT(om);
if (!om)
return dummy;
FirmwareIAPObj *firmwareIap = FirmwareIAPObj::GetInstance(om);
Q_ASSERT(firmwareIap);
if (!firmwareIap)
return dummy;
// The code below will ask for the object update and wait for the updated to be received,
// or the timeout of the timer, set to 1 second.
QEventLoop loop;
connect(firmwareIap, SIGNAL(objectUpdated(UAVObject*)), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); // Create a timeout
firmwareIap->requestUpdate();
loop.exec();
return firmwareIap->getData();
}
/** /**
* Get the UAV Board model, for anyone interested. Return format is: * Get the UAV Board model, for anyone interested. Return format is:
@ -232,25 +264,8 @@ void UAVObjectUtilManager::objectPersistenceUpdated(UAVObject * obj)
*/ */
int UAVObjectUtilManager::getBoardModel() int UAVObjectUtilManager::getBoardModel()
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); FirmwareIAPObj::DataFields firmwareIapData = getFirmwareIap();
if (!pm) return (firmwareIapData.BoardType << 8) + firmwareIapData.BoardRevision;
return 0;
UAVObjectManager *om = pm->getObject<UAVObjectManager>();
if (!om)
return 0;
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(om->getObject(QString("FirmwareIAPObj")));
// The code below will ask for the object update and wait for the updated to be received,
// or the timeout of the timer, set to 1 second.
QEventLoop loop;
connect(obj, SIGNAL(objectUpdated(UAVObject*)), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); // Create a timeout
obj->requestUpdate();
loop.exec();
int boardType = (obj->getField("BoardType")->getValue().toInt()) << 8;
boardType += obj->getField("BoardRevision")->getValue().toInt();
return boardType;
} }
/** /**
@ -259,54 +274,18 @@ int UAVObjectUtilManager::getBoardModel()
QByteArray UAVObjectUtilManager::getBoardCPUSerial() QByteArray UAVObjectUtilManager::getBoardCPUSerial()
{ {
QByteArray cpuSerial; QByteArray cpuSerial;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); FirmwareIAPObj::DataFields firmwareIapData = getFirmwareIap();
if (!pm)
return 0;
UAVObjectManager *om = pm->getObject<UAVObjectManager>();
if (!om)
return 0;
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(om->getObject(QString("FirmwareIAPObj"))); for (int i = 0; i < FirmwareIAPObj::CPUSERIAL_NUMELEM; i++)
// The code below will ask for the object update and wait for the updated to be received, cpuSerial.append(firmwareIapData.CPUSerial[i]);
// or the timeout of the timer, set to 1 second.
QEventLoop loop;
connect(obj, SIGNAL(objectUpdated(UAVObject*)), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); // Create a timeout
obj->requestUpdate();
loop.exec();
UAVObjectField* cpuField = obj->getField("CPUSerial");
for (uint i = 0; i < cpuField->getNumElements(); ++i) {
cpuSerial.append(cpuField->getValue(i).toUInt());
}
return cpuSerial; return cpuSerial;
} }
quint32 UAVObjectUtilManager::getFirmwareCRC() quint32 UAVObjectUtilManager::getFirmwareCRC()
{ {
quint32 fwCRC; FirmwareIAPObj::DataFields firmwareIapData = getFirmwareIap();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); return firmwareIapData.crc;
if (!pm)
return 0;
UAVObjectManager *om = pm->getObject<UAVObjectManager>();
if (!om)
return 0;
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(om->getObject(QString("FirmwareIAPObj")));
obj->getField("crc")->setValue(0);
obj->updated();
// The code below will ask for the object update and wait for the updated to be received,
// or the timeout of the timer, set to 1 second.
QEventLoop loop;
connect(obj, SIGNAL(objectUpdated(UAVObject*)), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); // Create a timeout
obj->requestUpdate();
loop.exec();
UAVObjectField* fwCRCField = obj->getField("crc");
fwCRC=(quint32)fwCRCField->getValue().toLongLong();
return fwCRC;
} }
/** /**
@ -315,27 +294,11 @@ quint32 UAVObjectUtilManager::getFirmwareCRC()
QByteArray UAVObjectUtilManager::getBoardDescription() QByteArray UAVObjectUtilManager::getBoardDescription()
{ {
QByteArray ret; QByteArray ret;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); FirmwareIAPObj::DataFields firmwareIapData = getFirmwareIap();
if (!pm)
return 0;
UAVObjectManager *om = pm->getObject<UAVObjectManager>();
if (!om)
return 0;
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(om->getObject(QString("FirmwareIAPObj"))); for (int i = 0; i < FirmwareIAPObj::DESCRIPTION_NUMELEM; i++)
// The code below will ask for the object update and wait for the updated to be received, ret.append(firmwareIapData.Description[i]);
// or the timeout of the timer, set to 1 second.
QEventLoop loop;
connect(obj, SIGNAL(objectUpdated(UAVObject*)), &loop, SLOT(quit()));
QTimer::singleShot(1000, &loop, SLOT(quit())); // Create a timeout
obj->requestUpdate();
loop.exec();
UAVObjectField* descriptionField = obj->getField("Description");
// Description starts with an offset of
for (uint i = 0; i < descriptionField->getNumElements(); ++i) {
ret.append(descriptionField->getValue(i).toInt());
}
return ret; return ret;
} }

View File

@ -43,6 +43,8 @@
#include <QQueue> #include <QQueue>
#include <QComboBox> #include <QComboBox>
#include <QDateTime> #include <QDateTime>
#include <firmwareiapobj.h>
class UAVOBJECTUTIL_EXPORT UAVObjectUtilManager: public QObject class UAVOBJECTUTIL_EXPORT UAVObjectUtilManager: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -69,6 +71,8 @@ public:
static bool descriptionToStructure(QByteArray desc,deviceDescriptorStruct * struc); static bool descriptionToStructure(QByteArray desc,deviceDescriptorStruct * struc);
UAVObjectManager* getObjectManager(); UAVObjectManager* getObjectManager();
void saveObjectToSD(UAVObject *obj); void saveObjectToSD(UAVObject *obj);
protected:
FirmwareIAPObj::DataFields getFirmwareIap();
signals: signals:
void saveCompleted(int objectID, bool status); void saveCompleted(int objectID, bool status);