修复ascii发送模式

master
feiyangqingyun 2022-04-27 09:24:14 +08:00
parent bc5429bebb
commit 50d4e9ab0a
6 changed files with 63 additions and 27 deletions

View File

@ -2,19 +2,23 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
greaterThan(QT_MAJOR_VERSION, 4): CONFIG += c++11
#lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11
#没有定义任何版本则默认采用2.0
!contains(DEFINES, qcustomplot_v1_3) {
!contains(DEFINES, qcustomplot_v2_0) {
!contains(DEFINES, qcustomplot_v2_1) {
DEFINES += qcustomplot_v2_0
}}}
#定义了2.0版本在Qt5以上采用2.1
contains(DEFINES, qcustomplot_v2_0) {
!contains(DEFINES, qcustomplot_v2_1) {
greaterThan(QT_MAJOR_VERSION, 4) {
DEFINES -= qcustomplot_v1_3
DEFINES -= qcustomplot_v2_0
DEFINES += qcustomplot_v2_1
}}
}}}
#根据定义的版本引入文件
contains(DEFINES, qcustomplot_v1_3) {
INCLUDEPATH += $$PWD/v1_3
HEADERS += $$PWD/v1_3/qcustomplot.h
@ -26,6 +30,7 @@ HEADERS += $$PWD/v2_0/qcustomplot.h
SOURCES += $$PWD/v2_0/qcustomplot.cpp
} else {
INCLUDEPATH += $$PWD/v2_1
#引入对应修复不支持Qt6的头文件
greaterThan(QT_MAJOR_VERSION, 5) {
HEADERS += $$PWD/v2_1_6/qcustomplot.h
} else {

View File

@ -26,7 +26,7 @@ QString QUIHelperData::strHexToStrBin(const QString &strHex)
uchar len = bin.length();
if (len < 8) {
for (int i = 0; i < 8 - len; i++) {
for (int i = 0; i < 8 - len; ++i) {
bin = "0" + bin;
}
}
@ -39,7 +39,7 @@ QString QUIHelperData::decimalToStrBin1(int decimal)
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 8) {
for (int i = 0; i < 8 - len; i++) {
for (int i = 0; i < 8 - len; ++i) {
bin = "0" + bin;
}
}
@ -52,7 +52,7 @@ QString QUIHelperData::decimalToStrBin2(int decimal)
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 16) {
for (int i = 0; i < 16 - len; i++) {
for (int i = 0; i < 16 - len; ++i) {
bin = "0" + bin;
}
}
@ -184,9 +184,14 @@ QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key)
key = 127;
}
//大概从5.9版本输出的加密密码字符串前面会加上 @String 字符
QString result = value;
if (result.startsWith("@String")) {
result = result.mid(8, result.length() - 9);
}
int count = result.count();
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
result[i] = QChar(result.at(i).toLatin1() ^ key);
}
return result;
@ -196,7 +201,7 @@ uchar QUIHelperData::getOrCode(const QByteArray &data)
{
int len = data.length();
uchar result = 0;
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; ++i) {
result ^= data.at(i);
}
@ -207,7 +212,7 @@ uchar QUIHelperData::getCheckCode(const QByteArray &data)
{
int len = data.length();
uchar temp = 0;
for (uchar i = 0; i < len; i++) {
for (uchar i = 0; i < len; ++i) {
temp += data.at(i);
}
@ -344,7 +349,7 @@ QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data)
QString temp;
int len = data.size();
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; ++i) {
char byte = data.at(i);
QString value = listChar.value(byte);
if (!value.isEmpty()) {
@ -370,7 +375,7 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
QStringList list = data.split("\\");
int count = list.count();
for (int i = 1; i < count; i++) {
for (int i = 1; i < count; ++i) {
QString str = list.at(i);
int key = 0;
if (str.contains("x")) {
@ -382,6 +387,11 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
buffer.append(key);
}
//可能是纯字符串不带控制字符
if (buffer.size() == 0) {
buffer = data.toUtf8();
}
return buffer;
}

View File

@ -386,8 +386,7 @@ void frmComTool::sendData(QString data)
void frmComTool::saveData()
{
QString tempData = ui->txtMain->toPlainText();
if (tempData == "") {
if (tempData.isEmpty()) {
return;
}

View File

@ -58,9 +58,11 @@ private slots:
void on_btnStopShow_clicked();
void on_btnSendCount_clicked();
void on_btnReceiveCount_clicked();
void on_btnClear_clicked();
void on_btnData_clicked();
void on_btnStart_clicked();
void on_ckAutoSend_stateChanged(int arg1);
void on_ckAutoSave_stateChanged(int arg1);
};

View File

@ -26,7 +26,7 @@ QString QUIHelperData::strHexToStrBin(const QString &strHex)
uchar len = bin.length();
if (len < 8) {
for (int i = 0; i < 8 - len; i++) {
for (int i = 0; i < 8 - len; ++i) {
bin = "0" + bin;
}
}
@ -39,7 +39,7 @@ QString QUIHelperData::decimalToStrBin1(int decimal)
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 8) {
for (int i = 0; i < 8 - len; i++) {
for (int i = 0; i < 8 - len; ++i) {
bin = "0" + bin;
}
}
@ -52,7 +52,7 @@ QString QUIHelperData::decimalToStrBin2(int decimal)
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 16) {
for (int i = 0; i < 16 - len; i++) {
for (int i = 0; i < 16 - len; ++i) {
bin = "0" + bin;
}
}
@ -184,9 +184,14 @@ QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key)
key = 127;
}
//大概从5.9版本输出的加密密码字符串前面会加上 @String 字符
QString result = value;
if (result.startsWith("@String")) {
result = result.mid(8, result.length() - 9);
}
int count = result.count();
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
result[i] = QChar(result.at(i).toLatin1() ^ key);
}
return result;
@ -196,7 +201,7 @@ uchar QUIHelperData::getOrCode(const QByteArray &data)
{
int len = data.length();
uchar result = 0;
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; ++i) {
result ^= data.at(i);
}
@ -207,7 +212,7 @@ uchar QUIHelperData::getCheckCode(const QByteArray &data)
{
int len = data.length();
uchar temp = 0;
for (uchar i = 0; i < len; i++) {
for (uchar i = 0; i < len; ++i) {
temp += data.at(i);
}
@ -344,7 +349,7 @@ QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data)
QString temp;
int len = data.size();
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; ++i) {
char byte = data.at(i);
QString value = listChar.value(byte);
if (!value.isEmpty()) {
@ -370,7 +375,7 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
QStringList list = data.split("\\");
int count = list.count();
for (int i = 1; i < count; i++) {
for (int i = 1; i < count; ++i) {
QString str = list.at(i);
int key = 0;
if (str.contains("x")) {
@ -382,6 +387,11 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
buffer.append(key);
}
//可能是纯字符串不带控制字符
if (buffer.size() == 0) {
buffer = data.toUtf8();
}
return buffer;
}

View File

@ -26,7 +26,7 @@ QString QUIHelperData::strHexToStrBin(const QString &strHex)
uchar len = bin.length();
if (len < 8) {
for (int i = 0; i < 8 - len; i++) {
for (int i = 0; i < 8 - len; ++i) {
bin = "0" + bin;
}
}
@ -39,7 +39,7 @@ QString QUIHelperData::decimalToStrBin1(int decimal)
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 8) {
for (int i = 0; i < 8 - len; i++) {
for (int i = 0; i < 8 - len; ++i) {
bin = "0" + bin;
}
}
@ -52,7 +52,7 @@ QString QUIHelperData::decimalToStrBin2(int decimal)
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 16) {
for (int i = 0; i < 16 - len; i++) {
for (int i = 0; i < 16 - len; ++i) {
bin = "0" + bin;
}
}
@ -184,9 +184,14 @@ QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key)
key = 127;
}
//大概从5.9版本输出的加密密码字符串前面会加上 @String 字符
QString result = value;
if (result.startsWith("@String")) {
result = result.mid(8, result.length() - 9);
}
int count = result.count();
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
result[i] = QChar(result.at(i).toLatin1() ^ key);
}
return result;
@ -196,7 +201,7 @@ uchar QUIHelperData::getOrCode(const QByteArray &data)
{
int len = data.length();
uchar result = 0;
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; ++i) {
result ^= data.at(i);
}
@ -207,7 +212,7 @@ uchar QUIHelperData::getCheckCode(const QByteArray &data)
{
int len = data.length();
uchar temp = 0;
for (uchar i = 0; i < len; i++) {
for (uchar i = 0; i < len; ++i) {
temp += data.at(i);
}
@ -344,7 +349,7 @@ QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data)
QString temp;
int len = data.size();
for (int i = 0; i < len; i++) {
for (int i = 0; i < len; ++i) {
char byte = data.at(i);
QString value = listChar.value(byte);
if (!value.isEmpty()) {
@ -370,7 +375,7 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
QStringList list = data.split("\\");
int count = list.count();
for (int i = 1; i < count; i++) {
for (int i = 1; i < count; ++i) {
QString str = list.at(i);
int key = 0;
if (str.contains("x")) {
@ -382,6 +387,11 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
buffer.append(key);
}
//可能是纯字符串不带控制字符
if (buffer.size() == 0) {
buffer = data.toUtf8();
}
return buffer;
}