add codes.
This commit is contained in:
parent
50901aefed
commit
576fe1ffd1
@ -11,7 +11,9 @@ CONFIG += c++11
|
||||
SOURCES += \
|
||||
MyTcpClient.cpp \
|
||||
acceleration.cpp \
|
||||
cardbase.cpp \
|
||||
common.cpp \
|
||||
config_mgr.cpp \
|
||||
keyphase.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
@ -21,13 +23,16 @@ SOURCES += \
|
||||
setpoint.cpp \
|
||||
singlerelay.cpp \
|
||||
tachometer.cpp \
|
||||
velocity.cpp
|
||||
velocity.cpp \
|
||||
vibrationdata.cpp
|
||||
|
||||
HEADERS += \
|
||||
MyTcpClient.h \
|
||||
acceleration.h \
|
||||
acceleration_ds.h \
|
||||
cardbase.h \
|
||||
common.h \
|
||||
config_mgr.h \
|
||||
data_config.h \
|
||||
displacement_ds.h \
|
||||
keyphase.h \
|
||||
@ -39,7 +44,8 @@ HEADERS += \
|
||||
singlerelay.h \
|
||||
tachometer.h \
|
||||
velocity.h \
|
||||
velocity_ds.h
|
||||
velocity_ds.h \
|
||||
vibrationdata.h
|
||||
|
||||
FORMS += \
|
||||
acceleration.ui \
|
||||
|
6
cardbase.cpp
Normal file
6
cardbase.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "cardbase.h"
|
||||
|
||||
CardBase::CardBase()
|
||||
{
|
||||
|
||||
}
|
67
cardbase.h
Normal file
67
cardbase.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef CARDBASE_H
|
||||
#define CARDBASE_H
|
||||
|
||||
#include "data_config.h"
|
||||
#ifdef NAME
|
||||
#undef NAME
|
||||
#endif
|
||||
#define NAME(x) (x, #x)
|
||||
|
||||
class CardBase {
|
||||
public:
|
||||
CardBase() {}
|
||||
~CardBase() {}
|
||||
void FromJson(const Json::Value &cfg) {
|
||||
version_ = cfg["version"].asInt();
|
||||
slot_ = cfg["slot"].asInt();
|
||||
card_type_ = static_cast<CardType>(cfg["type"].asInt());
|
||||
}
|
||||
|
||||
Json::Value ToJson() {
|
||||
Json::Value ch;
|
||||
ch[NAME(version)] = version_;
|
||||
ch[NAME(slot)] = slot_;
|
||||
ch[NAME(type)] = card_type_;
|
||||
return ch;
|
||||
}
|
||||
|
||||
protected:
|
||||
int version_;
|
||||
int slot_; // 从1~15
|
||||
CardType card_type_;
|
||||
};
|
||||
|
||||
class VariableBase {
|
||||
public:
|
||||
VariableBase() {}
|
||||
~VariableBase() {}
|
||||
// TODO: fromjson, tojson
|
||||
int id_;
|
||||
VibChannelType type_;
|
||||
Delay delay_;
|
||||
DirectImpl direct_;
|
||||
XImpl x1_;
|
||||
XImpl x2_;
|
||||
RecorderOut recorder_out_;
|
||||
};
|
||||
|
||||
// 位移
|
||||
class RadialVariable : public VariableBase {
|
||||
public:
|
||||
bool alert_latching_;
|
||||
bool danger_latching_;
|
||||
RadialImpl not1x_;
|
||||
RadialImpl smax_;
|
||||
};
|
||||
|
||||
// 加速度与速度
|
||||
class AccVelVariable : public VariableBase {
|
||||
public:
|
||||
bool alert_latching_;
|
||||
bool danger_latching_;
|
||||
bool timed_ok_;
|
||||
bool rms_active_;
|
||||
bool integrate_active_;
|
||||
};
|
||||
|
||||
#endif // CARDBASE_H
|
102
config_mgr.cpp
Normal file
102
config_mgr.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
#include "config_mgr.h"
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "data_config.h"
|
||||
#include "vibrationdata.h"
|
||||
|
||||
ConfigMgr *ConfigMgr::instance = nullptr;
|
||||
|
||||
ConfigMgr::~ConfigMgr() {
|
||||
}
|
||||
|
||||
void ConfigMgr::Save() {
|
||||
}
|
||||
|
||||
void ConfigMgr::Load(QString filename) {
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug() << "Cannot open file for reading:" << filename;
|
||||
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;
|
||||
}
|
||||
QJsonObject json_obj = jsonDoc.object();
|
||||
// parse card_type
|
||||
QJsonArray card_type = json_obj["card_type"].toArray();
|
||||
int slot = 0;
|
||||
QJsonObject temp_obj;
|
||||
for (int i = 0; i < card_type.size(); ++i) {
|
||||
temp_obj = card_type[i].toObject();
|
||||
slot = temp_obj["slot"].toInt();
|
||||
card_type_[slot - 1] = static_cast<CardType>(temp_obj["type"].toInt());
|
||||
}
|
||||
// parse each slot
|
||||
QJsonObject channel;
|
||||
for (int i = 0; i < SLOT_NUM; ++i) {
|
||||
if (card_type_[i] == kCardNone) {
|
||||
continue;
|
||||
}
|
||||
slot = i + 1;
|
||||
if (json_obj[QString::number(slot)].isNull()) {
|
||||
continue;
|
||||
}
|
||||
temp_obj = json_obj[QString::number(slot)].toObject();
|
||||
if (card_type_[i] == kCardVibSingle) {
|
||||
std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
|
||||
for (int j = 0; j < CHANNEL_COUNT; ++j) {
|
||||
channel = temp_obj[QString::number(j + 1)].toObject();
|
||||
// base info
|
||||
vib_data->base_config_[j].standby = channel["standby"].toBool();
|
||||
vib_data->base_config_[j].active = channel["active"].toBool();
|
||||
vib_data->base_config_[j].rack_type = channel["rack_type"].toInt();
|
||||
// vib_data->base_config_[j].tmr_group = channel["tmr_group"].toString();
|
||||
vib_data->base_config_[j].channel_type = channel["channel_type"].toInt();
|
||||
memset(vib_data->base_config_[j].transducer_name, 0, 32);
|
||||
memcpy(vib_data->base_config_[j].transducer_name, channel["transducer_name"].toString().toStdString().c_str(), channel["transducer_name"].toString().length());
|
||||
vib_data->base_config_[j].scale_factor = channel["scale_factor"].toDouble();
|
||||
vib_data->base_config_[j].sampling_rate = channel["sampling_rate"].toInt();
|
||||
QJsonArray voltage_range_array = channel["normal_voltage_range"].toArray();
|
||||
vib_data->base_config_[j].normal_voltage_low = voltage_range_array[0].toDouble();
|
||||
vib_data->base_config_[j].normal_voltage_high = voltage_range_array[1].toDouble();
|
||||
// filter
|
||||
QJsonArray filter_array = channel["filter"].toArray();
|
||||
for (int k = 0; k < filter_array.size(); k++) {
|
||||
QJsonObject filter_ele = filter_array[i].toObject();
|
||||
vib_data->filter_[j].filter[k].low = filter_ele["low"].toInt();
|
||||
vib_data->filter_[j].filter[k].high = filter_ele["high"].toInt();
|
||||
vib_data->filter_[j].filter[k].checked = filter_ele["checked"].toBool();
|
||||
}
|
||||
// variables
|
||||
QJsonObject tmp_variable = channel["variable"].toObject();
|
||||
switch (vib_data->base_config_[j].channel_type) {
|
||||
case kVibRadial: {
|
||||
std::shared_ptr<RadialVariable> radial_variable = std::make_shared<RadialVariable>();
|
||||
radial_variable->id_ = j + 1;
|
||||
vib_data->variables_.push_back(radial_variable);
|
||||
break;
|
||||
}
|
||||
case kVibVelocity:
|
||||
case kVibAcc: {
|
||||
std::shared_ptr<AccVelVariable> acc_vel_variable = std::make_shared<AccVelVariable>();
|
||||
vib_data->variables_.push_back(acc_vel_variable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cards_.push_back(vib_data);
|
||||
}
|
||||
}
|
||||
}
|
30
config_mgr.h
Normal file
30
config_mgr.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef CONFIG_MGR_H
|
||||
#define CONFIG_MGR_H
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "cardbase.h"
|
||||
|
||||
class ConfigMgr {
|
||||
private:
|
||||
static ConfigMgr *instance;
|
||||
ConfigMgr() {
|
||||
for (int i = 0; i < SLOT_NUM; ++i) {
|
||||
card_type_[i] = kCardNone;
|
||||
}
|
||||
}
|
||||
public:
|
||||
static ConfigMgr *Instance() {
|
||||
if (instance == nullptr) {
|
||||
instance = new ConfigMgr();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
~ConfigMgr();
|
||||
void Save();
|
||||
void Load(QString filename);
|
||||
private:
|
||||
int card_type_[15];
|
||||
std::vector<std::shared_ptr<CardBase>> cards_;
|
||||
};
|
||||
|
||||
#endif // CONFIG_MGR_H
|
@ -10,7 +10,34 @@ typedef unsigned short uint16_t;
|
||||
|
||||
extern QString g_strServerIp; // 服务端IP
|
||||
|
||||
#define CHANNLE_COUNT 4
|
||||
#define SLOT_NUM 15
|
||||
#define CHANNEL_COUNT 4
|
||||
|
||||
typedef enum {
|
||||
kCardNone = 0,
|
||||
kCardCpu = 1,
|
||||
|
||||
kCardVibSingle = 10,
|
||||
kCardVibTMRPrimary = 11,
|
||||
kCardVibTMRBackup = 12,
|
||||
|
||||
kCardSpeedSingle = 20,
|
||||
kCardSpeedTMRPrimary = 21,
|
||||
kCardSpeedTMRBackup = 22,
|
||||
|
||||
kCardKeyphase = 30,
|
||||
kCardRelaySingle = 31,
|
||||
kCardRelayTMRPrimary = 32,
|
||||
kCardRelayTMRBackup = 33,
|
||||
} CardType;
|
||||
|
||||
// 振动板通道类型
|
||||
typedef enum {
|
||||
kVibRadial = 0, // 径向位移
|
||||
kVibAcc = 1, // 加速度
|
||||
kVibVelocity = 2 // 速度
|
||||
} VibChannelType;
|
||||
|
||||
typedef struct {
|
||||
int slot;
|
||||
QString slot_type;
|
||||
@ -30,13 +57,6 @@ enum CMTCommand {
|
||||
kUpgradeProgress = 7
|
||||
};
|
||||
|
||||
// 振动板通道类型
|
||||
typedef enum {
|
||||
kVibRadial = 0, // 径向位移
|
||||
kVibAcc = 1, // 加速度
|
||||
kVibVelocity = 2 // 速度
|
||||
} VibChannelType;
|
||||
|
||||
// 振动板采样率
|
||||
typedef enum {
|
||||
kVibSR16K = 0, // 16k
|
||||
@ -53,26 +73,35 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
QString channel_name;
|
||||
// QString channel_name;
|
||||
bool standby;
|
||||
bool active;
|
||||
int rack_type; // VibRackType
|
||||
QString tmr_group;
|
||||
char tmr_group[32];
|
||||
int channel_type; // VibChannelType
|
||||
QString transducer_name;
|
||||
char transducer_name[32];
|
||||
float scale_factor;
|
||||
int sampling_rate; // VibSamplingRate
|
||||
float normal_voltage_low;
|
||||
float normal_voltage_high;
|
||||
} SeismicMonitor;
|
||||
|
||||
typedef enum {
|
||||
kFilterTypeLowPass = 0,
|
||||
kFilterTypeHighPass = 1,
|
||||
kFilterTypeBandPass = 2,
|
||||
} FilterType;
|
||||
|
||||
typedef struct {
|
||||
QString type;
|
||||
int low;
|
||||
int high;
|
||||
bool checked;
|
||||
} Filter;
|
||||
|
||||
typedef struct {
|
||||
Filter filter[3]; // 0: kFilterTypeLowPass, 1: kFilterTypeHighPass, 2: kFilterTypeBandPass
|
||||
} AllFilter;
|
||||
|
||||
typedef struct {
|
||||
QString type;
|
||||
int full_sacle_range;
|
||||
@ -83,11 +112,33 @@ typedef struct {
|
||||
float custom;
|
||||
} Variables;
|
||||
|
||||
typedef struct {
|
||||
int full_sacle_range;
|
||||
float clamp_value;
|
||||
float custom;
|
||||
} DirectImpl;
|
||||
|
||||
typedef struct {
|
||||
bool checked;
|
||||
int full_sacle_range;
|
||||
float clamp_value;
|
||||
float custom;
|
||||
int phase_lag;
|
||||
} XImpl;
|
||||
|
||||
typedef struct {
|
||||
bool checked;
|
||||
int full_sacle_range;
|
||||
float clamp_value;
|
||||
float custom;
|
||||
} RadialImpl;
|
||||
|
||||
typedef struct {
|
||||
int alert;
|
||||
float danger;
|
||||
bool active_100ms;
|
||||
} Dealy;
|
||||
} Delay;
|
||||
|
||||
typedef struct {
|
||||
bool rms_active;
|
||||
bool integrate_active;
|
||||
@ -101,6 +152,14 @@ typedef struct {
|
||||
int comparision_percentage;
|
||||
} Alert_Variables;
|
||||
|
||||
typedef struct {
|
||||
int recorder_output;
|
||||
bool two_ma_clamp;
|
||||
float trip_multiply;
|
||||
QString comparision;
|
||||
int comparision_percentage;
|
||||
} RecorderOut;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
bool active;
|
||||
|
346
mainwindow.cpp
346
mainwindow.cpp
@ -24,10 +24,9 @@ QString g_strServerIp;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
, ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
QMenuBar* menuBar = this->menuBar();
|
||||
QMenuBar *menuBar = this->menuBar();
|
||||
this->setMenuBar(menuBar); //添加到对象树
|
||||
menuBar->addMenu(ui->menu_tool);
|
||||
ui->widget_body->setProperty("flag", "title");
|
||||
@ -35,19 +34,15 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
//关联事件过滤器用于双击放大
|
||||
ui->widget_body->installEventFilter(this);
|
||||
ui->widget_body->setProperty("flag", "body");
|
||||
ui->statusBar->setProperty("flag","status");
|
||||
|
||||
ui->statusBar->setProperty("flag", "status");
|
||||
// 创建进度条
|
||||
progressBar = new QProgressBar(this);
|
||||
|
||||
// 设置进度条的范围(0到100)
|
||||
progressBar->setRange(0, 100);
|
||||
|
||||
// 将进度条添加到状态栏
|
||||
statusBar()->addWidget(progressBar);
|
||||
progressBar->setVisible(false); // 初始隐藏
|
||||
progressBar->setFixedWidth(300);
|
||||
|
||||
//this->initStyle();
|
||||
//添加信号槽
|
||||
QObject::connect(ui->action_realy, &QAction::triggered, this, &MainWindow::onMenuAction_relay);
|
||||
@ -69,7 +64,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
btnGroup_slot->addButton(ui->pushButton_slot13);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot14);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot15);
|
||||
|
||||
list_label.reserve(16);
|
||||
list_label.push_back(ui->label_18);
|
||||
list_label.push_back(ui->label_1);
|
||||
@ -87,51 +81,42 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
list_label.push_back(ui->label_13);
|
||||
list_label.push_back(ui->label_14);
|
||||
list_label.push_back(ui->label_15);
|
||||
|
||||
|
||||
ui->pushButton_slot->setChecked(true);
|
||||
readJsonFile(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
||||
createMenu();
|
||||
|
||||
connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *)));
|
||||
QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini",QSettings::IniFormat);
|
||||
|
||||
QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat);
|
||||
g_strServerIp = settingsread.value("Server/IP").toString();
|
||||
//connectServer();
|
||||
// 设置自定义日志处理函数
|
||||
#ifndef QT_DEBUG
|
||||
qInstallMessageHandler(messageHandler);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
}
|
||||
void MainWindow::onDisConnected()
|
||||
{
|
||||
|
||||
void MainWindow::onDisConnected() {
|
||||
statusBar()->showMessage("连接失败!正在重连……", 3000); // 显示3秒
|
||||
}
|
||||
void MainWindow::onConnected()
|
||||
{
|
||||
|
||||
void MainWindow::onConnected() {
|
||||
statusBar()->showMessage("连接成功!", 3000); // 显示3秒
|
||||
}
|
||||
void MainWindow::connectServer()
|
||||
{
|
||||
|
||||
void MainWindow::connectServer() {
|
||||
m_tcpClient = MyTcpClient::instance();
|
||||
// 监听信号
|
||||
connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray&)), this, SLOT(readData(const QByteArray&)));
|
||||
connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &)));
|
||||
connect(m_tcpClient, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
|
||||
connect(m_tcpClient, SIGNAL(connected()), this, SLOT(onConnected()));
|
||||
// 连接服务器
|
||||
m_tcpClient->connectToServer(g_strServerIp, 10000);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::initStyle()
|
||||
{
|
||||
void MainWindow::initStyle() {
|
||||
//加载样式表
|
||||
QString qss;
|
||||
QFile file(":/qss/soft.css");
|
||||
@ -143,8 +128,8 @@ void MainWindow::initStyle()
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
void MainWindow::readJsonFile(const QString &filePath)
|
||||
{
|
||||
|
||||
void MainWindow::readJsonFile(const QString &filePath) {
|
||||
// 创建文件对象
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
@ -153,9 +138,7 @@ void MainWindow::readJsonFile(const QString &filePath)
|
||||
}
|
||||
QString content = file.readAll();
|
||||
file.close();
|
||||
|
||||
QByteArray jsonData = content.toUtf8();
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
||||
if (jsonDoc.isNull()) {
|
||||
qDebug() << "Cannot parse JSON document";
|
||||
@ -175,56 +158,47 @@ void MainWindow::readJsonFile(const QString &filePath)
|
||||
slot_config.slot_type = obj["slot_type"].toString();
|
||||
slot_config.chan_display = obj["chan_display"].toString();
|
||||
slot_config.rack_type = obj["rack_type"].toString();
|
||||
map_slot_config.insert(slot_id,slot_config);
|
||||
map_slot_config.insert(slot_id, slot_config);
|
||||
slot_id ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
void MainWindow::createMenu()
|
||||
{
|
||||
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
||||
for (int i = 0; i < buttonList.count(); i++){
|
||||
|
||||
void MainWindow::createMenu() {
|
||||
QList<QAbstractButton *> buttonList = btnGroup_slot->buttons();
|
||||
for (int i = 0; i < buttonList.count(); i++) {
|
||||
buttonList[i]->setText(map_slot_config[i].chan_display);
|
||||
createMenu(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||
map_slot_config[i].slot_btn = (QPushButton*)buttonList[i];
|
||||
createMenu(QString("%1").arg(i + 1), (QPushButton *)buttonList[i]);
|
||||
map_slot_config[i].slot_btn = (QPushButton *)buttonList[i];
|
||||
map_slot_config[i].slot_label = list_label[i];
|
||||
// else
|
||||
// createMenuSet(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||
}
|
||||
}
|
||||
void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
||||
{
|
||||
|
||||
void MainWindow::createMenu(const QString &rootTitle, QPushButton *parent) {
|
||||
// 创建主菜单
|
||||
QMenu *mainMenu = new QMenu(rootTitle, parent);
|
||||
|
||||
// 创建第一层子菜单
|
||||
QMenu *monitors = new QMenu("监视器", mainMenu);
|
||||
QMenu *relays = new QMenu("/DOM810 继电器模块", mainMenu);
|
||||
QMenu *keyphasor = new QMenu("/KPM834 键相模块", mainMenu);
|
||||
|
||||
// 创建第二层子菜单:/HAM824 振动板卡
|
||||
QMenu *proximitor_menu = new QMenu("/HAM824 振动板卡", monitors);
|
||||
QMenu *rpm_menu = new QMenu("/OPM844 转速板卡", monitors);
|
||||
|
||||
// 创建第三层子菜单:/HAM824 单板卡、三冗余板卡
|
||||
QAction *proximitor_1 = proximitor_menu->addAction("/HAM824 单板卡");
|
||||
QAction *proximitor_2 = proximitor_menu->addAction("/HAM824 三冗余板卡");
|
||||
|
||||
QAction *rpm_1 = rpm_menu->addAction("/OPM844 单板卡");
|
||||
|
||||
|
||||
// 创建第二层子菜单:/KPM834 键相模块
|
||||
QAction *keyphasor_1 = keyphasor->addAction("/KPM834 单板卡");
|
||||
QAction *keyphasor_2 = keyphasor->addAction("/KPM834 两板卡");
|
||||
|
||||
// 创建第二层子菜单:/DOM810 继电器模块
|
||||
QAction *relays_1 = relays->addAction("/DOM810 单板卡");
|
||||
QAction *relays_2 = relays->addAction("/DOM810 三冗余板卡");
|
||||
|
||||
// 将子菜单加入上一级菜单
|
||||
monitors->addMenu(proximitor_menu); // 将第二层加入第一层
|
||||
monitors->addMenu(rpm_menu); // 第二层另一个子菜单
|
||||
|
||||
mainMenu->addMenu(monitors); // 将第一层加入主菜单
|
||||
mainMenu->addMenu(relays);
|
||||
mainMenu->addMenu(keyphasor);
|
||||
@ -234,100 +208,89 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
||||
// 绑定 **鼠标事件过滤器**,确保只响应右键
|
||||
// 设置右键菜单策略
|
||||
parent->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// 使用 `customContextMenuRequested` 事件,确保只有右键点击时弹出菜单
|
||||
connect(parent, &QPushButton::customContextMenuRequested, this, [=](const QPoint &pos)
|
||||
{
|
||||
connect(parent, &QPushButton::customContextMenuRequested, this, [ = ](const QPoint &pos) {
|
||||
qDebug() << "右键菜单触发1:" << pos;
|
||||
|
||||
// 弹出菜单并捕获右键点击
|
||||
mainMenu->exec(QCursor::pos());
|
||||
|
||||
mainMenu->close();
|
||||
});
|
||||
// 连接所有菜单项
|
||||
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);
|
||||
QObject::connect(upgrade, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(version, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
|
||||
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);
|
||||
QObject::connect(upgrade, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(version, &QAction::triggered, this, &MainWindow::onMenuActionTriggered);
|
||||
}
|
||||
|
||||
void MainWindow::createMenuSet(const QString& rootTitle, QPushButton* parent )
|
||||
{
|
||||
void MainWindow::createMenuSet(const QString &rootTitle, QPushButton *parent) {
|
||||
// 创建主菜单
|
||||
qDebug() << "createMenu" << parent->objectName() ;
|
||||
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)
|
||||
{
|
||||
void MainWindow::clearMenuProperties(QMenu *menu) {
|
||||
// 遍历菜单的所有动作
|
||||
if (!menu) {
|
||||
qWarning() << "菜单为空,无法清除属性!";
|
||||
return;
|
||||
}
|
||||
|
||||
// 遍历菜单的所有动作
|
||||
for (QAction* action : menu->actions()) {
|
||||
if (!action) continue;
|
||||
|
||||
for (QAction *action : menu->actions()) {
|
||||
if (!action) {
|
||||
continue;
|
||||
}
|
||||
// 检查是否有子菜单
|
||||
if (QMenu* subMenu = action->menu()) {
|
||||
if (QMenu *subMenu = action->menu()) {
|
||||
clearMenuProperties(subMenu); // 递归处理子菜单
|
||||
}
|
||||
|
||||
// 清除动作的属性
|
||||
action->setProperty("customProperty", QVariant());
|
||||
qDebug() << "清除了属性,动作:" << action->text();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuActionTriggered()
|
||||
{
|
||||
void MainWindow::onMenuActionTriggered() {
|
||||
qDebug() << "onMenuActionTriggered()" ;
|
||||
QAction *action = qobject_cast<QAction*>(sender());
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (action) {
|
||||
// 获取触发动作的父菜单
|
||||
QMenu *menu = qobject_cast<QMenu*>(action->parent());
|
||||
QMenu *menu = qobject_cast<QMenu *>(action->parent());
|
||||
// 遍历所有父菜单,直到找到按钮
|
||||
while (menu) {
|
||||
QPushButton *button = qobject_cast<QPushButton*>(menu->parent());
|
||||
QPushButton *button = qobject_cast<QPushButton *>(menu->parent());
|
||||
if (button) {
|
||||
qDebug() << "子菜单项被点击,所属按钮:" << button->objectName() << action->text();
|
||||
QString slot_type = action->text().mid(1,6);
|
||||
QString rack_type = action->text().right(action->text().length()-8);
|
||||
int button_id = button->objectName().right(button->objectName().length()-15).toInt();
|
||||
QString slot_type = action->text().mid(1, 6);
|
||||
QString rack_type = action->text().right(action->text().length() - 8);
|
||||
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 ;
|
||||
map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}");
|
||||
QString chan_display = "";
|
||||
if(slot_type == "DOM810")
|
||||
if (slot_type == "DOM810") {
|
||||
chan_display = "继电器";
|
||||
else if(slot_type == "KPM834")
|
||||
} else if (slot_type == "KPM834") {
|
||||
chan_display = "键相";
|
||||
else if(slot_type == "HAM824")
|
||||
} else if (slot_type == "HAM824") {
|
||||
chan_display = "振动";
|
||||
else if(slot_type == "OPM844")
|
||||
} else if (slot_type == "OPM844") {
|
||||
chan_display = "转速";
|
||||
if(rack_type == "三冗余板卡" && (map_slot_config[button_id].slot_type != "" || map_slot_config[button_id + 1].slot_type != "" \
|
||||
|| map_slot_config[button_id + 2].slot_type != "")){
|
||||
}
|
||||
if (rack_type == "三冗余板卡" && (map_slot_config[button_id].slot_type != "" || map_slot_config[button_id + 1].slot_type != "" \
|
||||
|| map_slot_config[button_id + 2].slot_type != "")) {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠三冗余板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
}else if(rack_type == "三冗余板卡" && map_slot_config[button_id + 1].slot_type == "" \
|
||||
&& map_slot_config[button_id + 2].slot_type == ""){
|
||||
|
||||
|
||||
} else if (rack_type == "三冗余板卡" && map_slot_config[button_id + 1].slot_type == "" \
|
||||
&& map_slot_config[button_id + 2].slot_type == "") {
|
||||
map_slot_config[button_id].slot_type = slot_type;
|
||||
map_slot_config[button_id].rack_type = "TMR1";
|
||||
map_slot_config[button_id].slot_btn->setText(chan_display);
|
||||
@ -341,10 +304,10 @@ void MainWindow::onMenuActionTriggered()
|
||||
map_slot_config[button_id + 2].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id + 2].chan_display = chan_display;
|
||||
}
|
||||
if(rack_type == "两板卡" && (map_slot_config[button_id].slot_type != "" || map_slot_config[button_id + 1].slot_type != "" )){
|
||||
if (rack_type == "两板卡" && (map_slot_config[button_id].slot_type != "" || map_slot_config[button_id + 1].slot_type != "")) {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠两板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
}else if(rack_type == "两板卡" && map_slot_config[button_id + 1].slot_type == ""){
|
||||
} else if (rack_type == "两板卡" && map_slot_config[button_id + 1].slot_type == "") {
|
||||
map_slot_config[button_id].slot_type = slot_type;
|
||||
map_slot_config[button_id].rack_type = "Double1";
|
||||
map_slot_config[button_id].slot_btn->setText(chan_display);
|
||||
@ -354,18 +317,17 @@ void MainWindow::onMenuActionTriggered()
|
||||
map_slot_config[button_id + 1].slot_btn->setText(chan_display);
|
||||
map_slot_config[button_id + 1].chan_display = chan_display;
|
||||
}
|
||||
if(rack_type == "单板卡" && map_slot_config[button_id].slot_type != ""){
|
||||
if (rack_type == "单板卡" && map_slot_config[button_id].slot_type != "") {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠单板卡配置,请在创建新配置之前移除现有的配置!");
|
||||
return;
|
||||
}else if(rack_type == "单板卡" && map_slot_config[button_id].slot_type == "") {
|
||||
} else if (rack_type == "单板卡" && map_slot_config[button_id].slot_type == "") {
|
||||
map_slot_config[button_id].slot_type = slot_type;
|
||||
map_slot_config[button_id].rack_type = "Single";
|
||||
map_slot_config[button_id].chan_display = chan_display;
|
||||
button->setText(chan_display);
|
||||
}
|
||||
|
||||
if(action->text() == "重置模块"){
|
||||
if(map_slot_config[button_id].rack_type == "TMR1"){
|
||||
if (action->text() == "重置模块") {
|
||||
if (map_slot_config[button_id].rack_type == "TMR1") {
|
||||
map_slot_config[button_id].slot_type = "";
|
||||
map_slot_config[button_id].rack_type = "0";
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
@ -378,7 +340,7 @@ void MainWindow::onMenuActionTriggered()
|
||||
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"){
|
||||
} else if (map_slot_config[button_id].rack_type == "TMR2") {
|
||||
map_slot_config[button_id - 1].slot_type = "";
|
||||
map_slot_config[button_id - 1].rack_type = "0";
|
||||
map_slot_config[button_id - 1].slot_btn->setText("");
|
||||
@ -391,7 +353,7 @@ void MainWindow::onMenuActionTriggered()
|
||||
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"){
|
||||
} else if (map_slot_config[button_id].rack_type == "TMR3") {
|
||||
map_slot_config[button_id - 2].slot_type = "";
|
||||
map_slot_config[button_id - 2].rack_type = "0";
|
||||
map_slot_config[button_id - 2].slot_btn->setText("");
|
||||
@ -405,8 +367,7 @@ void MainWindow::onMenuActionTriggered()
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
map_slot_config[button_id].chan_display = "";
|
||||
}
|
||||
|
||||
if(map_slot_config[button_id].rack_type == "Double1"){
|
||||
if (map_slot_config[button_id].rack_type == "Double1") {
|
||||
map_slot_config[button_id].slot_type = "";
|
||||
map_slot_config[button_id].rack_type = "0";
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
@ -415,8 +376,7 @@ void MainWindow::onMenuActionTriggered()
|
||||
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"){
|
||||
} else if (map_slot_config[button_id].rack_type == "Double2") {
|
||||
map_slot_config[button_id - 1].slot_type = "";
|
||||
map_slot_config[button_id - 1].rack_type = "0";
|
||||
map_slot_config[button_id - 1].slot_btn->setText("");
|
||||
@ -426,55 +386,51 @@ void MainWindow::onMenuActionTriggered()
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
map_slot_config[button_id].chan_display = "";
|
||||
}
|
||||
if(map_slot_config[button_id].rack_type == "Single"){
|
||||
if (map_slot_config[button_id].rack_type == "Single") {
|
||||
map_slot_config[button_id].slot_type = "";
|
||||
map_slot_config[button_id].rack_type = "0";
|
||||
map_slot_config[button_id].slot_btn->setText("");
|
||||
map_slot_config[button_id].chan_display = "";
|
||||
}
|
||||
|
||||
}else if(action->text() == "升级固件"){
|
||||
} else if (action->text() == "升级固件") {
|
||||
sendUpgradePackage(button_id);
|
||||
}else if(action->text() == "查看版本"){
|
||||
} else if (action->text() == "查看版本") {
|
||||
getVersion(button_id);
|
||||
}
|
||||
break; // 找到按钮后,跳出循环
|
||||
}
|
||||
// 如果没有找到按钮,继续向上查找
|
||||
menu = qobject_cast<QMenu*>(menu->parent());
|
||||
menu = qobject_cast<QMenu *>(menu->parent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OnButtonGroup(QAbstractButton * slot_btn)
|
||||
{
|
||||
if(slot_btn != NULL && ui->pushButton_chan->isChecked())
|
||||
{
|
||||
void MainWindow::OnButtonGroup(QAbstractButton *slot_btn) {
|
||||
if (slot_btn != NULL && ui->pushButton_chan->isChecked()) {
|
||||
QString object_name = slot_btn->objectName();
|
||||
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];
|
||||
map_slot_config[button_id].slot_label->setStyleSheet("QLabel { color :#2980b9; font: bold 16px}");
|
||||
if (slot_config.slot_type == "KPM834"){// 键相模块
|
||||
if (slot_config.slot_type == "KPM834") { // 键相模块
|
||||
KeyPhase *key_phase = new KeyPhase(button_id);
|
||||
key_phase->setWindowModality(Qt::ApplicationModal);
|
||||
key_phase->show();
|
||||
}else if (slot_config.slot_type == "DOM810"){// 继电器模块
|
||||
} else if (slot_config.slot_type == "DOM810") { // 继电器模块
|
||||
SingleRelay *single_relay = new SingleRelay();
|
||||
single_relay->setWindowModality(Qt::ApplicationModal);
|
||||
single_relay->show();
|
||||
}else if (slot_config.slot_type == "HAM824"){// 振动模块
|
||||
} else if (slot_config.slot_type == "HAM824") { // 振动模块
|
||||
Seismic_monitor *seismic_monitor = new Seismic_monitor(button_id);
|
||||
seismic_monitor->setWindowModality(Qt::ApplicationModal);
|
||||
seismic_monitor->show();
|
||||
}else if (slot_config.slot_type == "OPM844"){// 转速模块
|
||||
} else if (slot_config.slot_type == "OPM844") { // 转速模块
|
||||
Tachometer *tachometer = new Tachometer(button_id);
|
||||
tachometer->setWindowModality(Qt::ApplicationModal);
|
||||
tachometer->show();
|
||||
|
||||
}
|
||||
}
|
||||
if(slot_btn != NULL && ui->pushButton_alarm->isChecked()){
|
||||
if (slot_btn != NULL && ui->pushButton_alarm->isChecked()) {
|
||||
QString object_name = slot_btn->objectName();
|
||||
qDebug() << object_name ;
|
||||
Setpoint *setpoint = new Setpoint();
|
||||
@ -483,66 +439,69 @@ void MainWindow::OnButtonGroup(QAbstractButton * slot_btn)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_slot_clicked()
|
||||
{
|
||||
if(ui->pushButton_chan->isChecked())
|
||||
void MainWindow::on_pushButton_slot_clicked() {
|
||||
if (ui->pushButton_chan->isChecked()) {
|
||||
ui->pushButton_chan->setChecked(false);
|
||||
if(ui->pushButton_alarm->isChecked())
|
||||
}
|
||||
if (ui->pushButton_alarm->isChecked()) {
|
||||
ui->pushButton_alarm->setChecked(false);
|
||||
if(ui->pushButton_point_name->isChecked())
|
||||
}
|
||||
if (ui->pushButton_point_name->isChecked()) {
|
||||
ui->pushButton_point_name->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_chan_clicked()
|
||||
{
|
||||
if(ui->pushButton_slot->isChecked())
|
||||
void MainWindow::on_pushButton_chan_clicked() {
|
||||
if (ui->pushButton_slot->isChecked()) {
|
||||
ui->pushButton_slot->setChecked(false);
|
||||
if(ui->pushButton_alarm->isChecked())
|
||||
}
|
||||
if (ui->pushButton_alarm->isChecked()) {
|
||||
ui->pushButton_alarm->setChecked(false);
|
||||
if(ui->pushButton_point_name->isChecked())
|
||||
}
|
||||
if (ui->pushButton_point_name->isChecked()) {
|
||||
ui->pushButton_point_name->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_alarm_clicked()
|
||||
{
|
||||
if(ui->pushButton_slot->isChecked())
|
||||
void MainWindow::on_pushButton_alarm_clicked() {
|
||||
if (ui->pushButton_slot->isChecked()) {
|
||||
ui->pushButton_slot->setChecked(false);
|
||||
if(ui->pushButton_chan->isChecked())
|
||||
}
|
||||
if (ui->pushButton_chan->isChecked()) {
|
||||
ui->pushButton_chan->setChecked(false);
|
||||
if(ui->pushButton_point_name->isChecked())
|
||||
}
|
||||
if (ui->pushButton_point_name->isChecked()) {
|
||||
ui->pushButton_point_name->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_point_name_clicked()
|
||||
{
|
||||
if(ui->pushButton_slot->isChecked())
|
||||
void MainWindow::on_pushButton_point_name_clicked() {
|
||||
if (ui->pushButton_slot->isChecked()) {
|
||||
ui->pushButton_slot->setChecked(false);
|
||||
if(ui->pushButton_chan->isChecked())
|
||||
}
|
||||
if (ui->pushButton_chan->isChecked()) {
|
||||
ui->pushButton_chan->setChecked(false);
|
||||
if(ui->pushButton_alarm->isChecked())
|
||||
}
|
||||
if (ui->pushButton_alarm->isChecked()) {
|
||||
ui->pushButton_alarm->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuAction_relay()
|
||||
{
|
||||
void MainWindow::onMenuAction_relay() {
|
||||
qDebug() << " onMenuAction_relay " ;
|
||||
RelaySetting *relay_setting = new RelaySetting();
|
||||
relay_setting->setWindowModality(Qt::ApplicationModal);
|
||||
relay_setting->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_save_clicked()
|
||||
{
|
||||
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+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;
|
||||
for (int i = 0; i < map_slot_config.size(); i++) {
|
||||
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;
|
||||
@ -553,46 +512,43 @@ void MainWindow::on_pushButton_save_clicked()
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_open_clicked()
|
||||
{
|
||||
|
||||
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;
|
||||
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)
|
||||
{
|
||||
|
||||
void MainWindow::sendUpgradePackage(int slot) {
|
||||
QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*"));
|
||||
qDebug() << filepath << slot ;
|
||||
QFileInfo fileinfo;
|
||||
fileinfo = QFileInfo(filepath);
|
||||
QString file_suffix = fileinfo.suffix();
|
||||
QString FileName = fileinfo.fileName();
|
||||
if(FileName.isEmpty())
|
||||
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();
|
||||
if(fileSize > 10 * 1024 * 1024)
|
||||
{
|
||||
if (fileSize > 10 * 1024 * 1024) {
|
||||
QMessageBox::information(this, QStringLiteral("提示"), "文件大小超过10M,请重新选择!");
|
||||
file.close();
|
||||
return;
|
||||
@ -605,39 +561,34 @@ void MainWindow::sendUpgradePackage(int slot)
|
||||
}
|
||||
qDebug() << "fileSize" << fileSize ;
|
||||
// 创建 PackageHead 结构体
|
||||
PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize,0,{} };
|
||||
PackageHead header = { {0xAA, 0x55, 0xAA}, 3, fileSize, 0, {} };
|
||||
// 计算文件的 CRC 校验和
|
||||
|
||||
qDebug() << "filheader.slot" << slot ;
|
||||
UpgradeCardReq upgrade_car_req;
|
||||
if(slot == 0)
|
||||
if (slot == 0) {
|
||||
upgrade_car_req.card_id = 0xFF;
|
||||
else
|
||||
} else {
|
||||
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 + sizeof(UpgradeCardReq);
|
||||
qDebug() << "filheader.crc" << header.crc << "card_id" << upgrade_car_req.card_id << "header len" << header.len;
|
||||
|
||||
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);
|
||||
memset(send_buf, 0, sizeof(PackageHead) + sizeof(UpgradeCardReq) + fileData.size() + 1);
|
||||
memcpy(send_buf, &header, sizeof(PackageHead));
|
||||
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;
|
||||
qDebug() << "totalBytes" << totalBytes ;
|
||||
|
||||
while (bytesSent < totalBytes) {
|
||||
qint64 chunkSize = 0;
|
||||
if(MAX_CHUNK_SIZE < totalBytes - bytesSent){
|
||||
if (MAX_CHUNK_SIZE < totalBytes - bytesSent) {
|
||||
chunkSize = MAX_CHUNK_SIZE;
|
||||
|
||||
}else{
|
||||
} else {
|
||||
chunkSize = totalBytes - bytesSent;
|
||||
}
|
||||
qint64 bytesWritten = m_tcpClient->sendData(send_buf + bytesSent, chunkSize);
|
||||
@ -655,39 +606,40 @@ void MainWindow::sendUpgradePackage(int slot)
|
||||
progressBar->setTextVisible(true);
|
||||
progressBar->setFormat(upgrade_text);
|
||||
file.close();
|
||||
if(send_buf != NULL)
|
||||
if (send_buf != NULL) {
|
||||
free(send_buf);
|
||||
}
|
||||
}
|
||||
void MainWindow::getVersion(int slot)
|
||||
{
|
||||
|
||||
void MainWindow::getVersion(int slot) {
|
||||
slot_no = slot;
|
||||
PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1,0,{} };
|
||||
PackageHead header = { {0xAA, 0x55, 0xAA}, kGetVersionInfo, 1, 0, {} };
|
||||
qDebug() << "slot" << slot ;
|
||||
GetVersionReq get_version_req;
|
||||
if(slot == 0)
|
||||
if (slot == 0) {
|
||||
get_version_req.card_id = 0xFF;
|
||||
else
|
||||
} 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));
|
||||
}
|
||||
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 = m_tcpClient->sendData(send_buf, length);
|
||||
m_tcpClient->waitForRead();
|
||||
qDebug() << "bytesWritten: " << bytesWritten;
|
||||
}
|
||||
|
||||
void MainWindow::readData(const QByteArray& data)
|
||||
{
|
||||
void MainWindow::readData(const QByteArray &data) {
|
||||
qDebug() << "Received from server:" << data;
|
||||
PackageHead header;
|
||||
memcpy(&header,data.data(),sizeof(PackageHead));
|
||||
if(header.cmd == kGetVersionInfo){
|
||||
memcpy(&header, data.data(), sizeof(PackageHead));
|
||||
if (header.cmd == kGetVersionInfo) {
|
||||
VersionRsp version_rsp;
|
||||
memcpy(&version_rsp,data.data() + sizeof(PackageHead),sizeof(VersionRsp));
|
||||
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){
|
||||
} else if (header.cmd == kUpgradeCard) {
|
||||
UpgradeRsp resp;
|
||||
QByteArray byteArray = data.mid(sizeof(PackageHead));
|
||||
QDataStream stream(&byteArray, QIODevice::ReadOnly);
|
||||
@ -695,13 +647,13 @@ void MainWindow::readData(const QByteArray& data)
|
||||
// if(resp.code == 1){
|
||||
// QMessageBox::information(this, QStringLiteral("提示"), "上传成功!");
|
||||
// }
|
||||
}else if(header.cmd == kUpgradeProgress){
|
||||
} 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){
|
||||
if (upgrade_resp.code == 100) {
|
||||
progressBar->setVisible(false);
|
||||
statusBar()->showMessage("升级完成!", 3000); // 显示3秒
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ void Seismic_monitor::readJsonFile(const QString &filePath) {
|
||||
for (int i = 0; i < chan_array.size(); i++) {
|
||||
QJsonObject temp_obj = chan_array[i].toObject();
|
||||
seismic_monitor[i].id = temp_obj["id"].toInt();
|
||||
seismic_monitor[i].channel_name = temp_obj["channle_name"].toString();
|
||||
// seismic_monitor[i].channel_name = temp_obj["channle_name"].toString();
|
||||
seismic_monitor[i].standby = temp_obj["standby"].toBool();
|
||||
seismic_monitor[i].active = temp_obj["active"].toBool();
|
||||
seismic_monitor[i].rack_type = temp_obj["rack_type"].toInt();
|
||||
@ -71,7 +71,7 @@ void Seismic_monitor::readJsonFile(const QString &filePath) {
|
||||
seismic_monitor[i].channel_type = temp_obj["channel_type"].toInt();
|
||||
seismic_monitor[i].transducer_name = temp_obj["transducer_name"].toString();
|
||||
seismic_monitor[i].scale_factor = temp_obj["scale_factor"].toDouble();
|
||||
seismic_monitor[i].sampling_rate = temp_obj["sample_rate"].toInt();
|
||||
seismic_monitor[i].sampling_rate = temp_obj["sampling_rate"].toInt();
|
||||
QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray();
|
||||
seismic_monitor[i].normal_voltage_low = voltage_range_array[0].toDouble();
|
||||
seismic_monitor[i].normal_voltage_high = voltage_range_array[1].toDouble();
|
||||
@ -245,7 +245,7 @@ void Seismic_monitor::on_pushButton_confirm_clicked() {
|
||||
item_obj["channel_type"] = seismic_monitor[i].channel_type;
|
||||
item_obj["transducer_name"] = seismic_monitor[i].transducer_name;
|
||||
item_obj["scale_factor"] = seismic_monitor[i].scale_factor;
|
||||
item_obj["sample_rate"] = seismic_monitor[i].sampling_rate;
|
||||
item_obj["sampling_rate"] = seismic_monitor[i].sampling_rate;
|
||||
QJsonArray normal_voltage_array;
|
||||
normal_voltage_array.append(seismic_monitor[i].normal_voltage_low);
|
||||
normal_voltage_array.append(seismic_monitor[i].normal_voltage_high);
|
||||
@ -255,7 +255,7 @@ void Seismic_monitor::on_pushButton_confirm_clicked() {
|
||||
monitor_obj["chan"] = chan_array;
|
||||
monitor_obj["slot"] = slot_no;
|
||||
monitor_obj["version"] = 1;
|
||||
monitor_obj["card_type"] = 1;
|
||||
monitor_obj["card_type"] = kCardVibSingle;
|
||||
QJsonDocument jsonDoc;
|
||||
jsonDoc.setObject(monitor_obj);
|
||||
QString file_name = QString("\\config\\%1\\seismic_monitor_slot.json").arg(slot_no);
|
||||
|
15
velocity.ui
15
velocity.ui
@ -905,7 +905,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>460</x>
|
||||
<y>80</y>
|
||||
<y>60</y>
|
||||
<width>181</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
@ -914,19 +914,6 @@
|
||||
<string> Timed OK channel Defeat</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="checkBox_not_ok">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>460</x>
|
||||
<y>60</y>
|
||||
<width>131</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string> 非正常锁定</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_85">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
|
6
vibrationdata.cpp
Normal file
6
vibrationdata.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "vibrationdata.h"
|
||||
|
||||
VibrationData::VibrationData()
|
||||
{
|
||||
|
||||
}
|
30
vibrationdata.h
Normal file
30
vibrationdata.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef VIBRATIONDATA_H
|
||||
#define VIBRATIONDATA_H
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "cardbase.h"
|
||||
|
||||
|
||||
class VibrationData : public CardBase {
|
||||
public:
|
||||
VibrationData();
|
||||
void FromJson(const Json::Value &cfg) {
|
||||
version_ = cfg["version"].asInt();
|
||||
slot_ = cfg["slot"].asInt();
|
||||
card_type_ = static_cast<CardType>(cfg["type"].asInt());
|
||||
}
|
||||
|
||||
Json::Value ToJson() {
|
||||
Json::Value ch;
|
||||
ch[NAME(version)] = version_;
|
||||
ch[NAME(slot)] = slot_;
|
||||
ch[NAME(type)] = card_type_;
|
||||
return ch;
|
||||
}
|
||||
// private:
|
||||
SeismicMonitor base_config_[CHANNEL_COUNT];
|
||||
AllFilter filter_[CHANNEL_COUNT];
|
||||
std::vector<std::shared_ptr<VariableBase>> variables_;
|
||||
};
|
||||
|
||||
#endif // VIBRATIONDATA_H
|
Loading…
x
Reference in New Issue
Block a user