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;