QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MockLinkWorker.cc
Go to the documentation of this file.
1#include "MockLinkWorker.h"
2#include "MockLink.h"
3
4#include <QtCore/QTimer>
5
7 : QObject(parent)
8 , _mockLink(link)
9{
10
11}
12
17
19{
20 // Prevent double-start which would leak timers
21 if (_timer1Hz) {
22 return;
23 }
24
25 _timer1Hz = new QTimer(this);
26 _timer10Hz = new QTimer(this);
27 _timer500Hz = new QTimer(this);
28 _timerStatusText = new QTimer(this);
29
30 (void) connect(_timer1Hz, &QTimer::timeout, this, &MockLinkWorker::run1HzTasks);
31 (void) connect(_timer10Hz, &QTimer::timeout, this, &MockLinkWorker::run10HzTasks);
32 (void) connect(_timer500Hz, &QTimer::timeout, this, &MockLinkWorker::run500HzTasks);
33 (void) connect(_timerStatusText, &QTimer::timeout, this, &MockLinkWorker::sendStatusTextMessages);
34
35 _timer1Hz->start(kTimer1HzIntervalMs);
36 _timer10Hz->start(kTimer10HzIntervalMs);
37 _timer500Hz->start(kTimer500HzIntervalMs);
38
39 if (_mockLink && _mockLink->shouldSendStatusText()) {
40 _timerStatusText->setSingleShot(true);
41 _timerStatusText->start(kStatusTextDelayMs);
42 }
43
44 run1HzTasks();
45 run10HzTasks();
46 run500HzTasks();
47}
48
50{
51 if (_timer1Hz) {
52 _timer1Hz->stop();
53 }
54 if (_timer10Hz) {
55 _timer10Hz->stop();
56 }
57 if (_timer500Hz) {
58 _timer500Hz->stop();
59 }
60 if (_timerStatusText) {
61 _timerStatusText->stop();
62 }
63}
64
65void MockLinkWorker::run1HzTasks()
66{
67 if (_mockLink) {
68 _mockLink->run1HzTasks();
69 }
70}
71
72void MockLinkWorker::run10HzTasks()
73{
74 if (_mockLink) {
75 _mockLink->run10HzTasks();
76 }
77}
78
79void MockLinkWorker::run500HzTasks()
80{
81 if (_mockLink) {
82 _mockLink->run500HzTasks();
83 }
84}
85
86void MockLinkWorker::sendStatusTextMessages()
87{
88 if (_mockLink) {
89 _mockLink->sendStatusTextMessages();
90 }
91}
MockLinkWorker(MockLink *link, QObject *parent=nullptr)
static constexpr int kTimer1HzIntervalMs
Timer intervals in milliseconds.
static constexpr int kTimer500HzIntervalMs
500 Hz tasks (param list, log download)
static constexpr int kTimer10HzIntervalMs
10 Hz tasks (heartbeat, GPS, position)
static constexpr int kStatusTextDelayMs
Delay before sending status text messages.