新增U盘获取图语License功能
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
// ClientHandler.cpp
|
||||
#include "ClientHandler.h"
|
||||
#include "LicenseConfirmWindow.h"
|
||||
|
||||
ClientHandler::ClientHandler(QTcpSocket* socket, QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest, QJsonArray frontBoardFuncConfig, QJsonArray getDevInfoJson,
|
||||
QJsonArray getPicJson, QJsonArray getVideoJson, int clientId, QObject* parent)
|
||||
: QObject(parent), socket(socket), frontBoardOneClickTest(frontBoardOneClickTest), frontBoardTest(frontBoardTest), frontBoardFuncConfig(frontBoardFuncConfig), getDevInfoJson(getDevInfoJson),
|
||||
getPicJson(getPicJson), getVideoJson(getVideoJson), currentItemIndex(0), clientId(clientId),
|
||||
isManualSend(false), isSingleSend(false), isClickedSend(false), size(0), isFirstDataReceived(true), processDataFunction(nullptr),
|
||||
isDataStuck(false), dataProcessingActive(false), isRecvVideoData(false)
|
||||
ClientHandler::ClientHandler(QTcpSocket* socket, QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest, QJsonArray frontBoardFuncConfig,
|
||||
QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson, QJsonArray backBoardDevInfoJson,
|
||||
QJsonArray getPicJson, QJsonArray getVideoJson, int clientId, QObject* parent)
|
||||
: QObject(parent), socket(socket),
|
||||
frontBoardOneClickTest(frontBoardOneClickTest), frontBoardTest(frontBoardTest),
|
||||
frontBoardFuncConfig(frontBoardFuncConfig), frontBoardDevInfoJson(frontBoardDevInfoJson),
|
||||
frontBoardLicenseJson(frontBoardLicenseJson),
|
||||
backBoardDevInfoJson(backBoardDevInfoJson), getPicJson(getPicJson),
|
||||
getVideoJson(getVideoJson), currentItemIndex(0), clientId(clientId),
|
||||
isManualSend(false), isSingleSend(false), isClickedSend(false), size(0),
|
||||
isFirstDataReceived(true), processDataFunction(nullptr),
|
||||
isDataStuck(false), dataProcessingActive(false), isRecvVideoData(false),
|
||||
currentFrontBoardIndex(0), // 初始化为0
|
||||
currentBackBoardIndex(0)
|
||||
{
|
||||
connect(socket, &QTcpSocket::readyRead, this, &ClientHandler::onDataReceived);
|
||||
connect(socket, &QTcpSocket::disconnected, this, &ClientHandler::onDisconnected);
|
||||
@@ -179,6 +188,30 @@ void ClientHandler::sendGetVideoItem(int itemIndex, int video_flag)
|
||||
sendJsonItem(getVideoJson, itemIndex, "", "getVideo");
|
||||
}
|
||||
|
||||
// 发送License处理按键
|
||||
void ClientHandler::sendLicenseItem(int itemIndex)
|
||||
{
|
||||
if (itemIndex < 0 || itemIndex >= frontBoardLicenseJson.size()) {
|
||||
qDebug() << "Invalid itemIndex";
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject item = frontBoardLicenseJson[itemIndex].toObject();
|
||||
QString label = item["lable"].toString();
|
||||
|
||||
if (label == "write_license" || label == "get_license") {
|
||||
LicenseConfirmWindow dialog("你确定要发送此授权项吗?");
|
||||
int result = dialog.exec();
|
||||
|
||||
if (result == QDialog::Accepted) {
|
||||
sendJsonItem(frontBoardLicenseJson, itemIndex, "", "License");
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendJsonItem(frontBoardLicenseJson, itemIndex, "", "License");
|
||||
}
|
||||
}
|
||||
|
||||
// 发送单独一个功能配置 JSON 项目
|
||||
void ClientHandler::sendFuncItem(int itemIndex, const QString text)
|
||||
{
|
||||
@@ -192,6 +225,50 @@ void ClientHandler::sendItem(int itemIndex)
|
||||
sendJsonItem(frontBoardTest, itemIndex, "", "test");
|
||||
}
|
||||
|
||||
void ClientHandler::sendDevInfoJsonItem(const QJsonObject& jsonItem, int itemIndex)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
isPowerOnSend = true;
|
||||
qDebug() << "itemIndex:" << itemIndex;
|
||||
qDebug() << "jsonItem.size():" << jsonItem.size();
|
||||
|
||||
QString itemData = QJsonDocument(jsonItem).toJson();
|
||||
emit sendData(itemData.toUtf8());
|
||||
|
||||
if (jsonItem.contains("timeout")) {
|
||||
int timeout = jsonItem.value("timeout").toInt();
|
||||
if (timeout > 0) {
|
||||
emit startTimeout(timeout);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 如果没有 timeout 字段,则不设置超时处理,一直等待数据接收
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ClientHandler::sendDevInfoItem()
|
||||
{
|
||||
// 前板
|
||||
if (1) {
|
||||
qDebug() << "frontBoardDevInfoJson.size():" << frontBoardDevInfoJson.size();
|
||||
if (currentFrontBoardIndex < frontBoardDevInfoJson.size()) {
|
||||
sendDevInfoJsonItem(frontBoardDevInfoJson[currentFrontBoardIndex].toObject(), 1);
|
||||
currentFrontBoardIndex ++;
|
||||
}
|
||||
else
|
||||
isPowerOnSend = false;
|
||||
}
|
||||
// 后板
|
||||
else {
|
||||
if (currentBackBoardIndex < backBoardDevInfoJson.size()) {
|
||||
sendDevInfoJsonItem(backBoardDevInfoJson[currentBackBoardIndex ++].toObject(), 1);
|
||||
}
|
||||
else
|
||||
isPowerOnSend = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 发送下一个 JSON 项目
|
||||
void ClientHandler::sendNextItem()
|
||||
{
|
||||
@@ -330,11 +407,11 @@ void ClientHandler::onDataReceived()
|
||||
{
|
||||
// 接收其他数据 添加区分 视频与其他数据 的标志位
|
||||
if (!isRecvVideoData &&
|
||||
(isClickedSend || (isSingleSend && (currentItemIndex < frontBoardTest.size())))) {
|
||||
(isPowerOnSend || isClickedSend || (isSingleSend && (currentItemIndex < frontBoardTest.size())))) {
|
||||
QByteArray allData;
|
||||
while (socket->bytesAvailable() > 0) {
|
||||
qint64 bytesAvailableBefore = socket->bytesAvailable();
|
||||
qDebug() << "Bytes available before read:" << bytesAvailableBefore << "clientId:" << clientId;
|
||||
//qDebug() << "Bytes available before read:" << bytesAvailableBefore << "clientId:" << clientId;
|
||||
QByteArray buffer;
|
||||
buffer.resize(qMin(bytesAvailableBefore, qint64(5 * 1024))); // 每次读取最多 5KB
|
||||
qint64 bytesRead = socket->read(buffer.data(), buffer.size());
|
||||
@@ -349,7 +426,7 @@ void ClientHandler::onDataReceived()
|
||||
}
|
||||
if (!allData.isEmpty()) {
|
||||
emit dataReceived(getClientAddress(), allData, 0xFF, currentItemIndex, currentFuncItemIndex, "", "");
|
||||
if (!isSingleSend) {
|
||||
if (!isSingleSend && !isPowerOnSend) {
|
||||
currentItemIndex ++;
|
||||
itemsProcessedCount ++;
|
||||
}
|
||||
@@ -360,17 +437,25 @@ void ClientHandler::onDataReceived()
|
||||
isSingleSend = false; // 重置标志
|
||||
isClickedSend = false;
|
||||
}
|
||||
else if (currentItemIndex < frontBoardOneClickTest.size()) {
|
||||
else if (isPowerOnSend && currentFrontBoardIndex < frontBoardDevInfoJson.size()) {
|
||||
sendDevInfoItem();
|
||||
}
|
||||
/*else if (isPowerOnSend) {
|
||||
qDebug() << "All items processed in onDataReceived.";
|
||||
emit allItemsProcessed(getClientAddress(), currentFrontBoardIndex);
|
||||
isPowerOnSend = false;
|
||||
}*/
|
||||
else if (isClickedSend && (currentItemIndex < frontBoardOneClickTest.size())) {
|
||||
//qDebug() << "-------- start sendNextItem";
|
||||
sendNextItem();
|
||||
}
|
||||
else {
|
||||
qDebug() << "All items processed in onDataReceived.";
|
||||
else if(isClickedSend) {
|
||||
//qDebug() << "All items processed in onDataReceived.";
|
||||
emit allItemsProcessed(getClientAddress(), itemsProcessedCount);
|
||||
isClickedSend = false;
|
||||
//resetCurrentItemIndex();
|
||||
}
|
||||
qDebug() << "" << __FUNCTION__ << "------> itemsProcessedCount :" << itemsProcessedCount;
|
||||
//qDebug() << "" << __FUNCTION__ << "------> itemsProcessedCount :" << itemsProcessedCount;
|
||||
}
|
||||
// 接收视频流数据 isRecvVideoData 置 0
|
||||
else if (!dataProcessingActive) {
|
||||
@@ -387,7 +472,7 @@ void ClientHandler::processPendingData()
|
||||
QByteArray allData;
|
||||
while (socket->bytesAvailable() > 0 && maxIterations-- > 0) {
|
||||
qint64 bytesAvailableBefore = socket->bytesAvailable();
|
||||
qDebug() << "Bytes available before read:" << bytesAvailableBefore << "clientId:" << clientId;
|
||||
//qDebug() << "Bytes available before read:" << bytesAvailableBefore << "clientId:" << clientId;
|
||||
RETRY:
|
||||
// 分块读取数据,避免一次性读取过多数据
|
||||
QByteArray buffer;
|
||||
@@ -398,9 +483,9 @@ void ClientHandler::processPendingData()
|
||||
buffer.resize(bytesRead);
|
||||
allData.append(buffer);
|
||||
qint64 bytesAvailableAfter = socket->bytesAvailable();
|
||||
qDebug() << "--1--Received data size:" << buffer.size() << "clientId:" << clientId
|
||||
/*qDebug() << "--1--Received data size:" << buffer.size() << "clientId:" << clientId
|
||||
<< "at" << QDateTime::currentDateTime().toString(Qt::ISODate)
|
||||
<< "bytesAvailable after read:" << bytesAvailableAfter;
|
||||
<< "bytesAvailable after read:" << bytesAvailableAfter; */
|
||||
|
||||
if (isFirstDataReceived) {
|
||||
RNDISFirstData(buffer);
|
||||
@@ -474,23 +559,31 @@ void ClientHandler::onTimeout()
|
||||
//emit statusUpdated(socket->peerAddress().toString(), currentItemIndex, false, itemData);
|
||||
emit statusUpdated(getClientAddress(), currentItemIndex + 1, currentFuncItemIndex + 1,
|
||||
false, getCurrentItemLable(), getCurrentFuncItemLable());
|
||||
if (isSingleSend == false) {
|
||||
if (!isSingleSend && !isPowerOnSend) {
|
||||
currentItemIndex ++;
|
||||
itemsProcessedCount ++;
|
||||
}
|
||||
}
|
||||
if (isSingleSend) {
|
||||
isSingleSend = false; // 重置标志
|
||||
isSingleSend = false;
|
||||
}
|
||||
else if (currentItemIndex < frontBoardOneClickTest.size()) {
|
||||
else if (isPowerOnSend && currentFrontBoardIndex < frontBoardDevInfoJson.size()) {
|
||||
sendDevInfoItem();
|
||||
}
|
||||
else if (isClickedSend && (currentItemIndex < frontBoardOneClickTest.size())) {
|
||||
//qDebug() << "------> onTimeout";
|
||||
sendNextItem();
|
||||
}
|
||||
else {
|
||||
else if(isClickedSend) {
|
||||
qDebug() << "All items processed in onTimeout.";
|
||||
emit allItemsProcessed(getClientAddress(), itemsProcessedCount);
|
||||
//resetCurrentItemIndex();
|
||||
}
|
||||
else if (isPowerOnSend) {
|
||||
qDebug() << "All items processed in onTimeout.";
|
||||
emit allItemsProcessed(getClientAddress(), currentFrontBoardIndex);
|
||||
//resetCurrentItemIndex();
|
||||
}
|
||||
//qDebug() << "------> end mutex :" << __FUNCTION__;
|
||||
qDebug() << "" << __FUNCTION__ << "------> itemsProcessedCount :" << itemsProcessedCount;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <QThread>
|
||||
#include <QElapsedTimer>
|
||||
#include <QStorageInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "DelUserWindows.h"
|
||||
|
||||
@@ -28,11 +29,15 @@ class ClientHandler : public QObject, public QRunnable
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ClientHandler(QTcpSocket* socket, QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest, QJsonArray frontBoardFuncConfig, QJsonArray getDevInfoJson,
|
||||
QJsonArray getPicJson, QJsonArray getVideoJson, int clientId, QObject* parent = nullptr);
|
||||
explicit ClientHandler(QTcpSocket* socket, QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest,
|
||||
QJsonArray frontBoardFuncConfig, QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson,
|
||||
QJsonArray backBoardDevInfoJson, QJsonArray getPicJson, QJsonArray getVideoJson,
|
||||
int clientId, QObject* parent = nullptr);
|
||||
|
||||
~ClientHandler();
|
||||
|
||||
void sendDevInfoItem();
|
||||
|
||||
bool isData_Stuck() const;
|
||||
//static int pre_H264_clientId; // 预览H264的客户端ID
|
||||
QTcpSocket* getSocket() const { return socket; }
|
||||
@@ -48,6 +53,8 @@ public:
|
||||
void sendGetPicItem(int itemIndex);
|
||||
// 发送拉视频流按键
|
||||
void sendGetVideoItem(int itemIndex, int video_flag);
|
||||
// 发送License处理按键
|
||||
void sendLicenseItem(int itemIndex);
|
||||
// 发送下一个功能配置 JSON 项目
|
||||
void sendFuncItem(int itemIndex, QString text);
|
||||
// 发送下一个 JSON 项目
|
||||
@@ -110,7 +117,10 @@ private:
|
||||
QTcpSocket* socket; // 客户端 socket
|
||||
QJsonArray frontBoardOneClickTest; // 前板一键功能测试 JSON
|
||||
QJsonArray frontBoardTest; // 前板单项测试 JSON
|
||||
QJsonArray frontBoardFuncConfig; // 前板功能配置参数 JSON
|
||||
QJsonArray frontBoardFuncConfig; // 前板功能配置参数 JSON
|
||||
QJsonArray frontBoardDevInfoJson; // 前板设备信息参数 JSON
|
||||
QJsonArray frontBoardLicenseJson; // 前板license信息 JSON
|
||||
QJsonArray backBoardDevInfoJson; // 后板设备信息参数 JSON
|
||||
QJsonArray jsonConfig; // 测试区 JSON 配置
|
||||
QJsonArray funcJsonConfig; // 功能区 JSON 配置
|
||||
QJsonArray getDevInfoJson; // 获取设备信息 JSON 配置
|
||||
@@ -127,9 +137,12 @@ private:
|
||||
bool isSingleSend; // 单独点击按键发送的标志
|
||||
bool isClickedSend; // 点击按键发送的标志,没有点击不接收数据
|
||||
bool isRecvVideoData;
|
||||
bool isPowerOnSend = false; // 上电发送设备信息
|
||||
//QTimer* timeoutTimer; // 超时定时器
|
||||
|
||||
int size;
|
||||
int currentFrontBoardIndex; // 当前发送的前板设备信息项的索引
|
||||
int currentBackBoardIndex; // 当前发送的后板设备信息项的索引
|
||||
|
||||
void checkThreadStatus();
|
||||
bool isFirstDataReceived;
|
||||
@@ -141,6 +154,9 @@ private:
|
||||
void RNDISClient3Data(QByteArray& data);
|
||||
void RNDISClient4Data(QByteArray& data);
|
||||
|
||||
void sendDevInfoJsonItem(const QJsonObject& jsonItem, int itemIndex);
|
||||
//void sendDevInfoItem();
|
||||
|
||||
QTimer* readTimer;
|
||||
QTimer* threadStatusTimer;
|
||||
QTimer* connectionCheckTimer;
|
||||
|
||||
52
FactoryTestTool/SourceCode/Network/LicenseConfirmWindow.h
Normal file
52
FactoryTestTool/SourceCode/Network/LicenseConfirmWindow.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef LICENSECONFIRMWINDOW_H
|
||||
#define LICENSECONFIRMWINDOW_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
class LicenseConfirmWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LicenseConfirmWindow(const QString& message, QWidget* parent = nullptr)
|
||||
{
|
||||
messageLabel = new QLabel(message, this);
|
||||
confirmButton = new QPushButton("确认", this);
|
||||
cancelButton = new QPushButton("取消", this);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
layout->addWidget(messageLabel);
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addWidget(confirmButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
setLayout(layout);
|
||||
setWindowTitle("获取License");
|
||||
resize(260, 100); // 设置对话框的大小
|
||||
|
||||
connect(confirmButton, &QPushButton::clicked, this, &LicenseConfirmWindow::onConfirmClicked);
|
||||
connect(cancelButton, &QPushButton::clicked, this, &LicenseConfirmWindow::onCancelClicked);
|
||||
}
|
||||
|
||||
private slots:
|
||||
void onConfirmClicked()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
void onCancelClicked()
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
private:
|
||||
QLabel* messageLabel;
|
||||
QPushButton* confirmButton;
|
||||
QPushButton* cancelButton;
|
||||
};
|
||||
|
||||
#endif // LICENSECONFIRMWINDOW_H
|
||||
Reference in New Issue
Block a user