From 5a32c7064c99783e267faac8253b87da42f91073 Mon Sep 17 00:00:00 2001 From: wsb Date: Fri, 10 Feb 2023 14:13:43 +0800 Subject: [PATCH] =?utf8?q?=E7=AC=AC=E4=B8=80=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- protectpro/main.cpp | 12 ++ protectpro/protectpro.pro | 28 +++ protectpro/protectpro.pro.user | 319 +++++++++++++++++++++++++++++++++ protectpro/widget.cpp | 54 ++++++ protectpro/widget.h | 25 +++ 5 files changed, 438 insertions(+) create mode 100644 protectpro/main.cpp create mode 100644 protectpro/protectpro.pro create mode 100644 protectpro/protectpro.pro.user create mode 100644 protectpro/widget.cpp create mode 100644 protectpro/widget.h diff --git a/protectpro/main.cpp b/protectpro/main.cpp new file mode 100644 index 00000000..ba04a3ad --- /dev/null +++ b/protectpro/main.cpp @@ -0,0 +1,12 @@ +#include "widget.h" + +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + //w.show(); + return a.exec(); +} diff --git a/protectpro/protectpro.pro b/protectpro/protectpro.pro new file mode 100644 index 00000000..3b14352f --- /dev/null +++ b/protectpro/protectpro.pro @@ -0,0 +1,28 @@ +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/protectpro/protectpro.pro.user b/protectpro/protectpro.pro.user new file mode 100644 index 00000000..fb8d6629 --- /dev/null +++ b/protectpro/protectpro.pro.user @@ -0,0 +1,319 @@ + + + + + + EnvironmentId + {fdb8d9d2-ac9a-4bc5-8670-5bdddab385d5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 0 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.2 MinGW 32-bit + Desktop Qt 5.14.2 MinGW 32-bit + qt.qt5.5142.win32_mingw73_kit + 0 + 0 + 0 + + E:/verygood/yanshou/build-protectpro-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + E:/verygood/yanshou/build-protectpro-Desktop_Qt_5_14_2_MinGW_32_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + E:/verygood/yanshou/build-protectpro-Desktop_Qt_5_14_2_MinGW_32_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:E:/verygood/yanshou/protectpro/protectpro.pro + E:/verygood/yanshou/protectpro/protectpro.pro + + false + + false + true + true + false + false + true + + E:/verygood/yanshou/build-protectpro-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/protectpro/widget.cpp b/protectpro/widget.cpp new file mode 100644 index 00000000..0a33b8a8 --- /dev/null +++ b/protectpro/widget.cpp @@ -0,0 +1,54 @@ +#include "widget.h" + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ + reBootFlag = false; + reBootNumber = 0; + m_receiver=new QUdpSocket(this); + //绑定发送端,ShareAddress允许多接收端绑定6666端口 + m_receiver->bind(6666,QUdpSocket::ShareAddress); + //当接收端接收到数据时,就会发送readRead信号 + connect(m_receiver,&QUdpSocket::readyRead,this,&Widget::processData); + timer =new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout())); + timer->start(2000); +} + +Widget::~Widget() +{ +} + +void Widget::processData() +{ + reBootNumber = 0; + QString strData; + //有未处理的数据报 + while(m_receiver->hasPendingDatagrams()){ + QByteArray dataGram; + //读取的数据报大小 + dataGram.resize(m_receiver->pendingDatagramSize()); + m_receiver->readDatagram(dataGram.data(),dataGram.size()); + qDebug()<<"protectpro11111111111111111111111111111111111111111111111111111111dataGram"<start(2000); + } +} + +void Widget::timerTimeout() +{ + reBootNumber++; + if(reBootNumber > 10) + { + reBootFlag = true; + reBootNumber = 0; + timer->stop(); +#ifdef LINUX + std::system("killall jiemian"); + std::system("reboot"); +#endif + } +} diff --git a/protectpro/widget.h b/protectpro/widget.h new file mode 100644 index 00000000..84a33a39 --- /dev/null +++ b/protectpro/widget.h @@ -0,0 +1,25 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include +#define LINUX 1 +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); +private slots: + void processData(); + void timerTimeout(); +private: + QUdpSocket* m_receiver; + QTimer* timer; + bool reBootFlag; + int reBootNumber; +}; +#endif // WIDGET_H -- 2.34.1