改进串口调试助手和网络调试助手代码
This commit is contained in:
@@ -17,18 +17,28 @@ frmTcpClient::~frmTcpClient()
|
||||
void frmTcpClient::initForm()
|
||||
{
|
||||
isOk = false;
|
||||
|
||||
//实例化对象并绑定信号槽
|
||||
socket = new QTcpSocket(this);
|
||||
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)),this, SLOT(disconnected()));
|
||||
#else
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(disconnected()));
|
||||
#endif
|
||||
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
|
||||
//定时器发送数据
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(AppConfig::Intervals);
|
||||
ui->cboxData->addItems(AppConfig::Datas);
|
||||
//填充数据到下拉框
|
||||
ui->cboxInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
AppData::loadIP(ui->cboxBindIP);
|
||||
|
||||
//打印下外网地址
|
||||
#ifndef emsdk
|
||||
QString ip = QUIHelper::getNetIP(QUIHelper::getHtml("http://whois.pconline.com.cn/"));
|
||||
append(1, QString("外网IP -> %1").arg(ip));
|
||||
@@ -55,13 +65,19 @@ void frmTcpClient::initConfig()
|
||||
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalTcpClient)));
|
||||
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->cboxBindIP->setCurrentIndex(ui->cboxBindIP->findText(AppConfig::TcpBindIP));
|
||||
connect(ui->cboxBindIP, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtBindPort->setText(QString::number(AppConfig::TcpBindPort));
|
||||
connect(ui->txtBindPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerIP->setText(AppConfig::TcpServerIP);
|
||||
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerPort->setText(QString::number(AppConfig::TcpServerPort));
|
||||
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmTcpClient::saveConfig()
|
||||
@@ -72,16 +88,21 @@ void frmTcpClient::saveConfig()
|
||||
AppConfig::DebugTcpClient = ui->ckDebug->isChecked();
|
||||
AppConfig::AutoSendTcpClient = ui->ckAutoSend->isChecked();
|
||||
AppConfig::IntervalTcpClient = ui->cboxInterval->currentText().toInt();
|
||||
AppConfig::TcpBindIP = ui->cboxBindIP->currentText();
|
||||
AppConfig::TcpBindPort = ui->txtBindPort->text().trimmed().toInt();
|
||||
AppConfig::TcpServerIP = ui->txtServerIP->text().trimmed();
|
||||
AppConfig::TcpServerPort = ui->txtServerPort->text().trimmed().toInt();
|
||||
AppConfig::writeConfig();
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmTcpClient::changeTimer()
|
||||
void frmTcpClient::initTimer()
|
||||
{
|
||||
timer->setInterval(AppConfig::IntervalTcpClient);
|
||||
if (timer->interval() != AppConfig::IntervalTcpClient) {
|
||||
timer->setInterval(AppConfig::IntervalTcpClient);
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSendTcpClient) {
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
@@ -168,10 +189,10 @@ void frmTcpClient::readData()
|
||||
|
||||
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
|
||||
if (AppConfig::DebugTcpClient) {
|
||||
int count = AppConfig::Keys.count();
|
||||
int count = AppData::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (AppConfig::Keys.at(i) == buffer) {
|
||||
sendData(AppConfig::Values.at(i));
|
||||
if (AppData::Keys.at(i) == buffer) {
|
||||
sendData(AppData::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +217,13 @@ void frmTcpClient::sendData(const QString &data)
|
||||
void frmTcpClient::on_btnConnect_clicked()
|
||||
{
|
||||
if (ui->btnConnect->text() == "连接") {
|
||||
//断开所有连接和操作
|
||||
socket->abort();
|
||||
//绑定网卡和端口
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
socket->bind(QHostAddress(AppConfig::TcpBindIP), AppConfig::TcpBindPort);
|
||||
#endif
|
||||
//连接服务器
|
||||
socket->connectToHost(AppConfig::TcpServerIP, AppConfig::TcpServerPort);
|
||||
} else {
|
||||
socket->abort();
|
||||
@@ -206,7 +233,7 @@ void frmTcpClient::on_btnConnect_clicked()
|
||||
void frmTcpClient::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
AppConfig::saveData(data);
|
||||
AppData::saveData(data);
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void changeTimer();
|
||||
void initTimer();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
@@ -111,6 +111,26 @@
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxInterval"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labBindIP">
|
||||
<property name="text">
|
||||
<string>绑定地址</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxBindIP"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labBindPort">
|
||||
<property name="text">
|
||||
<string>绑定端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtBindPort"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerIP">
|
||||
<property name="text">
|
||||
@@ -220,6 +240,25 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>txtMain</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
<tabstop>ckHexReceive</tabstop>
|
||||
<tabstop>ckHexSend</tabstop>
|
||||
<tabstop>ckAscii</tabstop>
|
||||
<tabstop>ckShow</tabstop>
|
||||
<tabstop>ckDebug</tabstop>
|
||||
<tabstop>ckAutoSend</tabstop>
|
||||
<tabstop>cboxInterval</tabstop>
|
||||
<tabstop>cboxBindIP</tabstop>
|
||||
<tabstop>txtBindPort</tabstop>
|
||||
<tabstop>txtServerIP</tabstop>
|
||||
<tabstop>txtServerPort</tabstop>
|
||||
<tabstop>btnConnect</tabstop>
|
||||
<tabstop>btnSave</tabstop>
|
||||
<tabstop>btnClear</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -17,24 +17,22 @@ frmTcpServer::~frmTcpServer()
|
||||
void frmTcpServer::initForm()
|
||||
{
|
||||
isOk = false;
|
||||
|
||||
//实例化对象并绑定信号槽
|
||||
server = new TcpServer(this);
|
||||
connect(server, SIGNAL(clientConnected(QString, int)), this, SLOT(clientConnected(QString, int)));
|
||||
connect(server, SIGNAL(clientDisconnected(QString, int)), this, SLOT(clientDisconnected(QString, int)));
|
||||
connect(server, SIGNAL(sendData(QString, int, QString)), this, SLOT(sendData(QString, int, QString)));
|
||||
connect(server, SIGNAL(receiveData(QString, int, QString)), this, SLOT(receiveData(QString, int, QString)));
|
||||
|
||||
//定时器发送数据
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(AppConfig::Intervals);
|
||||
ui->cboxData->addItems(AppConfig::Datas);
|
||||
|
||||
//获取本机所有IP
|
||||
QStringList ips = QUIHelper::getLocalIPs();
|
||||
ui->cboxListenIP->addItems(ips);
|
||||
if (!ips.contains("127.0.0.1")) {
|
||||
ui->cboxListenIP->addItem("127.0.0.1");
|
||||
}
|
||||
//填充数据到下拉框
|
||||
ui->cboxInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
AppData::loadIP(ui->cboxListenIP);
|
||||
}
|
||||
|
||||
void frmTcpServer::initConfig()
|
||||
@@ -66,7 +64,7 @@ void frmTcpServer::initConfig()
|
||||
ui->ckSelectAll->setChecked(AppConfig::SelectAllTcpServer);
|
||||
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmTcpServer::saveConfig()
|
||||
@@ -82,12 +80,15 @@ void frmTcpServer::saveConfig()
|
||||
AppConfig::SelectAllTcpServer = ui->ckSelectAll->isChecked();
|
||||
AppConfig::writeConfig();
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmTcpServer::changeTimer()
|
||||
void frmTcpServer::initTimer()
|
||||
{
|
||||
timer->setInterval(AppConfig::IntervalTcpServer);
|
||||
if (timer->interval() != AppConfig::IntervalTcpServer) {
|
||||
timer->setInterval(AppConfig::IntervalTcpServer);
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSendTcpServer) {
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
@@ -192,7 +193,7 @@ void frmTcpServer::on_btnListen_clicked()
|
||||
void frmTcpServer::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
AppConfig::saveData(data);
|
||||
AppData::saveData(data);
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void changeTimer();
|
||||
void initTimer();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -248,6 +248,8 @@
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>txtMain</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
<tabstop>ckHexReceive</tabstop>
|
||||
<tabstop>ckHexSend</tabstop>
|
||||
<tabstop>ckAscii</tabstop>
|
||||
@@ -263,8 +265,6 @@
|
||||
<tabstop>btnClose</tabstop>
|
||||
<tabstop>listWidget</tabstop>
|
||||
<tabstop>ckSelectAll</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -16,14 +16,18 @@ frmUdpClient::~frmUdpClient()
|
||||
|
||||
void frmUdpClient::initForm()
|
||||
{
|
||||
//实例化对象并绑定信号槽
|
||||
socket = new QUdpSocket(this);
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
|
||||
//定时器发送数据
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(AppConfig::Intervals);
|
||||
ui->cboxData->addItems(AppConfig::Datas);
|
||||
//填充数据到下拉框
|
||||
ui->cboxInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
AppData::loadIP(ui->cboxBindIP);
|
||||
}
|
||||
|
||||
void frmUdpClient::initConfig()
|
||||
@@ -46,13 +50,19 @@ void frmUdpClient::initConfig()
|
||||
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::IntervalUdpClient)));
|
||||
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->cboxBindIP->setCurrentIndex(ui->cboxBindIP->findText(AppConfig::UdpBindIP));
|
||||
connect(ui->cboxBindIP, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtBindPort->setText(QString::number(AppConfig::UdpBindPort));
|
||||
connect(ui->txtBindPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerIP->setText(AppConfig::UdpServerIP);
|
||||
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerPort->setText(QString::number(AppConfig::UdpServerPort));
|
||||
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmUdpClient::saveConfig()
|
||||
@@ -63,16 +73,21 @@ void frmUdpClient::saveConfig()
|
||||
AppConfig::DebugUdpClient = ui->ckDebug->isChecked();
|
||||
AppConfig::AutoSendUdpClient = ui->ckAutoSend->isChecked();
|
||||
AppConfig::IntervalUdpClient = ui->cboxInterval->currentText().toInt();
|
||||
AppConfig::UdpBindIP = ui->cboxBindIP->currentText();
|
||||
AppConfig::UdpBindPort = ui->txtBindPort->text().trimmed().toInt();
|
||||
AppConfig::UdpServerIP = ui->txtServerIP->text().trimmed();
|
||||
AppConfig::UdpServerPort = ui->txtServerPort->text().trimmed().toInt();
|
||||
AppConfig::writeConfig();
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmUdpClient::changeTimer()
|
||||
void frmUdpClient::initTimer()
|
||||
{
|
||||
timer->setInterval(AppConfig::IntervalUdpClient);
|
||||
if (timer->interval() != AppConfig::IntervalUdpClient) {
|
||||
timer->setInterval(AppConfig::IntervalUdpClient);
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSendUdpClient) {
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
@@ -153,10 +168,10 @@ void frmUdpClient::readData()
|
||||
append(1, str);
|
||||
|
||||
if (AppConfig::DebugUdpClient) {
|
||||
int count = AppConfig::Keys.count();
|
||||
int count = AppData::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (AppConfig::Keys.at(i) == buffer) {
|
||||
sendData(ip, port, AppConfig::Values.at(i));
|
||||
if (AppData::Keys.at(i) == buffer) {
|
||||
sendData(ip, port, AppData::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -175,6 +190,13 @@ void frmUdpClient::sendData(const QString &ip, int port, const QString &data)
|
||||
buffer = data.toUtf8();
|
||||
}
|
||||
|
||||
//绑定网卡和端口
|
||||
if (socket->localPort() != AppConfig::UdpBindPort) {
|
||||
socket->abort();
|
||||
socket->bind(QHostAddress(AppConfig::UdpBindIP), AppConfig::UdpBindPort);
|
||||
}
|
||||
|
||||
//指定地址和端口发送数据
|
||||
socket->writeDatagram(buffer, QHostAddress(ip), port);
|
||||
|
||||
QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(data);
|
||||
@@ -184,7 +206,7 @@ void frmUdpClient::sendData(const QString &ip, int port, const QString &data)
|
||||
void frmUdpClient::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
AppConfig::saveData(data);
|
||||
AppData::saveData(data);
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void changeTimer();
|
||||
void initTimer();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
@@ -111,10 +111,30 @@
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxInterval"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labBindIP">
|
||||
<property name="text">
|
||||
<string>绑定地址</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxBindIP"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labBindPort">
|
||||
<property name="text">
|
||||
<string>绑定端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtBindPort"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerIP">
|
||||
<property name="text">
|
||||
<string>远程地址</string>
|
||||
<string>服务器地址</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -124,7 +144,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerPort">
|
||||
<property name="text">
|
||||
<string>远程端口</string>
|
||||
<string>服务器端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -213,6 +233,24 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>txtMain</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
<tabstop>ckHexReceive</tabstop>
|
||||
<tabstop>ckHexSend</tabstop>
|
||||
<tabstop>ckAscii</tabstop>
|
||||
<tabstop>ckShow</tabstop>
|
||||
<tabstop>ckDebug</tabstop>
|
||||
<tabstop>ckAutoSend</tabstop>
|
||||
<tabstop>cboxInterval</tabstop>
|
||||
<tabstop>cboxBindIP</tabstop>
|
||||
<tabstop>txtBindPort</tabstop>
|
||||
<tabstop>txtServerIP</tabstop>
|
||||
<tabstop>txtServerPort</tabstop>
|
||||
<tabstop>btnSave</tabstop>
|
||||
<tabstop>btnClear</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -16,21 +16,18 @@ frmUdpServer::~frmUdpServer()
|
||||
|
||||
void frmUdpServer::initForm()
|
||||
{
|
||||
//实例化对象并绑定信号槽
|
||||
socket = new QUdpSocket(this);
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
|
||||
//定时器发送数据
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(AppConfig::Intervals);
|
||||
ui->cboxData->addItems(AppConfig::Datas);
|
||||
|
||||
//获取本机所有IP
|
||||
QStringList ips = QUIHelper::getLocalIPs();
|
||||
ui->cboxListenIP->addItems(ips);
|
||||
if (!ips.contains("127.0.0.1")) {
|
||||
ui->cboxListenIP->addItem("127.0.0.1");
|
||||
}
|
||||
//填充数据到下拉框
|
||||
ui->cboxInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
AppData::loadIP(ui->cboxListenIP);
|
||||
}
|
||||
|
||||
void frmUdpServer::initConfig()
|
||||
@@ -62,7 +59,7 @@ void frmUdpServer::initConfig()
|
||||
ui->ckSelectAll->setChecked(AppConfig::SelectAllUdpServer);
|
||||
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmUdpServer::saveConfig()
|
||||
@@ -78,12 +75,15 @@ void frmUdpServer::saveConfig()
|
||||
AppConfig::SelectAllUdpServer = ui->ckSelectAll->isChecked();
|
||||
AppConfig::writeConfig();
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmUdpServer::changeTimer()
|
||||
void frmUdpServer::initTimer()
|
||||
{
|
||||
timer->setInterval(AppConfig::IntervalUdpServer);
|
||||
if (timer->interval() != AppConfig::IntervalUdpServer) {
|
||||
timer->setInterval(AppConfig::IntervalUdpServer);
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSendUdpServer) {
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
@@ -165,10 +165,10 @@ void frmUdpServer::readData()
|
||||
clientConnected(ip, port);
|
||||
|
||||
if (AppConfig::DebugUdpServer) {
|
||||
int count = AppConfig::Keys.count();
|
||||
int count = AppData::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (AppConfig::Keys.at(i) == buffer) {
|
||||
sendData(ip, port, AppConfig::Values.at(i));
|
||||
if (AppData::Keys.at(i) == buffer) {
|
||||
sendData(ip, port, AppData::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ void frmUdpServer::on_btnListen_clicked()
|
||||
void frmUdpServer::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
AppConfig::saveData(data);
|
||||
AppData::saveData(data);
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void changeTimer();
|
||||
void initTimer();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -241,6 +241,8 @@
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>txtMain</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
<tabstop>ckHexReceive</tabstop>
|
||||
<tabstop>ckHexSend</tabstop>
|
||||
<tabstop>ckAscii</tabstop>
|
||||
@@ -253,8 +255,8 @@
|
||||
<tabstop>btnListen</tabstop>
|
||||
<tabstop>btnSave</tabstop>
|
||||
<tabstop>btnClear</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
<tabstop>listWidget</tabstop>
|
||||
<tabstop>ckSelectAll</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -17,6 +17,8 @@ frmWebClient::~frmWebClient()
|
||||
void frmWebClient::initForm()
|
||||
{
|
||||
isOk = false;
|
||||
|
||||
//实例化对象并绑定信号槽
|
||||
socket = new QWebSocket("WebSocket", QWebSocketProtocol::VersionLatest, this);
|
||||
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(disconnected()));
|
||||
@@ -29,11 +31,13 @@ void frmWebClient::initForm()
|
||||
//connect(socket, SIGNAL(textFrameReceived(QString, bool)), this, SLOT(textFrameReceived(QString, bool)));
|
||||
//connect(socket, SIGNAL(binaryFrameReceived(QByteArray, bool)), this, SLOT(binaryFrameReceived(QByteArray, bool)));
|
||||
|
||||
//定时器发送数据
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(AppConfig::Intervals);
|
||||
ui->cboxData->addItems(AppConfig::Datas);
|
||||
//填充数据到下拉框
|
||||
ui->cboxInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
}
|
||||
|
||||
void frmWebClient::initConfig()
|
||||
@@ -62,7 +66,7 @@ void frmWebClient::initConfig()
|
||||
ui->txtServerPort->setText(QString::number(AppConfig::WebServerPort));
|
||||
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmWebClient::saveConfig()
|
||||
@@ -77,12 +81,15 @@ void frmWebClient::saveConfig()
|
||||
AppConfig::WebServerPort = ui->txtServerPort->text().trimmed().toInt();
|
||||
AppConfig::writeConfig();
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmWebClient::changeTimer()
|
||||
void frmWebClient::initTimer()
|
||||
{
|
||||
timer->setInterval(AppConfig::IntervalWebClient);
|
||||
if (timer->interval() != AppConfig::IntervalWebClient) {
|
||||
timer->setInterval(AppConfig::IntervalWebClient);
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSendWebClient) {
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
@@ -174,10 +181,10 @@ void frmWebClient::textFrameReceived(const QString &data, bool isLastFrame)
|
||||
|
||||
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
|
||||
if (AppConfig::DebugWebClient) {
|
||||
int count = AppConfig::Keys.count();
|
||||
int count = AppData::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (AppConfig::Keys.at(i) == buffer) {
|
||||
sendData(AppConfig::Values.at(i));
|
||||
if (AppData::Keys.at(i) == buffer) {
|
||||
sendData(AppData::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -220,7 +227,7 @@ void frmWebClient::on_btnConnect_clicked()
|
||||
void frmWebClient::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
AppConfig::saveData(data);
|
||||
AppData::saveData(data);
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void changeTimer();
|
||||
void initTimer();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -17,24 +17,22 @@ frmWebServer::~frmWebServer()
|
||||
void frmWebServer::initForm()
|
||||
{
|
||||
isOk = false;
|
||||
|
||||
//实例化对象并绑定信号槽
|
||||
server = new WebServer("WebServer", QWebSocketServer::NonSecureMode, this);
|
||||
connect(server, SIGNAL(clientConnected(QString, int)), this, SLOT(clientConnected(QString, int)));
|
||||
connect(server, SIGNAL(clientDisconnected(QString, int)), this, SLOT(clientDisconnected(QString, int)));
|
||||
connect(server, SIGNAL(sendData(QString, int, QString)), this, SLOT(sendData(QString, int, QString)));
|
||||
connect(server, SIGNAL(receiveData(QString, int, QString)), this, SLOT(receiveData(QString, int, QString)));
|
||||
|
||||
//定时器发送数据
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(AppConfig::Intervals);
|
||||
ui->cboxData->addItems(AppConfig::Datas);
|
||||
|
||||
//获取本机所有IP
|
||||
QStringList ips = QUIHelper::getLocalIPs();
|
||||
ui->cboxListenIP->addItems(ips);
|
||||
if (!ips.contains("127.0.0.1")) {
|
||||
ui->cboxListenIP->addItem("127.0.0.1");
|
||||
}
|
||||
//填充数据到下拉框
|
||||
ui->cboxInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
AppData::loadIP(ui->cboxListenIP);
|
||||
}
|
||||
|
||||
void frmWebServer::initConfig()
|
||||
@@ -66,7 +64,7 @@ void frmWebServer::initConfig()
|
||||
ui->ckSelectAll->setChecked(AppConfig::SelectAllWebServer);
|
||||
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmWebServer::saveConfig()
|
||||
@@ -82,12 +80,15 @@ void frmWebServer::saveConfig()
|
||||
AppConfig::SelectAllWebServer = ui->ckSelectAll->isChecked();
|
||||
AppConfig::writeConfig();
|
||||
|
||||
this->changeTimer();
|
||||
this->initTimer();
|
||||
}
|
||||
|
||||
void frmWebServer::changeTimer()
|
||||
void frmWebServer::initTimer()
|
||||
{
|
||||
timer->setInterval(AppConfig::IntervalWebServer);
|
||||
if (timer->interval() != AppConfig::IntervalWebServer) {
|
||||
timer->setInterval(AppConfig::IntervalWebServer);
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSendWebServer) {
|
||||
if (!timer->isActive()) {
|
||||
timer->start();
|
||||
@@ -192,7 +193,7 @@ void frmWebServer::on_btnListen_clicked()
|
||||
void frmWebServer::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
AppConfig::saveData(data);
|
||||
AppData::saveData(data);
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void changeTimer();
|
||||
void initTimer();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -246,6 +246,26 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>txtMain</tabstop>
|
||||
<tabstop>cboxData</tabstop>
|
||||
<tabstop>btnSend</tabstop>
|
||||
<tabstop>ckHexReceive</tabstop>
|
||||
<tabstop>ckHexSend</tabstop>
|
||||
<tabstop>ckAscii</tabstop>
|
||||
<tabstop>ckShow</tabstop>
|
||||
<tabstop>ckDebug</tabstop>
|
||||
<tabstop>ckAutoSend</tabstop>
|
||||
<tabstop>cboxInterval</tabstop>
|
||||
<tabstop>cboxListenIP</tabstop>
|
||||
<tabstop>txtListenPort</tabstop>
|
||||
<tabstop>btnListen</tabstop>
|
||||
<tabstop>btnSave</tabstop>
|
||||
<tabstop>btnClear</tabstop>
|
||||
<tabstop>btnClose</tabstop>
|
||||
<tabstop>listWidget</tabstop>
|
||||
<tabstop>ckSelectAll</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user