From 77dd027ff73e0e3bce2a848339e01e741eff5065 Mon Sep 17 00:00:00 2001 From: luocai Date: Tue, 3 Dec 2024 19:11:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=BB=BB=E5=8A=A1=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E5=92=8C=E5=BF=83=E8=B7=B3=E8=AE=A1=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E5=88=86=E5=BC=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DeviceConnection.cpp | 10 +++++++++- DeviceConnection.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/DeviceConnection.cpp b/DeviceConnection.cpp index b1f4d32..d4fa8a4 100644 --- a/DeviceConnection.cpp +++ b/DeviceConnection.cpp @@ -392,7 +392,7 @@ void DeviceConnection::requestOta(const QString &firmware, const QString &file) killTimer(m_heartbeatTimerId); m_heartbeatTimerId = -1; } - if (!m_requests.empty()) { + while (!m_requests.empty()) { // 清除之前的命令 m_requests.pop(); } Task task; @@ -693,6 +693,9 @@ void DeviceConnection::onConnected() { if (m_otaTimer != nullptr) { m_otaTimer->stop(); } + if (m_requestTimerId < 0) { + m_requestTimerId = startTimer(HeartbeatInterval); + } } else if (socket == m_h264Socket) { if (m_videoEnabled) { setLiveStreamEnabled(true); @@ -703,6 +706,10 @@ void DeviceConnection::onConnected() { void DeviceConnection::onDisconnected() { auto socket = dynamic_cast(sender()); if (socket == m_commandSocket) { + if (m_requestTimerId > 0) { + killTimer(m_requestTimerId); + m_requestTimerId = -1; + } if (m_heartbeatTimerId > 0) { killTimer(m_heartbeatTimerId); m_heartbeatTimerId = -1; @@ -786,6 +793,7 @@ void DeviceConnection::timerEvent(QTimerEvent *event) { } heartbeats++; } + } else if (event->timerId() == m_requestTimerId) { if (!m_requests.empty()) { auto &command = m_requests.front(); auto elapsed = duration_cast(system_clock::now() - command.time); diff --git a/DeviceConnection.h b/DeviceConnection.h index bc6108d..2d6c80e 100644 --- a/DeviceConnection.h +++ b/DeviceConnection.h @@ -137,6 +137,7 @@ private: H264FrameCallback m_frameCallback; std::queue m_requests; + int m_requestTimerId = -1; int m_heartbeatTimerId = -1; int heartbeats = 0; NetworkInfomation m_networkInfomation;