新增产测与服务器的HTTP连接及交互功能

This commit is contained in:
2024-08-26 18:33:55 +08:00
parent 0a5b0db9a5
commit 07ab6b9608
24 changed files with 2825 additions and 1654 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,9 @@
#include <QTabWidget>
#include <QTimer>
#include <QGroupBox>
#include <QFormLayout>
#include <QLabel>
#include <QStackedLayout>
#include <QJsonDocument>
#include <QFile>
#include <QDebug>
@@ -29,6 +31,18 @@
#include <QTextStream>
#include <QScrollArea>
#include <QDateTime>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include <QMap>
#include <QList>
#include <QPair>
#include <QTextCodec>
#include <QCryptographicHash>
#include <QRandomGenerator>
#include <QMessageAuthenticationCode>
#include <QCoreApplication>
#include "../Json/readJsonFile.h"
#include "../RecvDataHandler/RecvDataHandler.h"
@@ -36,6 +50,7 @@
#include "../LicenseGenerate/LicenseConfirmWindow.h"
#include "../Network/mdns/servicemodel.h"
#include "../Network/ClientHandler.h"
#include "../Network/httpClient.h"
#include "FocusWindow.h"
// 用于测试 UDP 组播实现 mdns 功能 非标准 mdns
@@ -53,6 +68,12 @@ public:
~MainWidget();
private slots:
// 发送HTTP请求
//void onSomeButtonClicked();
// 处理HTTP响应
void onHttpRequestFinished(const QJsonObject& response);
// 处理HTTP错误
void onHttpRequestError(const QString& errorString);
// 处理开始服务器按钮点击事件
void onStartServerClicked();
// 处理发送获取设备信息按键点击事件
@@ -62,12 +83,15 @@ private slots:
// 处理发送拉视频流按键点击事件
void onSendGetVideoClicked();
void onLicenseButtonClicked();
void onUuidButtonClicked();
// 处理一键发送按钮点击事件
void onSendAllClicked();
// 处理单独发送项按钮点击事件
void onSendItemClicked();
void onSendFrontItemClicked();
void onSendBackItemClicked();
// 处理单独发送功能配置项按钮点击事件
void onSendFuncItemClicked();
void onSendFrontFuncItemClicked();
void onSendBackFuncItemClicked();
// 处理数据接收信号
//void onDataReceived(const QString& client, const QByteArray& data);
// 处理状态更新信号
@@ -103,16 +127,30 @@ private:
void readJsonConfig();
// 设置 UI
void setupUI();
QGroupBox* createLicenseGroupBox();
QGroupBox* createFrontDeviceInfoGroupBox();
QGroupBox* createBackDeviceInfoGroupBox();
QWidget* createFunctionTestTab(const QJsonArray& BoardFuncTest, const QString& propertyName);
QWidget* createFunctionConfigTab(const QJsonArray& BoardFuncConfig, const QString& propertyName);
QWidget* createImageDisplayTab();
QWidget* createVideoDisplayTab();
QGroupBox* createBackConnectServerGroupBox();
// 保存日志到文件
void saveStatusListToFile(const QString& filePath);
// 用于更新按键文本的函数
void updateServerButtonText();
void onDisconnectClient(int clientId);
void setupTimerForThreadPoolInfo();
bool isSendingAll; // 一键功能测试 状态
QTcpServer* server; // TCP 服务器
//QUdpSocket* udpSocket;
void sendDataToClient(int clientId, const QByteArray& data);
//void FactoryToolSendPostFactoryInfotoHttpServer();
void FactoryToolSendPostTestToHttpServer();
void FactoryToolSendPostLicenseToHttpServer(const QString& hardware_info, const QString& license_info);
void FactoryToolSendPostComfirmToHttpServer(const QString& mac_addr, const QString& uuid);
void FactoryToolSendGetUuidToHttpServer(const QString& mac_addr);
void FactoryToolSendGetLicenseToHttpServer(const QString& hw_info);
QTcpServer* server; // TCP 服务器
HttpClient* httpClient; // HTTP 服务器
QJsonArray frontBoardOneClickTest; // 前板一键功能测试 JSON
QJsonArray frontBoardTest; // 前板单项测试 JSON
QJsonArray frontBoardFuncConfig; // 前板功能配置参数 JSON
@@ -122,6 +160,7 @@ private:
QJsonArray backBoardTest; // 后板单项测试 JSON
QJsonArray backBoardFuncConfig; // 后板功能配置参数 JSON
QJsonArray backBoardDevInfoJson; // 后板设备信息参数 JSON
QJsonArray backBoardUuidJson; // 后板UUID JSON
QJsonArray testJsonConfig; // 功能测试区 JSON 配置
QJsonArray funcJsonConfig; // 功能配置区 JSON 配置
QJsonArray getDevInfoJson; // 获取设备信息 JSON 配置
@@ -136,8 +175,12 @@ private:
QMutex mutex; // 互斥锁
int nextClientId; // 新增的客户端编号
int connectedClientsCount = 0; // 连接客户端的数量
int isRequestSuccessful = 0; // GET请求是否成功
bool manualSend; // 判断是否是手动触发的发送
bool deviceConnected = false; // 判断是否有设备连接过
bool isSendingAll; // 一键功能测试 状态
QJsonObject licenseDataArray; // 用于保存从服务器获取的 data 字段对象
QVector<QPushButton*> itemButtons; // 项目按键集合
QVector<QPushButton*> funcItemButtons; // 功能配置项目按键集合
@@ -154,8 +197,10 @@ private:
QLabel* leftLens_imageLabel; // 左边镜头图像显示
QLabel* rightLens_imageLabel; // 右边镜头图像显示
QLabel* videoLabel; // 视频显示
QLineEdit* funcConfigLineEdit; // 功能配置编辑框
QLineEdit* frontFuncConfigLineEdit; // 前板功能配置编辑框
QLineEdit* backFuncConfigLineEdit; // 后板功能配置编辑框
QTextEdit* licenseHwInfoEdit; // 获取license的硬件信息
QTextEdit* UuidHwInfoEdit; // Uuid的硬件信息
MainWidget* mainWidget;
QTabWidget* tabWidget; // 标签页
QWidget* functionTestArea; // 功能测试区

