2 ******************************************************************************
4 * @file flightlogmanager.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
8 * @addtogroup FlightLogManager
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef FLIGHTLOGMANAGER_H
29 #define FLIGHTLOGMANAGER_H
34 #include <QQmlListProperty>
36 #include <QXmlStreamWriter>
37 #include <QTextStream>
39 #include "uavobjectmanager.h"
40 #include "uavobjectutilmanager.h"
41 #include "debuglogentry.h"
42 #include "debuglogstatus.h"
43 #include "debuglogsettings.h"
44 #include "debuglogcontrol.h"
45 #include "objectpersistence.h"
46 #include "uavtalk/telemetrymanager.h"
48 class UAVOLogSettingsWrapper
: public QObject
{
49 Q_OBJECT
Q_PROPERTY(UAVDataObject
*object READ object NOTIFY objectChanged
)
50 Q_PROPERTY(QString name READ name NOTIFY nameChanged
)
51 Q_PROPERTY(int setting READ setting WRITE setSetting NOTIFY settingChanged
)
52 Q_PROPERTY(int period READ period WRITE setPeriod NOTIFY periodChanged
)
53 Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged
)
56 enum UAVLogSetting
{ DISABLED
= 0, ON_CHANGE
, THROTTLED
, PERIODICALLY
};
58 explicit UAVOLogSettingsWrapper();
59 explicit UAVOLogSettingsWrapper(UAVDataObject
*object
);
60 ~UAVOLogSettingsWrapper();
64 return m_object
->getName();
72 UAVObject::UpdateMode
settingAsUpdateMode();
79 UAVDataObject
*object() const
90 void setSetting(int setting
)
92 if (m_setting
!= setting
) {
95 if (m_setting
!= 1 && m_setting
!= 3) {
102 emit
settingChanged(setting
);
106 void setPeriod(int arg
)
108 if (m_period
!= arg
) {
111 emit
periodChanged(arg
);
115 void setDirty(bool arg
)
117 if (m_dirty
!= arg
) {
119 emit
dirtyChanged(arg
);
123 void reset(bool clear
);
126 void settingChanged(int setting
);
127 void nameChanged(QString name
);
128 void periodChanged(int period
);
129 void objectChanged(UAVDataObject
*arg
);
131 void dirtyChanged(bool arg
);
134 UAVDataObject
*m_object
;
140 class ExtendedDebugLogEntry
: public DebugLogEntry
{
141 Q_OBJECT
Q_PROPERTY(QString LogString READ getLogString WRITE setLogString NOTIFY LogStringUpdated
)
144 explicit ExtendedDebugLogEntry();
145 ~ExtendedDebugLogEntry();
147 QString
getLogString();
148 void toXML(QXmlStreamWriter
*xmlWriter
, quint32 baseTime
);
149 void toCSV(QTextStream
*csvStream
, quint32 baseTime
);
150 UAVDataObject
*uavObject()
155 void setData(const DataFields
& data
, UAVObjectManager
*objectManager
);
158 void setLogString(QString arg
)
164 void LogStringUpdated(QString arg
);
167 UAVDataObject
*m_object
;
170 class FlightLogManager
: public QObject
{
171 Q_OBJECT
Q_PROPERTY(DebugLogStatus
*flightLogStatus READ flightLogStatus
)
172 Q_PROPERTY(DebugLogControl
* flightLogControl READ flightLogControl
)
173 Q_PROPERTY(DebugLogSettings
* flightLogSettings READ flightLogSettings
)
174 Q_PROPERTY(QQmlListProperty
<ExtendedDebugLogEntry
> logEntries READ logEntries NOTIFY logEntriesChanged
)
175 Q_PROPERTY(QStringList flightEntries READ flightEntries NOTIFY flightEntriesChanged
)
176 Q_PROPERTY(bool disableControls READ disableControls WRITE setDisableControls NOTIFY disableControlsChanged
)
177 Q_PROPERTY(bool disableExport READ disableExport WRITE setDisableExport NOTIFY disableExportChanged
)
178 Q_PROPERTY(bool adjustExportedTimestamps READ adjustExportedTimestamps WRITE setAdjustExportedTimestamps NOTIFY adjustExportedTimestampsChanged
)
179 Q_PROPERTY(bool boardConnected READ boardConnected WRITE setBoardConnected NOTIFY boardConnectedChanged
)
181 Q_PROPERTY(QQmlListProperty
<UAVOLogSettingsWrapper
> uavoEntries READ uavoEntries NOTIFY uavoEntriesChanged
)
182 Q_PROPERTY(QStringList logSettings READ logSettings NOTIFY logSettingsChanged
)
183 Q_PROPERTY(QStringList logStatuses READ logStatuses NOTIFY logStatusesChanged
)
184 Q_PROPERTY(int loggingEnabled READ loggingEnabled WRITE setLoggingEnabled NOTIFY loggingEnabledChanged
)
185 Q_PROPERTY(int logEntriesCount READ logEntriesCount NOTIFY logEntriesChanged
)
188 explicit FlightLogManager(QObject
*parent
= 0);
191 QQmlListProperty
<ExtendedDebugLogEntry
> logEntries();
192 QQmlListProperty
<UAVOLogSettingsWrapper
> uavoEntries();
194 QStringList
flightEntries();
196 QStringList
logSettings()
198 return m_logSettings
;
201 DebugLogStatus
*flightLogStatus() const
203 return m_flightLogStatus
;
206 bool disableControls() const
208 return m_disableControls
;
211 bool disableExport() const
213 return m_disableExport
;
218 bool adjustExportedTimestamps() const
220 return m_adjustExportedTimestamps
;
223 bool boardConnected() const
225 return m_boardConnected
;
228 QStringList
logStatuses() const
230 return m_logStatuses
;
233 DebugLogControl
*flightLogControl() const
235 return m_flightLogControl
;
238 DebugLogSettings
*flightLogSettings() const
240 return m_flightLogSettings
;
243 int loggingEnabled() const
245 return m_loggingEnabled
;
247 int logEntriesCount()
249 return m_logEntries
.count();
252 void logEntriesChanged();
253 void flightEntriesChanged();
254 void logSettingsChanged();
255 void uavoEntriesChanged();
256 void disableControlsChanged(bool arg
);
257 void disableExportChanged(bool arg
);
258 void adjustExportedTimestampsChanged(bool arg
);
259 void boardConnectedChanged(bool arg
);
261 void logStatusesChanged(QStringList arg
);
262 void loggingEnabledChanged(int arg
);
266 void retrieveLogs(int flightToRetrieve
= -1);
268 void cancelExportLogs();
271 void resetSettings(bool clear
);
272 void saveSettingsToBoard();
273 bool saveUAVObjectToFlash(UAVObject
*object
);
275 void setDisableControls(bool arg
)
277 if (m_disableControls
!= arg
) {
278 m_disableControls
= arg
;
279 emit
disableControlsChanged(arg
);
283 void setDisableExport(bool arg
)
285 if (m_disableExport
!= arg
) {
286 m_disableExport
= arg
;
287 emit
disableExportChanged(arg
);
291 void setAdjustExportedTimestamps(bool arg
)
293 if (m_adjustExportedTimestamps
!= arg
) {
294 m_adjustExportedTimestamps
= arg
;
295 emit
adjustExportedTimestampsChanged(arg
);
299 void setBoardConnected(bool arg
)
301 if (m_boardConnected
!= arg
) {
302 m_boardConnected
= arg
;
303 emit
boardConnectedChanged(arg
);
307 void setLoggingEnabled(int arg
)
309 if (m_loggingEnabled
!= arg
) {
310 m_loggingEnabled
= arg
;
311 emit
loggingEnabledChanged(arg
);
316 void updateFlightEntries(quint16 currentFlight
);
317 void setupUAVOWrappers();
318 void setupLogSettings();
319 void setupLogStatuses();
320 void connectionStatusChanged();
321 bool updateLogWrapper(QString name
, int level
, int period
);
324 UAVObjectManager
*m_objectManager
;
325 UAVObjectUtilManager
*m_objectUtilManager
;
326 TelemetryManager
*m_telemtryManager
;
327 DebugLogControl
*m_flightLogControl
;
328 DebugLogStatus
*m_flightLogStatus
;
329 DebugLogEntry
*m_flightLogEntry
;
330 DebugLogSettings
*m_flightLogSettings
;
331 ObjectPersistence
*m_objectPersistence
;
333 QList
<ExtendedDebugLogEntry
*> m_logEntries
;
334 QStringList m_flightEntries
;
335 QStringList m_logSettings
;
336 QStringList m_logStatuses
;
338 QList
<UAVOLogSettingsWrapper
*> m_uavoEntries
;
339 QHash
<QString
, UAVOLogSettingsWrapper
*> m_uavoEntriesHash
;
341 void exportToOPL(QString fileName
);
342 void exportToCSV(QString fileName
);
343 void exportToXML(QString fileName
);
345 static const int UAVTALK_TIMEOUT
= 4000;
346 static const int LOG_SETTINGS_FILE_VERSION
= 1;
347 bool m_disableControls
;
348 bool m_disableExport
;
349 bool m_cancelDownload
;
350 bool m_adjustExportedTimestamps
;
351 bool m_boardConnected
;
352 int m_loggingEnabled
;
355 #endif // FLIGHTLOGMANAGER_H