zhongfuqiang上传最新代码20250325
This commit is contained in:
@@ -145,7 +145,7 @@ void DataHandler::handleData(const QString& client, const QByteArray& recv
|
||||
(static_cast<unsigned char>(buffer->at(7)) << 8) |
|
||||
(static_cast<unsigned char>(buffer->at(6)));
|
||||
//qDebug() << "---Received dataSize:" << dataSize;
|
||||
//qDebug() << "---Received buffer->size():" << buffer->size();
|
||||
qDebug() << "---Received buffer->size():" << buffer->size();
|
||||
//qDebug() << "---msg_id:" << QString::number(msg_id, 16).toUpper();
|
||||
// 第11字节为返回 OK/NG
|
||||
bool success = (static_cast<unsigned char>(buffer->at(10)) != 0x00);
|
||||
@@ -159,6 +159,7 @@ void DataHandler::handleData(const QString& client, const QByteArray& recv
|
||||
break;
|
||||
}
|
||||
}
|
||||
qDebug() << "---Received totalSize:" << totalSize;
|
||||
if (buffer->size() >= totalSize) {
|
||||
// 调试查看收到的前19个字节
|
||||
/*for (int i = 0; i < 19; i++) {
|
||||
|
||||
@@ -142,7 +142,6 @@ void SerialDataHandler::handleData(const QString& client, const QByteArray
|
||||
qDebug() << "read file data size:" << recvdata.size();
|
||||
#endif
|
||||
qDebug() << "---Received data size:" << recvData.size();
|
||||
// 将接收到的数据追加到buffer
|
||||
buffer->append(recvData);
|
||||
while (buffer->size() >= 11) { // 至少需要11个字节来解析数据头
|
||||
|
||||
@@ -156,6 +155,7 @@ void SerialDataHandler::handleData(const QString& client, const QByteArray
|
||||
emit sendHeartBeatData(payload, heartBeat);
|
||||
buffer->remove(0, 11); // 移除已处理的数据
|
||||
//buffer->remove(0, recvData.size()); // 移除已处理的数据
|
||||
// 这里开始发送获取设备信息
|
||||
emit statusUpdated(-2, client, true, jsonArray, itemJsonIndex);
|
||||
//break;
|
||||
continue;
|
||||
@@ -184,7 +184,7 @@ void SerialDataHandler::handleData(const QString& client, const QByteArray
|
||||
(static_cast<unsigned char>(buffer->at(7)) << 8) |
|
||||
(static_cast<unsigned char>(buffer->at(6)));
|
||||
qDebug() << "---Received dataSize:" << dataSize;
|
||||
//qDebug() << "---Received buffer->size():" << buffer->size();
|
||||
qDebug() << "---Received buffer->size():" << buffer->size();
|
||||
//qDebug() << "---msg_id:" << QString::number(msg_id, 16).toUpper();
|
||||
// 第11字节为返回 OK/NG
|
||||
bool success = (static_cast<unsigned char>(buffer->at(10)) != 0x00);
|
||||
@@ -207,26 +207,34 @@ void SerialDataHandler::handleData(const QString& client, const QByteArray
|
||||
QByteArray data = buffer->mid(11, dataSize);
|
||||
QString hexString = QString::fromUtf8(data.toHex().data());
|
||||
QByteArray actual_data = hexStringToByteArray(hexString);
|
||||
buffer->remove(0, totalSize); // 移除已处理的数据
|
||||
qDebug() << "-------------------------------------------- isTimeout:" << isTimeout;
|
||||
//buffer->remove(0, totalSize); // 移除已处理的数据
|
||||
buffer->remove(0, buffer->size()); // 移除已处理的数据
|
||||
if (msg_id < 0x0200) // 忽略小于产测指令的大小
|
||||
{
|
||||
qDebug() << "--- msg_id:" << msg_id << " < 0x0200 to give up";
|
||||
break;
|
||||
}
|
||||
if (!isTimeout)
|
||||
{
|
||||
if (msg_id != 0x0040 && msg_id != START_VIDEO && msg_id != GET_IMG && msg_id != VIDEO_TEST &&
|
||||
msg_id != STOP_VIDEO) {
|
||||
msg_id != STOP_VIDEO && msg_id != FACE_ENROLL_SINGLE && msg_id != FACE_ENROLL && msg_id != HAND_ENROLL &&
|
||||
msg_id != FACE_VERIFY && msg_id != HAND_VERIFY) {
|
||||
qDebug() << "--- msg_id:" << QString::number(msg_id, 16).toUpper();
|
||||
qDebug() << "--- clientLastMsgId.value(client, 0):" << clientLastMsgId.value(client, 0);
|
||||
qDebug() << "--- success:" << success;
|
||||
//qDebug() << "--- itemJsonIndex:" << itemJsonIndex;
|
||||
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();
|
||||
(msg_id != START_VIDEO || clientLastMsgId.value(client, 0) != START_VIDEO) &&
|
||||
(msg_id != GET_BACK_MAC || clientLastMsgId.value(client, 0) != GET_BACK_MAC) &&
|
||||
(msg_id != GET_FRONT_HW_INFO || clientLastMsgId.value(client, 0) != GET_FRONT_HW_INFO)) {
|
||||
qDebug() << "Emitting statusUpdated for client:" << client << "with msg_id:" << QString::number(msg_id, 16).toUpper();
|
||||
emit statusUpdated(-1, client, success, jsonArray, itemJsonIndex);
|
||||
emit recvNormalDataFlag(true);
|
||||
}
|
||||
clientLastMsgId[client] = msg_id;
|
||||
}
|
||||
handleCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex);
|
||||
handleCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex, success);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -313,36 +321,69 @@ void SerialDataHandler::initializeMsgIdToCmdMap() {
|
||||
msgIdToCmdMap[GET_BACK_HW_VERSION] = "GET_BACK_HW_VERSION";
|
||||
}
|
||||
|
||||
void SerialDataHandler::handleCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex)
|
||||
void SerialDataHandler::handleCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex, bool success)
|
||||
{
|
||||
if (msg_id < 0x0400) {
|
||||
handleFrontCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex);
|
||||
handleFrontCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex, success);
|
||||
}
|
||||
else if (msg_id < 0x0500) {
|
||||
handleDevInfo(msg_id, client, actual_data);
|
||||
handleDevInfo(msg_id, client, actual_data, jsonArray, itemJsonIndex);
|
||||
}
|
||||
else if (msg_id < 0x0800) {
|
||||
//handleBackCmd(msg_id, client, actual_data, jsonArray, itemJsonIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SerialDataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex)
|
||||
void SerialDataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex, bool success)
|
||||
{
|
||||
switch (msg_id) {
|
||||
case FACE_ENROLL_SINGLE:
|
||||
{}
|
||||
break;
|
||||
case FACE_ENROLL:
|
||||
{}
|
||||
break;
|
||||
case HAND_ENROLL:
|
||||
{}
|
||||
break;
|
||||
case FACE_VERIFY:
|
||||
{}
|
||||
break;
|
||||
case FACE_ENROLL_SINGLE:
|
||||
case FACE_ENROLL:
|
||||
case HAND_ENROLL:
|
||||
case FACE_VERIFY:
|
||||
case HAND_VERIFY:
|
||||
{}
|
||||
{
|
||||
#if REG_AND_VERIFY_GET_PIC
|
||||
qDebug() << "---- ENROLL and VERIFY get pic ----";
|
||||
int lens_n = static_cast<unsigned char>(actual_data[1]);
|
||||
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;
|
||||
QByteArray yuvData = actual_data.mid(7);
|
||||
qDebug() << "showPic width * height * 1.5:" << picSize;
|
||||
qDebug() << "showPic picBuffer.size():" << picBuffer->size();
|
||||
qDebug() << "showPic yuvData.size():" << yuvData.size();
|
||||
if (yuvData.size() + picBuffer->size() == picSize) {
|
||||
picBuffer->append(yuvData);
|
||||
showPic(labelSize, lens_n, width, height, format, picBuffer);
|
||||
QJsonObject currentTempItem = jsonArray[itemJsonIndex].toObject();
|
||||
qDebug() << "--1-- showPic ----";
|
||||
//emit statusUpdated(-1, client, success, jsonArray, itemJsonIndex);
|
||||
emit statusUpdated(-1, client, true, jsonArray, itemJsonIndex);
|
||||
emit picRecvFinished();
|
||||
picBuffer->remove(0, picSize);
|
||||
}
|
||||
else if (yuvData.size() + picBuffer->size() > picSize) {
|
||||
picBuffer->append(yuvData);
|
||||
qDebug() << "width is " << width << " height is " << height << "PIC size is" << picSize;
|
||||
qDebug() << "But recv PIC size is " << picBuffer->size();
|
||||
int excessSize = picBuffer->size() - picSize; // 计算超出的大小
|
||||
// 删除末尾超出的部分
|
||||
picBuffer->chop(excessSize);
|
||||
showPic(labelSize, lens_n, width, height, format, picBuffer);
|
||||
QJsonObject currentTempItem = jsonArray[itemJsonIndex].toObject();
|
||||
qDebug() << "--2-- showPic ----";
|
||||
//emit statusUpdated(-1, client, success, jsonArray, itemJsonIndex);
|
||||
emit statusUpdated(-1, client, true, jsonArray, itemJsonIndex);
|
||||
emit picRecvFinished();
|
||||
picBuffer->remove(0, picBuffer->size());
|
||||
}
|
||||
else {
|
||||
picBuffer->append(yuvData);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case DEL_USER:
|
||||
{}
|
||||
@@ -385,6 +426,12 @@ void SerialDataHandler::handleFrontCmd(int msg_id, const QString& client, QByteA
|
||||
picBuffer->append(yuvData);
|
||||
qDebug() << "width is " << width << " height is " << height << "PIC size is" << picSize;
|
||||
qDebug() << "But recv PIC size is " << picBuffer->size();
|
||||
int excessSize = picBuffer->size() - picSize; // 计算超出的大小
|
||||
// 删除末尾超出的部分
|
||||
picBuffer->chop(excessSize);
|
||||
showPic(labelSize, lens_n, width, height, format, picBuffer);
|
||||
QJsonObject currentTempItem = jsonArray[itemJsonIndex].toObject();
|
||||
emit statusUpdated(-1, client, true, jsonArray, itemJsonIndex);
|
||||
picBuffer->remove(0, picBuffer->size());
|
||||
}
|
||||
else {
|
||||
@@ -525,10 +572,10 @@ void SerialDataHandler::handleFrontCmd(int msg_id, const QString& client, QByteA
|
||||
}
|
||||
}
|
||||
|
||||
void SerialDataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray actual_data)
|
||||
void SerialDataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex)
|
||||
{
|
||||
qDebug() << "actual_data.size(): " << actual_data.size();
|
||||
qDebug() << "actual_data: " << QString::fromUtf8(actual_data.toHex().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:
|
||||
@@ -572,8 +619,10 @@ void SerialDataHandler::handleDevInfo(int msg_id, const QString& client, QByteAr
|
||||
}
|
||||
dataStr = hexList.join(", ");
|
||||
}
|
||||
else
|
||||
else {
|
||||
emit statusUpdated(-1, client, false, jsonArray, itemJsonIndex);
|
||||
dataStr = "前板发送的 HW INFO 数据大小不正确";
|
||||
}
|
||||
QString displayText = dataStr;
|
||||
//licenseHwInfoEdit->setPlainText(displayText);
|
||||
emit updateLicenseHwInfoEdit(displayText);
|
||||
@@ -589,8 +638,10 @@ void SerialDataHandler::handleDevInfo(int msg_id, const QString& client, QByteAr
|
||||
dataStr.append(ch);
|
||||
}
|
||||
}
|
||||
else
|
||||
else {
|
||||
emit statusUpdated(-1, client, false, jsonArray, itemJsonIndex);
|
||||
dataStr = "后板发送的 MAC addr 数据大小不正确";
|
||||
}
|
||||
QString displayText = dataStr;
|
||||
emit updateUuidHwInfoEdit(displayText);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#define YUV422 2
|
||||
|
||||
#define BACK_MAC_ADDRESS_LEN 17
|
||||
// 打开注册识别取图
|
||||
#define REG_AND_VERIFY_GET_PIC 1
|
||||
|
||||
class SerialDataHandler : public QObject
|
||||
{
|
||||
@@ -107,9 +109,9 @@ private:
|
||||
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, 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 handleCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex, bool success);
|
||||
void handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data, const QJsonArray& jsonArray, int itemJsonIndex, bool success);
|
||||
void handleDevInfo(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,
|
||||
|
||||
Reference in New Issue
Block a user