增加获取版本号
This commit is contained in:
parent
aa85119143
commit
964affc137
@ -20,7 +20,6 @@ SOURCES += \
|
||||
setpoint.cpp \
|
||||
singlerelay.cpp \
|
||||
tachometer.cpp \
|
||||
tcpclient.cpp \
|
||||
velocity.cpp
|
||||
|
||||
HEADERS += \
|
||||
@ -35,7 +34,6 @@ HEADERS += \
|
||||
setpoint.h \
|
||||
singlerelay.h \
|
||||
tachometer.h \
|
||||
tcpclient.h \
|
||||
velocity.h
|
||||
|
||||
FORMS += \
|
||||
|
@ -16,7 +16,12 @@ typedef struct {
|
||||
QPushButton* slot_btn;
|
||||
}SlotConfig;
|
||||
|
||||
|
||||
enum CMTCommand {
|
||||
kEigenvalueCmd = 1,
|
||||
kExceptionInfo = 2,
|
||||
kUpgradeCard = 3,
|
||||
kGetVersionInfo = 4
|
||||
};
|
||||
enum SlotType{
|
||||
POWER = 10,
|
||||
CONFIG = 20,
|
||||
@ -79,10 +84,11 @@ typedef struct{
|
||||
typedef struct {
|
||||
uint8_t head[3]; // 固定值:0xAA55AA
|
||||
uint8_t cmd; // 命令
|
||||
int len; // 数据长度
|
||||
int len; // 数据长度
|
||||
uint8_t crc; // 数据 CRC 校验和
|
||||
char data[0]; // 文件内容
|
||||
} PackageHead;
|
||||
|
||||
typedef struct {
|
||||
uint8_t card_id; // 0xff是本机,其它子卡是1~15
|
||||
char data[0];
|
||||
@ -92,6 +98,15 @@ typedef struct {
|
||||
uint8_t code; // 0: 上传成功
|
||||
} UpgradeRsp;
|
||||
|
||||
typedef struct {
|
||||
uint8_t card_id; // 0xff是本机,其它子卡是1~15
|
||||
} GetVersionReq;
|
||||
|
||||
typedef struct {
|
||||
uint8_t fpga; // fpga版本号
|
||||
uint8_t sw; // 软件版本号
|
||||
char fpga_data[9]; // fpga版本日期
|
||||
} VersionRsp;
|
||||
#pragma pack()
|
||||
|
||||
#endif // DATA_CONFIG_H
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QTcpSocket>
|
||||
#include "keyphase.h"
|
||||
#include "singlerelay.h"
|
||||
#include "tachometer.h"
|
||||
@ -15,14 +16,13 @@
|
||||
#include <stdio.h>
|
||||
#include <QSysInfo>
|
||||
#include <qsettings.h>
|
||||
#include "ftpclient.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
slot = -1;
|
||||
btnGroup_slot = new QButtonGroup(this);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot3);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot4);
|
||||
@ -39,6 +39,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
btnGroup_slot->addButton(ui->pushButton_slot15);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot16);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot17);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot18);
|
||||
|
||||
ui->pushButton_slot->setChecked(true);
|
||||
readJsonFile(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
||||
@ -77,7 +78,7 @@ void MainWindow::readJsonFile(const QString &filePath)
|
||||
qDebug() << "JSON document is not an object or an array";
|
||||
return;
|
||||
}
|
||||
int slot_id = 3;
|
||||
int slot_id = 0;
|
||||
QJsonArray jsonArray = jsonDoc.array();
|
||||
for (const QJsonValue &value : jsonArray) {
|
||||
SlotConfig slot_config;
|
||||
@ -96,9 +97,9 @@ void MainWindow::createMenu()
|
||||
{
|
||||
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
||||
for (int i = 0; i < buttonList.count(); i++){
|
||||
buttonList[i]->setText(map_slot_config[i + 3].chan_display);
|
||||
createMenu(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||
map_slot_config[ i + 3].slot_btn = (QPushButton*)buttonList[i];
|
||||
buttonList[i]->setText(map_slot_config[i].chan_display);
|
||||
createMenu(QString("%1").arg(i + 3), (QPushButton*)buttonList[i]);
|
||||
map_slot_config[i].slot_btn = (QPushButton*)buttonList[i];
|
||||
// else
|
||||
// createMenuSet(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||
}
|
||||
@ -141,6 +142,7 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
||||
mainMenu->addMenu(keyphasor);
|
||||
QAction *reset = mainMenu->addAction("重置模块");
|
||||
QAction *upgrade = mainMenu->addAction("升级固件");
|
||||
QAction *version = mainMenu->addAction("查看版本");
|
||||
parent->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(parent,&QPushButton::customContextMenuRequested,[=](const QPoint &pos)
|
||||
{
|
||||
@ -157,6 +159,7 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
||||
QObject::connect(keyphasor_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(reset, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(upgrade, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(version, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
|
||||
}
|
||||
|
||||
@ -322,13 +325,10 @@ void MainWindow::onMenuActionTriggered()
|
||||
map_slot_config[button_id].chan_display = "";
|
||||
}
|
||||
}else if(action->text() == "升级固件"){
|
||||
sendUpgradePackage(button_id-3);
|
||||
sendUpgradePackage(button_id - 3);
|
||||
}else if(action->text() == "查看版本"){
|
||||
getVersion(button_id - 3);
|
||||
}
|
||||
// QMenu* menu = button->menu();
|
||||
// if (!menu) {
|
||||
// qWarning() << "菜单为空,无法清除属性!";
|
||||
// return;
|
||||
// }
|
||||
clearMenuProperties(button->menu());
|
||||
createMenu();
|
||||
break; // 找到按钮后,跳出循环
|
||||
@ -424,10 +424,10 @@ void MainWindow::on_pushButton_save_clicked()
|
||||
QJsonObject itemObj;
|
||||
QJsonArray slotArray;
|
||||
for(int i = 0; i < map_slot_config.size();i++){
|
||||
itemObj["slot"] = map_slot_config[i+3].slot;
|
||||
itemObj["slot_type"] = map_slot_config[i+3].slot_type;
|
||||
itemObj["chan_display"] = map_slot_config[i+3].chan_display;
|
||||
itemObj["rack_type"] = map_slot_config[i+3].rack_type;
|
||||
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;
|
||||
slotArray.append(itemObj);
|
||||
}
|
||||
QJsonDocument jsonDoc;
|
||||
@ -491,9 +491,8 @@ void MainWindow::sendUpgradePackage(int slot)
|
||||
PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize,0,{} };
|
||||
// 计算文件的 CRC 校验和
|
||||
|
||||
qDebug() << "filheader.file_md5" << slot <<endl;
|
||||
qDebug() << "filheader.slot" << slot <<endl;
|
||||
UpgradeCardReq upgrade_car_req;
|
||||
uint8_t card_id;
|
||||
if(slot == 0)
|
||||
upgrade_car_req.card_id = 0xFF;
|
||||
else
|
||||
@ -544,14 +543,8 @@ void MainWindow::sendUpgradePackage(int slot)
|
||||
// Handle error
|
||||
break;
|
||||
}
|
||||
|
||||
bytesSent += bytesWritten;
|
||||
}
|
||||
|
||||
// 发送头部
|
||||
// qDebug() << "File sent successfully";
|
||||
// // 等待服务器响应(根据需要处理响应)
|
||||
|
||||
if (socket.waitForReadyRead()) {
|
||||
QByteArray response = socket.readAll();
|
||||
UpgradeRsp resp;
|
||||
@ -569,3 +562,40 @@ void MainWindow::sendUpgradePackage(int slot)
|
||||
if(send_buf != NULL)
|
||||
free(send_buf);
|
||||
}
|
||||
void MainWindow::getVersion(int slot)
|
||||
{
|
||||
// 连接到服务器
|
||||
QTcpSocket socket;
|
||||
// 连接到服务器
|
||||
socket.connectToHost(m_strServerIp, 10000);
|
||||
if (!socket.waitForConnected()) {
|
||||
qDebug() << "Connection failed!";
|
||||
return;
|
||||
}
|
||||
PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1,0,{} };
|
||||
qDebug() << "slot" << slot <<endl;
|
||||
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);
|
||||
qint64 bytesWritten = socket.write(send_buf, length);
|
||||
qDebug() << "Server response: " << bytesWritten;
|
||||
if (socket.waitForReadyRead()) {
|
||||
QByteArray response = socket.readAll();
|
||||
VersionRsp version_rsp;
|
||||
PackageHead header;
|
||||
memcpy(&header,response.data(),sizeof(PackageHead));
|
||||
qDebug() << "header len" << header.len << endl;
|
||||
if(header.cmd == kGetVersionInfo){
|
||||
memcpy(&version_rsp,response.data() + sizeof(PackageHead),sizeof(VersionRsp));
|
||||
QString strVerion = QString("第 %1 板卡\nFPGA 版本:%2\n软件版本:%3\nFPGA版本日期:%4").arg(slot).arg(version_rsp.fpga).arg(version_rsp.sw).arg(version_rsp.fpga_data);
|
||||
QMessageBox::information(this, QStringLiteral("提示"), strVerion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,8 @@ private:
|
||||
|
||||
QButtonGroup * btnGroup_slot = nullptr;
|
||||
QString m_strServerIp; // 服务端IP
|
||||
int slot;
|
||||
|
||||
void createMenu();
|
||||
void createMenu(const QString& rootTitle, QPushButton* button = nullptr);
|
||||
void createMenuSet(const QString& rootTitle, QPushButton* button = nullptr);
|
||||
@ -41,6 +43,8 @@ private:
|
||||
|
||||
void readJsonFile(const QString &filePath);
|
||||
void sendUpgradePackage(int slot);
|
||||
void getVersion(int slot);
|
||||
|
||||
private slots:
|
||||
|
||||
void OnButtonGroup(QAbstractButton *);
|
||||
|
132
mainwindow.ui
132
mainwindow.ui
@ -362,9 +362,6 @@
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_19">
|
||||
<property name="minimumSize">
|
||||
@ -380,29 +377,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -424,7 +399,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -446,7 +421,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
<string>1</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -468,7 +443,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
<string>2</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -490,7 +465,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>6</string>
|
||||
<string>3</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -512,7 +487,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>7</string>
|
||||
<string>4</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -534,7 +509,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>8</string>
|
||||
<string>5</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -556,7 +531,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>9</string>
|
||||
<string>6</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -578,7 +553,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>10</string>
|
||||
<string>7</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -600,7 +575,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>11</string>
|
||||
<string>8</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -622,7 +597,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>12</string>
|
||||
<string>9</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -644,7 +619,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>13</string>
|
||||
<string>10</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -666,7 +641,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>14</string>
|
||||
<string>11</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -688,7 +663,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>15</string>
|
||||
<string>12</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -710,7 +685,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>16</string>
|
||||
<string>13</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -732,7 +707,29 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>17</string>
|
||||
<string>14</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>15</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
@ -779,28 +776,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>通信板</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_slot3">
|
||||
<property name="minimumSize">
|
||||
@ -819,7 +794,7 @@
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>CPU</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -841,7 +816,7 @@
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>振动</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -860,7 +835,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>振动</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -879,7 +854,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>振动</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -898,7 +873,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>振动</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -1092,6 +1067,25 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_slot18">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>280</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>280</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -1112,7 +1106,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1072</width>
|
||||
<height>23</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu">
|
||||
|
Loading…
x
Reference in New Issue
Block a user