修改ledset找卡

This commit is contained in:
gangphon 2023-03-20 12:11:58 +08:00
parent 36433b4d75
commit b8d679984c
4 changed files with 41 additions and 38 deletions

View File

@ -6,6 +6,9 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
pcap_t *pcapSend{0};
PcapReThread *reThd{0};
QByteArray getNetDev(QWidget *parent, QByteArray def) { QByteArray getNetDev(QWidget *parent, QByteArray def) {
char errbuf[PCAP_ERRBUF_SIZE]; char errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t *devs; pcap_if_t *devs;
@ -119,13 +122,11 @@ QByteArray getNetDev(QWidget *parent, QByteArray def) {
} }
QByteArray sendMsg(QByteArray msg) { int sendMsg(QByteArray msg, const Resp &resp) {
return sendMsgNet(msg); return sendMsgNet(msg, resp);
} }
QByteArray sendMsgNet(QByteArray msg) { int sendMsgNet(QByteArray msg, const Resp &resp) {
reThd->addResp(resp);
return pcap_sendpacket(pcapSend, (u_char*)msg.data(), msg.size());
return msg;
} }

View File

@ -4,9 +4,15 @@
#include <QWidget> #include <QWidget>
#include <QByteArray> #include <QByteArray>
#include "pcaprethread.h"
extern pcap_t *pcapSend;
extern PcapReThread *reThd;
QByteArray getNetDev(QWidget *parent, QByteArray); QByteArray getNetDev(QWidget *parent, QByteArray);
QByteArray sendMsg(QByteArray); int sendMsg(QByteArray, const Resp &resp);
QByteArray sendMsgNet(QByteArray); int sendMsgNet(QByteArray, const Resp &resp);
#endif // GLOBALFUNC_H #endif // GLOBALFUNC_H

View File

@ -160,27 +160,7 @@ MainWin::MainWin() {
auto btnRefresh = new QPushButton(tr("刷新")); auto btnRefresh = new QPushButton(tr("刷新"));
btnRefresh->setMinimumWidth(80); btnRefresh->setMinimumWidth(80);
connect(btnRefresh, &QPushButton::clicked, this, [this] { connect(btnRefresh, &QPushButton::clicked, this, &MainWin::getCard);
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;
}
});
hstatus->addWidget(btnRefresh); hstatus->addWidget(btnRefresh);
vBox->addLayout(hstatus); vBox->addLayout(hstatus);
@ -204,11 +184,30 @@ MainWin::MainWin() {
} }
} }
config.endGroup(); 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;
}
} }

View File

@ -3,7 +3,6 @@
#include "basewin.h" #include "basewin.h"
#include "table.h" #include "table.h"
#include "pcaprethread.h"
class MainWin : public BaseWin { class MainWin : public BaseWin {
Q_OBJECT Q_OBJECT
@ -11,12 +10,10 @@ public:
MainWin(); MainWin();
QWidget *win{0}; QWidget *win{0};
QByteArray net_name; QByteArray net_name;
pcap_t *pcapSend{0};
PcapReThread *reThd{0};
Table *table{0}; Table *table{0};
protected slots: public slots:
void ProNetData(const uint8_t *data, int len); void getCard();
}; };
#endif // MAINWIN_H #endif // MAINWIN_H