15 Commits
v1.4 ... v1.7

Author SHA1 Message Date
7284f18c43 更新版本。
All checks were successful
Release tag / build (push) Successful in 3m9s
2024-12-04 15:24:37 +08:00
fb27b0fa57 实现向设备发起防夹灵敏度设置,恢复出厂设置请求。 2024-12-04 15:23:42 +08:00
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
d0966cfcc7 修正ci拉取代码步骤。
All checks were successful
Release tag / build (push) Successful in 2m53s
2024-11-14 12:15:48 +08:00
d6a36c0450 完善CI构建。
Some checks failed
Release tag / build (push) Failing after 49s
2024-11-14 12:11:59 +08:00
27e5db45d6 减小打包体积。 2024-11-14 11:20:32 +08:00
51f9a2af52 打包时显示版本号。 2024-11-13 14:54:14 +08:00
0b3198c90e 修正编译条件。 2024-11-13 14:40:10 +08:00
f55d3aa9df 实现视频旋转及翻转指令控制。 2024-11-13 14:25:22 +08:00
bf3ad2be2f 修改升级文件校验。 2024-10-21 19:35:49 +08:00
f230e4cc8b update ffmpeg ver. 2024-10-21 17:00:48 +08:00
10 changed files with 490 additions and 100 deletions

View File

@ -8,8 +8,18 @@ jobs:
build:
runs-on: [windows11]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Clone repository
run: |
$ref = "${{ github.ref }}"
if ($ref -like 'refs/heads/*') {
$branch = $ref -replace '^refs/heads/', ''
} elseif ($ref -like 'refs/tags/*') {
$branch = $ref -replace '^refs/tags/', ''
} else {
$branch = $ref
}
git clone --depth 1 --branch=$branch https://${{ secrets.GIT_USERNAME }}:${{ secrets.GIT_PASSWORD }}@amass.fun/gitea/${{ gitea.repository }}.git .
git checkout ${{ github.sha }}
- name: Build and deploy
run: |
resources/build.ps1 build
@ -20,4 +30,4 @@ jobs:
with:
body_path: build/CHANGELOG.txt
files: |-
build/AntiClipSettings.zip
build/视觉防夹设备上位机工具*.zip

View File

