Sfoglia il codice sorgente

QT与smartPDU 消息队列通讯功能开发

chenyuanjie 1 anno fa
parent
commit
d2adce2bb6

+ 15 - 3
Qt/Qt_Test_Pro_5inch/Qt_Test.pro

@@ -36,7 +36,12 @@ SOURCES += \
     volviewform.cpp \
     udphelper.cpp \
     dataupdatethread.cpp \
-    buttonclickthread.cpp
+    buttonclickthread.cpp \
+    qt_pdu_msgq.cpp \
+    warningwnd.cpp \
+    mousemovewidget.cpp \
+    qmousemovelist.cpp
+
 
 HEADERS += \
     ch_widget.h \
@@ -52,7 +57,12 @@ HEADERS += \
     volviewform.h \
     udphelper.h \
     dataupdatethread.h \
-    buttonclickthread.h
+    buttonclickthread.h \
+    qt_pdu_msgq.h \
+    warningwnd.h \
+    mousemovewidget.h \
+    qmousemovelist.h
+
 
 FORMS += \
     ch_widget.ui \
@@ -62,7 +72,9 @@ FORMS += \
     runlogwidget.ui \
     thresholdlistwidget.ui \
     volviewform.ui \
-    widget.ui
+    widget.ui \
+    warningwnd.ui
 
 target.path = /root/web_temp
 INSTALLS += target
+LIBS += -lrt

+ 2 - 2
Qt/Qt_Test_Pro_5inch/Qt_Test.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.5.2, 2025-03-27T11:27:39. -->
+<!-- Written by QtCreator 4.5.2, 2025-04-19T13:38:06. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -128,7 +128,7 @@
     <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
    </valuemap>
    <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
-    <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/tronlong/Desktop/qt/Qt_Test_Pro/Output</value>
+    <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/tronlong/Desktop/qt/Output</value>
     <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
      <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
       <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>

+ 20 - 0
Qt/Qt_Test_Pro_5inch/ch_widget.cpp

@@ -1,5 +1,6 @@
 #include "ch_widget.h"
 #include "ui_ch_widget.h"
+#include "warningwnd.h"
 #include <QDebug>
 #define RunStatus "#ch_Widget{border: 2px solid #00FF00;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #00FF00; }"
 #define StopStatus "#ch_Widget{border: 2px solid #000000;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #000000; }"
@@ -11,6 +12,7 @@ ch_Widget::ch_Widget(QWidget *parent) :
     m_pChWarning(nullptr)
 {
     ui->setupUi(this);
+    pTimeLastset=QTime::currentTime();
 }
 
 ch_Widget::~ch_Widget()
@@ -72,13 +74,31 @@ void ch_Widget::UpdateData()
    }
 }
 
+void ch_Widget::mouseDoubleClickEvent(QMouseEvent *event)
+{
+    if (event->buttons()&Qt::MouseButton::LeftButton)
+    {
+        qDebug()<<"Clicke CH"+QString::number(m_nIndex);
+        QTime pNow=QTime::currentTime();
+        if(pTimeLastset.msecsTo(pNow)<250)
+        {
+           qDebug()<<"DClicke CH"+QString::number(m_nIndex);
+           emit singal_DoubleClick(m_nIndex);
+        }
+        pTimeLastset=pNow;
+    }
+
+}
+
 bool ch_Widget::event(QEvent *event)
 {
     if (event->type() == QEvent::TouchBegin ||
         event->type() == QEvent::TouchUpdate ||
         event->type() == QEvent::TouchEnd) {
         // 不处理触摸事件,交给父级(QScrollArea 的视口)处理
+        event->ignore();  // 标记事件未处理
         return false;
     }
+
     return QWidget::event(event);
 }

+ 11 - 2
Qt/Qt_Test_Pro_5inch/ch_widget.h

@@ -1,8 +1,8 @@
 #ifndef CH_WIDGET_H
 #define CH_WIDGET_H
-#include "common.h"
-#include <QWidget>
 
+#include <QWidget>
+#include "pdu_ctrl.h"
 namespace Ui {
 class ch_Widget;
 }
@@ -19,6 +19,13 @@ public:
 
     void UpdateData();
 
+public:
+    //void mousePressEvent(QMouseEvent *event) override;
+    void mouseDoubleClickEvent(QMouseEvent *event) override;
+    //void mouseMoveEvent(QMouseEvent *event) override;
+
+signals:
+    void singal_DoubleClick(int CHID);
 protected:
     bool event(QEvent *event);
 private:
@@ -28,6 +35,8 @@ private:
     PowerInfo* m_pCHData;
     PowerWarningInfo* m_pChWarning;
     int nStatus=0;
+    QTime pTimeLastset;
+
 };
 
 #endif // CH_WIDGET_H

+ 16 - 0
Qt/Qt_Test_Pro_5inch/common.h

@@ -12,6 +12,22 @@ enum {
     ALARM_TYPE_OPRATION,
     ALARM_TYPE_RUNNING,
 };
