From b8d679984c6bc12ec302d4acbae2939f3628deb1 Mon Sep 17 00:00:00 2001 From: gangphon Date: Mon, 20 Mar 2023 12:11:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ledset=E6=89=BE=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ledset/globalfunc.cpp | 15 +++++++------- ledset/globalfunc.h | 10 +++++++-- ledset/mainwin.cpp | 47 +++++++++++++++++++++---------------------- ledset/mainwin.h | 7 ++----- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/ledset/globalfunc.cpp b/ledset/globalfunc.cpp index b95178a..974b8bb 100644 --- a/ledset/globalfunc.cpp +++ b/ledset/globalfunc.cpp @@ -6,6 +6,9 @@ #include #include +pcap_t *pcapSend{0}; +PcapReThread *reThd{0}; + QByteArray getNetDev(QWidget *parent, QByteArray def) { char errbuf[PCAP_ERRBUF_SIZE]; pcap_if_t *devs; @@ -119,13 +122,11 @@ QByteArray getNetDev(QWidget *parent, QByteArray def) { } -QByteArray sendMsg(QByteArray msg) { - return sendMsgNet(msg); +int sendMsg(QByteArray msg, const Resp &resp) { + return sendMsgNet(msg, resp); } -QByteArray sendMsgNet(QByteArray msg) { - - - - return msg; +int sendMsgNet(QByteArray msg, const Resp &resp) { + reThd->addResp(resp); + return pcap_sendpacket(pcapSend, (u_char*)msg.data(), msg.size()); } diff --git a/ledset/globalfunc.h b/ledset/globalfunc.h index 54ea7d6..fe0efd1 100644 --- a/ledset/globalfunc.h +++ b/ledset/globalfunc.h @@ -4,9 +4,15 @@ #include #include +#include "pcaprethread.h" + +extern pcap_t *pcapSend; +extern PcapReThread *reThd; + + QByteArray getNetDev(QWidget *parent, QByteArray); -QByteArray sendMsg(QByteArray); -QByteArray sendMsgNet(QByteArray); +int sendMsg(QByteArray, const Resp &resp); +int sendMsgNet(QByteArray, const Resp &resp); #endif // GLOBALFUNC_H diff --git a/ledset/mainwin.cpp b/ledset/mainwin.cpp index 4ec8718..72ae1ab 100644 --- a/ledset/mainwin.cpp +++ b/ledset/mainwin.cpp @@ -160,27 +160,7 @@ MainWin::MainWin() { auto btnRefresh = new QPushButton(tr("刷新")); btnRefresh->setMinimumWidth(80); - connect(btnRefresh, &QPushButton::clicked, this, [this] { - reThd->addResp({0x1E0, [=](const QByteArray data) { - if(((u_char)data[10])==0xB0 && data[11]==0 && data[12]==1 && data[13]==1) { - auto rr = table->rowCount(); - table->setRowCount(rr+1); - uint32_t virtualVCM = data[6]<<8 | data[7] ; - table->setValue(rr, "type", tr("虚拟设备")); - table->setValue(rr, "name", tr("网口:")+QString::number(virtualVCM)); - table->setValue(rr, "link", "千兆网直连"); - uint32_t vcsNum = data[20] << 24 | data[21] <<16 | data[22] <<8 | data[23] ; - table->setValue(rr, "vcs", QString::number(vcsNum)); - table->setValue(rr, "Pinfo", "P:"+QString::number(virtualVCM)); - table->setValue(rr, "Oinfo", "备注:可直接配屏,无需发送卡"); - } - }}); - auto bytes = QByteArray::fromHex("55 55 01 AD 00 01 FF FF FF FF 00 00 00 00 B0 00 01 00 00 00 3B 11 0A 6C 00 00 00 00 21 44 DF 1C"); - if(pcap_sendpacket(pcapSend, (u_char*)bytes.data(), bytes.size())) { - QMessageBox::critical(this, "Error", QString(tr("发送失败: "))+pcap_geterr(pcapSend)); - return; - } - }); + connect(btnRefresh, &QPushButton::clicked, this, &MainWin::getCard); hstatus->addWidget(btnRefresh); vBox->addLayout(hstatus); @@ -204,11 +184,30 @@ MainWin::MainWin() { } } config.endGroup(); + + getCard(); } -void MainWin::ProNetData(const u_char *data,int len) { - - +void MainWin::getCard() { + auto msg = QByteArray::fromHex("55 55 01 0D 00 08 FF FF FF FF 00 00 AB CD A0 00 00 00 00 00 38 CB 84 7E 00 00 00 00 00 00 AB CD CD 04 04 46"); + auto res = sendMsg(msg, {0x10d, [=](const QByteArray data) { + if(((u_char)data[10])==0xA0 && data[11]==0 && data[12]==0 && data[13]==0) { + auto rr = 0; + table->setRowCount(rr+1); + uint32_t virtualVCM = data[6]<<8 | data[7] ; + table->setValue(rr, "type", tr("虚拟设备")); + table->setValue(rr, "name", tr("网口:")+QString::number(virtualVCM)); + table->setValue(rr, "link", "千兆网直连"); + uint32_t vcsNum = data[20] << 24 | data[21] <<16 | data[22] <<8 | data[23] ; + table->setValue(rr, "vcs", QString::number(vcsNum)); + table->setValue(rr, "Pinfo", "P:"+QString::number(virtualVCM)); + table->setValue(rr, "Oinfo", "备注:可直接配屏,无需发送卡"); + } + }}); + if(res) { + QMessageBox::critical(this, "Error", QString(tr("发送失败: "))+pcap_geterr(pcapSend)); + return; + } } diff --git a/ledset/mainwin.h b/ledset/mainwin.h index 6e99a15..2cd6fe0 100644 --- a/ledset/mainwin.h +++ b/ledset/mainwin.h @@ -3,7 +3,6 @@ #include "basewin.h" #include "table.h" -#include "pcaprethread.h" class MainWin : public BaseWin { Q_OBJECT @@ -11,12 +10,10 @@ public: MainWin(); QWidget *win{0}; QByteArray net_name; - pcap_t *pcapSend{0}; - PcapReThread *reThd{0}; Table *table{0}; -protected slots: - void ProNetData(const uint8_t *data, int len); +public slots: + void getCard(); }; #endif // MAINWIN_H