#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"; cmdlist[1] << "/c" << "ping" << "172.10.1.183"; cmdlist[2] << "/c" << "ping" << "www.baidu.com"; cmdlist[3] << "/c" << "ping" << "www.baidu.com"; cmdlist[4] << "/c" << "ping" << "www.baidu.com"; 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; default: break; } } // 接收更改的IP void deviceStateDlg::setDeviceIP(int id, settingStruct param) { QString strIp; switch (id) { case HomePageSetingWidget::GDDC: strIp = stringIPSelect(param.net.remoteIp); cmdlist[0].clear(); cmdlist[0] << "/c" << "ping" << strIp; m_networkDetection[0]->DyChangeCmdList(cmdlist[0]); // 更新到网络检测线程 break; case HomePageSetingWidget::L_Link: strIp = stringIPSelect(param.url); cmdlist[1].clear(); cmdlist[1] << "/c" << "ping" << strIp; m_networkDetection[1]->DyChangeCmdList(cmdlist[1]); // 更新到网络检测线程 break; case HomePageSetingWidget::Adhoc_Network: strIp = stringIPSelect(param.url); cmdlist[2].clear(); cmdlist[2] << "/c" << "ping" << strIp; m_networkDetection[2]->DyChangeCmdList(cmdlist[2]); // 更新到网络检测线程 break; case HomePageSetingWidget::Satelite_Comm: strIp = stringIPSelect(param.url); cmdlist[3].clear(); cmdlist[3] << "/c" << "ping" << strIp; m_networkDetection[3]->DyChangeCmdList(cmdlist[3]); // 更新到网络检测线程 break; case HomePageSetingWidget::ModelCamera: strIp = stringIPSelect(param.net.remoteIp); cmdlist[4].clear(); cmdlist[4] << "/c" << "ping" << strIp; m_networkDetection[4]->DyChangeCmdList(cmdlist[4]); // 更新到网络检测线程 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 &urlMap) { m_urlMap = urlMap; setDeviceIP(HomePageSetingWidget::GDDC, m_urlMap["光电吊舱"]); setDeviceIP(HomePageSetingWidget::L_Link, m_urlMap["L链"]); setDeviceIP(HomePageSetingWidget::Adhoc_Network, m_urlMap["宽带自组网"]); setDeviceIP(HomePageSetingWidget::Satelite_Comm, m_urlMap["机载卫通"]); setDeviceIP(HomePageSetingWidget::ModelCamera, m_urlMap["三维建模"]); } // 开始网络监测 void deviceStateDlg::startNetDetn() { for (int i = 0; i < deviceNum; ++i) { m_networkDetection[i] = new networkDetection(); 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))); // 接收线程运行结果 switch (i) { case 0: connect(this, &deviceStateDlg::startThread0, m_networkDetection[i], &networkDetection::dowork); // 光电吊舱 线程开始处理数据 emit startThread0(i, cmdlist[i]); // 启用线程信号 break; case 1: connect(this, &deviceStateDlg::startThread1, m_networkDetection[i], &networkDetection::dowork); // L链路 线程开始处理数据 emit startThread1(i, cmdlist[i]); // 启用线程信号 break; case 2: connect(this, &deviceStateDlg::startThread2, m_networkDetection[i], &networkDetection::dowork); // 自组网 线程开始处理数据 emit startThread2(i, cmdlist[i]); // 启用线程信号 break; case 3: connect(this, &deviceStateDlg::startThread3, m_networkDetection[i], &networkDetection::dowork); // ku卫通 线程开始处理数据 emit startThread3(i, cmdlist[i]); // 启用线程信号 break; case 4: connect(this, &deviceStateDlg::startThread4, m_networkDetection[i], &networkDetection::dowork); // 线程开始处理数据 emit startThread4(i, cmdlist[i]); // 启用线程信号 break; default: break; } } } // 停止网络监测 void deviceStateDlg::stopNetDetn() { for (int i = 0; i < deviceNum; ++i) { m_networkDetection[i]->stop(); // 线程退出循环 m_workerThread[i]->quit(); // 退出线程请求 m_workerThread[i]->wait(); // 使线程正常退出。 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(); }