|
|
#include "communicationsettingdlg.h"
|
|
|
|
|
|
#include "ui_communicationsettingdlg.h"
|
|
|
|
|
|
CommunicationSettingDlg::CommunicationSettingDlg(QWidget *parent)
|
|
|
: QDialog(parent), ui(new Ui::CommunicationSettingDlg) {
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
this->setWindowTitle("通信设置");
|
|
|
|
|
|
initCombobox();
|
|
|
initNetworkSetting();
|
|
|
}
|
|
|
|
|
|
CommunicationSettingDlg::~CommunicationSettingDlg() {
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
void CommunicationSettingDlg::showEvent(QShowEvent *event) {
|
|
|
setSaveSettingParms();
|
|
|
setPodIniSetting();
|
|
|
}
|
|
|
|
|
|
|
|
|
bool CommunicationSettingDlg::isValidIP()
|
|
|
{
|
|
|
QHostAddress addrLocal(ui->podLocalIP->currentText());
|
|
|
QHostAddress addrremote(ui->podRemoteIPEdit->text());
|
|
|
|
|
|
if (addrLocal.isNull() || addrLocal.protocol() != QAbstractSocket::IPv4Protocol)
|
|
|
{
|
|
|
emit sendErrorMessage("本地IP格式错误!", 2);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (addrremote.isNull() || addrremote.protocol() != QAbstractSocket::IPv4Protocol)
|
|
|
{
|
|
|
emit sendErrorMessage("远端IP格式错误!", 2);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (ui->podLocalPort->value() == 0 || ui->podRemotePort->value() == 0)
|
|
|
{
|
|
|
emit sendErrorMessage("请输入正确的端口号!", 2);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
void CommunicationSettingDlg::savePodIniSetting()
|
|
|
{
|
|
|
g_networkSettingInfo->setValue("PodSetting/localIP",
|
|
|
ui->podLocalIP->currentText());
|
|
|
g_networkSettingInfo->setValue("PodSetting/remoteIP",
|
|
|
ui->podRemoteIPEdit->text());
|
|
|
g_networkSettingInfo->setValue("PodSetting/localPort",
|
|
|
ui->podLocalPort->value());
|
|
|
g_networkSettingInfo->setValue("PodSetting/remotePort",
|
|
|
ui->podRemotePort->value());
|
|
|
}
|
|
|
|
|
|
void CommunicationSettingDlg::setPodIniSetting()
|
|
|
{
|
|
|
ui->podRemoteIPEdit->setText(
|
|
|
g_networkSettingInfo->value("PodSetting/remoteIP", "192.168.1.160").toString());
|
|
|
ui->podRemotePort->setValue(
|
|
|
g_networkSettingInfo->value("PodSetting/remotePort", 10000).toInt());
|
|
|
ui->podLocalPort->setValue(
|
|
|
g_networkSettingInfo->value("PodSetting/localPort", 10001).toInt());
|
|
|
|
|
|
QString localIP =
|
|
|
g_networkSettingInfo->value("PodSetting/localIP").toString();
|
|
|
for (int i = 0; i < ui->podLocalIP->count(); ++i) {
|
|
|
if (localIP == ui->podLocalIP->itemText(i)) {
|
|
|
ui->podLocalIP->setCurrentIndex(i);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void CommunicationSettingDlg::on_podConnectBtn_clicked()
|
|
|
{
|
|
|
if (!isValidIP()) { return; }
|
|
|
|
|
|
savePodIniSetting();
|
|
|
|
|
|
NetworkIPStruct networkIP;
|
|
|
if (!_commIsConnect)//断开时点击连接
|
|
|
{
|
|
|
_commIsConnect = true;//状态为连接
|
|
|
networkIP.localIP = ui->podLocalIP->currentText();
|
|
|
networkIP.remoteIP = ui->podRemoteIPEdit->text();
|
|
|
networkIP.localPort = ui->podLocalPort->value();
|
|
|
networkIP.remotePort = ui->podRemotePort->value();
|
|
|
emit sendPodData(networkIP, _commIsConnect);
|
|
|
ui->podConnectBtn->setText("断开");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_commIsConnect = false;//状态为连接
|
|
|
emit sendPodData(networkIP, _commIsConnect);
|
|
|
ui->podConnectBtn->setText("连接");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void CommunicationSettingDlg::initCombobox() {
|
|
|
ui->dataSourceCombox->addItem(QStringLiteral("L测控"));
|
|
|
ui->dataSourceCombox->addItem(QStringLiteral("卫通1路"));
|
|
|
ui->dataSourceCombox->addItem(QStringLiteral("卫通2路"));
|
|
|
ui->dataSourceCombox->setCurrentIndex(0);
|
|
|
}
|
|
|
|
|
|
void CommunicationSettingDlg::initNetworkSetting() {
|
|
|
QStringList localIPList;
|
|
|
getLocalIP(localIPList);
|
|
|
ui->localIP->addItems(localIPList);
|
|
|
ui->podLocalIP->addItems(localIPList);
|
|
|
|
|
|
ui->remoteIPEdit->setText(QStringLiteral("223.0.0.1"));
|
|
|
ui->remotePort->setValue(8080);
|
|
|
ui->localPort->setValue(8082);
|
|
|
|
|
|
ui->podRemotePort->setValue(10000);
|
|
|
ui->podLocalPort->setValue(10001);
|
|
|
}
|
|
|
|
|
|
void CommunicationSettingDlg::setSaveSettingParms() {
|
|
|
if (!g_networkSettingInfo) return;
|
|
|
int dataSourceType = g_networkSettingInfo->value("DataSource").toInt();
|
|
|
ui->dataSourceCombox->setCurrentIndex(dataSourceType);
|
|
|
QString groupName = "";
|
|
|
switch (dataSourceType) {
|
|
|
case 0:
|
|
|
groupName = "LLink";
|
|
|
break;
|
|
|
case 1:
|
|
|
groupName = "SATCOM1";
|
|
|
break;
|
|
|
case 2:
|
|
|
groupName = "SATCOM2";
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
ui->remoteIPEdit->setText(
|
|
|
g_networkSettingInfo->value(groupName + "/remoteIP").toString());
|
|
|
ui->remotePort->setValue(
|
|
|
g_networkSettingInfo->value(groupName + "/remotePort").toInt());
|
|
|
ui->localPort->setValue(
|
|
|
g_networkSettingInfo->value(groupName + "/localPort").toInt());
|
|
|
|
|
|
QString localIP =
|
|
|
g_networkSettingInfo->value(groupName + "/localIP").toString();
|
|
|
for (int i = 0; i < ui->localIP->count(); ++i) {
|
|
|
if (localIP == ui->localIP->itemText(i)) {
|
|
|
ui->localIP->setCurrentIndex(i);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 保存设置
|
|
|
void CommunicationSettingDlg::on_saveSettingBtn_clicked() {
|
|
|
ui->saveSettingBtn->setDisabled(true);
|
|
|
int dataType = ui->dataSourceCombox->currentIndex();
|
|
|
|
|
|
QString remoteIP = ui->remoteIPEdit->text();
|
|
|
if (dataType == 0) { // L链为组播
|
|
|
if (!isMulticastAddress(remoteIP)) {
|
|
|
emit sendErrorMessage("当前IP地址为单播地址,请改为组播地址!", 2);
|
|
|
ui->saveSettingBtn->setDisabled(false);
|
|
|
return;
|
|
|
};
|
|
|
} else { // 卫通为单播
|
|
|
if (isMulticastAddress(remoteIP)) {
|
|
|
emit sendErrorMessage("当前IP地址为组播地址,请改为单播地址!", 2);
|
|
|
ui->saveSettingBtn->setDisabled(false);
|
|
|
return;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 保存配置参数
|
|
|
if (!g_networkSettingInfo) {
|
|
|
this->close();
|
|
|
return;
|
|
|
};
|
|
|
g_networkSettingInfo->setValue("DataSource", dataType);
|
|
|
QString groupName = "";
|
|
|
switch (dataType) {
|
|
|
case 0:
|
|
|
groupName = "LLink";
|
|
|
break;
|
|
|
case 1:
|
|
|
groupName = "SATCOM1";
|
|
|
break;
|
|
|
case 2:
|
|
|
groupName = "SATCOM2";
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
g_networkSettingInfo->setValue(groupName + "/localIP",
|
|
|
ui->localIP->currentText());
|
|
|
g_networkSettingInfo->setValue(groupName + "/localPort",
|
|
|
ui->localPort->value());
|
|
|
g_networkSettingInfo->setValue(groupName + "/remoteIP",
|
|
|
ui->remoteIPEdit->text());
|
|
|
g_networkSettingInfo->setValue(groupName + "/remotePort",
|
|
|
ui->remotePort->value());
|
|
|
|
|
|
ui->saveSettingBtn->setDisabled(false);
|
|
|
emit sendErrorMessage("保存成功!", 1);
|
|
|
this->close();
|
|
|
}
|