优化更新文件逻辑
This commit is contained in:
parent
50c55283a0
commit
fe9771587b
@ -18,6 +18,7 @@
|
|||||||
#include <qsettings.h>
|
#include <qsettings.h>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
#include "relaysetting.h"
|
#include "relaysetting.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
QString g_strServerIp;
|
QString g_strServerIp;
|
||||||
|
|
||||||
@ -268,7 +269,7 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
|||||||
void MainWindow::createMenuSet(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);
|
QMenu *mainMenu = new QMenu(rootTitle, parent);
|
||||||
|
|
||||||
QAction *option = mainMenu->addAction("通道配置…");
|
QAction *option = mainMenu->addAction("通道配置…");
|
||||||
@ -302,7 +303,7 @@ void MainWindow::clearMenuProperties(QMenu* menu)
|
|||||||
|
|
||||||
void MainWindow::onMenuActionTriggered()
|
void MainWindow::onMenuActionTriggered()
|
||||||
{
|
{
|
||||||
qDebug() << "onMenuActionTriggered()" << endl;
|
qDebug() << "onMenuActionTriggered()" ;
|
||||||
QAction *action = qobject_cast<QAction*>(sender());
|
QAction *action = qobject_cast<QAction*>(sender());
|
||||||
if (action) {
|
if (action) {
|
||||||
// 获取触发动作的父菜单
|
// 获取触发动作的父菜单
|
||||||
@ -315,7 +316,7 @@ void MainWindow::onMenuActionTriggered()
|
|||||||
int slot_type = action->text().mid(1,2).toInt();
|
int slot_type = action->text().mid(1,2).toInt();
|
||||||
QString rack_type = action->text().right(action->text().length()-4);
|
QString rack_type = action->text().right(action->text().length()-4);
|
||||||
int button_id = button->objectName().right(button->objectName().length()-15).toInt();
|
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}");
|
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 \
|
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)){
|
|| 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())
|
if(slot_btn != NULL && ui->pushButton_chan->isChecked())
|
||||||
{
|
{
|
||||||
QString object_name = slot_btn->objectName();
|
QString object_name = slot_btn->objectName();
|
||||||
qDebug() << object_name << endl;
|
qDebug() << object_name ;
|
||||||
int button_id = object_name.right(object_name.length()-15).toInt();
|
int button_id = object_name.right(object_name.length()-15).toInt();
|
||||||
SlotConfig slot_config = map_slot_config[button_id];
|
SlotConfig slot_config = map_slot_config[button_id];
|
||||||
map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}");
|
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()){
|
if(slot_btn != NULL && ui->pushButton_alarm->isChecked()){
|
||||||
QString object_name = slot_btn->objectName();
|
QString object_name = slot_btn->objectName();
|
||||||
qDebug() << object_name << endl;
|
qDebug() << object_name ;
|
||||||
Setpoint *setpoint = new Setpoint();
|
Setpoint *setpoint = new Setpoint();
|
||||||
setpoint->setWindowModality(Qt::ApplicationModal);
|
setpoint->setWindowModality(Qt::ApplicationModal);
|
||||||
setpoint->show();
|
setpoint->show();
|
||||||
@ -523,7 +524,7 @@ void MainWindow::on_pushButton_point_name_clicked()
|
|||||||
|
|
||||||
void MainWindow::onMenuAction_relay()
|
void MainWindow::onMenuAction_relay()
|
||||||
{
|
{
|
||||||
qDebug() << " onMenuAction_relay " << endl;
|
qDebug() << " onMenuAction_relay " ;
|
||||||
RelaySetting *relay_setting = new RelaySetting();
|
RelaySetting *relay_setting = new RelaySetting();
|
||||||
relay_setting->setWindowModality(Qt::ApplicationModal);
|
relay_setting->setWindowModality(Qt::ApplicationModal);
|
||||||
relay_setting->show();
|
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 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) {
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
crc += static_cast<uint8_t>(data[i]); // 累加每个字节
|
crc += static_cast<uint8_t>(data[i]); // 累加每个字节
|
||||||
}
|
}
|
||||||
@ -569,7 +570,7 @@ uint32_t myHtonl(uint32_t value) {
|
|||||||
void MainWindow::sendUpgradePackage(int slot)
|
void MainWindow::sendUpgradePackage(int slot)
|
||||||
{
|
{
|
||||||
QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*"));
|
QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*"));
|
||||||
qDebug() << filepath << slot << endl;
|
qDebug() << filepath << slot ;
|
||||||
QFileInfo fileinfo;
|
QFileInfo fileinfo;
|
||||||
fileinfo = QFileInfo(filepath);
|
fileinfo = QFileInfo(filepath);
|
||||||
QString file_suffix = fileinfo.suffix();
|
QString file_suffix = fileinfo.suffix();
|
||||||
@ -586,13 +587,24 @@ void MainWindow::sendUpgradePackage(int slot)
|
|||||||
// 读取文件内容
|
// 读取文件内容
|
||||||
QByteArray fileData = file.readAll();
|
QByteArray fileData = file.readAll();
|
||||||
int fileSize = fileData.size();
|
int fileSize = fileData.size();
|
||||||
|
if(fileSize > 10 * 1024 * 1024)
|
||||||
qDebug() << "fileSize" << fileSize <<endl;
|
{
|
||||||
|
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 ;
|
||||||
// 创建 PackageHead 结构体
|
// 创建 PackageHead 结构体
|
||||||
PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize,0,{} };
|
PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize,0,{} };
|
||||||
// 计算文件的 CRC 校验和
|
// 计算文件的 CRC 校验和
|
||||||
|
|
||||||
qDebug() << "filheader.slot" << slot <<endl;
|
qDebug() << "filheader.slot" << slot ;
|
||||||
UpgradeCardReq upgrade_car_req;
|
UpgradeCardReq upgrade_car_req;
|
||||||
if(slot == 0)
|
if(slot == 0)
|
||||||
upgrade_car_req.card_id = 0xFF;
|
upgrade_car_req.card_id = 0xFF;
|
||||||
@ -600,8 +612,8 @@ void MainWindow::sendUpgradePackage(int slot)
|
|||||||
upgrade_car_req.card_id = slot & 0xFF;
|
upgrade_car_req.card_id = slot & 0xFF;
|
||||||
|
|
||||||
header.crc = calculate_crc(upgrade_car_req.card_id,fileData);
|
header.crc = calculate_crc(upgrade_car_req.card_id,fileData);
|
||||||
header.len = fileSize;
|
header.len = fileSize + sizeof(UpgradeCardReq);
|
||||||
qDebug() << "filheader.crc" << header.crc << "card_id" << upgrade_car_req.card_id << endl;
|
qDebug() << "filheader.crc" << header.crc << "card_id" << upgrade_car_req.card_id << "header len" << header.len;
|
||||||
|
|
||||||
char *send_buf = NULL;
|
char *send_buf = NULL;
|
||||||
send_buf = (char *)malloc(sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size() + 1);
|
send_buf = (char *)malloc(sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size() + 1);
|
||||||
@ -609,13 +621,12 @@ void MainWindow::sendUpgradePackage(int slot)
|
|||||||
memcpy(send_buf, &header, sizeof(PackageHead));
|
memcpy(send_buf, &header, sizeof(PackageHead));
|
||||||
memcpy(send_buf + sizeof(PackageHead), &upgrade_car_req, sizeof(UpgradeCardReq));
|
memcpy(send_buf + sizeof(PackageHead), &upgrade_car_req, sizeof(UpgradeCardReq));
|
||||||
memcpy(send_buf + sizeof(PackageHead) + sizeof(UpgradeCardReq), fileData.data(), fileData.size());
|
memcpy(send_buf + sizeof(PackageHead) + sizeof(UpgradeCardReq), fileData.data(), fileData.size());
|
||||||
|
|
||||||
int length = sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size();
|
int length = sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size();
|
||||||
|
|
||||||
const int MAX_CHUNK_SIZE = 50 * 1024; // 64 KB
|
const int MAX_CHUNK_SIZE = 50 * 1024; // 64 KB
|
||||||
qint64 bytesSent = 0;
|
qint64 bytesSent = 0;
|
||||||
qint64 totalBytes = length;
|
qint64 totalBytes = length;
|
||||||
qDebug() << "totalBytes" << totalBytes << endl;
|
qDebug() << "totalBytes" << totalBytes ;
|
||||||
|
|
||||||
while (bytesSent < totalBytes) {
|
while (bytesSent < totalBytes) {
|
||||||
qint64 chunkSize = 0;
|
qint64 chunkSize = 0;
|
||||||
@ -625,13 +636,13 @@ void MainWindow::sendUpgradePackage(int slot)
|
|||||||
chunkSize = totalBytes - bytesSent;
|
chunkSize = totalBytes - bytesSent;
|
||||||
}
|
}
|
||||||
qint64 bytesWritten = client.sendData(send_buf + bytesSent, chunkSize);
|
qint64 bytesWritten = client.sendData(send_buf + bytesSent, chunkSize);
|
||||||
qDebug() << "bytesWritten" << bytesWritten << "bytesSent" << bytesSent << endl;
|
qDebug() << "bytesWritten" << bytesWritten << "bytesSent" << bytesSent ;
|
||||||
if (bytesWritten == -1) {
|
if (bytesWritten == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytesSent += bytesWritten;
|
bytesSent += bytesWritten;
|
||||||
}
|
}
|
||||||
qDebug() << "bytesSent" << bytesSent << endl;
|
qDebug() << "bytesSent" << bytesSent ;
|
||||||
client.waitForRead();
|
client.waitForRead();
|
||||||
progressBar->reset();
|
progressBar->reset();
|
||||||
progressBar->setVisible(true);
|
progressBar->setVisible(true);
|
||||||
@ -646,7 +657,7 @@ void MainWindow::getVersion(int slot)
|
|||||||
{
|
{
|
||||||
slot_no = slot;
|
slot_no = slot;
|
||||||
PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1,0,{} };
|
PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1,0,{} };
|
||||||
qDebug() << "slot" << slot <<endl;
|
qDebug() << "slot" << slot ;
|
||||||
GetVersionReq get_version_req;
|
GetVersionReq get_version_req;
|
||||||
if(slot == 0)
|
if(slot == 0)
|
||||||
get_version_req.card_id = 0xFF;
|
get_version_req.card_id = 0xFF;
|
||||||
@ -662,7 +673,7 @@ void MainWindow::getVersion(int slot)
|
|||||||
}
|
}
|
||||||
void MainWindow::onDisConnected()
|
void MainWindow::onDisConnected()
|
||||||
{
|
{
|
||||||
statusBar()->showMessage("连接失败!", 10000); // 显示3秒
|
statusBar()->showMessage("连接失败!", 30000); // 显示3秒
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::readData(const QByteArray& data)
|
void MainWindow::readData(const QByteArray& data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user