+//消息队列头结构体定义
+enum
+{
+    Msg_Ch_Ctrl=1,          //通道控制
+    Msg_All_Ctrl=2,         //整体控制
+    Msg_Threshold_Set=3,    //阈值设置
+    Msg_Threshold_Update=4, //阈值更新
+};
+#pragma pack(push, 1)  // 强制1字节对齐
+typedef struct {
+    long MsgType;       //消息方向1:Qt->PDU 2:pdu->Qt
+    int  CtrlType;      //控制类型
+    int  nValue[2];
+//    double fValue[10];
+}MsgData;
+#pragma pack(pop)      // 恢复默认对齐
 //地址部分
 typedef struct {
     int             id;

+ 48 - 29
Qt/Qt_Test_Pro_5inch/homewidget.ui

@@ -16,6 +16,9 @@
   <layout class="QVBoxLayout" name="verticalLayout" stretch="3,1">
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <property name="spacing">
+      <number>15</number>
+     </property>
      <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">
@@ -39,19 +42,6 @@
        </property>
       </widget>
      </item>
-     <item>
-      <spacer name="horizontalSpacer_2">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
      <item>
       <layout class="QGridLayout" name="gridLayout">
        <property name="spacing">
@@ -61,7 +51,7 @@
         <widget class="QLabel" name="label_6">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -73,7 +63,7 @@
         <widget class="QLabel" name="label_5">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -85,7 +75,7 @@
         <widget class="QLabel" name="label_10">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -97,7 +87,7 @@
         <widget class="QLabel" name="label_4">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -109,7 +99,7 @@
         <widget class="QLabel" name="label_7">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -121,7 +111,7 @@
         <widget class="QLabel" name="label_9">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -146,7 +136,7 @@
         <widget class="QLabel" name="label_8">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -158,7 +148,7 @@
         <widget class="QLabel" name="label_3">
          <property name="font">
           <font>
-           <pointsize>9</pointsize>
+           <pointsize>12</pointsize>
           </font>
          </property>
          <property name="text">
@@ -198,8 +188,22 @@
    </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
+     <property name="spacing">
+      <number>20</number>
+     </property>
+     <property name="leftMargin">
+      <number>20</number>
+     </property>
+     <property name="rightMargin">
+      <number>20</number>
+     </property>
      <item>
       <widget class="QPushButton" name="pushButton">
+       <property name="font">
+        <font>
+         <pointsize>13</pointsize>
+        </font>
+       </property>
        <property name="text">
         <string>运行</string>
        </property>
@@ -209,8 +213,8 @@
        </property>
        <property name="iconSize">
         <size>
-         <width>32</width>
-         <height>32</height>
+         <width>50</width>
+         <height>50</height>
         </size>
        </property>
        <property name="checkable">
@@ -229,6 +233,11 @@
      </item>
      <item>
       <widget class="QPushButton" name="pushButton_2">
+       <property name="font">
+        <font>
+         <pointsize>13</pointsize>
+        </font>
+       </property>
        <property name="text">
         <string>阈值</string>
        </property>
@@ -238,8 +247,8 @@
        </property>
        <property name="iconSize">
         <size>
-         <width>32</width>
-         <height>32</height>
+         <width>50</width>
+         <height>50</height>
         </size>
        </property>
        <property name="flat">
@@ -249,6 +258,11 @@
      </item>
      <item>
       <widget class="QPushButton" name="pushButton_4">
+       <property name="font">
+        <font>
+         <pointsize>13</pointsize>
+        </font>
+       </property>
        <property name="text">
         <string>日志</string>
        </property>
@@ -258,8 +272,8 @@
        </property>
        <property name="iconSize">
         <size>
-         <width>32</width>
-         <height>32</height>
+         <width>50</width>
+         <height>50</height>
         </size>
        </property>
        <property name="flat">
@@ -269,6 +283,11 @@
      </item>
      <item>
       <widget class="QPushButton" name="pushButton_3">
+       <property name="font">
+        <font>
+         <pointsize>13</pointsize>
+        </font>
+       </property>
        <property name="text">
         <string>设置</string>
        </property>
@@ -278,8 +297,8 @@
        </property>
        <property name="iconSize">
         <size>
-         <width>32</width>
-         <height>32</height>
+         <width>50</width>
+         <height>50</height>
         </size>
        </property>
        <property name="flat">

+ 4 - 1
Qt/Qt_Test_Pro_5inch/main.cpp

@@ -7,6 +7,8 @@
 #include <QGraphicsView>
 #include "pdu_ctrl.h"
 #include "mainwidget.h"
+#include "qt_pdu_msgq.h"
+
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
@@ -63,7 +65,8 @@ int main(int argc, char *argv[])
     thread_Button.InitConnect();
     thread_Button.start();
 
-
+    qt_pdu_msgq* pduMSG = new qt_pdu_msgq(nullptr);
+    pdu_Ctrl::instance()->pMsgq=pduMSG;
     int ret=a.exec();
     //析构
     thread_Update.isRunStats=false;

+ 21 - 11
Qt/Qt_Test_Pro_5inch/mainwidget.ui

@@ -70,8 +70,8 @@
         </property>
         <property name="iconSize">
          <size>
-          <width>40</width>
-          <height>40</height>
+          <width>64</width>
+          <height>64</height>
          </size>
         </property>
         <property name="autoRaise">
@@ -97,9 +97,13 @@
         <property name="font">
          <font>
           <family>微软雅黑</family>
-          <pointsize>13</pointsize>
-          <weight>75</weight>
-          <bold>true</bold>
+          <pointsize>15</pointsize>
+          <weight>50</weight>
+          <italic>false</italic>
+          <bold>false</bold>
+          <underline>false</underline>
+          <strikeout>false</strikeout>
+          <kerning>true</kerning>
          </font>
         </property>
         <property name="text">
@@ -117,14 +121,17 @@
           <property name="font">
            <font>
             <family>微软雅黑</family>
-            <pointsize>10</pointsize>
-            <weight>75</weight>
-            <bold>true</bold>
+            <pointsize>13</pointsize>
+            <weight>50</weight>
+            <bold>false</bold>
            </font>
           </property>
           <property name="text">
            <string>时间</string>
           </property>
+          <property name="alignment">
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
          </widget>
         </item>
         <item>
@@ -132,14 +139,17 @@
           <property name="font">
            <font>
             <family>微软雅黑</family>
-            <pointsize>10</pointsize>
-            <weight>75</weight>
-            <bold>true</bold>
+            <pointsize>13</pointsize>
+            <weight>50</weight>
+            <bold>false</bold>
            </font>
           </property>
           <property name="text">
            <string>日期</string>
           </property>
+          <property name="alignment">
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
          </widget>
         </item>
        </layout>

+ 40 - 0
Qt/Qt_Test_Pro_5inch/mousemovewidget.cpp

@@ -0,0 +1,40 @@
+#include "mousemovewidget.h"
+#include <QMouseEvent>
+MouseMoveWidget::MouseMoveWidget(QWidget *parent) : QWidget(parent),m_pMouseStart(0,0),m_pHScrollBar(nullptr),m_pVScrollBar(nullptr)
+{
+
+}
+
+void MouseMoveWidget::SetScrollBar(QScrollBar *pHScrollBar, QScrollBar *pVScrollBar)
+{
+    m_pHScrollBar=pHScrollBar;
+    m_pVScrollBar=pVScrollBar;
+}
+
+void MouseMoveWidget::mouseMoveEvent(QMouseEvent *event)
+{
+    if (event->buttons()&Qt::MouseButton::LeftButton)
+    {
+        QPoint delta = m_pMouseStart - event->pos();
+        if(m_pHScrollBar)
+        {
+            int hValue =m_pHScrollBar->value();
+            m_pHScrollBar->setValue(delta.x() + hValue);
+        }
+        if(m_pVScrollBar)
+        {
+            int vValue = m_pVScrollBar->value();
+            m_pVScrollBar->setValue(delta.y() + vValue);
+        }
+        m_pMouseStart = event->pos();
+    }
+}
+
+void MouseMoveWidget::mousePressEvent(QMouseEvent *event)
+{
+    if (event->buttons() & Qt::MouseButton::LeftButton)
+    {
+        m_pMouseStart = event->pos();
+    }
+    QWidget::mousePressEvent(event);
+}

+ 24 - 0
Qt/Qt_Test_Pro_5inch/mousemovewidget.h

@@ -0,0 +1,24 @@
+#ifndef MOUSEMOVEWIDGET_H
+#define MOUSEMOVEWIDGET_H
+
+#include <QWidget>
+#include <QScrollBar>
+class MouseMoveWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit MouseMoveWidget(QWidget *parent = nullptr);
+
+    void SetScrollBar(QScrollBar* pHScrollBar,QScrollBar* pVScrollBar);
+protected:
+    void mouseMoveEvent(QMouseEvent* event);
+
+    void mousePressEvent(QMouseEvent* event);
+private:
+    QPoint m_pMouseStart;
+    QScrollBar* m_pHScrollBar;
+    QScrollBar* m_pVScrollBar;
+
+};
+
+#endif // MOUSEMOVEWIDGET_H

