改进部分代码

master
feiyangqingyun 2021-04-13 09:36:22 +08:00
parent 99ef34b09d
commit 09ff5a7384
33 changed files with 809 additions and 807 deletions

View File

@ -1,7 +1,7 @@
HEADERS += \
$$PWD/app.h \
$$PWD/appconfig.h \
$$PWD/quiwidget.h
SOURCES += \
$$PWD/app.cpp \
$$PWD/appconfig.cpp \
$$PWD/quiwidget.cpp

View File

@ -1,160 +0,0 @@
#include "app.h"
#include "quiwidget.h"
QString App::ConfigFile = "config.ini";
QString App::SendFileName = "send.txt";
QString App::DeviceFileName = "device.txt";
QString App::PortName = "COM1";
int App::BaudRate = 9600;
int App::DataBit = 8;
QString App::Parity = QString::fromUtf8("");
double App::StopBit = 1;
bool App::HexSend = false;
bool App::HexReceive = false;
bool App::Debug = false;
bool App::AutoClear = false;
bool App::AutoSend = false;
int App::SendInterval = 1000;
bool App::AutoSave = false;
int App::SaveInterval = 5000;
QString App::Mode = "Tcp_Client";
QString App::ServerIP = "127.0.0.1";
int App::ServerPort = 6000;
int App::ListenPort = 6000;
int App::SleepTime = 100;
bool App::AutoConnect = false;
void App::readConfig()
{
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
writeConfig();
return;
}
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.beginGroup("ComConfig");
App::PortName = set.value("PortName", App::PortName).toString();
App::BaudRate = set.value("BaudRate", App::BaudRate).toInt();
App::DataBit = set.value("DataBit", App::DataBit).toInt();
App::Parity = set.value("Parity", App::Parity).toString();
App::StopBit = set.value("StopBit", App::StopBit).toInt();
App::HexSend = set.value("HexSend", App::HexSend).toBool();
App::HexReceive = set.value("HexReceive", App::HexReceive).toBool();
App::Debug = set.value("Debug", App::Debug).toBool();
App::AutoClear = set.value("AutoClear", App::AutoClear).toBool();
App::AutoSend = set.value("AutoSend", App::AutoSend).toBool();
App::SendInterval = set.value("SendInterval", App::SendInterval).toInt();
App::AutoSave = set.value("AutoSave", App::AutoSave).toBool();
App::SaveInterval = set.value("SaveInterval", App::SaveInterval).toInt();
set.endGroup();
set.beginGroup("NetConfig");
App::Mode = set.value("Mode", App::Mode).toString();
App::ServerIP = set.value("ServerIP", App::ServerIP).toString();
App::ServerPort = set.value("ServerPort", App::ServerPort).toInt();
App::ListenPort = set.value("ListenPort", App::ListenPort).toInt();
App::SleepTime = set.value("SleepTime", App::SleepTime).toInt();
App::AutoConnect = set.value("AutoConnect", App::AutoConnect).toBool();
set.endGroup();
}
void App::writeConfig()
{
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.beginGroup("ComConfig");
set.setValue("PortName", App::PortName);
set.setValue("BaudRate", App::BaudRate);
set.setValue("DataBit", App::DataBit);
set.setValue("Parity", App::Parity);
set.setValue("StopBit", App::StopBit);
set.setValue("HexSend", App::HexSend);
set.setValue("HexReceive", App::HexReceive);
set.setValue("Debug", App::Debug);
set.setValue("AutoClear", App::AutoClear);
set.setValue("AutoSend", App::AutoSend);
set.setValue("SendInterval", App::SendInterval);
set.setValue("AutoSave", App::AutoSave);
set.setValue("SaveInterval", App::SaveInterval);
set.endGroup();
set.beginGroup("NetConfig");
set.setValue("Mode", App::Mode);
set.setValue("ServerIP", App::ServerIP);
set.setValue("ServerPort", App::ServerPort);
set.setValue("ListenPort", App::ListenPort);
set.setValue("SleepTime", App::SleepTime);
set.setValue("AutoConnect", App::AutoConnect);
set.endGroup();
}
QStringList App::Intervals = QStringList();
QStringList App::Datas = QStringList();
QStringList App::Keys = QStringList();
QStringList App::Values = QStringList();
void App::readSendData()
{
//读取发送数据列表
App::Datas.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::SendFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
App::Datas.append(line);
}
}
file.close();
}
if (App::Datas.count() == 0) {
App::Datas << "16 FF 01 01 E0 E1" << "16 FF 01 01 E1 E2";
}
}
void App::readDeviceData()
{
//读取转发数据列表
App::Keys.clear();
App::Values.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::DeviceFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
QStringList list = line.split(";");
QString key = list.at(0);
QString value;
for (int i = 1; i < list.count(); i++) {
value += QString("%1;").arg(list.at(i));
}
//去掉末尾分号
value = value.mid(0, value.length() - 1);
App::Keys.append(key);
App::Values.append(value);
}
}
file.close();
}
}

160
comtool/api/appconfig.cpp Normal file
View File

@ -0,0 +1,160 @@
#include "appconfig.h"
#include "quiwidget.h"
QString AppConfig::ConfigFile = "config.ini";
QString AppConfig::SendFileName = "send.txt";
QString AppConfig::DeviceFileName = "device.txt";
QString AppConfig::PortName = "COM1";
int AppConfig::BaudRate = 9600;
int AppConfig::DataBit = 8;
QString AppConfig::Parity = QString::fromUtf8("");
double AppConfig::StopBit = 1;
bool AppConfig::HexSend = false;
bool AppConfig::HexReceive = false;
bool AppConfig::Debug = false;
bool AppConfig::AutoClear = false;
bool AppConfig::AutoSend = false;
int AppConfig::SendInterval = 1000;
bool AppConfig::AutoSave = false;
int AppConfig::SaveInterval = 5000;
QString AppConfig::Mode = "Tcp_Client";
QString AppConfig::ServerIP = "127.0.0.1";
int AppConfig::ServerPort = 6000;
int AppConfig::ListenPort = 6000;
int AppConfig::SleepTime = 100;
bool AppConfig::AutoConnect = false;
void AppConfig::readConfig()
{
if (!QUIHelper::checkIniFile(AppConfig::ConfigFile)) {
writeConfig();
return;
}
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
set.beginGroup("ComConfig");
AppConfig::PortName = set.value("PortName", AppConfig::PortName).toString();
AppConfig::BaudRate = set.value("BaudRate", AppConfig::BaudRate).toInt();
AppConfig::DataBit = set.value("DataBit", AppConfig::DataBit).toInt();
AppConfig::Parity = set.value("Parity", AppConfig::Parity).toString();
AppConfig::StopBit = set.value("StopBit", AppConfig::StopBit).toInt();
AppConfig::HexSend = set.value("HexSend", AppConfig::HexSend).toBool();
AppConfig::HexReceive = set.value("HexReceive", AppConfig::HexReceive).toBool();
AppConfig::Debug = set.value("Debug", AppConfig::Debug).toBool();
AppConfig::AutoClear = set.value("AutoClear", AppConfig::AutoClear).toBool();
AppConfig::AutoSend = set.value("AutoSend", AppConfig::AutoSend).toBool();
AppConfig::SendInterval = set.value("SendInterval", AppConfig::SendInterval).toInt();
AppConfig::AutoSave = set.value("AutoSave", AppConfig::AutoSave).toBool();
AppConfig::SaveInterval = set.value("SaveInterval", AppConfig::SaveInterval).toInt();
set.endGroup();
set.beginGroup("NetConfig");
AppConfig::Mode = set.value("Mode", AppConfig::Mode).toString();
AppConfig::ServerIP = set.value("ServerIP", AppConfig::ServerIP).toString();
AppConfig::ServerPort = set.value("ServerPort", AppConfig::ServerPort).toInt();
AppConfig::ListenPort = set.value("ListenPort", AppConfig::ListenPort).toInt();
AppConfig::SleepTime = set.value("SleepTime", AppConfig::SleepTime).toInt();
AppConfig::AutoConnect = set.value("AutoConnect", AppConfig::AutoConnect).toBool();
set.endGroup();
}
void AppConfig::writeConfig()
{
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
set.beginGroup("ComConfig");
set.setValue("PortName", AppConfig::PortName);
set.setValue("BaudRate", AppConfig::BaudRate);
set.setValue("DataBit", AppConfig::DataBit);
set.setValue("Parity", AppConfig::Parity);
set.setValue("StopBit", AppConfig::StopBit);
set.setValue("HexSend", AppConfig::HexSend);
set.setValue("HexReceive", AppConfig::HexReceive);
set.setValue("Debug", AppConfig::Debug);
set.setValue("AutoClear", AppConfig::AutoClear);
set.setValue("AutoSend", AppConfig::AutoSend);
set.setValue("SendInterval", AppConfig::SendInterval);
set.setValue("AutoSave", AppConfig::AutoSave);
set.setValue("SaveInterval", AppConfig::SaveInterval);
set.endGroup();
set.beginGroup("NetConfig");
set.setValue("Mode", AppConfig::Mode);
set.setValue("ServerIP", AppConfig::ServerIP);
set.setValue("ServerPort", AppConfig::ServerPort);
set.setValue("ListenPort", AppConfig::ListenPort);
set.setValue("SleepTime", AppConfig::SleepTime);
set.setValue("AutoConnect", AppConfig::AutoConnect);
set.endGroup();
}
QStringList AppConfig::Intervals = QStringList();
QStringList AppConfig::Datas = QStringList();
QStringList AppConfig::Keys = QStringList();
QStringList AppConfig::Values = QStringList();
void AppConfig::readSendData()
{
//读取发送数据列表
AppConfig::Datas.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(AppConfig::SendFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
AppConfig::Datas.append(line);
}
}
file.close();
}
if (AppConfig::Datas.count() == 0) {
AppConfig::Datas << "16 FF 01 01 E0 E1" << "16 FF 01 01 E1 E2";
}
}
void AppConfig::readDeviceData()
{
//读取转发数据列表
AppConfig::Keys.clear();
AppConfig::Values.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(AppConfig::DeviceFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
QStringList list = line.split(";");
QString key = list.at(0);
QString value;
for (int i = 1; i < list.count(); i++) {
value += QString("%1;").arg(list.at(i));
}
//去掉末尾分号
value = value.mid(0, value.length() - 1);
AppConfig::Keys.append(key);
AppConfig::Values.append(value);
}
}
file.close();
}
}

View File

@ -1,9 +1,9 @@
#ifndef APP_H
#define APP_H
#ifndef APPCONFIG_H
#define APPCONFIG_H
#include "head.h"
class App
class AppConfig
{
public:
static QString ConfigFile; //配置文件路径
@ -45,4 +45,4 @@ public:
static void readDeviceData();
};
#endif // APP_H
#endif // APPCONFIG_H

View File

