2013-11-19 07:39:52 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file flightlogmanager.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @addtogroup [Group]
|
|
|
|
* @{
|
|
|
|
* @addtogroup FlightLogManager
|
|
|
|
* @{
|
|
|
|
* @brief [Brief]
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "flightlogmanager.h"
|
2013-11-20 12:24:34 +01:00
|
|
|
#include "extensionsystem/pluginmanager.h"
|
2013-11-19 07:39:52 +01:00
|
|
|
|
2013-11-20 12:24:34 +01:00
|
|
|
#include "debuglogcontrol.h"
|
2013-11-24 17:50:07 +01:00
|
|
|
#include "uavobjecthelper.h"
|
2013-11-20 00:07:04 +01:00
|
|
|
|
|
|
|
FlightLogManager::FlightLogManager(QObject *parent) :
|
|
|
|
QObject(parent) {
|
|
|
|
|
2013-11-20 12:24:34 +01:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
m_objectManager = pm->getObject<UAVObjectManager>();
|
|
|
|
Q_ASSERT(m_objectManager);
|
|
|
|
|
2013-11-24 17:50:07 +01:00
|
|
|
m_flightLogControl = DebugLogControl::GetInstance(m_objectManager);
|
|
|
|
Q_ASSERT(m_flightLogControl);
|
|
|
|
|
2013-11-20 12:24:34 +01:00
|
|
|
m_flightLogStatus = DebugLogStatus::GetInstance(m_objectManager);
|
|
|
|
Q_ASSERT(m_flightLogStatus);
|
|
|
|
|
2013-11-24 17:50:07 +01:00
|
|
|
m_flightLogEntry = DebugLogEntry::GetInstance(m_objectManager);
|
|
|
|
Q_ASSERT(m_flightLogEntry);
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FlightLogManager::~FlightLogManager() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-25 14:59:23 +01:00
|
|
|
void addEntries(QQmlListProperty<ExtendedDebugLogEntry> *list, ExtendedDebugLogEntry *entry) {
|
|
|
|
Q_UNUSED(list);
|
|
|
|
Q_UNUSED(entry);
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 14:59:23 +01:00
|
|
|
int countEntries(QQmlListProperty<ExtendedDebugLogEntry> *list) {
|
|
|
|
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->size();
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 14:59:23 +01:00
|
|
|
ExtendedDebugLogEntry* entryAt(QQmlListProperty<ExtendedDebugLogEntry> *list, int index) {
|
|
|
|
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->at(index);
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 14:59:23 +01:00
|
|
|
void clearEntries(QQmlListProperty<ExtendedDebugLogEntry> *list) {
|
|
|
|
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->clear();
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 14:59:23 +01:00
|
|
|
QQmlListProperty<ExtendedDebugLogEntry> FlightLogManager::logEntries() {
|
|
|
|
return QQmlListProperty<ExtendedDebugLogEntry>(this, &m_logEntries, &addEntries, &countEntries, &entryAt, &clearEntries);
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-20 00:07:04 +01:00
|
|
|
void FlightLogManager::clearAllLogs() {
|
|
|
|
|
2013-11-20 16:24:57 +01:00
|
|
|
//Clear on flight side
|
|
|
|
m_logEntries.clear();
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:50:07 +01:00
|
|
|
void FlightLogManager::retrieveLogs(int flightToRetrieve) {
|
|
|
|
|
|
|
|
UAVObjectUpdaterHelper updateHelper;
|
|
|
|
UAVObjectRequestHelper requestHelper;
|
|
|
|
|
2013-11-20 16:24:57 +01:00
|
|
|
//Get logs from flight side
|
2013-11-24 17:50:07 +01:00
|
|
|
m_logEntries.clear();
|
|
|
|
|
|
|
|
// Set up what to retrieve
|
|
|
|
bool timedOut = false;
|
|
|
|
int startFlight = (flightToRetrieve == -1) ? 0 : flightToRetrieve;
|
|
|
|
int endFlight = (flightToRetrieve == -1 ) ? m_flightLogStatus->getFlight() : flightToRetrieve;
|
|
|
|
|
|
|
|
// Prepare to send request for event retrieval
|
|
|
|
m_flightLogControl->setOperation(DebugLogControl::OPERATION_RETRIEVE);
|
2013-11-24 21:47:57 +01:00
|
|
|
for(int flight = startFlight; flight <= endFlight; flight++) {
|
2013-11-24 17:50:07 +01:00
|
|
|
m_flightLogControl->setFlight(flight);
|
|
|
|
bool gotLast = false;
|
|
|
|
int entry = 0;
|
|
|
|
while(!gotLast) {
|
|
|
|
|
|
|
|
// Send request for loading flight entry on flight side and wait for ack/nack
|
|
|
|
m_flightLogControl->setEntry(entry);
|
|
|
|
|
|
|
|
UAVObjectUpdaterHelper::Result result = updateHelper.doObjectAndWait(m_flightLogControl, UAVTALK_TIMEOUT);
|
|
|
|
if(result == UAVObjectUpdaterHelper::SUCCESS) {
|
|
|
|
result = requestHelper.doObjectAndWait(m_flightLogEntry, UAVTALK_TIMEOUT);
|
|
|
|
if(result == UAVObjectUpdaterHelper::TIMEOUT) {
|
|
|
|
timedOut = true;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if(!m_flightLogEntry->getType() == DebugLogEntry::TYPE_EMPTY &&
|
|
|
|
m_flightLogEntry->getFlight() == flight && m_flightLogEntry->getEntry() == entry) {
|
|
|
|
|
|
|
|
//Ok, we retrieved the entry, and it was the correct one. clone it and add it to the list
|
2013-11-25 14:59:23 +01:00
|
|
|
|
|
|
|
ExtendedDebugLogEntry* logEntry = new ExtendedDebugLogEntry();
|
2013-11-25 17:58:29 +01:00
|
|
|
logEntry->setObjectManager(m_objectManager);
|
2013-11-25 14:59:23 +01:00
|
|
|
logEntry->setData(m_flightLogEntry->getData());
|
|
|
|
m_logEntries.append(logEntry);
|
2013-11-24 17:50:07 +01:00
|
|
|
|
|
|
|
// Increment to get next entry from flight side
|
|
|
|
entry++;
|
|
|
|
} else {
|
|
|
|
// We are done, not more entries on this flight
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(timedOut) {
|
|
|
|
// We timed out, do something smart here to alert the user
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 14:59:23 +01:00
|
|
|
emit logEntriesChanged();
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
2013-11-20 21:08:26 +01:00
|
|
|
|
|
|
|
void FlightLogManager::exportLogs()
|
|
|
|
{
|
2013-11-25 17:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry(),
|
|
|
|
m_objectManager(0), m_object(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtendedDebugLogEntry::~ExtendedDebugLogEntry()
|
|
|
|
{
|
|
|
|
if(m_object) {
|
|
|
|
delete m_object;
|
|
|
|
m_object = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-11-20 21:08:26 +01:00
|
|
|
|
2013-11-25 17:58:29 +01:00
|
|
|
QString ExtendedDebugLogEntry::getLogString()
|
|
|
|
{
|
|
|
|
if(getType() == DebugLogEntry::TYPE_TEXT) {
|
|
|
|
return QString((const char*)getData().Data);
|
|
|
|
} else if (getType() == DebugLogEntry::TYPE_UAVOBJECT) {
|
|
|
|
UAVDataObject *object = (UAVDataObject*)m_objectManager->getObject(getObjectID(), getInstanceID());
|
|
|
|
object = object->clone(getInstanceID());
|
|
|
|
object->unpack(getData().Data);
|
|
|
|
m_object = object;
|
|
|
|
return object->toString().replace("\n", " ").replace("\t", " ");
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2013-11-20 21:08:26 +01:00
|
|
|
}
|
2013-11-25 14:59:23 +01:00
|
|
|
|
2013-11-25 17:58:29 +01:00
|
|
|
void ExtendedDebugLogEntry::setObjectManager(UAVObjectManager *objectManager)
|
2013-11-25 14:59:23 +01:00
|
|
|
{
|
2013-11-25 17:58:29 +01:00
|
|
|
m_objectManager = objectManager;
|
2013-11-25 14:59:23 +01:00
|
|
|
}
|