diff --git a/connect.cpp b/connect.cpp index 5c78e3b..34cc2be 100644 --- a/connect.cpp +++ b/connect.cpp @@ -5,6 +5,7 @@ #include "data_config.h" #include #include +#include Connect::Connect(QWidget *parent) : QWidget(parent), @@ -26,6 +27,7 @@ Connect::~Connect() void Connect::on_pushButton_connect_clicked() { g_strServerIp = ui->lineEdit_IP->text(); + QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); m_tcpClient = MyTcpClient::instance(); // 连接服务器 m_tcpClient->connectToServer(g_strServerIp, 10000); diff --git a/data_config.h b/data_config.h index fd87660..7198e28 100644 --- a/data_config.h +++ b/data_config.h @@ -938,6 +938,38 @@ typedef struct { uint16_t pid2; // 辅助进程进程号,只有振动板有这个号 } GetCardProcessIDRsp; +typedef struct { + uint8_t head[3]; // 固定值:0xAA55AA + uint8_t cmd; // kGetProductInfo + uint8_t version; // 版本号,默认为1 +} GetProductInfoReq; + +typedef struct { + uint8_t head[3]; // 固定值:0xAA55AA + uint8_t cmd; // kGetProductInfo + uint8_t version; // 版本号,默认为1 + uint8_t code; // 0: 成功, 1:失败 + char date[32]; // 生产日期 + char config_sw[64]; // config软件版本 + char view_sw[64]; // view软件版本 +} GetProductInfoRsp; + +typedef struct { + uint8_t head[3]; // 固定值:0xAA55AA + uint8_t cmd; // kSetProductInfo + uint8_t version; // 版本号,默认为1 + char date[32]; // 生产日期 + char config_sw[64]; // config软件版本 + char view_sw[64]; // view软件版本 +} SetProductInfoReq; + +typedef struct { + uint8_t head[3]; // 固定值:0xAA55AA + uint8_t cmd; // kSetProductInfo + uint8_t version; // 版本号,默认为1 + uint8_t code; // 0: 成功, 1:失败 +} SetProductInfoRsp; + struct BaseHeader { uint8_t head[3]; // 固定 0xAA 0x55 0xAA uint8_t cmd; diff --git a/mainwindow.cpp b/mainwindow.cpp index b17520a..6e6d8c2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -29,7 +29,9 @@ #include "dc_outputs.h" #include "mqtt_config.h" #include "singlerelay_nok.h" -#include +#include +#include +#include QString g_strServerIp; QString g_version; @@ -55,6 +57,11 @@ MainWindow::MainWindow(QWidget *parent) statusBar()->addWidget(progressBar); progressBar->setVisible(false); // 初始隐藏 progressBar->setFixedWidth(300); + + connect_status = new QLabel("网络: 未连接", this); + statusBar()->addPermanentWidget(connect_status); + + shouldReconnect = true; //this->initStyle(); //添加信号槽 QObject::connect(ui->action_realy, &QAction::triggered, this, &MainWindow::onMenuAction_relay); @@ -105,18 +112,17 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->action_deviveID, &QAction::triggered, this, &MainWindow::onConfigDeviceID); QObject::connect(ui->action_get_deviceID, &QAction::triggered, this, &MainWindow::onGetDeviceID); QObject::connect(ui->action_close, &QAction::triggered, this, &MainWindow::onCloseConfig); - + QObject::connect(ui->action_user_manual, &QAction::triggered, this, &MainWindow::onOpenUserManual); QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat); g_strServerIp = settingsread.value("Server/IP").toString(); connectServer(); - statusBar()->showMessage("未连接",10000); // 设置自定义日志处理函数 #ifndef QT_DEBUG //qInstallMessageHandler(messageHandler); #endif QDate buildDate = QLocale( QLocale::English ).toDate( QString(__DATE__).replace(" ", " 0"), "MMM dd yyyy"); - QString Version = "V1.0_" + buildDate.toString("yyyyMMdd") + "_1c8b"; + QString Version = "V1.0_" + buildDate.toString("yyyyMMdd") + "_84da"; ui->label_version->setText(Version); } @@ -125,16 +131,22 @@ MainWindow::~MainWindow() { } void MainWindow::onDisConnected() { - statusBar()->showMessage("连接失败!正在重连……", 3000); // 显示3秒 + if(shouldReconnect){ + statusBar()->showMessage("网络已断开,正在重连……", 3000); // 显示3秒 + } + connect_status->setText("网络: 已断开"); } void MainWindow::onConnected() { + shouldReconnect = true; statusBar()->showMessage("连接成功!", 3000); + connect_status->setText("网络: 已连接"); } void MainWindow::onerrorOccurred(const QString &errorMsg) { statusBar()->showMessage(errorMsg, 3000); } void MainWindow::connectServer() { + QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); m_tcpClient = MyTcpClient::instance(); // 监听信号 connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &))); @@ -643,10 +655,10 @@ void MainWindow::on_pushButton_save_clicked() { QString file_name = ""; if(tsi_config_file == ""){ - QString strTips =QString("请输入保存的文件名称"); + QString strTips = QString("请输入保存的文件名称"); bool ok = false; QString defaultInput = "tsi_config_file"; - file_name = QInputDialog::getText(this, tr("输入名称对话框"), strTips, QLineEdit::Normal, defaultInput, &ok); + file_name = QInputDialog::getText(this, tr("输入保存文件名称"), strTips, QLineEdit::Normal, defaultInput, &ok); if(!ok) return; if( file_name == ""){ @@ -682,7 +694,7 @@ void MainWindow::on_pushButton_save_clicked() { void MainWindow::on_pushButton_open_clicked() { - tsi_config_file = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*.json")); + tsi_config_file = QFileDialog::getOpenFileName(this, tr("选择文件"), QCoreApplication::applicationDirPath()+ "\\config\\", tr("*.json")); QFileInfo fileinfo; fileinfo = QFileInfo(tsi_config_file); QString file_suffix = fileinfo.suffix(); @@ -889,7 +901,6 @@ void MainWindow::GetVoltageRangeValue(int slot){ 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); @@ -917,9 +928,9 @@ void MainWindow::GetCardProcessID(int slot){ } void MainWindow::CopySubCard(int slot){ slot_no = slot; - QString strTips = QString("请输入1到15之间的数值"); + QString strTips = QString("请输入需要复制的板卡号(1 ~ 15)"); bool ok = false; - int value = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, 0, 1, 15, 1, &ok); + int value = QInputDialog::getInt(this, tr("请输入需要复制的板卡号"), strTips, 0, 1, 15, 1, &ok); if(!ok) return; if(value < 1){ QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的板卡号!")); @@ -999,13 +1010,12 @@ void MainWindow::CopySubCard(int slot){ } } } - } void MainWindow::MoveSubCard(int slot){ slot_no = slot; - QString strTips = QString("请输入1到15之间的数值"); + QString strTips = QString("请输入需要移动的板卡号(1 ~ 15)"); bool ok = false; - int value = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, 0, 1, 15, 1, &ok); + int value = QInputDialog::getInt(this, tr("请输入需要移动的板卡号"), strTips, 0, 1, 15, 1, &ok); if(!ok) return; if(value < 1){ QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的板卡号!")); @@ -1212,6 +1222,7 @@ void MainWindow::onConnect(){ connect_config->show(); } void MainWindow::onDisconnect(){ + shouldReconnect = false; m_tcpClient->disconnectFromServer(); } @@ -1252,11 +1263,21 @@ void MainWindow::onCloseConfig(){ } tsi_config_file = ""; } +void MainWindow::onOpenUserManual(){ + QString pdfPath = QCoreApplication::applicationDirPath()+ "\\config\\南京凯奥思安全监视与保护装置使用说明书.pdf"; + QFileInfo file(pdfPath); + if (!file.exists()) { + QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("文件不存在!")); + return; + } + QDesktopServices::openUrl( + QUrl::fromLocalFile(file.absoluteFilePath()) + ); +} void MainWindow::onConfigDeviceID(){ - QString strTips =QString("请输入0到99之间的数值"); - + QString strTips = QString("请输入设备ID(0 ~ 99)"); bool ok = false; - int value = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, 0, 0, 99, 1, &ok); + int value = QInputDialog::getInt(this, tr("请输入设备ID"), strTips, 0, 0, 99, 1, &ok); if(!ok) return; if(value < 1){ @@ -1318,7 +1339,7 @@ void MainWindow::UploadConfigFile(uint8_t sub_cmd){ const int MAX_CHUNK_SIZE = 50 * 1024; // 50 KB qint64 bytesSent = 0; qint64 totalBytes = length; - qDebug() << "totalBytes" << totalBytes ; + qDebug() << "totalBytes" << totalBytes ; while (bytesSent < totalBytes) { qint64 chunkSize = 0; if (MAX_CHUNK_SIZE < totalBytes - bytesSent) { diff --git a/mainwindow.h b/mainwindow.h index b133837..ae965d0 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -47,6 +47,8 @@ private: QProgressBar *progressBar; int current_slot; QString tsi_config_file; + bool shouldReconnect ; + QLabel *connect_status; void createMenu(); void createMenu(const QString& rootTitle, QPushButton* button = nullptr); @@ -84,6 +86,7 @@ private slots: void onConfigDeviceID(); void onGetDeviceID(); void onCloseConfig(); + void onOpenUserManual(); void onMenuActionTriggered(); diff --git a/mainwindow.ui b/mainwindow.ui index d3ddb22..62049a6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -194,7 +194,7 @@ - 打开配置文件 + 关闭配置文件 关闭 @@ -1097,10 +1097,6 @@ 开始 - - - - @@ -1108,6 +1104,7 @@ 帮助 + @@ -1196,6 +1193,11 @@ 关闭 + + + 使用手册 + + diff --git a/seismic_monitor.ui b/seismic_monitor.ui index 8adfcb7..28c26c1 100644 --- a/seismic_monitor.ui +++ b/seismic_monitor.ui @@ -1421,46 +1421,6 @@ - - - - - - - 50 - 16777215 - - - - ===> - - - - - - - === - - - Qt::AlignCenter - - - - - - - - 50 - 16777215 - - - - <=== - - - - - @@ -1517,54 +1477,6 @@ 16777215 - - - - 10 - 210 - 52 - 91 - - - - - - - - 50 - 16777215 - - - - ===> - - - - - - - === - - - Qt::AlignCenter - - - - - - - - 50 - 16777215 - - - - <=== - - - - - @@ -2757,46 +2669,6 @@ - - - - - - - 50 - 16777215 - - - - ===> - - - - - - - === - - - Qt::AlignCenter - - - - - - - - 50 - 16777215 - - - - <=== - - - - -