OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / flightlog / flightlogmanager.h
blob0c93d014b077e2c0c3ea1829b69dadb6705e5ee4
1 /**
2 ******************************************************************************
4 * @file flightlogmanager.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup [Group]
7 * @{
8 * @addtogroup FlightLogManager
9 * @{
10 * @brief [Brief]
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
21 * for more details.
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
31 #include <QObject>
32 #include <QList>
33 #include <QHash>
34 #include <QQmlListProperty>
35 #include <QSemaphore>
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)
55 public:
56 enum UAVLogSetting { DISABLED = 0, ON_CHANGE, THROTTLED, PERIODICALLY };
58 explicit UAVOLogSettingsWrapper();
59 explicit UAVOLogSettingsWrapper(UAVDataObject *object);
60 ~UAVOLogSettingsWrapper();
62 QString name() const
64 return m_object->getName();
67 int setting() const
69 return m_setting;
72 UAVObject::UpdateMode settingAsUpdateMode();
74 int period() const
76 return m_period;
79 UAVDataObject *object() const
81 return m_object;
84 bool dirty() const
86 return m_dirty;
89 public slots:
90 void setSetting(int setting)
92 if (m_setting != setting) {
93 m_setting = setting;
94 setDirty(true);
95 if (m_setting != 1 && m_setting != 3) {
96 setPeriod(0);
97 } else {
98 if (!period()) {
99 setPeriod(500);
102 emit settingChanged(setting);
106 void setPeriod(int arg)
108 if (m_period != arg) {
109 m_period = arg;
110 setDirty(true);
111 emit periodChanged(arg);
115 void setDirty(bool arg)
117 if (m_dirty != arg) {
118 m_dirty = arg;
119 emit dirtyChanged(arg);
123 void reset(bool clear);
125 signals:
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);
133 private:
134 UAVDataObject *m_object;
135 int m_setting;
136 int m_period;
137 bool m_dirty;
140 class ExtendedDebugLogEntry : public DebugLogEntry {
141 Q_OBJECT Q_PROPERTY(QString LogString READ getLogString WRITE setLogString NOTIFY LogStringUpdated)
143 public:
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()
152 return m_object;
155 void setData(const DataFields & data, UAVObjectManager *objectManager);
157 public slots:
158 void setLogString(QString arg)
160 Q_UNUSED(arg);
163 signals:
164 void LogStringUpdated(QString arg);
166 private:
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)
187 public:
188 explicit FlightLogManager(QObject *parent = 0);
189 ~FlightLogManager();
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;
216 void clearLogList();
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();
251 signals:
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);
264 public slots:
265 void clearAllLogs();
266 void retrieveLogs(int flightToRetrieve = -1);
267 void exportLogs();
268 void cancelExportLogs();
269 void loadSettings();
270 void saveSettings();
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);
315 private slots:
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);
323 private:
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