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

OP-1245 Re-factored saving to board. Added code to save more things.

This commit is contained in:
m_thread 2014-03-20 17:02:44 +01:00
parent 838d8dd15f
commit b508c7dc96
2 changed files with 41 additions and 41 deletions

View File

@ -69,6 +69,9 @@ FlightLogManager::FlightLogManager(QObject *parent) :
m_flightLogSettings = DebugLogSettings::GetInstance(m_objectManager);
Q_ASSERT(m_flightLogSettings);
m_objectPersistence = ObjectPersistence::GetInstance(m_objectManager);
Q_ASSERT(m_objectPersistence);
updateFlightEntries(m_flightLogStatus->getFlight());
setupLogSettings();
@ -490,11 +493,40 @@ void FlightLogManager::resetSettings(bool clear)
void FlightLogManager::saveSettingsToBoard()
{
m_flightLogSettings->setLoggingEnabled(m_loggingEnabled);
saveUAVObjectToFlash(m_flightLogSettings);
foreach(UAVOLogSettingsWrapper * wrapper, m_uavoEntries) {
wrapper->save();
if (wrapper->dirty()) {
UAVObject::Metadata meta = wrapper->object()->getMetadata();
wrapper->object()->SetLoggingUpdateMode(meta, wrapper->settingAsUpdateMode());
meta.loggingUpdatePeriod = wrapper->period();
wrapper->object()->setMetadata(meta);
if (saveUAVObjectToFlash(wrapper->object()->getMetaObject())) {
wrapper->setDirty(false);
}
}
}
}
bool FlightLogManager::saveUAVObjectToFlash(UAVObject *object)
{
UAVObjectUpdaterHelper helper;
if (helper.doObjectAndWait(object, 3000) == UAVObjectUpdaterHelper::SUCCESS) {
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_SAVE;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = object->getObjID();
data.InstanceID = object->getInstID();
m_objectPersistence->setData(data);
return (helper.doObjectAndWait(m_objectPersistence, 3000) == UAVObjectUpdaterHelper::SUCCESS);
}
return false;
}
void FlightLogManager::updateFlightEntries(quint16 currentFlight)
{
Q_UNUSED(currentFlight);
@ -514,14 +546,10 @@ void FlightLogManager::updateFlightEntries(quint16 currentFlight)
void FlightLogManager::setupUAVOWrappers()
{
ObjectPersistence *objectPersistance = ObjectPersistence::GetInstance(m_objectManager);
Q_ASSERT(objectPersistance);
foreach(QList<UAVObject *> objectList, m_objectManager->getObjects()) {
UAVObject *object = objectList.at(0);
if (!object->isMetaDataObject() && !object->isSettingsObject()) {
UAVOLogSettingsWrapper *wrapper = new UAVOLogSettingsWrapper(qobject_cast<UAVDataObject *>(object), objectPersistance);
UAVOLogSettingsWrapper *wrapper = new UAVOLogSettingsWrapper(qobject_cast<UAVDataObject *>(object));
m_uavoEntries.append(wrapper);
m_uavoEntriesHash[wrapper->name()] = wrapper;
}
@ -641,8 +669,8 @@ void ExtendedDebugLogEntry::setData(const DebugLogEntry::DataFields &data, UAVOb
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper() : QObject()
{}
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper(UAVDataObject *object, ObjectPersistence *persistence) : QObject(),
m_object(object), m_setting(DISABLED), m_period(0), m_dirty(0), m_objectPersistence(persistence)
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper(UAVDataObject *object) : QObject(),
m_object(object), m_setting(DISABLED), m_period(0), m_dirty(0)
{
reset(false);
}
@ -657,34 +685,6 @@ void UAVOLogSettingsWrapper::reset(bool clear)
setDirty(false);
}
void UAVOLogSettingsWrapper::save()
{
if(m_dirty) {
UAVObject::Metadata meta = m_object->getMetadata();
m_object->SetLoggingUpdateMode(meta, settingAsUpdateMode());
meta.loggingUpdatePeriod = m_period;
m_object->setMetadata(meta);
UAVObjectUpdaterHelper helper;
if (helper.doObjectAndWait(m_object->getMetaObject(), 1000) == UAVObjectUpdaterHelper::SUCCESS) {
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_SAVE;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = m_object->getMetaObject()->getObjID();
data.InstanceID = m_object->getMetaObject()->getInstID();
m_objectPersistence->setData(data);
if (helper.doObjectAndWait(m_objectPersistence, 1000) == UAVObjectUpdaterHelper::SUCCESS) {
setDirty(false);
} else {
qDebug() << "Storing failed!";
}
} else {
qDebug() << "Updating failed!";
}
}
}
UAVObject::UpdateMode UAVOLogSettingsWrapper::settingAsUpdateMode()
{
switch (m_setting) {

View File

@ -56,7 +56,7 @@ public:
enum UAVLogSetting { DISABLED = 0, ON_CHANGE, THROTTLED, PERIODICALLY };
explicit UAVOLogSettingsWrapper();
explicit UAVOLogSettingsWrapper(UAVDataObject *object, ObjectPersistence *persistence);
explicit UAVOLogSettingsWrapper(UAVDataObject *object);
~UAVOLogSettingsWrapper();
QString name() const
@ -69,6 +69,8 @@ public:
return m_setting;
}
UAVObject::UpdateMode settingAsUpdateMode();
int period() const
{
return m_period;
@ -115,8 +117,6 @@ public slots:
}
void reset(bool clear);
void save();
void apply();
signals:
void settingChanged(int setting);
@ -131,9 +131,7 @@ private:
int m_setting;
int m_period;
bool m_dirty;
ObjectPersistence *m_objectPersistence;
UAVObject::UpdateMode settingAsUpdateMode();
};
class ExtendedDebugLogEntry : public DebugLogEntry {
@ -266,6 +264,7 @@ public slots:
void saveSettings();
void resetSettings(bool clear);
void saveSettingsToBoard();
bool saveUAVObjectToFlash(UAVObject *object);
void setDisableControls(bool arg)
{
@ -322,6 +321,7 @@ private:
DebugLogStatus *m_flightLogStatus;
DebugLogEntry *m_flightLogEntry;
DebugLogSettings *m_flightLogSettings;
ObjectPersistence *m_objectPersistence;
QList<ExtendedDebugLogEntry *> m_logEntries;
QStringList m_flightEntries;