diff --git a/mainwindow.cpp b/mainwindow.cpp index ec3127e..385b15f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -18,6 +18,7 @@ #include #include #include "relaysetting.h" +#include "common.h" QString g_strServerIp; @@ -268,7 +269,7 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent ) void MainWindow::createMenuSet(const QString& rootTitle, QPushButton* parent ) { // 创建主菜单 - qDebug() << "createMenu" << parent->objectName() << endl; + qDebug() << "createMenu" << parent->objectName() ; QMenu *mainMenu = new QMenu(rootTitle, parent); QAction *option = mainMenu->addAction("通道配置…"); @@ -302,7 +303,7 @@ void MainWindow::clearMenuProperties(QMenu* menu) void MainWindow::onMenuActionTriggered() { - qDebug() << "onMenuActionTriggered()" << endl; + qDebug() << "onMenuActionTriggered()" ; QAction *action = qobject_cast(sender()); if (action) { // 获取触发动作的父菜单 @@ -315,7 +316,7 @@ void MainWindow::onMenuActionTriggered() 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(); - qDebug() << slot_type << rack_type << button_id << map_slot_config[button_id + 1].slot_type << map_slot_config[button_id + 2].slot_type << endl; + qDebug() << slot_type << rack_type << button_id << map_slot_config[button_id + 1].slot_type << map_slot_config[button_id + 2].slot_type ; map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}"); if(rack_type == "三冗余板卡" && (map_slot_config[button_id].slot_type != 0 || map_slot_config[button_id + 1].slot_type != 0 \ || map_slot_config[button_id + 2].slot_type != 0)){ @@ -446,7 +447,7 @@ void MainWindow::OnButtonGroup(QAbstractButton * slot_btn) if(slot_btn != NULL && ui->pushButton_chan->isChecked()) { QString object_name = slot_btn->objectName(); - qDebug() << object_name << endl; + qDebug() << object_name ; int button_id = object_name.right(object_name.length()-15).toInt(); SlotConfig slot_config = map_slot_config[button_id]; map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}"); @@ -471,7 +472,7 @@ void MainWindow::OnButtonGroup(QAbstractButton * slot_btn) } if(slot_btn != NULL && ui->pushButton_alarm->isChecked()){ QString object_name = slot_btn->objectName(); - qDebug() << object_name << endl; + qDebug() << object_name ; Setpoint *setpoint = new Setpoint(); setpoint->setWindowModality(Qt::ApplicationModal); setpoint->show(); @@ -523,7 +524,7 @@ void MainWindow::on_pushButton_point_name_clicked() void MainWindow::onMenuAction_relay() { - qDebug() << " onMenuAction_relay " << endl; + qDebug() << " onMenuAction_relay " ; RelaySetting *relay_setting = new RelaySetting(); relay_setting->setWindowModality(Qt::ApplicationModal); relay_setting->show(); @@ -554,7 +555,7 @@ void MainWindow::on_pushButton_open_clicked() } uint8_t calculate_crc(uint8_t c,const QByteArray &data) { - uint8_t crc = c; // 初始化 CRC 为 0 + uint8_t crc = c; for (int i = 0; i < data.size(); ++i) { crc += static_cast(data[i]); // 累加每个字节 } @@ -569,7 +570,7 @@ uint32_t myHtonl(uint32_t value) { void MainWindow::sendUpgradePackage(int slot) { QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*")); - qDebug() << filepath << slot << endl; + qDebug() << filepath << slot ; QFileInfo fileinfo; fileinfo = QFileInfo(filepath); QString file_suffix = fileinfo.suffix(); @@ -586,13 +587,24 @@ void MainWindow::sendUpgradePackage(int slot) // 读取文件内容 QByteArray fileData = file.readAll(); int fileSize = fileData.size(); - - qDebug() << "fileSize" << fileSize < 10 * 1024 * 1024) + { + QMessageBox::information(this, QStringLiteral("提示"), "文件大小超过10M,请重新选择!"); + file.close(); + return; + } + for (int var = 0; var < 10; ++var) { + qDebug() << "Byte" << var << ":" << static_cast(fileData[var]); + } + for (int var = fileSize - 10; var < fileSize; ++var) { + qDebug() << "Byte" << var << ":" << static_cast(fileData[var]); + } + qDebug() << "fileSize" << fileSize ; // 创建 PackageHead 结构体 PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize,0,{} }; // 计算文件的 CRC 校验和 - qDebug() << "filheader.slot" << slot <reset(); progressBar->setVisible(true); @@ -646,7 +657,7 @@ void MainWindow::getVersion(int slot) { slot_no = slot; PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1,0,{} }; - qDebug() << "slot" << slot <showMessage("连接失败!", 10000); // 显示3秒 + statusBar()->showMessage("连接失败!", 30000); // 显示3秒 } void MainWindow::readData(const QByteArray& data)