1.增加整机测试工厂信息输入; 2. 增加前后板连接后自动发送获取设备版本信息指令; 3. 优化UI布局代码

This commit is contained in:
2024-09-10 11:29:44 +08:00
parent 9a49eab4af
commit 843b2058c3
377 changed files with 197841 additions and 231069 deletions

View File

@@ -69,7 +69,12 @@
#define GET_BACK_V851_VERSION 0x0450
#define GET_BACK_806_VERSION 0x0451
#define GET_BACK_HW_VERSION 0x0452
#define GET_BACK_SN 0x0453
#define GET_BACK_UID 0x0454
#define GET_BACK_MAC 0x0470
#define WRITE_BACK_UID_SN 0x0471
#define VIDEO_TEST 0x050A
#endif

View File

@@ -2,7 +2,8 @@
#include "RecvDataHandler.h"
#include "../Network/ClientHandler.h"
DataHandler::DataHandler(QLabel* videoLabel, QLineEdit* VideoResolutionEdit, QSize labelSize, QMap<QString, QLineEdit*>* devInfoLineEdits,
DataHandler::DataHandler(QLabel* videoLabel, QLabel* video_Label_back, QLineEdit* VideoResolutionEdit, QLineEdit* VideoResolutionEdit_back,
QSize labelSize, QMap<QString, QLineEdit*>* devInfoLineEdits, int isBackBoardOrAllBoard,
QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest, QJsonArray frontBoardFuncConfig,
QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson,
QJsonArray backBoardOneClickTest, QJsonArray backBoardTest, QJsonArray backBoardFuncConfig,
@@ -10,9 +11,12 @@ DataHandler::DataHandler(QLabel* videoLabel, QLineEdit* VideoResolutionEdit, QSi
QJsonArray getPicJson, QJsonArray getVideoJson, QObject* parent)
: QObject(parent),
videoLabel(videoLabel),
video_Label_back(video_Label_back),
VideoResolutionEdit(VideoResolutionEdit),
VideoResolutionEdit_back(VideoResolutionEdit_back),
labelSize(labelSize),
devInfoLineEdits(devInfoLineEdits),
isBackBoardOrAllBoard(isBackBoardOrAllBoard),
frontBoardOneClickTest(frontBoardOneClickTest), frontBoardTest(frontBoardTest),
frontBoardFuncConfig(frontBoardFuncConfig), frontBoardDevInfoJson(frontBoardDevInfoJson),
frontBoardLicenseJson(frontBoardLicenseJson),
@@ -22,7 +26,7 @@ DataHandler::DataHandler(QLabel* videoLabel, QLineEdit* VideoResolutionEdit, QSi
buffer(new QByteArray()), picBuffer(new QByteArray()),
ffmpegDecoder(new FFmpegDecoder()) // 初始化FFmpeg解码器
{
ffmpegDecoder->initialize(); // 初始化解码器
//ffmpegDecoder->initialize(); // 初始化解码器
clearAllRecvData();
initializeMsgIdToCmdMap();
qDebug() << "DataHandler thread created";
@@ -81,8 +85,9 @@ void DataHandler::showVideo(const QString& client, const QByteArray& valData)
}
if (!start_run) {
ffmpegDecoder->initialize(); // 初始化解码器
start_run = 1;
ffmpegDecoder->decodeFile(h264filePath, videoLabel, VideoResolutionEdit);
ffmpegDecoder->decodeFile(h264filePath, isBackBoardOrAllBoard, videoLabel, video_Label_back, VideoResolutionEdit, VideoResolutionEdit_back);
}
//ffmpegDecoder->decodeFile(filePath_1, videoLabel);
}
@@ -150,26 +155,23 @@ void DataHandler::handleData(const QString& client, const QByteArray& recv
/*for (int i = 0; i < 19; i++) {
qDebug() << "buffer->at(" << i << "):" << QString::number(static_cast<unsigned char>(buffer->at(i)), 16).toUpper();
}*/
// 去掉前面 11 字节
QByteArray data = buffer->mid(11, dataSize);
//QByteArray data = buffer->mid(10, dataSize);
QString hexString = QString::fromUtf8(data.toHex().data());
QString hexString = QString::fromUtf8(data.toHex().data());
QByteArray actual_data = hexStringToByteArray(hexString);
buffer->remove(0, totalSize); // 移除已处理的数据
if(msg_id != 0x0040 && msg_id != START_VIDEO && msg_id != GET_IMG) {
buffer->remove(0, totalSize); // 移除已处理的数据
if(msg_id != 0x0040 && msg_id != START_VIDEO && msg_id != GET_IMG && msg_id != VIDEO_TEST &&
msg_id != STOP_VIDEO) {
qDebug() << "--- msg_id:" << msg_id;
qDebug() << "--- clientLastMsgId.value(client, 0):" << clientLastMsgId.value(client, 0);
// 同一个client仅当 msg_id 不连续为 0x11/0x21 或第一次处理时才执行 emit statusUpdated
if ((msg_id != 0x0011 || clientLastMsgId.value(client, 0) != 0x0011) &&
(msg_id != 0x0021 || clientLastMsgId.value(client, 0) != 0x0021) &&
(msg_id != START_VIDEO || clientLastMsgId.value(client, 0) != START_VIDEO)) {
//qDebug() << "Emitting statusUpdated for client:" << client << "with msg_id:" << QString::number(msg_id, 16).toUpper();
emit statusUpdated(client, currentRecvItemIndex + 1, currentRecvFuncItemIndex + 1,
true, itemData, funcItemData, jsonArray, itemJsonIndex);
emit statusUpdated(client, true, jsonArray, itemJsonIndex);
}
clientLastMsgId[client] = msg_id;
}
handleCmd(msg_id, client, actual_data);
handleCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex);
}
else {
break; // 数据还不完整,等待下一次接收
@@ -191,80 +193,56 @@ void DataHandler::initializeMsgIdToCmdMap() {
msgIdToCmdMap[GET_BACK_V851_VERSION] = "GET_BACK_V851_VERSION";
msgIdToCmdMap[GET_BACK_806_VERSION] = "GET_BACK_806_VERSION";
msgIdToCmdMap[GET_BACK_HW_VERSION] = "GET_BACK_HW_VERSION";
msgIdToCmdMap[GET_BACK_SN] = "GET_BACK_SN";
msgIdToCmdMap[GET_BACK_UID] = "GET_BACK_UID";
}
void DataHandler::handleCmd(int msg_id, const QString& client, QByteArray actual_data)
void DataHandler::handleCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex)
{
if (msg_id < 0x0400) {
handleFrontCmd(msg_id, client, actual_data);
handleFrontCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex);
}
else if (msg_id < 0x0500) {
handleDevInfo(msg_id, client, actual_data);
}
else if (msg_id < 0x0800) {
handleBackCmd(msg_id, client, actual_data);
handleBackCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex);
}
}
void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data)
void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex)
{
switch (msg_id) {
case FACE_ENROLL_SINGLE:
{
}
{}
break;
case FACE_ENROLL:
{
}
{}
break;
case HAND_ENROLL:
{
}
{}
break;
case FACE_VERIFY:
{
}
{}
break;
case HAND_VERIFY:
{
}
{}
break;
case DEL_USER:
{
}
{}
break;
case DEL_ALLUSER:
{
}
{}
break;
case GET_USER:
{
}
{}
break;
case GET_ALLUSER:
{
}
{}
break;
case PASSWD_ENROLL:
{
}
{}
break;
case IMG_ENROLL:
{
}
{}
break;
case GET_IMG:
{
@@ -272,14 +250,16 @@ void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray a
int width = (static_cast<unsigned char>(actual_data[3]) << 8) | static_cast<unsigned char>(actual_data[2]);
int height = (static_cast<unsigned char>(actual_data[5]) << 8) | static_cast<unsigned char>(actual_data[4]);
int format = static_cast<unsigned char>(actual_data[6]);
qint32 picSize = width * height * 1.5;
qint32 picSize = width * height * 1.5;
QByteArray yuvData = actual_data.mid(7);
qDebug() << "showPic width * height * 1.5:" << picSize;
qDebug() << "showPic picBuffer.size():" << picBuffer->size();
if (yuvData.size() + picBuffer->size() == picSize) {
emit picRecvFinished();
picBuffer->append(yuvData);
showPic(labelSize, lens_n, width, height, format, picBuffer);
QJsonObject currentTempItem = jsonArray[itemJsonIndex].toObject();
emit statusUpdated(client, true, jsonArray, itemJsonIndex);
picBuffer->remove(0, picSize);
}
else if (yuvData.size() + picBuffer->size() > picSize) {
@@ -295,173 +275,130 @@ void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray a
break;
case START_VIDEO:
{
if (!isStartVideo) {
isStartVideo = ffmpegDecoder->isStartVideo;
if (isStartVideo) {
emit statusUpdated(client, true, getVideoJson, 0);
}
}
showVideo(client, actual_data);
}
break;
case STOP_VIDEO:
{
isStartVideo = false;
emit statusUpdated(client, true, jsonArray, itemJsonIndex);
qDebug() << "--- STOP_VIDEO Current path: " << QDir::currentPath();
QString filePath = QDir::currentPath() + "/add1.h264";
if (QFile::exists(filePath)) {
QFile file(filePath);
if (file.open(QIODevice::WriteOnly | QIODevice::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.";
}
}
break;
case TOUCH_TEST:
{
}
{}
break;
case MIC_TEST:
{
}
{}
break;
case SPK_TEST:
{
}
{}
break;
case RADAR_TEST:
{
}
{}
break;
case NFC_TEST:
{
}
{}
break;
case PR_SWITCH:
{
}
{}
break;
case PS_TEST:
{
}
{}
break;
case BACKLIGHT:
{
}
{}
break;
case IR_LED:
{
}
{}
break;
case UART_TEST:
{
}
{}
break;
case PIR_TEST:
{
}
{}
break;
case FACE_VERIFY_THRES:
{
}
{}
break;
case FACE_THRES_LEVEL:
{
}
{}
break;
case FACE_LIVE_THRES:
{
}
{}
break;
case FACE_ACC_THRES:
{
}
{}
break;
case FACE_ACC_LEVEL:
{
}
{}
break;
case FACE_DIS_RANGE:
{
}
{}
break;
case FACE_ANGLE_RANGE:
{
}
{}
break;
case HAND_VERIFY_THRES:
{
}
{}
break;
case HANS_THRES_LEVEL:
{
}
{}
break;
case HAND_LIVE_THRES:
{
}
{}
break;
case USER_MAX_NUM:
{
}
{}
break;
case ADMI_USER_MAX_NUM:
{
}
{}
break;
case FACE_REPEAT:
{
}
{}
break;
case HAND_REPEAT:
{
}
{}
break;
case SET_IP:
{
}
{}
break;
case SET_PORT:
{
}
{}
break;
case SET_VOLUME:
{
}
{}
break;
case SET_BACKLIGHT:
{
}
{}
break;
case SET_RADAR_DIS:
{
}
{}
break;
case SET_UART_BARTRATE:
{
}
{}
break;
case SET_LOG_LEVEL:
{
}
{}
break;
default:
{}
@@ -471,6 +408,8 @@ void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray a
void DataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray actual_data)
{
qDebug() << "actual_data.size(): " << actual_data.size();
qDebug() << "actual_data: " << QString::fromUtf8(actual_data.toHex().data());
switch (msg_id) {
case GET_FRONT_V851_VERSION:
case GET_FRONT_MCU_VERSION:
@@ -481,8 +420,8 @@ void DataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray ac
case GET_BACK_V851_VERSION:
case GET_BACK_806_VERSION:
case GET_BACK_HW_VERSION:
case GET_BACK_SN:
case GET_BACK_UID:
/*case GET_BACK_SN:
case GET_BACK_UID:*/
{
// aa55aa5503041d00000048464d3231305f4b3431343234395f423230323031305f41302e302e38
qDebug() << "GET_DEV_INFO";
@@ -502,8 +441,6 @@ void DataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray ac
qDebug() << "GET_FRONT_HW_INFO";
QStringList hexList;
QString dataStr;
qDebug() << "actual_data.size(): " << actual_data.size();
qDebug() << "actual_data: " << QString::fromUtf8(actual_data.toHex().data());
if (actual_data.size() == PIX_HARDWARE_INFO_BYTES) {
for (int i = 0; i < actual_data.size(); ++i) {
hexList << QString("0x%1").arg(static_cast<unsigned char>(actual_data[i]), 2, 16, QLatin1Char('0')).toUpper().replace("0X", "0x");
@@ -511,15 +448,26 @@ void DataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray ac
dataStr = hexList.join(", ");
}
else
dataStr = "前板发送的HW INFO 数据大小不正确";
dataStr = "前板发送的 HW INFO 数据大小不正确";
QString displayText = dataStr;
//licenseHwInfoEdit->setPlainText(displayText);
emit updateLicenseHwInfoEdit(displayText);
}
break;
case WRITE_FRONT_LICENSE:
case GET_BACK_MAC:
{
qDebug() << "WRITE_FRONT_LICENSE";
qDebug() << "GET_BACK_MAC";
QString dataStr;
if (actual_data.size() == BACK_MAC_ADDRESS_LEN) {
for (int i = 0; i < actual_data.size(); ++i) {
char ch = static_cast<unsigned char>(actual_data[i]);
dataStr.append(ch);
}
}
else
dataStr = "后板发送的 MAC addr 数据大小不正确";
QString displayText = dataStr;
emit updateUuidHwInfoEdit(displayText);
}
break;
default:
@@ -527,9 +475,51 @@ void DataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray ac
}
}
void DataHandler::handleBackCmd(int msg_id, const QString& client, QByteArray actual_data)
void DataHandler::handleBackCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex)
{
switch (msg_id) {
case VIDEO_TEST:
{
if (!isStartVideo) {
isStartVideo = ffmpegDecoder->isStartVideo;
if (isStartVideo) {
emit statusUpdated(client, true, jsonArray, itemJsonIndex);
}
}
QJsonObject jsonObject = jsonArray[itemJsonIndex].toObject();
if (jsonObject["val"] == 0) {
showVideo(client, actual_data);
}
else if (jsonObject["val"] == 1) {
isStartVideo = false;
emit statusUpdated(client, true, jsonArray, itemJsonIndex);
qDebug() << "--- STOP_VIDEO";
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)) {
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 (ffmpegDecoder) {
ffmpegDecoder->stopFFmpegDecoder();
ffmpegDecoder->requestInterruption();
ffmpegDecoder->wait(); // 等待解码器线程完成
delete ffmpegDecoder;
ffmpegDecoder = nullptr;
}
}
}
break;
default:
{}
break;
}
}

View File

@@ -28,12 +28,15 @@
#define YUV420 1
#define YUV422 2
#define BACK_MAC_ADDRESS_LEN 11
class DataHandler : public QObject
{
Q_OBJECT
public:
explicit DataHandler(QLabel* videoLabel, QLineEdit* VideoResolutionEdit, QSize labelSize, QMap<QString, QLineEdit*>* devInfoLineEdits,
explicit DataHandler(QLabel* videoLabel, QLabel* video_Label_back, QLineEdit* VideoResolutionEdit, QLineEdit* VideoResolutionEdit_back,
QSize labelSize, QMap<QString, QLineEdit*>* devInfoLineEdits, int isBackBoardOrAllBoard,
QJsonArray frontBoardOneClickTest, QJsonArray frontBoardTest, QJsonArray frontBoardFuncConfig,
QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson,
QJsonArray backBoardOneClickTest, QJsonArray backBoardTest, QJsonArray backBoardFuncConfig,
@@ -46,14 +49,14 @@ public slots:
int currentRecvFuncItemIndex, const QString& itemData, const QString& funcItemData,
const QJsonArray& jsonArray, int itemJsonIndex);
signals:
void statusUpdated(const QString& clientAddress, int currentItemIndex, int currentFuncItemIndex,
bool success, const QString& currentItemLabel, const QString& currentFuncItemLabel,
const QJsonArray& jsonArray, int itemJsonIndex);
void statusUpdated(const QString& clientAddress, bool success, const QJsonArray& jsonArray, int itemJsonIndex);
void updateLicenseHwInfoEdit(const QString& text);
void updateUuidHwInfoEdit(const QString& text);
void updateLeftLensImage(const QPixmap& pixmap);
void updateRightLensImage(const QPixmap& pixmap);
void updateVideoLabel(const QPixmap& pixmap);
void updateVideoResolution(const QString& resolutionText);
void picRecvFinished();
private:
QJsonArray frontBoardOneClickTest; // 前板一键功能测试 JSON
QJsonArray frontBoardTest; // 前板单项测试 JSON
@@ -71,12 +74,15 @@ private:
//QLabel* leftLens_m_imageLabel;
//QLabel* rightLens_m_imageLabel;
QLabel* videoLabel;
QLineEdit* VideoResolutionEdit;
QLabel* video_Label_back;
QLineEdit* VideoResolutionEdit;
QLineEdit* VideoResolutionEdit_back;
//QTextEdit* licenseHwInfoEdit;
QByteArray allRecvData; // 完整的一帧数据
int remain = 0;
int start_run = 0;
long dataLen = 0;
int isBackBoardOrAllBoard = 0;
FFmpegDecoder* ffmpegDecoder;
QByteArray* buffer;
QByteArray* picBuffer;
@@ -84,15 +90,16 @@ private:
QMap<QString, QLineEdit*>* devInfoLineEdits;
QMap<int, QString> msgIdToCmdMap;
QSize labelSize;
bool isStartVideo = false;
// 如果接收十六进制数据,转为二进制
QByteArray hexStringToByteArray(const QString& hexString);
void showVideo(const QString& client, const QByteArray& valData);
void clearAllRecvData();
void handleCmd(int msg_id, const QString& client, QByteArray actual_data);
void handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data);
void handleCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex);
void handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex);
void handleDevInfo(int msg_id, const QString& client, QByteArray actual_data);
void handleBackCmd(int msg_id, const QString& client, QByteArray actual_data);
void handleBackCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex);
void initializeMsgIdToCmdMap();
void updateLineEdit(int msg_id, const QByteArray& actual_data);
void showPic(QSize labelSize, int lens_n,