+ 21 - 0
Qt/Qt_Test_Pro_5inch/pdu_ctrl.cpp

@@ -25,6 +25,7 @@ pdu_Ctrl::pdu_Ctrl(QObject *parent) : QObject(parent),m_PowerBoard(nullptr),nPow
     nChidPHIndex=0;
     m_nAngle=0;
     isT_ACType=0;
+    pMsgq=nullptr;
     memset(nButtonStatus,0,sizeof(nButtonStatus));
     //
 }
@@ -474,6 +475,26 @@ void pdu_Ctrl::RestartSys()
     system("reboot");
 }
 
+void pdu_Ctrl::setCHCtrl(int nCh, int nStatus)
+{
+    if(pMsgq)
+    {
+        MsgData pMsgData;
+        memset(&pMsgData,0,sizeof(MsgData));
+        if(nCh<=0)
+        {
+            pMsgData.CtrlType=Msg_All_Ctrl;
+            pMsgData.nValue[0]=nStatus;
+        }else
+        {
+            pMsgData.CtrlType=Msg_Ch_Ctrl;
+            pMsgData.nValue[0]=nCh;
+            pMsgData.nValue[1]=nStatus;
+        }
+        pMsgq->sendResponse(&pMsgData);
+    }
+}
+
 void pdu_Ctrl::ButtonDown(int nButtonID, BtnDownType nDownType)
 {
     //规整按钮状态

+ 12 - 2
Qt/Qt_Test_Pro_5inch/pdu_ctrl.h

@@ -2,15 +2,16 @@
 #define PDU_CTRL_H
 
 
-
+#include "common.h"
 #include "global.h"
 #include "widget.h"
+#include "qt_pdu_msgq.h"
 #define hightSmartPDU
 //#define RS485Type
 //#define RS485IpType
 //#define PDU_sys
 #define pduRun
-#include "common.h"
+
 enum WidgetType
 {
     widgetType_Main=0,      //轮询页面
@@ -75,6 +76,7 @@ struct CHOverMG
     GlobalOverManager OverData;
 };
 
+class qt_pdu_msgq;
 class pdu_Ctrl : public QObject
 {
     Q_OBJECT
@@ -128,6 +130,9 @@ public:
     void AddOverMG(CHOverMG& pData);
     //获取报警信息
     PowerWarningInfo* getWarningData(int nAddrID,int nAddrCHID);
+
+    //======设置所通道开关=======
+    void setCHCtrl(int nCh,int nStatus);//-1则是全部控制
 private:
     //处理多个点
     void ButtonDown(int nButtonID, BtnDownType nDownType);
@@ -146,6 +151,8 @@ private:
     //======恢复出厂设置=========
     void ResetAll();
     void RestartSys();
+
+
 signals:
 
 public slots:
@@ -185,6 +192,7 @@ private:
     //超限设置
     QMap<int,QMap<int,CHOverMG>> m_chOverMG;
     //modbus设置
+
 public:
     int m_nModbusSelect;
     int m_nModbusAddress;//从机地址
@@ -194,6 +202,8 @@ public:
 
     int isT_ACType;
     int lastACIndex;
+
+    qt_pdu_msgq* pMsgq;
 };
 
 #endif // PDU_CTRL_H

+ 36 - 0
Qt/Qt_Test_Pro_5inch/qmousemovelist.cpp

@@ -0,0 +1,36 @@
+#include "qmousemovelist.h"
+#include <QMouseEvent>
+
+QMouseMoveList::QMouseMoveList(QWidget *parent):QTableWidget(parent),m_pMouseStart(0,0)
+{
+    setHorizontalScrollMode(ScrollPerPixel);
+    setVerticalScrollMode(ScrollPerPixel);
+}
+
+void QMouseMoveList::mouseMoveEvent(QMouseEvent *event)
+{
+    if (event->buttons()&Qt::MouseButton::LeftButton)
+    {
+        QPoint delta = m_pMouseStart - event->pos();
+        if(horizontalScrollBar())
+        {
+            int hValue =horizontalScrollBar()->value();
+            horizontalScrollBar()->setValue(delta.x() + hValue);
+        }
+        if(verticalScrollBar())
+        {
+            int vValue = verticalScrollBar()->value();
+            verticalScrollBar()->setValue(delta.y() + vValue);
+        }
+        m_pMouseStart = event->pos();
+    }
+}
+
+void QMouseMoveList::mousePressEvent(QMouseEvent *event)
+{
+    if (event->buttons() & Qt::MouseButton::LeftButton)
+    {
+        m_pMouseStart = event->pos();
+    }
+    QWidget::mousePressEvent(event);
+}

+ 22 - 0
Qt/Qt_Test_Pro_5inch/qmousemovelist.h

@@ -0,0 +1,22 @@
+#ifndef QMOUSEMOVELIST_H
+#define QMOUSEMOVELIST_H
+
+#include <QTableWidget>
+#include <QScrollBar>
+class QMouseMoveList : public QTableWidget
+{
+    Q_OBJECT
+public:
+    explicit QMouseMoveList(QWidget *parent = nullptr);
+protected:
+    void mouseMoveEvent(QMouseEvent* event);
+
+    void mousePressEvent(QMouseEvent* event);
+private:
+    QPoint m_pMouseStart;
+    QScrollBar* m_pHScrollBar;
+    QScrollBar* m_pVScrollBar;
+
+};
+
+#endif // QMOUSEMOVELIST_H

+ 87 - 0
Qt/Qt_Test_Pro_5inch/qt_pdu_msgq.cpp

@@ -0,0 +1,87 @@
+#include "qt_pdu_msgq.h"
+#include <QDebug>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <qfile.h>
+qt_pdu_msgq::qt_pdu_msgq(QObject *parent) : QObject(parent)
+{
+
+/*
+    // 尝试清理旧队列
+    int msgid = msgget(key, 0666);
+    if (msgid != -1) {
+        struct msqid_ds buf;
+        if (msgctl(msgid, IPC_STAT, &buf) == 0) {
+            if (buf.msg_qnum > 0) {
+                qWarning() << "Cleaning" << buf.msg_qnum << "stale messages";
+                while(msgrcv(msgid, nullptr, 0, 0, IPC_NOWAIT) != -1);
+            }
+            msgctl(msgid, IPC_RMID, nullptr);
+        }
+    }
+*/
+    // 创建新队列
+
+//    qDebug()<<"MSG INIT SUCCESS msgid"<<msgid;
+}
+void qt_pdu_msgq::startListening()
+{
+    running = true;
+    MsgData msg;
+
+    while(running) {
+        if(msgrcv(msgid, &msg, sizeof(msg)-sizeof(long),1,IPC_NOWAIT) > 0)
+        {
+            //emit newMessageReceived(msg.CtrlType, msg.nValue);
+        }else
+        {
+            usleep(100000); // 100ms轮询
+        }
+
+    }
+}
+
+void qt_pdu_msgq::sendResponse(MsgData* pMSGData)
+{
+    if(!pMSGData)
+    {
+        return;
+    }
+    const char* path = "/root/run/app/smartPDU_MSGQ";
+    QFile::setPermissions(path, QFile::ReadOwner|QFile::WriteOwner|QFile::ReadGroup|QFile::WriteGroup|QFile::ReadOther|QFile::WriteOther);
+    key_t key = ftok(path, 'Q');
+    if (key == -1) {
+        qCritical() << "ftok failed:" << strerror(errno);
+        return;
+    }
+    msgid = msgget(key, 0666 | IPC_CREAT);
+    if (msgid == -1) {
+        qCritical() << "msgget failed:" << strerror(errno);
+        return;
+    }
+
+    MsgData msg;
+    msg=*pMSGData;
+    msg.MsgType=1;
+    qDebug()<<"MSGType="<<QString::number(msg.MsgType);
+    qDebug()<<"CtrlType="<<QString::number(msg.CtrlType);
+//    qDebug()<<"strData="<<QString::fromLocal8Bit(msg.strData);
+    qDebug()<<"nValue1="<<QString::number(msg.nValue[0]);
+    qDebug()<<"nValue2="<<QString::number(msg.nValue[1]);
+    qDebug()<<"msgid="<<msgid;
+    int r=msgsnd(msgid, &msg, sizeof(msg) - sizeof(long), IPC_NOWAIT);
+    if( r<0) {
+        qWarning() << "Qt send failed:" << strerror(errno);
+
+        if(r<0) {
+            qWarning()<<"msgsnd failed"<<r<<", errno:"<< errno;
+        }
+        else {
+            qWarning()<<"msgsnd ok\n";
+        }
+    }
+}
+
+void qt_pdu_msgq::stopListening() {
+    running = false;
+}

+ 29 - 0
Qt/Qt_Test_Pro_5inch/qt_pdu_msgq.h

@@ -0,0 +1,29 @@
+#ifndef QTMSGQUEUE_H
+#define QTMSGQUEUE_H
+
+
+#include <QObject>
+#include <sys/msg.h>
+#include "pdu_ctrl.h"
+
+class qt_pdu_msgq : public QObject
+{
+    Q_OBJECT
+public:
+    explicit qt_pdu_msgq(QObject *parent = nullptr);
+
+signals:
+    void newMessageReceived(int nCtrlType,const char* msg, int* nvalue,double* fvalue);
+
+public slots:
+    void startListening();
+    void stopListening();
+    void sendResponse(MsgData* pMSGData);
+
+private:
+    int msgid;
+    bool running;
+
+};
+
+#endif // QTMSGQUEUE_H

+ 23 - 0
Qt/Qt_Test_Pro_5inch/runchwiget.cpp

@@ -2,6 +2,7 @@
 #include "ui_runchwiget.h"
 #include "pdu_ctrl.h"
 #include <QScroller>
+#include <warningwnd.h>
 RunChWiget::RunChWiget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::RunChWiget),
