|
|
#include "deviceStateDlg.h"
|
|
|
#include "ui_deviceStateDlg.h"
|
|
|
|
|
|
deviceStateDlg::deviceStateDlg(QWidget *parent)
|
|
|
: QWidget(parent), ui(new Ui::deviceStateDlg) {
|
|
|
ui->setupUi(this);
|
|
|
initWindow();
|
|
|
initParam();
|
|
|
}
|
|
|
|
|
|
deviceStateDlg::~deviceStateDlg() {
|
|
|
stopNetDetn();
|
|
|
delete m_timer;
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::initWindow() {
|
|
|
// 嵌入到主窗口
|
|
|
setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
|
|
|
hide();
|
|
|
|
|
|
m_greyIcon.addFile(":/res/lamp/grey.png");
|
|
|
m_greenIcon.addFile(":/res/lamp/green.png");
|
|
|
m_redIcon.addFile(":/res/lamp/red.png");
|
|
|
|
|
|
QString stateButtonStyle =
|
|
|
/*正常情况下样式*/
|
|
|
"QPushButton{"
|
|
|
//"image: url(:/res/lamp/grey.png)-23px 0px no-repeat;"
|
|
|
"border-radius: 13px;"
|
|
|
"border-style: solid;"
|
|
|
"border-width: 1px;"
|
|
|
"padding: 5px;"
|
|
|
"}";
|
|
|
ui->pushButton_state_GDDC->setStyleSheet(stateButtonStyle);
|
|
|
ui->pushButton_state_LLink->setStyleSheet(stateButtonStyle);
|
|
|
ui->pushButton_state_3DCamra->setStyleSheet(stateButtonStyle);
|
|
|
ui->pushButton_state_KuSatelliteComm->setStyleSheet(stateButtonStyle);
|
|
|
ui->pushButton_state_PDT->setStyleSheet(stateButtonStyle);
|
|
|
ui->pushButton_state_adHocNetwork->setStyleSheet(stateButtonStyle);
|
|
|
ui->pushButton_state_rescue->setStyleSheet(stateButtonStyle);
|
|
|
//"image: url(:/res/lamp/grey.png)-23px 0px no-repeat;"
|
|
|
|
|
|
|
|
|
ui->pushButton_state_GDDC->setIcon(m_greyIcon);
|
|
|
ui->pushButton_state_LLink->setIcon(m_greyIcon);
|
|
|
ui->pushButton_state_3DCamra->setIcon(m_greyIcon);
|
|
|
ui->pushButton_state_KuSatelliteComm->setIcon(m_greyIcon);
|
|
|
ui->pushButton_state_PDT->setIcon(m_greyIcon);
|
|
|
ui->pushButton_state_adHocNetwork->setIcon(m_greyIcon);
|
|
|
ui->pushButton_state_rescue->setIcon(m_greyIcon);
|
|
|
|
|
|
ui->pushButton_state_GDDC->setIconSize(QSize(35, 35));
|
|
|
ui->pushButton_state_LLink->setIconSize(QSize(35, 35));
|
|
|
ui->pushButton_state_3DCamra->setIconSize(QSize(35, 35));
|
|
|
ui->pushButton_state_KuSatelliteComm->setIconSize(QSize(35, 35));
|
|
|
ui->pushButton_state_PDT->setIconSize(QSize(35, 35));
|
|
|
ui->pushButton_state_adHocNetwork->setIconSize(QSize(35, 35));
|
|
|
ui->pushButton_state_rescue->setIconSize(QSize(35, 35));
|
|
|
|
|
|
ui->pushButton_state_GDDC->setToolTip("未知");
|
|
|
ui->pushButton_state_LLink->setToolTip("未知");
|
|
|
ui->pushButton_state_3DCamra->setToolTip("未知");
|
|
|
ui->pushButton_state_KuSatelliteComm->setToolTip("未知");
|
|
|
ui->pushButton_state_PDT->setToolTip("未知");
|
|
|
ui->pushButton_state_adHocNetwork->setToolTip("未知");
|
|
|
ui->pushButton_state_rescue->setToolTip("未知");
|
|
|
|
|
|
ui->lineEdit_1_GDDC->setText("--");
|
|
|
ui->lineEdit_2_GDDC->setText("--");
|
|
|
ui->lineEdit_3_GDDC->setText("--");
|
|
|
ui->lineEdit_1_Llink->setText("--");
|
|
|
ui->lineEdit_2_Llink->setText("--");
|
|
|
ui->lineEdit_3_Llink->setText("--");
|
|
|
ui->lineEdit_1_3DCamra->setText("--");
|
|
|
ui->lineEdit_2_3DCamra->setText("--");
|
|
|
ui->lineEdit_3_3DCamra->setText("--");
|
|
|
ui->lineEdit_1_KuSatelliteComm->setText("--");
|
|
|
ui->lineEdit_2_KuSatelliteComm->setText("--");
|
|
|
ui->lineEdit_3_KuSatelliteComm->setText("--");
|
|
|
ui->lineEdit_1_PDT->setText("--");
|
|
|
ui->lineEdit_2_PDT->setText("--");
|
|
|
ui->lineEdit_3_PDT->setText("--");
|
|
|
ui->lineEdit_1_adHocNetwork->setText("--");
|
|
|
ui->lineEdit_2_adHocNetwork->setText("--");
|
|
|
ui->lineEdit_3_adHocNetwork->setText("--");
|
|
|
ui->lineEdit_1_rescue->setText("--");
|
|
|
ui->lineEdit_2_rescue->setText("--");
|
|
|
ui->lineEdit_3_rescue->setText("--");
|
|
|
|
|
|
m_timer = new QTimer();
|
|
|
m_timer->setInterval(2000);
|
|
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeOut()));
|
|
|
m_timer->start();
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::initParam() {
|
|
|
// 172.10.1.183 -n 2 -w 500"
|
|
|
cmdlist[0] << "/c" << "ping" << "172.10.1.183 -n 2";
|
|
|
cmdlist[1] << "/c" << "ping" << "172.10.1.183 -n 2";
|
|
|
cmdlist[2] << "/c" << "ping" << "www.baidu.com -n 2";
|
|
|
cmdlist[3] << "/c" << "ping" << "www.baidu.com -n 2";
|
|
|
cmdlist[4] << "/c" << "ping" << "www.baidu.com -n 2";
|
|
|
cmdlist[5] << "/c" << "ping" << "www.baidu.com -n 2";
|
|
|
cmdlist[6] << "/c" << "ping" << "www.baidu.com -n 2";
|
|
|
startNetDetn();
|
|
|
}
|
|
|
|
|
|
// 接收线程结果
|
|
|
void deviceStateDlg::receiveResult(int id, QString result,QString delay) {
|
|
|
// qDebug() << result;
|
|
|
switch (id) {
|
|
|
case 0:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_GDDC->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_GDDC->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_GDDC->setToolTip(delay);
|
|
|
break;
|
|
|
case 1:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_LLink->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_LLink->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_LLink->setToolTip(delay);
|
|
|
break;
|
|
|
case 2:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_adHocNetwork->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_adHocNetwork->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_adHocNetwork->setToolTip(delay);
|
|
|
break;
|
|
|
case 3:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_KuSatelliteComm->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_KuSatelliteComm->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_KuSatelliteComm->setToolTip(delay);
|
|
|
break;
|
|
|
case 4:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_3DCamra->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_3DCamra->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_3DCamra->setToolTip(delay);
|
|
|
break;
|
|
|
case 5:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_rescue->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_rescue->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_rescue->setToolTip(delay);
|
|
|
break;
|
|
|
case 6:
|
|
|
if (result == "在线") {
|
|
|
ui->pushButton_state_PDT->setIcon(m_greenIcon);
|
|
|
} else {
|
|
|
ui->pushButton_state_PDT->setIcon(m_redIcon);
|
|
|
}
|
|
|
ui->pushButton_state_PDT->setToolTip(delay);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
// 接收更改的IP
|
|
|
void deviceStateDlg::setDeviceIP(int id, settingStruct param) {
|
|
|
QString strIp;
|
|
|
switch (id) {
|
|
|
case HomePageSetingWidget::GDDC:
|
|
|
strIp = stringIPSelect(param.net.remoteIp);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[0].clear();
|
|
|
cmdlist[0] << strIp;
|
|
|
m_networkDetection[0]->DyChangeCmdList(cmdlist[0]); // 更新到网络检测线程
|
|
|
break;
|
|
|
case HomePageSetingWidget::L_Link:
|
|
|
strIp = stringIPSelect(param.url);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[1].clear();
|
|
|
cmdlist[1] << strIp;
|
|
|
m_networkDetection[1]->DyChangeCmdList(cmdlist[1]); // 更新到网络检测线程
|
|
|
break;
|
|
|
case HomePageSetingWidget::Adhoc_Network:
|
|
|
strIp = stringIPSelect(param.url);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[2].clear();
|
|
|
cmdlist[2] << strIp;
|
|
|
m_networkDetection[2]->DyChangeCmdList(cmdlist[2]); // 更新到网络检测线程
|
|
|
break;
|
|
|
case HomePageSetingWidget::Satelite_Comm:
|
|
|
strIp = stringIPSelect(param.url);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[3].clear();
|
|
|
cmdlist[3] << strIp;
|
|
|
m_networkDetection[3]->DyChangeCmdList(cmdlist[3]); // 更新到网络检测线程
|
|
|
break;
|
|
|
case HomePageSetingWidget::ModelCamera:
|
|
|
strIp = stringIPSelect(param.net.remoteIp);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[4].clear();
|
|
|
cmdlist[4] << strIp;
|
|
|
m_networkDetection[4]->DyChangeCmdList(cmdlist[4]); // 更新到网络检测线程
|
|
|
break;
|
|
|
case HomePageSetingWidget::RescueLoading:
|
|
|
strIp = stringIPSelect(param.url);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[5].clear();
|
|
|
cmdlist[5] << strIp;
|
|
|
m_networkDetection[5]->DyChangeCmdList(cmdlist[5]); // 更新到网络检测线程
|
|
|
break;
|
|
|
case HomePageSetingWidget::PdtLoading:
|
|
|
strIp = stringIPSelect(param.url);
|
|
|
strIp="/c ping " + strIp + " -n 1";
|
|
|
cmdlist[6].clear();
|
|
|
cmdlist[6] << strIp;
|
|
|
m_networkDetection[6]->DyChangeCmdList(cmdlist[6]); // 更新到网络检测线程
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
// 字符串网络地址截取
|
|
|
QString deviceStateDlg::stringIPSelect(QString str) {
|
|
|
int start = -1;
|
|
|
int end = -1;
|
|
|
// str = https://192.168.1.2/22
|
|
|
start = str.indexOf("//");
|
|
|
if (start != -1) {
|
|
|
start += 2;
|
|
|
QString str2 = str.remove(0, start); // 192.168.1.2/224//115
|
|
|
end = str2.indexOf("/");
|
|
|
if (end != -1) {
|
|
|
// end += 1;
|
|
|
str2.truncate(end);
|
|
|
return str2;
|
|
|
} else {
|
|
|
return str2;
|
|
|
}
|
|
|
} else {
|
|
|
end = str.indexOf("/");
|
|
|
if (end != -1) {
|
|
|
// end += 1;
|
|
|
str.truncate(end);
|
|
|
return str;
|
|
|
} else {
|
|
|
return str;
|
|
|
}
|
|
|
}
|
|
|
// index = str.indexOf("http://")
|
|
|
}
|
|
|
// 获得url地址
|
|
|
void deviceStateDlg::setUrl(
|
|
|
std::unordered_map<QString, settingStruct> &urlMap) {
|
|
|
m_urlMap = urlMap;
|
|
|
setDeviceIP(HomePageSetingWidget::GDDC, m_urlMap["Pod"]);
|
|
|
setDeviceIP(HomePageSetingWidget::L_Link, m_urlMap["L-Link"]);
|
|
|
setDeviceIP(HomePageSetingWidget::Adhoc_Network, m_urlMap["HocNetwork"]);
|
|
|
setDeviceIP(HomePageSetingWidget::Satelite_Comm, m_urlMap["SatelliteComm"]);
|
|
|
setDeviceIP(HomePageSetingWidget::ModelCamera, m_urlMap["ModelCamera"]);
|
|
|
setDeviceIP(HomePageSetingWidget::RescueLoading, m_urlMap["RescueLoading"]);
|
|
|
setDeviceIP(HomePageSetingWidget::PdtLoading, m_urlMap["PdtLoading"]);
|
|
|
}
|
|
|
// 开始网络监测
|
|
|
void deviceStateDlg::startNetDetn() {
|
|
|
for (int i = 0; i < deviceNum; ++i) {
|
|
|
m_networkDetection[i] = new networkDetection(NULL,i);
|
|
|
m_workerThread[i] = new QThread();
|
|
|
m_networkDetection[i]->moveToThread(m_workerThread[i]);
|
|
|
m_workerThread[i]->start();
|
|
|
connect(m_networkDetection[i], SIGNAL(resultReady(int,QString,QString)), this,
|
|
|
SLOT(receiveResult(int,QString,QString))); // 接收线程运行结果
|
|
|
connect(this, &deviceStateDlg::startThread, m_networkDetection[i],
|
|
|
&networkDetection::dowork); // 开始线程
|
|
|
connect(this, &deviceStateDlg::stopMyThread, m_networkDetection[i],
|
|
|
&networkDetection::stopwork); // 结束线程
|
|
|
emit startThread(i, cmdlist[i]); // 启用线程信号
|
|
|
qDebug("网络监测线程启动,线程id:%d",i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 停止网络监测
|
|
|
void deviceStateDlg::stopNetDetn() {
|
|
|
for (int i = 0; i < deviceNum; ++i) {
|
|
|
m_networkDetection[i]->stopwork(i);
|
|
|
//emit stopMyThread(i);//信号不起作用
|
|
|
m_workerThread[i]->quit(); // 退出线程请求
|
|
|
m_workerThread[i]->wait(); // 使线程正常退出。
|
|
|
qDebug("网络监测线程结束,线程id:%d",i);
|
|
|
m_workerThread[i]->deleteLater();
|
|
|
m_workerThread[i] = nullptr;
|
|
|
m_networkDetection[i]->deleteLater();
|
|
|
m_networkDetection[i] = nullptr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_GDDC_clicked() {
|
|
|
emit switchToDevicePage(0);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_LLink_clicked() {
|
|
|
emit switchToDevicePage(1);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_adHocNetwork_clicked() {
|
|
|
emit switchToDevicePage(2);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_rescue_clicked() {
|
|
|
emit switchToDevicePage(5);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_PDT_clicked() {
|
|
|
emit switchToDevicePage(3);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_3DCamra_clicked() {
|
|
|
emit switchToDevicePage(6);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::on_pushButton_homePage_KuSatelliteComm_clicked() {
|
|
|
emit switchToDevicePage(4);
|
|
|
}
|
|
|
|
|
|
void deviceStateDlg::onTimeOut() {
|
|
|
// QProcess *m_process = new QProcess();
|
|
|
|
|
|
// QStringList m_cmd;
|
|
|
// // m_cmd << "/c" << "ping" << "baidu.com -n 2 -w 1000";
|
|
|
// m_cmd << "/c" << "ping" << "172.10.1.183";
|
|
|
// QString result;
|
|
|
// m_process->start("cmd", m_cmd);
|
|
|
// m_process->waitForFinished(); // 等待指令执行完毕
|
|
|
// result = m_process->readAll(); // 获取指令执行结果
|
|
|
// qDebug() << result;
|
|
|
// if (result.contains(QString("TTL="))) // 若包含TTL=字符串则认为网络在线
|
|
|
// {
|
|
|
// qDebug() << "在线";
|
|
|
// ui->pushButton_state_GDDC->setIcon(QIcon(":/res/lamp/green.png"));
|
|
|
|
|
|
// } else {
|
|
|
// qDebug() << "离线";
|
|
|
// ui->pushButton_state_GDDC->setIcon(QIcon(":/res/lamp/red.png"));
|
|
|
// }
|
|
|
// m_process->kill();
|
|
|
}
|