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-03-13 15:10:35 +08:00
|
|
|
|
|
2025-02-11 19:54:22 +08:00
|
|
|
|
#include "keyphase.h"
|
|
|
|
|
#include "singlerelay.h"
|
|
|
|
|
#include "tachometer.h"
|
|
|
|
|
#include "seismic_monitor.h"
|
2025-02-13 10:50:09 +08:00
|
|
|
|
#include "setpoint.h"
|
2025-02-11 19:54:22 +08:00
|
|
|
|
#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-03-14 09:33:14 +08:00
|
|
|
|
#include "common.h"
|
2025-03-13 15:10:35 +08:00
|
|
|
|
|
2025-03-04 16:00:19 +08:00
|
|
|
|
QString g_strServerIp;
|
2024-12-17 18:53:41 +08:00
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2025-03-04 16:00:19 +08:00
|
|
|
|
QMenuBar* menuBar = this->menuBar();
|
|
|
|
|
this->setMenuBar(menuBar); //添加到对象树
|
|
|
|
|
menuBar->addMenu(ui->menu_tool);
|
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");
|
|
|
|
|
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-10 10:48:43 +08:00
|
|
|
|
|
2025-02-11 19:54:22 +08:00
|
|
|
|
ui->pushButton_slot->setChecked(true);
|
|
|
|
|
readJsonFile(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
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-03-01 13:40:11 +08:00
|
|
|
|
QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini",QSettings::IniFormat);
|
2025-02-11 19:54:22 +08:00
|
|
|
|
|
2025-03-04 16:00:19 +08:00
|
|
|
|
g_strServerIp = settingsread.value("Server/IP").toString();
|
2025-03-13 15:10:35 +08:00
|
|
|
|
connectServer();
|
2025-03-05 09:33:48 +08:00
|
|
|
|
// 设置自定义日志处理函数
|
|
|
|
|
#ifndef QT_DEBUG
|
|
|
|
|
qInstallMessageHandler(messageHandler);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-12-17 18:53:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
2025-03-13 15:10:35 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::connectServer()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 连接服务器
|
|
|
|
|
client.connectToServer(g_strServerIp, 10000);
|
|
|
|
|
//client.sendData("send_buf", 1);
|
|
|
|
|
// // 监听信号
|
|
|
|
|
// QObject::connect(&client, &MyTcpClient::connected, []() {
|
|
|
|
|
// qDebug() << "Client connected!";
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// // QObject::connect(&client, &MyTcpClient::dataReceived, [](const QByteArray &data) {
|
|
|
|
|
// // qDebug() << "Received from server:" << data;
|
|
|
|
|
// // });
|
|
|
|
|
connect(&client, SIGNAL(dataReceived(const QByteArray&)), this, SLOT(readData(const QByteArray&)));
|
|
|
|
|
connect(&client, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
|
|
|
|
|
// // QObject::connect(&client, &MyTcpClient::errorOccurred, [](const QString &error) {
|
|
|
|
|
// // qDebug() << "Error:" << error;
|
|
|
|
|
// // });
|
|
|
|
|
// socket = new QTcpSocket(this);
|
|
|
|
|
// connect(socket, &QTcpSocket::connected, this, &MainWindow::onConnected);
|
|
|
|
|
// connect(socket, &QTcpSocket::readyRead, this, &MainWindow::readData);
|
|
|
|
|
// socket->connectToHost(g_strServerIp, 10000);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 16:42:00 +08:00
|
|
|
|
void MainWindow::initStyle()
|
|
|
|
|
{
|
|
|
|
|
//加载样式表
|
|
|
|
|
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-02-11 19:54:22 +08:00
|
|
|
|
void MainWindow::readJsonFile(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
// 创建文件对象
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
qDebug() << "Cannot open file for reading:" << filePath;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QString content = file.readAll();
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
QByteArray jsonData = content.toUtf8();
|
|
|
|
|
|
|
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
|
|
|
if (jsonDoc.isNull()) {
|
|
|
|
|
qDebug() << "Cannot parse JSON document";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
|
|
|
|
|
qDebug() << "JSON document is not an object or an array";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-03-03 21:57:15 +08:00
|
|
|
|
int slot_id = 0;
|
2025-02-11 19:54:22 +08:00
|
|
|
|
QJsonArray jsonArray = jsonDoc.array();
|
|
|
|
|
for (const QJsonValue &value : jsonArray) {
|
|
|
|
|
SlotConfig slot_config;
|
|
|
|
|
if (value.isObject()) { // 处理数组中的对象,例如每个对象代表一个记录或用户等。
|
|
|
|
|
QJsonObject obj = value.toObject();
|
|
|
|
|
slot_config.slot = obj["slot"].toInt();
|
|
|
|
|
slot_config.slot_type = obj["slot_type"].toInt();
|
2025-02-13 10:50:09 +08:00
|
|
|
|
slot_config.chan_display = obj["chan_display"].toString();
|
2025-02-11 19:54:22 +08:00
|
|
|
|
slot_config.rack_type = obj["rack_type"].toString();
|
|
|
|
|
map_slot_config.insert(slot_id,slot_config);
|
|
|
|
|
slot_id ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-10 10:48:43 +08:00
|
|
|
|
void MainWindow::createMenu()
|
|
|
|
|
{
|
|
|
|
|
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
|
|
|
|
for (int i = 0; i < buttonList.count(); i++){
|
2025-03-03 21:57:15 +08:00
|
|
|
|
buttonList[i]->setText(map_slot_config[i].chan_display);
|
2025-03-11 16:42:00 +08:00
|
|
|
|
createMenu(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
2025-03-03 21:57:15 +08:00
|
|
|
|
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-02-11 19:54:22 +08:00
|
|
|
|
// else
|
|
|
|
|
// createMenuSet(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
|
|
|
|
{
|
|
|
|
|
// 创建主菜单
|
|
|
|
|
QMenu *mainMenu = new QMenu(rootTitle, parent);
|
|
|
|
|
|
|
|
|
|
// 创建第一层子菜单:/30 振电器模块
|
|
|
|
|
QMenu *monitors = new QMenu("监视器", mainMenu);
|
|
|
|
|
QMenu *relays = new QMenu("/30 继电器模块", mainMenu);
|
|
|
|
|
QMenu *keyphasor = new QMenu("/25 键相模块", mainMenu);
|
|
|
|
|
|
|
|
|
|
// 创建第二层子菜单:/40 振动板卡
|
|
|
|
|
QMenu *proximitor_menu = new QMenu("/40 振动板卡", monitors);
|
|
|
|
|
QMenu *rpm_menu = new QMenu("/50 转速板卡", monitors);
|
|
|
|
|
|
|
|
|
|
// 创建第三层子菜单:/40 单板卡、三冗余板卡
|
|
|
|
|
QAction *proximitor_1 = proximitor_menu->addAction("/40 单板卡");
|
|
|
|
|
QAction *proximitor_2 = proximitor_menu->addAction("/40 三冗余板卡");
|
|
|
|
|
|
|
|
|
|
QAction *rpm_1 = rpm_menu->addAction("/50 单板卡");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建第二层子菜单:/25 键相模块
|
|
|
|
|
QAction *keyphasor_1 = keyphasor->addAction("/25 单板卡");
|
|
|
|
|
QAction *keyphasor_2 = keyphasor->addAction("/25 两板卡");
|
|
|
|
|
|
|
|
|
|
// 创建第二层子菜单:/30 继电器模块
|
|
|
|
|
QAction *relays_1 = relays->addAction("/30 单板卡");
|
|
|
|
|
QAction *relays_2 = relays->addAction("/30 三冗余板卡");
|
|
|
|
|
|
|
|
|
|
// 将子菜单加入上一级菜单
|
|
|
|
|
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-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` 事件,确保只有右键点击时弹出菜单
|
|
|
|
|
connect(parent, &QPushButton::customContextMenuRequested, this, [=](const QPoint &pos)
|
2025-02-10 10:48:43 +08:00
|
|
|
|
{
|
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
|
|
|
|
});
|
|
|
|
|
// 连接所有菜单项
|
|
|
|
|
QObject::connect(proximitor_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(proximitor_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(rpm_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(relays_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(relays_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(keyphasor_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(keyphasor_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
|
|
|
|
QObject::connect(reset, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
2025-03-01 13:40:11 +08:00
|
|
|
|
QObject::connect(upgrade, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
2025-03-03 21:57:15 +08:00
|
|
|
|
QObject::connect(version, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
2025-02-11 19:54:22 +08:00
|
|
|
|
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
2025-02-11 19:54:22 +08:00
|
|
|
|
|
2025-02-10 10:48:43 +08:00
|
|
|
|
void MainWindow::createMenuSet(const QString& rootTitle, QPushButton* parent )
|
|
|
|
|
{
|
|
|
|
|
// 创建主菜单
|
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("测点名称");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清除菜单中所有动作的属性
|
|
|
|
|
void MainWindow::clearMenuProperties(QMenu* menu)
|
|
|
|
|
{
|
|
|
|
|
// 遍历菜单的所有动作
|
|
|
|
|
if (!menu) {
|
|
|
|
|
qWarning() << "菜单为空,无法清除属性!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历菜单的所有动作
|
|
|
|
|
for (QAction* action : menu->actions()) {
|
|
|
|
|
if (!action) continue;
|
|
|
|
|
|
|
|
|
|
// 检查是否有子菜单
|
|
|
|
|
if (QMenu* subMenu = action->menu()) {
|
|
|
|
|
clearMenuProperties(subMenu); // 递归处理子菜单
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清除动作的属性
|
|
|
|
|
action->setProperty("customProperty", QVariant());
|
|
|
|
|
qDebug() << "清除了属性,动作:" << action->text();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onMenuActionTriggered()
|
|
|
|
|
{
|
2025-03-14 09:33:14 +08:00
|
|
|
|
qDebug() << "onMenuActionTriggered()" ;
|
2025-02-10 10:48:43 +08:00
|
|
|
|
QAction *action = qobject_cast<QAction*>(sender());
|
|
|
|
|
if (action) {
|
|
|
|
|
// 获取触发动作的父菜单
|
|
|
|
|
QMenu *menu = qobject_cast<QMenu*>(action->parent());
|
|
|
|
|
// 遍历所有父菜单,直到找到按钮
|
|
|
|
|
while (menu) {
|
|
|
|
|
QPushButton *button = qobject_cast<QPushButton*>(menu->parent());
|
|
|
|
|
if (button) {
|
2025-02-11 19:54:22 +08:00
|
|
|
|
qDebug() << "子菜单项被点击,所属按钮:" << button->objectName() << action->text();
|
|
|
|
|
int slot_type = action->text().mid(1,2).toInt();
|
|
|
|
|
QString rack_type = action->text().right(action->text().length()-4);
|
|
|
|
|
int button_id = button->objectName().right(button->objectName().length()-15).toInt();
|
2025-03-14 09:33:14 +08:00
|
|
|
|
qDebug() << slot_type << rack_type << button_id << map_slot_config[button_id + 1].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-02-13 10:50:09 +08:00
|
|
|
|
if(rack_type == "三冗余板卡" && (map_slot_config[button_id].slot_type != 0 || map_slot_config[button_id + 1].slot_type != 0 \
|
2025-02-11 19:54:22 +08:00
|
|
|
|
|| map_slot_config[button_id + 2].slot_type != 0)){
|
|
|
|
|
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠三冗余板卡配置,请在创建新配置之前移除现有的配置!");
|
|
|
|
|
return;
|
|
|
|
|
}else if(rack_type == "三冗余板卡" && map_slot_config[button_id + 1].slot_type == 0 \
|
|
|
|
|
&& map_slot_config[button_id + 2].slot_type == 0){
|
|
|
|
|
map_slot_config[button_id].slot_type = slot_type;
|
2025-02-13 10:50:09 +08:00
|
|
|
|
map_slot_config[button_id].rack_type = "TMR1";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText(action->text());
|
|
|
|
|
map_slot_config[button_id].chan_display = action->text();
|
|
|
|
|
map_slot_config[button_id + 1].slot_type = slot_type;
|
|
|
|
|
map_slot_config[button_id + 1].rack_type = "TMR2";
|
|
|
|
|
map_slot_config[button_id + 1].slot_btn->setText(action->text());
|
|
|
|
|
map_slot_config[button_id + 1].chan_display = action->text();
|
|
|
|
|
map_slot_config[button_id + 2].slot_type = slot_type;
|
|
|
|
|
map_slot_config[button_id + 2].rack_type = "TMR3";
|
|
|
|
|
map_slot_config[button_id + 2].slot_btn->setText(action->text());
|
|
|
|
|
map_slot_config[button_id + 2].chan_display = action->text();
|
2025-02-11 19:54:22 +08:00
|
|
|
|
}
|
2025-02-13 10:50:09 +08:00
|
|
|
|
if(rack_type == "两板卡" && (map_slot_config[button_id].slot_type != 0 || map_slot_config[button_id + 1].slot_type != 0 )){
|
2025-02-11 19:54:22 +08:00
|
|
|
|
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠两板卡配置,请在创建新配置之前移除现有的配置!");
|
|
|
|
|
return;
|
|
|
|
|
}else if(rack_type == "两板卡" && map_slot_config[button_id + 1].slot_type == 0){
|
|
|
|
|
map_slot_config[button_id].slot_type = slot_type;
|
2025-02-13 10:50:09 +08:00
|
|
|
|
map_slot_config[button_id].rack_type = "Double1";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText(action->text());
|
|
|
|
|
map_slot_config[button_id].chan_display = action->text();
|
|
|
|
|
map_slot_config[button_id + 1].slot_type = slot_type;
|
|
|
|
|
map_slot_config[button_id + 1].rack_type = "Double2";
|
|
|
|
|
map_slot_config[button_id + 1].slot_btn->setText(action->text());
|
|
|
|
|
map_slot_config[button_id + 1].chan_display = action->text();
|
|
|
|
|
}
|
|
|
|
|
if(rack_type == "单板卡" && map_slot_config[button_id].slot_type != 0){
|
|
|
|
|
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠单板卡配置,请在创建新配置之前移除现有的配置!");
|
|
|
|
|
return;
|
|
|
|
|
}else if(rack_type == "单板卡" && map_slot_config[button_id].slot_type == 0) {
|
|
|
|
|
map_slot_config[button_id].slot_type = slot_type;
|
|
|
|
|
map_slot_config[button_id].rack_type = "Single";
|
|
|
|
|
map_slot_config[button_id].chan_display = action->text();
|
|
|
|
|
button->setText(action->text());
|
2025-02-11 19:54:22 +08:00
|
|
|
|
}
|
2025-02-13 10:50:09 +08:00
|
|
|
|
|
2025-03-01 13:40:11 +08:00
|
|
|
|
if(action->text() == "重置模块"){
|
2025-02-13 10:50:09 +08:00
|
|
|
|
if(map_slot_config[button_id].rack_type == "TMR1"){
|
|
|
|
|
map_slot_config[button_id].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id].chan_display = "";
|
|
|
|
|
map_slot_config[button_id + 1].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id + 1].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id + 1].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id + 1].chan_display = "";
|
|
|
|
|
map_slot_config[button_id + 2].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id + 2].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id + 2].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id + 2].chan_display = "";
|
|
|
|
|
}else if(map_slot_config[button_id].rack_type == "TMR2"){
|
|
|
|
|
map_slot_config[button_id - 1].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id - 1].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id - 1].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id - 1].chan_display = "";
|
|
|
|
|
map_slot_config[button_id].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id].chan_display = "";
|
|
|
|
|
map_slot_config[button_id + 1].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id + 1].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id + 1].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id + 1].chan_display = "";
|
|
|
|
|
}else if(map_slot_config[button_id].rack_type == "TMR3"){
|
|
|
|
|
map_slot_config[button_id - 2].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id - 2].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id - 2].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id - 2].chan_display = "";
|
|
|
|
|
map_slot_config[button_id - 1].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id - 1].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id - 1].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id - 1].chan_display = "";
|
|
|
|
|
map_slot_config[button_id].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id].chan_display = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(map_slot_config[button_id].rack_type == "Double1"){
|
|
|
|
|
map_slot_config[button_id].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id].chan_display = "";
|
|
|
|
|
map_slot_config[button_id + 1].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id + 1].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id + 1].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id + 1].chan_display = "";
|
|
|
|
|
|
|
|
|
|
}else if(map_slot_config[button_id].rack_type == "Double2"){
|
|
|
|
|
map_slot_config[button_id - 1].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id - 1].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id - 1].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id - 1].chan_display = "";
|
|
|
|
|
map_slot_config[button_id].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id].chan_display = "";
|
|
|
|
|
}
|
|
|
|
|
if(map_slot_config[button_id].rack_type == "Single"){
|
|
|
|
|
map_slot_config[button_id].slot_type = 0;
|
|
|
|
|
map_slot_config[button_id].rack_type = "0";
|
|
|
|
|
map_slot_config[button_id].slot_btn->setText("");
|
|
|
|
|
map_slot_config[button_id].chan_display = "";
|
|
|
|
|
}
|
2025-03-11 16:42:00 +08:00
|
|
|
|
|
2025-03-01 13:40:11 +08:00
|
|
|
|
}else if(action->text() == "升级固件"){
|
2025-03-11 16:42:00 +08:00
|
|
|
|
sendUpgradePackage(button_id);
|
2025-03-03 21:57:15 +08:00
|
|
|
|
}else if(action->text() == "查看版本"){
|
2025-03-11 16:42:00 +08:00
|
|
|
|
getVersion(button_id);
|
2025-02-11 19:54:22 +08:00
|
|
|
|
}
|
2025-02-10 10:48:43 +08:00
|
|
|
|
break; // 找到按钮后,跳出循环
|
|
|
|
|
}
|
|
|
|
|
// 如果没有找到按钮,继续向上查找
|
|
|
|
|
menu = qobject_cast<QMenu*>(menu->parent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:54:22 +08:00
|
|
|
|
void MainWindow::OnButtonGroup(QAbstractButton * slot_btn)
|
2025-02-10 10:48:43 +08:00
|
|
|
|
{
|
2025-02-11 19:54:22 +08:00
|
|
|
|
if(slot_btn != NULL && ui->pushButton_chan->isChecked())
|
2025-02-10 10:48:43 +08:00
|
|
|
|
{
|
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-02-11 19:54:22 +08:00
|
|
|
|
int button_id = object_name.right(object_name.length()-15).toInt();
|
|
|
|
|
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-02-11 19:54:22 +08:00
|
|
|
|
if (slot_config.slot_type == KEYPHASOR){
|
|
|
|
|
KeyPhase *key_phase = new KeyPhase();
|
|
|
|
|
key_phase->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
key_phase->show();
|
|
|
|
|
}else if (slot_config.slot_type == RELAY){
|
|
|
|
|
SingleRelay *single_relay = new SingleRelay();
|
|
|
|
|
single_relay->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
single_relay->show();
|
|
|
|
|
}else if (slot_config.slot_type == VIBRATE){
|
2025-02-18 10:55:51 +08:00
|
|
|
|
Seismic_monitor *seismic_monitor = new Seismic_monitor(button_id);
|
2025-02-11 19:54:22 +08:00
|
|
|
|
seismic_monitor->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
seismic_monitor->show();
|
|
|
|
|
}else if (slot_config.slot_type == RPM){
|
|
|
|
|
Tachometer *tachometer = new Tachometer();
|
|
|
|
|
tachometer->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
tachometer->show();
|
2025-03-01 17:36:57 +08:00
|
|
|
|
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-13 10:50:09 +08:00
|
|
|
|
if(slot_btn != NULL && ui->pushButton_alarm->isChecked()){
|
|
|
|
|
QString object_name = slot_btn->objectName();
|
2025-03-14 09:33:14 +08:00
|
|
|
|
qDebug() << object_name ;
|
2025-02-13 10:50:09 +08:00
|
|
|
|
Setpoint *setpoint = new Setpoint();
|
|
|
|
|
setpoint->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
setpoint->show();
|
|
|
|
|
}
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_slot_clicked()
|
|
|
|
|
{
|
2025-02-11 19:54:22 +08:00
|
|
|
|
if(ui->pushButton_chan->isChecked())
|
|
|
|
|
ui->pushButton_chan->setChecked(false);
|
|
|
|
|
if(ui->pushButton_alarm->isChecked())
|
|
|
|
|
ui->pushButton_alarm->setChecked(false);
|
|
|
|
|
if(ui->pushButton_point_name->isChecked())
|
|
|
|
|
ui->pushButton_point_name->setChecked(false);
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_chan_clicked()
|
|
|
|
|
{
|
2025-02-11 19:54:22 +08:00
|
|
|
|
if(ui->pushButton_slot->isChecked())
|
|
|
|
|
ui->pushButton_slot->setChecked(false);
|
|
|
|
|
if(ui->pushButton_alarm->isChecked())
|
|
|
|
|
ui->pushButton_alarm->setChecked(false);
|
|
|
|
|
if(ui->pushButton_point_name->isChecked())
|
|
|
|
|
ui->pushButton_point_name->setChecked(false);
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_alarm_clicked()
|
|
|
|
|
{
|
2025-02-11 19:54:22 +08:00
|
|
|
|
if(ui->pushButton_slot->isChecked())
|
|
|
|
|
ui->pushButton_slot->setChecked(false);
|
|
|
|
|
if(ui->pushButton_chan->isChecked())
|
|
|
|
|
ui->pushButton_chan->setChecked(false);
|
|
|
|
|
if(ui->pushButton_point_name->isChecked())
|
|
|
|
|
ui->pushButton_point_name->setChecked(false);
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_point_name_clicked()
|
|
|
|
|
{
|
2025-02-11 19:54:22 +08:00
|
|
|
|
if(ui->pushButton_slot->isChecked())
|
|
|
|
|
ui->pushButton_slot->setChecked(false);
|
|
|
|
|
if(ui->pushButton_chan->isChecked())
|
|
|
|
|
ui->pushButton_chan->setChecked(false);
|
|
|
|
|
if(ui->pushButton_alarm->isChecked())
|
|
|
|
|
ui->pushButton_alarm->setChecked(false);
|
|
|
|
|
}
|
2025-02-10 10:48:43 +08:00
|
|
|
|
|
2025-03-04 16:00:19 +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-02-11 19:54:22 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_save_clicked()
|
|
|
|
|
{
|
|
|
|
|
QJsonObject itemObj;
|
|
|
|
|
QJsonArray slotArray;
|
|
|
|
|
for(int i = 0; i < map_slot_config.size();i++){
|
2025-03-03 21:57:15 +08:00
|
|
|
|
itemObj["slot"] = map_slot_config[i+1].slot;
|
|
|
|
|
itemObj["slot_type"] = map_slot_config[i+1].slot_type;
|
|
|
|
|
itemObj["chan_display"] = map_slot_config[i+1].chan_display;
|
|
|
|
|
itemObj["rack_type"] = map_slot_config[i+1].rack_type;
|
2025-02-11 19:54:22 +08:00
|
|
|
|
slotArray.append(itemObj);
|
|
|
|
|
}
|
|
|
|
|
QJsonDocument jsonDoc;
|
|
|
|
|
jsonDoc.setArray(slotArray);
|
|
|
|
|
QFile file(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
|
file.write(jsonDoc.toJson());
|
|
|
|
|
file.close();
|
2025-02-10 10:48:43 +08:00
|
|
|
|
}
|
2024-12-17 18:53:41 +08:00
|
|
|
|
|
2025-02-18 10:55:51 +08:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_open_clicked()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-01 13:40:11 +08:00
|
|
|
|
uint8_t calculate_crc(uint8_t c,const QByteArray &data) {
|
2025-03-14 09:33:14 +08:00
|
|
|
|
uint8_t crc = c;
|
2025-03-01 13:40:11 +08:00
|
|
|
|
for (int i = 0; i < data.size(); ++i) {
|
|
|
|
|
crc += static_cast<uint8_t>(data[i]); // 累加每个字节
|
|
|
|
|
}
|
|
|
|
|
return crc;
|
|
|
|
|
}
|
|
|
|
|
uint32_t myHtonl(uint32_t value) {
|
|
|
|
|
return ((value >> 24) & 0x000000FF) | // 提取最高的8位
|
|
|
|
|
((value >> 8) & 0x0000FF00) | // 提取中间的8位
|
|
|
|
|
((value << 8) & 0x00FF0000) | // 提取次高的8位
|
|
|
|
|
((value << 24) & 0xFF000000); // 提取最低的8位
|
|
|
|
|
}
|
|
|
|
|
void MainWindow::sendUpgradePackage(int slot)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
if(FileName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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-14 09:33:14 +08:00
|
|
|
|
if(fileSize > 10 * 1024 * 1024)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(this, QStringLiteral("提示"), "文件大小超过10M,请重新选择!");
|
|
|
|
|
file.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
qDebug() << "fileSize" << fileSize ;
|
2025-03-01 13:40:11 +08:00
|
|
|
|
// 创建 PackageHead 结构体
|
|
|
|
|
PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize,0,{} };
|
|
|
|
|
// 计算文件的 CRC 校验和
|
|
|
|
|
|
2025-03-14 09:33:14 +08:00
|
|
|
|
qDebug() << "filheader.slot" << slot ;
|
2025-03-01 13:40:11 +08:00
|
|
|
|
UpgradeCardReq upgrade_car_req;
|
|
|
|
|
if(slot == 0)
|
2025-03-01 19:22:48 +08:00
|
|
|
|
upgrade_car_req.card_id = 0xFF;
|
2025-03-01 13:40:11 +08:00
|
|
|
|
else
|
2025-03-01 19:22:48 +08:00
|
|
|
|
upgrade_car_req.card_id = slot & 0xFF;
|
2025-03-01 13:40:11 +08:00
|
|
|
|
|
|
|
|
|
header.crc = calculate_crc(upgrade_car_req.card_id,fileData);
|
2025-03-14 09:33:14 +08:00
|
|
|
|
header.len = fileSize + sizeof(UpgradeCardReq);
|
|
|
|
|
qDebug() << "filheader.crc" << header.crc << "card_id" << upgrade_car_req.card_id << "header len" << header.len;
|
2025-03-01 17:36:57 +08:00
|
|
|
|
|
|
|
|
|
char *send_buf = NULL;
|
|
|
|
|
send_buf = (char *)malloc(sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size() + 1);
|
|
|
|
|
memset(send_buf,0,sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size() + 1);
|
|
|
|
|
memcpy(send_buf, &header, sizeof(PackageHead));
|
2025-03-01 19:22:48 +08:00
|
|
|
|
memcpy(send_buf + sizeof(PackageHead), &upgrade_car_req, sizeof(UpgradeCardReq));
|
|
|
|
|
memcpy(send_buf + sizeof(PackageHead) + sizeof(UpgradeCardReq), fileData.data(), fileData.size());
|
|
|
|
|
int length = sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
if(MAX_CHUNK_SIZE < totalBytes - bytesSent){
|
|
|
|
|
chunkSize = MAX_CHUNK_SIZE;
|
|
|
|
|
}else{
|
|
|
|
|
chunkSize = totalBytes - bytesSent;
|
|
|
|
|
}
|
2025-03-13 15:10:35 +08:00
|
|
|
|
qint64 bytesWritten = client.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-13 15:10:35 +08:00
|
|
|
|
client.waitForRead();
|
|
|
|
|
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-01 17:36:57 +08:00
|
|
|
|
if(send_buf != NULL)
|
|
|
|
|
free(send_buf);
|
2025-03-01 13:40:11 +08:00
|
|
|
|
}
|
2025-03-03 21:57:15 +08:00
|
|
|
|
void MainWindow::getVersion(int slot)
|
|
|
|
|
{
|
2025-03-13 15:10:35 +08:00
|
|
|
|
slot_no = slot;
|
2025-03-03 21:57:15 +08:00
|
|
|
|
PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1,0,{} };
|
2025-03-14 09:33:14 +08:00
|
|
|
|
qDebug() << "slot" << slot ;
|
2025-03-03 21:57:15 +08:00
|
|
|
|
GetVersionReq get_version_req;
|
|
|
|
|
if(slot == 0)
|
|
|
|
|
get_version_req.card_id = 0xFF;
|
|
|
|
|
else
|
|
|
|
|
get_version_req.card_id = slot & 0xFF;
|
|
|
|
|
char send_buf[20] ={0};
|
|
|
|
|
memcpy(send_buf, (char*)&header, sizeof(PackageHead));
|
|
|
|
|
memcpy(send_buf + sizeof(PackageHead), (char*)&get_version_req, sizeof(GetVersionReq));
|
|
|
|
|
int length = sizeof(PackageHead) + sizeof(GetVersionReq);
|
2025-03-13 15:10:35 +08:00
|
|
|
|
qint64 bytesWritten = client.sendData(send_buf, length);
|
|
|
|
|
client.waitForRead();
|
|
|
|
|
qDebug() << "bytesWritten: " << bytesWritten;
|
|
|
|
|
}
|
|
|
|
|
void MainWindow::onDisConnected()
|
|
|
|
|
{
|
2025-03-14 09:33:14 +08:00
|
|
|
|
statusBar()->showMessage("连接失败!", 30000); // 显示3秒
|
2025-03-13 15:10:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::readData(const QByteArray& data)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Received from server:" << data;
|
|
|
|
|
PackageHead header;
|
|
|
|
|
memcpy(&header,data.data(),sizeof(PackageHead));
|
|
|
|
|
if(header.cmd == kGetVersionInfo){
|
2025-03-03 21:57:15 +08:00
|
|
|
|
VersionRsp version_rsp;
|
2025-03-13 15:10:35 +08:00
|
|
|
|
memcpy(&version_rsp,data.data() + sizeof(PackageHead),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_data);
|
|
|
|
|
QMessageBox::information(this, QStringLiteral("提示"), strVerion);
|
|
|
|
|
}else if(header.cmd == kUpgradeCard){
|
|
|
|
|
UpgradeRsp resp;
|
|
|
|
|
QByteArray byteArray = data.mid(sizeof(PackageHead));
|
|
|
|
|
QDataStream stream(&byteArray, QIODevice::ReadOnly);
|
|
|
|
|
stream >> resp.code ;
|
|
|
|
|
// if(resp.code == 1){
|
|
|
|
|
// QMessageBox::information(this, QStringLiteral("提示"), "上传成功!");
|
|
|
|
|
// }
|
|
|
|
|
}else if(header.cmd == kUpgradeProgress){
|
|
|
|
|
QByteArray byteArray = data.mid(sizeof(PackageHead));
|
|
|
|
|
UpgradeRsp upgrade_resp;
|
|
|
|
|
QDataStream stream(&byteArray, QIODevice::ReadOnly);
|
|
|
|
|
stream >> upgrade_resp.code ;
|
|
|
|
|
progressBar->setValue(upgrade_resp.code);
|
|
|
|
|
if(upgrade_resp.code == 100){
|
|
|
|
|
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-03-03 21:57:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|