@@ -9,6 +10,8 @@ RunChWiget::RunChWiget(QWidget *parent) :
 {
     ui->setupUi(this);
     //setRunCh();
+    ui->scrollAreaWidgetContents->SetScrollBar(ui->scrollArea->horizontalScrollBar(),ui->scrollArea->verticalScrollBar());
+    connect(ui->pushButton,&QPushButton::clicked,this,&RunChWiget::slot_ALLCHCtrl);
 }
 
 RunChWiget::~RunChWiget()
@@ -37,6 +40,7 @@ void RunChWiget::setRunCh()
             int nChIndex=nChId++;
             ch_Widget* pNewCH=new ch_Widget(this);
             pNewCH->setDataCHP(nChIndex,&(pAllChData[nIndex]._PowerInfo[nSubIndex]),&(pAllChData[nIndex]._PowerWarninginfo[nSubIndex]));
+            connect(pNewCH,SIGNAL(singal_DoubleClick(int)),this,SLOT(slot_CtrlCH(int)));
             qDebug()<<"AddWidget="<<nChIndex;
             AddWidget(pNewCH);
             pNewCH->show();
@@ -104,3 +108,22 @@ void RunChWiget::initScrollArea()
     // 设置视口必须接受触摸事件
     ui->scrollArea->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
 }
