新增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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user