release Version 1.0.0
This commit is contained in:
parent
8279590f38
commit
25f0c01a47
|
@ -25,7 +25,8 @@ SOURCES += \
|
||||||
modbusrtu.cpp \
|
modbusrtu.cpp \
|
||||||
proto/battery.pb.cc \
|
proto/battery.pb.cc \
|
||||||
appserial.cpp \
|
appserial.cpp \
|
||||||
proto/battery_english.pb.cc
|
proto/battery_english.pb.cc \
|
||||||
|
upgradeicon.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
appproto.h \
|
appproto.h \
|
||||||
|
@ -46,7 +47,8 @@ HEADERS += \
|
||||||
modbusrtu.h \
|
modbusrtu.h \
|
||||||
proto/battery.pb.h \
|
proto/battery.pb.h \
|
||||||
appserial.h \
|
appserial.h \
|
||||||
proto/battery_english.pb.h
|
proto/battery_english.pb.h \
|
||||||
|
upgradeicon.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
dialoglogin.ui \
|
dialoglogin.ui \
|
||||||
|
|
Binary file not shown.
|
@ -13,6 +13,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QLabel>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
Delegate::Delegate(QObject *parent): QStyledItemDelegate(parent)
|
Delegate::Delegate(QObject *parent): QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
|
@ -81,9 +82,16 @@ QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*o
|
||||||
else if (delegateType == "QLineEdit")
|
else if (delegateType == "QLineEdit")
|
||||||
{
|
{
|
||||||
QLineEdit *lineEidt = new QLineEdit(parent);
|
QLineEdit *lineEidt = new QLineEdit(parent);
|
||||||
|
// lineEidt->setReadOnly(true);
|
||||||
editor = lineEidt;
|
editor = lineEidt;
|
||||||
connect(lineEidt, SIGNAL(textChanged(QString)), this, SLOT(on_valueChanged(QString)));
|
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;
|
return editor;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +134,11 @@ void Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||||
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
||||||
lineEidt->setText(value.toString());
|
lineEidt->setText(value.toString());
|
||||||
}
|
}
|
||||||
|
else if (delegateType == "QLabel")
|
||||||
|
{
|
||||||
|
QLabel *label = static_cast<QLabel *>(editor);
|
||||||
|
label->setText(value.toString());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QStyledItemDelegate::setEditorData(editor, index);
|
QStyledItemDelegate::setEditorData(editor, index);
|
||||||
|
@ -171,6 +184,11 @@ void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
QLineEdit *lineEidt = static_cast<QLineEdit *>(editor);
|
||||||
value = lineEidt->text();
|
value = lineEidt->text();
|
||||||
}
|
}
|
||||||
|
else if (delegateType == "QLabel")
|
||||||
|
{
|
||||||
|
QLabel *label = static_cast<QLabel *>(editor);
|
||||||
|
value = label->text();
|
||||||
|
}
|
||||||
model->setData(index, value, Qt::EditRole);
|
model->setData(index, value, Qt::EditRole);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -208,6 +226,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
|
||||||
drawLineEdit(painter, option, index);
|
drawLineEdit(painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//if
|
}//if
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,6 +105,16 @@ void DialogLogin::init()
|
||||||
//主窗口接受语言选择number的信号与槽的连接
|
//主窗口接受语言选择number的信号与槽的连接
|
||||||
connect(this, &DialogLogin::sendLanNumberSignals, m_MainWindow, &MainWindow::getLanNumberSlot);
|
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);
|
||||||
|
|
||||||
|
|
||||||
// QMetaObject::invokeMethod(m_ModbusRTU,"read_regs_slot",Qt::QueuedConnection);
|
// QMetaObject::invokeMethod(m_ModbusRTU,"read_regs_slot",Qt::QueuedConnection);
|
||||||
// connect(m_ModbusRTU, &ModbusRTU::sig_readMoveToThread, m_ModbusRTU, &ModbusRTU::read_regs_slot, Qt::QueuedConnection);
|
// connect(m_ModbusRTU, &ModbusRTU::sig_readMoveToThread, m_ModbusRTU, &ModbusRTU::read_regs_slot, Qt::QueuedConnection);
|
||||||
|
|
967
mainwindow.cpp
967
mainwindow.cpp
File diff suppressed because it is too large
Load Diff
55
mainwindow.h
55
mainwindow.h
|
@ -35,6 +35,13 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QStandardItemModel *model;
|
QStandardItemModel *model;
|
||||||
|
|
||||||
|
QStandardItemModel *modelBCU; //设置BCU目录
|
||||||
|
QStandardItem *rootItem;
|
||||||
|
|
||||||
|
QStandardItemModel *model_history_alarm;
|
||||||
|
QStandardItemModel *model_get_version;
|
||||||
|
|
||||||
ComLogin *m_ComLogin;
|
ComLogin *m_ComLogin;
|
||||||
AppProto *m_AppProto;
|
AppProto *m_AppProto;
|
||||||
Appproto_English *m_AppProto_English;
|
Appproto_English *m_AppProto_English;
|
||||||
|
@ -45,10 +52,9 @@ public:
|
||||||
QLabel *statusBarCompany;
|
QLabel *statusBarCompany;
|
||||||
QLabel *statusBarBcu;
|
QLabel *statusBarBcu;
|
||||||
QLabel *statusBarVersion;
|
QLabel *statusBarVersion;
|
||||||
ChartPaint *chartPat;
|
// ChartPaint *chartPat;
|
||||||
|
QString currentBCU = "BCU01";
|
||||||
|
|
||||||
QStandardItemModel *modelBCU; //设置BCU目录
|
|
||||||
QStandardItem *rootItem;
|
|
||||||
|
|
||||||
int BCUNumbers;
|
int BCUNumbers;
|
||||||
// QGridLayout *gridLayout;
|
// QGridLayout *gridLayout;
|
||||||
|
@ -70,6 +76,14 @@ public:
|
||||||
|
|
||||||
int tabWidget_paraset_index = 0;
|
int tabWidget_paraset_index = 0;
|
||||||
|
|
||||||
|
QList<QLabel*> trouble_list;
|
||||||
|
QList<int> trouble_list_flag;
|
||||||
|
|
||||||
|
bool trouble_history = 1;
|
||||||
|
|
||||||
|
int count_history_alarm = 0; //如果不放到全局变量中去,每次刷新的都是同一个报警的内容,无法达到历史告警的作用
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum DataType{
|
enum DataType{
|
||||||
|
@ -103,6 +117,8 @@ private:
|
||||||
void init();
|
void init();
|
||||||
void setMenuStyle();
|
void setMenuStyle();
|
||||||
void pageBatteryInit();
|
void pageBatteryInit();
|
||||||
|
void pageHomeHistoryAlarm();
|
||||||
|
void pageFlashGetVersion();
|
||||||
void pageParaSetInit();
|
void pageParaSetInit();
|
||||||
void pageParaSetInit_alert_value();
|
void pageParaSetInit_alert_value();
|
||||||
void pageParaSetInit_alert_delay();
|
void pageParaSetInit_alert_delay();
|
||||||
|
@ -120,6 +136,8 @@ private:
|
||||||
int findMaxIndex(const QList<int> sgl_info);
|
int findMaxIndex(const QList<int> sgl_info);
|
||||||
int findMinIndex(const QList<int> sgl_info);
|
int findMinIndex(const QList<int> sgl_info);
|
||||||
|
|
||||||
|
void trubleListInit();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// void setNum(QString value);
|
// void setNum(QString value);
|
||||||
void getLanNumberSlot(int number);
|
void getLanNumberSlot(int number);
|
||||||
|
@ -129,18 +147,23 @@ signals:
|
||||||
void closeLogin();
|
void closeLogin();
|
||||||
void write_regs_signals(int addr, const uint16_t data);
|
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_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 closeThread();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void slot_getBcuNumberFromDialoglogin(int number);
|
void slot_getBcuNumberFromDialoglogin(int number);
|
||||||
void slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType);
|
void slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType);
|
void slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeSglTempt(QByteArray byteArray, int dataType);
|
void slot_pageHomeSglTempt(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType);
|
void slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType);
|
void slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void slot_pageHomeBaseInfo83_106(QByteArray byteArray, int dataType);
|
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_pageHomeBaseInfo47_49_51_53_55(QList<int> byteArray, int dataType);
|
||||||
void slot_pageParaSetShow(QByteArray byteArray, int dataType, int row, int nb);
|
void slot_pageParaSetShow(QByteArray byteArray, int dataType, int row, int nb);
|
||||||
|
void slot_pageHomeFault(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *e) override;
|
void closeEvent(QCloseEvent *e) override;
|
||||||
|
@ -153,6 +176,20 @@ private slots:
|
||||||
void on_comBoxBCUSelect();
|
void on_comBoxBCUSelect();
|
||||||
// void on_horizontalSlider_valueChanged(int value);
|
// 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:
|
public:
|
||||||
struct Battery_data {
|
struct Battery_data {
|
||||||
uint16_t pack_total_voltage; // 电池组总压
|
uint16_t pack_total_voltage; // 电池组总压
|
||||||
|
|
15028
mainwindow.ui
15028
mainwindow.ui
File diff suppressed because it is too large
Load Diff
123
modbusrtu.cpp
123
modbusrtu.cpp
|
@ -30,7 +30,7 @@ void ModbusRTU::run()
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
// qDebug() << "11111111111111111111111111111111";
|
// qDebug() << "11111111111111111111111111111111";
|
||||||
QThread::msleep(200);
|
QThread::msleep(500);
|
||||||
uint16_t base1_45[45];
|
uint16_t base1_45[45];
|
||||||
uint16_t base57_78[22];
|
uint16_t base57_78[22];
|
||||||
uint16_t base83_106[24];
|
uint16_t base83_106[24];
|
||||||
|
@ -40,24 +40,25 @@ void ModbusRTU::run()
|
||||||
uint16_t base53[1];
|
uint16_t base53[1];
|
||||||
uint16_t base55[1];
|
uint16_t base55[1];
|
||||||
QList<int> base_list_47_49_51_53_55;
|
QList<int> base_list_47_49_51_53_55;
|
||||||
uint16_t sgl_vol[112]; // Buffer to store the registers
|
uint16_t sgl_vol[16]; // Buffer to store the registers
|
||||||
uint16_t sgl_tempt[112];
|
uint16_t sgl_tempt[16];
|
||||||
|
uint16_t fault[8];
|
||||||
// uint16_t alarm[];
|
// uint16_t alarm[];
|
||||||
|
|
||||||
label: int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
|
label: int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
|
||||||
if(MODBUS_ERR == ret_base1_45)
|
if(MODBUS_ERR == ret_base1_45)
|
||||||
{
|
{
|
||||||
qDebug() << "modbus no message";
|
// qDebug() << "modbus no message";
|
||||||
goto label;
|
goto label;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// qDebug() << "2222222222222222222222222222222";
|
// qDebug() << "2222222222222222222222222222222";
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
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);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
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);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
// qDebug() << "in modbus:" << base1_45;
|
// qDebug() << "in modbus:" << base1_45;
|
||||||
}
|
}
|
||||||
|
@ -107,14 +108,34 @@ void ModbusRTU::run()
|
||||||
{
|
{
|
||||||
// qDebug() << "4444444444444444444444444444";
|
// qDebug() << "4444444444444444444444444444";
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
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);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
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)
|
||||||
|
{
|
||||||
|
// qDebug() << "modbus no message";
|
||||||
|
goto label;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// qDebug() << "4444444444444444444444444444";
|
||||||
|
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);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret_base83_106 = modbus_read_input_registers(m_ModbusRTUDevice, 83, 24, base83_106);
|
int ret_base83_106 = modbus_read_input_registers(m_ModbusRTUDevice, 83, 24, base83_106);
|
||||||
|
// qDebug() << "#######" << base83_106[0] << base83_106[1] << base83_106[2] << base83_106[3];
|
||||||
|
// qDebug() << "#######" << sgl_vol[0] << sgl_vol[1] << sgl_vol[2] << sgl_vol[3] << sgl_vol[4] << sgl_vol[5] << sgl_vol[6] << sgl_vol[7]
|
||||||
|
// << sgl_vol[8] << sgl_vol[9] << sgl_vol[10] << sgl_vol[11] << sgl_vol[12] << sgl_vol[13] << sgl_vol[14] << sgl_vol[15];
|
||||||
if(MODBUS_ERR == ret_base83_106)
|
if(MODBUS_ERR == ret_base83_106)
|
||||||
{
|
{
|
||||||
// qDebug() << "modbus no message";
|
// qDebug() << "modbus no message";
|
||||||
|
@ -124,45 +145,57 @@ void ModbusRTU::run()
|
||||||
{
|
{
|
||||||
// qDebug() << "5555555555555555555555555555";
|
// qDebug() << "5555555555555555555555555555";
|
||||||
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
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);
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
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);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, 1001, 112, sgl_vol);
|
// qDebug() << "the current of the BMU is :" << BMUIndex;
|
||||||
// if(MODBUS_ERR == ret_vol)
|
int volAddress = (1001 + BMUIndex * 16);
|
||||||
// {
|
int tempAddress = (1601 + BMUIndex * 16);
|
||||||
// // qDebug() << "modbus no message";
|
// qDebug() << "volAddress: " << volAddress;
|
||||||
// goto label;
|
// qDebug() << "tempAddress: " << tempAddress;
|
||||||
|
// QElapsedTimer time;
|
||||||
|
// time.start();
|
||||||
|
// qDebug() << "#######" << sgl_vol[0] << sgl_vol[1] << sgl_vol[2] << sgl_vol[3] << sgl_vol[4] << sgl_vol[5] << sgl_vol[6] << sgl_vol[7]
|
||||||
|
// << sgl_vol[8] << sgl_vol[9] << sgl_vol[10] << sgl_vol[11] << sgl_vol[12] << sgl_vol[13] << sgl_vol[14] << sgl_vol[15];
|
||||||
|
// int milsec = time.elapsed();
|
||||||
|
// qDebug() <<"0.12311231" << milsec;
|
||||||
|
|
||||||
// }
|
int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, volAddress, 16, sgl_vol);
|
||||||
// else
|
if(MODBUS_ERR == ret_vol)
|
||||||
// {
|
{
|
||||||
// QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
// qDebug() << "modbus no message";
|
||||||
// emit sig_showModbusData(sendArray, TypeSendData);
|
goto label;
|
||||||
// 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)
|
else
|
||||||
// {
|
{
|
||||||
// // qDebug() << "modbus no message";
|
QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
||||||
// goto label;
|
emit sig_showModbusData(sendArray, TypeSendData, sgl_vol);
|
||||||
// }
|
free(m_ModbusRTUDevice->sendMsg);
|
||||||
// else
|
QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
||||||
// {
|
emit sig_showModbusData(recvArray, TypeRecvData, sgl_vol);
|
||||||
// QByteArray sendArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->sendMsg), m_ModbusRTUDevice->sendMsgLen);
|
free(m_ModbusRTUDevice->recvMsg);
|
||||||
// emit sig_showModbusData_sgl_tempt(sendArray, TypeSendData);
|
}
|
||||||
// free(m_ModbusRTUDevice->sendMsg);
|
// QThread::msleep(500);
|
||||||
// QByteArray recvArray = QByteArray::fromRawData(reinterpret_cast<char *>(m_ModbusRTUDevice->recvMsg), m_ModbusRTUDevice->recvMsgLen);
|
int ret_tempt = modbus_read_input_registers(m_ModbusRTUDevice, tempAddress, 16, sgl_tempt);
|
||||||
// emit sig_showModbusData_sgl_tempt(recvArray, TypeRecvData);
|
if(MODBUS_ERR == ret_tempt)
|
||||||
// free(m_ModbusRTUDevice->recvMsg);
|
{
|
||||||
// }
|
// qDebug() << "modbus no message";
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -171,7 +204,7 @@ void ModbusRTU::run()
|
||||||
|
|
||||||
void ModbusRTU::write_regs_slot(int addr,const uint16_t data)
|
void ModbusRTU::write_regs_slot(int addr,const uint16_t data)
|
||||||
{
|
{
|
||||||
qDebug() << "write:进入线程:" << QThread::currentThread();
|
// qDebug() << "write:进入线程:" << QThread::currentThread();
|
||||||
int rc = write_single_register(addr, data);
|
int rc = write_single_register(addr, data);
|
||||||
if(MODBUS_ERR == rc) {
|
if(MODBUS_ERR == rc) {
|
||||||
qDebug() << "######modbus no message";
|
qDebug() << "######modbus no message";
|
||||||
|
@ -181,7 +214,7 @@ void ModbusRTU::write_regs_slot(int addr,const uint16_t data)
|
||||||
|
|
||||||
void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row)
|
void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row)
|
||||||
{
|
{
|
||||||
qDebug() << "read:进入线程:" << QThread::currentThread();
|
// qDebug() << "read:进入线程:" << QThread::currentThread();
|
||||||
int rc = read_holding_register(addr, nb, data);
|
int rc = read_holding_register(addr, nb, data);
|
||||||
if(MODBUS_ERR == rc) {
|
if(MODBUS_ERR == rc) {
|
||||||
// qDebug() << "modbus no message";
|
// qDebug() << "modbus no message";
|
||||||
|
@ -194,6 +227,12 @@ void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModbusRTU::change_BMUIndex_slot(int index)
|
||||||
|
{
|
||||||
|
BMUIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ModbusRTU::modbusRTUConnect(const char *comPort, int baudRate, char parity, int dataBit, int stopBit)
|
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;
|
qDebug() << "comPort:" << comPort << "baudRate:" << baudRate << "parity:" << parity << "dataBit" << dataBit << "stopBit:" << stopBit;
|
||||||
|
|
15
modbusrtu.h
15
modbusrtu.h
|
@ -17,6 +17,9 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void write_regs_slot(int addr, const uint16_t data);
|
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_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:
|
public:
|
||||||
modbus_t *m_ModbusRTUDevice;
|
modbus_t *m_ModbusRTUDevice;
|
||||||
|
@ -26,6 +29,7 @@ public:
|
||||||
char parity;
|
char parity;
|
||||||
int dataBit;
|
int dataBit;
|
||||||
int stopBit;
|
int stopBit;
|
||||||
|
int BMUIndex = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void run() override;
|
void run() override;
|
||||||
|
@ -63,14 +67,15 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sig_ModbusRTUConnected();
|
void sig_ModbusRTUConnected();
|
||||||
void sig_showModbusData(QByteArray byteArray, int dataType);
|
void sig_showModbusData(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_sgl_tempt(QByteArray byteArray, int dataType);
|
void sig_showModbusData_sgl_tempt(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info1_45(QByteArray byteArray,int dataType);
|
void sig_showModbusData_base_info1_45(QByteArray byteArray,int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info57_78(QByteArray byteArray,int dataType);
|
void sig_showModbusData_base_info57_78(QByteArray byteArray,int dataType, uint16_t *data);
|
||||||
void sig_showModbusData_base_info83_106(QByteArray byteArray,int dataType);
|
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_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_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(QByteArray byteArray,int dataType, int row, int nb);
|
||||||
|
void sig_showFault(QByteArray byteArray, int dataType, uint16_t *data);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -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