QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
OnboardLogController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtQmlIntegration/QtQmlIntegration>
5
9class QTimer;
10class QThread;
11class Vehicle;
12class OnboardLogDownloadTest;
13
14class OnboardLogController : public QObject
15{
16 Q_OBJECT
17 QML_ELEMENT
18 QML_SINGLETON
19
20 Q_MOC_INCLUDE("Vehicle.h")
21 Q_MOC_INCLUDE("QmlObjectListModel.h")
22
23 Q_PROPERTY(QmlObjectListModel *model READ _getModel CONSTANT)
24 Q_PROPERTY(bool requestingList READ _getRequestingList NOTIFY requestingListChanged)
25 Q_PROPERTY(bool downloadingLogs READ _getDownloadingLogs NOTIFY downloadingLogsChanged)
26 Q_PROPERTY(bool allLogsSelected READ allLogsSelected NOTIFY selectionChanged)
27 Q_PROPERTY(bool sortAscending READ sortAscending WRITE setSortAscending NOTIFY sortAscendingChanged)
28 Q_PROPERTY(bool compressLogs READ compressLogs WRITE setCompressLogs NOTIFY compressLogsChanged)
29 Q_PROPERTY(bool compressing READ compressing NOTIFY compressingChanged)
31
33
34public:
35 explicit OnboardLogController(QObject *parent = nullptr);
37
38 Q_INVOKABLE void refresh();
39 Q_INVOKABLE void download(const QString &path = QString());
40 Q_INVOKABLE void eraseAll();
41 Q_INVOKABLE void cancel();
42 Q_INVOKABLE void selectAll(bool select);
43 Q_INVOKABLE int selectedCount() const;
44 Q_INVOKABLE void toggleSortByDate();
45
46 bool compressLogs() const { return _compressLogs; }
47 void setCompressLogs(bool compress);
48 bool compressing() const { return _compressing; }
49 float compressionProgress() const { return _compressionProgress; }
50 bool allLogsSelected() const;
51 bool sortAscending() const { return _sortAscending; }
52 void setSortAscending(bool ascending);
53
55 Q_INVOKABLE bool compressLogFile(const QString &logPath);
56
58 Q_INVOKABLE void cancelCompression();
59
60signals:
68 void compressionComplete(const QString &outputPath, const QString &error);
69
70private slots:
71 void _setActiveVehicle(Vehicle *vehicle);
72
73 void _logEntry(uint32_t time_utc, uint32_t size, uint16_t id, uint16_t num_logs, uint16_t last_log_num);
74 void _logData(uint32_t ofs, uint16_t id, uint8_t count, const uint8_t *data);
75 void _processDownload();
76 void _handleCompressionProgress(qreal progress);
77 void _handleCompressionFinished(bool success);
78
79private:
80 QmlObjectListModel *_getModel() const { return _logEntriesModel; }
81 bool _getRequestingList() const { return _requestingLogEntries; }
82 bool _getDownloadingLogs() const { return _downloadingLogs; }
83
84 bool _chunkComplete() const;
85 bool _entriesComplete() const;
86 bool _logComplete() const;
87 bool _prepareLogDownload();
88 void _downloadToDirectory(const QString &dir);
89 void _findMissingData();
90 void _findMissingEntries();
91 void _receivedAllData();
92 void _receivedAllEntries();
93 void _requestLogData(uint16_t id, uint32_t offset, uint32_t count, int retryCount = 0);
94 void _requestLogList(uint32_t start, uint32_t end);
95 void _requestLogEnd();
96 void _resetSelection(bool canceled = false);
97 void _setDownloading(bool active);
98 void _setListing(bool active);
99 void _updateDataRate();
100
101 void _sortEntriesByTimestamp();
102
103 QGCOnboardLogEntry *_getNextSelected() const;
104
105 QTimer *_timer = nullptr;
106 QmlObjectListModel *_logEntriesModel = nullptr;
107
108 bool _downloadingLogs = false;
109 bool _requestingLogEntries = false;
110 int _apmOffset = 0;
111 int _retries = 0;
112 std::unique_ptr<OnboardLogDownloadData> _downloadData;
113 QString _downloadPath;
114 Vehicle *_vehicle = nullptr;
115 bool _compressLogs = false;
116 bool _compressing = false;
117 float _compressionProgress = 0.0F;
118 bool _sortAscending = false;
119
120 static constexpr uint32_t kTimeOutMs = 500;
121 static constexpr uint32_t kGUIRateMs = 500;
122 static constexpr uint32_t kRequestLogListTimeoutMs = 5000;
123};
Error error
Q_INVOKABLE int selectedCount() const
Q_INVOKABLE void selectAll(bool select)
Q_INVOKABLE void eraseAll()
Q_INVOKABLE void download(const QString &path=QString())
void compressionComplete(const QString &outputPath, const QString &error)
void compressionProgressChanged()
Q_INVOKABLE void toggleSortByDate()
float compressionProgress() const
void setCompressLogs(bool compress)
void setSortAscending(bool ascending)
friend class OnboardLogDownloadTest
Q_INVOKABLE bool compressLogFile(const QString &logPath)
Compress a single log file.
Q_INVOKABLE void cancelCompression()
Cancel compression.