From 36433b4d75504b59c9cf1004dad839f8fa92a6d8 Mon Sep 17 00:00:00 2001 From: gangphon Date: Mon, 20 Mar 2023 11:30:19 +0800 Subject: [PATCH] =?UTF-8?q?ledset=E5=A2=9E=E5=8A=A0=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ledset/expertwin.cpp | 7 +- ledset/expertwin.h | 1 - ledset/globalfunc.cpp | 12 ++ ledset/globalfunc.h | 3 + ledset/ledset.pro | 16 +- ledset/main.cpp | 55 ++--- ledset/mainwin.cpp | 74 +++---- ledset/mainwin.h | 30 +-- ledset/pcaprethread.cpp | 31 +++ ledset/pcaprethread.h | 35 ++++ ledset/pcapwin.h | 1 - ledset/translations/app_en.ts | 370 ++++++++++++++++++++-------------- ledset/videowin.h | 5 +- 13 files changed, 360 insertions(+), 280 deletions(-) create mode 100644 ledset/pcaprethread.cpp create mode 100644 ledset/pcaprethread.h diff --git a/ledset/expertwin.cpp b/ledset/expertwin.cpp index 8b19cd2..518e319 100644 --- a/ledset/expertwin.cpp +++ b/ledset/expertwin.cpp @@ -537,6 +537,8 @@ QTabBar::tab:selected {margin-top: 0; border-bottom: none; color: #acf; backgrou connect(btn, &QPushButton::clicked, this, [=] { QByteArray data; addMapData(data); + + QMessageBox::information(this, tr("发送成功"), tr("发送成功")); }); hBox->addWidget(btn); @@ -731,10 +733,11 @@ void run() { // bytes.append("\0\x4", 2); //数据长度 // bytes.append(4, '\xff'); //目的地址 // bytes.append(4, 0); //源地址 -// bytes.append("\x35\0\xc\xbb", 4); //内存指针 +// bytes.append("\xB1\x04\0\0", 4); //内存指针 // bytes.append(2, 0); //应答填充项 // auto crc32 = crc32_calc((uint8_t*)bytes.data()+2, bytes.length()-2); -// bytes.append(crc32>>24).append(crc32>>16).append(crc32>>8).append(crc32); +// bytes.append(crc32>>24).append(crc32>>16).append(crc32>>8).append(crc32); //包头校验 + // crc32 = crc32_calc((uint8_t*)bytes.data()+bytes.length()-4, 4); // bytes.append(crc32>>24).append(crc32>>16).append(crc32>>8).append(crc32); // //发送帧开始指令包 diff --git a/ledset/expertwin.h b/ledset/expertwin.h index 9954859..567f17b 100644 --- a/ledset/expertwin.h +++ b/ledset/expertwin.h @@ -3,7 +3,6 @@ #include "basewin.h" #define HAVE_REMOTE -#include #include "pcap.h" #include #include diff --git a/ledset/globalfunc.cpp b/ledset/globalfunc.cpp index 34ac7c7..b95178a 100644 --- a/ledset/globalfunc.cpp +++ b/ledset/globalfunc.cpp @@ -117,3 +117,15 @@ QByteArray getNetDev(QWidget *parent, QByteArray def) { return name; } } + + +QByteArray sendMsg(QByteArray msg) { + return sendMsgNet(msg); +} + +QByteArray sendMsgNet(QByteArray msg) { + + + + return msg; +} diff --git a/ledset/globalfunc.h b/ledset/globalfunc.h index c77b3ee..54ea7d6 100644 --- a/ledset/globalfunc.h +++ b/ledset/globalfunc.h @@ -6,4 +6,7 @@ QByteArray getNetDev(QWidget *parent, QByteArray); +QByteArray sendMsg(QByteArray); +QByteArray sendMsgNet(QByteArray); + #endif // GLOBALFUNC_H diff --git a/ledset/ledset.pro b/ledset/ledset.pro index ff3b620..d6e070a 100644 --- a/ledset/ledset.pro +++ b/ledset/ledset.pro @@ -10,6 +10,13 @@ CONFIG += embed_translations # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +INCLUDEPATH += $$PWD/WpdPack_4_1_2/Include +LIBS += -L$$PWD/WpdPack_4_1_2/Lib/\ + -lwpcap\ + -lpacket + -lWs2_32 + msvc { QMAKE_CXXFLAGS += -execution-charset:utf-8 QMAKE_CXXFLAGS += -source-charset:utf-8 @@ -36,6 +43,7 @@ SOURCES += \ gqt.cpp \ main.cpp \ mainwin.cpp \ + pcaprethread.cpp \ pcapwin.cpp \ screenunit.cpp \ table.cpp \ @@ -52,6 +60,7 @@ HEADERS += \ globalfunc.h \ gqt.h \ mainwin.h \ + pcaprethread.h \ pcapwin.h \ screenunit.h \ table.h \ @@ -71,13 +80,6 @@ RESOURCES += \ RC_ICONS = 128.ico - -INCLUDEPATH += $$PWD/WpdPack_4_1_2/Include -LIBS += -L$$PWD/WpdPack_4_1_2/Lib/\ - -lwpcap\ - -lpacket - - # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin diff --git a/ledset/main.cpp b/ledset/main.cpp index 5723e6f..7ee20e9 100644 --- a/ledset/main.cpp +++ b/ledset/main.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #ifdef _MSC_VER //MSVC编译器 #define _WINSOCKAPI_ @@ -18,10 +18,7 @@ LONG WINAPI handleException(_EXCEPTION_POINTERS *excep) { QString errCode = QString::number(excep->ExceptionRecord->ExceptionCode, 16); QString errAddr = QString::number((uint)excep->ExceptionRecord->ExceptionAddress, 16); HANDLE hDumpFile = CreateFile(L"c:/ledset-crash.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if(hDumpFile == INVALID_HANDLE_VALUE) { - qDebug()<<"handleException hDumpFile INVALID"<<"ExceptionCode"<status = 2; if(pcapSend) pcap_close(pcapSend); - pcapRe = pcapR; pcapSend = pcapS; + reThd = new PcapReThread(pcapR); + reThd->start(); QSettings config(QApplication::applicationDirPath()+"/ledset.config", QSettings::IniFormat);//QDir::currentPath()为exe位置 config.beginGroup("GLOBAL"); config.setValue("net_name", net_name = name); @@ -159,6 +161,20 @@ 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)); @@ -175,63 +191,23 @@ MainWin::MainWin() { name = getNetDev(this, name); if(! name.isEmpty()) { char errbuf[PCAP_ERRBUF_SIZE]{'\0'}; - pcapRe = pcap_open_live(name.data(), 65536, PCAP_OPENFLAG_PROMISCUOUS|4|8|16, 50, errbuf); + auto pcapRe = pcap_open_live(name.data(), 65536, PCAP_OPENFLAG_PROMISCUOUS|4|8|16, 50, errbuf); if(pcapRe == 0) QMessageBox::critical(this, "Error", QString(tr("打开网卡失败"))+errbuf); else { pcapSend = pcap_open_live(name.data(), 65536, 0, 50, errbuf); if(pcapSend == 0) QMessageBox::critical(this, "Error", QString(tr("打开网卡失败"))+errbuf); - else config.setValue("net_name", net_name = name); + else { + config.setValue("net_name", net_name = name); + reThd = new PcapReThread(pcapRe); + reThd->start(); + } } } config.endGroup(); } -MainPcapThread::MainPcapThread(pcap_t *pcap) : pcap(pcap) { - connect(this, &QThread::finished, this, &QThread::deleteLater); -} +void MainWin::ProNetData(const u_char *data,int len) { -void MainPcapThread::run() { - pcap_pkthdr *header; - const u_char *data; - int res; - while((res = pcap_next_ex(pcap, &header, &data)) >= 0) { - if(status==2) return; - if(status==1 || res == 0) continue; //超时 - //if(data[0]!=0x55 || data[1]!=0x55 || (data[6] ==0xff && data[7] ==0xff && data[8] == 0xff && data[9] == 0xff)) continue; - if(data[0]!=0x55 || data[1]!=0x55 ) - continue; - emit onMsg(data,header->caplen); - } - emit onError(pcap_geterr(pcap)); -} -void MainWin::ProNetData(const u_char *data,int len) -{ - if(table != nullptr) - { - uint32_t pio=data[14] << 24 | data[15] <<16 | data[16] <<8 | data[17] ; - uint8_t srv = data[3]; - if(srv == 0xEA && pio == 0xB0000101 ) - { - table->setRowCount(1); - uint16_t pIndex = data[10]<<8 | data[11]; - uint32_t virtualVCM = pIndex ; - uint32_t vcsNum = data[24] << 24 | data[25] <<16 | data[26] <<8 | data[27] ; - table->setValue(0, "type", tr("虚拟设备")); - table->setValue(0, "name", tr("网口:")+QString::number(virtualVCM)); - table->setValue(0, "link", "千兆网直连"); - table->setValue(0, "vcs", QString::number(vcsNum)); - table->setValue(0, "Pinfo", "P:"+QString::number(virtualVCM)); - table->setValue(0, "Oinfo", "备注:可直接配屏,无需发送卡"); - } - else - { - QString data_str; - for(uint i=0; i -#include "pcap.h" -#include - -class MainPcapThread : public QThread { - Q_OBJECT -public: - explicit MainPcapThread(pcap *pcap); - ~MainPcapThread() { - pcap_close(pcap); - } - pcap *pcap; - std::atomic status{0}; -protected: - void run(); -signals: - void onMsg(const u_char *data,int len); - void onError(char *); -}; +#include "pcaprethread.h" class MainWin : public BaseWin { Q_OBJECT @@ -30,13 +11,12 @@ public: MainWin(); QWidget *win{0}; QByteArray net_name; - pcap_t *pcapRe{0}; pcap_t *pcapSend{0}; - MainPcapThread *thd{0}; - Table *table = nullptr; -protected slots: - void ProNetData(const u_char *data,int len); + PcapReThread *reThd{0}; + Table *table{0}; +protected slots: + void ProNetData(const uint8_t *data, int len); }; #endif // MAINWIN_H diff --git a/ledset/pcaprethread.cpp b/ledset/pcaprethread.cpp new file mode 100644 index 0000000..339db72 --- /dev/null +++ b/ledset/pcaprethread.cpp @@ -0,0 +1,31 @@ +#include "pcaprethread.h" + +PcapReThread::PcapReThread(pcap_t *pcap) : pcap(pcap) { + connect(this, &QThread::finished, this, &QThread::deleteLater); + connect(this, &PcapReThread::onMsg, this, [](Resp resp, const QByteArray data) { + resp.callback(data); + }); +} + +void PcapReThread::run() { + pcap_pkthdr *header; + const u_char *data; + int res; + while((res = pcap_next_ex(pcap, &header, &data)) >= 0) { + if(status==2) return; + if(status==1 || res == 0) continue; //超时 + if(data[0]!=0x55 || data[1]!=0x55 ) continue; + int id = data[2]<<8 | data[3]; + { + std::lock_guard lock(mtx); + for(int i=0; icaplen)); + break; + } + } + } + emit onError(pcap_geterr(pcap)); +} + + diff --git a/ledset/pcaprethread.h b/ledset/pcaprethread.h new file mode 100644 index 0000000..86c0dd2 --- /dev/null +++ b/ledset/pcaprethread.h @@ -0,0 +1,35 @@ +#ifndef PCAPRETHREAD_H +#define PCAPRETHREAD_H + +#include +#define HAVE_REMOTE +#include "pcap.h" + +struct Resp { + int id; + std::function callback; +}; + +class PcapReThread : public QThread { + Q_OBJECT +public: + explicit PcapReThread(pcap *pcap); + ~PcapReThread() { + pcap_close(pcap); + } + void addResp(const Resp &resp) { + std::lock_guard lock(mtx); + resps.append(resp); + } + std::atomic status{0}; + QList resps; + std::mutex mtx; + pcap *pcap; +signals: + void onMsg(Resp resp, const QByteArray data); + void onError(char *); +protected: + void run(); +}; + +#endif // PCAPRETHREAD_H diff --git a/ledset/pcapwin.h b/ledset/pcapwin.h index 82269d3..d994704 100644 --- a/ledset/pcapwin.h +++ b/ledset/pcapwin.h @@ -3,7 +3,6 @@ #include "basewin.h" #define HAVE_REMOTE -#include #include "pcap.h" #include diff --git a/ledset/translations/app_en.ts b/ledset/translations/app_en.ts index 06847c5..e9edc87 100644 --- a/ledset/translations/app_en.ts +++ b/ledset/translations/app_en.ts @@ -136,430 +136,486 @@ - + 基本参数 - + 模组宽度: - + 模组高度: - + 数据组数: - + 驱动芯片: - + 译码方式: - + 138译码 - + 分组方式: - + 三线并行 - + 三色1点串 - + 三色8点串 - + 三色16点串 - + 扫描行数 - + 根据亮线的行/列数确定扫描行/列数: - + - + - + 亮线的行/列数: - + 芯片245版本: - + 数据线颜色 - + 依次点击以下状态, 根据模组颜色选择对应颜色 - + 状态1 - - - + + + - - - + + + 绿 - - - + + + - - - + + + - + 状态2 - + 状态3 - + 插入虚点 - + 重新走点 - - + 完成 - - + + 提示 - + 列走完 - + 行走完 - + 第一扫灯数: - + 实: 虚: - + 上一步 - + 下一步 - + + + + + 失败 + + + + + + 准备写入 %1 文件失败 + + + + + + 写入 %1 文件失败 + + + + 保存文件 - + + Module file (*.module) + + + + 保存成功 - - - 保存设置 - - - - - 文件名称: - - - - - 1X2_3扫 - - - - - 保存路径: - - - - - 选择路径 - - - - - 选择存储文件的目录 - - - - - 返回 - - ExpertWin - + 数据线颜色 - + 模组抽行设置 - + 宽度 - + 高度 - + 多开设置 - + 级联方向 - + - + 双开 - + 三开 - + 四开 - - 从左到右 + + 五开 - - 从右到左 - - - - - 从上到下 - - - - - 从下到上 - - - - - 选择180度 - - - - - 数据交换 + + 六开 - 平面造型 + 七开 + + + + + 八开 + 从左到右 + + + + + 从右到左 + + + + + 从上到下 + + + + + 从下到上 + + + + + 旋转180° + + + + + 数据交换 + + + + + 平面造型 + + + + 效果测试 - + 视觉刷新率: - + DCLK频率: - + DCLK相位: - + DCLK占空比: - + 换行时间(ns): - + 亮度有效率: - + 100% - + GCLK频率: - + 灰度级数: - + GCLK占空比: - + 换行位置(ns): - + 更多设置 - + 打开配置 - + 保存配置 - + + + 保存文件 + + + + + Box file (*.box) + + + + + + + + 失败 + + + + + + 准备写入 %1 文件失败 + + + + + + 写入 %1 文件失败 + + + + + + 保存成功 + + + + + 保存Map + + + + 发送数据 - + + 发送成功 + + + + 固化数据 - + 回读数据 - + 状态: - + 显示屏连接(正面看屏) @@ -567,76 +623,82 @@ MainWin - + 专家调屏 - + 亮度控制 - + 相机矫正 - + 屏体监控 - + 多功能卡 - + 协议调试 - + 模拟同步 - + 版本:221114 - - - - + + + + 打开网卡失败 - + 刷新 - + 发送失败: - + 虚拟设备 - + 网口: PcapWin + + + + 打开网卡失败 + + 网口通信 diff --git a/ledset/videowin.h b/ledset/videowin.h index fcedd48..4b03ff9 100644 --- a/ledset/videowin.h +++ b/ledset/videowin.h @@ -3,8 +3,8 @@ #include "basewin.h" #define HAVE_REMOTE -#include #include "pcap.h" +#include #include #include #include @@ -12,9 +12,6 @@ #include #include "Win32-Extensions.h" -#pragma comment(lib, "wpcap.lib") -#pragma comment(lib, "Ws2_32.lib") - class VideoSendThread : public QThread { Q_OBJECT public: