From c89404d9217977af426437d8d85f1685ddb59f94 Mon Sep 17 00:00:00 2001 From: acfloria Date: Thu, 14 Jun 2018 10:35:42 +0200 Subject: [PATCH] Split constructor of HeartbeatTimer up in two functions Previously the first activeChanged signal got lost because it was not connected yet to the LinkInterface which resulted in a link incorrectly shown as inactive. --- src/comm/HeartbeatTimer.cc | 10 ++++++++-- src/comm/HeartbeatTimer.h | 7 +++++++ src/comm/LinkInterface.cc | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/comm/HeartbeatTimer.cc b/src/comm/HeartbeatTimer.cc index 7090b7367..ec1843a65 100644 --- a/src/comm/HeartbeatTimer.cc +++ b/src/comm/HeartbeatTimer.cc @@ -17,7 +17,11 @@ HeartbeatTimer::HeartbeatTimer(int vehicle_id, bool high_latency) : _vehicleID(vehicle_id), _high_latency(high_latency) { - if (!high_latency) { +} + +void HeartbeatTimer::init() +{ + if (!_high_latency) { _timer->setInterval(_heartbeatReceivedTimeoutMSecs); _timer->setSingleShot(true); _timer->start(); @@ -26,7 +30,9 @@ HeartbeatTimer::HeartbeatTimer(int vehicle_id, bool high_latency) : QObject::connect(_timer, &QTimer::timeout, this, &HeartbeatTimer::timerTimeout); } -HeartbeatTimer::~HeartbeatTimer() { + +HeartbeatTimer::~HeartbeatTimer() +{ if (_timer) { QObject::disconnect(_timer, &QTimer::timeout, this, &HeartbeatTimer::timerTimeout); _timer->stop(); diff --git a/src/comm/HeartbeatTimer.h b/src/comm/HeartbeatTimer.h index c62a63f69..ea166873c 100644 --- a/src/comm/HeartbeatTimer.h +++ b/src/comm/HeartbeatTimer.h @@ -36,6 +36,13 @@ public: */ HeartbeatTimer(int vehicle_id, bool high_latency); + /** + * @brief init + * + * Starts the timer and emits the signal that the link is active for this vehicle ID + */ + void init(); + ~HeartbeatTimer(); /** diff --git a/src/comm/LinkInterface.cc b/src/comm/LinkInterface.cc index 13da6a850..d2c1923cb 100644 --- a/src/comm/LinkInterface.cc +++ b/src/comm/LinkInterface.cc @@ -195,6 +195,7 @@ void LinkInterface::startHeartbeatTimer(int vehicle_id) { } else { _heartbeatTimers.insert(vehicle_id, new HeartbeatTimer(vehicle_id, _highLatency)); QObject::connect(_heartbeatTimers.value(vehicle_id), &HeartbeatTimer::activeChanged, this, &LinkInterface::_activeChanged); + _heartbeatTimers.value(vehicle_id)->init(); } } -- 2.22.0