添加广播MDNS服务

This commit is contained in:
2024-08-19 09:39:32 +08:00
parent 1f7bc017ca
commit 0a5b0db9a5
192 changed files with 22181 additions and 616 deletions

View File

@@ -1,6 +1,8 @@
// ClientHandler.cpp
#include "ClientHandler.h"
#include "LicenseConfirmWindow.h"
#include "../LicenseGenerate/LicenseConfirmWindow.h"
#include "ImageEnrollWindow.h"
#include "PasswordEnrollWindow.h"
ClientHandler::ClientHandler(QTcpSocket* socket, QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest, QJsonArray frontBoardFuncConfig,
QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson, QJsonArray backBoardDevInfoJson,
@@ -14,14 +16,13 @@ ClientHandler::ClientHandler(QTcpSocket* socket, QJsonArray frontBoardOneClickTe
isManualSend(false), isSingleSend(false), isClickedSend(false), size(0),
isFirstDataReceived(true), processDataFunction(nullptr),
isDataStuck(false), dataProcessingActive(false), isRecvVideoData(false),
currentFrontBoardIndex(0), // 初始化为0
currentFrontBoardIndex(0),
currentBackBoardIndex(0)
{
connect(socket, &QTcpSocket::readyRead, this, &ClientHandler::onDataReceived);
connect(socket, &QTcpSocket::disconnected, this, &ClientHandler::onDisconnected);
qint64 bufferSize = socket->socketOption(QAbstractSocket::ReceiveBufferSizeSocketOption).toLongLong();
qDebug() << "------Receive buffer size:" << bufferSize;
/*connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error),
this, &ClientHandler::onSocketError);*/
@@ -88,14 +89,14 @@ QString ClientHandler::getCurrentFuncItemData() const
QString ClientHandler::getCurrentItemLable() const
{
QString lable = currentItem.value("lable").toString();
qDebug() << "Getting current item lable:" << lable;
//qDebug() << "Getting current item lable:" << lable;
return lable; // 返回当前项的 "data" 字段
}
QString ClientHandler::getCurrentFuncItemLable() const
{
QString lable = currentFuncItem.value("lable").toString();
qDebug() << "Getting current funcItem lable:" << lable;
//qDebug() << "Getting current funcItem lable:" << lable;
return lable; // 返回当前项的 "data" 字段
}
@@ -131,8 +132,11 @@ void ClientHandler::sendJsonItem(const QJsonArray& jsonArray, int itemIndex, con
QMutexLocker locker(&mutex);
isSingleSend = true;
isClickedSend = true;
if (itemType == "getVideo") {
isRecvVideoData = 1;
if (itemType == "handleVideo") {
if(itemIndex == 0)
isRecvVideoData = 1;
else
isRecvVideoData = 0;
startReadVideoDataTimer();
}
qDebug() << "itemIndex" << itemIndex;
@@ -177,15 +181,16 @@ void ClientHandler::sendGetDevInfoItem(int itemIndex)
}
// 发送取图按键
void ClientHandler::sendGetPicItem(int itemIndex)
void ClientHandler::sendGetPicItem(int itemIndex, int lastClickedGetVideoCamIndex)
{
sendJsonItem(getPicJson, itemIndex, "", "getPic");
sendJsonItem(getPicJson, itemIndex, QString::number(lastClickedGetVideoCamIndex), "getPic");
}
// 发送拉视频按键
void ClientHandler::sendGetVideoItem(int itemIndex, int video_flag)
{
sendJsonItem(getVideoJson, itemIndex, "", "getVideo");
qDebug() << "sendGetVideoItem itemIndex:" << itemIndex;
sendJsonItem(getVideoJson, itemIndex, "", "handleVideo");
}
// 发送License处理按键
@@ -195,16 +200,12 @@ void ClientHandler::sendLicenseItem(int itemIndex)
qDebug() << "Invalid itemIndex";
return;
}
QJsonObject item = frontBoardLicenseJson[itemIndex].toObject();
QString label = item["lable"].toString();
if (label == "write_license" || label == "get_license") {
if (label == "write_license") {
LicenseConfirmWindow dialog("你确定要发送此授权项吗?");
int result = dialog.exec();
if (result == QDialog::Accepted) {
sendJsonItem(frontBoardLicenseJson, itemIndex, "", "License");
if (dialog.exec() == QDialog::Accepted) {
sendJsonItem(frontBoardLicenseJson, itemIndex, "", "License");
}
}
else {
@@ -222,7 +223,43 @@ void ClientHandler::sendFuncItem(int itemIndex, const QString text)
// 发送单独一个测试配置 JSON 项目
void ClientHandler::sendItem(int itemIndex)
{
sendJsonItem(frontBoardTest, itemIndex, "", "test");
QString text = "";
QJsonObject currentItem = frontBoardTest[itemIndex].toObject();
if (currentItem.contains("cmd") && currentItem["cmd"].toString() == "IMG_ENROLL") {
ImageEnrollWindow dialog;
if (dialog.exec() == QDialog::Accepted) {
text = dialog.getFilePath();
QByteArray imageData = dialog.getImageData();
if (!imageData.isEmpty()) {
text = QString::fromUtf8(imageData);
}
}
else {
return;
}
}
else if (currentItem.contains("cmd") && currentItem["cmd"].toString() == "DEL_USER") {
DelUserWindow dialog;
if (dialog.exec() == QDialog::Accepted) {
QString userInput = dialog.getUserInput();
if (!userInput.isEmpty() && currentItem.contains("val")) {
text = userInput;
}
}
else {
return;
}
}
else if (currentItem.contains("cmd") && currentItem["cmd"].toString() == "PASSWD_ENROLL") {
PasswordEnrollWindow dialog;
if (dialog.exec() == QDialog::Accepted) {
text = dialog.getPassword();
}
else {
return;
}
}
sendJsonItem(frontBoardTest, itemIndex, text, "test");
}
void ClientHandler::sendDevInfoJsonItem(const QJsonObject& jsonItem, int itemIndex)
@@ -406,6 +443,10 @@ void ClientHandler::setThreadPriority(QThread::Priority priority) {
void ClientHandler::onDataReceived()
{
// 接收其他数据 添加区分 视频与其他数据 的标志位
qDebug() << "isRecvVideoData:" << isRecvVideoData;
qDebug() << "isPowerOnSend:" << isPowerOnSend;
qDebug() << "isClickedSend:" << isClickedSend;
qDebug() << "isSingleSend:" << isSingleSend;
if (!isRecvVideoData &&
(isPowerOnSend || isClickedSend || (isSingleSend && (currentItemIndex < frontBoardTest.size())))) {
QByteArray allData;
@@ -425,7 +466,8 @@ void ClientHandler::onDataReceived()
emit startTimeout(0);
}
if (!allData.isEmpty()) {
emit dataReceived(getClientAddress(), allData, 0xFF, currentItemIndex, currentFuncItemIndex, "", "");
//emit dataReceived(getClientAddress(), allData, 0xFF, currentItemIndex, currentFuncItemIndex, "", "");
emit dataReceived(getClientAddress(), allData, 0xFF, currentItemIndex, currentFuncItemIndex, getCurrentItemLable(), "");
if (!isSingleSend && !isPowerOnSend) {
currentItemIndex ++;
itemsProcessedCount ++;
@@ -458,10 +500,13 @@ void ClientHandler::onDataReceived()
//qDebug() << "" << __FUNCTION__ << "------> itemsProcessedCount " << itemsProcessedCount;
}
// 接收视频流数据 isRecvVideoData 置 0
else if (!dataProcessingActive) {
else if (isRecvVideoData && (!dataProcessingActive)) {
dataProcessingActive = true;
QTimer::singleShot(0, this, &ClientHandler::processPendingData);
}
else {
socket->readAll();
}
}
void ClientHandler::processPendingData()