@ -40,7 +40,7 @@ Application::Application(int &argc, char **argv)
font.setFamily("微软雅黑");
m_app->setFont(font);
m_app->setApplicationName(APPLICATION_NAME);
m_app->setApplicationVersion(QString("V%1").arg(APP_VERSION));
m_app->setApplicationVersion(QString("v%1").arg(APP_VERSION));
m_player->open();
}
@ -127,7 +127,24 @@ void Application::setCurrentAntiClipAreaEnabled(bool enabled) {
emit currentAntiClipAreaEnabledChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints);
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints,
m_currentAntiClipSensitivity);
}
}
}
int Application::currentAntiClipSensitivity() const {
return m_currentAntiClipSensitivity;
}
void Application::setCurrentAntiClipSensitivity(int sensitivity) {
if (m_currentAntiClipSensitivity != sensitivity) {
m_currentAntiClipSensitivity = sensitivity;
emit currentAntiClipSensitivityChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints,
m_currentAntiClipSensitivity);
}
}
}
@ -153,7 +170,7 @@ void Application::updateOpenDoorAreaPoints(const QList<QPointF> &points) {
void Application::updateAntiClipAreaPoints(const QList<QPointF> &points) {
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, points);
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, points, m_currentAntiClipSensitivity);
}
}
@ -164,6 +181,35 @@ void Application::updateShieldedAreaPoints(const QList<QPointF> &points) {
}
}
bool Application::currentDeviceFlip() const {
return m_currentDeviceFlip;
}
void Application::setCurrentDeviceFlip(bool flip) {
if (m_currentDeviceFlip != flip) {
m_currentDeviceFlip = flip;
emit currentDeviceFlipChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateFlip(flip);
}
}
}
int Application::currentDeviceRotation() const {
return m_currentDeviceRotation;
}
void Application::setCurrentDeviceRotation(int rotation) {
if (m_currentDeviceRotation != rotation) {
m_currentDeviceRotation = rotation;
emit currentDeviceRotationChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateRotation(rotation);
}
}
}
void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns) {
if (!m_device.expired()) {
@ -180,6 +226,8 @@ void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QS
void Application::connectToDevice(int index) {
if (!m_device.expired()) {
auto device = m_device.lock();
disconnect(device.get(), &DeviceConnection::rotationChanged, this, &Application::onDeviceRotationChanged);
disconnect(device.get(), &DeviceConnection::flipChanged, this, &Application::onDeviceFlipChanged);
disconnect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
@ -202,6 +250,8 @@ void Application::connectToDevice(int index) {
auto device = m_devices->device(index);
m_device = device;
connect(device.get(), &DeviceConnection::rotationChanged, this, &Application::onDeviceRotationChanged);
connect(device.get(), &DeviceConnection::flipChanged, this, &Application::onDeviceFlipChanged);
connect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
@ -220,22 +270,28 @@ void Application::connectToDevice(int index) {
}
});
device->setLiveStreamEnabled(true);
auto area = device->area();
m_currentOpenDoorAreaWay = area.openDoorAreaWay;
m_currentOpenDoorAreaPoints = area.openDoorArea;
m_currentShieldedAreaEnabled = area.shieldedAreaEnabled;
m_currentShieldedAreaPoints = area.shieldedArea;
m_currentAntiClipAreaEnabled = area.antiClipAreaEnabled;
m_currentAntiClipAreaPoints = area.antiClipArea;
auto info = device->infomation();
m_currentOpenDoorAreaWay = info.openDoorAreaWay;
m_currentOpenDoorAreaPoints = info.openDoorArea;
m_currentShieldedAreaEnabled = info.shieldedAreaEnabled;
m_currentShieldedAreaPoints = info.shieldedArea;
m_currentAntiClipAreaEnabled = info.antiClipAreaEnabled;
m_currentAntiClipAreaPoints = info.antiClipArea;
m_currentAntiClipSensitivity = info.antiClipSensitivity;
m_currentNetworkInfomation = device->networkInfomation();
m_currentFirmware = device->infomation().firmwareVersion;
m_currentDeviceConnected = device->isConnected();
m_currentDeviceFlip = info.flip;
m_currentDeviceRotation = info.rotation;
emit currentDeviceRotationChanged();
emit currentDeviceFlipChanged();
emit currentOpenDoorAreaPointsChanged();
emit currentShieldedAreaPointsChanged();
emit currentAntiClipAreaPointsChanged();
emit currentOpenDoorAreaWayChanged();
emit currentShieldedAreaEnabledChanged();
emit currentAntiClipAreaEnabledChanged();
emit currentAntiClipSensitivityChanged();
emit currentNetworkInfomationChanged();
}
emit currentFirmwareChanged();
@ -258,9 +314,10 @@ void Application::upgradeDevice(const QString &file) {
int position = baseName.indexOf(versionPrefix);
if (position < 0 || ((baseName.length() - position) < std::strlen(version))) {
emit newMessage(2, "OTA升级", "文件名格式不合法!");
LOG(error) << "baseName: " << baseName.toStdString() << ", position: " << position;
return;
}
QString firmware = baseName.mid(position, std::strlen(version));
QString firmware = baseName.mid(position);
if (device->isConnected()) {
device->requestOta(firmware, file);
} else {
@ -268,19 +325,37 @@ void Application::upgradeDevice(const QString &file) {
}
}
void Application::resetDevice() {
if (m_device.expired()) return;
auto device = m_device.lock();
if (device->isConnected()) {
device->requestReset();
} else {
emit newMessage(2, "恢复出厂设置", "设备已离线,请重新连接设备!");
}
}
void Application::onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points) {
setCurrentOpenDoorAreaWay(way);
setCurrentOpenDoorAreaPoints(points);
}
void Application::onDeviceRotationChanged(int rotation) {
setCurrentDeviceRotation(rotation);
}
void Application::onDeviceFlipChanged(bool flip) {
setCurrentDeviceFlip(flip);
}
void Application::onDeviceShieldedArea(bool enabled, const QList<QPointF> &points) {
setCurrentShieldedAreaEnabled(enabled);
setCurrentShieldedAreaPoints(points);
}
void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points) {
void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity) {
setCurrentAntiClipAreaEnabled(enabled);
setCurrentAntiClipAreaPoints(points);
setCurrentAntiClipSensitivity(sensitivity);
}
void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) {

View File

@ -34,12 +34,17 @@ class Application : public QObject {
setCurrentShieldedAreaPoints NOTIFY currentShieldedAreaPointsChanged)
Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled
NOTIFY currentAntiClipAreaEnabledChanged)
Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY(
NetworkInfomation currentNetworkInfomation READ currentNetworkInfomation NOTIFY currentNetworkInfomationChanged)
Q_PROPERTY(QString currentFirmware MEMBER m_currentFirmware NOTIFY currentFirmwareChanged)
Q_PROPERTY(bool currentDeviceConnected MEMBER m_currentDeviceConnected NOTIFY currentDeviceConnectedChanged)
Q_PROPERTY(bool currentDeviceFlip READ currentDeviceFlip WRITE setCurrentDeviceFlip NOTIFY currentDeviceFlipChanged)
Q_PROPERTY(int currentDeviceRotation READ currentDeviceRotation WRITE setCurrentDeviceRotation NOTIFY
currentDeviceRotationChanged)
friend class Amass::Singleton<Application>;
public:
@ -61,9 +66,17 @@ public:
bool currentAntiClipAreaEnabled() const;
void setCurrentAntiClipAreaEnabled(bool enabled);
int currentAntiClipSensitivity() const;
void setCurrentAntiClipSensitivity(int sensitivity);
QList<QPointF> currentAntiClipAreaPoints() const;
void setCurrentAntiClipAreaPoints(const QList<QPointF> &points);
bool currentDeviceFlip() const;
void setCurrentDeviceFlip(bool flip);
int currentDeviceRotation() const;
void setCurrentDeviceRotation(int rotation);
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points);
@ -71,6 +84,7 @@ public:
const QString &gateway, const QString &dns);
Q_INVOKABLE void connectToDevice(int index);
Q_INVOKABLE void upgradeDevice(const QString &file);
Q_INVOKABLE void resetDevice();
Q_INVOKABLE void startSearchDevice();
int exec();
@ -84,17 +98,22 @@ signals:
void currentOpenDoorAreaWayChanged();
void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged();
void currentNetworkInfomationChanged();
void currentFirmwareChanged();
void currentDeviceConnectedChanged();
void currentDeviceOtaProgressChanged(bool status, int progress, const QString &message);
void currentDeviceFlipChanged();
void currentDeviceRotationChanged();
void newMessage(int type, const QString &title, const QString &message);
protected:
Application(int &argc, char **argv);
void onDeviceRotationChanged(int rotation);
void onDeviceFlipChanged(bool flip);
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity);
void onDeviceNetworkInfomation(const NetworkInfomation &info);
void onDeviceFirmware(const QString &firmware);
void onDeviceConnected();
@ -114,10 +133,13 @@ private:
bool m_currentShieldedAreaEnabled = false;
QList<QPointF> m_currentShieldedAreaPoints;
bool m_currentAntiClipAreaEnabled = false;
int m_currentAntiClipSensitivity = 1;
QList<QPointF> m_currentAntiClipAreaPoints;
NetworkInfomation m_currentNetworkInfomation;
QString m_currentFirmware;
bool m_currentDeviceConnected = false;
bool m_currentDeviceFlip = false;
int m_currentDeviceRotation = 0;
};
#endif // APPLICATION_H

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16)
project(AntiClipSettings VERSION 1.4 LANGUAGES C CXX)
project(AntiClipSettings VERSION 1.7 LANGUAGES C CXX)
set(APPLICATION_NAME "视觉防夹设备上位机工具")
set(CMAKE_CXX_STANDARD 17)
@ -18,6 +18,7 @@ if (Qt6_FOUND)
add_compile_definitions(
BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN10
)
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-7.0.2-full_build-shared)
else()
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
@ -25,6 +26,7 @@ else()
set(CMAKE_AUTORCC ON)
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_83_0_msvc2022_64bit)
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include/boost-1_83)
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-6.1.1-full_build-shared)
endif()
option(Boost_USE_STATIC_LIBS OFF)
@ -33,15 +35,19 @@ set(OPENSSL_INCLUDE_DIR ${OpenSSL_ROOT}/include)
set(OpenSSL_LIBRARY_DIRS ${OpenSSL_ROOT}/lib)
set(OpenSSL_LIBRARIES libssl libcrypto)
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-7.0.2-full_build-shared)
set(FFmpeg_INCLUDE_DIR ${FFmpeg_ROOT}/include)
set(FFmpeg_LIB_DIR ${FFmpeg_ROOT}/lib)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(JPEGTURBO_ROOT ${Libraries_ROOT}/libjpeg-turbo-3.0.3_msvc2022_64bit_debug)
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2_msvc2022_64bit_debug)
else()
set(JPEGTURBO_ROOT ${Libraries_ROOT}/libjpeg-turbo-3.0.3_msvc2022_64bit_release)
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2_msvc2022_64bit_release)
endif()
set(MbedTLS_DIR ${MBEDTLS_ROOT}/lib/cmake/MbedTLS)
set(JPEGTURBO_INCLUDE_DIR ${JPEGTURBO_ROOT}/include)
set(JPEGTURBO_LIB_DIR ${JPEGTURBO_ROOT}/lib)
@ -102,7 +108,7 @@ set_target_properties(AntiClipSettings PROPERTIES
include(CPack)
include(FetchContent)
FetchContent_Declare(Kylin
GIT_REPOSITORY https://gitea.amass.fun/amass/Kylin.git
GIT_REPOSITORY https://amass.fun/gitea/amass/Kylin.git
)
set(KYLIN_WITH_FLUENT OFF)
FetchContent_MakeAvailable(Kylin)

View File

@ -4,6 +4,7 @@
#include <QFileInfo>
#include <QPointF>
#include <QTimer>
#include <QTimerEvent>
#include <WinSock2.h>
#include <boost/json/object.hpp>
#include <boost/json/parse.hpp>
@ -24,9 +25,9 @@ void DeviceConnection::close() {
m_otaTimer->deleteLater();
m_otaTimer = nullptr;
}
if (m_timerId > 0) {
killTimer(m_timerId);
m_timerId = -1;
if (m_heartbeatTimerId > 0) {
killTimer(m_heartbeatTimerId);
m_heartbeatTimerId = -1;
}
if (m_commandSocket != nullptr) {
m_commandSocket->deleteLater();
@ -73,10 +74,6 @@ void DeviceConnection::connect(const Infomation &infomation) {
m_h264Socket->connectToHost(infomation.ip, 8000);
}
DeviceConnection::Area DeviceConnection::area() const {
return m_area;
}
NetworkInfomation DeviceConnection::networkInfomation() const {
return m_networkInfomation;
}
@ -213,15 +210,16 @@ void DeviceConnection::requestAntiClipArea() {
m_requests.push(task);
}
void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points) {
void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity) {
Task task;
task.command = "a03opendoor5_setdata";
task.task = [this, enabled, points]() {
task.task = [this, enabled, points, sensitivity]() {
boost::json::object request;
request["func"] = "a03opendoor5_setdata";
request["deviceid"] = "0";
boost::json::object data;
data["value"] = enabled ? "1" : "0";
data["sensitivity"] = std::to_string(sensitivity);
boost::json::array pointArray;
for (auto &p : points) {
boost::json::object point;
@ -262,6 +260,44 @@ void DeviceConnection::requestResolution(Resolution resolution) {
m_requests.push(task);
}
void DeviceConnection::updateRotation(int rotation) {
Task task;
task.command = "a23imagerotate_setdata";
task.task = [this, rotation]() {
boost::json::object request;
request["func"] = "a23imagerotate_setdata";
request["deviceid"] = "0";
boost::json::object data;
data["value"] = std::to_string(rotation);
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
LOG(info) << "updateRotation: " << text;
};
if (m_requests.empty()) {
task.task();
}
m_requests.push(task);
}
void DeviceConnection::updateFlip(bool flip) {
Task task;
task.command = "a04imageflipping_setdata";
task.task = [this, flip]() {
boost::json::object request;
request["func"] = "a04imageflipping_setdata";
request["deviceid"] = "0";
boost::json::object data;
data["value"] = flip ? "2" : "1";
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
if (m_requests.empty()) {
task.task();
}
m_requests.push(task);
}
void DeviceConnection::requestVersion() {
Task task;
task.command = "a15devicedetail_getdata";
@ -281,6 +317,27 @@ void DeviceConnection::requestVersion() {
m_requests.push(task);
}
void DeviceConnection::requestVideoInformation() {
constexpr const char *commands[] = {"a23imagerotate_getdata", "a04imageflipping_getdata"};
for (auto command : commands) {
Task task;
task.command = command;
task.task = [this, command]() {
boost::json::object request;
request["func"] = command;
request["deviceid"] = "0";
boost::json::object data;
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
if (m_requests.empty()) {
task.task();
}
m_requests.push(task);
}
}
void DeviceConnection::requestNetworkInfomation() {
Task task;
task.command = "netconfig_getdata";
@ -332,11 +389,11 @@ QFuture<bool> DeviceConnection::updateNetworkInfomation(bool dhcp, const QString
void DeviceConnection::requestOta(const QString &firmware, const QString &file) {
m_otaProgress = 0;
emit otaProgressChanged(true, m_otaProgress, "正在向设备发起OTA请求......");
if (m_timerId > 0) {
killTimer(m_timerId);
m_timerId = -1;
if (m_heartbeatTimerId > 0) {
killTimer(m_heartbeatTimerId);
m_heartbeatTimerId = -1;
}
if (!m_requests.empty()) {
while (!m_requests.empty()) { // 清除之前的命令
m_requests.pop();
}
Task task;
@ -377,6 +434,28 @@ void DeviceConnection::requestOta(const QString &firmware, const QString &file)
m_requests.push(task);
}
void DeviceConnection::requestReset() {
Task task;
task.command = "a12factory_setdata";
task.task = [this]() {
boost::json::object request;
request["func"] = "a12factory_setdata";
request["deviceid"] = "0";
boost::json::object data;
data["value"] = "1";
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
task.future = std::make_shared<QFutureInterface<bool>>();
if (m_requests.empty()) {
task.task();
}
auto ret = task.future->future();
m_requests.push(task);
}
void DeviceConnection::transferBinContent() {
constexpr int SliceSize = 1024;
constexpr int WaitMd5CheckTime = 3000; // ms
@ -425,7 +504,7 @@ void DeviceConnection::transferBinContent() {
m_h264Socket->close();
},
type);
m_otaTimer->start(60 * 1000);
m_otaTimer->start(5 * 60 * 1000); // 固件升级五分钟正常升级2.5分钟左右(包含算法模型)
}
}
@ -457,8 +536,8 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
} else if (value == "2") {
way = Quadrangle;
}
m_area.openDoorAreaWay = way;
m_area.openDoorArea = points;
m_infomation.openDoorAreaWay = way;
m_infomation.openDoorArea = points;
emit openDoorAreaChanged(way, points);
} else if (function == "a03opendoor4_getdata") {
auto &data = reply.at("data").as_object();
@ -472,8 +551,8 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
point.setY(obj.at("y").as_double());
points.push_back(point);
}
m_area.shieldedAreaEnabled = value == "1";
m_area.shieldedArea = points;
m_infomation.shieldedAreaEnabled = value == "1";
m_infomation.shieldedArea = points;
emit shieldedAreaChanged(value == "1", points);
} else if (function == "a03opendoor5_getdata") {
auto &data = reply.at("data").as_object();
@ -487,9 +566,12 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
point.setY(obj.at("y").as_double());
points.push_back(point);
}
m_area.antiClipAreaEnabled = value == "1";
m_area.antiClipArea = points;
emit antiClipAreaChanged(value == "1", points);
m_infomation.antiClipAreaEnabled = value == "1";
m_infomation.antiClipArea = points;
if (data.contains("sensitivity")) {
m_infomation.antiClipSensitivity = std::stoi(static_cast<std::string>(data.at("sensitivity").as_string()));
}
emit antiClipAreaChanged(value == "1", points, m_infomation.antiClipSensitivity);
} else if (function == "netconfig_getdata") {
auto &data = reply.at("data").as_object();
m_networkInfomation.dhcp = data.at("type").as_string() == "dhcp";
@ -558,7 +640,7 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
emit otaProgressChanged(true, m_otaProgress, "设备正在升级中,请稍后......");
} else {
m_otaTimer->stop(); // 这里不需要再超时了
emit otaProgressChanged(true, 100, "设备正在升级中,请于分钟后重新连接wifi搜索设备");
emit otaProgressChanged(true, 100, "设备正在升级中,请于分钟后重新连接wifi搜索设备");
}
} else {
const char *message = nullptr;
@ -579,10 +661,46 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
}
emit otaProgressChanged(false, m_otaProgress, tip);
}
} else if (function == "a23imagerotate_getdata") {
// {"data":{"value":"2"},"deviceid":"0","flag":"ok","func":"a23imagerotate_getdata"}
auto &data = reply.at("data").as_object();
auto &value = data.at("value").as_string();
m_infomation.rotation = std::stoi(static_cast<std::string>(value));
emit rotationChanged(m_infomation.rotation);
} else if (function == "a04imageflipping_getdata") {
// {"data":{"value":"1"},"deviceid":"0","flag":"ok","func":"a04imageflipping_getdata"}
auto &data = reply.at("data").as_object();
auto &value = data.at("value").as_string();
m_infomation.flip = value == "2";
emit flipChanged(m_infomation.flip);
} else if (function == "a04imageflipping_setdata") {
if ((task != nullptr) && (task->command.toStdString() == function)) {
if (task->timeoutTimer) {
task->timeoutTimer->stop();
}
bool status = true;
if (task->future) {
task->future->reportFinished(&status);
}
}
requestVideoInformation();
} else if (function == "a23imagerotate_setdata") {
if ((task != nullptr) && (task->command.toStdString() == function)) {
if (task->timeoutTimer) {
task->timeoutTimer->stop();
}
bool status = true;
if (task->future) {
task->future->reportFinished(&status);
}
}
requestVideoInformation();
} else if (function == "a12factory_setdata") {
LOG(info) << "device factory reset";
} else {
LOG(warning) << "unknown reply: " << replyText;
}
return QString::fromStdString(std::string(std::move(function)));
return QString::fromStdString(std::string(function));
}
void DeviceConnection::onConnected() {
@ -593,8 +711,9 @@ void DeviceConnection::onConnected() {
requestShieldedArea();
requestAntiClipArea();
requestNetworkInfomation();
requestVideoInformation();
emit connected();
m_timerId = startTimer(2500);
m_heartbeatTimerId = startTimer(2500);
if (m_otaProgress == 99) {
m_otaProgress = -1;
emit otaProgressChanged(true, 100, "设备升级成功!");
@ -602,6 +721,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);
@ -612,9 +734,13 @@ void DeviceConnection::onConnected() {
void DeviceConnection::onDisconnected() {
auto socket = dynamic_cast<QTcpSocket *>(sender());
if (socket == m_commandSocket) {
if (m_timerId > 0) {
killTimer(m_timerId);
m_timerId = -1;
if (m_requestTimerId > 0) {
killTimer(m_requestTimerId);
m_requestTimerId = -1;
}
if (m_heartbeatTimerId > 0) {
killTimer(m_heartbeatTimerId);
m_heartbeatTimerId = -1;
}
emit disconnected();
if ((m_otaProgress >= 0) && (m_otaProgress <= 98)) {
@ -653,7 +779,6 @@ void DeviceConnection::onH264ReadyRead() {
void DeviceConnection::onCommandReadyRead() {
auto data = m_commandSocket->readAll();
m_commandBuffer.push_back(data);
while (!m_commandBuffer.isEmpty()) {
auto packageSize = ntohl(*reinterpret_cast<uint32_t *>(m_commandBuffer.data()));
if (m_commandBuffer.size() < (packageSize + sizeof(uint32_t))) break;
@ -665,9 +790,13 @@ void DeviceConnection::onCommandReadyRead() {
auto &task = m_requests.front();
if (task.command == command) {
m_requests.pop();
} else {
LOG(warning) << "current command[" << command.toStdString() << "] is no the task queue's head["
<< task.command.toStdString() << "]";
}
if (!m_requests.empty()) {
m_requests.front().task();
auto &command = m_requests.front();
command.task();
}
}
}
@ -679,15 +808,35 @@ void DeviceConnection::onErrorOccurred(QAbstractSocket::SocketError socketError)
}
void DeviceConnection::timerEvent(QTimerEvent *event) {
if (isConnected()) {
int index = heartbeats % 3;
if (index == 0) {
requestOpenDoorArea();
} else if (index == 1) {
requestShieldedArea();
} else if (index == 2) {
requestAntiClipArea();
using namespace std::chrono;
if (event->timerId() == m_heartbeatTimerId) {
if (isConnected()) {
int index = heartbeats % 3;
if (index == 0) {
requestOpenDoorArea();
} else if (index == 1) {
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:
constexpr static auto WirelessAddress = "192.168.10.2";
constexpr static auto HeartbeatInterval = std::chrono::milliseconds(2500);
enum Resolution {
Video_360P = 0,
Video_720P,
@ -34,11 +35,10 @@ public:
QString softwareVersion;
QString firmwareVersion;
QString ip;
};
Q_ENUM(AreaWay)
class Area {
public:
int rotation = 0;
bool flip = false;
QList<QPointF> openDoorArea;
AreaWay openDoorAreaWay;
@ -47,7 +47,9 @@ public:
QList<QPointF> antiClipArea;
bool antiClipAreaEnabled;
int antiClipSensitivity = 1;
};
Q_ENUM(AreaWay)
using H264FrameCallback = std::function<void(const char *data, uint32_t size)>;
DeviceConnection(QObject *parent = nullptr);
@ -60,19 +62,21 @@ public:
void setLiveStreamEnabled(bool enabled);
NetworkInfomation networkInfomation() const;
Area area() const;
void requestOpenDoorArea();
QFuture<bool> updateOpenDoorAreaPoints(AreaWay way, const QList<QPointF> &points);
void requestShieldedArea();
void updateShieldedAreaPoints(bool enabled, const QList<QPointF> &points);
void requestAntiClipArea();
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points);
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity);
void requestResolution(Resolution resolution);
void requestNetworkInfomation();
QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns);
void requestVersion();
void requestVideoInformation();
void updateRotation(int rotation);
void updateFlip(bool flip);
/**
* @brief 对设备升级OTA,主要有几个步骤
@ -84,13 +88,16 @@ public:
* @param file
*/
void requestOta(const QString &firmware, const QString &file);
void requestReset();
signals:
void connected();
void disconnected();
void openDoorAreaChanged(AreaWay way, const QList<QPointF> &points);
void shieldedAreaChanged(bool enabled, const QList<QPointF> &points);
void antiClipAreaChanged(bool enabled, const QList<QPointF> &points);
void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity);
void rotationChanged(int rotation);
void flipChanged(bool flip);
void networkInfomationChanged(const NetworkInfomation &info);
void firmwareChanged(const QString &firmware);
void otaProgressChanged(bool status, int progress, const QString &message);
@ -99,6 +106,7 @@ protected:
class Task {
public:
QString command;
std::chrono::system_clock::time_point time = std::chrono::system_clock::now();
std::function<void()> task;
std::shared_ptr<QTimer> timeoutTimer = nullptr;
std::shared_ptr<QFutureInterface<bool>> future;
@ -131,9 +139,9 @@ private:
H264FrameCallback m_frameCallback;
std::queue<Task> m_requests;
int m_timerId = -1;
int m_requestTimerId = -1;
int m_heartbeatTimerId = -1;
int heartbeats = 0;
Area m_area;
NetworkInfomation m_networkInfomation;
QString m_firmware;
};

View File

@ -16,6 +16,10 @@ Item {
property color antiClipAreaColor: "blue"
property var antiClipAreaPoints: []
property bool antiClipAreaEnabled: false
property int antiClipSensitivity: 1
property alias flip: flipSwitch.checked
property alias videoRotation: rotateComboBox.currentIndex
Item {
anchors.left: parent.left
anchors.right: parent.right
@ -238,19 +242,48 @@ Item {
}
}
}
Grid {
GridLayout {
id: controlBar
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
columns: 2
spacing: 10
verticalItemAlignment: Qt.AlignVCenter
columns: 4
Label { text: qsTr("图像: ") }
Row {
enabled: root.enabled
Layout.columnSpan: 3
Label {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("旋转")
}
Item {width: 10; height:10}
ComboBox {
id: rotateComboBox
model: ["0°","90°","180°","270°"]
onCurrentIndexChanged: {
App.currentDeviceRotation = rotateComboBox.currentIndex
}
}
Item {width: 70; height:10}
Label {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("翻转")
}
Item {width: 10; height:10}
Switch {
id: flipSwitch
onToggled: App.currentDeviceFlip=flipSwitch.checked
}
}
Label {
text: qsTr("开门区域: ")
}
Row {
enabled: root.enabled
Layout.columnSpan: 3
RadioButton {
text: "关闭"
checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled
@ -278,6 +311,7 @@ Item {
Label {text: qsTr("防夹区域: ")}
Row {
enabled: root.enabled
Layout.columnSpan: 1
RadioButton {
text: "关闭"
checked: !App.currentAntiClipAreaEnabled
@ -295,6 +329,19 @@ Item {
}
}
Label { text: qsTr("灵敏度: ")
Layout.alignment: Qt.AlignRight
}
ComboBox {
id: antiClipSensitivityComboBox
enabled: root.enabled
Layout.alignment: Qt.AlignLeft
model: [1,2,3,4,5]
currentIndex: root.antiClipSensitivity-1
onCurrentIndexChanged: {
App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1
}
}
Label {text: qsTr("屏蔽区域: ")}
Row {

View File

@ -118,7 +118,10 @@ ApplicationWindow {
shieldedAreaEnabled: App.currentShieldedAreaEnabled
shieldedAreaPoints: App.currentShieldedAreaPoints
antiClipAreaEnabled: App.currentAntiClipAreaEnabled
antiClipSensitivity: App.currentAntiClipSensitivity
antiClipAreaPoints: App.currentAntiClipAreaPoints
flip: App.currentDeviceFlip
videoRotation: App.currentDeviceRotation
}
NetworkSettingPopup {
@ -161,6 +164,7 @@ ApplicationWindow {
}
Item {}
Button {
Layout.alignment: Qt.AlignRight
text: "升级"
onClicked: {
if (deviceList.currentIndex < 0) {
@ -173,17 +177,32 @@ ApplicationWindow {
otaPopup.open()
}
}
Item {}
Button {
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 5
text: "重置"
onClicked: {
if (deviceList.currentIndex < 0) {
showMessageDialog(2, "恢复出厂设置", "请先选择设备")
return
} else {
showMessageDialog(2, "恢复出厂设置", "设备将会重启,重启后配置恢复默认",()=>{
App.resetDevice();
})
}
}
}
spacing: (parent.width - (2 * 100)) / 3
}
function showMessageDialog(type, title, message) {
function showMessageDialog(type, title, message, callback) {
let component = Qt.createComponent("MessageDialog.qml")
if (component.status === Component.Ready) {
let dialog = component.createObject(window, {
"type": type,
"titleText": title,
"text": message
"text": message,
"callback": callback
})
dialog.open()
}

View File

@ -13,6 +13,7 @@ Dialog {
property alias text: textLabel.text
property alias textFontSize: textLabel.font.pixelSize
property int type: MessageDialog.Type.Successful
property var callback
closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose
background: Rectangle {
radius: 8
@ -62,30 +63,60 @@ Dialog {
wrapMode: Text.WordWrap
}
Button {
id: cancelButton
Row {
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 6
Layout.preferredWidth: 72
Layout.preferredHeight: 40
font.family: control.font.family
text: "关闭"
font.pixelSize: 14
contentItem: Text {
text: parent.text
font: parent.font
color: parent.down ? "#FFFFFF" : "#53627C"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
spacing: 10
Button {
id: okButton
width: 72
height: 40
font.family: control.font.family
text: "好的"
font.pixelSize: 14
contentItem: Text {
text: parent.text
font: parent.font
color: parent.down ? "#FFFFFF" : "#53627C"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
border.color: "#E1E4E8"
border.width: 1
color: parent.down ? "#F25959" : "#FFFFFF"
radius: 2
}
onClicked: {
if(callback !== undefined){
callback()
}
control.accept()
}
}
background: Rectangle {
border.color: "#E1E4E8"
border.width: 1
color: parent.down ? "#F25959" : "#FFFFFF"
radius: 2
Button {
id: cancelButton
visible: callback !== undefined
width: 72
height: 40
font.family: control.font.family
text: "取消"
font.pixelSize: 14
contentItem: Text {
text: parent.text
font: parent.font
color: parent.down ? "#FFFFFF" : "#53627C"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
border.color: "#E1E4E8"
border.width: 1
color: parent.down ? "#F25959" : "#FFFFFF"
radius: 2
}
onClicked: control.reject()
}
onClicked: control.reject()
}
}
onTypeChanged: {

View File

@ -1,4 +1,5 @@
param($type)
param($type)
# 该脚本设置为 UTF8-bom 编码即可支持中文
$MsvcScript = 'D:\Program Files\Microsoft Visual Studio\2022\\Community\Common7\Tools\Launch-VsDevShell.ps1'
if (!(Test-Path $MsvcScript)) { $MsvcScript = 'D:\Program Files\Microsoft Visual Studio\2022\\Professional\Common7\Tools\Launch-VsDevShell.ps1' }
@ -10,12 +11,22 @@ $openSSLRoot = "D:\Qt\Tools\OpenSSLv3\Win_x64"
$librariesPath = "E:\Projects\Libraries"
if (!(Test-Path $librariesPath)) { $librariesPath = "D:\Projects\Libraries" }
$boostRoot = "$librariesPath\boost_1_83_0_msvc2022_64bit"
$ffmpegRoot = "$librariesPath\ffmpeg-7.0.2-full_build-shared"
# 6.1.1 版本支持 windows7
$ffmpegRoot = "$librariesPath\ffmpeg-6.1.1-full_build-shared"
$projectPath = Get-Location
$buildPath = Join-Path -Path $projectPath -ChildPath "build"
$deployPath = Join-Path -Path $buildPath -ChildPath "AntiClipSettings"
$zipFilePath = Join-Path -Path $buildPath -ChildPath "AntiClipSettings.zip"
$fileContent = (Get-Content -Path "CMakeLists.txt") -join " "
if ($fileContent -match 'project\([^\)]+VERSION\s+([0-9]+\.[0-9]+)') {
$version = $Matches[1]
} else {
Write-Output "未找到版本号"
}
$deployPath = Join-Path -Path $buildPath -ChildPath "视觉防夹设备上位机工具v$version"
$zipFilePath = Join-Path -Path $buildPath -ChildPath "视觉防夹设备上位机工具v$version.zip"
$changelogPath = Join-Path -Path $buildPath -ChildPath "CHANGELOG.txt"
function Build() {
@ -36,8 +47,19 @@ function Deploy() {
Remove-Item $deployPath -Recurse -Force
}
New-Item $deployPath -ItemType Directory
Copy-Item $buildPath\AntiClipSettings.exe $deployPath\AntiClipSettings.exe
& $qtHome\bin\windeployqt.exe $deployPath\AntiClipSettings.exe --qmldir=$qtHome\qml
Copy-Item $buildPath\AntiClipSettings.exe $deployPath\视觉防夹设备上位机工具v$version.exe
& $qtHome\bin\windeployqt.exe $deployPath\视觉防夹设备上位机工具v$version.exe --qmldir=$qtHome\qml
# 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\Qt5Test.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\qmltooling -Recurse -Force
Remove-Item -Path $deployPath\QtTest -Recurse -Force
Remove-Item -Path $deployPath\QtGraphicalEffects -Recurse -Force
# $modules = "QmlCore"
@ -61,7 +83,8 @@ function Deploy() {
Copy-Item -Path $boostRoot\lib\boost_$boost-vc143-mt-x64-1_83.dll -Destination $deployPath
}
$ffmpegs = "avcodec-61", "avdevice-61", "avfilter-10", "avformat-61", "avutil-59", "postproc-58", "swresample-5", "swscale-8"
# 暂时不需要 avfilter-9、avformat-60、postproc-57、avdevice-60
$ffmpegs = "avcodec-60", "avutil-58", "swresample-4", "swscale-7"
foreach ($ffmpeg in $ffmpegs) {
Copy-Item -Path $ffmpegRoot\bin\$ffmpeg.dll -Destination $deployPath
}