Compare commits
10 Commits
old_versio
...
develop
Author | SHA1 | Date |
---|---|---|
|
a13d1e4a98 | |
|
525d6adb0c | |
|
2e7e92e4da | |
|
25f0c01a47 | |
|
8279590f38 | |
|
27f3def00a | |
|
bfee5f9d49 | |
|
d4ae45d1dc | |
|
d36da2f3ce | |
|
f474423549 |
|
@ -11,6 +11,7 @@ CONFIG += c++17
|
|||
|
||||
SOURCES += \
|
||||
appproto.cpp \
|
||||
appproto_english.cpp \
|
||||
batt.cpp \
|
||||
chartpaint.cpp \
|
||||
custom/delegate.cpp \
|
||||
|
@ -23,10 +24,13 @@ SOURCES += \
|
|||
mainwindow.cpp \
|
||||
modbusrtu.cpp \
|
||||
proto/battery.pb.cc \
|
||||
appserial.cpp
|
||||
appserial.cpp \
|
||||
proto/battery_english.pb.cc \
|
||||
upgradeicon.cpp
|
||||
|
||||
HEADERS += \
|
||||
appproto.h \
|
||||
appproto_english.h \
|
||||
batt.h \
|
||||
chartpaint.h \
|
||||
custom/delegate.h \
|
||||
|
@ -42,7 +46,9 @@ HEADERS += \
|
|||
mainwindow.h \
|
||||
modbusrtu.h \
|
||||
proto/battery.pb.h \
|
||||
appserial.h
|
||||
appserial.h \
|
||||
proto/battery_english.pb.h \
|
||||
upgradeicon.h
|
||||
|
||||
FORMS += \
|
||||
dialoglogin.ui \
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
Binary file not shown.
32
appproto.cpp
32
appproto.cpp
|
@ -15,38 +15,6 @@ AppProto::~AppProto()
|
|||
|
||||
void AppProto::init()
|
||||
{
|
||||
// Battery::BCUList bcus;
|
||||
// std::ifstream finBetteryData("battery.data", std::ios::binary);
|
||||
// if(!bcus.ParseFromIstream(&finBetteryData)) {
|
||||
// qDebug() << "Failed to parse BSU message.";
|
||||
// // config message
|
||||
// int bmuNum = 16;
|
||||
// int cellNum = 26;
|
||||
// for(int i = 0; i < bmuNum; i++) {
|
||||
// bcus.add_bmus();
|
||||
// bcus.mutable_bmus(i)->set_name("BUM" + QString("%1").arg(i+1).toStdString());
|
||||
// for(int j = 0; j < cellNum; j++) {
|
||||
// bcus.mutable_bmus(i)->add_cells();
|
||||
// bcus.mutable_bmus(i)->mutable_cells(j)->set_name("Cell" + QString("%1").arg(j+1).toStdString());
|
||||
// }
|
||||
// }
|
||||
// std::fstream foutBetteryData("battery.data",std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
// if(!bcus.SerializePartialToOstream(&foutBetteryData)) {
|
||||
// qDebug() << "filed";
|
||||
// }
|
||||
// foutBetteryData.close();
|
||||
// foutBetteryData.clear();
|
||||
// }
|
||||
// else {
|
||||
// qDebug() << "bum num:" << bcus.bmus_size();
|
||||
// for(int i = 0; i < bcus.bmus_size(); i++) {
|
||||
// qDebug() << "bmu name:" << bcus.bmus(i).name().c_str() << "cell num:" << bcus.bmus(i).cells_size();
|
||||
// for(int j = 0; j < bcus.bmus(i).cells_size(); j++) {
|
||||
// qDebug() << "cell name:" << bcus.bmus(i).cells(j).name().c_str();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
BatteryConfig::Item item;
|
||||
std::ifstream finBetteryData("battery.data", std::ios::binary);
|
||||
if(!item.ParseFromIstream(&finBetteryData)) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
|||
#ifndef APPPROTO_ENGLISH_H
|
||||
#define APPPROTO_ENGLISH_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Appproto_English : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Appproto_English(QObject *parent = nullptr);
|
||||
~Appproto_English();
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
int itemCount = 0;
|
||||
int itemCount_balance = 0;
|
||||
int itemCount_DIDO = 0;
|
||||
int itemCount_SOX = 0;
|
||||
int itemCount_other = 0;
|
||||
int itemCount_alert_value = 0;
|
||||
int itemCount_alert_delay = 0;
|
||||
int itemCount_alert_release_value = 0;
|
||||
int itemCount_alert_release_delay = 0;
|
||||
int itemCount_alert_dropcurr_rate = 0;
|
||||
int itemCount_alert_solve_measure = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // APPPROTO_ENGLISH_H
|
|
@ -13,6 +13,7 @@
|
|||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include <QLabel>
|
||||
#include <QTableView>
|
||||
Delegate::Delegate(QObject *parent): QStyledItemDelegate(parent)
|
||||
{
|
||||
|
@ -81,9 +82,16 @@ QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*o
|
|||
else if (delegateType == "QLineEdit")
|
||||
{
|
||||
QLineEdit *lineEidt = new QLineEdit(parent);
|
||||
// lineEidt->setReadOnly(true);
|
||||
editor = lineEidt;
|
||||
connect(lineEidt, SIGNAL(textChanged(QString)), this, SLOT(on_valueChanged(QString)));
|
||||
}
|
||||
else if (delegateType == "QLabel")
|
||||
{
|
||||
QLabel *label = new QLabel(parent);
|
||||
editor = label;
|
||||
connect(label, SIGNAL(textChanged(QString)), this, SLOT(on_valueChanged(QString)));
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
@ -126,6 +134,11 @@ void Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|||
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
||||
lineEidt->setText(value.toString());
|
||||
}
|
||||
else if (delegateType == "QLabel")
|
||||
{
|
||||
QLabel *label = static_cast<QLabel *>(editor);
|
||||
label->setText(value.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
|
@ -171,6 +184,11 @@ void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|||
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
||||
value = lineEidt->text();
|
||||
}
|
||||
else if (delegateType == "QLabel")
|
||||
{
|
||||
QLabel *label = static_cast<QLabel *>(editor);
|
||||
value = label->text();
|
||||
}
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
|
||||
}
|
||||
|
@ -208,6 +226,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
|
|||
drawLineEdit(painter, option, index);
|
||||
}
|
||||
|
||||
|
||||
}//if
|
||||
else
|
||||
{
|
||||
|
|
136
dialoglogin.cpp
136
dialoglogin.cpp
|
@ -10,12 +10,16 @@
|
|||
#include "appserial.h"
|
||||
#include "modbusrtu.h"
|
||||
#include <windef.h>
|
||||
#include <QTranslator>
|
||||
#include <QThread>
|
||||
#include <QMetaType>
|
||||
|
||||
DialogLogin::DialogLogin(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::DialogLogin)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
qRegisterMetaType<QList<int>>("QList<int>");
|
||||
init();
|
||||
serialInit();
|
||||
mainwindowInit();
|
||||
|
@ -52,6 +56,15 @@ void DialogLogin::init()
|
|||
ini = new QSettings("config.ini", QSettings::IniFormat);
|
||||
connect(ui->btnConnect, &QPushButton::clicked, this, &DialogLogin::slot_btnConnect_clicked);
|
||||
|
||||
ui->groupBox->setStyleSheet("QGroupBox { border: none; }");
|
||||
|
||||
ui->label_bluesunLogo->setStyleSheet("QLabel { background-image: url(:/Image/bluesun.png); "
|
||||
"background-repeat: no-repeat; background-size: cover; background-position: center center;}");
|
||||
// //将背景设置为白色
|
||||
// ui->groupBox->setStyleSheet("background-color: #FFFFFF;");
|
||||
|
||||
m_MainWindow->setStyleSheet("background-color: #FFFFFF;");
|
||||
|
||||
// //传递BCU个数的信号与槽
|
||||
// BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
||||
// qDebug() << "the number of the BCU: " << BCUNumbers;
|
||||
|
@ -89,6 +102,42 @@ void DialogLogin::init()
|
|||
//读寄存器的信号与槽的连接
|
||||
connect(m_MainWindow, &MainWindow::read_regs_signals, m_ModbusRTU, &ModbusRTU::read_regs_slot);
|
||||
connect(m_ModbusRTU, &ModbusRTU::sig_showReadHoldingRegs, m_MainWindow, &MainWindow::slot_pageParaSetShow);
|
||||
|
||||
//主窗口关闭时,关闭线程
|
||||
connect(m_MainWindow, &MainWindow::quitThread, this, [=]{
|
||||
qDebug() << "关闭线程";
|
||||
m_ModbusRTU->quit();
|
||||
});
|
||||
|
||||
connect(m_MainWindow, &MainWindow::closeThread, m_ModbusRTU, &ModbusRTU::slot_pauseThread);
|
||||
|
||||
connect(m_MainWindow, &MainWindow::openThread, m_ModbusRTU, &ModbusRTU::slot_resumeThread);
|
||||
|
||||
// ui->btnConnect->setStyleSheet("QPushButton { background-color: lightgray; color: black; border: none; }");
|
||||
|
||||
//主窗口接受语言选择number的信号与槽的连接
|
||||
connect(this, &DialogLogin::sendLanNumberSignals, m_MainWindow, &MainWindow::getLanNumberSlot);
|
||||
|
||||
//故障解析的信号与槽
|
||||
connect(m_ModbusRTU, &ModbusRTU::sig_showFault, m_MainWindow, &MainWindow::slot_pageHomeFault);
|
||||
|
||||
//电池界面中,点击bmu发送对应的数据
|
||||
// connect(m_MainWindow, &MainWindow::read_regs_input_signals_vol, m_ModbusRTU, &ModbusRTU::read_regs_input_slot_vol);
|
||||
// connect(m_MainWindow, &MainWindow::read_regs_input_signals_temp, m_ModbusRTU, &ModbusRTU::read_regs_input_slot_temp);
|
||||
|
||||
//上面的方法太low了,直接将row的索引传到modbus的线程中去
|
||||
connect(m_MainWindow, &MainWindow::row_of_bmus_index, m_ModbusRTU, &ModbusRTU::change_BMUIndex_slot);
|
||||
|
||||
|
||||
// ui->btnConnect->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
|
||||
// "QPushButton:hover { background-color: #77B5D6; color: white; }");
|
||||
|
||||
// QMetaObject::invokeMethod(m_ModbusRTU,"read_regs_slot",Qt::QueuedConnection);
|
||||
// connect(m_ModbusRTU, &ModbusRTU::sig_readMoveToThread, m_ModbusRTU, &ModbusRTU::read_regs_slot, Qt::QueuedConnection);
|
||||
// thread = new QThread;
|
||||
|
||||
// m_ModbusRTU->moveToThread(thread);
|
||||
// thread->start();
|
||||
}
|
||||
|
||||
void DialogLogin::serialInit()
|
||||
|
@ -103,6 +152,8 @@ void DialogLogin::serialInit()
|
|||
ui->comboBoxDataBits->setCurrentIndex(3);
|
||||
ui->comboBoxStopBits->setCurrentIndex(0);
|
||||
ui->comboBoxParity->setCurrentIndex(0);
|
||||
ui->comboBoxLanguage->setCurrentIndex(ini->value("System/Language").toUInt());
|
||||
// qDebug() << "lan currentIndex false:" << ini->value("System/Language").toUInt();
|
||||
}
|
||||
else {
|
||||
ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
||||
|
@ -110,6 +161,9 @@ void DialogLogin::serialInit()
|
|||
ui->comboBoxDataBits->setCurrentIndex(ini->value("Serial/DataBits").toUInt());
|
||||
ui->comboBoxStopBits->setCurrentIndex(ini->value("Serial/StopBits").toUInt());
|
||||
ui->comboBoxParity->setCurrentIndex(ini->value("Serial/Parity").toUInt());
|
||||
ui->comboBoxLanguage->setCurrentIndex(ini->value("System/Language").toUInt());
|
||||
// ui->comboBoxLanguage->setCurrentIndex(ini->value());
|
||||
// qDebug() << "lan currentIndex " << ini->value("System/Language").toUInt();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,29 +177,29 @@ void DialogLogin::mainwindowInit()
|
|||
connect(m_MainWindow, &MainWindow::showLogin, this, [=]{
|
||||
this->show();
|
||||
});
|
||||
connect(this, &DialogLogin::finished, m_MainWindow, [=]{
|
||||
m_MainWindow->ui->btnSetup->setStyleSheet("#btnSetup{"
|
||||
"background-image: url(:/Image/advance-set-line.png);"
|
||||
"background-repeat: no-repeat;"
|
||||
"background-position: center;"
|
||||
"background-color: rgba(255, 255, 255, 0);"
|
||||
"}"
|
||||
"#btnSetup::hover{"
|
||||
"background-image: url(:/Image/advance-set-line1.png);"
|
||||
"background-repeat: no-repeat;"
|
||||
"background-position: center;"
|
||||
"background-color: rgba(255, 255, 255, 0);"
|
||||
"}");
|
||||
});
|
||||
connect(m_MainWindow->ui->btnSetup, &QPushButton::pressed, this, [=]{
|
||||
qDebug() << __FUNCTION__ << "disconnected";
|
||||
m_ModbusRTU->isConnect = false;
|
||||
m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected1.png").pixmap(QSize(24, 24))));
|
||||
m_Serial->m_SerialPort->close();
|
||||
m_ModbusRTU->modbusRTUDisconnect();
|
||||
ui->comboBoxSerialPort->clear();
|
||||
ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
||||
});
|
||||
// connect(this, &DialogLogin::finished, m_MainWindow, [=]{
|
||||
// m_MainWindow->ui->btnSetup->setStyleSheet("#btnSetup{"
|
||||
// "background-image: url(:/Image/advance-set-line.png);"
|
||||
// "background-repeat: no-repeat;"
|
||||
// "background-position: center;"
|
||||
// "background-color: rgba(255, 255, 255, 0);"
|
||||
// "}"
|
||||
// "#btnSetup::hover{"
|
||||
// "background-image: url(:/Image/advance-set-line1.png);"
|
||||
// "background-repeat: no-repeat;"
|
||||
// "background-position: center;"
|
||||
// "background-color: rgba(255, 255, 255, 0);"
|
||||
// "}");
|
||||
// });
|
||||
// connect(m_MainWindow->ui->btnSetup, &QPushButton::pressed, this, [=]{
|
||||
// qDebug() << __FUNCTION__ << "disconnected";
|
||||
// m_ModbusRTU->isConnect = false;
|
||||
// m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected1.png").pixmap(QSize(24, 24))));
|
||||
// m_Serial->m_SerialPort->close();
|
||||
// m_ModbusRTU->modbusRTUDisconnect();
|
||||
// ui->comboBoxSerialPort->clear();
|
||||
// ui->comboBoxSerialPort->addItems(m_Serial->getAvailablePort());
|
||||
// });
|
||||
}
|
||||
|
||||
void DialogLogin::slot_comChangeStatus(QString name, bool flag)
|
||||
|
@ -158,14 +212,40 @@ void DialogLogin::slot_comChangeStatus(QString name, bool flag)
|
|||
|
||||
void DialogLogin::slot_btnConnect_clicked()
|
||||
{
|
||||
BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
||||
emit sendBCUNumberSignals(BCUNumbers);
|
||||
connect(this, &DialogLogin::sendBCUNumberSignals, m_MainWindow, &MainWindow::slot_getBcuNumberFromDialoglogin);
|
||||
ini->setValue("Serial/BaudRate", ui->comboBoxBaudRate->currentIndex());
|
||||
ini->setValue("Serial/DataBits", ui->comboBoxDataBits->currentIndex());
|
||||
ini->setValue("Serial/StopBits", ui->comboBoxStopBits->currentIndex());
|
||||
ini->setValue("Serial/Parity", ui->comboBoxParity->currentIndex());
|
||||
ini->sync();
|
||||
// BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
|
||||
|
||||
QString language = ui->comboBoxLanguage->currentText();
|
||||
if (language == "English")
|
||||
{
|
||||
qDebug() << "ini lanuage index" << ini->value("System/Language");
|
||||
ini->setValue("System/Language", 1);
|
||||
ini->sync();
|
||||
QTranslator trans;
|
||||
emit sendLanNumberSignals(0);
|
||||
trans.load(":/Language/BatteryMonitor_ENG.qm");
|
||||
QApplication::installTranslator(&trans);
|
||||
m_MainWindow->ui->retranslateUi(m_MainWindow);
|
||||
}
|
||||
else if (language == "Chinese")
|
||||
{
|
||||
qDebug() << "ini lanuage index" << ini->value("System/Language");
|
||||
ini->setValue("System/Language", 0);
|
||||
ini->sync();
|
||||
emit sendLanNumberSignals(1);
|
||||
QTranslator trans;
|
||||
trans.load(":/Language/BatteryMonitor_CHN.qm");
|
||||
QApplication::installTranslator(&trans);
|
||||
m_MainWindow->ui->retranslateUi(m_MainWindow);
|
||||
}
|
||||
|
||||
emit sendBCUNumberSignals(BCUNumbers);
|
||||
connect(this, &DialogLogin::sendBCUNumberSignals, m_MainWindow, &MainWindow::slot_getBcuNumberFromDialoglogin);
|
||||
|
||||
|
||||
if(m_Serial->getAvailablePort().size() == 0) {
|
||||
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {
|
||||
|
@ -246,7 +326,9 @@ void DialogLogin::slot_btnConnect_clicked()
|
|||
m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected2.png").pixmap(QSize(24, 24))));
|
||||
m_MainWindow->show();
|
||||
// m_MainWindow->showMaximized();
|
||||
|
||||
// m_ModbusRTU->start();
|
||||
m_ModbusRTU->start();
|
||||
m_MainWindow->showMaximized();
|
||||
}
|
||||
else {
|
||||
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {
|
||||
|
|
|
@ -31,10 +31,12 @@ private:
|
|||
AppSerial *m_Serial;
|
||||
ModbusRTU *m_ModbusRTU;
|
||||
QSettings *ini;
|
||||
// QThread *thread;
|
||||
int BCUNumbers;
|
||||
|
||||
signals:
|
||||
void sendBCUNumberSignals(int number);
|
||||
void sendLanNumberSignals(int number);
|
||||
|
||||
private slots:
|
||||
void slot_comChangeStatus(QString name, bool flag);
|
||||
|
|
397
dialoglogin.ui
397
dialoglogin.ui
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>260</width>
|
||||
<height>320</height>
|
||||
<width>362</width>
|
||||
<height>444</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -20,43 +20,121 @@
|
|||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<item row="2" column="1">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>黑体</family>
|
||||
<pointsize>11</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Communication</string>
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="4,7,1,3,3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_bluesunLogo">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="9" column="3">
|
||||
<widget class="QComboBox" name="comboBoxParity">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelBCUQuantity_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Language</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBoxLanguage">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>None</string>
|
||||
<string>Chinese</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Odd</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Even</string>
|
||||
<string>English</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QComboBox" name="comboBoxSerialPort"/>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelSerialPort">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Serial Port</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBoxSerialPort">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelBaudRate">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Baud Rate</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="3">
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboBoxBaudRate">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1200</string>
|
||||
|
@ -99,94 +177,30 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="labelSerialPort">
|
||||
<property name="text">
|
||||
<string>Serial Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="3">
|
||||
<widget class="QComboBox" name="comboBoxDataBits">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>6</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>7</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>8</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="2">
|
||||
<widget class="QLabel" name="labelStopBits">
|
||||
<property name="text">
|
||||
<string>Stop Bits</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="2">
|
||||
<widget class="QLabel" name="labelParity">
|
||||
<property name="text">
|
||||
<string>Parity</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="3">
|
||||
<widget class="QComboBox" name="comboBoxStopBits">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelDataBits">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Data Bits</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QComboBox" name="comboBoxBCUQuantity">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="comboBoxDataBits">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
|
@ -207,59 +221,88 @@
|
|||
<string>8</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="labelStopBits">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop Bits</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="comboBoxStopBits">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>9</string>
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>10</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>11</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>12</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>13</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>14</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>15</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>16</string>
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="labelBCUQuantity">
|
||||
<property name="text">
|
||||
<string>BCU Quantity</string>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="labelParity">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Parity</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="comboBoxParity">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>华文中宋</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>None</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Odd</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Even</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
@ -272,13 +315,93 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Microsoft YaHei UI</family>
|
||||
<pointsize>12</pointsize>
|
||||
<italic>false</italic>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 12pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Copyright">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>幼圆</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><html><head/><body><p align="center">Copyright © 2016 Bluesun Solar Co.,Ltd </p><p align="center">All Rights Reserved.</p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -35,5 +35,7 @@
|
|||
<file>Image/record-out-black.png</file>
|
||||
<file>Image/record-out-gray.png</file>
|
||||
<file>Image/record-out-green.png</file>
|
||||
<file>Image/bluesun.png</file>
|
||||
<file>Image/bunuo.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
15
main.cpp
15
main.cpp
|
@ -1,12 +1,27 @@
|
|||
#include "dialoglogin.h"
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QPersistentModelIndex>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// 设置高DPI
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
QApplication a(argc, argv);
|
||||
a.setStyleSheet("QToolTip { font-size: 18px; font-family: 'SimHei'; }");
|
||||
DialogLogin loginWidget;
|
||||
loginWidget.setStyleSheet("background-color: #FFFFFF;");
|
||||
qRegisterMetaType<QList<QPersistentModelIndex>>("QList<QPersistentModelIndex>");
|
||||
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("QAbstractItemModel::LayoutChangeHint");
|
||||
qRegisterMetaType<QVector<int>>("QVector<int>");
|
||||
loginWidget.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
|
1817
mainwindow.cpp
1817
mainwindow.cpp
File diff suppressed because it is too large
Load Diff
70
mainwindow.h
70
mainwindow.h
|
@ -13,6 +13,7 @@ class QSettings;
|
|||
class QLabel;
|
||||
class QFile;
|
||||
class AppProto;
|
||||
class Appproto_English;
|
||||
class ChartPaint;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -34,14 +35,27 @@ public:
|
|||
|
||||
public:
|
||||
QStandardItemModel *model;
|
||||
|
||||
QStandardItemModel *modelBCU; //设置BCU目录
|
||||
QStandardItem *rootItem;
|
||||
|
||||
QStandardItemModel *model_history_alarm;
|
||||
QStandardItemModel *model_get_version;
|
||||
|
||||
ComLogin *m_ComLogin;
|
||||
AppProto *m_AppProto;
|
||||
Appproto_English *m_AppProto_English;
|
||||
QSettings *ini;
|
||||
QFile *logFile;
|
||||
QLabel *statusBarConnectedIcon;
|
||||
QLabel *statusBarConnectedType;
|
||||
QLabel *statusBarCompany;
|
||||
ChartPaint *chartPat;
|
||||
QLabel *statusBarBcu;
|
||||
QLabel *statusBarVersion;
|
||||
// ChartPaint *chartPat;
|
||||
QString currentBCU = "BCU01";
|
||||
|
||||
|
||||
int BCUNumbers;
|
||||
// QGridLayout *gridLayout;
|
||||
// QHBoxLayout *hBoxLayout;
|
||||
|
@ -58,9 +72,18 @@ public:
|
|||
QList<int> base_info83_106;
|
||||
int battery_count;
|
||||
ModbusRTU *m_modbusrtu_main;
|
||||
int lan;
|
||||
|
||||
int tabWidget_paraset_index = 0;
|
||||
|
||||
QList<QLabel*> trouble_list;
|
||||
QList<int> trouble_list_flag;
|
||||
|
||||
bool trouble_history = 1;
|
||||
|
||||
int count_history_alarm = 0; //如果不放到全局变量中去,每次刷新的都是同一个报警的内容,无法达到历史告警的作用
|
||||
|
||||
|
||||
|
||||
private:
|
||||
enum DataType{
|
||||
|
@ -94,6 +117,8 @@ private:
|
|||
void init();
|
||||
void setMenuStyle();
|
||||
void pageBatteryInit();
|
||||
void pageHomeHistoryAlarm();
|
||||
void pageFlashGetVersion();
|
||||
void pageParaSetInit();
|
||||
void pageParaSetInit_alert_value();
|
||||
void pageParaSetInit_alert_delay();
|
||||
|
@ -111,33 +136,62 @@ private:
|
|||
int findMaxIndex(const QList<int> sgl_info);
|
||||
int findMinIndex(const QList<int> sgl_info);
|
||||
|
||||
void trubleListInit();
|
||||
|
||||
public slots:
|
||||
// void setNum(QString value);
|
||||
void getLanNumberSlot(int number);
|
||||
|
||||
signals:
|
||||
void showLogin();
|
||||
void closeLogin();
|
||||
void write_regs_signals(int addr, const uint16_t data);
|
||||
void read_regs_signals(int addr, int nb, uint16_t *data, int row);
|
||||
// void read_regs_input_signals_vol(int addr, int nb, uint16_t *data);
|
||||
// void read_regs_input_signals_temp(int addr, int nb, uint16_t *data);
|
||||
void row_of_bmus_index(int index);
|
||||
void closeThread();
|
||||
void openThread();
|
||||
void quitThread();
|
||||
|
||||
public:
|
||||
void slot_getBcuNumberFromDialoglogin(int number);
|
||||
void slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType);
|
||||
void slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType);
|
||||
void slot_pageHomeSglTempt(QByteArray byteArray, int dataType);
|
||||
void slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType);
|
||||
void slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType);
|
||||
void slot_pageHomeBaseInfo83_106(QByteArray byteArray, int dataType);
|
||||
void slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void slot_pageHomeSglTempt(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void slot_pageHomeBaseInfo83_106(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void slot_pageHomeBaseInfo47_49_51_53_55(QList<int> byteArray, int dataType);
|
||||
void slot_pageParaSetShow(QByteArray byteArray, int dataType, int row, int nb);
|
||||
void slot_pageParaSetShow(int row, int nb, uint16_t *data);
|
||||
void slot_testData(uint16_t *data);
|
||||
void slot_pageHomeFault(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *e) override;
|
||||
|
||||
private slots:
|
||||
void on_pageParaSetCheck_stateChanged(int arg1);
|
||||
void on_pageParaSetRead_clicked();
|
||||
void on_pageParaSetWrite_clicked();
|
||||
void on_tabChanged(int index);
|
||||
void on_comBoxBCUSelect(int index);
|
||||
// void on_horizontalSlider_valueChanged(int value);
|
||||
|
||||
void on_btn_close_pos_clicked();
|
||||
|
||||
void on_btn_open_pos_clicked();
|
||||
|
||||
void on_btn_close_neg_clicked();
|
||||
|
||||
void on_btn_open_neg_clicked();
|
||||
|
||||
void on_btn_close_prechg_clicked();
|
||||
|
||||
void on_btn_open_prechg_clicked();
|
||||
|
||||
void on_btnImport_clicked();
|
||||
|
||||
public:
|
||||
struct Battery_data {
|
||||
uint16_t pack_total_voltage; // 电池组总压
|
||||
|
|
12928
mainwindow.ui
12928
mainwindow.ui
File diff suppressed because it is too large
Load Diff
213
modbusrtu.cpp
213
modbusrtu.cpp
|
@ -3,10 +3,13 @@
|
|||
#include <QEvent>
|
||||
#include <QDebug>
|
||||
#include "modbus-private.h"
|
||||
|
||||
ModbusRTU::ModbusRTU(QObject *parent) : QObject(parent)
|
||||
#include <QMessageBox>
|
||||
#include <QEventLoop>
|
||||
ModbusRTU::ModbusRTU(QObject *parent) : QThread(parent)
|
||||
{
|
||||
init();
|
||||
// start();
|
||||
|
||||
}
|
||||
|
||||
ModbusRTU::~ModbusRTU()
|
||||
|
@ -17,31 +20,19 @@ ModbusRTU::~ModbusRTU()
|
|||
|
||||
void ModbusRTU::init()
|
||||
{
|
||||
timer50msId = startTimer(50);
|
||||
timer100msId = startTimer(100);
|
||||
timer200msId = startTimer(200);
|
||||
timer1000msId = startTimer(1000);
|
||||
|
||||
}
|
||||
|
||||
void ModbusRTU::timerEvent(QTimerEvent *event)
|
||||
void ModbusRTU::run()
|
||||
{
|
||||
if(isConnect != true) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if(event->timerId() == timer50msId) {
|
||||
|
||||
}
|
||||
if(event->timerId() == timer100msId) {
|
||||
|
||||
}
|
||||
if(event->timerId() == timer200msId) {
|
||||
|
||||
}
|
||||
if(event->timerId() == timer1000msId) {
|
||||
uint16_t sgl_vol[112]; // Buffer to store the registers
|
||||
uint16_t sgl_tempt[112];
|
||||
qDebug() << "进入线程:" << QThread::currentThread();
|
||||
while(true)
|
||||
{
|
||||
if (closeThread)
|
||||
{
|
||||
QElapsedTimer time;
|
||||
time.start();
|
||||
QThread::msleep(300);
|
||||
uint16_t base1_45[45];
|
||||
uint16_t base57_78[22];
|
||||
uint16_t base83_106[24];
|
||||
|
@ -50,22 +41,24 @@ void ModbusRTU::timerEvent(QTimerEvent *event)
|
|||
uint16_t base51[1];
|
||||
uint16_t base53[1];
|
||||
uint16_t base55[1];
|
||||
uint16_t base47_49_51_53_55[5];
|
||||
uint16_t test2[2] = {10, 20};
|
||||
QList<int> base_list_47_49_51_53_55;
|
||||
int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
|
||||
if(MODBUS_ERR == ret_base1_45) {
|
||||
// qDebug() << "modbus no message";
|
||||
return;
|
||||
uint16_t sgl_vol[16]; // Buffer to store the registers
|
||||
uint16_t sgl_tempt[16];
|
||||
uint16_t fault[8];
|
||||
|
||||
label: int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
|
||||
if(MODBUS_ERR == ret_base1_45)
|
||||
{
|
||||
goto label;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData_base_info1_45(sendArray, TypeSendData);
|
||||
emit sig_showModbusData_base_info1_45(sendArray, TypeSendData, base1_45);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData_base_info1_45(recvArray, TypeRecvData);
|
||||
emit sig_showModbusData_base_info1_45(recvArray, TypeRecvData, base1_45);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
// qDebug() << "in modbus:" << base1_45;
|
||||
}
|
||||
|
||||
int ret_base47 = modbus_read_input_registers(m_ModbusRTUDevice, 47, 1, base47);
|
||||
|
@ -82,7 +75,6 @@ void ModbusRTU::timerEvent(QTimerEvent *event)
|
|||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData_base_info47_49_51_53_55(sendArray, TypeSendData);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
// QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
QByteArray recvArray;
|
||||
recvArray.append(reinterpret_cast<char*>(&base47), sizeof(base47));
|
||||
recvArray.append(reinterpret_cast<char*>(&base49), sizeof(base49));
|
||||
|
@ -94,97 +86,158 @@ void ModbusRTU::timerEvent(QTimerEvent *event)
|
|||
uint16_t value;
|
||||
memcpy(&value, recvArray.data() + i, 2);
|
||||
base_list_47_49_51_53_55.append(value);
|
||||
// base47_49_51_53_55[i] = value;
|
||||
// qDebug() << "Value: " << value;
|
||||
}
|
||||
|
||||
emit sig_showModbusData_base_info_list_47_49_51_53_55(base_list_47_49_51_53_55, TypeRecvData);
|
||||
// emit sig_showModbusData_base_info47_49_51_53_55(sendArray, TypeSendData);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
|
||||
int ret_base57_78 = modbus_read_input_registers(m_ModbusRTUDevice, 57, 22, base57_78);
|
||||
if(MODBUS_ERR == ret_base57_78) {
|
||||
// qDebug() << "modbus no message";
|
||||
return;
|
||||
if(MODBUS_ERR == ret_base57_78)
|
||||
{
|
||||
goto label;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData_base_info57_78(sendArray, TypeSendData);
|
||||
emit sig_showModbusData_base_info57_78(sendArray, TypeSendData, base57_78);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData_base_info57_78(recvArray, TypeRecvData);
|
||||
emit sig_showModbusData_base_info57_78(recvArray, TypeRecvData, base57_78);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
|
||||
int ret_fault = modbus_read_input_registers(m_ModbusRTUDevice, 66, 8, fault);
|
||||
if(MODBUS_ERR == ret_fault)
|
||||
{
|
||||
goto label;
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showFault(sendArray, TypeSendData, fault);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showFault(recvArray, TypeRecvData,fault);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
|
||||
int ret_base83_106 = modbus_read_input_registers(m_ModbusRTUDevice, 83, 24, base83_106);
|
||||
if(MODBUS_ERR == ret_base83_106) {
|
||||
// qDebug() << "modbus no message";
|
||||
return;
|
||||
if(MODBUS_ERR == ret_base83_106)
|
||||
{
|
||||
goto label;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData_base_info83_106(sendArray, TypeSendData);
|
||||
emit sig_showModbusData_base_info83_106(sendArray, TypeSendData, base83_106);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData_base_info83_106(recvArray, TypeRecvData);
|
||||
emit sig_showModbusData_base_info83_106(recvArray, TypeRecvData, base83_106);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
int volAddress = (1001 + BMUIndex * 16);
|
||||
int tempAddress = (1601 + BMUIndex * 16);
|
||||
|
||||
int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, volAddress, 16, sgl_vol);
|
||||
if(MODBUS_ERR == ret_vol)
|
||||
{
|
||||
goto label;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData(sendArray, TypeSendData, sgl_vol);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData(recvArray, TypeRecvData, sgl_vol);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
int ret_tempt = modbus_read_input_registers(m_ModbusRTUDevice, tempAddress, 16, sgl_tempt);
|
||||
if(MODBUS_ERR == ret_tempt)
|
||||
{
|
||||
goto label;
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData_sgl_tempt(sendArray, TypeSendData, sgl_tempt);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData_sgl_tempt(recvArray, TypeRecvData, sgl_tempt);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
|
||||
int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, 1001, 112, sgl_vol);
|
||||
if(MODBUS_ERR == ret_vol) {
|
||||
// qDebug() << "modbus no message";
|
||||
return;
|
||||
int milsec = time.elapsed();
|
||||
qDebug() <<"the time: " << milsec;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData(sendArray, TypeSendData);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData(recvArray, TypeRecvData);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
|
||||
int ret_tempt = modbus_read_input_registers(m_ModbusRTUDevice, 1601, 112, sgl_tempt);
|
||||
if(MODBUS_ERR == ret_tempt) {
|
||||
// qDebug() << "modbus no message";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
emit sig_showModbusData_sgl_tempt(sendArray, TypeSendData);
|
||||
free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showModbusData_sgl_tempt(recvArray, TypeRecvData);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusRTU::write_regs_slot(int addr,const uint16_t data)
|
||||
{
|
||||
// qDebug() << "write:进入线程:" << QThread::currentThread();
|
||||
int rc = write_single_register(addr, data);
|
||||
this->blockSignals(true);
|
||||
if(MODBUS_ERR == rc) {
|
||||
qDebug() << "######modbus no message";
|
||||
qDebug() << "write######modbus no message" << modbus_strerror(errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row)
|
||||
{
|
||||
// qDebug() << "read:进入线程:" << QThread::currentThread();
|
||||
// uint16_t temp[10];
|
||||
// uint16_t temp1[10] = {1, 2, 3, 4, 5};
|
||||
// memset(temp1, 0, sizeof(temp));
|
||||
qDebug() << "current add and nb" << addr << " " << nb;
|
||||
int rc = read_holding_register(addr, nb, data);
|
||||
if(MODBUS_ERR == rc) {
|
||||
// qDebug() << "modbus no message";
|
||||
qDebug() << "read modbus no message" << modbus_strerror(errno);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// qDebug() << "read rc" << rc;
|
||||
// QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||
// emit sig_showReadHoldingRegs(row, nb, temp);
|
||||
// free(m_ModbusRTUDevice->sendMsg);
|
||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||
emit sig_showReadHoldingRegs(recvArray, TypeRecvData, row, nb);
|
||||
emit sig_showReadHoldingRegs(row, nb, data);
|
||||
free(m_ModbusRTUDevice->recvMsg);
|
||||
// emit sig_testData(temp);
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusRTU::slot_pauseThread()
|
||||
{
|
||||
qDebug() << "暂停线程";
|
||||
closeThread = false;
|
||||
// emit paused();
|
||||
}
|
||||
|
||||
void ModbusRTU::slot_resumeThread()
|
||||
{
|
||||
qDebug() << "恢复线程";
|
||||
|
||||
// eventLoop.exit();
|
||||
// eventLoop.quit();
|
||||
|
||||
// qDebug() << "Event loop state before quit: " << eventLoop.isRunning();
|
||||
closeThread = true;
|
||||
// emit resumed();
|
||||
// qDebug() << "closeThread:" << closeThread;
|
||||
}
|
||||
|
||||
void ModbusRTU::change_BMUIndex_slot(int index)
|
||||
{
|
||||
BMUIndex = index;
|
||||
}
|
||||
|
||||
|
||||
bool ModbusRTU::modbusRTUConnect(const char *comPort, int baudRate, char parity, int dataBit, int stopBit)
|
||||
{
|
||||
qDebug() << "comPort:" << comPort << "baudRate:" << baudRate << "parity:" << parity << "dataBit" << dataBit << "stopBit:" << stopBit;
|
||||
|
|
39
modbusrtu.h
39
modbusrtu.h
|
@ -3,18 +3,24 @@
|
|||
|
||||
#include <QObject>
|
||||
#include "modbus.h"
|
||||
#include <QThread>
|
||||
#include <QEventLoop>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class ModbusRTU : public QObject
|
||||
class ModbusRTU : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ModbusRTU(QObject *parent = nullptr);
|
||||
~ModbusRTU();
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
public slots:
|
||||
void write_regs_slot(int addr, const uint16_t data);
|
||||
void read_regs_slot(int addr, int nb, uint16_t *data, int row);
|
||||
// void read_regs_input_slot_vol(int addr, int nb, uint16_t *data);
|
||||
// void read_regs_input_slot_temp(int addr, int nb, uint16_t *data);
|
||||
void change_BMUIndex_slot(int index);
|
||||
|
||||
public:
|
||||
modbus_t *m_ModbusRTUDevice;
|
||||
|
@ -24,12 +30,14 @@ public:
|
|||
char parity;
|
||||
int dataBit;
|
||||
int stopBit;
|
||||
int BMUIndex = 0;
|
||||
bool closeThread = true;
|
||||
|
||||
public:
|
||||
void run() override;
|
||||
QEventLoop eventLoop;
|
||||
|
||||
private:
|
||||
int timer50msId;
|
||||
int timer100msId;
|
||||
int timer200msId;
|
||||
int timer1000msId;
|
||||
|
||||
static constexpr int MODBUS_ERR = -1;
|
||||
|
||||
|
@ -62,17 +70,22 @@ public:
|
|||
|
||||
signals:
|
||||
void sig_ModbusRTUConnected();
|
||||
void sig_showModbusData(QByteArray byteArray, int dataType);
|
||||
void sig_showModbusData_sgl_tempt(QByteArray byteArray, int dataType);
|
||||
void sig_showModbusData_base_info1_45(QByteArray byteArray,int dataType);
|
||||
void sig_showModbusData_base_info57_78(QByteArray byteArray,int dataType);
|
||||
void sig_showModbusData_base_info83_106(QByteArray byteArray,int dataType);
|
||||
void sig_showModbusData(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void sig_showModbusData_sgl_tempt(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void sig_showModbusData_base_info1_45(QByteArray byteArray,int dataType, uint16_t *data);
|
||||
void sig_showModbusData_base_info57_78(QByteArray byteArray,int dataType, uint16_t *data);
|
||||
void sig_showModbusData_base_info83_106(QByteArray byteArray,int dataType, uint16_t *data);
|
||||
void sig_showModbusData_base_info47_49_51_53_55(QByteArray byteArray,int dataType);
|
||||
void sig_showModbusData_base_info_list_47_49_51_53_55(QList<int> byteArray,int dataType);
|
||||
void sig_showReadHoldingRegs(QByteArray byteArray,int dataType, int row, int nb);
|
||||
void sig_showReadHoldingRegs(int row, int nb, uint16_t *data);
|
||||
void sig_showFault(QByteArray byteArray, int dataType, uint16_t *data);
|
||||
void paused();
|
||||
void resumed();
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
void slot_pauseThread();
|
||||
void slot_resumeThread();
|
||||
};
|
||||
|
||||
#endif // MODBUSRTU_H
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
@echo off
|
||||
|
||||
set local
|
||||
:: 设置库路径
|
||||
SET LIB_PATH=..\library\libprotobuf\lib
|
||||
:: 设置环境变量
|
||||
SET PATH=%LIB_PATH%;%PATH%
|
||||
:: 设置protoc路径
|
||||
SET PROTOC_PATH=..\library\libprotobuf\bin\protoc.exe
|
||||
:: 编译proto文件
|
||||
%PROTOC_PATH% --cpp_out=.\ *.proto
|
||||
|
||||
pause
|
||||
endlocal
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,105 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package BatteryConfig_English;
|
||||
|
||||
message Item{
|
||||
repeated Attributes ItemAttr = 1;
|
||||
repeated Attributes_balance ItemAttr_balance = 2;
|
||||
repeated Attributes_DIDO ItemAttr_DIDO = 3;
|
||||
repeated Attributes_SOX ItemAttr_SOX = 4;
|
||||
repeated Attributes_other ItemAttr_other = 5;
|
||||
repeated Attributes_alert_value ItemAttr_alert_value = 6;
|
||||
repeated Attributes_alert_delay ItemAttr_alert_delay = 7;
|
||||
repeated Attributes_alert_release_value ItemAttr_alert_release_value = 8;
|
||||
repeated Attributes_alert_release_delay ItemAttr_alert_release_delay = 9;
|
||||
repeated Attributes_alert_dropcurr_rate ItemAttr_alert_dropcurr_rate = 10;
|
||||
repeated Attributes_alert_solve_measure ItemAttr_alert_solve_measure = 11;
|
||||
}
|
||||
|
||||
message Attributes{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_balance{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_DIDO{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_SOX{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_other{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_alert_value{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_alert_delay{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_alert_release_value{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_alert_release_delay{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_alert_dropcurr_rate{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
||||
|
||||
message Attributes_alert_solve_measure{
|
||||
string name = 1;
|
||||
int32 addr = 2;
|
||||
int32 value = 3;
|
||||
float scale = 4;
|
||||
string introduce = 5;
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
#include "upgradeicon.h"
|
||||
|
||||
upgradeIcon::upgradeIcon(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setContentsMargins(0,0,0,0);
|
||||
borderWidth = 4;
|
||||
headWidth = 20;
|
||||
value = 50;
|
||||
minValue = 0;
|
||||
maxValue = 100;
|
||||
alarmValue = 20;
|
||||
borderRadio = 10;
|
||||
drawInRadio = 8;
|
||||
borderColor = QColor(96, 96, 96);
|
||||
}
|
||||
|
||||
void upgradeIcon::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
drawBorder(&painter);
|
||||
// drawRightHead(&painter);
|
||||
drawBackground(&painter);
|
||||
drawText(&painter);
|
||||
}
|
||||
|
||||
void upgradeIcon::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 画边框
|
||||
void upgradeIcon::drawBorder(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
painter->setPen(QPen(borderColor,borderWidth));
|
||||
borderRect = QRect(borderWidth,borderWidth,width()-2*borderWidth-headWidth,height()-2*borderWidth);
|
||||
painter->drawRoundedRect(borderRect,borderRadio,borderRadio);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
// 画右边电池头部
|
||||
void upgradeIcon::drawRightHead(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
double headHeight = height()/2;
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QColor(96, 96, 96));
|
||||
QRectF headRect = QRectF(width()-headWidth-borderWidth/2,height()/2-headHeight/2,headWidth / 1.75,headHeight);
|
||||
painter->drawRect(headRect);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
// 画数值对应颜色
|
||||
void upgradeIcon::drawBackground(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
double batteryWidth = width()-headWidth-3*borderWidth; // 电池宽度
|
||||
double bgWidth= value * batteryWidth / (maxValue-minValue); // 背景绘制宽度
|
||||
QLinearGradient batteryGradient(QPointF(0, 0), QPointF(borderWidth+bgWidth,height()));
|
||||
|
||||
batteryGradient.setColorAt(0.0, QColor(135, 206, 250));
|
||||
// batteryGradient.setColorAt(1.0, QColor(102, 255, 0));
|
||||
|
||||
painter->setBrush(QBrush(batteryGradient));
|
||||
painter->setPen(Qt::NoPen);
|
||||
QRectF rectBg = QRectF(borderWidth+borderWidth/2,borderWidth+borderWidth/2,bgWidth,height()-3*borderWidth);
|
||||
painter->drawRoundedRect(rectBg,drawInRadio,drawInRadio);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
// 画百分比数值
|
||||
void upgradeIcon::drawText(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
QString value_str = QString("%1%").arg(value);
|
||||
painter->setPen(QPen(QColor(Qt::black)));
|
||||
double w = qMin(borderRect.width(),borderRect.height());
|
||||
// 文字大小自适应 90为控件初始高度,30位字体默认大小
|
||||
int fontSize = 30 * w / 90;
|
||||
painter->setFont(QFont("Microsoft YaHei UI",fontSize));
|
||||
painter->drawText(borderRect,value_str,QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
// 设置当前值
|
||||
void upgradeIcon::setValue(int value)
|
||||
{
|
||||
this->value = value;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setMinValue(int min)
|
||||
{
|
||||
minValue = min;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setMaxValue(int max)
|
||||
{
|
||||
maxValue = max;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setRange(int min, int max)
|
||||
{
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setBorderWidth(int width)
|
||||
{
|
||||
borderWidth = width;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setBorderRadio(int radio)
|
||||
{
|
||||
borderRadio = radio;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setInRadio(int radio)
|
||||
{
|
||||
drawInRadio = radio;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setAlarmValue(int alarm)
|
||||
{
|
||||
alarmValue = alarm;
|
||||
update();
|
||||
}
|
||||
|
||||
void upgradeIcon::setBorderColor(QColor color)
|
||||
{
|
||||
borderColor = color;
|
||||
update();
|
||||
}
|
||||
|
||||
int upgradeIcon::getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
int upgradeIcon::getMinValue()
|
||||
{
|
||||
return minValue;
|
||||
}
|
||||
|
||||
int upgradeIcon::getMaxValue()
|
||||
{
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
int upgradeIcon::getAlarmValue()
|
||||
{
|
||||
return alarmValue;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef UPGRADEICON_H
|
||||
#define UPGRADEICON_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
#include <QDebug>
|
||||
|
||||
class upgradeIcon : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int value READ getValue WRITE setValue)
|
||||
Q_PROPERTY(int minValue READ getMinValue WRITE setMinValue)
|
||||
Q_PROPERTY(int maxValue READ getMaxValue WRITE setMaxValue)
|
||||
Q_PROPERTY(int alarmValue READ getAlarmValue WRITE setAlarmValue)
|
||||
|
||||
public:
|
||||
explicit upgradeIcon(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
|
||||
protected:
|
||||
void drawBorder(QPainter *painter);
|
||||
void drawRightHead(QPainter *painter);
|
||||
void drawBackground(QPainter *painter);
|
||||
void drawText(QPainter *painter);
|
||||
|
||||
public slots:
|
||||
void setValue(int value); // 设置当前值
|
||||
void setMinValue(int min); // 设置最小值
|
||||
void setMaxValue(int max); // 设置最大值
|
||||
void setRange(int min,int max); // 设置数值范围
|
||||
void setBorderWidth(int width); // 设置边框宽度
|
||||
void setBorderRadio(int radio); // 设置外边框圆角
|
||||
void setInRadio(int radio); // 设置内部绘制区域圆角
|
||||
void setAlarmValue(int alarm); // 设置警告值
|
||||
void setBorderColor(QColor color); // 设置边框颜色
|
||||
int getValue(); // 获取当前值
|
||||
int getMinValue(); // 获取当前最小值
|
||||
int getMaxValue(); // 获取当前最大值
|
||||
int getAlarmValue(); // 获取告警值
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
int borderWidth; // 边缘线框宽度
|
||||
int headWidth; // 右侧头部宽度
|
||||
int value; // 当前值
|
||||
int minValue; // 最小值
|
||||
int maxValue; // 最大值
|
||||
int alarmValue; // 警告值
|
||||
int borderRadio; // 外部边框圆角
|
||||
int drawInRadio; // 内部绘制区域圆角
|
||||
QRectF borderRect; // 电池区域
|
||||
QColor borderColor;
|
||||
};
|
||||
|
||||
#endif // UPGRADEICON_H
|
Loading…
Reference in New Issue