5 Commits
v1.5 ... v1.6

Author SHA1 Message Date
77dd027ff7 将任务定时器和心跳计时器分开。
All checks were successful
Release tag / build (push) Successful in 2m46s
2024-12-03 19:11:30 +08:00
8e0018480b 精简打包。 2024-12-03 18:22:55 +08:00
16757c5f78 修复Windows7打包行为。 2024-12-03 18:13:16 +08:00
ef7aa73c8d 修复早期T009版本不回复不支持的命令,导致上位机不发送后续命令的问题。
All checks were successful
Release tag / build (push) Successful in 3m5s
2024-12-03 17:56:24 +08:00
95b68bc67d config mbedtls. 2024-12-02 23:23:49 +08:00
4 changed files with 69 additions and 32 deletions

View File

@ -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)
@ -46,8 +46,7 @@ else()
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2_msvc2022_64bit_release) set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2_msvc2022_64bit_release)
endif() endif()
set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_ROOT}/include) set(MbedTLS_DIR ${MBEDTLS_ROOT}/lib/cmake/MbedTLS)
set(MBEDTLS_LIBRARY_DIRS ${MBEDTLS_ROOT}/lib)
set(JPEGTURBO_INCLUDE_DIR ${JPEGTURBO_ROOT}/include) set(JPEGTURBO_INCLUDE_DIR ${JPEGTURBO_ROOT}/include)
set(JPEGTURBO_LIB_DIR ${JPEGTURBO_ROOT}/lib) set(JPEGTURBO_LIB_DIR ${JPEGTURBO_ROOT}/lib)

View File

@ -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,11 +388,11 @@ 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()) { while (!m_requests.empty()) { // 清除之前的命令
m_requests.pop(); m_requests.pop();
} }
Task task; Task task;
@ -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, "设备升级成功!");
@ -692,6 +693,9 @@ void DeviceConnection::onConnected() {
if (m_otaTimer != nullptr) { if (m_otaTimer != nullptr) {
m_otaTimer->stop(); m_otaTimer->stop();
} }
if (m_requestTimerId < 0) {
m_requestTimerId = startTimer(HeartbeatInterval);
}
} else if (socket == m_h264Socket) { } else if (socket == m_h264Socket) {
if (m_videoEnabled) { if (m_videoEnabled) {
setLiveStreamEnabled(true); setLiveStreamEnabled(true);
@ -702,9 +706,13 @@ 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_requestTimerId > 0) {
killTimer(m_timerId); killTimer(m_requestTimerId);
m_timerId = -1; m_requestTimerId = -1;
}
if (m_heartbeatTimerId > 0) {
killTimer(m_heartbeatTimerId);
m_heartbeatTimerId = -1;
} }
emit disconnected(); emit disconnected();
if ((m_otaProgress >= 0) && (m_otaProgress <= 98)) { if ((m_otaProgress >= 0) && (m_otaProgress <= 98)) {
@ -743,7 +751,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 +762,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 +780,35 @@ 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++;
}
} 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);
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++;
} }
} }

View File

@ -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,8 @@ private:
H264FrameCallback m_frameCallback; H264FrameCallback m_frameCallback;
std::queue<Task> m_requests; std::queue<Task> m_requests;
int m_timerId = -1; int m_requestTimerId = -1;
int m_heartbeatTimerId = -1;
int heartbeats = 0; int heartbeats = 0;
NetworkInfomation m_networkInfomation; NetworkInfomation m_networkInfomation;
QString m_firmware; QString m_firmware;

View File

@ -49,9 +49,13 @@ function Deploy() {
New-Item $deployPath -ItemType Directory New-Item $deployPath -ItemType Directory
Copy-Item $buildPath\AntiClipSettings.exe $deployPath\视觉防夹设备上位机工具v$version.exe Copy-Item $buildPath\AntiClipSettings.exe $deployPath\视觉防夹设备上位机工具v$version.exe
& $qtHome\bin\windeployqt.exe $deployPath\视觉防夹设备上位机工具v$version.exe --qmldir=$qtHome\qml & $qtHome\bin\windeployqt.exe $deployPath\视觉防夹设备上位机工具v$version.exe --qmldir=$qtHome\qml
Remove-Item -Path $deployPath\d3dcompiler_47.dll -Force # Remove-Item -Path $deployPath\d3dcompiler_47.dll -Force # 删了这个会导致Windows 7 无法正常显示
Remove-Item -Path $deployPath\Qt5Multimedia.dll -Force
Remove-Item -Path $deployPath\Qt5MultimediaQuick.dll -Force
Remove-Item -Path $deployPath\Qt5RemoteObjects.dll -Force Remove-Item -Path $deployPath\Qt5RemoteObjects.dll -Force
Remove-Item -Path $deployPath\Qt5Test.dll -Force
Remove-Item -Path $deployPath\Qt5QuickTest.dll -Force Remove-Item -Path $deployPath\Qt5QuickTest.dll -Force
Remove-Item -Path $deployPath\Qt5WinExtras.dll -Force
Remove-Item -Path $deployPath\translations -Recurse -Force # 暂时不需要翻译文件 Remove-Item -Path $deployPath\translations -Recurse -Force # 暂时不需要翻译文件
Remove-Item -Path $deployPath\qmltooling -Recurse -Force Remove-Item -Path $deployPath\qmltooling -Recurse -Force
Remove-Item -Path $deployPath\QtTest -Recurse -Force Remove-Item -Path $deployPath\QtTest -Recurse -Force
@ -79,8 +83,8 @@ function Deploy() {
Copy-Item -Path $boostRoot\lib\boost_$boost-vc143-mt-x64-1_83.dll -Destination $deployPath Copy-Item -Path $boostRoot\lib\boost_$boost-vc143-mt-x64-1_83.dll -Destination $deployPath
} }
# 暂时不需要 avfilter-9、avformat-60 # 暂时不需要 avfilter-9、avformat-60、postproc-57、avdevice-60
$ffmpegs = "avcodec-60", "avdevice-60", "avutil-58", "postproc-57", "swresample-4", "swscale-7" $ffmpegs = "avcodec-60", "avutil-58", "swresample-4", "swscale-7"
foreach ($ffmpeg in $ffmpegs) { foreach ($ffmpeg in $ffmpegs) {
Copy-Item -Path $ffmpegRoot\bin\$ffmpeg.dll -Destination $deployPath Copy-Item -Path $ffmpegRoot\bin\$ffmpeg.dll -Destination $deployPath
} }