[Add] English version work is done

This commit is contained in:
Carl 2024-11-05 15:44:19 +08:00
parent d4ae45d1dc
commit bfee5f9d49
16 changed files with 16582 additions and 1273 deletions

View File

@ -11,6 +11,7 @@ CONFIG += c++17
SOURCES += \
appproto.cpp \
appproto_english.cpp \
batt.cpp \
chartpaint.cpp \
custom/delegate.cpp \
@ -23,10 +24,12 @@ SOURCES += \
mainwindow.cpp \
modbusrtu.cpp \
proto/battery.pb.cc \
appserial.cpp
appserial.cpp \
proto/battery_english.pb.cc
HEADERS += \
appproto.h \
appproto_english.h \
batt.h \
chartpaint.h \
custom/delegate.h \
@ -42,7 +45,8 @@ HEADERS += \
mainwindow.h \
modbusrtu.h \
proto/battery.pb.h \
appserial.h
appserial.h \
proto/battery_english.pb.h
FORMS += \
dialoglogin.ui \

Binary file not shown.

View File

@ -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)) {

4943
appproto_english.cpp Normal file

File diff suppressed because it is too large Load Diff

30
appproto_english.h Normal file
View File

@ -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

View File

@ -10,6 +10,7 @@
#include "appserial.h"
#include "modbusrtu.h"
#include <windef.h>
#include <QTranslator>
#include <QThread>
DialogLogin::DialogLogin(QWidget *parent)
@ -53,6 +54,9 @@ void DialogLogin::init()
ini = new QSettings("config.ini", QSettings::IniFormat);
connect(ui->btnConnect, &QPushButton::clicked, this, &DialogLogin::slot_btnConnect_clicked);
// //将背景设置为白色
// ui->groupBox->setStyleSheet("background-color: #FFFFFF;");
// //传递BCU个数的信号与槽
// BCUNumbers = ui->comboBoxBCUQuantity->currentText().toInt();
// qDebug() << "the number of the BCU: " << BCUNumbers;
@ -97,6 +101,11 @@ void DialogLogin::init()
m_ModbusRTU->quit();
});
//主窗口接受语言选择number的信号与槽的连接
connect(this, &DialogLogin::sendLanNumberSignals, m_MainWindow, &MainWindow::getLanNumberSlot);
// 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;
@ -117,6 +126,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());
@ -124,6 +135,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();
}
}
@ -174,6 +188,30 @@ void DialogLogin::slot_btnConnect_clicked()
{
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);
ini->setValue("Serial/BaudRate", ui->comboBoxBaudRate->currentIndex());
@ -263,6 +301,7 @@ void DialogLogin::slot_btnConnect_clicked()
// m_MainWindow->showMaximized();
// m_ModbusRTU->start();
m_ModbusRTU->start();
m_MainWindow->showMaximized();
}
else {
if(ini->value("System/Language") == MainWindow::LANGUAGE_ENG) {

View File

@ -36,6 +36,7 @@ private:
signals:
void sendBCUNumberSignals(int number);
void sendLanNumberSignals(int number);
private slots:
void slot_comChangeStatus(QString name, bool flag);

View File

@ -20,93 +20,33 @@
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Communication</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="9" column="3">
<widget class="QComboBox" name="comboBoxParity">
<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>
<item row="2" column="3">
<widget class="QComboBox" name="comboBoxSerialPort"/>
</item>
<item row="5" column="2">
<widget class="QLabel" name="labelBaudRate">
<property name="text">
<string>Baud Rate</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QComboBox" name="comboBoxBaudRate">
<item>
<property name="text">
<string>1200</string>
</property>
</item>
<item>
<property name="text">
<string>2400</string>
</property>
</item>
<item>
<property name="text">
<string>4800</string>
</property>
</item>
<item>
<property name="text">
<string>9600</string>
</property>
</item>
<item>
<property name="text">
<string>19200</string>
</property>
</item>
<item>
<property name="text">
<string>38400</string>
</property>
</item>
<item>
<property name="text">
<string>57600</string>
</property>
</item>
<item>
<property name="text">
<string>115200</string>
</property>
</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">
<item row="8" column="3">
<widget class="QComboBox" name="comboBoxDataBits">
<item>
<property name="text">
@ -130,21 +70,10 @@
</item>
</widget>
</item>
<item row="8" column="2">
<widget class="QLabel" name="labelStopBits">
<property name="text">
<string>Stop Bits</string>
</property>
</widget>
<item row="4" column="3">
<widget class="QComboBox" name="comboBoxSerialPort"/>
</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">
<item row="10" column="3">
<widget class="QComboBox" name="comboBoxStopBits">
<item>
<property name="text">
@ -158,14 +87,7 @@
</item>
</widget>
</item>
<item row="6" column="2">
<widget class="QLabel" name="labelDataBits">
<property name="text">
<string>Data Bits</string>
</property>
</widget>
</item>
<item row="0" column="3">
<item row="2" column="3">
<widget class="QComboBox" name="comboBoxBCUQuantity">
<item>
<property name="text">
@ -249,36 +171,135 @@
</item>
</widget>
</item>
<item row="0" column="2">
<item row="7" column="3">
<widget class="QComboBox" name="comboBoxBaudRate">
<item>
<property name="text">
<string>1200</string>
</property>
</item>
<item>
<property name="text">
<string>2400</string>
</property>
</item>
<item>
<property name="text">
<string>4800</string>
</property>
</item>
<item>
<property name="text">
<string>9600</string>
</property>
</item>
<item>
<property name="text">
<string>19200</string>
</property>
</item>
<item>
<property name="text">
<string>38400</string>
</property>
</item>
<item>
<property name="text">
<string>57600</string>
</property>
</item>
<item>
<property name="text">
<string>115200</string>
</property>
</item>
</widget>
</item>
<item row="7" column="2">
<widget class="QLabel" name="labelBaudRate">
<property name="text">
<string>Baud Rate</string>
</property>
</widget>
</item>
<item row="10" column="2">
<widget class="QLabel" name="labelStopBits">
<property name="text">
<string>Stop Bits</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="labelBCUQuantity">
<property name="text">
<string>BCU Quantity</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="labelSerialPort">
<property name="text">
<string>Serial Port</string>
</property>
</widget>
</item>
<item row="11" column="2">
<widget class="QLabel" name="labelParity">
<property name="text">
<string>Parity</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QLabel" name="labelDataBits">
<property name="text">
<string>Data Bits</string>
</property>
</widget>
</item>
<item row="11" column="3">
<widget class="QComboBox" name="comboBoxParity">
<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>
<item row="1" column="2">
<widget class="QLabel" name="labelBCUQuantity_2">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QComboBox" name="comboBoxLanguage">
<item>
<property name="text">
<string>Chinese</string>
</property>
</item>
<item>
<property name="text">
<string>English</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@ class QSettings;
class QLabel;
class QFile;
class AppProto;
class Appproto_English;
class ChartPaint;
QT_BEGIN_NAMESPACE
@ -36,6 +37,7 @@ public:
QStandardItemModel *model;
ComLogin *m_ComLogin;
AppProto *m_AppProto;
Appproto_English *m_AppProto_English;
QSettings *ini;
QFile *logFile;
QLabel *statusBarConnectedIcon;
@ -58,6 +60,7 @@ public:
QList<int> base_info83_106;
int battery_count;
ModbusRTU *m_modbusrtu_main;
int lan;
int tabWidget_paraset_index = 0;
@ -113,6 +116,7 @@ private:
public slots:
// void setNum(QString value);
void getLanNumberSlot(int number);
signals:
void showLogin();

File diff suppressed because it is too large Load Diff

View File

@ -42,6 +42,7 @@ void ModbusRTU::run()
QList<int> base_list_47_49_51_53_55;
uint16_t sgl_vol[112]; // Buffer to store the registers
uint16_t sgl_tempt[112];
// uint16_t alarm[];
label: int ret_base1_45 = modbus_read_input_registers(m_ModbusRTUDevice, 1, 45, base1_45);
if(MODBUS_ERR == ret_base1_45)
@ -100,7 +101,7 @@ void ModbusRTU::run()
if(MODBUS_ERR == ret_base57_78)
{
// qDebug() << "modbus no message";
return;
goto label;
}
else
{
@ -130,38 +131,38 @@ void ModbusRTU::run()
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";
goto label;
// int ret_vol = modbus_read_input_registers(m_ModbusRTUDevice, 1001, 112, sgl_vol);
// if(MODBUS_ERR == ret_vol)
// {
// // qDebug() << "modbus no message";
// goto label;
}
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);
}
// }
// 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";
goto label;
}
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);
}
// int ret_tempt = modbus_read_input_registers(m_ModbusRTUDevice, 1601, 112, sgl_tempt);
// if(MODBUS_ERR == ret_tempt)
// {
// // 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);
// 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);
// }
}

14
proto/auto.bat Normal file
View File

@ -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

4897
proto/battery_english.pb.cc Normal file

File diff suppressed because it is too large Load Diff

4968
proto/battery_english.pb.h Normal file

File diff suppressed because it is too large Load Diff

105
proto/battery_english.proto Normal file
View File

@ -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;
}