From f8a0799e9d100ead007009bf59709174a9802550 Mon Sep 17 00:00:00 2001 From: mhvhm <1308784381@qq.com> Date: Fri, 30 Aug 2024 00:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86=E5=AD=97?= =?UTF-8?q?=E8=8A=82=E7=9A=84=E8=AF=A6=E7=BB=86=E8=A7=A3=E6=9E=90=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BB=A5=E5=8F=8A=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComParseTool/ComParseTool.pro.user | 29 +-- ComParseTool/mainwindow.cpp | 372 ++++++++++++++++++++++++++++- ComParseTool/mainwindow.h | 6 +- ComParseTool/mainwindow.ui | 46 +++- 4 files changed, 427 insertions(+), 26 deletions(-) diff --git a/ComParseTool/ComParseTool.pro.user b/ComParseTool/ComParseTool.pro.user index 5113917..9c8222b 100644 --- a/ComParseTool/ComParseTool.pro.user +++ b/ComParseTool/ComParseTool.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {b72ef07e-303d-4886-ad48-cd1f209eb895} + {a9a6bae5-cd8f-4b74-ae55-1c4ea6a77b25} ProjectExplorer.Project.ActiveTarget @@ -54,12 +54,7 @@ ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - + ProjectExplorer.Project.Target.0 @@ -71,7 +66,7 @@ 0 0 - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Debug true @@ -119,7 +114,7 @@ 2 - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Release + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Release true @@ -167,7 +162,7 @@ 0 - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Profile + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Profile true @@ -287,8 +282,8 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:D:/_SRC/_tools/ComParseTool/ComParseTool/ComParseTool.pro - D:/_SRC/_tools/ComParseTool/ComParseTool/ComParseTool.pro + Qt4ProjectManager.Qt4RunConfiguration:E:/Project/QT_Projects/ComParseTool/ComParseTool/ComParseTool.pro + E:/Project/QT_Projects/ComParseTool/ComParseTool/ComParseTool.pro false @@ -299,7 +294,7 @@ false true - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Debug 1 @@ -314,7 +309,7 @@ 0 0 - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Debug + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Debug true @@ -362,7 +357,7 @@ 2 - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Release + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Release true @@ -410,7 +405,7 @@ 0 - D:/_SRC/_tools/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Profile + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Profile true diff --git a/ComParseTool/mainwindow.cpp b/ComParseTool/mainwindow.cpp index 70f06cf..0b9344b 100644 --- a/ComParseTool/mainwindow.cpp +++ b/ComParseTool/mainwindow.cpp @@ -11,8 +11,11 @@ MainWindow::MainWindow(QWidget *parent) ui->tableWidget->setColumnCount(12); ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // 自适应列宽 + ui->tableWidget_detail->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // 自适应列宽 ui->tableWidget->horizontalHeader()->setMinimumHeight(40); + ui->tableWidget_detail->setVisible(false); + pQfile_ori = new QFile; pQfile_key = new QFile; @@ -32,7 +35,9 @@ void MainWindow::BindSlot(void) connect(ui->pushButton_oriPath, &QPushButton::clicked, this, PushButton_Clicked_CatchFile_Callback); connect(ui->pushButton_keyPath, &QPushButton::clicked, this, PushButton_Clicked_CatchFile_Callback); - connect(ui->pushButton_parse, &QPushButton::clicked, this, PushButton_Clicked_Parse_clicked); + connect(ui->pushButton_parse, &QPushButton::clicked, this, PushButton_Clicked_Parse_Callback); + + connect(ui->tableWidget, &QTableWidget::cellPressed, this, TableWidget_DoubleClicked_Callback); } // 打开资源管理器 @@ -42,8 +47,9 @@ void MainWindow::OpenExplorerFile(bool isOriFileOpen) QString filePath = QFileDialog::getOpenFileName(this, "选择文件", DesktopLocation, "文本文件(*.txt)"); if (filePath.isEmpty() != true) // 判断路径是否有效 { - ui->tableWidget->clear(); ui->tableWidget->setRowCount(0); + ui->tableWidget_detail->setVisible(false); + ui->tableWidget_detail->setRowCount(0); if (isOriFileOpen) { if (pQfile_ori->fileName() != filePath) @@ -712,6 +718,344 @@ QString MainWindow::AppendParse(DATA_TYPEDEF data) return ret; } +// 显示字节详细数据 +void MainWindow::ShowByteDetail(DATA_TYPEDEF data) +{ + bool notNeedShow = false; + + switch(data.buf[0]) // 指令解析 + { + case 0x11: + { + ui->tableWidget_detail->setRowCount(2); + ui->tableWidget_detail->setColumnCount(9); + for (uint8_t i = 0; i < 2; i++) + { + for (uint8_t j = 0; j < 9; j++) + { + QTableWidgetItem *item = new QTableWidgetItem; + item->setText("-"); + ui->tableWidget_detail->setItem(i, j, item); + } + } + ui->tableWidget_detail->setSpan(0, 1, 2, 3); + + ui->tableWidget_detail->item(0, 0)->setText("0"); + ui->tableWidget_detail->item(1, 0)->setText("1"); + ui->tableWidget_detail->item(0, 1)->setText(QString::number(((data.buf[7] & 0xe0) >> 5) + 1, 10)); + ui->tableWidget_detail->item(0, 7)->setText("右向熄灭"); + ui->tableWidget_detail->item(1, 7)->setText("右向点亮"); + ui->tableWidget_detail->item(0, 8)->setText("左向熄灭"); + ui->tableWidget_detail->item(1, 8)->setText("左向点亮"); + + if ((data.buf[7] & 0x02) == 0) + { + ui->tableWidget_detail->item(0, 7)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 7)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[7] & 0x01) == 0) + { + ui->tableWidget_detail->item(0, 8)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 8)->setBackground(QColor("#CCFFCC")); + } + }break; + case 0x12: + { + ui->tableWidget_detail->setRowCount(2); + ui->tableWidget_detail->setColumnCount(9); + for (uint8_t i = 0; i < 2; i++) + { + for (uint8_t j = 0; j < 9; j++) + { + QTableWidgetItem *item = new QTableWidgetItem; + item->setText("-"); + ui->tableWidget_detail->setItem(i, j, item); + } + } + ui->tableWidget_detail->setSpan(0, 1, 2, 3); + + ui->tableWidget_detail->item(0, 0)->setText("0"); + ui->tableWidget_detail->item(1, 0)->setText("1"); + ui->tableWidget_detail->item(0, 1)->setText(QString::number(((data.buf[7] & 0xe0) >> 5) + 1, 10)); + ui->tableWidget_detail->item(0, 5)->setText("中间熄灭"); + ui->tableWidget_detail->item(1, 5)->setText("中间点亮"); + ui->tableWidget_detail->item(0, 7)->setText("右向熄灭"); + ui->tableWidget_detail->item(1, 7)->setText("右向点亮"); + ui->tableWidget_detail->item(0, 8)->setText("左向熄灭"); + ui->tableWidget_detail->item(1, 8)->setText("左向点亮"); + + if ((data.buf[7] & 0x08) == 0) + { + ui->tableWidget_detail->item(0, 5)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 5)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[7] & 0x02) == 0) + { + ui->tableWidget_detail->item(0, 7)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 7)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[7] & 0x01) == 0) + { + ui->tableWidget_detail->item(0, 8)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 8)->setBackground(QColor("#CCFFCC")); + } + }break; + case 0x14: // todo + { + if (data.buf[1] == 0x00) + { + // todo + } + }break; + case 0x16: + { + ui->tableWidget_detail->setRowCount(2); + ui->tableWidget_detail->setColumnCount(9); + for (uint8_t i = 0; i < 2; i++) + { + for (uint8_t j = 0; j < 9; j++) + { + QTableWidgetItem *item = new QTableWidgetItem; + item->setText("-"); + ui->tableWidget_detail->setItem(i, j, item); + } + } + ui->tableWidget_detail->setSpan(0, 1, 2, 3); + + ui->tableWidget_detail->item(0, 0)->setText("0"); + ui->tableWidget_detail->item(1, 0)->setText("1"); + ui->tableWidget_detail->item(0, 1)->setText(QString::number(((data.buf[7] & 0xe0) >> 5) + 1, 10)); + ui->tableWidget_detail->item(0, 5)->setText("停止"); + ui->tableWidget_detail->item(1, 5)->setText("启动"); + ui->tableWidget_detail->item(0, 6)->setText("常亮"); + ui->tableWidget_detail->item(1, 6)->setText("闪亮"); + ui->tableWidget_detail->item(0, 8)->setText("照明灯具"); + ui->tableWidget_detail->item(1, 8)->setText("标志灯具"); + + if ((data.buf[7] & 0x08) == 0) + { + ui->tableWidget_detail->item(0, 5)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 5)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[7] & 0x04) == 0) + { + ui->tableWidget_detail->item(0, 6)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 6)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[7] & 0x01) == 0) + { + ui->tableWidget_detail->item(0, 8)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 8)->setBackground(QColor("#CCFFCC")); + } + }break; + case 0x1f: // todo + { + + }break; + case 0x25: // todo + { + ui->tableWidget_detail->setRowCount(6); + ui->tableWidget_detail->setColumnCount(9); + for (uint8_t i = 0; i < 6; i++) + { + for (uint8_t j = 0; j < 9; j++) + { + QTableWidgetItem *item = new QTableWidgetItem; + item->setText("-"); + ui->tableWidget_detail->setItem(i, j, item); + } + } + ui->tableWidget_detail->setSpan(0, 1, 2, 3); + ui->tableWidget_detail->setSpan(4, 1, 2, 3); + + ui->tableWidget_detail->item(0, 0)->setText("0"); + ui->tableWidget_detail->item(1, 0)->setText("1"); + ui->tableWidget_detail->item(0, 1)->setText(QString::number(((data.buf[5] & 0xe0) >> 5) + 1, 10)); + ui->tableWidget_detail->item(0, 5)->setText("旧国标"); + ui->tableWidget_detail->item(1, 5)->setText("新国标"); + ui->tableWidget_detail->item(0, 6)->setText("保险丝"); + ui->tableWidget_detail->item(1, 6)->setText("自恢复"); + ui->tableWidget_detail->item(0, 7)->setText("集中电源"); + ui->tableWidget_detail->item(1, 7)->setText("配电箱"); + ui->tableWidget_detail->item(0, 8)->setText("不带回路"); + ui->tableWidget_detail->item(1, 8)->setText("带回路"); + + ui->tableWidget_detail->item(2, 0)->setText("1"); + ui->tableWidget_detail->item(3, 0)->setText("0"); + for (uint8_t i = 0; i < 8; i++) + { + ui->tableWidget_detail->item(2, i + 1)->setText("离线"); + ui->tableWidget_detail->item(3, i + 1)->setText("在线"); + if ((data.buf[6] & (1 << i)) == 0) + { + ui->tableWidget_detail->item(2, 8 - i)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(3, 8 - i)->setBackground(QColor("#CCFFCC")); + } + } + + ui->tableWidget_detail->item(4, 0)->setText("0"); + ui->tableWidget_detail->item(5, 0)->setText("1"); + ui->tableWidget_detail->item(4, 1)->setText("回路数量:" + QString::number(((data.buf[7] & 0xe0) >> 5) + 1, 10)); + + if ((data.buf[5] & 0x08) == 0) + { + ui->tableWidget_detail->item(0, 5)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 5)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[5] & 0x04) == 0) + { + ui->tableWidget_detail->item(0, 6)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 6)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[5] & 0x02) == 0) + { + ui->tableWidget_detail->item(0, 7)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 7)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[5] & 0x02) == 0) + { + ui->tableWidget_detail->item(0, 8)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 8)->setBackground(QColor("#CCFFCC")); + } + }break; + case 0x26: + { + ui->tableWidget_detail->setRowCount(4); + ui->tableWidget_detail->setColumnCount(9); + for (uint8_t i = 0; i < 4; i++) + { + for (uint8_t j = 0; j < 9; j++) + { + QTableWidgetItem *item = new QTableWidgetItem; + item->setText("-"); + ui->tableWidget_detail->setItem(i, j, item); + } + } + + ui->tableWidget_detail->item(0, 0)->setText("0"); + ui->tableWidget_detail->item(1, 0)->setText("1"); + ui->tableWidget_detail->item(0, 1)->setText("手动"); + ui->tableWidget_detail->item(1, 1)->setText("自动"); + ui->tableWidget_detail->item(0, 2)->setText("正常"); + ui->tableWidget_detail->item(1, 2)->setText("强启"); + ui->tableWidget_detail->item(0, 3)->setText("非消音"); + ui->tableWidget_detail->item(1, 3)->setText("消音"); + ui->tableWidget_detail->item(0, 4)->setText("主电工作"); + ui->tableWidget_detail->item(1, 4)->setText("备电工作"); + ui->tableWidget_detail->item(0, 5)->setText("充电中"); + ui->tableWidget_detail->item(1, 5)->setText("充电完成"); + ui->tableWidget_detail->item(0, 6)->setText("非故障"); + ui->tableWidget_detail->item(1, 6)->setText("故障"); + ui->tableWidget_detail->item(0, 7)->setText("非应急"); + ui->tableWidget_detail->item(1, 7)->setText("应急"); + + ui->tableWidget_detail->item(2, 0)->setText("0"); + ui->tableWidget_detail->item(3, 0)->setText("1"); + ui->tableWidget_detail->item(2, 1)->setText("非输出故障"); + ui->tableWidget_detail->item(3, 1)->setText("输出故障"); + ui->tableWidget_detail->item(2, 2)->setText("非应急时间故障"); + ui->tableWidget_detail->item(3, 2)->setText("应急时间故障"); + ui->tableWidget_detail->item(2, 3)->setText("非应急功能故障"); + ui->tableWidget_detail->item(3, 3)->setText("应急功能故障"); + ui->tableWidget_detail->item(2, 4)->setText("电池正常"); + ui->tableWidget_detail->item(3, 4)->setText("电池故障"); + ui->tableWidget_detail->item(2, 5)->setText("主电正常"); + ui->tableWidget_detail->item(3, 5)->setText("主电故障"); + ui->tableWidget_detail->item(2, 6)->setText("灯具正常"); + ui->tableWidget_detail->item(3, 6)->setText("灯具故障"); + ui->tableWidget_detail->item(2, 7)->setText("回路正常"); + ui->tableWidget_detail->item(3, 7)->setText("回路故障"); + ui->tableWidget_detail->item(2, 8)->setText("通信正常"); + ui->tableWidget_detail->item(3, 8)->setText("通信故障"); + + for (uint8_t i = 0; i < 8; i++) + { + if ((data.buf[1] & (1 << i)) == 0) + { + ui->tableWidget_detail->item(0, 8 - i)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(1, 8 - i)->setBackground(QColor("#CCFFCC")); + } + + if ((data.buf[2] & (1 << i)) == 0) + { + ui->tableWidget_detail->item(2, 8 - i)->setBackground(QColor("#CCFFCC")); + } + else + { + ui->tableWidget_detail->item(3, 8 - i)->setBackground(QColor("#CCFFCC")); + } + } + }break; + default: + { + notNeedShow = true; + }break; + } + + + + // 表格2绘制 + if (!notNeedShow) + { + ui->tableWidget_detail->setHorizontalHeaderLabels(QStringList() << "值" << "Bit7" << "Bit6" << "Bit5" << "Bit4" << "Bit3" << "Bit2" << "Bit1" << "Bit0"); + ui->tableWidget_detail->setVisible(true); + } + else + { + ui->tableWidget_detail->setVisible(false); + ui->tableWidget_detail->setRowCount(0); + } +} /* ******************************************************************** */ // 文件浏览槽函数 void MainWindow::PushButton_Clicked_CatchFile_Callback(void) @@ -729,7 +1073,7 @@ void MainWindow::PushButton_Clicked_CatchFile_Callback(void) } } -void MainWindow::PushButton_Clicked_Parse_clicked() +void MainWindow::PushButton_Clicked_Parse_Callback() { bool isFirstLine = true; qDebug() << "*** \"pushButton_parse\" Clicked Callback ***"; @@ -767,7 +1111,6 @@ void MainWindow::PushButton_Clicked_Parse_clicked() break; // todo 需要调试 } } - // todo 将String转换为数组 QByteArray ba = QByteArray::fromHex(context.mid(strSecondIndex + 1, strFirstIndex - strSecondIndex - 2).toLatin1()); DATA_TYPEDEF bufData; @@ -803,3 +1146,24 @@ void MainWindow::PushButton_Clicked_Parse_clicked() disp = context; } } + +// 表格-选中单元格事件 +void MainWindow::TableWidget_DoubleClicked_Callback(int row, int colnum) +{ + if (colnum == 10) // 只针对解析后的数据进行字节解析 + { + QTableWidgetItem *item = ui->tableWidget->item(row, colnum); + QString temp = item->text().remove(" "); // 去除多余空格 + QByteArray ba = QByteArray::fromHex(temp.toLatin1()); + DATA_TYPEDEF data; + data.len = ba.length(); + memcpy(data.buf, ba.data(), data.len); + + ShowByteDetail(data); // 显示字节详细数据 + } + else + { + ui->tableWidget_detail->setVisible(false); + ui->tableWidget_detail->setRowCount(0); + } +} diff --git a/ComParseTool/mainwindow.h b/ComParseTool/mainwindow.h index e87ccea..55c5f6b 100644 --- a/ComParseTool/mainwindow.h +++ b/ComParseTool/mainwindow.h @@ -12,6 +12,7 @@ #include #include #include +#include #include typedef struct @@ -37,11 +38,14 @@ public: QString AppendParse(DATA_TYPEDEF data); QString GetLampType(uint8_t lampidx); QString GetEventCode(uint8_t lampidx); + void ShowByteDetail(DATA_TYPEDEF data); private slots: void PushButton_Clicked_CatchFile_Callback(); - void PushButton_Clicked_Parse_clicked(); + void PushButton_Clicked_Parse_Callback(); + + void TableWidget_DoubleClicked_Callback(int row, int colum); private: Ui::MainWindow *ui; diff --git a/ComParseTool/mainwindow.ui b/ComParseTool/mainwindow.ui index 9863444..00c21c0 100644 --- a/ComParseTool/mainwindow.ui +++ b/ComParseTool/mainwindow.ui @@ -6,10 +6,16 @@ 0 0 - 924 - 431 + 1560 + 919 + + + 1000 + 0 + + MainWindow @@ -186,7 +192,39 @@ background-color: rgb(91, 255, 88); - + + + + + + + + true + + + + 0 + 0 + + + + + 350 + 0 + + + + + 700 + 16777215 + + + + font: 11pt "Adobe Arabic"; + + + + @@ -214,7 +252,7 @@ background-color: rgb(91, 255, 88); 0 0 - 924 + 1560 21