| 
									
										
										
										
											2024-12-17 18:53:41 +08:00
										 |  |  |  | #include "mainwindow.h"
 | 
					
						
							|  |  |  |  | #include "ui_mainwindow.h"
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  |  | #include <QList>
 | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  | #include <QJsonDocument>
 | 
					
						
							|  |  |  |  | #include <QJsonArray>
 | 
					
						
							|  |  |  |  | #include <QJsonObject>
 | 
					
						
							| 
									
										
										
										
											2025-08-07 19:35:59 +08:00
										 |  |  |  | #include <QInputDialog>
 | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  | #include "keyphase.h"
 | 
					
						
							|  |  |  |  | #include "singlerelay.h"
 | 
					
						
							|  |  |  |  | #include "tachometer.h"
 | 
					
						
							|  |  |  |  | #include "seismic_monitor.h"
 | 
					
						
							|  |  |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  | #include <QFileDialog>
 | 
					
						
							|  |  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  |  | #include <QSysInfo>
 | 
					
						
							|  |  |  |  | #include <qsettings.h>
 | 
					
						
							| 
									
										
										
										
											2025-03-07 15:36:02 +08:00
										 |  |  |  | #include <QNetworkProxy>
 | 
					
						
							| 
									
										
										
										
											2025-03-04 16:00:19 +08:00
										 |  |  |  | #include "relaysetting.h"
 | 
					
						
							| 
									
										
										
										
											2025-04-07 19:30:10 +08:00
										 |  |  |  | #include "config_mgr.h"
 | 
					
						
							|  |  |  |  | #include "vibrationdata.h"
 | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  | #include "connect.h"
 | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  | #include "tmrrelayassociation.h"
 | 
					
						
							|  |  |  |  | #include "setpoint_tachometer.h"
 | 
					
						
							| 
									
										
										
										
											2025-04-22 20:55:40 +08:00
										 |  |  |  | #include "pointname.h"
 | 
					
						
							|  |  |  |  | #include "ethconfig.h"
 | 
					
						
							|  |  |  |  | #include "macconfig.h"
 | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  | #include <QDateTime>
 | 
					
						
							| 
									
										
										
										
											2025-08-04 12:25:12 +08:00
										 |  |  |  | #include "dc_outputs.h"
 | 
					
						
							| 
									
										
										
										
											2025-08-06 22:11:14 +08:00
										 |  |  |  | #include "mqtt_config.h"
 | 
					
						
							| 
									
										
										
										
											2025-08-08 21:59:34 +08:00
										 |  |  |  | #include <QInputDialog>
 | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-04 16:00:19 +08:00
										 |  |  |  | QString g_strServerIp; | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  | QString g_version; | 
					
						
							| 
									
										
										
										
											2024-12-17 18:53:41 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | MainWindow::MainWindow(QWidget *parent) | 
					
						
							|  |  |  |  |     : QMainWindow(parent) | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     , ui(new Ui::MainWindow) { | 
					
						
							| 
									
										
										
										
											2024-12-17 18:53:41 +08:00
										 |  |  |  |     ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |     g_version = "1.1"; | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  |     current_slot = -1; | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     tsi_config_file = ""; | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |     ui->widget_body->setProperty("flag", "title"); | 
					
						
							|  |  |  |  |     ui->menuBar->setProperty("flag", "menuBar"); | 
					
						
							|  |  |  |  |     //关联事件过滤器用于双击放大
 | 
					
						
							|  |  |  |  |     ui->widget_body->installEventFilter(this); | 
					
						
							|  |  |  |  |     ui->widget_body->setProperty("flag", "body"); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     ui->statusBar->setProperty("flag", "status"); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |     // 创建进度条
 | 
					
						
							|  |  |  |  |     progressBar = new QProgressBar(this); | 
					
						
							|  |  |  |  |     // 设置进度条的范围(0到100)
 | 
					
						
							|  |  |  |  |     progressBar->setRange(0, 100); | 
					
						
							|  |  |  |  |     // 将进度条添加到状态栏
 | 
					
						
							|  |  |  |  |     statusBar()->addWidget(progressBar); | 
					
						
							|  |  |  |  |     progressBar->setVisible(false); // 初始隐藏
 | 
					
						
							|  |  |  |  |     progressBar->setFixedWidth(300); | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |     //this->initStyle();
 | 
					
						
							| 
									
										
										
										
											2025-03-04 16:00:19 +08:00
										 |  |  |  |     //添加信号槽
 | 
					
						
							|  |  |  |  |     QObject::connect(ui->action_realy, &QAction::triggered, this, &MainWindow::onMenuAction_relay); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |     slot_no = -1; | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     btnGroup_slot = new QButtonGroup(this); | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot0); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot1); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot2); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot3); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot4); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot5); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot6); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot7); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot8); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot9); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot10); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot11); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot12); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot13); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot14); | 
					
						
							|  |  |  |  |     btnGroup_slot->addButton(ui->pushButton_slot15); | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |     list_label.reserve(16); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_18); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_1); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_2); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_3); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_4); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_5); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_6); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_7); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_8); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_9); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_10); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_11); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_12); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_13); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_14); | 
					
						
							|  |  |  |  |     list_label.push_back(ui->label_15); | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |     ui->pushButton_slot->setChecked(true); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     createMenu(); | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |     connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *))); | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  |     QObject::connect(ui->action_connect, &QAction::triggered, this, &MainWindow::onConnect); | 
					
						
							| 
									
										
										
										
											2025-04-22 20:55:40 +08:00
										 |  |  |  |     QObject::connect(ui->action_disconnect, &QAction::triggered, this, &MainWindow::onDisconnect); | 
					
						
							|  |  |  |  |     QObject::connect(ui->action_eth, &QAction::triggered, this, &MainWindow::onEthConfig); | 
					
						
							|  |  |  |  |     QObject::connect(ui->action_mac, &QAction::triggered, this, &MainWindow::onMACConfig); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |     QObject::connect(ui->action_time, &QAction::triggered, this, &MainWindow::onSetTime); | 
					
						
							| 
									
										
										
										
											2025-08-06 22:11:14 +08:00
										 |  |  |  |     QObject::connect(ui->action_mqtt, &QAction::triggered, this, &MainWindow::onMqttConfig); | 
					
						
							| 
									
										
										
										
											2025-08-08 21:59:34 +08:00
										 |  |  |  |     QObject::connect(ui->action_deviveID, &QAction::triggered, this, &MainWindow::onConfigDeviceID); | 
					
						
							|  |  |  |  |     QObject::connect(ui->action_get_deviceID, &QAction::triggered, this, &MainWindow::onGetDeviceID); | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat); | 
					
						
							| 
									
										
										
										
											2025-03-04 16:00:19 +08:00
										 |  |  |  |     g_strServerIp = settingsread.value("Server/IP").toString(); | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     connectServer(); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |     statusBar()->showMessage("未连接",10000); | 
					
						
							| 
									
										
										
										
											2025-03-05 09:33:48 +08:00
										 |  |  |  |     // 设置自定义日志处理函数
 | 
					
						
							|  |  |  |  | #ifndef QT_DEBUG
 | 
					
						
							| 
									
										
										
										
											2025-04-21 17:23:38 +08:00
										 |  |  |  |     //qInstallMessageHandler(messageHandler);
 | 
					
						
							| 
									
										
										
										
											2025-03-05 09:33:48 +08:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2024-12-17 18:53:41 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | MainWindow::~MainWindow() { | 
					
						
							| 
									
										
										
										
											2024-12-17 18:53:41 +08:00
										 |  |  |  |     delete ui; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::onDisConnected() { | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     statusBar()->showMessage("连接失败!正在重连……", 3000); // 显示3秒
 | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::onConnected() { | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  |     statusBar()->showMessage("连接成功!", 3000); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::onerrorOccurred(const QString &errorMsg) { | 
					
						
							|  |  |  |  |     statusBar()->showMessage(errorMsg, 3000); | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::connectServer() { | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     m_tcpClient = MyTcpClient::instance(); | 
					
						
							|  |  |  |  |     // 监听信号
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &))); | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     connect(m_tcpClient, SIGNAL(disconnected()), this, SLOT(onDisConnected())); | 
					
						
							|  |  |  |  |     connect(m_tcpClient, SIGNAL(connected()), this, SLOT(onConnected())); | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  |     connect(m_tcpClient, SIGNAL(errorOccurred(const QString &)), this, SLOT(onerrorOccurred(const QString &))); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::initStyle() { | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |     //加载样式表
 | 
					
						
							|  |  |  |  |     QString qss; | 
					
						
							|  |  |  |  |     QFile file(":/qss/soft.css"); | 
					
						
							|  |  |  |  |     if (file.open(QFile::ReadOnly)) { | 
					
						
							|  |  |  |  |         qss = QLatin1String(file.readAll()); | 
					
						
							|  |  |  |  |         QString paletteColor = qss.mid(20, 7); | 
					
						
							|  |  |  |  |         qApp->setPalette(QPalette(paletteColor)); | 
					
						
							|  |  |  |  |         qApp->setStyleSheet(qss); | 
					
						
							|  |  |  |  |         file.close(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::createMenu() { | 
					
						
							|  |  |  |  |     QList<QAbstractButton *> buttonList = btnGroup_slot->buttons(); | 
					
						
							|  |  |  |  |     for (int i = 0; i < buttonList.count(); i++) { | 
					
						
							|  |  |  |  |         createMenu(QString("%1").arg(i + 1), (QPushButton *)buttonList[i]); | 
					
						
							|  |  |  |  |         map_slot_config[i].slot_btn = (QPushButton *)buttonList[i]; | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |         map_slot_config[i].slot_label = list_label[i]; | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(i); | 
					
						
							|  |  |  |  |         if(base_ptr != nullptr){ | 
					
						
							|  |  |  |  |             switch (base_ptr->card_type_) { | 
					
						
							|  |  |  |  |                 case kCardVibSingle : | 
					
						
							|  |  |  |  |                     buttonList[i]->setText("振动"); | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 default: | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::createMenu(const QString &rootTitle, QPushButton *parent) { | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     // 创建主菜单
 | 
					
						
							|  |  |  |  |     QMenu *mainMenu = new QMenu(rootTitle, parent); | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     // 创建第一层子菜单
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     QMenu *monitors = new QMenu("监视器", mainMenu); | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     QMenu *relays = new QMenu("/DOM810 继电器模块", mainMenu); | 
					
						
							|  |  |  |  |     QMenu *keyphasor = new QMenu("/KPM834 键相模块", mainMenu); | 
					
						
							|  |  |  |  |     // 创建第二层子菜单:/HAM824 振动板卡
 | 
					
						
							|  |  |  |  |     QMenu *proximitor_menu = new QMenu("/HAM824 振动板卡", monitors); | 
					
						
							|  |  |  |  |     QMenu *rpm_menu = new QMenu("/OPM844 转速板卡", monitors); | 
					
						
							|  |  |  |  |     // 创建第三层子菜单:/HAM824 单板卡、三冗余板卡
 | 
					
						
							|  |  |  |  |     QAction *proximitor_1 = proximitor_menu->addAction("/HAM824 单板卡"); | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |     proximitor_1->setData(kCardVibSingle); | 
					
						
							| 
									
										
										
										
											2025-04-23 14:44:58 +08:00
										 |  |  |  |     //QAction *proximitor_2 = proximitor_menu->addAction("/HAM824 三冗余板卡");
 | 
					
						
							|  |  |  |  |     //proximitor_2->setData(kCardVibTMRPrimary);
 | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     QAction *rpm_1 = rpm_menu->addAction("/OPM844 单板卡"); | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |     rpm_1->setData(kCardSpeedSingle); | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     // 创建第二层子菜单:/KPM834 键相模块
 | 
					
						
							|  |  |  |  |     QAction *keyphasor_1 = keyphasor->addAction("/KPM834 单板卡"); | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |     keyphasor_1->setData(kCardKeyphaseSingle); | 
					
						
							| 
									
										
										
										
											2025-04-25 14:28:27 +08:00
										 |  |  |  |     //QAction *keyphasor_2 = keyphasor->addAction("/KPM834 两板卡");
 | 
					
						
							|  |  |  |  |     //keyphasor_2->setData(kCardKeyphaseDouble);
 | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     // 创建第二层子菜单:/DOM810 继电器模块
 | 
					
						
							|  |  |  |  |     QAction *relays_1 = relays->addAction("/DOM810 单板卡"); | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |     relays_1->setData(kCardRelaySingle); | 
					
						
							| 
									
										
										
										
											2025-07-17 20:10:38 +08:00
										 |  |  |  | //    QAction *relays_2 = relays->addAction("/DOM810 单板卡-非OK");
 | 
					
						
							|  |  |  |  | //    relays_2->setData(kCardRelaySingleNOK);
 | 
					
						
							|  |  |  |  | //    QAction *relays_3 = relays->addAction("/DOM810 三冗余板卡");
 | 
					
						
							|  |  |  |  | //    relays_3->setData(kCardRelayTMRPrimary);
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     // 将子菜单加入上一级菜单
 | 
					
						
							|  |  |  |  |     monitors->addMenu(proximitor_menu); // 将第二层加入第一层
 | 
					
						
							|  |  |  |  |     monitors->addMenu(rpm_menu); // 第二层另一个子菜单
 | 
					
						
							|  |  |  |  |     mainMenu->addMenu(monitors); // 将第一层加入主菜单
 | 
					
						
							|  |  |  |  |     mainMenu->addMenu(relays); | 
					
						
							|  |  |  |  |     mainMenu->addMenu(keyphasor); | 
					
						
							|  |  |  |  |     QAction *reset = mainMenu->addAction("重置模块"); | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |     QAction *upgrade = mainMenu->addAction("升级固件"); | 
					
						
							| 
									
										
										
										
											2025-03-03 21:57:15 +08:00
										 |  |  |  |     QAction *version = mainMenu->addAction("查看版本"); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |     QAction *config_sub_card = mainMenu->addAction("更新配置"); | 
					
						
							|  |  |  |  |     QAction *get_sub_log = mainMenu->addAction("获取日志"); | 
					
						
							| 
									
										
										
										
											2025-09-18 11:46:35 +08:00
										 |  |  |  |     QAction *get_sub_card_voltage = mainMenu->addAction("获取电压范围"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-07 15:36:02 +08:00
										 |  |  |  |     // 绑定 **鼠标事件过滤器**,确保只响应右键
 | 
					
						
							|  |  |  |  |     // 设置右键菜单策略
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     parent->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							| 
									
										
										
										
											2025-03-07 15:36:02 +08:00
										 |  |  |  |     // 使用 `customContextMenuRequested` 事件,确保只有右键点击时弹出菜单
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     connect(parent, &QPushButton::customContextMenuRequested, this, [ = ](const QPoint &pos) { | 
					
						
							| 
									
										
										
										
											2025-03-07 15:36:02 +08:00
										 |  |  |  |         qDebug() << "右键菜单触发1:" << pos; | 
					
						
							|  |  |  |  |         // 弹出菜单并捕获右键点击
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |         mainMenu->exec(QCursor::pos()); | 
					
						
							| 
									
										
										
										
											2025-03-07 15:36:02 +08:00
										 |  |  |  |         mainMenu->close(); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     }); | 
					
						
							|  |  |  |  |     // 连接所有菜单项
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     QObject::connect(proximitor_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							| 
									
										
										
										
											2025-04-23 14:44:58 +08:00
										 |  |  |  |     //QObject::connect(proximitor_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     QObject::connect(rpm_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							|  |  |  |  |     QObject::connect(relays_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							| 
									
										
										
										
											2025-07-17 20:10:38 +08:00
										 |  |  |  |     //QObject::connect(relays_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
 | 
					
						
							|  |  |  |  |     //QObject::connect(relays_3, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     QObject::connect(keyphasor_1, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							| 
									
										
										
										
											2025-04-25 15:40:40 +08:00
										 |  |  |  |     //QObject::connect(keyphasor_2, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     QObject::connect(reset, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							|  |  |  |  |     QObject::connect(upgrade, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							|  |  |  |  |     QObject::connect(version, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |     QObject::connect(config_sub_card, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							|  |  |  |  |     QObject::connect(get_sub_log, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							| 
									
										
										
										
											2025-09-18 11:46:35 +08:00
										 |  |  |  |     QObject::connect(get_sub_card_voltage, &QAction::triggered, this, &MainWindow::onMenuActionTriggered); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::createMenuSet(const QString &rootTitle, QPushButton *parent) { | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     // 创建主菜单
 | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "createMenu" << parent->objectName()   ; | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     QMenu *mainMenu = new QMenu(rootTitle, parent); | 
					
						
							|  |  |  |  |     QAction *option = mainMenu->addAction("通道配置…"); | 
					
						
							|  |  |  |  |     QAction *set_points = mainMenu->addAction("触发配置…"); | 
					
						
							|  |  |  |  |     QAction *point_names = mainMenu->addAction("测点名称"); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // 清除菜单中所有动作的属性
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::clearMenuProperties(QMenu *menu) { | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     // 遍历菜单的所有动作
 | 
					
						
							|  |  |  |  |     if (!menu) { | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |         qWarning() << "菜单为空,无法清除属性!"; | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     // 遍历菜单的所有动作
 | 
					
						
							|  |  |  |  |     for (QAction *action : menu->actions()) { | 
					
						
							|  |  |  |  |         if (!action) { | 
					
						
							|  |  |  |  |             continue; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         // 检查是否有子菜单
 | 
					
						
							|  |  |  |  |         if (QMenu *subMenu = action->menu()) { | 
					
						
							|  |  |  |  |             clearMenuProperties(subMenu); // 递归处理子菜单
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         // 清除动作的属性
 | 
					
						
							|  |  |  |  |         action->setProperty("customProperty", QVariant()); | 
					
						
							|  |  |  |  |         qDebug() << "清除了属性,动作:" << action->text(); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::onMenuActionTriggered() { | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "onMenuActionTriggered()"   ; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |     if (action) { | 
					
						
							|  |  |  |  |         // 获取触发动作的父菜单
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |         QMenu *menu = qobject_cast<QMenu *>(action->parent()); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |         // 遍历所有父菜单,直到找到按钮
 | 
					
						
							|  |  |  |  |         while (menu) { | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |             QPushButton *button = qobject_cast<QPushButton *>(menu->parent()); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |             if (button) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                 qDebug() << "子菜单项被点击,所属按钮:" << button->objectName() << action->text(); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 QString slot_type = action->text().mid(1, 6); | 
					
						
							|  |  |  |  |                 QString rack_type = action->text().right(action->text().length() - 8); | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |                 qDebug() << "rack_type" << action->data(); | 
					
						
							|  |  |  |  |                 card_type = static_cast<CardType>(action->data().toInt()); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 int button_id = button->objectName().right(button->objectName().length() - 15).toInt(); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |                 qDebug() << slot_type << rack_type << button_id << map_slot_config[button_id].slot_type << map_slot_config[button_id + 2].slot_type   ; | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |                 map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}"); | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                 QString chan_display = ""; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 if (slot_type == "DOM810") { | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     chan_display = "继电器"; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 } else if (slot_type == "KPM834") { | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     chan_display = "键相"; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 } else if (slot_type == "HAM824") { | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     chan_display = "振动"; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 } else if (slot_type == "OPM844") { | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     chan_display = "转速"; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  |                 if (card_type == kCardRelayTMRPrimary && | 
					
						
							|  |  |  |  |                         (ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone || | 
					
						
							|  |  |  |  |                          ConfigMgr::Instance()->card_type_[button_id] != kCardNone || | 
					
						
							|  |  |  |  |                          ConfigMgr::Instance()->card_type_[button_id + 1] != kCardNone)) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                     QMessageBox::information(this, QStringLiteral("提示"), "不要重叠三冗余板卡配置,请在创建新配置之前移除现有的配置!"); | 
					
						
							|  |  |  |  |                     return; | 
					
						
							| 
									
										
										
										
											2025-04-23 17:13:05 +08:00
										 |  |  |  |                 } else if (card_type == kCardRelayTMRPrimary && ConfigMgr::Instance()->card_type_[button_id - 1] == kCardNone \ | 
					
						
							|  |  |  |  |                            && ConfigMgr::Instance()->card_type_[button_id] == kCardNone && | 
					
						
							|  |  |  |  |                            ConfigMgr::Instance()->card_type_[button_id + 1] == kCardNone) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                     map_slot_config[button_id].slot_type = slot_type; | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     map_slot_config[button_id].slot_btn->setText(chan_display); | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                     map_slot_config[button_id + 1].slot_type = slot_type; | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     map_slot_config[button_id + 1].slot_btn->setText(chan_display); | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                     map_slot_config[button_id + 2].slot_type = slot_type; | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     map_slot_config[button_id + 2].slot_btn->setText(chan_display); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                     ConfigMgr::Instance()->card_type_[button_id - 1] = kCardRelayTMRPrimary; | 
					
						
							|  |  |  |  |                     ConfigMgr::Instance()->card_type_[button_id] = kCardRelayTMRBackup; | 
					
						
							|  |  |  |  |                     ConfigMgr::Instance()->card_type_[button_id + 1] = kCardRelayTMRBackup; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  |                 if (rack_type == "两板卡" && | 
					
						
							|  |  |  |  |                         (ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone || | 
					
						
							|  |  |  |  |                          ConfigMgr::Instance()->card_type_[button_id] != kCardNone)) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                     QMessageBox::information(this, QStringLiteral("提示"), "不要重叠两板卡配置,请在创建新配置之前移除现有的配置!"); | 
					
						
							|  |  |  |  |                     return; | 
					
						
							| 
									
										
										
										
											2025-04-23 17:13:05 +08:00
										 |  |  |  |                 } else if (rack_type == "两板卡" && ConfigMgr::Instance()->card_type_[button_id - 1] == kCardNone) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                     map_slot_config[button_id].slot_type = slot_type; | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     map_slot_config[button_id].slot_btn->setText(chan_display); | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                     map_slot_config[button_id + 1].slot_type = slot_type; | 
					
						
							| 
									
										
										
										
											2025-03-26 17:00:52 +08:00
										 |  |  |  |                     map_slot_config[button_id + 1].slot_btn->setText(chan_display); | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  |                  if ((card_type == kCardVibSingle || card_type == kCardSpeedSingle || | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  |                             card_type == kCardKeyphaseSingle || card_type == kCardRelaySingle || | 
					
						
							| 
									
										
										
										
											2025-04-23 17:13:05 +08:00
										 |  |  |  |                             card_type == kCardRelaySingleNOK) && ConfigMgr::Instance()->card_type_[button_id - 1] == kCardNone) { | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                     map_slot_config[button_id].slot_type = slot_type; | 
					
						
							|  |  |  |  |                     button->setText(chan_display); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  |                     ConfigMgr::Instance()->card_type_[button_id - 1] = card_type; | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  |                 }else if ((card_type == kCardVibSingle || card_type == kCardSpeedSingle || | 
					
						
							|  |  |  |  |                            card_type == kCardKeyphaseSingle || card_type == kCardRelaySingle || | 
					
						
							|  |  |  |  |                            card_type == kCardRelaySingleNOK) && ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone) { | 
					
						
							|  |  |  |  |                      QMessageBox::information(this, QStringLiteral("提示"), "不要重叠单板卡配置,请在创建新配置之前移除现有的配置!"); | 
					
						
							|  |  |  |  |                      return; | 
					
						
							| 
									
										
										
										
											2025-04-23 17:13:05 +08:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 if (action->text() == "重置模块") { | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |                     if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelayTMRPrimary) { | 
					
						
							| 
									
										
										
										
											2025-03-23 14:03:48 +08:00
										 |  |  |  |                         map_slot_config[button_id].slot_type = ""; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-03-23 14:03:48 +08:00
										 |  |  |  |                         map_slot_config[button_id + 1].slot_type = ""; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id + 1].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-03-23 14:03:48 +08:00
										 |  |  |  |                         map_slot_config[button_id + 2].slot_type = ""; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id + 2].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  |                         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id); | 
					
						
							|  |  |  |  |                         if(base_ptr != nullptr){ | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->RemoveCard(base_ptr); | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->card_type_[button_id - 1] = kCardNone; | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         std::shared_ptr<CardBase> base_ptr_backup = ConfigMgr::Instance()->GetSlotPtr(button_id + 1); | 
					
						
							|  |  |  |  |                         if(base_ptr_backup != nullptr){ | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->RemoveCard(base_ptr_backup); | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->card_type_[button_id] = kCardNone; | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         std::shared_ptr<CardBase> base_ptr_backup2 = ConfigMgr::Instance()->GetSlotPtr(button_id + 2); | 
					
						
							|  |  |  |  |                         if(base_ptr_backup2 != nullptr){ | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->RemoveCard(base_ptr_backup2); | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->card_type_[button_id + 1] = kCardNone; | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |                     } else if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelayTMRBackup) { | 
					
						
							| 
									
										
										
										
											2025-03-23 14:03:48 +08:00
										 |  |  |  |                         map_slot_config[button_id - 1].slot_type = ""; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id - 1].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-03-23 14:03:48 +08:00
										 |  |  |  |                         map_slot_config[button_id].slot_type = ""; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-03-23 14:03:48 +08:00
										 |  |  |  |                         map_slot_config[button_id + 1].slot_type = ""; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id + 1].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |                     }else if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardVibSingle || | 
					
						
							|  |  |  |  |                               ConfigMgr::Instance()->card_type_[button_id - 1] == kCardSpeedSingle || | 
					
						
							|  |  |  |  |                               ConfigMgr::Instance()->card_type_[button_id - 1] == kCardKeyphaseSingle) { | 
					
						
							|  |  |  |  |                         ConfigMgr::Instance()->card_type_[button_id - 1] = kCardNone; | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                         map_slot_config[button_id].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  |                         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id); | 
					
						
							|  |  |  |  |                         if(base_ptr != nullptr) | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->RemoveCard(base_ptr); | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                     }else if (ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelaySingle || | 
					
						
							|  |  |  |  |                               ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelaySingleNOK || | 
					
						
							|  |  |  |  |                               ConfigMgr::Instance()->card_type_[button_id - 1] == kCardRelayTMRPrimary) { | 
					
						
							|  |  |  |  |                         ConfigMgr::Instance()->card_type_[button_id - 1] = kCardNone; | 
					
						
							|  |  |  |  |                         map_slot_config[button_id].slot_btn->setText(""); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  |                         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id); | 
					
						
							|  |  |  |  |                         if(base_ptr != nullptr) | 
					
						
							|  |  |  |  |                             ConfigMgr::Instance()->RemoveCard(base_ptr); | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 } else if (action->text() == "升级固件") { | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |                     sendUpgradePackage(button_id); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |                 } else if (action->text() == "查看版本") { | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |                     getVersion(button_id); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |                 }else if (action->text() == "更新配置") { | 
					
						
							|  |  |  |  |                     ConfigSubCard(button_id); | 
					
						
							|  |  |  |  |                 }else if (action->text() == "获取日志") { | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  |                     GetSubLog(button_id); | 
					
						
							| 
									
										
										
										
											2025-09-18 11:46:35 +08:00
										 |  |  |  |                 }else if (action->text() == "获取电压范围") { | 
					
						
							|  |  |  |  |                     GetVoltageRangeValue(button_id); | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |                 break; // 找到按钮后,跳出循环
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             // 如果没有找到按钮,继续向上查找
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |             menu = qobject_cast<QMenu *>(menu->parent()); | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::OnButtonGroup(QAbstractButton *slot_btn) { | 
					
						
							|  |  |  |  |     if (slot_btn != NULL && ui->pushButton_chan->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         QString object_name =  slot_btn->objectName(); | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |         qDebug() << object_name   ; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |         int button_id = object_name.right(object_name.length() - 15).toInt(); | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         SlotConfig slot_config = map_slot_config[button_id]; | 
					
						
							| 
									
										
										
										
											2025-03-11 16:42:00 +08:00
										 |  |  |  |         map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}"); | 
					
						
							| 
									
										
										
										
											2025-04-21 20:57:37 +08:00
										 |  |  |  |         if(current_slot != -1) | 
					
						
							|  |  |  |  |             map_slot_config[current_slot].slot_label->setStyleSheet(""); | 
					
						
							|  |  |  |  |         current_slot = button_id; | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id); | 
					
						
							|  |  |  |  |         if(base_ptr == nullptr){ | 
					
						
							|  |  |  |  |             ConfigMgr::Instance()->card_type_[button_id - 1] = card_type; | 
					
						
							|  |  |  |  |             if (slot_config.slot_type == "KPM834") { // 键相模块
 | 
					
						
							|  |  |  |  |                 KeyPhase *key_phase = new KeyPhase(button_id,card_type); | 
					
						
							|  |  |  |  |                 key_phase->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 key_phase->show(); | 
					
						
							|  |  |  |  |             } else if (slot_config.slot_type == "DOM810") { // 继电器模块
 | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                 switch (card_type) { | 
					
						
							| 
									
										
										
										
											2025-07-17 20:10:38 +08:00
										 |  |  |  |                     case kCardRelaySingle:{ | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                         SingleRelay *single_relay = new SingleRelay(button_id,card_type); | 
					
						
							|  |  |  |  |                         single_relay->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                         single_relay->show(); | 
					
						
							|  |  |  |  |                     }break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |             } else if (slot_config.slot_type == "HAM824") { // 振动模块
 | 
					
						
							|  |  |  |  |                 Seismic_monitor *seismic_monitor = new Seismic_monitor(button_id,card_type); | 
					
						
							|  |  |  |  |                 seismic_monitor->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 seismic_monitor->show(); | 
					
						
							|  |  |  |  |             } else if (slot_config.slot_type == "OPM844") { // 转速模块
 | 
					
						
							|  |  |  |  |                 Tachometer *tachometer = new Tachometer(button_id,card_type); | 
					
						
							|  |  |  |  |                 tachometer->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 tachometer->show(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         switch(base_ptr->card_type_){ | 
					
						
							|  |  |  |  |             case kCardVibSingle:{ | 
					
						
							|  |  |  |  |                 Seismic_monitor *seismic_monitor = new Seismic_monitor(button_id,card_type); | 
					
						
							|  |  |  |  |                 seismic_monitor->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 seismic_monitor->show(); | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             case kCardKeyphaseSingle:{ | 
					
						
							|  |  |  |  |                 KeyPhase *key_phase = new KeyPhase(button_id,card_type); | 
					
						
							|  |  |  |  |                 key_phase->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 key_phase->show(); | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-04-21 17:23:38 +08:00
										 |  |  |  |             case kCardSpeedSingle:{ | 
					
						
							|  |  |  |  |                 Tachometer *tachometer = new Tachometer(button_id,card_type); | 
					
						
							|  |  |  |  |                 tachometer->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 tachometer->show(); | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-07-17 20:10:38 +08:00
										 |  |  |  |             case kCardRelaySingle:{ | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                 SingleRelay *single_relay = new SingleRelay(button_id,card_type); | 
					
						
							|  |  |  |  |                 single_relay->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 single_relay->show(); | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     if (slot_btn != NULL && ui->pushButton_alarm->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |         QString object_name =  slot_btn->objectName(); | 
					
						
							| 
									
										
										
										
											2025-04-16 13:55:32 +08:00
										 |  |  |  |         int button_id = object_name.right(object_name.length() - 15).toInt(); | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id); | 
					
						
							| 
									
										
										
										
											2025-04-23 17:13:05 +08:00
										 |  |  |  |         if(base_ptr == nullptr) | 
					
						
							|  |  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |         switch(base_ptr->card_type_){ | 
					
						
							|  |  |  |  |             case kCardVibSingle:{ | 
					
						
							|  |  |  |  |                 QString object_name =  slot_btn->objectName(); | 
					
						
							|  |  |  |  |                 int button_id = object_name.right(object_name.length() - 15).toInt(); | 
					
						
							| 
									
										
										
										
											2025-08-04 12:25:12 +08:00
										 |  |  |  |                 DC_Outputs *dc_output = new DC_Outputs(button_id,ConfigMgr::Instance()->card_type_[button_id - 1]); | 
					
						
							|  |  |  |  |                 dc_output->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 dc_output->show(); | 
					
						
							| 
									
										
										
										
											2025-07-28 22:41:24 +08:00
										 |  |  |  |                 // Setpoint *setpoint = new Setpoint(button_id,ConfigMgr::Instance()->card_type_[button_id - 1]);
 | 
					
						
							|  |  |  |  |                 // setpoint->setWindowModality(Qt::ApplicationModal);
 | 
					
						
							|  |  |  |  |                 // setpoint->show();
 | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             case kCardSpeedSingle:{ | 
					
						
							|  |  |  |  |                 QString object_name =  slot_btn->objectName(); | 
					
						
							|  |  |  |  |                 int button_id = object_name.right(object_name.length() - 15).toInt(); | 
					
						
							|  |  |  |  |                 Setpoint_Tachometer *setpoint_tachometer = new Setpoint_Tachometer(button_id,ConfigMgr::Instance()->card_type_[button_id - 1]); | 
					
						
							|  |  |  |  |                 setpoint_tachometer->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |                 setpoint_tachometer->show(); | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-02-13 10:50:09 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-22 20:55:40 +08:00
										 |  |  |  |     if(slot_btn != NULL && ui->pushButton_point_name->isChecked()){ | 
					
						
							|  |  |  |  |         QString object_name =  slot_btn->objectName(); | 
					
						
							|  |  |  |  |         int button_id = object_name.right(object_name.length() - 15).toInt(); | 
					
						
							| 
									
										
										
										
											2025-04-23 17:13:05 +08:00
										 |  |  |  |         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id); | 
					
						
							|  |  |  |  |         if(base_ptr == nullptr) | 
					
						
							|  |  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2025-04-22 20:55:40 +08:00
										 |  |  |  |         PointName *point_name = new PointName(button_id,ConfigMgr::Instance()->card_type_[button_id - 1]); | 
					
						
							|  |  |  |  |         point_name->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |         point_name->show(); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::on_pushButton_slot_clicked() { | 
					
						
							|  |  |  |  |     if (ui->pushButton_chan->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_chan->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_alarm->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_alarm->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_point_name->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_point_name->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::on_pushButton_chan_clicked() { | 
					
						
							|  |  |  |  |     if (ui->pushButton_slot->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_slot->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_alarm->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_alarm->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_point_name->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_point_name->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::on_pushButton_alarm_clicked() { | 
					
						
							|  |  |  |  |     if (ui->pushButton_slot->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_slot->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_chan->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_chan->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_point_name->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_point_name->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::on_pushButton_point_name_clicked() { | 
					
						
							|  |  |  |  |     if (ui->pushButton_slot->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_slot->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_chan->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_chan->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     if (ui->pushButton_alarm->isChecked()) { | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  |         ui->pushButton_alarm->setChecked(false); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-11 19:54:22 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::onMenuAction_relay() { | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << " onMenuAction_relay "   ; | 
					
						
							| 
									
										
										
										
											2025-03-04 16:00:19 +08:00
										 |  |  |  |     RelaySetting *relay_setting = new RelaySetting(); | 
					
						
							|  |  |  |  |     relay_setting->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |     relay_setting->show(); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  | uint8_t calculate_crc(const QByteArray &data) { | 
					
						
							|  |  |  |  |     uint8_t crc = 0; | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |     for (int i = 0; i < data.size(); ++i) { | 
					
						
							|  |  |  |  |         crc += static_cast<uint8_t>(data[i]);  // 累加每个字节
 | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return crc; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::on_pushButton_save_clicked() { | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-07 19:35:59 +08:00
										 |  |  |  |     QString file_name = ""; | 
					
						
							|  |  |  |  |     if(tsi_config_file == ""){ | 
					
						
							|  |  |  |  |         QString strTips =QString("请输入保存的文件名称"); | 
					
						
							|  |  |  |  |         bool ok = false; | 
					
						
							|  |  |  |  |         QString defaultInput = "tsi_config_file"; | 
					
						
							|  |  |  |  |         file_name = QInputDialog::getText(this, tr("输入名称对话框"), strTips, QLineEdit::Normal, defaultInput, &ok); | 
					
						
							|  |  |  |  |         if(!ok) return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if( file_name == ""){ | 
					
						
							|  |  |  |  |             QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的文件名称!")); | 
					
						
							|  |  |  |  |             return ; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         QString filepath = QFileDialog::getExistingDirectory(this, tr("选择文件夹"), tr("")); | 
					
						
							|  |  |  |  |         if(filepath == "") | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         file_name = filepath + "\\"+file_name +".json"; | 
					
						
							|  |  |  |  |         ConfigMgr::Instance()->Save(file_name); | 
					
						
							|  |  |  |  |         tsi_config_file = file_name; | 
					
						
							|  |  |  |  |     }else { | 
					
						
							|  |  |  |  |         ConfigMgr::Instance()->Save(tsi_config_file); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 14:44:58 +08:00
										 |  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-10 10:48:43 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-12-17 18:53:41 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::on_pushButton_open_clicked() { | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-06 16:31:13 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     tsi_config_file = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*.json")); | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  |     QFileInfo fileinfo; | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     fileinfo = QFileInfo(tsi_config_file); | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  |     QString file_suffix = fileinfo.suffix(); | 
					
						
							|  |  |  |  |     QString FileName = fileinfo.fileName(); | 
					
						
							|  |  |  |  |     if (FileName.isEmpty()) { | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     QFile file(tsi_config_file); | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  |     if (!file.open(QIODevice::ReadOnly)) { | 
					
						
							|  |  |  |  |         qWarning() << "Failed to open update file."; | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-07-06 16:31:13 +08:00
										 |  |  |  |     QList<QAbstractButton *> buttonList = btnGroup_slot->buttons(); | 
					
						
							| 
									
										
										
										
											2025-08-07 19:35:59 +08:00
										 |  |  |  |     for (int i = 1; i < buttonList.count(); i++) { | 
					
						
							| 
									
										
										
										
											2025-07-06 16:31:13 +08:00
										 |  |  |  |         buttonList[i]->setText(""); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     for (int i = 0; i < SLOT_NUM; i++) { | 
					
						
							|  |  |  |  |         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1); | 
					
						
							|  |  |  |  |         if(base_ptr != nullptr){ | 
					
						
							|  |  |  |  |             ConfigMgr::Instance()->RemoveCard(base_ptr); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     ConfigMgr::Instance()->Load(tsi_config_file); | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |     for (int i = 0; i < buttonList.count(); i++) { | 
					
						
							|  |  |  |  |         std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1); | 
					
						
							|  |  |  |  |         if(base_ptr != nullptr){ | 
					
						
							|  |  |  |  |             switch (base_ptr->card_type_) { | 
					
						
							|  |  |  |  |                 case kCardVibSingle :{ | 
					
						
							|  |  |  |  |                     buttonList[i + 1]->setText("振动"); | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 case kCardKeyphaseSingle:{ | 
					
						
							|  |  |  |  |                     buttonList[i + 1]->setText("键相"); | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 case kCardSpeedSingle:{ | 
					
						
							|  |  |  |  |                     buttonList[i + 1]->setText("转速"); | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                 case kCardRelaySingle: | 
					
						
							|  |  |  |  |                 case kCardRelaySingleNOK: | 
					
						
							| 
									
										
										
										
											2025-04-21 20:30:12 +08:00
										 |  |  |  |                 case kCardRelayTMRBackup: | 
					
						
							| 
									
										
										
										
											2025-04-19 16:25:33 +08:00
										 |  |  |  |                 case kCardRelayTMRPrimary:{ | 
					
						
							|  |  |  |  |                     buttonList[i + 1]->setText("继电器"); | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-04-10 16:45:20 +08:00
										 |  |  |  |                 default: | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-02-18 10:55:51 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  | uint32_t myHtonl(uint32_t value) { | 
					
						
							|  |  |  |  |     return ((value >> 24) & 0x000000FF) | // 提取最高的8位
 | 
					
						
							|  |  |  |  |            ((value >> 8)  & 0x0000FF00) | // 提取中间的8位
 | 
					
						
							|  |  |  |  |            ((value << 8)  & 0x00FF0000) | // 提取次高的8位
 | 
					
						
							|  |  |  |  |            ((value << 24) & 0xFF000000);   // 提取最低的8位
 | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::sendUpgradePackage(int slot) { | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |     QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*")); | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << filepath  << slot   ; | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |     QFileInfo fileinfo; | 
					
						
							|  |  |  |  |     fileinfo = QFileInfo(filepath); | 
					
						
							|  |  |  |  |     QString file_suffix = fileinfo.suffix(); | 
					
						
							|  |  |  |  |     QString FileName = fileinfo.fileName(); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     if (FileName.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |     QFile file(filepath); | 
					
						
							|  |  |  |  |     if (!file.open(QIODevice::ReadOnly)) { | 
					
						
							|  |  |  |  |         qWarning() << "Failed to open update file."; | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     // 读取文件内容
 | 
					
						
							|  |  |  |  |     QByteArray fileData = file.readAll(); | 
					
						
							|  |  |  |  |     int fileSize = fileData.size(); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     if (fileSize > 10 * 1024 * 1024) { | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |         QMessageBox::information(this, QStringLiteral("提示"), "文件大小超过10M,请重新选择!"); | 
					
						
							|  |  |  |  |         file.close(); | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  | //    for (int var = 0; var < 10; ++var) {
 | 
					
						
							|  |  |  |  | //        qDebug() << "Byte" << var << ":" << static_cast<uint8_t>(fileData[var]);
 | 
					
						
							|  |  |  |  | //    }
 | 
					
						
							|  |  |  |  | //    for (int var = fileSize - 10; var < fileSize; ++var) {
 | 
					
						
							|  |  |  |  | //        qDebug() << "Byte" << var << ":" << static_cast<uint8_t>(fileData[var]);
 | 
					
						
							|  |  |  |  | //    }
 | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "fileSize" << fileSize  ; | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |     // 计算文件的 CRC 校验和
 | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "filheader.slot"  << slot  ; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     UpgradeCardReq upgrade_car_req = { {0xAA, 0x55, 0xAA}, kUpgradeCard, 1, fileSize, 0, 0, {} }; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     if (slot == 0) { | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |         upgrade_car_req.card_id = 0xFF; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |         upgrade_car_req.card_id = slot & 0xFF; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  |     upgrade_car_req.crc = calculate_crc(fileData); | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     qDebug() << "filheader.crc" << upgrade_car_req.crc << "card_id" << upgrade_car_req.card_id << "header len" << upgrade_car_req.len; | 
					
						
							| 
									
										
										
										
											2025-03-01 17:36:57 +08:00
										 |  |  |  |     char *send_buf = NULL; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     send_buf = (char *)malloc(sizeof(UpgradeCardReq) + fileData.size() + 1); | 
					
						
							|  |  |  |  |     memset(send_buf, 0, sizeof(UpgradeCardReq) + fileData.size() + 1); | 
					
						
							|  |  |  |  |     memcpy(send_buf, &upgrade_car_req, sizeof(UpgradeCardReq)); | 
					
						
							|  |  |  |  |     memcpy(send_buf + sizeof(UpgradeCardReq), fileData.data(), fileData.size()); | 
					
						
							|  |  |  |  |     int length =  sizeof(UpgradeCardReq) + fileData.size(); | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |     const int MAX_CHUNK_SIZE = 50 * 1024;  // 64 KB
 | 
					
						
							|  |  |  |  |     qint64 bytesSent = 0; | 
					
						
							|  |  |  |  |     qint64 totalBytes = length; | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "totalBytes" << totalBytes   ; | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |     while (bytesSent < totalBytes) { | 
					
						
							|  |  |  |  |         qint64 chunkSize = 0; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |         if (MAX_CHUNK_SIZE < totalBytes - bytesSent) { | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |             chunkSize = MAX_CHUNK_SIZE; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |             chunkSize = totalBytes - bytesSent; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |         qint64 bytesWritten = m_tcpClient->sendData(send_buf + bytesSent, chunkSize); | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |         qDebug() << "bytesWritten" << bytesWritten << "bytesSent" << bytesSent   ; | 
					
						
							| 
									
										
										
										
											2025-03-01 19:22:48 +08:00
										 |  |  |  |         if (bytesWritten == -1) { | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         bytesSent += bytesWritten; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "bytesSent" << bytesSent   ; | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |     progressBar->reset(); | 
					
						
							|  |  |  |  |     progressBar->setVisible(true); | 
					
						
							|  |  |  |  |     QString upgrade_text = QStringLiteral("正在上传板卡 [ %1 ] ……  %p%").arg(slot); | 
					
						
							|  |  |  |  |     progressBar->setTextVisible(true); | 
					
						
							|  |  |  |  |     progressBar->setFormat(upgrade_text); | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  |     file.close(); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     if (send_buf != NULL) { | 
					
						
							| 
									
										
										
										
											2025-03-01 17:36:57 +08:00
										 |  |  |  |         free(send_buf); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-03-01 13:40:11 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::getVersion(int slot) { | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |     slot_no = slot; | 
					
						
							| 
									
										
										
										
											2025-03-14 09:33:14 +08:00
										 |  |  |  |     qDebug() << "slot"  << slot  ; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     GetVersionReq get_version_req =  { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1, 0 }; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     if (slot == 0) { | 
					
						
							| 
									
										
										
										
											2025-03-03 21:57:15 +08:00
										 |  |  |  |         get_version_req.card_id = 0xFF; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2025-03-03 21:57:15 +08:00
										 |  |  |  |         get_version_req.card_id = slot & 0xFF; | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     char send_buf[20] = {0}; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     memcpy(send_buf, (char *)&get_version_req, sizeof(GetVersionReq)); | 
					
						
							|  |  |  |  |     int length = sizeof(GetVersionReq); | 
					
						
							| 
									
										
										
										
											2025-03-20 14:38:14 +08:00
										 |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData(send_buf, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  | void MainWindow::ConfigSubCard(int slot){ | 
					
						
							|  |  |  |  |     slot_no = slot; | 
					
						
							|  |  |  |  |     qDebug() << "slot"  << slot  ; | 
					
						
							|  |  |  |  |     ConfigSubCardReq config_sub_card_req =  { {0xAA, 0x55, 0xAA}, kConfigSubCard, 1, 0 }; | 
					
						
							|  |  |  |  |     if (slot == 0) { | 
					
						
							|  |  |  |  |         config_sub_card_req.card_id = 0xFF; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |         config_sub_card_req.card_id = slot & 0xFF; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     char send_buf[20] = {0}; | 
					
						
							|  |  |  |  |     memcpy(send_buf, (char *)&config_sub_card_req, sizeof(ConfigSubCardReq)); | 
					
						
							|  |  |  |  |     int length = sizeof(ConfigSubCardReq); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData(send_buf, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::GetSubLog(int slot){ | 
					
						
							|  |  |  |  |     slot_no = slot; | 
					
						
							|  |  |  |  |     qDebug() << "slot"  << slot  ; | 
					
						
							|  |  |  |  |     GetSubCardLogReq get_sub_card_log_req =  { {0xAA, 0x55, 0xAA}, kGetLogInfo, 1, 0 }; | 
					
						
							|  |  |  |  |     if (slot == 0) { | 
					
						
							|  |  |  |  |         get_sub_card_log_req.card_id = 0xFF; | 
					
						
							|  |  |  |  |     } else { | 
					
						
							|  |  |  |  |         get_sub_card_log_req.card_id = slot & 0xFF; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     char send_buf[20] = {0}; | 
					
						
							|  |  |  |  |     memcpy(send_buf, (char *)&get_sub_card_log_req, sizeof(GetSubCardLogReq)); | 
					
						
							|  |  |  |  |     int length = sizeof(GetSubCardLogReq); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData(send_buf, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-09-18 11:46:35 +08:00
										 |  |  |  | void MainWindow::GetVoltageRangeValue(int slot){ | 
					
						
							|  |  |  |  |     slot_no = slot; | 
					
						
							|  |  |  |  |     qDebug() << "slot"  << slot  ; | 
					
						
							|  |  |  |  |     GetSubCardVoltageRangeReq get_sub_card_log_req =  { {0xAA, 0x55, 0xAA}, kGetVoltageRangeValue, 1, 0 }; | 
					
						
							|  |  |  |  |     SlotConfig slot_config = map_slot_config[slot]; | 
					
						
							|  |  |  |  |     if (slot == 0 || slot_config.slot_type == "DOM810") { | 
					
						
							|  |  |  |  |         QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请选择正确的板卡!")); | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     get_sub_card_log_req.card_id = slot & 0xFF; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     char send_buf[20] = {0}; | 
					
						
							|  |  |  |  |     memcpy(send_buf, (char *)&get_sub_card_log_req, sizeof(GetSubCardVoltageRangeReq)); | 
					
						
							|  |  |  |  |     int length = sizeof(GetSubCardVoltageRangeReq); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData(send_buf, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  | void MainWindow::readData(const QByteArray &data) { | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |     qDebug() << "Received from server:" << data; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     uint8_t cmd = data[3]; | 
					
						
							|  |  |  |  |     if (cmd == kGetVersionInfo) { | 
					
						
							| 
									
										
										
										
											2025-03-03 21:57:15 +08:00
										 |  |  |  |         VersionRsp version_rsp; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |         memcpy(&version_rsp, data.data(), sizeof(VersionRsp)); | 
					
						
							|  |  |  |  |         QString strVerion = QString("第 %1 板卡\nFPGA 版本:%2\n软件版本:%3\nFPGA版本日期:%4").arg(slot_no).arg(version_rsp.fpga).arg(version_rsp.sw).arg(version_rsp.fpga_date); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |         QMessageBox::information(this, QStringLiteral("提示"), strVerion); | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     } else if (cmd == kUpgradeCard) { | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |         UpgradeRsp resp; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |         memcpy(&resp, data.data(), sizeof(UpgradeRsp)); | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  |         if (resp.code == 0) { | 
					
						
							|  |  |  |  |             statusBar()->showMessage("上传成功!", 3000); | 
					
						
							|  |  |  |  |         }else { | 
					
						
							|  |  |  |  |             statusBar()->showMessage("上传失败!", 3000); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     } else if (cmd == kUpgradeProgress) { | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |         UpgradeRsp upgrade_resp; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |         memcpy(&upgrade_resp, data.data(), sizeof(UpgradeRsp)); | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |         progressBar->setValue(upgrade_resp.code); | 
					
						
							| 
									
										
										
										
											2025-03-29 18:05:12 +08:00
										 |  |  |  |         if (upgrade_resp.code == 100) { | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |             progressBar->setVisible(false); | 
					
						
							|  |  |  |  |             statusBar()->showMessage("升级完成!", 3000); // 显示3秒
 | 
					
						
							| 
									
										
										
										
											2025-03-03 21:57:15 +08:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-13 15:10:35 +08:00
										 |  |  |  |         //qDebug() << "Server response: " << upgrade_resp.code;
 | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     } else if(cmd == kDownloadConfigFile){ | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |         //qDebug() << "header.len" << header.len;
 | 
					
						
							|  |  |  |  |         char *config_file = NULL; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |         DownloadConfigRsp download_config; | 
					
						
							|  |  |  |  |         memcpy(&download_config,data,sizeof(DownloadConfigRsp)); | 
					
						
							|  |  |  |  |         config_file = (char*)malloc(download_config.len + 1); | 
					
						
							|  |  |  |  |         memset(config_file,0,download_config.len + 1); | 
					
						
							|  |  |  |  |         memcpy(config_file, data.data() + sizeof(DownloadConfigRsp), download_config.len); | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |         QString filename_ = QCoreApplication::applicationDirPath() + "\\config\\tsi_config_file_download.json"; | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |         QFile file(filename_); | 
					
						
							|  |  |  |  |         file.open(QIODevice::WriteOnly); | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |         file.write(config_file,download_config.len); | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |         file.close(); | 
					
						
							|  |  |  |  |         if(config_file != NULL) | 
					
						
							|  |  |  |  |             free(config_file); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |         statusBar()->showMessage("下载配置成功!", 3000); | 
					
						
							|  |  |  |  |     }else if(cmd == kConfigSubCard){ | 
					
						
							|  |  |  |  |         ConfigSubCardRsp config_sub_card; | 
					
						
							|  |  |  |  |         memcpy(&config_sub_card, data.data(), sizeof(ConfigSubCardRsp)); | 
					
						
							|  |  |  |  |         if(config_sub_card.code == 0){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("配置成功!", 3000); | 
					
						
							|  |  |  |  |         }else if(config_sub_card.code == 1){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("没有配置文件!", 3000); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     }else if(cmd == kGetLogInfo){ | 
					
						
							|  |  |  |  |         char *log_file = NULL; | 
					
						
							|  |  |  |  |         GetSubCardLogRsp sub_card_log_rsp; | 
					
						
							|  |  |  |  |         memcpy(&sub_card_log_rsp,data,sizeof(GetSubCardLogRsp)); | 
					
						
							|  |  |  |  |         log_file = (char*)malloc(sub_card_log_rsp.len + 1); | 
					
						
							|  |  |  |  |         memset(log_file,0,sub_card_log_rsp.len + 1); | 
					
						
							|  |  |  |  |         memcpy(log_file, data.data() + sizeof(GetSubCardLogRsp), sub_card_log_rsp.len); | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  |         QDateTime now_time = QDateTime::currentDateTime(); | 
					
						
							|  |  |  |  |         QString file_name = QString("log_%1_%2.tar.gz").arg(sub_card_log_rsp.card_id).arg(now_time.toString("yyyy-MM-dd_HHmmss")); | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |         QString log_path = QCoreApplication::applicationDirPath() + "\\log\\" + file_name; | 
					
						
							|  |  |  |  |         QFile file(log_path); | 
					
						
							|  |  |  |  |         file.open(QIODevice::WriteOnly); | 
					
						
							|  |  |  |  |         file.write(log_file,sub_card_log_rsp.len); | 
					
						
							|  |  |  |  |         file.close(); | 
					
						
							|  |  |  |  |         if(log_file != NULL) | 
					
						
							|  |  |  |  |             free(log_file); | 
					
						
							|  |  |  |  |     }else if(cmd == kTimingCmd){ | 
					
						
							|  |  |  |  |         SetTimingRsp set_time_rsp; | 
					
						
							|  |  |  |  |         memcpy(&set_time_rsp, data.data(), sizeof(SetTimingRsp)); | 
					
						
							|  |  |  |  |         if(set_time_rsp.code == 0){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("校时成功!", 3000); | 
					
						
							|  |  |  |  |         }else if(set_time_rsp.code == 1){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("校时失败!", 3000); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     }else if(cmd == kUploadConfigFile){ | 
					
						
							|  |  |  |  |         UploadConfigRsp upload_config_rsp; | 
					
						
							|  |  |  |  |         memcpy(&upload_config_rsp, data.data(), sizeof(UploadConfigRsp)); | 
					
						
							|  |  |  |  |         if(upload_config_rsp.code == 0){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("上传成功!", 2000); | 
					
						
							|  |  |  |  |         }else if(upload_config_rsp.code == 1){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("上传失败!", 2000); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-06 22:11:14 +08:00
										 |  |  |  |     }else if(cmd == kConfigProgress){ | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |         ConfigSubCardProgress config_sub_card_progress; | 
					
						
							|  |  |  |  |         memcpy(&config_sub_card_progress, data.data(), sizeof(ConfigSubCardProgress)); | 
					
						
							|  |  |  |  |         QString status ; | 
					
						
							|  |  |  |  |         if(config_sub_card_progress.code == 0 && config_sub_card_progress.stage == 1){ | 
					
						
							|  |  |  |  |             status = QString("板卡 %1 配置成功!").arg(config_sub_card_progress.subcard_id); | 
					
						
							|  |  |  |  |             map_slot_config[config_sub_card_progress.subcard_id].slot_label->setStyleSheet(""); | 
					
						
							|  |  |  |  |             statusBar()->showMessage(status, 2000); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if(config_sub_card_progress.code == 1){ | 
					
						
							|  |  |  |  |             status = QString("板卡 %1 配置失败!").arg(config_sub_card_progress.subcard_id); | 
					
						
							|  |  |  |  |             map_slot_config[config_sub_card_progress.subcard_id].slot_label->setStyleSheet("QLabel { color :#FF0000; font: bold 16px}"); | 
					
						
							|  |  |  |  |             statusBar()->showMessage(status, 2000); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-08 21:59:34 +08:00
										 |  |  |  |     }else if(cmd == kConfigDeviceID){ | 
					
						
							|  |  |  |  |         DeviceIDConfigRsp device_config_rsp; | 
					
						
							|  |  |  |  |         memcpy(&device_config_rsp, data.data(), sizeof(DeviceIDConfigRsp)); | 
					
						
							|  |  |  |  |         if(device_config_rsp.code == 0){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("配置成功!", 2000); | 
					
						
							|  |  |  |  |         }else if(device_config_rsp.code == 1){ | 
					
						
							|  |  |  |  |             statusBar()->showMessage("配置失败!", 2000); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if(device_config_rsp.sub_cmd == 0){ | 
					
						
							|  |  |  |  |             QString str = QString("设备ID: %1").arg(device_config_rsp.device_id); | 
					
						
							|  |  |  |  |             QMessageBox::information(this, QStringLiteral("提示"), str); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-03 21:57:15 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::on_pushButton_download_clicked() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     DownloadConfigReq download_config_req = { {0xAA, 0x55, 0xAA}, kDownloadConfigFile, 1 }; | 
					
						
							|  |  |  |  |     int length = sizeof(download_config_req); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData((char*)&download_config_req, length); | 
					
						
							| 
									
										
										
										
											2025-04-11 20:27:45 +08:00
										 |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-17 14:06:21 +08:00
										 |  |  |  | void MainWindow::onConnect(){ | 
					
						
							|  |  |  |  |     Connect *connect_config = new Connect(); | 
					
						
							|  |  |  |  |     connect_config->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |     connect_config->show(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::onDisconnect(){ | 
					
						
							|  |  |  |  |     m_tcpClient->disconnectFromServer(); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-04-22 20:55:40 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::onEthConfig(){ | 
					
						
							|  |  |  |  |     EthConfig *eth_config = new EthConfig(); | 
					
						
							|  |  |  |  |     eth_config->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |     eth_config->show(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::onMACConfig(){ | 
					
						
							|  |  |  |  |     MacConfig *mac_config = new MacConfig(); | 
					
						
							|  |  |  |  |     mac_config->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |     mac_config->show(); | 
					
						
							| 
									
										
										
										
											2025-08-06 22:11:14 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::onMqttConfig(){ | 
					
						
							|  |  |  |  |     MqttConfig *mqtt_config = new MqttConfig(); | 
					
						
							|  |  |  |  |     mqtt_config->setWindowModality(Qt::ApplicationModal); | 
					
						
							|  |  |  |  |     mqtt_config->show(); | 
					
						
							| 
									
										
										
										
											2025-04-22 20:55:40 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-08-08 21:59:34 +08:00
										 |  |  |  | void MainWindow::onGetDeviceID(){ | 
					
						
							|  |  |  |  |     DeviceIDConfigReq config_device_id = { {0xAA, 0x55, 0xAA}, kConfigDeviceID, 1,0,{}}; | 
					
						
							|  |  |  |  |     int length = sizeof(DeviceIDConfigReq); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData((char*)&config_device_id, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::onConfigDeviceID(){ | 
					
						
							| 
									
										
										
										
											2025-08-09 15:44:30 +08:00
										 |  |  |  |     QString strTips =QString("请输入0到99之间的数值"); | 
					
						
							| 
									
										
										
										
											2025-08-08 21:59:34 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     bool ok = false; | 
					
						
							| 
									
										
										
										
											2025-08-09 15:44:30 +08:00
										 |  |  |  |     int value = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, 0, 0, 99, 1, &ok); | 
					
						
							| 
									
										
										
										
											2025-08-08 21:59:34 +08:00
										 |  |  |  |     if(!ok) return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     if(value < 1){ | 
					
						
							|  |  |  |  |         QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的数字!")); | 
					
						
							|  |  |  |  |         return ; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     DeviceIDConfigReq config_device_id = { {0xAA, 0x55, 0xAA}, kConfigDeviceID, 1,1,{}}; | 
					
						
							|  |  |  |  |     config_device_id.device_id = value; | 
					
						
							|  |  |  |  |     int length = sizeof(DeviceIDConfigReq); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData((char*)&config_device_id, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  | void MainWindow::onSetTime(){ | 
					
						
							|  |  |  |  |     SetTimingReq set_time_req = { {0xAA, 0x55, 0xAA}, kTimingCmd, 1,0 }; | 
					
						
							|  |  |  |  |     int length = sizeof(SetTimingReq); | 
					
						
							|  |  |  |  |     set_time_req.ts = QDateTime::currentSecsSinceEpoch(); | 
					
						
							|  |  |  |  |     qint64 bytesWritten = m_tcpClient->sendData((char*)&set_time_req, length); | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     qDebug() << "bytesWritten: " << bytesWritten; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | void MainWindow::UploadConfigFile(uint8_t sub_cmd){ | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     QMessageBox *box = new QMessageBox(QMessageBox::Question, "提示", "确认上传配置文件?", QMessageBox::Yes | QMessageBox::No, this); | 
					
						
							|  |  |  |  |     box->button(QMessageBox::Yes)->setText("确认"); | 
					
						
							|  |  |  |  |     box->button(QMessageBox::No)->setText("取消"); | 
					
						
							|  |  |  |  |     int res = box->exec(); | 
					
						
							|  |  |  |  |     if(QMessageBox::No == res){ | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     // 读取文件内容
 | 
					
						
							|  |  |  |  |     if(tsi_config_file == ""){ | 
					
						
							|  |  |  |  |         QMessageBox::information(this, QStringLiteral("提示"), "请先打开配置文件!"); | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     QFile file(tsi_config_file); | 
					
						
							|  |  |  |  |     if (!file.open(QIODevice::ReadOnly)) { | 
					
						
							|  |  |  |  |         qWarning() << "Failed to open config file."; | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     QByteArray fileData = file.readAll(); | 
					
						
							|  |  |  |  |     int fileSize = fileData.size(); | 
					
						
							|  |  |  |  |     if (fileSize > 10 * 1024 * 1024) { | 
					
						
							|  |  |  |  |         QMessageBox::information(this, QStringLiteral("提示"), "文件大小超过10M,请重新选择!"); | 
					
						
							|  |  |  |  |         file.close(); | 
					
						
							|  |  |  |  |         return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     qDebug() << "fileSize" << fileSize  ; | 
					
						
							|  |  |  |  |     // 创建 PackageHead 结构体
 | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  |     UploadConfigReq upload_config_req = { {0xAA, 0x55, 0xAA}, kUploadConfigFile,1, fileSize, sub_cmd, 0, {} }; | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     // 计算文件的 CRC 校验和
 | 
					
						
							| 
									
										
										
										
											2025-05-17 10:58:08 +08:00
										 |  |  |  |     upload_config_req.crc = calculate_crc(fileData); | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     upload_config_req.len = fileSize; | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     char *send_buf = NULL; | 
					
						
							| 
									
										
										
										
											2025-05-14 23:14:50 +08:00
										 |  |  |  |     send_buf = (char *)malloc(sizeof(UploadConfigReq) + fileData.size() + 1); | 
					
						
							|  |  |  |  |     memset(send_buf, 0, sizeof(UploadConfigReq) + fileData.size() + 1); | 
					
						
							|  |  |  |  |     memcpy(send_buf, &upload_config_req, sizeof(UploadConfigReq)); | 
					
						
							|  |  |  |  |     memcpy(send_buf + sizeof(UploadConfigReq), fileData.data(), fileData.size()); | 
					
						
							|  |  |  |  |     int length = sizeof(UploadConfigReq) + fileData.size(); | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  |     const int MAX_CHUNK_SIZE = 50 * 1024;  // 50 KB
 | 
					
						
							|  |  |  |  |     qint64 bytesSent = 0; | 
					
						
							|  |  |  |  |     qint64 totalBytes = length; | 
					
						
							|  |  |  |  |     qDebug() << "totalBytes" << totalBytes   ; | 
					
						
							|  |  |  |  |     while (bytesSent < totalBytes) { | 
					
						
							|  |  |  |  |         qint64 chunkSize = 0; | 
					
						
							|  |  |  |  |         if (MAX_CHUNK_SIZE < totalBytes - bytesSent) { | 
					
						
							|  |  |  |  |             chunkSize = MAX_CHUNK_SIZE; | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             chunkSize = totalBytes - bytesSent; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         qint64 bytesWritten = m_tcpClient->sendData(send_buf + bytesSent, chunkSize); | 
					
						
							|  |  |  |  |         qDebug() << "bytesWritten" << bytesWritten << "bytesSent" << bytesSent  << "chunkSize" << chunkSize ; | 
					
						
							|  |  |  |  |         if (bytesWritten == -1) { | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         bytesSent += bytesWritten; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     qDebug() << "bytesSent" << bytesSent; | 
					
						
							|  |  |  |  |     m_tcpClient->waitForRead(); | 
					
						
							|  |  |  |  |     file.close(); | 
					
						
							|  |  |  |  |     if (send_buf != NULL) { | 
					
						
							|  |  |  |  |         free(send_buf); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-15 18:09:43 +08:00
										 |  |  |  | void MainWindow::on_pushButton_upload_clicked(){ | 
					
						
							|  |  |  |  |     UploadConfigFile(0x0); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void MainWindow::on_pushButton_upload_config_clicked(){ | 
					
						
							|  |  |  |  |     UploadConfigFile(0x1); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-06 10:17:16 +08:00
										 |  |  |  | 
 |