+
+void RunChWiget::slot_CtrlCH(int nIndex)
+{
+    WarningWnd pCtrlBox(this);
+    pCtrlBox.SetCHID(nIndex);
+    //connect(pCtrlBox,SIGNAL(signals_CHCtrl(int,int)),this,SLOT());
+    pCtrlBox.setModal(true);
+
+    pCtrlBox.exec();
+}
+
+void RunChWiget::slot_ALLCHCtrl()
+{
+    WarningWnd pCtrlBox(this);
+    pCtrlBox.SetCHID(0);
+    //connect(pCtrlBox,SIGNAL(signals_CHCtrl(int,int)),this,SLOT());
+    pCtrlBox.setModal(true);
+    pCtrlBox.exec();
+}

+ 4 - 0
Qt/Qt_Test_Pro_5inch/runchwiget.h

@@ -24,6 +24,10 @@ public:
     void AddWidget(ch_Widget* pCHWidget);
 
     void initScrollArea();
+public slots:
+    void slot_CtrlCH(int nIndex);
+
+    void slot_ALLCHCtrl();
 private:
     Ui::RunChWiget *ui;
     int SaveIndex=0;

+ 62 - 3
Qt/Qt_Test_Pro_5inch/runchwiget.ui

@@ -14,21 +14,72 @@
    <string>Form</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>5</number>
