修复早期T009版本不回复不支持的命令,导致上位机不发送后续命令的问题。
All checks were successful
Release tag / build (push) Successful in 3m5s
All checks were successful
Release tag / build (push) Successful in 3m5s
This commit is contained in:
parent
95b68bc67d
commit
ef7aa73c8d
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(AntiClipSettings VERSION 1.5 LANGUAGES C CXX)
|
project(AntiClipSettings VERSION 1.6 LANGUAGES C CXX)
|
||||||
set(APPLICATION_NAME "视觉防夹设备上位机工具")
|
set(APPLICATION_NAME "视觉防夹设备上位机工具")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTimerEvent>
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
#include <boost/json/object.hpp>
|
#include <boost/json/object.hpp>
|
||||||
#include <boost/json/parse.hpp>
|
#include <boost/json/parse.hpp>
|
||||||
@ -24,9 +25,9 @@ void DeviceConnection::close() {
|
|||||||
m_otaTimer->deleteLater();
|
m_otaTimer->deleteLater();
|
||||||
m_otaTimer = nullptr;
|
m_otaTimer = nullptr;
|
||||||
}
|
}
|
||||||
if (m_timerId > 0) {
|
if (m_heartbeatTimerId > 0) {
|
||||||
killTimer(m_timerId);
|
killTimer(m_heartbeatTimerId);
|
||||||
m_timerId = -1;
|
m_heartbeatTimerId = -1;
|
||||||
}
|
}
|
||||||
if (m_commandSocket != nullptr) {
|
if (m_commandSocket != nullptr) {
|
||||||
m_commandSocket->deleteLater();
|
m_commandSocket->deleteLater();
|
||||||
@ -387,9 +388,9 @@ QFuture<bool> DeviceConnection::updateNetworkInfomation(bool dhcp, const QString
|
|||||||
void DeviceConnection::requestOta(const QString &firmware, const QString &file) {
|
void DeviceConnection::requestOta(const QString &firmware, const QString &file) {
|
||||||
m_otaProgress = 0;
|
m_otaProgress = 0;
|
||||||
emit otaProgressChanged(true, m_otaProgress, "正在向设备发起OTA请求......");
|
emit otaProgressChanged(true, m_otaProgress, "正在向设备发起OTA请求......");
|
||||||
if (m_timerId > 0) {
|
if (m_heartbeatTimerId > 0) {
|
||||||
killTimer(m_timerId);
|
killTimer(m_heartbeatTimerId);
|
||||||
m_timerId = -1;
|
m_heartbeatTimerId = -1;
|
||||||
}
|
}
|
||||||
if (!m_requests.empty()) {
|
if (!m_requests.empty()) {
|
||||||
m_requests.pop();
|
m_requests.pop();
|
||||||
@ -480,7 +481,7 @@ void DeviceConnection::transferBinContent() {
|
|||||||
m_h264Socket->close();
|
m_h264Socket->close();
|
||||||
},
|
},
|
||||||
type);
|
type);
|
||||||
m_otaTimer->start(60 * 1000);
|
m_otaTimer->start(5 * 60 * 1000); // 固件升级五分钟,正常升级2.5分钟左右(包含算法模型)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,7 +614,7 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
|
|||||||
emit otaProgressChanged(true, m_otaProgress, "设备正在升级中,请稍后......");
|
emit otaProgressChanged(true, m_otaProgress, "设备正在升级中,请稍后......");
|
||||||
} else {
|
} else {
|
||||||
m_otaTimer->stop(); // 这里不需要再超时了
|
m_otaTimer->stop(); // 这里不需要再超时了
|
||||||
emit otaProgressChanged(true, 100, "设备正在升级中,请于一分钟后重新连接wifi搜索设备");
|
emit otaProgressChanged(true, 100, "设备正在升级中,请于五分钟后重新连接wifi搜索设备");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char *message = nullptr;
|
const char *message = nullptr;
|
||||||
@ -671,7 +672,7 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
|
|||||||
} else {
|
} else {
|
||||||
LOG(warning) << "unknown reply: " << replyText;
|
LOG(warning) << "unknown reply: " << replyText;
|
||||||
}
|
}
|
||||||
return QString::fromStdString(std::string(std::move(function)));
|
return QString::fromStdString(std::string(function));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConnection::onConnected() {
|
void DeviceConnection::onConnected() {
|
||||||
@ -684,7 +685,7 @@ void DeviceConnection::onConnected() {
|
|||||||
requestNetworkInfomation();
|
requestNetworkInfomation();
|
||||||
requestVideoInformation();
|
requestVideoInformation();
|
||||||
emit connected();
|
emit connected();
|
||||||
m_timerId = startTimer(2500);
|
m_heartbeatTimerId = startTimer(2500);
|
||||||
if (m_otaProgress == 99) {
|
if (m_otaProgress == 99) {
|
||||||
m_otaProgress = -1;
|
m_otaProgress = -1;
|
||||||
emit otaProgressChanged(true, 100, "设备升级成功!");
|
emit otaProgressChanged(true, 100, "设备升级成功!");
|
||||||
@ -702,9 +703,9 @@ void DeviceConnection::onConnected() {
|
|||||||
void DeviceConnection::onDisconnected() {
|
void DeviceConnection::onDisconnected() {
|
||||||
auto socket = dynamic_cast<QTcpSocket *>(sender());
|
auto socket = dynamic_cast<QTcpSocket *>(sender());
|
||||||
if (socket == m_commandSocket) {
|
if (socket == m_commandSocket) {
|
||||||
if (m_timerId > 0) {
|
if (m_heartbeatTimerId > 0) {
|
||||||
killTimer(m_timerId);
|
killTimer(m_heartbeatTimerId);
|
||||||
m_timerId = -1;
|
m_heartbeatTimerId = -1;
|
||||||
}
|
}
|
||||||
emit disconnected();
|
emit disconnected();
|
||||||
if ((m_otaProgress >= 0) && (m_otaProgress <= 98)) {
|
if ((m_otaProgress >= 0) && (m_otaProgress <= 98)) {
|
||||||
@ -743,7 +744,6 @@ void DeviceConnection::onH264ReadyRead() {
|
|||||||
void DeviceConnection::onCommandReadyRead() {
|
void DeviceConnection::onCommandReadyRead() {
|
||||||
auto data = m_commandSocket->readAll();
|
auto data = m_commandSocket->readAll();
|
||||||
m_commandBuffer.push_back(data);
|
m_commandBuffer.push_back(data);
|
||||||
|
|
||||||
while (!m_commandBuffer.isEmpty()) {
|
while (!m_commandBuffer.isEmpty()) {
|
||||||
auto packageSize = ntohl(*reinterpret_cast<uint32_t *>(m_commandBuffer.data()));
|
auto packageSize = ntohl(*reinterpret_cast<uint32_t *>(m_commandBuffer.data()));
|
||||||
if (m_commandBuffer.size() < (packageSize + sizeof(uint32_t))) break;
|
if (m_commandBuffer.size() < (packageSize + sizeof(uint32_t))) break;
|
||||||
@ -755,9 +755,13 @@ void DeviceConnection::onCommandReadyRead() {
|
|||||||
auto &task = m_requests.front();
|
auto &task = m_requests.front();
|
||||||
if (task.command == command) {
|
if (task.command == command) {
|
||||||
m_requests.pop();
|
m_requests.pop();
|
||||||
|
} else {
|
||||||
|
LOG(warning) << "current command[" << command.toStdString() << "] is no the task queue's head["
|
||||||
|
<< task.command.toStdString() << "]";
|
||||||
}
|
}
|
||||||
if (!m_requests.empty()) {
|
if (!m_requests.empty()) {
|
||||||
m_requests.front().task();
|
auto &command = m_requests.front();
|
||||||
|
command.task();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -769,15 +773,34 @@ void DeviceConnection::onErrorOccurred(QAbstractSocket::SocketError socketError)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConnection::timerEvent(QTimerEvent *event) {
|
void DeviceConnection::timerEvent(QTimerEvent *event) {
|
||||||
if (isConnected()) {
|
using namespace std::chrono;
|
||||||
int index = heartbeats % 3;
|
if (event->timerId() == m_heartbeatTimerId) {
|
||||||
if (index == 0) {
|
if (isConnected()) {
|
||||||
requestOpenDoorArea();
|
int index = heartbeats % 3;
|
||||||
} else if (index == 1) {
|
if (index == 0) {
|
||||||
requestShieldedArea();
|
requestOpenDoorArea();
|
||||||
} else if (index == 2) {
|
} else if (index == 1) {
|
||||||
requestAntiClipArea();
|
requestShieldedArea();
|
||||||
|
} else if (index == 2) {
|
||||||
|
requestAntiClipArea();
|
||||||
|
}
|
||||||
|
heartbeats++;
|
||||||
|
}
|
||||||
|
if (!m_requests.empty()) {
|
||||||
|
auto &command = m_requests.front();
|
||||||
|
auto elapsed = duration_cast<milliseconds>(system_clock::now() - command.time);
|
||||||
|
if (elapsed > (HeartbeatInterval * 2)) {
|
||||||
|
LOG(info) << "not received command[" << command.command.toStdString() << "] more than "
|
||||||
|
<< (HeartbeatInterval * 2).count() << " ms, consider it failed, send next command.";
|
||||||
|
m_requests.pop();
|
||||||
|
if (!m_requests.empty()) {
|
||||||
|
m_requests.front().task();
|
||||||
|
}
|
||||||
|
} else if (elapsed > HeartbeatInterval) {
|
||||||
|
LOG(info) << "not received command[" << command.command.toStdString() << "] more than "
|
||||||
|
<< HeartbeatInterval.count() << " ms, resend it.";
|
||||||
|
command.task();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
heartbeats++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ class DeviceConnection : public QObject {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr static auto WirelessAddress = "192.168.10.2";
|
constexpr static auto WirelessAddress = "192.168.10.2";
|
||||||
|
constexpr static auto HeartbeatInterval = std::chrono::milliseconds(2500);
|
||||||
enum Resolution {
|
enum Resolution {
|
||||||
Video_360P = 0,
|
Video_360P = 0,
|
||||||
Video_720P,
|
Video_720P,
|
||||||
@ -103,6 +104,7 @@ protected:
|
|||||||
class Task {
|
class Task {
|
||||||
public:
|
public:
|
||||||
QString command;
|
QString command;
|
||||||
|
std::chrono::system_clock::time_point time = std::chrono::system_clock::now();
|
||||||
std::function<void()> task;
|
std::function<void()> task;
|
||||||
std::shared_ptr<QTimer> timeoutTimer = nullptr;
|
std::shared_ptr<QTimer> timeoutTimer = nullptr;
|
||||||
std::shared_ptr<QFutureInterface<bool>> future;
|
std::shared_ptr<QFutureInterface<bool>> future;
|
||||||
@ -135,7 +137,7 @@ private:
|
|||||||
|
|
||||||
H264FrameCallback m_frameCallback;
|
H264FrameCallback m_frameCallback;
|
||||||
std::queue<Task> m_requests;
|
std::queue<Task> m_requests;
|
||||||
int m_timerId = -1;
|
int m_heartbeatTimerId = -1;
|
||||||
int heartbeats = 0;
|
int heartbeats = 0;
|
||||||
NetworkInfomation m_networkInfomation;
|
NetworkInfomation m_networkInfomation;
|
||||||
QString m_firmware;
|
QString m_firmware;
|
||||||
|
Loading…
Reference in New Issue
Block a user