@ -24,8 +24,8 @@ void frmComTool::initForm()
sendCount = 0;
isShow = true;
ui->cboxSendInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxSendInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
//读取数据
timerRead = new QTimer(this);
@ -72,7 +72,7 @@ void frmComTool::initConfig()
comList << "ttymxc1" << "ttymxc2" << "ttymxc3" << "ttymxc4";
comList << "ttySAC1" << "ttySAC2" << "ttySAC3" << "ttySAC4";
ui->cboxPortName->addItems(comList);
ui->cboxPortName->setCurrentIndex(ui->cboxPortName->findText(App::PortName));
ui->cboxPortName->setCurrentIndex(ui->cboxPortName->findText(AppConfig::PortName));
connect(ui->cboxPortName, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
QStringList baudList;
@ -81,14 +81,14 @@ void frmComTool::initConfig()
<< "56000" << "57600" << "76800" << "115200" << "128000" << "256000";
ui->cboxBaudRate->addItems(baudList);
ui->cboxBaudRate->setCurrentIndex(ui->cboxBaudRate->findText(QString::number(App::BaudRate)));
ui->cboxBaudRate->setCurrentIndex(ui->cboxBaudRate->findText(QString::number(AppConfig::BaudRate)));
connect(ui->cboxBaudRate, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
QStringList dataBitsList;
dataBitsList << "5" << "6" << "7" << "8";
ui->cboxDataBit->addItems(dataBitsList);
ui->cboxDataBit->setCurrentIndex(ui->cboxDataBit->findText(QString::number(App::DataBit)));
ui->cboxDataBit->setCurrentIndex(ui->cboxDataBit->findText(QString::number(AppConfig::DataBit)));
connect(ui->cboxDataBit, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
QStringList parityList;
@ -99,7 +99,7 @@ void frmComTool::initConfig()
parityList << "空格";
ui->cboxParity->addItems(parityList);
ui->cboxParity->setCurrentIndex(ui->cboxParity->findText(App::Parity));
ui->cboxParity->setCurrentIndex(ui->cboxParity->findText(AppConfig::Parity));
connect(ui->cboxParity, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
QStringList stopBitsList;
@ -110,25 +110,25 @@ void frmComTool::initConfig()
stopBitsList << "2";
ui->cboxStopBit->addItems(stopBitsList);
ui->cboxStopBit->setCurrentIndex(ui->cboxStopBit->findText(QString::number(App::StopBit)));
ui->cboxStopBit->setCurrentIndex(ui->cboxStopBit->findText(QString::number(AppConfig::StopBit)));
connect(ui->cboxStopBit, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->ckHexSend->setChecked(App::HexSend);
ui->ckHexSend->setChecked(AppConfig::HexSend);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceive);
ui->ckHexReceive->setChecked(AppConfig::HexReceive);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::Debug);
ui->ckDebug->setChecked(AppConfig::Debug);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoClear->setChecked(App::AutoClear);
ui->ckAutoClear->setChecked(AppConfig::AutoClear);
connect(ui->ckAutoClear, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSend);
ui->ckAutoSend->setChecked(AppConfig::AutoSend);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSave->setChecked(App::AutoSave);
ui->ckAutoSave->setChecked(AppConfig::AutoSave);
connect(ui->ckAutoSave, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
QStringList sendInterval;
@ -143,33 +143,33 @@ void frmComTool::initConfig()
ui->cboxSendInterval->addItems(sendInterval);
ui->cboxSaveInterval->addItems(saveInterval);
ui->cboxSendInterval->setCurrentIndex(ui->cboxSendInterval->findText(QString::number(App::SendInterval)));
ui->cboxSendInterval->setCurrentIndex(ui->cboxSendInterval->findText(QString::number(AppConfig::SendInterval)));
connect(ui->cboxSendInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->cboxSaveInterval->setCurrentIndex(ui->cboxSaveInterval->findText(QString::number(App::SaveInterval)));
ui->cboxSaveInterval->setCurrentIndex(ui->cboxSaveInterval->findText(QString::number(AppConfig::SaveInterval)));
connect(ui->cboxSaveInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
timerSend->setInterval(App::SendInterval);
timerSave->setInterval(App::SaveInterval);
timerSend->setInterval(AppConfig::SendInterval);
timerSave->setInterval(AppConfig::SaveInterval);
if (App::AutoSend) {
if (AppConfig::AutoSend) {
timerSend->start();
}
if (App::AutoSave) {
if (AppConfig::AutoSave) {
timerSave->start();
}
//串口转网络部分
ui->cboxMode->setCurrentIndex(ui->cboxMode->findText(App::Mode));
ui->cboxMode->setCurrentIndex(ui->cboxMode->findText(AppConfig::Mode));
connect(ui->cboxMode, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtServerIP->setText(App::ServerIP);
ui->txtServerIP->setText(AppConfig::ServerIP);
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtServerPort->setText(QString::number(App::ServerPort));
ui->txtServerPort->setText(QString::number(AppConfig::ServerPort));
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtListenPort->setText(QString::number(App::ListenPort));
ui->txtListenPort->setText(QString::number(AppConfig::ListenPort));
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
QStringList values;
@ -181,49 +181,49 @@ void frmComTool::initConfig()
ui->cboxSleepTime->addItems(values);
ui->cboxSleepTime->setCurrentIndex(ui->cboxSleepTime->findText(QString::number(App::SleepTime)));
ui->cboxSleepTime->setCurrentIndex(ui->cboxSleepTime->findText(QString::number(AppConfig::SleepTime)));
connect(ui->cboxSleepTime, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoConnect->setChecked(App::AutoConnect);
ui->ckAutoConnect->setChecked(AppConfig::AutoConnect);
connect(ui->ckAutoConnect, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
}
void frmComTool::saveConfig()
{
App::PortName = ui->cboxPortName->currentText();
App::BaudRate = ui->cboxBaudRate->currentText().toInt();
App::DataBit = ui->cboxDataBit->currentText().toInt();
App::Parity = ui->cboxParity->currentText();
App::StopBit = ui->cboxStopBit->currentText().toDouble();
AppConfig::PortName = ui->cboxPortName->currentText();
AppConfig::BaudRate = ui->cboxBaudRate->currentText().toInt();
AppConfig::DataBit = ui->cboxDataBit->currentText().toInt();
AppConfig::Parity = ui->cboxParity->currentText();
AppConfig::StopBit = ui->cboxStopBit->currentText().toDouble();
App::HexSend = ui->ckHexSend->isChecked();
App::HexReceive = ui->ckHexReceive->isChecked();
App::Debug = ui->ckDebug->isChecked();
App::AutoClear = ui->ckAutoClear->isChecked();
AppConfig::HexSend = ui->ckHexSend->isChecked();
AppConfig::HexReceive = ui->ckHexReceive->isChecked();
AppConfig::Debug = ui->ckDebug->isChecked();
AppConfig::AutoClear = ui->ckAutoClear->isChecked();
App::AutoSend = ui->ckAutoSend->isChecked();
App::AutoSave = ui->ckAutoSave->isChecked();
AppConfig::AutoSend = ui->ckAutoSend->isChecked();
AppConfig::AutoSave = ui->ckAutoSave->isChecked();
int sendInterval = ui->cboxSendInterval->currentText().toInt();
if (sendInterval != App::SendInterval) {
App::SendInterval = sendInterval;
timerSend->setInterval(App::SendInterval);
if (sendInterval != AppConfig::SendInterval) {
AppConfig::SendInterval = sendInterval;
timerSend->setInterval(AppConfig::SendInterval);
}
int saveInterval = ui->cboxSaveInterval->currentText().toInt();
if (saveInterval != App::SaveInterval) {
App::SaveInterval = saveInterval;
timerSave->setInterval(App::SaveInterval);
if (saveInterval != AppConfig::SaveInterval) {
AppConfig::SaveInterval = saveInterval;
timerSave->setInterval(AppConfig::SaveInterval);
}
App::Mode = ui->cboxMode->currentText();
App::ServerIP = ui->txtServerIP->text().trimmed();
App::ServerPort = ui->txtServerPort->text().toInt();
App::ListenPort = ui->txtListenPort->text().toInt();
App::SleepTime = ui->cboxSleepTime->currentText().toInt();
App::AutoConnect = ui->ckAutoConnect->isChecked();
AppConfig::Mode = ui->cboxMode->currentText();
AppConfig::ServerIP = ui->txtServerIP->text().trimmed();
AppConfig::ServerPort = ui->txtServerPort->text().toInt();
AppConfig::ListenPort = ui->txtListenPort->text().toInt();
AppConfig::SleepTime = ui->cboxSleepTime->currentText().toInt();
AppConfig::AutoConnect = ui->ckAutoConnect->isChecked();
App::writeConfig();
AppConfig::writeConfig();
}
void frmComTool::changeEnable(bool b)
@ -317,10 +317,10 @@ void frmComTool::readData()
//启用调试则模拟调试数据
if (ui->ckDebug->isChecked()) {
int count = App::Keys.count();
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (buffer.startsWith(App::Keys.at(i))) {
sendData(App::Values.at(i));
if (buffer.startsWith(AppConfig::Keys.at(i))) {
sendData(AppConfig::Values.at(i));
break;
}
}
@ -482,7 +482,7 @@ void frmComTool::on_btnData_clicked()
file.close();
ui->txtMain->clear();
ui->btnData->setText("管理数据");
App::readSendData();
AppConfig::readSendData();
}
}
@ -494,12 +494,12 @@ void frmComTool::on_btnClear_clicked()
void frmComTool::on_btnStart_clicked()
{
if (ui->btnStart->text() == "启动") {
if (App::ServerIP == "" || App::ServerPort == 0) {
if (AppConfig::ServerIP == "" || AppConfig::ServerPort == 0) {
append(6, "IP地址和远程端口不能为空");
return;
}
socket->connectToHost(App::ServerIP, App::ServerPort);
socket->connectToHost(AppConfig::ServerIP, AppConfig::ServerPort);
if (socket->waitForConnected(100)) {
ui->btnStart->setText("停止");
append(6, "连接服务器成功");
@ -539,9 +539,9 @@ void frmComTool::on_ckAutoSave_stateChanged(int arg1)
void frmComTool::connectNet()
{
if (!tcpOk && App::AutoConnect && ui->btnStart->text() == "启动") {
if (App::ServerIP != "" && App::ServerPort != 0) {
socket->connectToHost(App::ServerIP, App::ServerPort);
if (!tcpOk && AppConfig::AutoConnect && ui->btnStart->text() == "启动") {
if (AppConfig::ServerIP != "" && AppConfig::ServerPort != 0) {
socket->connectToHost(AppConfig::ServerIP, AppConfig::ServerPort);
if (socket->waitForConnected(100)) {
ui->btnStart->setText("停止");
append(6, "连接服务器成功");
@ -554,7 +554,7 @@ void frmComTool::connectNet()
void frmComTool::readDataNet()
{
if (socket->bytesAvailable() > 0) {
QUIHelper::sleep(App::SleepTime);
QUIHelper::sleep(AppConfig::SleepTime);
QByteArray data = socket->readAll();
QString buffer;

View File

@ -6,6 +6,6 @@
#include <QtWidgets>
#endif
#include "app.h"
#include "appconfig.h"
#pragma execution_character_set("utf-8")

View File

@ -17,11 +17,11 @@ int main(int argc, char *argv[])
QUIHelper::setTranslator(":/widgets.qm");
QUIHelper::initRand();
App::Intervals << "1" << "10" << "20" << "50" << "100" << "200" << "300" << "500" << "1000" << "1500" << "2000" << "3000" << "5000" << "10000";
App::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
App::readConfig();
App::readSendData();
App::readDeviceData();
AppConfig::Intervals << "1" << "10" << "20" << "50" << "100" << "200" << "300" << "500" << "1000" << "1500" << "2000" << "3000" << "5000" << "10000";
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
AppConfig::readConfig();
AppConfig::readSendData();
AppConfig::readDeviceData();
frmComTool w;
w.setWindowTitle("串口调试助手 V2021 (QQ: 517216493 WX: feiyangqingyun)");

View File

@ -1,11 +1,11 @@
HEADERS += \
$$PWD/app.h \
$$PWD/appconfig.h \
$$PWD/quiwidget.h \
$$PWD/tcpserver1.h \
$$PWD/tcpserver2.h
SOURCES += \
$$PWD/app.cpp \
$$PWD/appconfig.cpp \
$$PWD/quiwidget.cpp \
$$PWD/tcpserver1.cpp \
$$PWD/tcpserver2.cpp

View File

@ -1,50 +0,0 @@
#include "app.h"
#include "quiwidget.h"
QString App::ConfigFile = "config.ini";
int App::ListenPort1 = 6907;
int App::CmdStart1 = 76;
int App::CmdLen1 = 12;
bool App::HexData1 = false;
int App::ListenPort2 = 6908;
int App::CmdStart2 = 76;
int App::CmdLen2 = 12;
bool App::HexData2 = false;
void App::readConfig()
{
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
writeConfig();
return;
}
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
App::ListenPort1 = set.value("ListenPort1").toInt();
App::CmdStart1 = set.value("CmdStart1").toInt();
App::CmdLen1 = set.value("CmdLen1").toInt();
App::HexData1 = set.value("HexData1").toBool();
App::ListenPort2 = set.value("ListenPort2").toInt();
App::CmdStart2 = set.value("CmdStart2").toInt();
App::CmdLen2 = set.value("CmdLen2").toInt();
App::HexData2 = set.value("HexData2").toBool();
set.endGroup();
}
void App::writeConfig()
{
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
set.setValue("ListenPort1", App::ListenPort1);
set.setValue("CmdStart1", App::CmdStart1);
set.setValue("CmdLen1", App::CmdLen1);
set.setValue("HexData1", App::HexData1);
set.setValue("ListenPort2", App::ListenPort2);
set.setValue("CmdStart2", App::CmdStart2);
set.setValue("CmdLen2", App::CmdLen2);
set.setValue("HexData2", App::HexData2);
set.endGroup();
}

View File

@ -0,0 +1,50 @@
#include "appconfig.h"
#include "quiwidget.h"
QString AppConfig::ConfigFile = "config.ini";
int AppConfig::ListenPort1 = 6907;
int AppConfig::CmdStart1 = 76;
int AppConfig::CmdLen1 = 12;
bool AppConfig::HexData1 = false;
int AppConfig::ListenPort2 = 6908;
int AppConfig::CmdStart2 = 76;
int AppConfig::CmdLen2 = 12;
bool AppConfig::HexData2 = false;
void AppConfig::readConfig()
{
if (!QUIHelper::checkIniFile(AppConfig::ConfigFile)) {
writeConfig();
return;
}
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
AppConfig::ListenPort1 = set.value("ListenPort1").toInt();
AppConfig::CmdStart1 = set.value("CmdStart1").toInt();
AppConfig::CmdLen1 = set.value("CmdLen1").toInt();
AppConfig::HexData1 = set.value("HexData1").toBool();
AppConfig::ListenPort2 = set.value("ListenPort2").toInt();
AppConfig::CmdStart2 = set.value("CmdStart2").toInt();
AppConfig::CmdLen2 = set.value("CmdLen2").toInt();
AppConfig::HexData2 = set.value("HexData2").toBool();
set.endGroup();
}
void AppConfig::writeConfig()
{
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
set.setValue("ListenPort1", AppConfig::ListenPort1);
set.setValue("CmdStart1", AppConfig::CmdStart1);
set.setValue("CmdLen1", AppConfig::CmdLen1);
set.setValue("HexData1", AppConfig::HexData1);
set.setValue("ListenPort2", AppConfig::ListenPort2);
set.setValue("CmdStart2", AppConfig::CmdStart2);
set.setValue("CmdLen2", AppConfig::CmdLen2);
set.setValue("HexData2", AppConfig::HexData2);
set.endGroup();
}

View File

@ -1,9 +1,9 @@
#ifndef APP_H
#define APP_H
#ifndef APPCONFIG_H
#define APPCONFIG_H
#include "head.h"
class App
class AppConfig
{
public:
static QString ConfigFile; //配置文件路径
@ -23,4 +23,4 @@ public:
static void writeConfig(); //写入配置参数
};
#endif // APP_H
#endif // APPCONFIG_H

View File

@ -45,7 +45,7 @@ void TcpClient1::readData()
}
//取出唯一标识符,并过滤,可自行更改过滤条件
QByteArray cmd = data.mid(App::CmdStart1, App::CmdLen1);
QByteArray cmd = data.mid(AppConfig::CmdStart1, AppConfig::CmdLen1);
QString id = QString(cmd);
if (id.startsWith("S") && deviceID != id) {
deviceID = id;
@ -54,7 +54,7 @@ void TcpClient1::readData()
}
QString buffer;
if (App::HexData1) {
if (AppConfig::HexData1) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else {
buffer = QString(data);
@ -66,7 +66,7 @@ void TcpClient1::readData()
void TcpClient1::sendData(const QString &data)
{
QByteArray buffer;
if (App::HexData1) {
if (AppConfig::HexData1) {
buffer = QUIHelper::hexStrToByteArray(data);
} else {
buffer = data.toLatin1();
@ -121,9 +121,9 @@ void TcpServer1::disconnected()
bool TcpServer1::start()
{
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
bool ok = listen(QHostAddress::AnyIPv4, App::ListenPort1);
bool ok = listen(QHostAddress::AnyIPv4, AppConfig::ListenPort1);
#else
bool ok = listen(QHostAddress::Any, App::ListenPort1);
bool ok = listen(QHostAddress::Any, AppConfig::ListenPort1);
#endif
return ok;
}

View File

@ -45,7 +45,7 @@ void TcpClient2::readData()
}
//取出唯一标识符,并过滤,可自行更改过滤条件
QByteArray cmd = data.mid(App::CmdStart2, App::CmdLen2);
QByteArray cmd = data.mid(AppConfig::CmdStart2, AppConfig::CmdLen2);
QString id = QString(cmd);
if (id.startsWith("S") && deviceID != id) {
deviceID = id;
@ -54,7 +54,7 @@ void TcpClient2::readData()
}
QString buffer;
if (App::HexData2) {
if (AppConfig::HexData2) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else {
buffer = QString(data);
@ -66,7 +66,7 @@ void TcpClient2::readData()
void TcpClient2::sendData(const QString &data)
{
QByteArray buffer;
if (App::HexData2) {
if (AppConfig::HexData2) {
buffer = QUIHelper::hexStrToByteArray(data);
} else {
buffer = data.toLatin1();
@ -121,9 +121,9 @@ void TcpServer2::disconnected()
bool TcpServer2::start()
{
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
bool ok = listen(QHostAddress::AnyIPv4, App::ListenPort2);
bool ok = listen(QHostAddress::AnyIPv4, AppConfig::ListenPort2);
#else
bool ok = listen(QHostAddress::Any, App::ListenPort2);
bool ok = listen(QHostAddress::Any, AppConfig::ListenPort2);
#endif
return ok;
}

View File

@ -38,18 +38,18 @@ void frmMain::initForm()
void frmMain::initConfig()
{
ui->txtListenPort1->setText(QString::number(App::ListenPort1));
ui->txtListenPort1->setText(QString::number(AppConfig::ListenPort1));
connect(ui->txtListenPort1, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtListenPort2->setText(QString::number(App::ListenPort2));
ui->txtListenPort2->setText(QString::number(AppConfig::ListenPort2));
connect(ui->txtListenPort2, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
}
void frmMain::saveConfig()
{
App::ListenPort1 = ui->txtListenPort1->text().trimmed().toInt();
App::ListenPort2 = ui->txtListenPort2->text().trimmed().toInt();
App::writeConfig();
AppConfig::ListenPort1 = ui->txtListenPort1->text().trimmed().toInt();
AppConfig::ListenPort2 = ui->txtListenPort2->text().trimmed().toInt();
AppConfig::writeConfig();
}
void frmMain::append1(int type, const QString &data, bool clear)

View File

@ -7,4 +7,4 @@
#endif
#pragma execution_character_set("utf-8")
#include "app.h"
#include "appconfig.h"

View File

@ -17,8 +17,8 @@ int main(int argc, char *argv[])
QUIHelper::setTranslator(":/widgets.qm");
QUIHelper::initRand();
App::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
App::readConfig();
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
AppConfig::readConfig();
frmMain w;
w.setWindowTitle(QString("网络中转服务器V2018 本机IP: %1 QQ: 517216493").arg(QUIHelper::getLocalIP()));

View File

@ -1,9 +1,11 @@
HEADERS += $$PWD/app.h
HEADERS += \
$$PWD/appconfig.h
HEADERS += $$PWD/quiwidget.h
HEADERS += $$PWD/tcpclient.h
HEADERS += $$PWD/tcpserver.h
SOURCES += $$PWD/app.cpp
SOURCES += \
$$PWD/appconfig.cpp
SOURCES += $$PWD/quiwidget.cpp
SOURCES += $$PWD/tcpclient.cpp
SOURCES += $$PWD/tcpserver.cpp

View File

@ -1,296 +0,0 @@
#include "app.h"
#include "quiwidget.h"
QString App::ConfigFile = "config.ini";
QString App::SendFileName = "send.txt";
QString App::DeviceFileName = "device.txt";
int App::CurrentIndex = 0;
bool App::HexSendTcpClient = false;
bool App::HexReceiveTcpClient = false;
bool App::AsciiTcpClient = false;
bool App::DebugTcpClient = false;
bool App::AutoSendTcpClient = false;
int App::IntervalTcpClient = 1000;
QString App::TcpServerIP = "127.0.0.1";
int App::TcpServerPort = 6000;
bool App::HexSendTcpServer = false;
bool App::HexReceiveTcpServer = false;
bool App::AsciiTcpServer = false;
bool App::DebugTcpServer = false;
bool App::AutoSendTcpServer = false;
int App::IntervalTcpServer = 1000;
QString App::TcpListenIP = "127.0.0.1";
int App::TcpListenPort = 6000;
bool App::SelectAllTcpServer = true;
bool App::HexSendUdpClient = false;
bool App::HexReceiveUdpClient = false;
bool App::AsciiUdpClient = false;
bool App::DebugUdpClient = false;
bool App::AutoSendUdpClient = false;
int App::IntervalUdpClient = 1000;
QString App::UdpServerIP = "127.0.0.1";
int App::UdpServerPort = 6000;
bool App::HexSendUdpServer = false;
bool App::HexReceiveUdpServer = false;
bool App::AsciiUdpServer = false;
bool App::DebugUdpServer = false;
bool App::AutoSendUdpServer = false;
int App::IntervalUdpServer = 1000;
QString App::UdpListenIP = "127.0.0.1";
int App::UdpListenPort = 6000;
bool App::SelectAllUdpServer = false;
bool App::HexSendWebClient = false;
bool App::HexReceiveWebClient = false;
bool App::AsciiWebClient = true;
bool App::DebugWebClient = false;
bool App::AutoSendWebClient = false;
int App::IntervalWebClient = 1000;
QString App::WebServerIP = "ws://127.0.0.1";
int App::WebServerPort = 6000;
bool App::HexSendWebServer = false;
bool App::HexReceiveWebServer = false;
bool App::AsciiWebServer = true;
bool App::DebugWebServer = false;
bool App::AutoSendWebServer = false;
int App::IntervalWebServer = 1000;
QString App::WebListenIP = "127.0.0.1";
int App::WebListenPort = 6000;
bool App::SelectAllWebServer = true;
void App::readConfig()
{
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
writeConfig();
return;
}
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
App::CurrentIndex = set.value("CurrentIndex").toInt();
set.endGroup();
set.beginGroup("TcpClientConfig");
App::HexSendTcpClient = set.value("HexSendTcpClient", App::HexSendTcpClient).toBool();
App::HexReceiveTcpClient = set.value("HexReceiveTcpClient", App::HexReceiveTcpClient).toBool();
App::AsciiTcpClient = set.value("AsciiTcpClient", App::AsciiTcpClient).toBool();
App::DebugTcpClient = set.value("DebugTcpClient", App::DebugTcpClient).toBool();
App::AutoSendTcpClient = set.value("AutoSendTcpClient", App::AutoSendTcpClient).toBool();
App::IntervalTcpClient = set.value("IntervalTcpClient", App::IntervalTcpClient).toInt();
App::TcpServerIP = set.value("TcpServerIP", App::TcpServerIP).toString();
App::TcpServerPort = set.value("TcpServerPort", App::TcpServerPort).toInt();
set.endGroup();
set.beginGroup("TcpServerConfig");
App::HexSendTcpServer = set.value("HexSendTcpServer", App::HexSendTcpServer).toBool();
App::HexReceiveTcpServer = set.value("HexReceiveTcpServer", App::HexReceiveTcpServer).toBool();
App::AsciiTcpServer = set.value("AsciiTcpServer", App::AsciiTcpServer).toBool();
App::DebugTcpServer = set.value("DebugTcpServer", App::DebugTcpServer).toBool();
App::AutoSendTcpServer = set.value("AutoSendTcpServer", App::AutoSendTcpServer).toBool();
App::IntervalTcpServer = set.value("IntervalTcpServer", App::IntervalTcpServer).toInt();
App::TcpListenIP = set.value("TcpListenIP", App::TcpListenIP).toString();
App::TcpListenPort = set.value("TcpListenPort", App::TcpListenPort).toInt();
App::SelectAllTcpServer = set.value("SelectAllTcpServer", App::SelectAllTcpServer).toBool();
set.endGroup();
set.beginGroup("UdpClientConfig");
App::HexSendUdpClient = set.value("HexSendUdpClient", App::HexSendUdpClient).toBool();
App::HexReceiveUdpClient = set.value("HexReceiveUdpClient", App::HexReceiveUdpClient).toBool();
App::AsciiUdpClient = set.value("AsciiUdpClient", App::AsciiUdpClient).toBool();
App::DebugUdpClient = set.value("DebugUdpClient", App::DebugUdpClient).toBool();
App::AutoSendUdpClient = set.value("AutoSendUdpClient", App::AutoSendUdpClient).toBool();
App::IntervalUdpClient = set.value("IntervalUdpClient", App::IntervalUdpClient).toInt();
App::UdpServerIP = set.value("UdpServerIP", App::UdpServerIP).toString();
App::UdpServerPort = set.value("UdpServerPort", App::UdpServerPort).toInt();
set.endGroup();
set.beginGroup("UdpServerConfig");
App::HexSendUdpServer = set.value("HexSendUdpServer", App::HexSendUdpServer).toBool();
App::HexReceiveUdpServer = set.value("HexReceiveUdpServer", App::HexReceiveUdpServer).toBool();
App::AsciiUdpServer = set.value("AsciiUdpServer", App::AsciiUdpServer).toBool();
App::DebugUdpServer = set.value("DebugUdpServer", App::DebugUdpServer).toBool();
App::AutoSendUdpServer = set.value("AutoSendUdpServer", App::AutoSendUdpServer).toBool();
App::IntervalUdpServer = set.value("IntervalUdpServer", App::IntervalUdpServer).toInt();
App::UdpListenIP = set.value("UdpListenIP", App::UdpListenIP).toString();
App::UdpListenPort = set.value("UdpListenPort", App::UdpListenPort).toInt();
App::SelectAllUdpServer = set.value("SelectAllUdpServer", App::SelectAllUdpServer).toBool();
set.endGroup();
set.beginGroup("WebClientConfig");
App::HexSendWebClient = set.value("HexSendWebClient", App::HexSendWebClient).toBool();
App::HexReceiveWebClient = set.value("HexReceiveWebClient", App::HexReceiveWebClient).toBool();
App::AsciiWebClient = set.value("AsciiWebClient", App::AsciiWebClient).toBool();
App::DebugWebClient = set.value("DebugWebClient", App::DebugWebClient).toBool();
App::AutoSendWebClient = set.value("AutoSendWebClient", App::AutoSendWebClient).toBool();
App::IntervalWebClient = set.value("IntervalWebClient", App::IntervalWebClient).toInt();
App::WebServerIP = set.value("WebServerIP", App::WebServerIP).toString();
App::WebServerPort = set.value("WebServerPort", App::WebServerPort).toInt();
set.endGroup();
set.beginGroup("WebServerConfig");
App::HexSendWebServer = set.value("HexSendWebServer", App::HexSendWebServer).toBool();
App::HexReceiveWebServer = set.value("HexReceiveWebServer", App::HexReceiveWebServer).toBool();
App::AsciiWebServer = set.value("AsciiWebServer", App::AsciiWebServer).toBool();
App::DebugWebServer = set.value("DebugWebServer", App::DebugWebServer).toBool();
App::AutoSendWebServer = set.value("AutoSendWebServer", App::AutoSendWebServer).toBool();
App::IntervalWebServer = set.value("IntervalWebServer", App::IntervalWebServer).toInt();
App::WebListenIP = set.value("WebListenIP", App::WebListenIP).toString();
App::WebListenPort = set.value("WebListenPort", App::WebListenPort).toInt();
App::SelectAllWebServer = set.value("SelectAllWebServer", App::SelectAllWebServer).toBool();
set.endGroup();
}
void App::writeConfig()
{
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
set.setValue("CurrentIndex", App::CurrentIndex);
set.endGroup();
set.beginGroup("TcpClientConfig");
set.setValue("HexSendTcpClient", App::HexSendTcpClient);
set.setValue("HexReceiveTcpClient", App::HexReceiveTcpClient);
set.setValue("DebugTcpClient", App::DebugTcpClient);
set.setValue("AutoSendTcpClient", App::AutoSendTcpClient);
set.setValue("IntervalTcpClient", App::IntervalTcpClient);
set.setValue("TcpServerIP", App::TcpServerIP);
set.setValue("TcpServerPort", App::TcpServerPort);
set.endGroup();
set.beginGroup("TcpServerConfig");
set.setValue("HexSendTcpServer", App::HexSendTcpServer);
set.setValue("HexReceiveTcpServer", App::HexReceiveTcpServer);
set.setValue("DebugTcpServer", App::DebugTcpServer);
set.setValue("AutoSendTcpServer", App::AutoSendTcpServer);
set.setValue("IntervalTcpServer", App::IntervalTcpServer);
set.setValue("TcpListenIP", App::TcpListenIP);
set.setValue("TcpListenPort", App::TcpListenPort);
set.setValue("SelectAllTcpServer", App::SelectAllTcpServer);
set.endGroup();
set.beginGroup("UdpClientConfig");
set.setValue("HexSendUdpClient", App::HexSendUdpClient);
set.setValue("HexReceiveUdpClient", App::HexReceiveUdpClient);
set.setValue("DebugUdpClient", App::DebugUdpClient);
set.setValue("AutoSendUdpClient", App::AutoSendUdpClient);
set.setValue("IntervalUdpClient", App::IntervalUdpClient);
set.setValue("UdpServerIP", App::UdpServerIP);
set.setValue("UdpServerPort", App::UdpServerPort);
set.endGroup();
set.beginGroup("UdpServerConfig");
set.setValue("HexSendUdpServer", App::HexSendUdpServer);
set.setValue("HexReceiveUdpServer", App::HexReceiveUdpServer);
set.setValue("DebugUdpServer", App::DebugUdpServer);
set.setValue("AutoSendUdpServer", App::AutoSendUdpServer);
set.setValue("IntervalUdpServer", App::IntervalUdpServer);
set.setValue("UdpListenIP", App::UdpListenIP);
set.setValue("UdpListenPort", App::UdpListenPort);
set.setValue("SelectAllUdpServer", App::SelectAllUdpServer);
set.endGroup();
set.beginGroup("WebClientConfig");
set.setValue("HexSendWebClient", App::HexSendWebClient);
set.setValue("HexReceiveWebClient", App::HexReceiveWebClient);
set.setValue("DebugWebClient", App::DebugWebClient);
set.setValue("AutoSendWebClient", App::AutoSendWebClient);
set.setValue("IntervalWebClient", App::IntervalWebClient);
set.setValue("WebServerIP", App::WebServerIP);
set.setValue("WebServerPort", App::WebServerPort);
set.endGroup();
set.beginGroup("WebServerConfig");
set.setValue("HexSendWebServer", App::HexSendWebServer);
set.setValue("HexReceiveWebServer", App::HexReceiveWebServer);
set.setValue("DebugWebServer", App::DebugWebServer);
set.setValue("AutoSendWebServer", App::AutoSendWebServer);
set.setValue("IntervalWebServer", App::IntervalWebServer);
set.setValue("WebListenIP", App::WebListenIP);
set.setValue("WebListenPort", App::WebListenPort);
set.setValue("SelectAllWebServer", App::SelectAllWebServer);
set.endGroup();
}
QStringList App::Intervals = QStringList();
QStringList App::Datas = QStringList();
QStringList App::Keys = QStringList();
QStringList App::Values = QStringList();
void App::readSendData()
{
//读取发送数据列表
App::Datas.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::SendFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
App::Datas.append(line);
}
}
file.close();
}
if (App::Datas.count() == 0) {
App::Datas << "16 FF 01 01 E0 E1" << "16 FF 01 01 E1 E2";
}
}
void App::readDeviceData()
{
//读取转发数据列表
App::Keys.clear();
App::Values.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::DeviceFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
QStringList list = line.split(";");
QString key = list.at(0);
QString value;
for (int i = 1; i < list.count(); i++) {
value += QString("%1;").arg(list.at(i));
}
//去掉末尾分号
value = value.mid(0, value.length() - 1);
App::Keys.append(key);
App::Values.append(value);
}
}
file.close();
}
}
void App::saveData(const QString &data)
{
if (data.length() <= 0) {
return;
}
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(STRDATETIME);
QFile file(fileName);
if (file.open(QFile::WriteOnly | QFile::Text)) {
file.write(data.toUtf8());
file.close();
}
}

296
nettool/api/appconfig.cpp Normal file
View File

@ -0,0 +1,296 @@
#include "appconfig.h"
#include "quiwidget.h"
QString AppConfig::ConfigFile = "config.ini";
QString AppConfig::SendFileName = "send.txt";
QString AppConfig::DeviceFileName = "device.txt";
int AppConfig::CurrentIndex = 0;
bool AppConfig::HexSendTcpClient = false;
bool AppConfig::HexReceiveTcpClient = false;
bool AppConfig::AsciiTcpClient = false;
bool AppConfig::DebugTcpClient = false;
bool AppConfig::AutoSendTcpClient = false;
int AppConfig::IntervalTcpClient = 1000;
QString AppConfig::TcpServerIP = "127.0.0.1";
int AppConfig::TcpServerPort = 6000;
bool AppConfig::HexSendTcpServer = false;
bool AppConfig::HexReceiveTcpServer = false;
bool AppConfig::AsciiTcpServer = false;
bool AppConfig::DebugTcpServer = false;
bool AppConfig::AutoSendTcpServer = false;
int AppConfig::IntervalTcpServer = 1000;
QString AppConfig::TcpListenIP = "127.0.0.1";
int AppConfig::TcpListenPort = 6000;
bool AppConfig::SelectAllTcpServer = true;
bool AppConfig::HexSendUdpClient = false;
bool AppConfig::HexReceiveUdpClient = false;
bool AppConfig::AsciiUdpClient = false;
bool AppConfig::DebugUdpClient = false;
bool AppConfig::AutoSendUdpClient = false;
int AppConfig::IntervalUdpClient = 1000;
QString AppConfig::UdpServerIP = "127.0.0.1";
int AppConfig::UdpServerPort = 6000;
bool AppConfig::HexSendUdpServer = false;
bool AppConfig::HexReceiveUdpServer = false;
bool AppConfig::AsciiUdpServer = false;
bool AppConfig::DebugUdpServer = false;
bool AppConfig::AutoSendUdpServer = false;
int AppConfig::IntervalUdpServer = 1000;
QString AppConfig::UdpListenIP = "127.0.0.1";
int AppConfig::UdpListenPort = 6000;
bool AppConfig::SelectAllUdpServer = false;
bool AppConfig::HexSendWebClient = false;
bool AppConfig::HexReceiveWebClient = false;
bool AppConfig::AsciiWebClient = true;
bool AppConfig::DebugWebClient = false;
bool AppConfig::AutoSendWebClient = false;
int AppConfig::IntervalWebClient = 1000;
QString AppConfig::WebServerIP = "ws://127.0.0.1";
int AppConfig::WebServerPort = 6000;
bool AppConfig::HexSendWebServer = false;
bool AppConfig::HexReceiveWebServer = false;
bool AppConfig::AsciiWebServer = true;
bool AppConfig::DebugWebServer = false;
bool AppConfig::AutoSendWebServer = false;
int AppConfig::IntervalWebServer = 1000;
QString AppConfig::WebListenIP = "127.0.0.1";
int AppConfig::WebListenPort = 6000;
bool AppConfig::SelectAllWebServer = true;
void AppConfig::readConfig()
{
if (!QUIHelper::checkIniFile(AppConfig::ConfigFile)) {
writeConfig();
return;
}
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
AppConfig::CurrentIndex = set.value("CurrentIndex").toInt();
set.endGroup();
set.beginGroup("TcpClientConfig");
AppConfig::HexSendTcpClient = set.value("HexSendTcpClient", AppConfig::HexSendTcpClient).toBool();
AppConfig::HexReceiveTcpClient = set.value("HexReceiveTcpClient", AppConfig::HexReceiveTcpClient).toBool();
AppConfig::AsciiTcpClient = set.value("AsciiTcpClient", AppConfig::AsciiTcpClient).toBool();
AppConfig::DebugTcpClient = set.value("DebugTcpClient", AppConfig::DebugTcpClient).toBool();
AppConfig::AutoSendTcpClient = set.value("AutoSendTcpClient", AppConfig::AutoSendTcpClient).toBool();
AppConfig::IntervalTcpClient = set.value("IntervalTcpClient", AppConfig::IntervalTcpClient).toInt();
AppConfig::TcpServerIP = set.value("TcpServerIP", AppConfig::TcpServerIP).toString();
AppConfig::TcpServerPort = set.value("TcpServerPort", AppConfig::TcpServerPort).toInt();
set.endGroup();
set.beginGroup("TcpServerConfig");
AppConfig::HexSendTcpServer = set.value("HexSendTcpServer", AppConfig::HexSendTcpServer).toBool();
AppConfig::HexReceiveTcpServer = set.value("HexReceiveTcpServer", AppConfig::HexReceiveTcpServer).toBool();
AppConfig::AsciiTcpServer = set.value("AsciiTcpServer", AppConfig::AsciiTcpServer).toBool();
AppConfig::DebugTcpServer = set.value("DebugTcpServer", AppConfig::DebugTcpServer).toBool();
AppConfig::AutoSendTcpServer = set.value("AutoSendTcpServer", AppConfig::AutoSendTcpServer).toBool();
AppConfig::IntervalTcpServer = set.value("IntervalTcpServer", AppConfig::IntervalTcpServer).toInt();
AppConfig::TcpListenIP = set.value("TcpListenIP", AppConfig::TcpListenIP).toString();
AppConfig::TcpListenPort = set.value("TcpListenPort", AppConfig::TcpListenPort).toInt();
AppConfig::SelectAllTcpServer = set.value("SelectAllTcpServer", AppConfig::SelectAllTcpServer).toBool();
set.endGroup();
set.beginGroup("UdpClientConfig");
AppConfig::HexSendUdpClient = set.value("HexSendUdpClient", AppConfig::HexSendUdpClient).toBool();
AppConfig::HexReceiveUdpClient = set.value("HexReceiveUdpClient", AppConfig::HexReceiveUdpClient).toBool();
AppConfig::AsciiUdpClient = set.value("AsciiUdpClient", AppConfig::AsciiUdpClient).toBool();
AppConfig::DebugUdpClient = set.value("DebugUdpClient", AppConfig::DebugUdpClient).toBool();
AppConfig::AutoSendUdpClient = set.value("AutoSendUdpClient", AppConfig::AutoSendUdpClient).toBool();
AppConfig::IntervalUdpClient = set.value("IntervalUdpClient", AppConfig::IntervalUdpClient).toInt();
AppConfig::UdpServerIP = set.value("UdpServerIP", AppConfig::UdpServerIP).toString();
AppConfig::UdpServerPort = set.value("UdpServerPort", AppConfig::UdpServerPort).toInt();
set.endGroup();
set.beginGroup("UdpServerConfig");
AppConfig::HexSendUdpServer = set.value("HexSendUdpServer", AppConfig::HexSendUdpServer).toBool();
AppConfig::HexReceiveUdpServer = set.value("HexReceiveUdpServer", AppConfig::HexReceiveUdpServer).toBool();
AppConfig::AsciiUdpServer = set.value("AsciiUdpServer", AppConfig::AsciiUdpServer).toBool();
AppConfig::DebugUdpServer = set.value("DebugUdpServer", AppConfig::DebugUdpServer).toBool();
AppConfig::AutoSendUdpServer = set.value("AutoSendUdpServer", AppConfig::AutoSendUdpServer).toBool();
AppConfig::IntervalUdpServer = set.value("IntervalUdpServer", AppConfig::IntervalUdpServer).toInt();
AppConfig::UdpListenIP = set.value("UdpListenIP", AppConfig::UdpListenIP).toString();
AppConfig::UdpListenPort = set.value("UdpListenPort", AppConfig::UdpListenPort).toInt();
AppConfig::SelectAllUdpServer = set.value("SelectAllUdpServer", AppConfig::SelectAllUdpServer).toBool();
set.endGroup();
set.beginGroup("WebClientConfig");
AppConfig::HexSendWebClient = set.value("HexSendWebClient", AppConfig::HexSendWebClient).toBool();
AppConfig::HexReceiveWebClient = set.value("HexReceiveWebClient", AppConfig::HexReceiveWebClient).toBool();
AppConfig::AsciiWebClient = set.value("AsciiWebClient", AppConfig::AsciiWebClient).toBool();
AppConfig::DebugWebClient = set.value("DebugWebClient", AppConfig::DebugWebClient).toBool();
AppConfig::AutoSendWebClient = set.value("AutoSendWebClient", AppConfig::AutoSendWebClient).toBool();
AppConfig::IntervalWebClient = set.value("IntervalWebClient", AppConfig::IntervalWebClient).toInt();
AppConfig::WebServerIP = set.value("WebServerIP", AppConfig::WebServerIP).toString();
AppConfig::WebServerPort = set.value("WebServerPort", AppConfig::WebServerPort).toInt();
set.endGroup();
set.beginGroup("WebServerConfig");
AppConfig::HexSendWebServer = set.value("HexSendWebServer", AppConfig::HexSendWebServer).toBool();
AppConfig::HexReceiveWebServer = set.value("HexReceiveWebServer", AppConfig::HexReceiveWebServer).toBool();
AppConfig::AsciiWebServer = set.value("AsciiWebServer", AppConfig::AsciiWebServer).toBool();
AppConfig::DebugWebServer = set.value("DebugWebServer", AppConfig::DebugWebServer).toBool();
AppConfig::AutoSendWebServer = set.value("AutoSendWebServer", AppConfig::AutoSendWebServer).toBool();
AppConfig::IntervalWebServer = set.value("IntervalWebServer", AppConfig::IntervalWebServer).toInt();
AppConfig::WebListenIP = set.value("WebListenIP", AppConfig::WebListenIP).toString();
AppConfig::WebListenPort = set.value("WebListenPort", AppConfig::WebListenPort).toInt();
AppConfig::SelectAllWebServer = set.value("SelectAllWebServer", AppConfig::SelectAllWebServer).toBool();
set.endGroup();
}
void AppConfig::writeConfig()
{
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
set.beginGroup("AppConfig");
set.setValue("CurrentIndex", AppConfig::CurrentIndex);
set.endGroup();
set.beginGroup("TcpClientConfig");
set.setValue("HexSendTcpClient", AppConfig::HexSendTcpClient);
set.setValue("HexReceiveTcpClient", AppConfig::HexReceiveTcpClient);
set.setValue("DebugTcpClient", AppConfig::DebugTcpClient);
set.setValue("AutoSendTcpClient", AppConfig::AutoSendTcpClient);
set.setValue("IntervalTcpClient", AppConfig::IntervalTcpClient);
set.setValue("TcpServerIP", AppConfig::TcpServerIP);
set.setValue("TcpServerPort", AppConfig::TcpServerPort);
set.endGroup();
set.beginGroup("TcpServerConfig");
set.setValue("HexSendTcpServer", AppConfig::HexSendTcpServer);
set.setValue("HexReceiveTcpServer", AppConfig::HexReceiveTcpServer);
set.setValue("DebugTcpServer", AppConfig::DebugTcpServer);
set.setValue("AutoSendTcpServer", AppConfig::AutoSendTcpServer);
set.setValue("IntervalTcpServer", AppConfig::IntervalTcpServer);
set.setValue("TcpListenIP", AppConfig::TcpListenIP);
set.setValue("TcpListenPort", AppConfig::TcpListenPort);
set.setValue("SelectAllTcpServer", AppConfig::SelectAllTcpServer);
set.endGroup();
set.beginGroup("UdpClientConfig");
set.setValue("HexSendUdpClient", AppConfig::HexSendUdpClient);
set.setValue("HexReceiveUdpClient", AppConfig::HexReceiveUdpClient);
set.setValue("DebugUdpClient", AppConfig::DebugUdpClient);
set.setValue("AutoSendUdpClient", AppConfig::AutoSendUdpClient);
set.setValue("IntervalUdpClient", AppConfig::IntervalUdpClient);
set.setValue("UdpServerIP", AppConfig::UdpServerIP);
set.setValue("UdpServerPort", AppConfig::UdpServerPort);
set.endGroup();
set.beginGroup("UdpServerConfig");
set.setValue("HexSendUdpServer", AppConfig::HexSendUdpServer);
set.setValue("HexReceiveUdpServer", AppConfig::HexReceiveUdpServer);
set.setValue("DebugUdpServer", AppConfig::DebugUdpServer);
set.setValue("AutoSendUdpServer", AppConfig::AutoSendUdpServer);
set.setValue("IntervalUdpServer", AppConfig::IntervalUdpServer);
set.setValue("UdpListenIP", AppConfig::UdpListenIP);
set.setValue("UdpListenPort", AppConfig::UdpListenPort);
set.setValue("SelectAllUdpServer", AppConfig::SelectAllUdpServer);
set.endGroup();
set.beginGroup("WebClientConfig");
set.setValue("HexSendWebClient", AppConfig::HexSendWebClient);
set.setValue("HexReceiveWebClient", AppConfig::HexReceiveWebClient);
set.setValue("DebugWebClient", AppConfig::DebugWebClient);
set.setValue("AutoSendWebClient", AppConfig::AutoSendWebClient);
set.setValue("IntervalWebClient", AppConfig::IntervalWebClient);
set.setValue("WebServerIP", AppConfig::WebServerIP);
set.setValue("WebServerPort", AppConfig::WebServerPort);
set.endGroup();
set.beginGroup("WebServerConfig");
set.setValue("HexSendWebServer", AppConfig::HexSendWebServer);
set.setValue("HexReceiveWebServer", AppConfig::HexReceiveWebServer);
set.setValue("DebugWebServer", AppConfig::DebugWebServer);
set.setValue("AutoSendWebServer", AppConfig::AutoSendWebServer);
set.setValue("IntervalWebServer", AppConfig::IntervalWebServer);
set.setValue("WebListenIP", AppConfig::WebListenIP);
set.setValue("WebListenPort", AppConfig::WebListenPort);
set.setValue("SelectAllWebServer", AppConfig::SelectAllWebServer);
set.endGroup();
}
QStringList AppConfig::Intervals = QStringList();
QStringList AppConfig::Datas = QStringList();
QStringList AppConfig::Keys = QStringList();
QStringList AppConfig::Values = QStringList();
void AppConfig::readSendData()
{
//读取发送数据列表
AppConfig::Datas.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(AppConfig::SendFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
AppConfig::Datas.append(line);
}
}
file.close();
}
if (AppConfig::Datas.count() == 0) {
AppConfig::Datas << "16 FF 01 01 E0 E1" << "16 FF 01 01 E1 E2";
}
}
void AppConfig::readDeviceData()
{
//读取转发数据列表
AppConfig::Keys.clear();
AppConfig::Values.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(AppConfig::DeviceFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
QStringList list = line.split(";");
QString key = list.at(0);
QString value;
for (int i = 1; i < list.count(); i++) {
value += QString("%1;").arg(list.at(i));
}
//去掉末尾分号
value = value.mid(0, value.length() - 1);
AppConfig::Keys.append(key);
AppConfig::Values.append(value);
}
}
file.close();
}
}
void AppConfig::saveData(const QString &data)
{
if (data.length() <= 0) {
return;
}
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(STRDATETIME);
QFile file(fileName);
if (file.open(QFile::WriteOnly | QFile::Text)) {
file.write(data.toUtf8());
file.close();
}
}

View File

@ -1,9 +1,9 @@
#ifndef APP_H
#define APP_H
#ifndef APPCONFIG_H
#define APPCONFIG_H
#include "head.h"
class App
class AppConfig
{
public:
static QString ConfigFile; //配置文件路径
@ -88,4 +88,4 @@ public:
static void saveData(const QString &data);
};
#endif // APP_H
#endif // APPCONFIG_H

View File

@ -38,9 +38,9 @@ void TcpClient::readData()
}
QString buffer;
if (App::HexReceiveTcpServer) {
if (AppConfig::HexReceiveTcpServer) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else if (App::AsciiTcpServer) {
} else if (AppConfig::AsciiTcpServer) {
buffer = QUIHelper::byteArrayToAsciiStr(data);
} else {
buffer = QString(data);
@ -49,11 +49,11 @@ void TcpClient::readData()
emit receiveData(ip, port, buffer);
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
if (App::DebugTcpServer) {
int count = App::Keys.count();
if (AppConfig::DebugTcpServer) {
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (App::Keys.at(i) == buffer) {
sendData(App::Values.at(i));
if (AppConfig::Keys.at(i) == buffer) {
sendData(AppConfig::Values.at(i));
break;
}
}
@ -63,9 +63,9 @@ void TcpClient::readData()
void TcpClient::sendData(const QString &data)
{
QByteArray buffer;
if (App::HexSendTcpServer) {
if (AppConfig::HexSendTcpServer) {
buffer = QUIHelper::hexStrToByteArray(data);
} else if (App::AsciiTcpServer) {
} else if (AppConfig::AsciiTcpServer) {
buffer = QUIHelper::asciiStrToByteArray(data);
} else {
buffer = data.toUtf8();

View File

@ -37,7 +37,7 @@ void TcpServer::disconnected()
bool TcpServer::start()
{
bool ok = listen(QHostAddress(App::TcpListenIP), App::TcpListenPort);
bool ok = listen(QHostAddress(AppConfig::TcpListenIP), AppConfig::TcpListenPort);
return ok;
}

View File

@ -42,11 +42,11 @@ void WebClient::textFrameReceived(const QString &data, bool isLastFrame)
emit receiveData(ip, port, buffer);
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
if (App::DebugWebServer) {
int count = App::Keys.count();
if (AppConfig::DebugWebServer) {
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (App::Keys.at(i) == buffer) {
sendData(App::Values.at(i));
if (AppConfig::Keys.at(i) == buffer) {
sendData(AppConfig::Values.at(i));
break;
}
}
@ -56,7 +56,7 @@ void WebClient::textFrameReceived(const QString &data, bool isLastFrame)
void WebClient::binaryFrameReceived(const QByteArray &data, bool isLastFrame)
{
QString buffer;
if (App::HexReceiveWebClient) {
if (AppConfig::HexReceiveWebClient) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else {
buffer = QString(data);
@ -78,13 +78,13 @@ void WebClient::binaryMessageReceived(const QByteArray &data)
void WebClient::sendData(const QString &data)
{
QByteArray buffer;
if (App::HexSendWebServer) {
if (AppConfig::HexSendWebServer) {
buffer = QUIHelper::hexStrToByteArray(data);
} else {
buffer = data.toUtf8();
}
if (App::AsciiWebServer) {
if (AppConfig::AsciiWebServer) {
socket->sendTextMessage(data);
} else {
socket->sendBinaryMessage(buffer);

View File

@ -37,7 +37,7 @@ void WebServer::disconnected()
bool WebServer::start()
{
bool ok = listen(QHostAddress(App::WebListenIP), App::WebListenPort);
bool ok = listen(QHostAddress(AppConfig::WebListenIP), AppConfig::WebListenPort);
return ok;
}

View File

@ -34,18 +34,18 @@ void frmMain::initForm()
ui->tabWidget->addTab(new frmWebServer, "WEB服务端");
#endif
#ifdef emsdk
App::CurrentIndex = 4;
AppConfig::CurrentIndex = 4;
#endif
}
void frmMain::initConfig()
{
ui->tabWidget->setCurrentIndex(App::CurrentIndex);
ui->tabWidget->setCurrentIndex(AppConfig::CurrentIndex);
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(saveConfig()));
}
void frmMain::saveConfig()
{
App::CurrentIndex = ui->tabWidget->currentIndex();
App::writeConfig();
AppConfig::CurrentIndex = ui->tabWidget->currentIndex();
AppConfig::writeConfig();
}

View File

@ -26,8 +26,8 @@ void frmTcpClient::initForm()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
ui->cboxInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
#ifndef emsdk
QString ip = QUIHelper::getNetIP(QUIHelper::getHtml("http://whois.pconline.com.cn/"));
@ -37,28 +37,28 @@ void frmTcpClient::initForm()
void frmTcpClient::initConfig()
{
ui->ckHexSend->setChecked(App::HexSendTcpClient);
ui->ckHexSend->setChecked(AppConfig::HexSendTcpClient);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceiveTcpClient);
ui->ckHexReceive->setChecked(AppConfig::HexReceiveTcpClient);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAscii->setChecked(App::AsciiTcpClient);
ui->ckAscii->setChecked(AppConfig::AsciiTcpClient);
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::DebugTcpClient);
ui->ckDebug->setChecked(AppConfig::DebugTcpClient);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSendTcpClient);
ui->ckAutoSend->setChecked(AppConfig::AutoSendTcpClient);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalTcpClient)));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalTcpClient)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtServerIP->setText(App::TcpServerIP);
ui->txtServerIP->setText(AppConfig::TcpServerIP);
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtServerPort->setText(QString::number(App::TcpServerPort));
ui->txtServerPort->setText(QString::number(AppConfig::TcpServerPort));
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
this->changeTimer();
@ -66,23 +66,23 @@ void frmTcpClient::initConfig()
void frmTcpClient::saveConfig()
{
App::HexSendTcpClient = ui->ckHexSend->isChecked();
App::HexReceiveTcpClient = ui->ckHexReceive->isChecked();
App::AsciiTcpClient = ui->ckAscii->isChecked();
App::DebugTcpClient = ui->ckDebug->isChecked();
App::AutoSendTcpClient = ui->ckAutoSend->isChecked();
App::IntervalTcpClient = ui->cboxInterval->currentText().toInt();
App::TcpServerIP = ui->txtServerIP->text().trimmed();
App::TcpServerPort = ui->txtServerPort->text().trimmed().toInt();
App::writeConfig();
AppConfig::HexSendTcpClient = ui->ckHexSend->isChecked();
AppConfig::HexReceiveTcpClient = ui->ckHexReceive->isChecked();
AppConfig::AsciiTcpClient = ui->ckAscii->isChecked();
AppConfig::DebugTcpClient = ui->ckDebug->isChecked();
AppConfig::AutoSendTcpClient = ui->ckAutoSend->isChecked();
AppConfig::IntervalTcpClient = ui->cboxInterval->currentText().toInt();
AppConfig::TcpServerIP = ui->txtServerIP->text().trimmed();
AppConfig::TcpServerPort = ui->txtServerPort->text().trimmed().toInt();
AppConfig::writeConfig();
this->changeTimer();
}
void frmTcpClient::changeTimer()
{
timer->setInterval(App::IntervalTcpClient);
if (App::AutoSendTcpClient) {
timer->setInterval(AppConfig::IntervalTcpClient);
if (AppConfig::AutoSendTcpClient) {
if (!timer->isActive()) {
timer->start();
}
@ -156,9 +156,9 @@ void frmTcpClient::readData()
}
QString buffer;
if (App::HexReceiveTcpClient) {
if (AppConfig::HexReceiveTcpClient) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else if (App::AsciiTcpClient) {
} else if (AppConfig::AsciiTcpClient) {
buffer = QUIHelper::byteArrayToAsciiStr(data);
} else {
buffer = QString(data);
@ -167,11 +167,11 @@ void frmTcpClient::readData()
append(1, buffer);
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
if (App::DebugTcpClient) {
int count = App::Keys.count();
if (AppConfig::DebugTcpClient) {
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (App::Keys.at(i) == buffer) {
sendData(App::Values.at(i));
if (AppConfig::Keys.at(i) == buffer) {
sendData(AppConfig::Values.at(i));
break;
}
}
@ -181,9 +181,9 @@ void frmTcpClient::readData()
void frmTcpClient::sendData(const QString &data)
{
QByteArray buffer;
if (App::HexSendTcpClient) {
if (AppConfig::HexSendTcpClient) {
buffer = QUIHelper::hexStrToByteArray(data);
} else if (App::AsciiTcpClient) {
} else if (AppConfig::AsciiTcpClient) {
buffer = QUIHelper::asciiStrToByteArray(data);
} else {
buffer = data.toUtf8();
@ -197,7 +197,7 @@ void frmTcpClient::on_btnConnect_clicked()
{
if (ui->btnConnect->text() == "连接") {
socket->abort();
socket->connectToHost(App::TcpServerIP, App::TcpServerPort);
socket->connectToHost(AppConfig::TcpServerIP, AppConfig::TcpServerPort);
} else {
socket->abort();
}
@ -206,7 +206,7 @@ void frmTcpClient::on_btnConnect_clicked()
void frmTcpClient::on_btnSave_clicked()
{
QString data = ui->txtMain->toPlainText();
App::saveData(data);
AppConfig::saveData(data);
on_btnClear_clicked();
}

View File

@ -26,8 +26,8 @@ void frmTcpServer::initForm()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
ui->cboxInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
//获取本机所有IP
QStringList ips = QUIHelper::getLocalIPs();
@ -39,31 +39,31 @@ void frmTcpServer::initForm()
void frmTcpServer::initConfig()
{
ui->ckHexSend->setChecked(App::HexSendTcpServer);
ui->ckHexSend->setChecked(AppConfig::HexSendTcpServer);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceiveTcpServer);
ui->ckHexReceive->setChecked(AppConfig::HexReceiveTcpServer);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAscii->setChecked(App::AsciiTcpServer);
ui->ckAscii->setChecked(AppConfig::AsciiTcpServer);
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::DebugTcpServer);
ui->ckDebug->setChecked(AppConfig::DebugTcpServer);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSendTcpServer);
ui->ckAutoSend->setChecked(AppConfig::AutoSendTcpServer);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalTcpServer)));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalTcpServer)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->cboxListenIP->setCurrentIndex(ui->cboxListenIP->findText(App::TcpListenIP));
ui->cboxListenIP->setCurrentIndex(ui->cboxListenIP->findText(AppConfig::TcpListenIP));
connect(ui->cboxListenIP, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtListenPort->setText(QString::number(App::TcpListenPort));
ui->txtListenPort->setText(QString::number(AppConfig::TcpListenPort));
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->ckSelectAll->setChecked(App::SelectAllTcpServer);
ui->ckSelectAll->setChecked(AppConfig::SelectAllTcpServer);
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
this->changeTimer();
@ -71,24 +71,24 @@ void frmTcpServer::initConfig()
void frmTcpServer::saveConfig()
{
App::HexSendTcpServer = ui->ckHexSend->isChecked();
App::HexReceiveTcpServer = ui->ckHexReceive->isChecked();
App::AsciiTcpServer = ui->ckAscii->isChecked();
App::DebugTcpServer = ui->ckDebug->isChecked();
App::AutoSendTcpServer = ui->ckAutoSend->isChecked();
App::IntervalTcpServer = ui->cboxInterval->currentText().toInt();
App::TcpListenIP = ui->cboxListenIP->currentText();
App::TcpListenPort = ui->txtListenPort->text().trimmed().toInt();
App::SelectAllTcpServer = ui->ckSelectAll->isChecked();
App::writeConfig();
AppConfig::HexSendTcpServer = ui->ckHexSend->isChecked();
AppConfig::HexReceiveTcpServer = ui->ckHexReceive->isChecked();
AppConfig::AsciiTcpServer = ui->ckAscii->isChecked();
AppConfig::DebugTcpServer = ui->ckDebug->isChecked();
AppConfig::AutoSendTcpServer = ui->ckAutoSend->isChecked();
AppConfig::IntervalTcpServer = ui->cboxInterval->currentText().toInt();
AppConfig::TcpListenIP = ui->cboxListenIP->currentText();
AppConfig::TcpListenPort = ui->txtListenPort->text().trimmed().toInt();
AppConfig::SelectAllTcpServer = ui->ckSelectAll->isChecked();
AppConfig::writeConfig();
this->changeTimer();
}
void frmTcpServer::changeTimer()
{
timer->setInterval(App::IntervalTcpServer);
if (App::AutoSendTcpServer) {
timer->setInterval(AppConfig::IntervalTcpServer);
if (AppConfig::AutoSendTcpServer) {
if (!timer->isActive()) {
timer->start();
}
@ -192,7 +192,7 @@ void frmTcpServer::on_btnListen_clicked()
void frmTcpServer::on_btnSave_clicked()
{
QString data = ui->txtMain->toPlainText();
App::saveData(data);
AppConfig::saveData(data);
on_btnClear_clicked();
}

View File

@ -22,34 +22,34 @@ void frmUdpClient::initForm()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
ui->cboxInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
}
void frmUdpClient::initConfig()
{
ui->ckHexSend->setChecked(App::HexSendUdpClient);
ui->ckHexSend->setChecked(AppConfig::HexSendUdpClient);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceiveUdpClient);
ui->ckHexReceive->setChecked(AppConfig::HexReceiveUdpClient);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAscii->setChecked(App::AsciiUdpClient);
ui->ckAscii->setChecked(AppConfig::AsciiUdpClient);
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::DebugUdpClient);
ui->ckDebug->setChecked(AppConfig::DebugUdpClient);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSendUdpClient);
ui->ckAutoSend->setChecked(AppConfig::AutoSendUdpClient);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalUdpClient)));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalUdpClient)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtServerIP->setText(App::UdpServerIP);
ui->txtServerIP->setText(AppConfig::UdpServerIP);
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtServerPort->setText(QString::number(App::UdpServerPort));
ui->txtServerPort->setText(QString::number(AppConfig::UdpServerPort));
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
this->changeTimer();
@ -57,23 +57,23 @@ void frmUdpClient::initConfig()
void frmUdpClient::saveConfig()
{
App::HexSendUdpClient = ui->ckHexSend->isChecked();
App::HexReceiveUdpClient = ui->ckHexReceive->isChecked();
App::AsciiUdpClient = ui->ckAscii->isChecked();
App::DebugUdpClient = ui->ckDebug->isChecked();
App::AutoSendUdpClient = ui->ckAutoSend->isChecked();
App::IntervalUdpClient = ui->cboxInterval->currentText().toInt();
App::UdpServerIP = ui->txtServerIP->text().trimmed();
App::UdpServerPort = ui->txtServerPort->text().trimmed().toInt();
App::writeConfig();
AppConfig::HexSendUdpClient = ui->ckHexSend->isChecked();
AppConfig::HexReceiveUdpClient = ui->ckHexReceive->isChecked();
AppConfig::AsciiUdpClient = ui->ckAscii->isChecked();
AppConfig::DebugUdpClient = ui->ckDebug->isChecked();
AppConfig::AutoSendUdpClient = ui->ckAutoSend->isChecked();
AppConfig::IntervalUdpClient = ui->cboxInterval->currentText().toInt();
AppConfig::UdpServerIP = ui->txtServerIP->text().trimmed();
AppConfig::UdpServerPort = ui->txtServerPort->text().trimmed().toInt();
AppConfig::writeConfig();
this->changeTimer();
}
void frmUdpClient::changeTimer()
{
timer->setInterval(App::IntervalUdpClient);
if (App::AutoSendUdpClient) {
timer->setInterval(AppConfig::IntervalUdpClient);
if (AppConfig::AutoSendUdpClient) {
if (!timer->isActive()) {
timer->start();
}
@ -135,9 +135,9 @@ void frmUdpClient::readData()
data.resize(socket->pendingDatagramSize());
socket->readDatagram(data.data(), data.size(), &host, &port);
if (App::HexReceiveUdpClient) {
if (AppConfig::HexReceiveUdpClient) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else if (App::AsciiUdpClient) {
} else if (AppConfig::AsciiUdpClient) {
buffer = QUIHelper::byteArrayToAsciiStr(data);
} else {
buffer = QString(data);
@ -152,11 +152,11 @@ void frmUdpClient::readData()
QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(buffer);
append(1, str);
if (App::DebugUdpClient) {
int count = App::Keys.count();
if (AppConfig::DebugUdpClient) {
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (App::Keys.at(i) == buffer) {
sendData(ip, port, App::Values.at(i));
if (AppConfig::Keys.at(i) == buffer) {
sendData(ip, port, AppConfig::Values.at(i));
break;
}
}
@ -167,9 +167,9 @@ void frmUdpClient::readData()
void frmUdpClient::sendData(const QString &ip, int port, const QString &data)
{
QByteArray buffer;
if (App::HexSendUdpClient) {
if (AppConfig::HexSendUdpClient) {
buffer = QUIHelper::hexStrToByteArray(data);
} else if (App::AsciiUdpClient) {
} else if (AppConfig::AsciiUdpClient) {
buffer = QUIHelper::asciiStrToByteArray(data);
} else {
buffer = data.toUtf8();
@ -184,7 +184,7 @@ void frmUdpClient::sendData(const QString &ip, int port, const QString &data)
void frmUdpClient::on_btnSave_clicked()
{
QString data = ui->txtMain->toPlainText();
App::saveData(data);
AppConfig::saveData(data);
on_btnClear_clicked();
}
@ -200,5 +200,5 @@ void frmUdpClient::on_btnSend_clicked()
return;
}
sendData(App::UdpServerIP, App::UdpServerPort, data);
sendData(AppConfig::UdpServerIP, AppConfig::UdpServerPort, data);
}

View File

@ -22,8 +22,8 @@ void frmUdpServer::initForm()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
ui->cboxInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
//获取本机所有IP
QStringList ips = QUIHelper::getLocalIPs();
@ -35,31 +35,31 @@ void frmUdpServer::initForm()
void frmUdpServer::initConfig()
{
ui->ckHexSend->setChecked(App::HexSendUdpServer);
ui->ckHexSend->setChecked(AppConfig::HexSendUdpServer);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceiveUdpServer);
ui->ckHexReceive->setChecked(AppConfig::HexReceiveUdpServer);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAscii->setChecked(App::AsciiUdpServer);
ui->ckAscii->setChecked(AppConfig::AsciiUdpServer);
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::DebugUdpServer);
ui->ckDebug->setChecked(AppConfig::DebugUdpServer);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSendUdpServer);
ui->ckAutoSend->setChecked(AppConfig::AutoSendUdpServer);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalUdpServer)));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalUdpServer)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->cboxListenIP->setCurrentIndex(ui->cboxListenIP->findText(App::UdpListenIP));
ui->cboxListenIP->setCurrentIndex(ui->cboxListenIP->findText(AppConfig::UdpListenIP));
connect(ui->cboxListenIP, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtListenPort->setText(QString::number(App::UdpListenPort));
ui->txtListenPort->setText(QString::number(AppConfig::UdpListenPort));
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->ckSelectAll->setChecked(App::SelectAllUdpServer);
ui->ckSelectAll->setChecked(AppConfig::SelectAllUdpServer);
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
this->changeTimer();
@ -67,24 +67,24 @@ void frmUdpServer::initConfig()
void frmUdpServer::saveConfig()
{
App::HexSendUdpServer = ui->ckHexSend->isChecked();
App::HexReceiveUdpServer = ui->ckHexReceive->isChecked();
App::AsciiUdpServer = ui->ckAscii->isChecked();
App::DebugUdpServer = ui->ckDebug->isChecked();
App::AutoSendUdpServer = ui->ckAutoSend->isChecked();
App::IntervalUdpServer = ui->cboxInterval->currentText().toInt();
App::UdpListenIP = ui->cboxListenIP->currentText();
App::UdpListenPort = ui->txtListenPort->text().trimmed().toInt();
App::SelectAllUdpServer = ui->ckSelectAll->isChecked();
App::writeConfig();
AppConfig::HexSendUdpServer = ui->ckHexSend->isChecked();
AppConfig::HexReceiveUdpServer = ui->ckHexReceive->isChecked();
AppConfig::AsciiUdpServer = ui->ckAscii->isChecked();
AppConfig::DebugUdpServer = ui->ckDebug->isChecked();
AppConfig::AutoSendUdpServer = ui->ckAutoSend->isChecked();
AppConfig::IntervalUdpServer = ui->cboxInterval->currentText().toInt();
AppConfig::UdpListenIP = ui->cboxListenIP->currentText();
AppConfig::UdpListenPort = ui->txtListenPort->text().trimmed().toInt();
AppConfig::SelectAllUdpServer = ui->ckSelectAll->isChecked();
AppConfig::writeConfig();
this->changeTimer();
}
void frmUdpServer::changeTimer()
{
timer->setInterval(App::IntervalUdpServer);
if (App::AutoSendUdpServer) {
timer->setInterval(AppConfig::IntervalUdpServer);
if (AppConfig::AutoSendUdpServer) {
if (!timer->isActive()) {
timer->start();
}
@ -146,9 +146,9 @@ void frmUdpServer::readData()
data.resize(socket->pendingDatagramSize());
socket->readDatagram(data.data(), data.size(), &host, &port);
if (App::HexReceiveUdpServer) {
if (AppConfig::HexReceiveUdpServer) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else if (App::AsciiUdpServer) {
} else if (AppConfig::AsciiUdpServer) {
buffer = QUIHelper::byteArrayToAsciiStr(data);
} else {
buffer = QString(data);
@ -164,11 +164,11 @@ void frmUdpServer::readData()
append(1, str);
clientConnected(ip, port);
if (App::DebugUdpServer) {
int count = App::Keys.count();
if (AppConfig::DebugUdpServer) {
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (App::Keys.at(i) == buffer) {
sendData(ip, port, App::Values.at(i));
if (AppConfig::Keys.at(i) == buffer) {
sendData(ip, port, AppConfig::Values.at(i));
break;
}
}
@ -179,9 +179,9 @@ void frmUdpServer::readData()
void frmUdpServer::sendData(const QString &ip, int port, const QString &data)
{
QByteArray buffer;
if (App::HexSendUdpServer) {
if (AppConfig::HexSendUdpServer) {
buffer = QUIHelper::hexStrToByteArray(data);
} else if (App::AsciiUdpServer) {
} else if (AppConfig::AsciiUdpServer) {
buffer = QUIHelper::asciiStrToByteArray(data);
} else {
buffer = data.toUtf8();
@ -211,7 +211,7 @@ void frmUdpServer::clientConnected(const QString &ip, int port)
void frmUdpServer::on_btnListen_clicked()
{
if (ui->btnListen->text() == "监听") {
bool ok = socket->bind(QHostAddress(App::UdpListenIP), App::UdpListenPort);
bool ok = socket->bind(QHostAddress(AppConfig::UdpListenIP), AppConfig::UdpListenPort);
if (ok) {
ui->btnListen->setText("关闭");
append(0, "监听成功");
@ -225,7 +225,7 @@ void frmUdpServer::on_btnListen_clicked()
void frmUdpServer::on_btnSave_clicked()
{
QString data = ui->txtMain->toPlainText();
App::saveData(data);
AppConfig::saveData(data);
on_btnClear_clicked();
}

View File

@ -32,34 +32,34 @@ void frmWebClient::initForm()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
ui->cboxInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
}
void frmWebClient::initConfig()
{
ui->ckHexSend->setChecked(App::HexSendWebClient);
ui->ckHexSend->setChecked(AppConfig::HexSendWebClient);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceiveWebClient);
ui->ckHexReceive->setChecked(AppConfig::HexReceiveWebClient);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAscii->setChecked(App::AsciiWebClient);
ui->ckAscii->setChecked(AppConfig::AsciiWebClient);
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::DebugWebClient);
ui->ckDebug->setChecked(AppConfig::DebugWebClient);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSendWebClient);
ui->ckAutoSend->setChecked(AppConfig::AutoSendWebClient);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalWebClient)));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalWebClient)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtServerIP->setText(App::WebServerIP);
ui->txtServerIP->setText(AppConfig::WebServerIP);
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtServerPort->setText(QString::number(App::WebServerPort));
ui->txtServerPort->setText(QString::number(AppConfig::WebServerPort));
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
this->changeTimer();
@ -67,23 +67,23 @@ void frmWebClient::initConfig()
void frmWebClient::saveConfig()
{
App::HexSendWebClient = ui->ckHexSend->isChecked();
App::HexReceiveWebClient = ui->ckHexReceive->isChecked();
App::AsciiWebClient = ui->ckAscii->isChecked();
App::DebugWebClient = ui->ckDebug->isChecked();
App::AutoSendWebClient = ui->ckAutoSend->isChecked();
App::IntervalWebClient = ui->cboxInterval->currentText().toInt();
App::WebServerIP = ui->txtServerIP->text().trimmed();
App::WebServerPort = ui->txtServerPort->text().trimmed().toInt();
App::writeConfig();
AppConfig::HexSendWebClient = ui->ckHexSend->isChecked();
AppConfig::HexReceiveWebClient = ui->ckHexReceive->isChecked();
AppConfig::AsciiWebClient = ui->ckAscii->isChecked();
AppConfig::DebugWebClient = ui->ckDebug->isChecked();
AppConfig::AutoSendWebClient = ui->ckAutoSend->isChecked();
AppConfig::IntervalWebClient = ui->cboxInterval->currentText().toInt();
AppConfig::WebServerIP = ui->txtServerIP->text().trimmed();
AppConfig::WebServerPort = ui->txtServerPort->text().trimmed().toInt();
AppConfig::writeConfig();
this->changeTimer();
}
void frmWebClient::changeTimer()
{
timer->setInterval(App::IntervalWebClient);
if (App::AutoSendWebClient) {
timer->setInterval(AppConfig::IntervalWebClient);
if (AppConfig::AutoSendWebClient) {
if (!timer->isActive()) {
timer->start();
}
@ -152,13 +152,13 @@ void frmWebClient::disconnected()
void frmWebClient::sendData(const QString &data)
{
QByteArray buffer;
if (App::HexSendWebClient) {
if (AppConfig::HexSendWebClient) {
buffer = QUIHelper::hexStrToByteArray(data);
} else {
buffer = data.toUtf8();
}
if (App::AsciiWebClient) {
if (AppConfig::AsciiWebClient) {
socket->sendTextMessage(data);
} else {
socket->sendBinaryMessage(buffer);
@ -173,11 +173,11 @@ void frmWebClient::textFrameReceived(const QString &data, bool isLastFrame)
append(1, buffer);
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
if (App::DebugWebClient) {
int count = App::Keys.count();
if (AppConfig::DebugWebClient) {
int count = AppConfig::Keys.count();
for (int i = 0; i < count; i++) {
if (App::Keys.at(i) == buffer) {
sendData(App::Values.at(i));
if (AppConfig::Keys.at(i) == buffer) {
sendData(AppConfig::Values.at(i));
break;
}
}
@ -187,7 +187,7 @@ void frmWebClient::textFrameReceived(const QString &data, bool isLastFrame)
void frmWebClient::binaryFrameReceived(const QByteArray &data, bool isLastFrame)
{
QString buffer;
if (App::HexReceiveWebClient) {
if (AppConfig::HexReceiveWebClient) {
buffer = QUIHelper::byteArrayToHexStr(data);
} else {
buffer = QString(data);
@ -209,7 +209,7 @@ void frmWebClient::binaryMessageReceived(const QByteArray &data)
void frmWebClient::on_btnConnect_clicked()
{
if (ui->btnConnect->text() == "连接") {
QString url = QString("%1:%2").arg(App::WebServerIP).arg(App::WebServerPort);
QString url = QString("%1:%2").arg(AppConfig::WebServerIP).arg(AppConfig::WebServerPort);
socket->abort();
socket->open(QUrl(url));
} else {
@ -220,7 +220,7 @@ void frmWebClient::on_btnConnect_clicked()
void frmWebClient::on_btnSave_clicked()
{
QString data = ui->txtMain->toPlainText();
App::saveData(data);
AppConfig::saveData(data);
on_btnClear_clicked();
}

View File

@ -26,8 +26,8 @@ void frmWebServer::initForm()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
ui->cboxInterval->addItems(App::Intervals);
ui->cboxData->addItems(App::Datas);
ui->cboxInterval->addItems(AppConfig::Intervals);
ui->cboxData->addItems(AppConfig::Datas);
//获取本机所有IP
QStringList ips = QUIHelper::getLocalIPs();
@ -39,31 +39,31 @@ void frmWebServer::initForm()
void frmWebServer::initConfig()
{
ui->ckHexSend->setChecked(App::HexSendWebServer);
ui->ckHexSend->setChecked(AppConfig::HexSendWebServer);
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckHexReceive->setChecked(App::HexReceiveWebServer);
ui->ckHexReceive->setChecked(AppConfig::HexReceiveWebServer);
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAscii->setChecked(App::AsciiWebServer);
ui->ckAscii->setChecked(AppConfig::AsciiWebServer);
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckDebug->setChecked(App::DebugWebServer);
ui->ckDebug->setChecked(AppConfig::DebugWebServer);
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->ckAutoSend->setChecked(App::AutoSendWebServer);
ui->ckAutoSend->setChecked(AppConfig::AutoSendWebServer);
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalWebServer)));
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalWebServer)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->cboxListenIP->setCurrentIndex(ui->cboxListenIP->findText(App::WebListenIP));
ui->cboxListenIP->setCurrentIndex(ui->cboxListenIP->findText(AppConfig::WebListenIP));
connect(ui->cboxListenIP, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->txtListenPort->setText(QString::number(App::WebListenPort));
ui->txtListenPort->setText(QString::number(AppConfig::WebListenPort));
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->ckSelectAll->setChecked(App::SelectAllWebServer);
ui->ckSelectAll->setChecked(AppConfig::SelectAllWebServer);
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
this->changeTimer();
@ -71,24 +71,24 @@ void frmWebServer::initConfig()
void frmWebServer::saveConfig()
{
App::HexSendWebServer = ui->ckHexSend->isChecked();
App::HexReceiveWebServer = ui->ckHexReceive->isChecked();
App::AsciiWebServer = ui->ckAscii->isChecked();
App::DebugWebServer = ui->ckDebug->isChecked();
App::AutoSendWebServer = ui->ckAutoSend->isChecked();
App::IntervalWebServer = ui->cboxInterval->currentText().toInt();
App::WebListenIP = ui->cboxListenIP->currentText();
App::WebListenPort = ui->txtListenPort->text().trimmed().toInt();
App::SelectAllWebServer = ui->ckSelectAll->isChecked();
App::writeConfig();
AppConfig::HexSendWebServer = ui->ckHexSend->isChecked();
AppConfig::HexReceiveWebServer = ui->ckHexReceive->isChecked();
AppConfig::AsciiWebServer = ui->ckAscii->isChecked();
AppConfig::DebugWebServer = ui->ckDebug->isChecked();
AppConfig::AutoSendWebServer = ui->ckAutoSend->isChecked();
AppConfig::IntervalWebServer = ui->cboxInterval->currentText().toInt();
AppConfig::WebListenIP = ui->cboxListenIP->currentText();
AppConfig::WebListenPort = ui->txtListenPort->text().trimmed().toInt();
AppConfig::SelectAllWebServer = ui->ckSelectAll->isChecked();
AppConfig::writeConfig();
this->changeTimer();
}
void frmWebServer::changeTimer()
{
timer->setInterval(App::IntervalWebServer);
if (App::AutoSendWebServer) {
timer->setInterval(AppConfig::IntervalWebServer);
if (AppConfig::AutoSendWebServer) {
if (!timer->isActive()) {
timer->start();
}
@ -192,7 +192,7 @@ void frmWebServer::on_btnListen_clicked()
void frmWebServer::on_btnSave_clicked()
{
QString data = ui->txtMain->toPlainText();
App::saveData(data);
AppConfig::saveData(data);
on_btnClear_clicked();
}

View File

@ -9,6 +9,6 @@
#endif
#endif
#include "app.h"
#include "appconfig.h"
#pragma execution_character_set("utf-8")

View File

@ -13,11 +13,11 @@ int main(int argc, char *argv[])
QUIHelper::setTranslator(":/widgets.qm");
QUIHelper::initRand();
App::Intervals << "1" << "10" << "20" << "50" << "100" << "200" << "300" << "500" << "1000" << "1500" << "2000" << "3000" << "5000" << "10000";
App::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
App::readConfig();
App::readSendData();
App::readDeviceData();
AppConfig::Intervals << "1" << "10" << "20" << "50" << "100" << "200" << "300" << "500" << "1000" << "1500" << "2000" << "3000" << "5000" << "10000";
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
AppConfig::readConfig();
AppConfig::readSendData();
AppConfig::readDeviceData();
frmMain w;
w.setWindowTitle("网络调试助手 V2021 (QQ: 517216493 WX: feiyangqingyun)");