+   </property>
+   <property name="leftMargin">
+    <number>5</number>
+   </property>
+   <property name="topMargin">
+    <number>5</number>
+   </property>
+   <property name="rightMargin">
+    <number>5</number>
+   </property>
+   <property name="bottomMargin">
+    <number>5</number>
+   </property>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButton">
+       <property name="text">
+        <string>通道总控</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
    <item>
     <widget class="QScrollArea" name="scrollArea">
      <property name="widgetResizable">
       <bool>true</bool>
      </property>
-     <widget class="QWidget" name="scrollAreaWidgetContents">
+     <widget class="MouseMoveWidget" name="scrollAreaWidgetContents">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
-        <width>456</width>
-        <height>248</height>
+        <width>468</width>
+        <height>217</height>
        </rect>
       </property>
       <layout class="QGridLayout" name="gridLayout">
+       <property name="leftMargin">
+        <number>5</number>
+       </property>
+       <property name="topMargin">
+        <number>5</number>
+       </property>
+       <property name="rightMargin">
+        <number>5</number>
+       </property>
+       <property name="bottomMargin">
+        <number>5</number>
+       </property>
        <property name="spacing">
         <number>0</number>
        </property>
@@ -38,6 +89,14 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>MouseMoveWidget</class>
+   <extends>QWidget</extends>
+   <header>mousemovewidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

+ 7 - 5
Qt/Qt_Test_Pro_5inch/runlogwidget.cpp

@@ -33,12 +33,14 @@ void RunLogWidget::InitUI()
     ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
     //ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
     ui->tableWidget->verticalHeader()->setVisible(false);
+    ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
     ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
-    QScroller::grabGesture(ui->tableWidget->viewport(), QScroller::TouchGesture);
-    QScrollerProperties properties = QScroller::scroller(ui->tableWidget)->scrollerProperties();
-    properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6); // 惯性系数
-    properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2); // 弹性效果
-    ui->tableWidget->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); // 启用触控事件
+
+//    QScroller::grabGesture(ui->tableWidget->viewport(), QScroller::TouchGesture);
+//    QScrollerProperties properties = QScroller::scroller(ui->tableWidget)->scrollerProperties();
+//    properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6); // 惯性系数
+//    properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2); // 弹性效果
+//    ui->tableWidget->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); // 启用触控事件
 }
 
 void RunLogWidget::AddRowData(int nIndex, int nType, QString nTime, QString strMSG)

+ 132 - 0
Qt/Qt_Test_Pro_5inch/runlogwidget.cpp.autosave

