1.调通所有与服务器HTTP连接的接口 2.更新图语License从服务器查询和U盘获取后上报,前板可直接使用产测工具写入License 3.优化接收到前板的H264解码后出现视频卡的问题 4.更新从前板取图后旋转 5.增加ffmpeg解码的视频分辨率获取

This commit is contained in:
2024-08-29 11:49:55 +08:00
parent 07ab6b9608
commit e0c1e37191
21 changed files with 456 additions and 1882 deletions

View File

@@ -80,7 +80,7 @@ MainWidget::MainWidget(QWidget* parent) :
ClientHandler* handler = new ClientHandler(socket, frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
frontBoardDevInfoJson, frontBoardLicenseJson,
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
getPicJson, getVideoJson, clientId, nullptr);
backBoardUuidJson, getPicJson, getVideoJson, clientId, nullptr);
// 将 ClientHandler 移动到线程池中的线程
handler->moveToThread(thread);
@@ -119,18 +119,22 @@ MainWidget::MainWidget(QWidget* parent) :
clients.append(handler);
clients_1[clientId] = handler;
clientThreads[clientId] = thread;
connect(handler, &ClientHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
connect(handler, &ClientHandler::clientDisconnected, this, &MainWidget::onClientDisconnected);
connect(handler, &ClientHandler::allItemsProcessed, this, &MainWidget::onAllItemsProcessed);
connect(handler, &ClientHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
connect(handler, &ClientHandler::clientDisconnected, this, &MainWidget::onClientDisconnected);
connect(handler, &ClientHandler::allItemsProcessed, this, &MainWidget::onAllItemsProcessed);
connect(handler, &ClientHandler::selectClientDisconnected, this, &MainWidget::onDisconnectClient);
// 创建 DataHandler 对象并连接信号
DataHandler* dataHandler = new DataHandler(leftLens_imageLabel, rightLens_imageLabel, videoLabel, licenseHwInfoEdit, &devInfoLineEdits, this);
connect(handler, &ClientHandler::dataReceived, dataHandler, &DataHandler::handleData);
connect(dataHandler, &DataHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
DataHandler* dataHandler = new DataHandler(leftLens_imageLabel, rightLens_imageLabel, videoLabel, licenseHwInfoEdit, &devInfoLineEdits,
frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
frontBoardDevInfoJson, frontBoardLicenseJson,
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
backBoardUuidJson, getPicJson, getVideoJson, this);
connect(handler, &ClientHandler::dataReceived, dataHandler, &DataHandler::handleData);
connect(dataHandler, &DataHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
connect(handler, &ClientHandler::startReadTimer, this, &MainWidget::startClientReadTimer);
connect(handler, &ClientHandler::stopReadTimer, this, &MainWidget::stopClientReadTimer);
connect(handler, &ClientHandler::startReadTimer, this, &MainWidget::startClientReadTimer);
connect(handler, &ClientHandler::stopReadTimer, this, &MainWidget::stopClientReadTimer);
// 创建和管理定时器
QTimer* readTimer = new QTimer(this);
@@ -244,9 +248,10 @@ void MainWidget::onHttpRequestError(const QString& errorString)
isRequestSuccessful = 2;
}
QString generateRandomRequestID() {
// 生成随机字符串
QString generateRandomRequestID(int minBitStr, int maxBitStr) {
const QString possibleCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~";
int length = QRandomGenerator::global()->bounded(1, 33); // 生成长度在1到32之间
int length = QRandomGenerator::global()->bounded(minBitStr, maxBitStr); // 生成长度在minBitStr到maxBitStr之间
QString randomString;
for (int i = 0; i < length; ++i) {
int index = QRandomGenerator::global()->bounded(possibleCharacters.size());
@@ -256,6 +261,7 @@ QString generateRandomRequestID() {
return randomString;
}
// 哈希256 转 base64
QString HmacSha256ToBase64(const QString& data, const QString& secret) {
QByteArray keyBytes = secret.toUtf8();
QByteArray dataBytes = data.toUtf8();
@@ -319,7 +325,7 @@ void prepareRequestHeaders(QNetworkRequest& request, const QString& sign, const
// GET 请求
void sendGetRequest(HttpClient* httpClient, const QUrl& url, const QMap<QString, QString>& params, const QString& secret) {
QString request_id = generateRandomRequestID();
QString request_id = generateRandomRequestID(1, 33);
qDebug() << "request_id:" << request_id;
QUrl modifiedUrl = url;
QUrlQuery query;
@@ -337,7 +343,7 @@ void sendGetRequest(HttpClient* httpClient, const QUrl& url, const QMap<QString,
// POST 请求
void sendPostRequest(HttpClient* httpClient, const QUrl& url, const QMap<QString, QString>& params, const QJsonObject& jsonData, const QString& secret) {
QString request_id = generateRandomRequestID();
QString request_id = generateRandomRequestID(1, 33);
qDebug() << "request_id:" << request_id;
QString sign = calculateSignature(params, "POST", secret, request_id, QString::number(QDateTime::currentSecsSinceEpoch()));
qDebug() << "sendPostRequest URL:" << url.toString();
@@ -357,7 +363,6 @@ void MainWidget::FactoryToolSendGetUuidToHttpServer(const QString& mac_addr) {
{"batch", "1"},
{"mac", mac_addr}
};
QString secret = "rCeOzwisLFLasvlt";
sendGetRequest(httpClient, url, params, secret);
}
@@ -423,12 +428,14 @@ void MainWidget::FactoryToolSendPostTestToHttpServer() {
// POST 图语 License 上报
void MainWidget::FactoryToolSendPostLicenseToHttpServer(const QString& hardware_info, const QString& license_info) {
QUrl url("http://admin.hassecurity.cn/v1/algorithmKey");
QString UTC_time = QString::number(QDateTime::currentSecsSinceEpoch());
qint64 UTC_time = QDateTime::currentSecsSinceEpoch();
QMap<QString, QString> params = {
{"id", hardware_info},
{"key", license_info},
{"time", UTC_time},
{"type", "TUYU"}
{"time", QString::number(UTC_time)}
};
QJsonObject jsonData = {
@@ -565,6 +572,7 @@ void MainWidget::setupUI()
leftLayout->setStretch(1, 200);
saveCheckBox = new QCheckBox("", this);
saveCheckBox->setChecked(true);
selectFileButton = new QPushButton("Save", this);
selectFileButton->setFixedSize(45, 28);
clearLogButton = new QPushButton("Clear", this);
@@ -585,10 +593,6 @@ void MainWidget::setupUI()
// 读取 JSON 配置文件
readJsonConfig();
/*QGroupBox* groupBox = createLicenseGroupBox();
leftLayout->addWidget(groupBox);
leftLayout->setStretch(3, 1);*/
QWidget* leftContainer = new QWidget(this);
leftContainer->setLayout(leftLayout);
leftContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -657,7 +661,7 @@ void MainWidget::setupUI()
setLayout(mainLayout);
setWindowTitle("SL100 工厂产测工具 - V0.0.1");
resize(1340, 1000);
resize(1340, 900);
connect(startServerButton, &QPushButton::clicked, this, &MainWidget::onStartServerClicked);
connect(sendAllButton, &QPushButton::clicked, this, &MainWidget::onSendAllClicked);
@@ -682,19 +686,29 @@ void MainWidget::onclearLogButtonClicked()
void MainWidget::onSaveCheckBoxStateChanged(int state)
{
if (state == Qt::Checked) {
saveStatusListToFile(filePathLineEdit->text());
}
if (state == Qt::Checked) checkBoxState = true;
else checkBoxState = false;
}
void MainWidget::saveStatusListToFile(const QString& filePath)
{
if (filePath.isEmpty()) {
return;
QString actualFilePath = filePath;
if (actualFilePath.isEmpty()) {
QString defaultDirPath = QDir::currentPath() + "/TestLog";
QDir dir(defaultDirPath);
if (!dir.exists()) {
if (!dir.mkpath(defaultDirPath)) {
qWarning() << "Failed to create directory:" << defaultDirPath;
return;
}
}
QString currentTime = QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss");
actualFilePath = defaultDirPath + "/" + currentTime + ".txt";
}
QFile file(filePath);
QFile file(actualFilePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Failed to open file:" << actualFilePath;
return;
}
@@ -755,6 +769,24 @@ void MainWidget::onDisconnectClient(int clientId)
void MainWidget::onClientDisconnected(ClientHandler* handler)
{
int clientId = handler->getClientId();
qDebug() << " preVideoClientId :" << handler->preVideoClientId;
qDebug() << " clientId :" << clientId;
if (handler->preVideoClientId == clientId) {
qDebug() << "Current path: " << QDir::currentPath();
QString filePath = QDir::currentPath() + "/add1.h264";
if (QFile::exists(filePath)) {
QFile file(filePath);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { // 使用 Truncate 模式打开文件以清空内容
qDebug() << "File add1.h264 cleared successfully.";
}
else {
qDebug() << "Failed to clear file add1.h264:" << file.errorString();
}
}
else {
qDebug() << "File add1.h264 does not exist.";
}
}
if (clientTimers.contains(clientId)) {
QTimer* timer = clientTimers[clientId];
timer->stop();
@@ -771,8 +803,10 @@ void MainWidget::onClientDisconnected(ClientHandler* handler)
// 更新连接数并更新按键文本
connectedClientsCount--;
qDebug() << " connectedClientsCount :" << connectedClientsCount;
if (nextClientId <= 2) nextClientId--;
deviceConnected = true;
updateServerButtonText();
}
@@ -829,6 +863,7 @@ void MainWidget::onLicenseButtonClicked()
}
qDebug() << "isRequestSuccessful:" << isRequestSuccessful;
if (isRequestSuccessful == 2) {
isRequestSuccessful = 0;
return;
}
else if(isRequestSuccessful == 1) {
@@ -839,6 +874,7 @@ void MainWidget::onLicenseButtonClicked()
licenseKey = formatLicenseKey(licenseKey);
licenseHwInfoEdit->setPlainText(licenseKey);
qDebug() << "HTTP Server License is:" << licenseKey;
isRequestSuccessful = 0;
return;
}
}
@@ -856,13 +892,19 @@ void MainWidget::onLicenseButtonClicked()
QByteArray dataByteArray = QByteArray::fromHex(dataStr.toUtf8());
memcpy(hardware_info, dataByteArray.data(), qMin(dataByteArray.size(), PIX_HARDWARE_INFO_BYTES));
//unsigned char hardware_info[PIX_HARDWARE_INFO_BYTES] = { 0x46,0x0b,0x5d,0x11,0x58,0x17,0x4d,0x5e,0x55,0x5c,0x51,0x4a,0x5a,0x07,0x59,0x4c,0x5f,0x45,0x5b,0x5f,0x5a,0x45,0x1c,0x5a,0x45,0x43,0x44,0x47,0x51,0x5e,0x44,0x30 };
LicenseConfirmWindow dialog("你确定要获取此授权吗?");
LicenseConfirmWindow dialog("你确定要获取此授权吗?\n请确认你的hw_info是否正确");
if (dialog.exec() == QDialog::Accepted) {
#if 0
licenseGenerate(hardware_info, license_info);
#if !MANUAL_UPLOAD_LICENSE
if (!(licenseGenerate(hardware_info, license_info))) {
qDebug() << "从U盘获取License失败" ;
isRequestSuccessful = 0;
licenseHwInfoEdit->setPlainText("从U盘获取License失败,请检查U盘是否插入电脑!!!");
return;
}
QString licenseInfoHex = QByteArray(reinterpret_cast<char*>(license_info), PIX_LICENCE_BYTES).toHex().toUpper();
#else
unsigned char license_info_1[PIX_LICENCE_BYTES] = { 0x07, 0xe8, 0xf3, 0x80, 0xa8, 0x07, 0x72, 0xa1, 0x17, 0xfe, 0xda, 0x67, 0xbd, 0x4a, 0x5a, 0xb5, 0xbb, 0x8b, 0x2d, 0xb2, 0xbf, 0x89, 0x74, 0xe5, 0xb0, 0x99, 0x70, 0x74, 0x3c, 0x6f, 0xf8, 0x82, 0x79, 0xab, 0x31, 0x9c, 0xdf, 0xe8, 0x9e, 0x75, 0x8f, 0x42, 0xb3, 0xcf, 0x00, 0x60, 0xa0, 0x38, 0xa4, 0xb8, 0xbe, 0xa6, 0x5d, 0x9f, 0x8b, 0x41, 0xf3, 0x0a, 0x69, 0xf6, 0x50, 0x94, 0x3f, 0xd0, 0xa5, 0xee, 0x88, 0x20, 0x93, 0x9a, 0x1c, 0xe9, 0x64, 0xd3, 0xaf, 0x9f, 0xc7, 0x66, 0x00, 0x7d, 0x7d, 0x68, 0xf1, 0xa4, 0xe1, 0x58, 0x00, 0x1d, 0x03, 0x0d, 0x40, 0x08, 0xa4, 0xcc, 0x0b, 0xd8, 0x19, 0x70, 0x9a, 0x83, 0x81, 0xbf, 0x27, 0x35, 0xb8, 0xec, 0x59, 0xa8, 0xd0, 0x03, 0xdb, 0xf6, 0xcf, 0x83, 0xaa, 0x0e, 0xfc, 0x95, 0x29, 0x77, 0xec, 0x89, 0xc5, 0x79, 0x10, 0x40, 0xd8, 0xbb };
//unsigned char license_info_1[PIX_LICENCE_BYTES] = { 0x07, 0xe8, 0xf3, 0x80, 0xa8, 0x07, 0x72, 0xa1, 0x17, 0xfe, 0xda, 0x67, 0xbd, 0x4a, 0x5a, 0xb5, 0xbb, 0x8b, 0x2d, 0xb2, 0xbf, 0x89, 0x74, 0xe5, 0xb0, 0x99, 0x70, 0x74, 0x3c, 0x6f, 0xf8, 0x82, 0x79, 0xab, 0x31, 0x9c, 0xdf, 0xe8, 0x9e, 0x75, 0x8f, 0x42, 0xb3, 0xcf, 0x00, 0x60, 0xa0, 0x38, 0xa4, 0xb8, 0xbe, 0xa6, 0x5d, 0x9f, 0x8b, 0x41, 0xf3, 0x0a, 0x69, 0xf6, 0x50, 0x94, 0x3f, 0xd0, 0xa5, 0xee, 0x88, 0x20, 0x93, 0x9a, 0x1c, 0xe9, 0x64, 0xd3, 0xaf, 0x9f, 0xc7, 0x66, 0x00, 0x7d, 0x7d, 0x68, 0xf1, 0xa4, 0xe1, 0x58, 0x00, 0x1d, 0x03, 0x0d, 0x40, 0x08, 0xa4, 0xcc, 0x0b, 0xd8, 0x19, 0x70, 0x9a, 0x83, 0x81, 0xbf, 0x27, 0x35, 0xb8, 0xec, 0x59, 0xa8, 0xd0, 0x03, 0xdb, 0xf6, 0xcf, 0x83, 0xaa, 0x0e, 0xfc, 0x95, 0x29, 0x77, 0xec, 0x89, 0xc5, 0x79, 0x10, 0x40, 0xd8, 0xbb };
unsigned char license_info_1[PIX_LICENCE_BYTES] = { 0x6a, 0x70, 0xc0, 0x40, 0xc9, 0x20, 0xf5, 0xd2, 0x78, 0xac, 0x05, 0x80, 0xa6, 0xcf, 0x3f, 0xd5, 0x72, 0xf6, 0xc3, 0x82, 0x11, 0x0d, 0x56, 0x37, 0xb3, 0x87, 0x19, 0x13, 0x79, 0xa5, 0x9b, 0x37, 0xf2, 0xab, 0xcb, 0xa3, 0xea, 0xc4, 0x45, 0xc6, 0xae, 0xc4, 0xa4, 0x72, 0xe9, 0x36, 0x1e, 0xbe, 0x78, 0xd6, 0xcd, 0x85, 0xd, 0x63, 0x93, 0x7a, 0x84, 0x9a, 0x31, 0x99, 0xe1, 0x09, 0xc1, 0xfa, 0xbe, 0x32, 0x42, 0xc5, 0xc9, 0x89, 0x03, 0x7e, 0x81, 0xe5, 0x25, 0xf, 0x4d, 0x68, 0x9d, 0x53, 0xd1, 0x04, 0x29, 0x34, 0x53, 0x09, 0x22, 0x5, 0x29, 0xce, 0xb1, 0xc9, 0x01, 0xed, 0x2a, 0xd2, 0x16, 0xfb, 0x3c, 0x27, 0xba, 0x4a, 0x69, 0x10, 0x3a, 0x54, 0x5a, 0x8f, 0xca, 0x47, 0x8d, 0x34, 0x2b, 0x57, 0xad, 0x27, 0x9a, 0x15, 0x37, 0x86, 0x60, 0xd6, 0x34, 0xd8, 0x32, 0xee, 0x9c, 0x46 };
QString licenseInfoHex = QByteArray(reinterpret_cast<char*>(license_info_1), PIX_LICENCE_BYTES).toHex().toUpper();
#endif
qDebug() << "上报服务器 licenseInfoHex:" << licenseInfoHex;
@@ -871,13 +913,17 @@ void MainWidget::onLicenseButtonClicked()
QString licenseInfoStr;
printf("U盘 Get License is\n");
for (int j = 0; j < PIX_LICENCE_BYTES; ++j) {
//printf("0x%02x, ", license_info[j]);
//licenseInfoStr.append(QString::asprintf("0x%02x, ", license_info[j]));
#if !MANUAL_UPLOAD_LICENSE
printf("0x%02x, ", license_info[j]);
licenseInfoStr.append(QString::asprintf("0x%02x, ", license_info[j]));
#else
printf("0x%02x, ", license_info_1[j]);
licenseInfoStr.append(QString::asprintf("0x%02x, ", license_info_1[j]));
#endif
}
printf("\n");
licenseHwInfoEdit->setPlainText(licenseInfoStr);
isRequestSuccessful = 0;
}
}
else {
@@ -908,15 +954,14 @@ void MainWidget::onLicenseButtonClicked()
dataStr = dataStr.replace("0x", "").replace(" ", ""); // 去掉0x和空格
QByteArray dataByteArray = QByteArray::fromHex(dataStr.toUtf8());
memcpy(license_info, dataByteArray.data(), qMin(dataByteArray.size(), PIX_LICENCE_BYTES));
//qDebug() << "hardware_info:" << QByteArray(reinterpret_cast<char*>(hardware_info), PIX_HARDWARE_INFO_BYTES).toHex();
//licenseGenerate(hardware_info, license_info);
QString licenseInfoStr;
for (int j = 0; j < PIX_LICENCE_BYTES; ++j) {
licenseInfoStr.append(QString::asprintf("0x%02x, ", license_info[j]));
}
//printf("\n");
dataStr = QByteArray(reinterpret_cast<char*>(license_info), PIX_LICENCE_BYTES).toHex();
qDebug() << "license_info:" << dataStr;
dataStr = dataByteArray.toBase64();
qDebug() << "Base64 Encoded:" << dataStr;
}
#endif
for (ClientHandler* handler : clients) {
@@ -932,41 +977,6 @@ void MainWidget::onLicenseButtonClicked()
}
}
//void MainWidget::onLicenseButtonClicked()
//{
// if (connectedClientsCount) {
// QPushButton* button = qobject_cast<QPushButton*>(sender());
// if (button) {
// int index = button->property("licenseIndex").toInt();
// if (index >= 0 && index < frontBoardLicenseJson.size()) {
// QJsonObject jsonObject = frontBoardLicenseJson[index].toObject();
// //QString jsonString = QJsonDocument(jsonObject).toJson(QJsonDocument::Compact);
// //qDebug() << "license Button clicked, sending JSON:" << jsonString;
// unsigned char license_info[PIX_LICENCE_BYTES] = { 0 };
// if (jsonObject["lable"].toString() == "get_license") {
// LicenseConfirmWindow dialog("你确定要获取此授权吗?");
// if (dialog.exec() == QDialog::Accepted)
// licenseGenerate(license_info, license_info);
// }
// else {
// if (jsonObject["lable"].toString() == "write_license") {
// LicenseConfirmWindow dialog("你确定要发送此授权吗?");
// if (dialog.exec() == QDialog::Accepted)
// licenseGenerate(license_info, license_info);
// }
// for (ClientHandler* handler : clients) {
// handler->sendLicenseItem(index);
// }
// }
// }
// }
// }
// else {
// QListWidgetItem* listItem = new QListWidgetItem(QString("No device is connected !!!"), statusListWidget);
// listItem->setBackground(Qt::red);
// }
//}
void MainWidget::onUuidButtonClicked()
{
if (connectedClientsCount) {
@@ -975,17 +985,27 @@ void MainWidget::onUuidButtonClicked()
int index = button->property("UuidIndex").toInt();
if (index >= 0 && index < backBoardUuidJson.size()) {
QJsonObject jsonObject = backBoardUuidJson[index].toObject();
//QString jsonString = QJsonDocument(jsonObject).toJson(QJsonDocument::Compact);
//qDebug() << "license Button clicked, sending JSON:" << jsonString;
unsigned char license_info[PIX_LICENCE_BYTES] = { 0 };
if (jsonObject["lable"].toString() == "get_license") {
QString dataStr = "";
if (jsonObject["lable"].toString() == "get_UUID_SN") {
QString sendToHttpServerDataStr = UuidHwInfoEdit->toPlainText();
qDebug() << "sendToHttpServerDataStr:" << sendToHttpServerDataStr;
// 测试随机生成8-12位字符串
sendToHttpServerDataStr = generateRandomRequestID(8, 13);
FactoryToolSendGetUuidToHttpServer(sendToHttpServerDataStr);
while (isRequestSuccessful == 0) {
QCoreApplication::processEvents(); // 防止阻塞UI线程
}
qDebug() << "isRequestSuccessful:" << isRequestSuccessful;
if (isRequestSuccessful == 2) {
return;
}
else if (isRequestSuccessful == 1) {
}
}
else {
if (jsonObject["lable"].toString() == "write_license") {
LicenseConfirmWindow dialog("你确定要发送此授权吗?");
if (dialog.exec() == QDialog::Accepted)
licenseGenerate(license_info, license_info);
if (jsonObject["lable"].toString() == "write_UUID_SN") {
}
for (ClientHandler* handler : clients) {
handler->sendUuidItem(index, "");
@@ -1094,7 +1114,10 @@ void MainWidget::onSendGetDevInfoClicked()
}
else {
for (ClientHandler* handler : clients) {
handler->sendGetDevInfoItem(itemIndex);
if (handler->getClientId() == handler->controlClientId) {
handler->sendGetDevInfoItem(itemIndex);
break;
}
}
}
}
@@ -1125,7 +1148,7 @@ void MainWidget::onSendGetPicClicked()
}
else {
if (itemIndex - 2 >= connectedClientsCount) {
QListWidgetItem* listItem = new QListWidgetItem(QString("No device %1 is connected !!!").arg(itemIndex - 1), statusListWidget);
QListWidgetItem* listItem = new QListWidgetItem(QString("This device is not connected !!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
@@ -1136,7 +1159,10 @@ void MainWidget::onSendGetPicClicked()
lastClickedGetPicDevIndex = itemIndex;
//QMutexLocker locker(&mutex);
for (ClientHandler* handler : clients) {
handler->sendGetPicItem(itemIndex - 2, lastClickedGetPicCamIndex);
if (handler->getClientId() == handler->controlClientId) {
handler->sendGetPicItem(itemIndex - 2, lastClickedGetPicCamIndex);
break;
}
}
}
}
@@ -1169,18 +1195,24 @@ void MainWidget::onSendGetVideoClicked()
}
else {
if (itemIndex - 6 >= connectedClientsCount) {
QListWidgetItem* listItem = new QListWidgetItem(QString("No device %1 is connected !!!").arg(itemIndex - 4), statusListWidget);
QListWidgetItem* listItem = new QListWidgetItem(QString("This device is not connected !!!").arg(itemIndex - 4), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
//qDebug() << "lastClickedGetVideoDevIndex:" << lastClickedGetVideoDevIndex;
//qDebug() << "itemIndex:" << itemIndex;
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoDevIndex != -1 && lastClickedGetVideoDevIndex != itemIndex) {
getVideoButtons[lastClickedGetVideoDevIndex]->setStyleSheet("");
//qDebug() << "itemIndex:" << itemIndex;
getVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
lastClickedGetVideoDevIndex = itemIndex;
//QMutexLocker locker(&mutex);
for (ClientHandler* handler : clients) {
handler->sendGetVideoItem(itemIndex - 5, 1);
if (handler->getClientId() == handler->controlClientId) {
handler->sendGetVideoItem(itemIndex - 5, lastClickedGetVideoCamIndex);
break;
}
}
getVideoButtons[2]->setEnabled(true);
}
@@ -1220,8 +1252,11 @@ void MainWidget::onSendAllClicked()
for (ClientHandler* handler : clients) {
// 重置索引
handler->resetCurrentItemIndex();
handler->sendNextItem();
//handler->sendDevInfoItem();
if (handler->getClientId() == handler->controlClientId) {
handler->sendNextItem();
//handler->sendDevInfoItem();
break;
}
}
}
else {
@@ -1246,9 +1281,12 @@ void MainWidget::onSendFrontFuncItemClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("frontBoardFuncConfig").toInt();
for (ClientHandler* handler : clients) {
QString text = frontFuncConfigLineEdit->text();
qDebug() << "Text in frontFuncConfigLineEdit:" << text;
handler->sendFrontFuncItem(itemIndex, text);
if (handler->getClientId() == handler->controlClientId) {
QString text = frontFuncConfigLineEdit->text();
qDebug() << "Text in frontFuncConfigLineEdit:" << text;
handler->sendFrontFuncItem(itemIndex, text);
break;
}
}
}
else {
@@ -1263,9 +1301,12 @@ void MainWidget::onSendBackFuncItemClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("backBoardFuncConfig").toInt();
for (ClientHandler* handler : clients) {
QString text = backFuncConfigLineEdit->text();
qDebug() << "Text in backFuncConfigLineEdit:" << text;
handler->sendBackFuncItem(itemIndex, text);
if (handler->getClientId() == handler->controlClientId) {
QString text = backFuncConfigLineEdit->text();
qDebug() << "Text in backFuncConfigLineEdit:" << text;
handler->sendBackFuncItem(itemIndex, text);
break;
}
}
}
else {
@@ -1282,7 +1323,10 @@ void MainWidget::onSendFrontItemClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("frontBoardTest").toInt();
for (ClientHandler* handler : clients) {
handler->sendFrontItem(itemIndex);
if (handler->getClientId() == handler->controlClientId) {
handler->sendFrontItem(itemIndex);
break;
}
}
}
else {
@@ -1298,7 +1342,10 @@ void MainWidget::onSendBackItemClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("backBoardTest").toInt();
for (ClientHandler* handler : clients) {
handler->sendBackItem(itemIndex);
if (handler->getClientId() == handler->controlClientId) {
handler->sendBackItem(itemIndex);
break;
}
}
}
else {
@@ -1309,9 +1356,11 @@ void MainWidget::onSendBackItemClicked()
// 处理状态更新信号
void MainWidget::onStatusUpdated(const QString& client, int itemIndex, int FuncItemIndex,
bool success, const QString& itemData, const QString& funcItemData)
bool success, const QString& itemData, const QString& funcItemData,
const QJsonArray& jsonArray, int itemJsonIndex)
{
int clientId = -1;
QString label;
// 遍历所有的 ClientHandler找到匹配的 client
for (ClientHandler* handler : clients) {
if (handler->getClientAddress() == client) {
@@ -1327,26 +1376,44 @@ void MainWidget::onStatusUpdated(const QString& client, int itemIndex, int FuncI
}
//qDebug() << "itemIndex :" << itemIndex;
//qDebug() << "FuncItemIndex:" << FuncItemIndex;
if (itemIndex > 0) {
QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - Item %2: %3 ---> %4")
.arg(clientId)
.arg(itemIndex)
.arg(itemData) // data 字段
.arg(success ? "OK" : "NG"), statusListWidget);
//if (itemIndex > 0) {
// QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - Item %2: %3 ---> %4")
// .arg(clientId)
// .arg(itemIndex)
// .arg(itemData) // data 字段
// .arg(success ? "OK" : "NG"), statusListWidget);
listItem->setBackground(success ? Qt::green : Qt::red);
statusListWidget->addItem(listItem);
}
else if (FuncItemIndex > 0) {
QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - funcItem %2: %3 ---> %4")
.arg(clientId)
.arg(FuncItemIndex)
.arg(funcItemData) // data 字段
.arg(success ? "OK" : "NG"), statusListWidget);
// listItem->setBackground(success ? Qt::green : Qt::red);
// statusListWidget->addItem(listItem);
//}
//else if (FuncItemIndex > 0) {
// QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - funcItem %2: %3 ---> %4")
// .arg(clientId)
// .arg(FuncItemIndex)
// .arg(funcItemData) // data 字段
// .arg(success ? "OK" : "NG"), statusListWidget);
listItem->setBackground(success ? Qt::green : Qt::red);
statusListWidget->addItem(listItem);
// listItem->setBackground(success ? Qt::green : Qt::red);
// statusListWidget->addItem(listItem);
//}
qDebug() << "itemJsonIndex :" << itemJsonIndex;
if (itemJsonIndex >= 0 && itemJsonIndex < jsonArray.size()) {
QJsonObject jsonObject = jsonArray.at(itemJsonIndex).toObject();
if (jsonObject.contains("lable")) {
label = jsonObject["lable"].toString();
qDebug() << "label :" << label;
}
}
QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - Item %2: %3 ---> %4")
.arg(clientId)
.arg(itemJsonIndex + 1)
.arg(label) // data 字段
.arg(success ? "OK" : "NG"), statusListWidget);
listItem->setBackground(success ? Qt::green : Qt::red);
statusListWidget->addItem(listItem);
statusListWidget->scrollToBottom();
}
@@ -1373,6 +1440,8 @@ void MainWidget::onAllItemsProcessed(const QString& client, int itemsProcessedCo
QListWidgetItem* listItem = new QListWidgetItem(QString("device ID:-%1 ---> All %2 items test completed !!!")
.arg(clientId)
.arg(itemsProcessedCount), statusListWidget);
if(checkBoxState)
saveStatusListToFile(filePathLineEdit->text());
statusListWidget->addItem(listItem);
statusListWidget->scrollToBottom();
}

View File

@@ -53,10 +53,11 @@
#include "../Network/httpClient.h"
#include "FocusWindow.h"
// 用于测试 UDP 组播实现 mdns 功能 非标准 mdns
#define TEST_UDP_BROADCAST 0
#define TCP_CONNECT_PORT 12412
#define TEST_UDP_BROADCAST 0 // 用于测试 UDP 组播实现 mdns 功能 非标准 mdns
#define MANUAL_UPLOAD_LICENSE 0 // 打开手动上传 License的功能
#define TCP_CONNECT_PORT 12412 // TCP监听的端口
class MainWidget : public QWidget
{
@@ -96,7 +97,8 @@ private slots:
//void onDataReceived(const QString& client, const QByteArray& data);
// 处理状态更新信号
void onStatusUpdated(const QString& client, int itemIndex, int funcItemIndex,
bool success, const QString& itemData, const QString& funcItemData);
bool success, const QString& itemData, const QString& funcItemData,
const QJsonArray& jsonArray, int itemJsonIndex);
// 处理所有项目处理完毕信号
void onAllItemsProcessed(const QString& client, int itemsProcessedCount);
// 处理客户端断开连接
@@ -179,6 +181,7 @@ private:
bool manualSend; // 判断是否是手动触发的发送
bool deviceConnected = false; // 判断是否有设备连接过
bool isSendingAll; // 一键功能测试 状态
bool checkBoxState = true;
QJsonObject licenseDataArray; // 用于保存从服务器获取的 data 字段对象

View File

@@ -16,7 +16,7 @@ QGroupBox* MainWidget::createLicenseGroupBox()
//licenseHwInfoEdit->setReadOnly(true);
licenseHwInfoEdit->setReadOnly(false);
licenseHwInfoEdit->setPlaceholderText("1. 点击“get_hw_info”可以获取hw info并显示在此处\n2. 可将hw info输入此处, 点击“get_license”获取License并显示在此处\n3. 点击“write_license”可将License直接写入前板");
licenseHwInfoEdit->setPlaceholderText("1. 点击“get_hw_info”可以获取hw info并显示在此处\n2. 可将hw info输入此处, 点击“get_license”获取License并显示在此处\n3. 点击“write_license”可将License写入前板");
licenseHwInfoEdit->setFixedHeight(80);
QVBoxLayout* groupBoxLayout_license = new QVBoxLayout;
@@ -81,8 +81,9 @@ QGroupBox* MainWidget::createBackConnectServerGroupBox()
connect(button, &QPushButton::clicked, this, &MainWidget::onUuidButtonClicked);
}
UuidHwInfoEdit->setReadOnly(true);
UuidHwInfoEdit->setPlaceholderText("1. 点击“获取后板MAC地址”会将后板MAC地址显示在此处\n2. 可将后板MAC地址输入到此处点击“获取UUID”显示在此处\n");
//UuidHwInfoEdit->setReadOnly(true);
UuidHwInfoEdit->setReadOnly(false);
UuidHwInfoEdit->setPlaceholderText("1. 点击“get_MAC_addr”从后板获取MAC地址显示在此处\n2. 可将后板MAC地址输入到此处点击“get_UUID_SN”获取UUID和SN并显示在此处\n3. 点击“write_UUID_SN”可将UUID和SN写入前板");
UuidHwInfoEdit->setFixedHeight(80);
QVBoxLayout* groupBoxLayout_uuid = new QVBoxLayout;
@@ -243,14 +244,13 @@ QWidget* MainWidget::createVideoDisplayTab()
{
QWidget* videoDisplayTab = new QWidget(this);
QVBoxLayout* videoDisplayLayout = new QVBoxLayout(videoDisplayTab);
QVBoxLayout* videoButtonsColumnLayout = new QVBoxLayout;
for (int i = 0; i < 6; ++i) {
QHBoxLayout* videoButtonsRowLayout = new QHBoxLayout;
for (int j = 0; j < 2; ++j) {
QPushButton* button;
if (i == 0 && j == 0) {
button = new QPushButton(QString("IR"), this);
button = new QPushButton(QString("左边镜头"), this);
button->setFixedSize(73, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
@@ -259,7 +259,7 @@ QWidget* MainWidget::createVideoDisplayTab()
continue;
}
else if (i == 0 && j == 1) {
button = new QPushButton(QString("RGB"), this);
button = new QPushButton(QString("右边镜头"), this);
button->setFixedSize(73, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
@@ -279,8 +279,15 @@ QWidget* MainWidget::createVideoDisplayTab()
getVideoButtons.append(button);
break; // 跳出内层循环,只添加一个按键
}
button = new QPushButton(QString("Device %1").arg(i * 2 + j - 3), this);
if (i >= 2 && i <= 5) {
if(j == 0)
button = new QPushButton(QString("Device %1\n打开视频").arg(i - 1), this);
else if(j == 1)
button = new QPushButton(QString("Device %1\n关闭视频").arg(i - 1), this);
}
else {
button = new QPushButton(QString("Device %1").arg(i * 2 + (j * 1 - 1) - 3), this);
}
button->setFixedSize(73, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j + 1);
@@ -292,6 +299,7 @@ QWidget* MainWidget::createVideoDisplayTab()
QHBoxLayout* videoAndButtonsLayout = new QHBoxLayout;
videoLabel = new QLabel(this);
videoLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
videoAndButtonsLayout->addLayout(videoButtonsColumnLayout, 1);
videoAndButtonsLayout->addWidget(videoLabel, 6);
videoDisplayLayout->addLayout(videoAndButtonsLayout);