From d145c6128e309e543108ec90fec13358a1b9a5d2 Mon Sep 17 00:00:00 2001 From: gangphon Date: Wed, 28 Sep 2022 18:21:57 +0800 Subject: [PATCH] =?UTF-8?q?ledok=20=E4=BF=AE=E6=94=B9=E6=8C=87=E5=AE=9Aip?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LedOK/LedOK.pro | 5 - LedOK/communication/network.cpp | 126 --------- LedOK/communication/network.h | 41 --- LedOK/devicepanel.cpp | 256 ++++++++++++++---- LedOK/devicepanel.h | 17 +- LedOK/globaldefine.cpp | 6 +- LedOK/mainwindow.cpp | 10 +- LedOK/mguangyingpinwidget.cpp | 42 +-- LedOK/wDevicesManager/controlhdmiwidget.cpp | 2 + LedOK/wDevicesManager/controlhdmiwidget.ui | 157 ----------- .../{specialdlg.cpp => specialdlg - 副本.cpp} | 8 +- .../{specialdlg.h => specialdlg - 副本.h} | 3 +- LedOK/wDevicesManager/upgradeapkdialog.cpp | 16 +- LedOK/wProgramManager/sendprogramdialog.cpp | 7 +- 14 files changed, 249 insertions(+), 447 deletions(-) delete mode 100644 LedOK/communication/network.cpp delete mode 100644 LedOK/communication/network.h delete mode 100644 LedOK/wDevicesManager/controlhdmiwidget.ui rename LedOK/wDevicesManager/{specialdlg.cpp => specialdlg - 副本.cpp} (88%) rename LedOK/wDevicesManager/{specialdlg.h => specialdlg - 副本.h} (64%) diff --git a/LedOK/LedOK.pro b/LedOK/LedOK.pro index 1ac2109..9e543a0 100644 --- a/LedOK/LedOK.pro +++ b/LedOK/LedOK.pro @@ -62,7 +62,6 @@ SOURCES += \ basewin.cpp \ cfg.cpp \ communication/hpptclient.cpp \ - communication/network.cpp \ communication/taserialthread.cpp \ devicectrlpanel.cpp \ deviceitem.cpp \ @@ -106,7 +105,6 @@ SOURCES += \ wDevicesManager/ctrladvancedpanel.cpp \ wDevicesManager/ctrlbrightpanel.cpp \ wDevicesManager/ledcard.cpp \ - wDevicesManager/specialdlg.cpp \ wDevicesManager/threadupgradeapk.cpp \ wDevicesManager/upgradeapkdialog.cpp \ wDevicesManager/wupgradeapkitem.cpp \ @@ -164,7 +162,6 @@ HEADERS += \ basewin.h \ cfg.h \ communication/hpptclient.h \ - communication/network.h \ communication/taserialthread.h \ devicectrlpanel.h \ deviceitem.h \ @@ -207,7 +204,6 @@ HEADERS += \ wDevicesManager/ctrladvancedpanel.h \ wDevicesManager/ctrlbrightpanel.h \ wDevicesManager/ledcard.h \ - wDevicesManager/specialdlg.h \ wDevicesManager/threadupgradeapk.h \ wDevicesManager/upgradeapkdialog.h \ wDevicesManager/wupgradeapkitem.h \ @@ -247,7 +243,6 @@ FORMS += \ tipdialog.ui \ wDevicesManager/controlencryptwidget.ui \ wDevicesManager/controlhdmischedule.ui \ - wDevicesManager/controlhdmiwidget.ui \ wDevicesManager/controlpowermanual.ui \ wDevicesManager/controlpowerschedule.ui \ wDevicesManager/controlpowerwidget.ui \ diff --git a/LedOK/communication/network.cpp b/LedOK/communication/network.cpp deleted file mode 100644 index 0e2bf9e..0000000 --- a/LedOK/communication/network.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "network.h" -#include -#include -#include "string" -#include -#include -#include -#include - -NetComm::NetComm(QObject *p) : QObject(p) { -} - -STREAM_PACKET NetComm::LedOkMakeStreamPacket(int iComType,int iLen,unsigned char *ucBuf,QString str) -{ - STREAM_PACKET Temp; - memset(&Temp,0x00,sizeof(STREAM_PACKET)); - if(iLen>2048) - return Temp; - memset(Temp.SyncHead,STREAM_SYNC_HEAD,STREAM_SYNC_HEAD_NUM); - memset(Temp.ucSerialCode,0x00,20); - char* ch; - QByteArray ba = str.toLatin1(); // must - ch=ba.data(); - memcpy(Temp.ucSerialCode,ch,ba.size()); - Temp.iLength=iLen; - Temp.ucCommType=iComType; - memcpy(Temp.pDataBuffer,ucBuf,iLen); - Temp.pDataBuffer[Temp.iLength]= - GetCheckCodeIn8(&Temp.ucCommType,Temp.iLength+sizeof(Temp.ucCommType)+sizeof(char)*20+sizeof(Temp.iLength)); - return Temp; -} -void NetComm::RestoreLedCardIpByUdpCmd() { - //UDP多网卡广播 - QList networkinterfaces = QNetworkInterface::allInterfaces(); - foreach (QNetworkInterface interfaces, networkinterfaces) //networkinterfaces负责提供主机的IP地址和网络接口的列表 - { - { - foreach (QNetworkAddressEntry entry, interfaces.addressEntries())//QNetworkAddressEntry存储了一个IP地址,子网掩码和广播地址 - { - entry.setBroadcast(QHostAddress::Broadcast); - QHostAddress broadcastAddress("255.255.255.255"); - { - entry.setBroadcast(QHostAddress::Broadcast); - - RESTORE_IP stTempIp; - memset(&stTempIp,0x00,sizeof(RESTORE_IP)); - - QString strNew=entry.ip().toString(); - int itempOffset = strNew.lastIndexOf("."); - QString sstrNew=strNew.left(itempOffset)+".254"; - if(sstrNew.length()<=20) - memcpy(stTempIp.cNewIp,sstrNew.toLatin1().data(),sstrNew.length()); - QString strMask=entry.netmask().toString(); - if(strMask.length()<=20) - memcpy(stTempIp.cMask,strMask.toLatin1().data(),strMask.length()); - QString strGateway=entry.ip().toString(); - if(strGateway.length()<=20) - memcpy(stTempIp.cGateway,strGateway.toLatin1().data(),strGateway.length()); - if(strGateway.length()<=20) - memcpy(stTempIp.cDns,strGateway.toLatin1().data(),strGateway.length()); - STREAM_PACKET tempStreadPacket=LedOkMakeStreamPacket(COMMAND_ONLY_RESET_CARD_IP,80,(unsigned char *)&stTempIp,"Broadcast!"); - int iLenPacket=tempStreadPacket.iLength+sizeof(int)+STREAM_SYNC_HEAD_NUM*sizeof(unsigned char)+sizeof(char)+20*sizeof(char)+sizeof(char);/////除正文外的协议结构大小; - QUdpSocket *tempUdpSocket= new QUdpSocket(this); - if(!tempUdpSocket->bind(entry.ip())) break; - tempUdpSocket->writeDatagram((char *)&tempStreadPacket,iLenPacket,broadcastAddress,m_port); - } - } - } - } -} - -void NetComm::JieXiQJsonObjectOfLedCardInfoOld(const QString &strId,const QString &strIp){ - LedCard *pLedCard = new LedCard(this);//alahover 没有释放 - pLedCard->m_strCardId=strId; - pLedCard->m_strCardIp=strIp; - for(int i=0;im_strCardId==pLedCard->m_strCardId ) {//如果已经存在在列表中 - auto pOldLedCard = LedCardList.at(i);//获取到旧的对象指针 - pOldLedCard->m_bOnLine = true; - if(pOldLedCard->CompareHTTPGetParam(pLedCard)==false) {//如果ip地址变化了 - pOldLedCard->copyLedCardHTTPGetParam(pLedCard); - emit addLedCard(pOldLedCard);//发送信号到界面 - } else { - //post失败的概率比较小,所以这里是否需要平凡的更新,不需要刻意屏蔽该操作改为在其他点击操作中进行 - emit ClearHeartbeatFlagByUdp(pOldLedCard); - } - delete pLedCard; - return; - } - LedCardList.append(pLedCard); - emit addLedCard(pLedCard);//发送信号到界面 -} - -void NetComm::JieXiQJsonObjectOfLedCardInfo(const QJsonObject &subObj, const QString &strIp){ - LedCard *pLedCard = new LedCard(this);//alahover 没有释放 - pLedCard->m_strCardId=subObj["cardId"].toString(); - if(! strIp.isEmpty()) pLedCard->m_strCardIp = strIp; - else { - pLedCard->m_strCardIp = subObj["newIp"].toString(); - if(pLedCard->m_strCardIp.isEmpty()) pLedCard->m_strCardIp = subObj["ip"].toString(); - } - pLedCard->m_iWidth=subObj["width"].toInt(); - pLedCard->m_iHeight=subObj["height"].toInt(); - pLedCard->starterversionName=subObj["versionName"].toString(); - pLedCard->starterPort=subObj["starterPort"].toInt(); - pLedCard->androidVersion=subObj["androidVersion"].toString(); - pLedCard->iHttpGetId=subObj["id"].toInt(); - pLedCard->androidHeight=subObj["androidHeight"].toInt(); - pLedCard->androidWidth=subObj["androidWidth"].toInt(); - pLedCard->lastActive=subObj["lastActive"].toInt(); - - for(int i=0;im_strCardId==pLedCard->m_strCardId ) { //如果已经存在在列表中 - auto pOldLedCard = LedCardList.at(i);//获取到旧的对象指针 - pOldLedCard->m_bOnLine = true; - if(! pOldLedCard->CompareHTTPGetParam(pLedCard)) {//如果ip地址变化了 - pOldLedCard->copyLedCardHTTPGetParam(pLedCard); - emit addLedCard(pOldLedCard);//发送信号到界面 - } else { - //post失败的概率比较小,所以这里是否需要平凡的更新,不需要刻意屏蔽该操作改为在其他点击操作中进行 - emit ClearHeartbeatFlagByUdp(pOldLedCard); - } - delete pLedCard; - return; - } - LedCardList.append(pLedCard); - emit addLedCard(pLedCard);//发送信号到界面 -} diff --git a/LedOK/communication/network.h b/LedOK/communication/network.h deleted file mode 100644 index ed7edff..0000000 --- a/LedOK/communication/network.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef NETWORK_H -#define NETWORK_H -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class NetComm : public QObject { - Q_OBJECT -public: - NetComm(QObject *p = nullptr); - STREAM_PACKET LedOkMakeStreamPacket(int iComType,int iLen,unsigned char *ucBuf,QString str); - - static DWORD WINAPI send(void *); - - void JieXiQJsonObjectOfLedCardInfo(const QJsonObject &subObj,const QString &strIp); - void JieXiQJsonObjectOfLedCardInfoOld(const QString &strId,const QString &strIp); - - QList LedCardList; - QTimer mUdpTimer; - QUdpSocket mUdpSocket; -signals: - void addLedCard(LedCard *); - void ClearHeartbeatFlagByUdp(LedCard *); -public slots: - void RestoreLedCardIpByUdpCmd(); -private: - QString m_strCardId; - qint32 m_iWidth; - LedCard *m_pLedCard; - int m_port = 31296; -}; - -extern NetComm *gUdp; - -#endif // NETWORK_H diff --git a/LedOK/devicepanel.cpp b/LedOK/devicepanel.cpp index 57d09eb..3df7f42 100644 --- a/LedOK/devicepanel.cpp +++ b/LedOK/devicepanel.cpp @@ -1,18 +1,19 @@ #include "devicepanel.h" #include "devicectrlpanel.h" #include "tools.h" -#include "communication/network.h" -#include "wDevicesManager/specialdlg.h" +#include "gqt.h" #include #include #include #include #include #include +#include +#include +#include DevicePanel *gDevicePanel; QList *gSelCards; -NetComm *gUdp; //设备管理响应页面 DevicePanel::DevicePanel(QWidget *parent) : QWidget(parent) { gDevicePanel = this; @@ -68,10 +69,54 @@ DevicePanel::DevicePanel(QWidget *parent) : QWidget(parent) { bnSpecifyIP->setGeometry(0, 0, areaFlash->width(), areaFlash->height()); bnSpecifyIP->setItemDelegate(new QStyledItemDelegate); connect(bnSpecifyIP, &QComboBox::textActivated, this, [this] { - pNetComm->mUdpTimer.stop(); - SpecialDlg pDlg(this, pNetComm); - pDlg.exec(); - pNetComm->mUdpTimer.start(30000); + if(specifyIPDlg==0) { + specifyIPDlg = new QDialog(this); + specifyIPDlg->setWindowTitle(tr("Specify IP")); + + auto vBox = new VBox(specifyIPDlg); + vBox->addStretch(); + + auto label = new QLabel(tr("Specify IP list")); + label->setAlignment(Qt::AlignCenter); + vBox->addWidget(label); + + fdIP = new QTextEdit(QSettings().value("SpecifyIP").toString()); + fdIP->setPlaceholderText("192.168.1.1\n192.168.1.2\n ..."); + fdIP->setMinimumWidth(160); + vBox->addWidget(fdIP); + + auto hBox = new HBox(vBox); + hBox->addStretch(); + + auto bnSearch = new QPushButton(tr("Search")); + connect(bnSearch, &QPushButton::clicked, this, [this] { + QString ipsStr = fdIP->toPlainText(); + if(ipsStr.isEmpty()) { + QMessageBox::warning(gMainWin, tr("Attention"), tr("Please input IP address!")); + return; + } + auto ips = ipsStr.split("\n", Qt::SkipEmptyParts); + if(ips.isEmpty()) { + QMessageBox::warning(gMainWin, tr("Attention"), tr("Please input IP address!")); + return; + } + QByteArray data = QJsonDocument({{"action", "getInfo"}}).toJson(QJsonDocument::Compact); + foreach(auto ip, ips) { + if(gDevicePanel->mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "Specify IP write Failed." << ip; + } + specifyIPDlg->accept(); + }); + hBox->addWidget(bnSearch); + + auto btnCancel = new QPushButton(tr("Cancel")); + connect(btnCancel, &QPushButton::clicked, specifyIPDlg, &QDialog::reject); + hBox->addWidget(btnCancel); + + hBox->addStretch(); + } + mUdpTimer.stop(); + specifyIPDlg->exec(); + mUdpTimer.start(30000); }); bnSpecifyIP->setStyleSheet(R"rrr( QComboBox { @@ -89,16 +134,16 @@ QComboBox QAbstractItemView::item { QComboBox QAbstractItemView::item:selected {background-color: #09c;} )rrr"); - btnRefrash = new QPushButton(tr("Refresh"), areaFlash); - btnRefrash->setGeometry(0, 0, 75, areaFlash->height()); - connect(btnRefrash, &QPushButton::clicked, this, [this] { - pNetComm->LedCardList.clear(); + btnRefresh = new QPushButton(tr("Refresh"), areaFlash); + btnRefresh->setGeometry(0, 0, 75, areaFlash->height()); + connect(btnRefresh, &QPushButton::clicked, this, [this] { + LedCardList.clear(); mDeviceTable->onCheckAll(false); mDeviceTable->clear(); nDeviceNum->setText("0"); sendGetInfo(); }); - btnRefrash->setStyleSheet(R"rrr( + btnRefresh->setStyleSheet(R"rrr( QPushButton { border-radius: 5px; background-color: #19c; @@ -120,14 +165,12 @@ QPushButton:hover {background-color: #08b;} vBox->addLayout(mHBox); - pNetComm = new NetComm(this); - connect(&pNetComm->mUdpTimer, &QTimer::timeout, this, &DevicePanel::sendGetInfo); - connect(&pNetComm->mUdpSocket, &QUdpSocket::readyRead, this, [this] { - while(pNetComm->mUdpSocket.hasPendingDatagrams()) { - auto gram = pNetComm->mUdpSocket.receiveDatagram(); + connect(&mUdpTimer, &QTimer::timeout, this, &DevicePanel::sendGetInfo); + connect(&mUdpSocket, &QUdpSocket::readyRead, this, [this] { + while(mUdpSocket.hasPendingDatagrams()) { + auto gram = mUdpSocket.receiveDatagram(); auto data = gram.data(); if(data.isEmpty()) continue; - qDebug() << "data" << data; auto senderAddress = gram.senderAddress(); bool ok = true; if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok)); @@ -139,42 +182,31 @@ QPushButton:hover {background-color: #08b;} qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误!"; continue; } - pNetComm->JieXiQJsonObjectOfLedCardInfo(document.object(), addr); + parseInfo(document.object(), addr); } else { STREAM_PACKET *pStreamPacket = (STREAM_PACKET *)gram.data().data(); - pNetComm->JieXiQJsonObjectOfLedCardInfoOld(pStreamPacket->ucSerialCode, addr); + LedCard *pLedCard = new LedCard(this);//alahover 没有释放 + pLedCard->m_strCardId = pStreamPacket->ucSerialCode; + pLedCard->m_strCardIp = addr; + for(int i=0;im_strCardId==pLedCard->m_strCardId ) {//如果已经存在在列表中 + auto pOldLedCard = LedCardList.at(i);//获取到旧的对象指针 + pOldLedCard->m_bOnLine = true; + if(pOldLedCard->CompareHTTPGetParam(pLedCard)==false) {//如果ip地址变化了 + pOldLedCard->copyLedCardHTTPGetParam(pLedCard); + emit addLedCard(pOldLedCard);//发送信号到界面 + } else { + //post失败的概率比较小,所以这里是否需要平凡的更新,不需要刻意屏蔽该操作改为在其他点击操作中进行 + emit clearUdpHeartbeat(pOldLedCard); + } + delete pLedCard; + return; + } + LedCardList.append(pLedCard); + emit addLedCard(pLedCard);//发送信号到界面 } } }); - gUdp = pNetComm; - connect(pNetComm, &NetComm::addLedCard, this, [this](LedCard *p){ - int cnt = mDeviceTable->topLevelItemCount(); - for(int i=0; i(mDeviceTable->topLevelItem(i)); - if(item->m_pLedCard->m_strCardId != p->m_strCardId) continue; - item->setData(DeviceTable_ID, 0, p->m_strCardId); - item->setData(DeviceTable_IP, 0, p->m_strCardIp); - item->setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(p->m_iWidth).arg(p->m_iHeight)); - return; - } - new DeviceItem(p, mDeviceTable, this); - nDeviceNum->setText(QString::number(mDeviceTable->topLevelItemCount())); - }); - connect(pNetComm, &NetComm::ClearHeartbeatFlagByUdp, this, [this](LedCard *p) { - int cnt = mDeviceTable->topLevelItemCount(); - for(int i=0; i(mDeviceTable->topLevelItem(i)); - if(item->m_pLedCard->m_strCardId != p->m_strCardId) continue; - item->m_HeartbeatCount = 0; - if(item->m_ImageOnline) { - item->m_pLedCard->m_bOnLine = true; - item->m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png")); - } - return; - } - }); - m_headerItem = new QTreeWidgetItem(); for(int i=1; isetTextAlignment(i, Qt::AlignCenter); mDeviceTable->setHeaderItem(m_headerItem); @@ -203,20 +235,20 @@ QPushButton:hover {background-color: #08b;} //开始轮训查找局域网内的控制卡 sendGetInfo(); - pNetComm->mUdpTimer.start(30000); + mUdpTimer.start(30000); mDeviceTable->hideColumn(0); mDeviceTable->fdIsSelAll->hide(); transUi(); } DevicePanel::~DevicePanel() { - pNetComm->mUdpSocket.close(); - pNetComm->mUdpTimer.stop(); + mUdpSocket.close(); + mUdpTimer.stop(); } void DevicePanel::sendGetInfo() { QByteArray data = QJsonDocument({{"action", "getInfo"}}).toJson(QJsonDocument::Compact); -// if(pNetComm->mUdpSocket.writeDatagram(data, QHostAddress("255.255.255.255"), 22222) != data.length()) { +// if(mUdpSocket.writeDatagram(data, QHostAddress("255.255.255.255"), 22222) != data.length()) { // qDebug() << "getInfo writeDatagram to 255.255.255.255 Failed"; // } QList networkinterfaces = QNetworkInterface::allInterfaces(); @@ -230,7 +262,7 @@ void DevicePanel::sendGetInfo() { auto ip = addrEntry.ip(); if(ip.protocol()!=QAbstractSocket::IPv4Protocol) continue; auto broadcast = addrEntry.broadcast(); - if(pNetComm->mUdpSocket.writeDatagram(data, broadcast, 22222) != data.length()) qDebug() << "getInfo writeDatagram Failed." << ip.toString() << "->" << broadcast.toString(); + if(mUdpSocket.writeDatagram(data, broadcast, 22222) != data.length()) qDebug() << "getInfo writeDatagram Failed." << ip.toString() << "->" << broadcast.toString(); } } } @@ -266,7 +298,7 @@ void DevicePanel::changeEvent(QEvent *event) { if(event->type() == QEvent::LanguageChange) transUi(); } void DevicePanel::transUi() { - btnRefrash->setText(tr("Refresh")); + btnRefresh->setText(tr("Refresh")); bnSpecifyIP->setItemText(0,tr("Specify IP")); label_3->setText(tr("All")); @@ -348,12 +380,7 @@ void DevicePanel::FilterProgram(const QString &strtemp){ void DevicePanel::OnControlTcpSend(int iProgramIndex){ int cnt = mDeviceTable->topLevelItemCount(); - QList list; - int iSelectCount=0; - for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) { - iSelectCount++; - static_cast(mDeviceTable->topLevelItem(i))->OnControlTcpSend(iProgramIndex); - } + for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) static_cast(mDeviceTable->topLevelItem(i))->OnControlTcpSend(iProgramIndex); } void DevicePanel::OnControlSendJson(QJsonObject &json,QString strFanYi){ @@ -387,3 +414,112 @@ void DevicePanel::onCheckStateChanged(int f){ emit sigSelectedDeviceList(&mSelCards); } } +void DevicePanel::addLedCard(LedCard *p){ + int cnt = mDeviceTable->topLevelItemCount(); + for(int i=0; i(mDeviceTable->topLevelItem(i)); + if(item->m_pLedCard->m_strCardId != p->m_strCardId) continue; + item->setData(DeviceTable_ID, 0, p->m_strCardId); + item->setData(DeviceTable_IP, 0, p->m_strCardIp); + item->setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(p->m_iWidth).arg(p->m_iHeight)); + return; + } + new DeviceItem(p, mDeviceTable, this); + nDeviceNum->setText(QString::number(mDeviceTable->topLevelItemCount())); +} +void DevicePanel::clearUdpHeartbeat(LedCard *p) { + int cnt = mDeviceTable->topLevelItemCount(); + for(int i=0; i(mDeviceTable->topLevelItem(i)); + if(item->m_pLedCard->m_strCardId != p->m_strCardId) continue; + item->m_HeartbeatCount = 0; + if(item->m_ImageOnline) { + item->m_pLedCard->m_bOnLine = true; + item->m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png")); + } + return; + } +} + +void DevicePanel::parseInfo(const QJsonObject &subObj, const QString &strIp) { + LedCard *pLedCard = new LedCard(this);//alahover 没有释放 + pLedCard->m_strCardId=subObj["cardId"].toString(); + if(! strIp.isEmpty()) pLedCard->m_strCardIp = strIp; + else { + pLedCard->m_strCardIp = subObj["newIp"].toString(); + if(pLedCard->m_strCardIp.isEmpty()) pLedCard->m_strCardIp = subObj["ip"].toString(); + } + pLedCard->m_iWidth=subObj["width"].toInt(); + pLedCard->m_iHeight=subObj["height"].toInt(); + pLedCard->starterversionName=subObj["versionName"].toString(); + pLedCard->starterPort=subObj["starterPort"].toInt(); + pLedCard->androidVersion=subObj["androidVersion"].toString(); + pLedCard->iHttpGetId=subObj["id"].toInt(); + pLedCard->androidHeight=subObj["androidHeight"].toInt(); + pLedCard->androidWidth=subObj["androidWidth"].toInt(); + pLedCard->lastActive=subObj["lastActive"].toInt(); + + for(int i=0;im_strCardId==pLedCard->m_strCardId ) { //如果已经存在在列表中 + auto pOldLedCard = LedCardList.at(i);//获取到旧的对象指针 + pOldLedCard->m_bOnLine = true; + if(! pOldLedCard->CompareHTTPGetParam(pLedCard)) {//如果ip地址变化了 + pOldLedCard->copyLedCardHTTPGetParam(pLedCard); + addLedCard(pOldLedCard);//发送信号到界面 + } else { + //post失败的概率比较小,所以这里是否需要平凡的更新,不需要刻意屏蔽该操作改为在其他点击操作中进行 + clearUdpHeartbeat(pOldLedCard); + } + delete pLedCard; + return; + } + LedCardList.append(pLedCard); + addLedCard(pLedCard);//发送信号到界面 +} + +STREAM_PACKET LedOkMakeStreamPacket(int iComType,int iLen,unsigned char *ucBuf,QString str) { + STREAM_PACKET Temp; + memset(&Temp, 0, sizeof(STREAM_PACKET)); + if(iLen>2048) return Temp; + memset(Temp.SyncHead,STREAM_SYNC_HEAD,STREAM_SYNC_HEAD_NUM); + memset(Temp.ucSerialCode,0x00,20); + char* ch; + QByteArray ba = str.toLatin1(); // must + ch=ba.data(); + memcpy(Temp.ucSerialCode,ch,ba.size()); + Temp.iLength=iLen; + Temp.ucCommType=iComType; + memcpy(Temp.pDataBuffer,ucBuf,iLen); + Temp.pDataBuffer[Temp.iLength] = GetCheckCodeIn8(&Temp.ucCommType,Temp.iLength+sizeof(Temp.ucCommType)+sizeof(char)*20+sizeof(Temp.iLength)); + return Temp; +} +//UDP多网卡广播 +void DevicePanel::RestoreLedCardIpByUdpCmd() { + QList networkinterfaces = QNetworkInterface::allInterfaces(); + foreach (QNetworkInterface interfaces, networkinterfaces) {//networkinterfaces负责提供主机的IP地址和网络接口的列表 + foreach (QNetworkAddressEntry entry, interfaces.addressEntries()) {//QNetworkAddressEntry存储了一个IP地址,子网掩码和广播地址 + entry.setBroadcast(QHostAddress::Broadcast); + QHostAddress broadcastAddress("255.255.255.255"); + entry.setBroadcast(QHostAddress::Broadcast); + RESTORE_IP stTempIp; + memset(&stTempIp,0x00,sizeof(RESTORE_IP)); + QString strNew=entry.ip().toString(); + int itempOffset = strNew.lastIndexOf("."); + QString sstrNew=strNew.left(itempOffset)+".254"; + if(sstrNew.length()<=20) memcpy(stTempIp.cNewIp,sstrNew.toLatin1().data(),sstrNew.length()); + QString strMask=entry.netmask().toString(); + if(strMask.length()<=20) + memcpy(stTempIp.cMask,strMask.toLatin1().data(),strMask.length()); + QString strGateway=entry.ip().toString(); + if(strGateway.length()<=20) + memcpy(stTempIp.cGateway,strGateway.toLatin1().data(),strGateway.length()); + if(strGateway.length()<=20) + memcpy(stTempIp.cDns,strGateway.toLatin1().data(),strGateway.length()); + STREAM_PACKET tempStreadPacket = LedOkMakeStreamPacket(COMMAND_ONLY_RESET_CARD_IP, 80, (unsigned char *)&stTempIp,"Broadcast!"); + int iLenPacket=tempStreadPacket.iLength+sizeof(int)+STREAM_SYNC_HEAD_NUM*sizeof(unsigned char)+sizeof(char)+20*sizeof(char)+sizeof(char);/////除正文外的协议结构大小; + QUdpSocket *tempUdpSocket = new QUdpSocket(this); + if(!tempUdpSocket->bind(entry.ip())) break; + tempUdpSocket->writeDatagram((char *)&tempStreadPacket,iLenPacket,broadcastAddress, 31296); + + } + } +} diff --git a/LedOK/devicepanel.h b/LedOK/devicepanel.h index 5e920af..2dd5d45 100644 --- a/LedOK/devicepanel.h +++ b/LedOK/devicepanel.h @@ -2,16 +2,15 @@ #define DEVICEPANEL_H #include "deviceitem.h" -#include #include #include #include #include -#include +#include #include #include #include -#include +#include class DeviceCtrlPanel; class DevicePanel : public QWidget { @@ -24,7 +23,15 @@ public: QLabel *fdCardNumInfo; LoQTreeWidget *mDeviceTable; - NetComm *pNetComm; + QUdpSocket mUdpSocket; + QTimer mUdpTimer; + QDialog *specifyIPDlg{0}; + QTextEdit *fdIP{0}; + void addLedCard(LedCard *); + void clearUdpHeartbeat(LedCard *); + void parseInfo(const QJsonObject &subObj,const QString &strIp); + void RestoreLedCardIpByUdpCmd(); + QList LedCardList; protected: void changeEvent(QEvent *) override; void transUi(); @@ -42,7 +49,7 @@ signals: private: QLabel *label_3, *nDeviceNum; QComboBox *bnSpecifyIP; - QPushButton *btnRefrash; + QPushButton *btnRefresh; QTreeWidgetItem *m_headerItem; QHBoxLayout *mHBox{0}; DeviceCtrlPanel *mDeviceCtrlPanel{0}; diff --git a/LedOK/globaldefine.cpp b/LedOK/globaldefine.cpp index 4ed6f06..f4bf200 100644 --- a/LedOK/globaldefine.cpp +++ b/LedOK/globaldefine.cpp @@ -157,9 +157,9 @@ bool copyDir(const QString &source, const QString &destination, bool override) return !error; } -unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize) -{ unsigned int i=0; - unsigned char ucCheckCode=0; +unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize) { + unsigned int i=0; + unsigned char ucCheckCode=0; for (i=0;i #include #include +#include QWidget *gMainWin; extern QPoint gPlayPos; @@ -271,7 +272,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) { curIndex = id; if(curIndex == MainPage_DeviceManager || curIndex == MainPage_Setting) { //开启UDP定时器 - gUdp->mUdpTimer.start(60000); + mDevicePanel->mUdpTimer.start(60000); int cnt = mDevicePanel->mDeviceTable->topLevelItemCount(); for(int i=0; i(mDevicePanel->mDeviceTable->topLevelItem(i)); @@ -289,7 +290,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) { m_pOneKeyCheckCard->setProperty("ssType", "progManageTool"); connect(m_pOneKeyCheckCard, &QPushButton::clicked, this, [this] { auto res = QMessageBox::warning(this, tr("Tip Info"), tr("RestoreLedCardIpByUdpTip"), QMessageBox::Ok, QMessageBox::Cancel); - if(res == QMessageBox::Ok) mDevicePanel->pNetComm->RestoreLedCardIpByUdpCmd(); + if(res == QMessageBox::Ok) mDevicePanel->RestoreLedCardIpByUdpCmd(); }); hBox->addWidget(m_pOneKeyCheckCard); hBox->addStretch(); @@ -396,7 +397,10 @@ MainWindow::~MainWindow() { settings.setValue("MainGeo", normalGeometry()); settings.setValue("MainIsMax", isMaximized()); settings.setValue("PlayPos", gPlayPos); - + if(mDevicePanel->fdIP) { + auto ips = mDevicePanel->fdIP->toPlainText(); + if(! ips.isEmpty()) settings.setValue("SpecifyIP", ips); + } if(m_pTimerSendResoreIpOneKey!=nullptr) { if(m_pTimerSendResoreIpOneKey->isActive()) m_pTimerSendResoreIpOneKey->stop(); delete m_pTimerSendResoreIpOneKey; diff --git a/LedOK/mguangyingpinwidget.cpp b/LedOK/mguangyingpinwidget.cpp index ab0130f..f7425e2 100644 --- a/LedOK/mguangyingpinwidget.cpp +++ b/LedOK/mguangyingpinwidget.cpp @@ -765,35 +765,23 @@ void mGuangYingPinWidget::MWSendCmdByUdp(unsigned char cmd,unsigned char *pUcVal QList networkinterfaces = QNetworkInterface::allInterfaces(); foreach (QNetworkInterface interfaces, networkinterfaces) //networkinterfaces负责提供主机的IP地址和网络接口的列表 { - foreach (QNetworkAddressEntry entry, interfaces.addressEntries())//QNetworkAddressEntry存储了一个IP地址,子网掩码和广播地址 - { - QHostAddress broadcastAddress("255.255.255.255"); - - { - entry.setBroadcast(QHostAddress::Broadcast); - QUdpSocket *tempUdpSocket= new QUdpSocket(this); - if(!tempUdpSocket->bind(entry.ip())) - break; - int iSendLength=tempUdpSocket->writeDatagram((char *)&tempStreadPakcet,iLenPacket,broadcastAddress,31296); - if( iSendLength != iLenPacket) - { -// qDebug() << "error" << "RestoreLedCardIpByUdpCmd error!send restore led card ip by udp cmd"; -// // return; - char *aa=reinterpret_cast(&tempStreadPakcet); - tempUdpSocket->writeDatagram(&aa[iSendLength],iLenPacket-iSendLength,broadcastAddress,31296); - } - else { - -// strIpAddress =entry.ip().toString();// broadcastAddress.toString(); -// qDebug() << strIpAddress << "send restore led card ip by udp cmd" ; - } - delete tempUdpSocket; - } + foreach (QNetworkAddressEntry entry, interfaces.addressEntries())//QNetworkAddressEntry存储了一个IP地址,子网掩码和广播地址 + { + QHostAddress broadcastAddress("255.255.255.255"); + entry.setBroadcast(QHostAddress::Broadcast); + QUdpSocket *tempUdpSocket= new QUdpSocket(this); + if(!tempUdpSocket->bind(entry.ip())) + break; + int iSendLength=tempUdpSocket->writeDatagram((char *)&tempStreadPakcet,iLenPacket,broadcastAddress,31296); + if(iSendLength != iLenPacket) { + char *aa=reinterpret_cast(&tempStreadPakcet); + tempUdpSocket->writeDatagram(&aa[iSendLength],iLenPacket-iSendLength,broadcastAddress,31296); + } + delete tempUdpSocket; } } - if(ui->checkBoxDebug->isChecked()) - { - ui->textEditReadBuf->append("udp:"+tr(databuf.toHex())); + if(ui->checkBoxDebug->isChecked()) { + ui->textEditReadBuf->append("udp:"+tr(databuf.toHex())); } } void mGuangYingPinWidget::MWSendCmd(uint8_t iComIndex,unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd) diff --git a/LedOK/wDevicesManager/controlhdmiwidget.cpp b/LedOK/wDevicesManager/controlhdmiwidget.cpp index 48b2f8c..3c24656 100644 --- a/LedOK/wDevicesManager/controlhdmiwidget.cpp +++ b/LedOK/wDevicesManager/controlhdmiwidget.cpp @@ -1,8 +1,10 @@ #include "controlhdmiwidget.h" #include "gqt.h" #include "tools.h" +#include "globaldefine.h" #include "base/waitingdlg.h" #include +#include ControlHdmiWidget::ControlHdmiWidget(QWidget *parent,QList *list) : QWidget(parent) { auto vBox = new QVBoxLayout(this); diff --git a/LedOK/wDevicesManager/controlhdmiwidget.ui b/LedOK/wDevicesManager/controlhdmiwidget.ui deleted file mode 100644 index 4cd27fe..0000000 --- a/LedOK/wDevicesManager/controlhdmiwidget.ui +++ /dev/null @@ -1,157 +0,0 @@ - - - ControlHdmiWidget - - - - 0 - 0 - 381 - 500 - - - - Form - - - - - - - - - - Arial - 12 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - HDMI Configuration - - - Qt::AlignCenter - - - - - - - Qt::Horizontal - - - - - - - 9 - - - 9 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Arial - 12 - - - - background-color:transparent - - - Manual - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Arial - 12 - - - - background-color:transparent - - - Schedule - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - diff --git a/LedOK/wDevicesManager/specialdlg.cpp b/LedOK/wDevicesManager/specialdlg - 副本.cpp similarity index 88% rename from LedOK/wDevicesManager/specialdlg.cpp rename to LedOK/wDevicesManager/specialdlg - 副本.cpp index 2908554..4e5a1e6 100644 --- a/LedOK/wDevicesManager/specialdlg.cpp +++ b/LedOK/wDevicesManager/specialdlg - 副本.cpp @@ -6,7 +6,7 @@ #include #include -SpecialDlg::SpecialDlg(QWidget *parent, NetComm *netComm) : QDialog(parent) { +SpecialDlg::SpecialDlg(QWidget *parent) : QDialog(parent) { resize(300, 100); setWindowTitle(tr("Specify IP")); @@ -44,7 +44,7 @@ SpecialDlg::SpecialDlg(QWidget *parent, NetComm *netComm) : QDialog(parent) { vBox->addLayout(hBox); //绑定信号和槽函数 - connect(bnSearch, &QPushButton::clicked, this, [this, fdIP, netComm] { + connect(bnSearch, &QPushButton::clicked, this, [this, fdIP] { QString strTempIp = fdIP->text(); if(strTempIp=="...") { QMessageBox::warning(gMainWin, tr("Attention"), tr("Please input IP address!")); @@ -57,7 +57,7 @@ SpecialDlg::SpecialDlg(QWidget *parent, NetComm *netComm) : QDialog(parent) { waitingDlg->show(); auto reply = Tools::netManager().get(reqForJson("http://"+strTempIp+":3000/deviceList?fromDetector=true")); //在该ip的3000端口get方法deviceList,可以一次性获取到局域网中设备列表的详细信息 - connect(reply, &QNetworkReply::finished, this, [reply, this, waitingDlg, netComm] { + connect(reply, &QNetworkReply::finished, this, [reply, this, waitingDlg] { QJsonDocument json; QString err = parseReplyJson(reply); if(! err.isEmpty()) { @@ -69,7 +69,7 @@ SpecialDlg::SpecialDlg(QWidget *parent, NetComm *netComm) : QDialog(parent) { close(); QStringList keys = json.object().keys(); qDebug()<<"json size"<JieXiQJsonObjectOfLedCardInfo(json[key].toObject(), ""); + for(auto key : keys) gDevicePanel->parseInfo(json[key].toObject(), ""); }); }); } diff --git a/LedOK/wDevicesManager/specialdlg.h b/LedOK/wDevicesManager/specialdlg - 副本.h similarity index 64% rename from LedOK/wDevicesManager/specialdlg.h rename to LedOK/wDevicesManager/specialdlg - 副本.h index d8657b5..cdafa95 100644 --- a/LedOK/wDevicesManager/specialdlg.h +++ b/LedOK/wDevicesManager/specialdlg - 副本.h @@ -2,12 +2,11 @@ #define SPECIALDLG_H #include -#include class SpecialDlg : public QDialog { Q_OBJECT public: - explicit SpecialDlg(QWidget *, NetComm *); + explicit SpecialDlg(QWidget *); }; #endif // SPECIALDLG_H diff --git a/LedOK/wDevicesManager/upgradeapkdialog.cpp b/LedOK/wDevicesManager/upgradeapkdialog.cpp index aaf9f49..b3f1139 100644 --- a/LedOK/wDevicesManager/upgradeapkdialog.cpp +++ b/LedOK/wDevicesManager/upgradeapkdialog.cpp @@ -2,7 +2,6 @@ #include "tools.h" #include "ui_upgradeapkdialog.h" #include -#include #include #include #include @@ -190,11 +189,10 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) { pushButtonPublish->setEnabled(false); pushButtonUpgradeFpga->setEnabled(false); connect(pushButtonRefresh, &QPushButton::clicked, this, [this, label] { - if(gUdp==nullptr) return; wDevicePublishList->clear(); wDevicePublishList->onCheckAll(false); - int iCount=gUdp->LedCardList.count(); - for(int i=0;iLedCardList.at(i)); + int iCount = gDevicePanel->LedCardList.count(); + for(int i=0;iLedCardList.at(i)); label->setText(tr("All")+":"+QString::number(iCount)); }); connect(pushButtonPublish, &QPushButton::clicked, this, [this, label_ApkPath] { @@ -241,16 +239,14 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) { } else lineEditPackageName->setVisible(false); }); - if(gUdp==nullptr) return; - int iCount=gUdp->LedCardList.count(); - for(int i=0;iLedCardList.at(i)); + int iCount = gDevicePanel->LedCardList.count(); + for(int i=0; iLedCardList.at(i)); label->setText(tr("All")+":"+QString::number(iCount)); auto timer = new QTimer(this); connect(timer, &QTimer::timeout, this, [this, label] { - if(gUdp==nullptr) return; - int iCount=gUdp->LedCardList.count(); - for(int i=0;iLedCardList.at(i)); + int iCount = gDevicePanel->LedCardList.count(); + for(int i=0;iLedCardList.at(i)); label->setText(tr("All")+":"+QString::number(iCount)); }); timer->start(500000); diff --git a/LedOK/wProgramManager/sendprogramdialog.cpp b/LedOK/wProgramManager/sendprogramdialog.cpp index 43d7b7d..ec3f8f6 100644 --- a/LedOK/wProgramManager/sendprogramdialog.cpp +++ b/LedOK/wProgramManager/sendprogramdialog.cpp @@ -1,5 +1,5 @@ #include "sendprogramdialog.h" -#include "communication/network.h" +#include "tools.h" #include #include #include @@ -171,9 +171,8 @@ void SendProgramDialog::sendNext() { } void SendProgramDialog::onRefresh() { - if(gUdp==0) return; - int iCount = gUdp->LedCardList.count(); - for(int i=0; iLedCardList.at(i)); + int iCount = gDevicePanel->LedCardList.count(); + for(int i=0; iLedCardList.at(i)); label->setText(tr("All")+":"+QString::number(iCount)); } void SendProgramDialog::onAddLedCard(LedCard *p) {