@@ -0,0 +1,132 @@
+#include "runlogwidget.h"
+#include "ui_runlogwidget.h"
+#include "pdu_ctrl.h"
+#include <QScroller>
+RunLogWidget::RunLogWidget(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::RunLogWidget)
+{
+    ui->setupUi(this);
+    InitUI();
+    currentPage=1;
+}
+
+RunLogWidget::~RunLogWidget()
+{
+    delete ui;
+}
+
+void RunLogWidget::UpdateLog()
+{
+    calculateTotalPages();
+    loadPage(currentPage);
+}
+
+void RunLogWidget::InitUI()
+{
+    connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(slot_upPage()));
+    connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(slot_downPage()));
+    QStringList headers = {"序号", "时间", "类型","记录"};
+    ui->tableWidget->setColumnCount(4);
+    ui->tableWidget->setHorizontalHeaderLabels(headers);
+    // 设置自动调整列宽
+    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
+    //ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
+    ui->tableWidget->verticalHeader()->setVisible(false);
+    ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
+    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
+
+//    QScroller::grabGesture(ui->tableWidget->viewport(), QScroller::TouchGesture);
+//    QScrollerProperties properties = QScroller::scroller(ui->tableWidget)->scrollerProperties();
+//    properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6); // 惯性系数
+//    properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2); // 弹性效果
+//    ui->tableWidget->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); // 启用触控事件
+}
+
+void RunLogWidget::AddRowData(int nIndex, int nType, QString nTime, QString strMSG)
+{
+    int row = ui->tableWidget->rowCount();
+    ui->tableWidget->insertRow(row);
+
+    QTableWidgetItem *item = new QTableWidgetItem(QString::number(nIndex));
+    ui->tableWidget->setItem(row, 0, item);
+    QTableWidgetItem *item1 = new QTableWidgetItem(nTime);
+    ui->tableWidget->setItem(row, 1, item1);
+    QTableWidgetItem *item2 = new QTableWidgetItem(QString::number(nType));
+    ui->tableWidget->setItem(row, 2, item2);
+    QString strData=strMSG;
+    strData.replace("$","");
+    strData.replace("|","");
+    QTableWidgetItem *item3 = new QTableWidgetItem(strData);
+    ui->tableWidget->setItem(row, 3, item3);
+}
+
+void RunLogWidget::ClearList()
+{
+    ui->tableWidget->clearContents();
+    ui->tableWidget->setRowCount(0);
+}
+
+void RunLogWidget::calculateTotalPages()
+{
+    QSqlQuery query(pdu_Ctrl::instance()->getDB());
+    QString strExec="SELECT COUNT(*) FROM Table_AlarmManage";
+    if (query.exec(strExec) && query.next()) {
+        int totalRecords = query.value(0).toInt();
+        totalPages = (totalRecords + perPage - 1) / perPage;
+    }
+}
+
+void RunLogWidget::loadPage(int page)
+{
+
+
+    QSqlQuery query(pdu_Ctrl::instance()->getDB());
+        query.prepare(
+            "SELECT alarmNumber, alarmDate, alarmType, product_id, alarmContent "
+            "FROM Table_AlarmManage "
+            "ORDER BY alarmDate DESC "
+            "LIMIT :limit OFFSET :offset"
+        );
+        query.bindValue(":limit", perPage);
+        query.bindValue(":offset", (page - 1) * perPage);
+        if (!query.exec()) {
+            //QMessageBox::warning(this, "Query Error", query.lastError().text());
+            return;
+        }
+        ClearList();
+        while (query.next()) {
+            int totalRecords = query.value(0).toInt();
+            //int totalRecords1 = query.value(1).toInt();
+            int totalRecords2 = query.value(2).toInt();
+            QString totalRecords3 = query.value(1).toString();
+            QString totalRecords4 = query.value(4).toString();
+            AddRowData(totalRecords,totalRecords2,totalRecords3,totalRecords4);
+        }
+        ui->tableWidget->resizeColumnsToContents();
+
+        ui->labelPage->setText(QString("Page: %1/%2").arg(page).arg(totalPages));
+
+}
+
+void RunLogWidget::updateButtons()
+{
+    ui->prevButton->setEnabled(currentPage > 1);
+    ui->nextButton->setEnabled(currentPage < totalPages);
+}
+
+void RunLogWidget::slot_upPage()
+{
+    if (currentPage > 1) {
+           loadPage(--currentPage);
+           updateButtons();
+       }
+}
+
+void RunLogWidget::slot_downPage()
+{
+    if (currentPage < totalPages) {
+        loadPage(++currentPage);
+        updateButtons();
+    }
+}

+ 1 - 1
Qt/Qt_Test_Pro_5inch/runlogwidget.h

@@ -38,7 +38,7 @@ private:
 
     int currentPage = 1;
     int totalPages = 0;
-    const int perPage = 20;
+    const int perPage = 6;
 };
 
 #endif // RUNLOGWIDGET_H

+ 8 - 1
Qt/Qt_Test_Pro_5inch/runlogwidget.ui

@@ -15,7 +15,7 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QTableWidget" name="tableWidget"/>
+    <widget class="QMouseMoveList" name="tableWidget"/>
    </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
@@ -57,6 +57,13 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QMouseMoveList</class>
+   <extends>QTableWidget</extends>
+   <header>qmousemovelist.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

+ 6 - 5
Qt/Qt_Test_Pro_5inch/thresholdlistwidget.cpp

@@ -96,14 +96,15 @@ void ThresholdListWidget::InitUI()
                                   "电流上限(A)", "功率上限(W)", "电量上限(Wh)"};
     ui->tableWidget->setColumnCount(6);
     ui->tableWidget->setHorizontalHeaderLabels(headers);
-    QScroller::grabGesture(ui->tableWidget->viewport(), QScroller::TouchGesture);
-    QScrollerProperties properties = QScroller::scroller(ui->tableWidget)->scrollerProperties();
-    properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6); // 惯性系数
-    properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2); // 弹性效果
-    ui->tableWidget->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); // 启用触控事件
+//    QScroller::grabGesture(ui->tableWidget->viewport(), QScroller::TouchGesture);
+//    QScrollerProperties properties = QScroller::scroller(ui->tableWidget)->scrollerProperties();
+//    properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6); // 惯性系数
+//    properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2); // 弹性效果
+//    ui->tableWidget->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); // 启用触控事件
     // 设置自动调整列宽
     ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
     ui->tableWidget->verticalHeader()->setVisible(false);