View File

@@ -0,0 +1,302 @@
#include "../MainWidget.h"
QGroupBox* MainWidget::createLicenseGroupBox()
{
QGroupBox* groupBox = new QGroupBox("算法 license", this);
QHBoxLayout* buttonRowLayout = new QHBoxLayout;
for (int i = 0; i < frontBoardLicenseJson.size(); ++i) {
QJsonObject item = frontBoardLicenseJson[i].toObject();
QString buttonText = item["lable"].toString();
QPushButton* button = new QPushButton(buttonText, this);
button->setProperty("licenseIndex", i);
buttonRowLayout->addWidget(button);
connect(button, &QPushButton::clicked, this, &MainWidget::onLicenseButtonClicked);
}
//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->setFixedHeight(80);
QVBoxLayout* groupBoxLayout_license = new QVBoxLayout;
groupBoxLayout_license->addLayout(buttonRowLayout);
groupBoxLayout_license->addWidget(licenseHwInfoEdit);
groupBox->setLayout(groupBoxLayout_license);
return groupBox;
}
QGroupBox* MainWidget::createFrontDeviceInfoGroupBox()
{
QGroupBox* frontDeviceInfoGroupBox = new QGroupBox("前板设备信息", this);
QFormLayout* formLayout = new QFormLayout(frontDeviceInfoGroupBox);
for (const QJsonValue& value : frontBoardDevInfoJson) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QString cmd = item["cmd"].toString();
QLabel* itemLabel = new QLabel(label, this);
QLineEdit* itemLineEdit = new QLineEdit(this);
itemLineEdit->setReadOnly(true);
formLayout->addRow(itemLabel, itemLineEdit);
devInfoLineEdits[cmd] = itemLineEdit;
}
return frontDeviceInfoGroupBox;
}
QGroupBox* MainWidget::createBackDeviceInfoGroupBox()
{
QGroupBox* backDeviceInfoGroupBox = new QGroupBox("后板设备信息", this);
QFormLayout* formLayout = new QFormLayout(backDeviceInfoGroupBox);
for (const QJsonValue& value : backBoardDevInfoJson) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QString cmd = item["cmd"].toString();
QLabel* itemLabel = new QLabel(label, this);
QLineEdit* itemLineEdit = new QLineEdit(this);
itemLineEdit->setReadOnly(true);
formLayout->addRow(itemLabel, itemLineEdit);
devInfoLineEdits[cmd] = itemLineEdit;
}
return backDeviceInfoGroupBox;
}
QGroupBox* MainWidget::createBackConnectServerGroupBox()
{
QGroupBox* BackConnectServerGroupBox = new QGroupBox("后板获取UUID", this);
QHBoxLayout* frontDeviceInfoLayout = new QHBoxLayout;
for (int i = 0; i < backBoardUuidJson.size(); ++i) {
QJsonObject item = backBoardUuidJson[i].toObject();
QString buttonText = item["lable"].toString();
QPushButton* button = new QPushButton(buttonText, this);
button->setProperty("UuidIndex", i);
frontDeviceInfoLayout->addWidget(button);
connect(button, &QPushButton::clicked, this, &MainWidget::onUuidButtonClicked);
}
UuidHwInfoEdit->setReadOnly(true);
UuidHwInfoEdit->setPlaceholderText("1. 点击“获取后板MAC地址”会将后板MAC地址显示在此处\n2. 可将后板MAC地址输入到此处点击“获取UUID”显示在此处\n");
UuidHwInfoEdit->setFixedHeight(80);
QVBoxLayout* groupBoxLayout_uuid = new QVBoxLayout;
groupBoxLayout_uuid->addLayout(frontDeviceInfoLayout);
groupBoxLayout_uuid->addWidget(UuidHwInfoEdit);
BackConnectServerGroupBox->setLayout(groupBoxLayout_uuid);
return BackConnectServerGroupBox;
}
QWidget* MainWidget::createFunctionTestTab(const QJsonArray& BoardFuncTest, const QString& propertyName)
{
QWidget* functionTestTab = new QWidget(this);
QVBoxLayout* functionTestLayout = new QVBoxLayout(functionTestTab);
QGridLayout* buttonGridLayout = new QGridLayout();
int buttonsPerRow = 7;
for (int i = 0; i < BoardFuncTest.size() + (77 - BoardFuncTest.size()); ++i) {
QJsonObject item = BoardFuncTest[i].toObject();
QString buttonText = item["lable"].toString();
if (buttonText.isEmpty()) {
buttonText = QString("Send Item %1").arg(i + 1);
}
QPushButton* button = new QPushButton(buttonText, this);
button->setProperty(propertyName.toUtf8().constData(), i);
button->setFixedSize(110, 35);
if (propertyName == "frontBoardTest") {
connect(button, &QPushButton::clicked, this, &MainWidget::onSendFrontItemClicked);
}
else if (propertyName == "backBoardTest") {
connect(button, &QPushButton::clicked, this, &MainWidget::onSendBackItemClicked);
}
int row = i / buttonsPerRow;
int col = i % buttonsPerRow;
buttonGridLayout->addWidget(button, row, col, Qt::AlignLeft);
itemButtons.append(button);
}
QWidget* buttonContainer = new QWidget;
buttonContainer->setLayout(buttonGridLayout);
QScrollArea* scrollArea = new QScrollArea;
scrollArea->setWidget(buttonContainer);
scrollArea->setWidgetResizable(true);
functionTestLayout->addWidget(scrollArea);
return functionTestTab;
}
QWidget* MainWidget::createFunctionConfigTab(const QJsonArray& BoardFuncConfig, const QString& propertyName)
{
QWidget* functionConfigTab = new QWidget(this);
QVBoxLayout* functionConfigLayout = new QVBoxLayout(functionConfigTab);
if (propertyName == "frontBoardFuncConfig") {
frontFuncConfigLineEdit->setPlaceholderText("请输入配置参数...");
functionConfigLayout->addWidget(frontFuncConfigLineEdit);
}
else if (propertyName == "backBoardFuncConfig") {
backFuncConfigLineEdit->setPlaceholderText("请输入配置参数...");
functionConfigLayout->addWidget(backFuncConfigLineEdit);
}
QGridLayout* configButtonGridLayout = new QGridLayout();
int buttonsPerRow = 7; // 每行显示的按键数量,根据需要调整
for (int i = 0; i < BoardFuncConfig.size() + (77 - BoardFuncConfig.size()); ++i) {
QJsonObject item = BoardFuncConfig[i].toObject();
QString buttonText = item["lable"].toString();
if (buttonText.isEmpty()) {
buttonText = QString("Cfg Item %1").arg(i + 1);
}
QPushButton* button = new QPushButton(buttonText, this);
button->setProperty(propertyName.toUtf8().constData(), i);
button->setFixedSize(110, 35);
if (propertyName == "frontBoardFuncConfig") {
connect(button, &QPushButton::clicked, this, &MainWidget::onSendFrontFuncItemClicked);
}
else if (propertyName == "backBoardFuncConfig") {
connect(button, &QPushButton::clicked, this, &MainWidget::onSendBackFuncItemClicked);
}
int row = i / buttonsPerRow;
int col = i % buttonsPerRow;
configButtonGridLayout->addWidget(button, row, col, Qt::AlignLeft);
funcItemButtons.append(button);
}
QWidget* configButtonContainer = new QWidget;
configButtonContainer->setLayout(configButtonGridLayout);
QScrollArea* configScrollArea = new QScrollArea;
configScrollArea->setWidget(configButtonContainer);
configScrollArea->setWidgetResizable(true);
functionConfigLayout->addWidget(configScrollArea);
return functionConfigTab;
}
QWidget* MainWidget::createImageDisplayTab()
{
QWidget* imageDisplayTab = new QWidget(this);
QVBoxLayout* imageDisplayLayout = new QVBoxLayout(imageDisplayTab);
QVBoxLayout* imageButtonsColumnLayout = new QVBoxLayout;
for (int i = 0; i < 5; ++i) {
QHBoxLayout* imageButtonsRowLayout = new QHBoxLayout;
for (int j = 0; j < 2; ++j) {
QPushButton* button;
if (i == 0 && j == 0) {
button = new QPushButton(QString("IR"), this);
button->setFixedSize(73, 50);
imageButtonsRowLayout->addWidget(button);
button->setProperty("getPicIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetPicClicked);
getPicButtons.append(button);
continue;
}
else if (i == 0 && j == 1) {
button = new QPushButton(QString("RGB"), this);
button->setFixedSize(73, 50);
imageButtonsRowLayout->addWidget(button);
button->setProperty("getPicIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetPicClicked);
getPicButtons.append(button);
continue;
}
button = new QPushButton(QString("Device %1").arg(i * 2 + j - 1), this);
button->setFixedSize(73, 50);
imageButtonsRowLayout->addWidget(button);
button->setProperty("getPicIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetPicClicked);
getPicButtons.append(button);
}
imageButtonsColumnLayout->addLayout(imageButtonsRowLayout);
}
QHBoxLayout* lensesLayout = new QHBoxLayout;
leftLens_imageLabel = new QLabel(this);
rightLens_imageLabel = new QLabel(this);
lensesLayout->addWidget(leftLens_imageLabel);
lensesLayout->addWidget(rightLens_imageLabel);
QHBoxLayout* imageAndButtonsLayout = new QHBoxLayout;
imageAndButtonsLayout->addLayout(imageButtonsColumnLayout, 1);
imageAndButtonsLayout->addLayout(lensesLayout, 4);
imageDisplayLayout->addLayout(imageAndButtonsLayout);
return imageDisplayTab;
}
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->setFixedSize(73, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
continue;
}
else if (i == 0 && j == 1) {
button = new QPushButton(QString("RGB"), this);
button->setFixedSize(73, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
continue;
}
// 调价调焦窗口按键
if (i == 1 && j == 0) {
button = new QPushButton(QString("大窗口播放视频"), this);
button->setFixedSize(150, 50);
button->setEnabled(false);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onOpenFocusWindowClicked);
getVideoButtons.append(button);
break; // 跳出内层循环,只添加一个按键
}
button = new QPushButton(QString("Device %1").arg(i * 2 + j - 3), this);
button->setFixedSize(73, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j + 1);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
}
videoButtonsColumnLayout->addLayout(videoButtonsRowLayout);
}
QHBoxLayout* videoAndButtonsLayout = new QHBoxLayout;
videoLabel = new QLabel(this);
videoAndButtonsLayout->addLayout(videoButtonsColumnLayout, 1);
videoAndButtonsLayout->addWidget(videoLabel, 6);
videoDisplayLayout->addLayout(videoAndButtonsLayout);
return videoDisplayTab;
}