将任务定时器和心跳计时器分开。
All checks were successful
Release tag / build (push) Successful in 2m46s

This commit is contained in:
luocai 2024-12-03 19:11:30 +08:00
parent 8e0018480b
commit 77dd027ff7
2 changed files with 10 additions and 1 deletions

View File

@ -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<QTcpSocket *>(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<milliseconds>(system_clock::now() - command.time);

View File

@ -137,6 +137,7 @@ private:
H264FrameCallback m_frameCallback;
std::queue<Task> m_requests;
int m_requestTimerId = -1;
int m_heartbeatTimerId = -1;
int heartbeats = 0;
NetworkInfomation m_networkInfomation;