+    ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
     ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
 }
 

+ 1 - 1
Qt/Qt_Test_Pro_5inch/thresholdlistwidget.h

@@ -2,7 +2,7 @@
 #define THRESHOLDLISTWIDGET_H
 
 #include <QWidget>
-#include "common.h"
+#include "pdu_ctrl.h"
 namespace Ui {
 class ThresholdListWidget;
 }

+ 8 - 1
Qt/Qt_Test_Pro_5inch/thresholdlistwidget.ui

@@ -15,10 +15,17 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QTableWidget" name="tableWidget"/>
+    <widget class="QMouseMoveList" name="tableWidget"/>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QMouseMoveList</class>
+   <extends>QTableWidget</extends>
+   <header>qmousemovelist.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

+ 59 - 0
Qt/Qt_Test_Pro_5inch/warningwnd.cpp

@@ -0,0 +1,59 @@
+#include "warningwnd.h"
+#include "ui_warningwnd.h"
+#include "pdu_ctrl.h"
+WarningWnd::WarningWnd(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::WarningWnd)
+{
+    ui->setupUi(this);
+    connect(ui->pushButton,&QPushButton::clicked,this,&WarningWnd::slot_CHOpen);
+    connect(ui->pushButton_2,&QPushButton::clicked,this,&WarningWnd::slot_CHClose);
+    connect(ui->pushButton_3,&QPushButton::clicked,this,&WarningWnd::slot_ClostWnd);
+    connect(ui->pushButton_4,&QPushButton::clicked,this,&WarningWnd::slot_ClostWnd);
+    nCHID=0;
+
+}
+
+WarningWnd::~WarningWnd()
+{
+    delete ui;
+}
+
+void WarningWnd::SetCHID(int CHID)
+{
+    QString strText ="CH通道控制";
+    if(CHID<=0)
+    {
+        strText="所有通道控制";
+    }else
+    {
+        strText="CH"+QString::number(CHID)+"通道控制";
+    }
+    nCHID=CHID;
+    ui->label_2->setText(strText);
+}
+
+void WarningWnd::slot_CHOpen()
+{
+    pdu_Ctrl::instance()->setCHCtrl(nCHID,1);
+    //emit signals_CHCtrl(nCHID,1);
+}
+
+void WarningWnd::slot_CHClose()
+{
+    pdu_Ctrl::instance()->setCHCtrl(nCHID,0);
+    //emit signals_CHCtrl(nCHID,0);
+}
+
+void WarningWnd::slot_ClostWnd()
+{
+    close();
+}
+
+void WarningWnd::paintEvent(QPaintEvent *event)
+{
+    QPainter painter(this);
+    QPen pen(Qt::black, 5); // 5px 红色边框
+    painter.setPen(pen);
+    painter.drawRect(rect().adjusted(1, 1, -1, -1)); // 向内缩进2px
+}

+ 33 - 0
Qt/Qt_Test_Pro_5inch/warningwnd.h

@@ -0,0 +1,33 @@
+#ifndef WARNINGWND_H
+#define WARNINGWND_H
+
+#include <QDialog>
+
+namespace Ui {
+class WarningWnd;
+}
+
+class WarningWnd : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit WarningWnd(QWidget *parent = 0);
+    ~WarningWnd();
+
+    void SetCHID(int CHID);
+private slots:
+    void slot_CHOpen();
+    void slot_CHClose();
+    void slot_ClostWnd();
+protected:
+    void paintEvent(QPaintEvent *event) ;
+signals:
+    void signals_CHCtrl(int nCHID,int nStatus);
+private:
+    Ui::WarningWnd *ui;
+    int nCHID;
+
+};
+
+#endif // WARNINGWND_H

+ 95 - 0
Qt/Qt_Test_Pro_5inch/warningwnd.ui

@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WarningWnd</class>
+ <widget class="QWidget" name="WarningWnd">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>348</width>
+    <height>155</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
+   <property name="leftMargin">
+    <number>5</number>
+   </property>
+   <property name="topMargin">
+    <number>5</number>
+   </property>
+   <property name="rightMargin">
+    <number>5</number>
+   </property>
+   <property name="bottomMargin">
+    <number>5</number>
+   </property>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>通道控制</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButton_3">
+       <property name="text">
+        <string>X</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QLabel" name="label_2">
+     <property name="text">
+      <string>CH通道控制</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <property name="leftMargin">
+      <number>20</number>
+     </property>
+     <property name="rightMargin">
+      <number>20</number>
+     </property>
+     <property name="bottomMargin">
+      <number>5</number>
+     </property>
+     <item>
+      <widget class="QPushButton" name="pushButton">
+       <property name="text">
+        <string>开启</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButton_2">
+       <property name="text">
+        <string>关闭</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButton_4">
+       <property name="text">
+        <string>取消</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>