Просмотр исходного кода

上传QT和app两方提示信息同步的功能

chenyuanjie 1 год назад
Родитель
Сommit
ccbe4d0777

+ 6 - 3
Qt/Qt_Test/Qt_Test.pro

@@ -30,7 +30,8 @@ SOURCES += \
     volviewform.cpp \
     udphelper.cpp \
     dataupdatethread.cpp \
-    buttonclickthread.cpp
+    buttonclickthread.cpp \
+    msgwidget.cpp
 
 HEADERS += \
     pdu_ctrl.h \
@@ -38,11 +39,13 @@ HEADERS += \
     volviewform.h \
     udphelper.h \
     dataupdatethread.h \
-    buttonclickthread.h
+    buttonclickthread.h \
+    msgwidget.h
 
 FORMS += \
     volviewform.ui \
-    widget.ui
+    widget.ui \
+    msgwidget.ui
 
 target.path = /root/web_temp
 INSTALLS += target

+ 1 - 1
Qt/Qt_Test/Qt_Test.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.5.2, 2025-06-22T00:53:08. -->
+<!-- Written by QtCreator 4.5.2, 2025-07-19T14:10:39. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 1 - 2
Qt/Qt_Test/buttonclickthread.h

@@ -1,7 +1,6 @@
 #ifndef BUTTONCLICKTHREAD_H
 #define BUTTONCLICKTHREAD_H
-//#define hightSmartPDU
-#define rs485KEY
+
 #include <QObject>
 #include <QThread>
 #include <QDebug>

+ 103 - 0
Qt/Qt_Test/dataupdatethread.cpp

@@ -19,6 +19,7 @@ DataUpdateThread::DataUpdateThread(QObject *parent)
     nReadType=0;
     m_shmData=0;
     bTacStatus=0;
+    nIndexMSG=0;
 }
 
 DataUpdateThread::~DataUpdateThread()
@@ -80,12 +81,14 @@ void DataUpdateThread::run()
                     pwidget->UpdateDate();
                     pwidget->update();
                 }
+                ReadMSG();
             }else
             {
                 int nMode=pwidget->getShowModeIndex();
                 int nPage=pwidget->getShowPagIndex();
                 //qDebug() <<"ReadType=1 nMode:"<<nMode<<";nPage"<<nPage;
                 ReadShmMaxch();
+                ReadMSG();
                 if(nMode==0&&nPage!=0)
                 {
                     int nSubPag=pwidget->getShowSubIndex();
@@ -118,6 +121,12 @@ void DataUpdateThread::run()
     }
 }
 
+void DataUpdateThread::SetShowWidget(Widget *pShowWidget)
+{
+    pwidget=pShowWidget;
+    connect(pwidget,SIGNAL(signal_ClickMSG()),this,SLOT(slot_ClickMSG()));
+}
+
 void DataUpdateThread::ReadSqlData(int nCHID)
 {
     if(!isDBOpen)
@@ -319,4 +328,98 @@ int DataUpdateThread::isT_ACType()
     return bTacStatus;
 }
 
+void DataUpdateThread::ReadMSG()
+{
+    if(nReadType!=1&&!m_shmData)
+    {
+        return;
+    }
+    if(0<=nIndexMSG&&nIndexMSG<10)
+    {
+        switch(m_shmData->nTypeCtrlType[nIndexMSG])
+        {
+            case MSGCtrl_Null:
+            case MSGCtrl_Click:
+            {
+                bool isHaveMSG=false;
+                //未检测到更新从当前位置循环遍历一遍
+                qDebug()<<"MSG_Find"<<nIndexMSG<<"=Null";
+                for(int nIndex=0;nIndex<10;nIndex++)//监测其他的点是否有被更新依次刷新过去
+                {
+                    nIndexMSG=NextIndex();
+                    if(m_shmData->nTypeCtrlType[nIndexMSG]==MSGCtrl_Write)//检测到新的点。
+                    {
+                        qDebug()<<nIndexMSG<<"=MSGCtrl_Write";
+                        isHaveMSG=true;
+                        QString strShow=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
+                        qDebug()<<"MSG_Update char*MSG="<<m_shmData->strMSG[nIndexMSG];
+                        qDebug()<<"MSG_Update strMSG="<<strShow;
+                        ShowMSGWidget(strShow);
+                        break;
+                    }else
+                    {
+                        //qDebug()<<nIndexMSG<<"="<<m_shmData->nTypeCtrlType[nIndexMSG];
+                    }
+                }
+                if(isHaveMSG)
+                {
+                    nIndexMSG=0;//如果全没有就重新设置到0从0开始
+                }
+            }
+            break;
+            case MSGCtrl_Write://存在已写入的数据
+            {
+                QString strShow=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
+                qDebug()<<"MSG_Update char*MSG="<<m_shmData->strMSG[nIndexMSG];
+                qDebug()<<"MSG_Update strMSG="<<strShow;
+                ShowMSGWidget(strShow);
+            }
+            break;
+            default:
+                break;
+        }
+        qDebug()<<"MSG_Switch_end nIndexMSG ="<<nIndexMSG;
+    }
+}
+
+int DataUpdateThread::NextIndex()
+{
+    if(0<=nIndexMSG&&nIndexMSG<9)
+    {
+        return nIndexMSG+1;
+    }else
+    {
+        return 0;
+    }
+}
+
+void DataUpdateThread::ShowMSGWidget(QString strShowData)
+{
+    if(strShowData.isEmpty())return;
+    if(pwidget&&pwidget->isHiddenMSGWidget())
+    {
+        if(strShowData!=strNowMSG)
+        {
+            strNowMSG=strShowData;
+            pwidget->ShowMSGWidget(strShowData);
+        }
+    }
+}
+
+void DataUpdateThread::slot_ClickMSG()
+{
+    strNowMSG="";
+    if(nReadType!=1&&!m_shmData)
+    {
+        return;
+    }
+    if(0<=nIndexMSG&&nIndexMSG<10)
+    {
+        m_shmData->nTypeCtrlType[nIndexMSG]=MSGCtrl_Click;
+    }
+    nIndexMSG=NextIndex();
+
+    //ReadMSG();
+}
+
 

+ 21 - 1
Qt/Qt_Test/dataupdatethread.h

@@ -30,6 +30,16 @@ struct smartPDU_shm_data
     //三项数据
     int bT_ACType;//三相类型
     int nSelectPh;//当前通道的三相ph参数:0:A相 1:B相 2:C相 -1通道总计
+    //报警列表 0表示空,1表示写入,2表示已确认可清空。
+    int nTypeCtrlType[10];
+    char strMSG[10][50];
+};
+enum MSGCtrlType
+{
+    MSGCtrl_Null=0,
+    MSGCtrl_Write=1,
+    MSGCtrl_Click=2,
+    MSGCtrl_ReWrite=3,
 };
 class DataUpdateThread : public QThread
 {
@@ -41,6 +51,7 @@ public:
 
     void run();
 
+    void SetShowWidget(Widget* pShowWidget);
     void ReadSqlData(int nCHID=0);
     void ReadMaxCh();
 
@@ -52,6 +63,12 @@ public:
     void ReadShmMaxch();
     void ReadShmVer();
     int isT_ACType();//三相标志
+
+    void ReadMSG();//获取报警提示
+    int NextIndex();
+    void ShowMSGWidget(QString strShowData);
+public slots:
+    void slot_ClickMSG();//确认msg
 public:
     //窗口
     Widget* pwidget;
@@ -74,12 +91,15 @@ public:
     QString strStatus;
     QString strVer;
     int nMaxCh;
-
+    //读取状态:-1空删除,0
     int nReadType;
     int shm_fd;
 
     int bTacStatus;
     smartPDU_shm_data* m_shmData;
+    //显示msg位置
+    int nIndexMSG;
+    QString strNowMSG;//当前显示的名字
 };
 
 #endif // DATAUPDATETHREAD_H

+ 2 - 1
Qt/Qt_Test/main.cpp

@@ -46,7 +46,8 @@ int main(int argc, char *argv[])
     //============================线程开启====================================
     //数据更新线程
     DataUpdateThread thread_Update(nullptr);
-    thread_Update.pwidget=&w;
+    thread_Update.SetShowWidget(&w);
+
     //QString appDirPath = QCoreApplication::applicationDirPath();
     //thread_Update.strSqliteAddress=appDirPath+"/pdu_dat.db";
     thread_Update.initShm();

+ 22 - 0
Qt/Qt_Test/msgwidget.cpp

@@ -0,0 +1,22 @@
+#include "msgwidget.h"
+#include "ui_msgwidget.h"
+
+MSGWidget::MSGWidget(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::MSGWidget)
+{
+    ui->setupUi(this);
+    setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
+    setAttribute(Qt::WA_TranslucentBackground);
+    ui->label->setWordWrap(true);
+}
+
+MSGWidget::~MSGWidget()
+{
+    delete ui;
+}
+
+void MSGWidget::SetText(QString strShow)
+{
+    ui->label->setText(strShow);
+}

+ 22 - 0
Qt/Qt_Test/msgwidget.h

@@ -0,0 +1,22 @@
+#ifndef MSGWIDGET_H
+#define MSGWIDGET_H
+
+#include <QDialog>
+
+namespace Ui {
+class MSGWidget;
+}
+
+class MSGWidget : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit MSGWidget(QWidget *parent = 0);
+    ~MSGWidget();
+    void SetText(QString strShow);
+private:
+    Ui::MSGWidget *ui;
+};
+
+#endif // MSGWIDGET_H

+ 74 - 0
Qt/Qt_Test/msgwidget.ui

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MSGWidget</class>
+ <widget class="QWidget" name="MSGWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>144</width>
+    <height>71</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string/>
+  </property>
+  <property name="styleSheet">
+   <string notr="true">QWidget
+{
+	background-color: rgb(125, 125, 125);
+}
+QLabel
+{
+	color: rgb(255, 255, 255);
+}</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>0</number>
+   </property>
+   <property name="leftMargin">
+    <number>2</number>
+   </property>
+   <property name="topMargin">
+    <number>2</number>
+   </property>
+   <property name="rightMargin">
+    <number>2</number>
+   </property>
+   <property name="bottomMargin">
+    <number>2</number>
+   </property>
+   <item>
+    <widget class="QLabel" name="label_2">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>WARNING</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="font">
+      <font>
+       <pointsize>9</pointsize>
+      </font>
+     </property>
+     <property name="text">
+      <string>xxxxxxxxxxxxxxxxxxxxxxx</string>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 8 - 0
Qt/Qt_Test/pdu_ctrl.cpp

@@ -579,6 +579,14 @@ void pdu_Ctrl::ButtonDown(int nButtonID, BtnDownType nDownType)
         return;
     }
 
+    if(m_pWidget&&!m_pWidget->isHiddenMSGWidget())
+    {
+        if(nDownType==BtnDown_C||nDownType==BtnDown_D)
+        {
+            m_pWidget->ClickMSGBtn();
+            return;
+        }
+    }
     if(nViewShowType==widgetType_Main)
     {
         qDebug()<<"widgetType="<<widgetType_Main;

+ 5 - 1
Qt/Qt_Test/pdu_ctrl.h

@@ -6,6 +6,8 @@
 #include <QGraphicsProxyWidget>
 #include <QGraphicsView>
 #include "widget.h"
+
+
 #define hightSmartPDU
 //#define RS485Type
 //#define RS485IpType
@@ -116,6 +118,8 @@ public slots:
     void slot_DClickBtn(int nButton);
     void slot_LClickBtn(int nButton);
     void slot_BtnClear(int nButton);
+
+
 private:
     //单例数据
     explicit pdu_Ctrl(QObject *parent = nullptr);
@@ -134,7 +138,7 @@ private:
     //其他界面指针
     QGraphicsProxyWidget* m_pAngleCtrl;
     QGraphicsView* m_pView;
-    Widget* m_pWidget;
+    Widget* m_pWidget;//主界面
     int m_nWidth;
     int m_nHeight;
 

+ 28 - 1
Qt/Qt_Test/widget.cpp

@@ -20,6 +20,7 @@ Widget::Widget(QWidget *parent) :
     m_nWidth = 160;
     m_nHeight = 128;
     m_pAngleCtrl=NULL;
+#ifdef RS485Type
 #ifdef RS485IpType
     //ui->label_MSName->hide();
     //ui->label_MSData->hide();
@@ -35,12 +36,16 @@ Widget::Widget(QWidget *parent) :
     ui->label_4->hide();
     ui->label_5->hide();
 #endif
-#ifdef hightSmartPDU
+#else
+//#ifdef hightSmartPDU
     ui->label_modbus_type->hide();
     ui->label_modbus_Addr->hide();
+//#endif
 #endif
     ui->stackedWidget_Main->setCurrentIndex(0);
     //ui->stackedWidget_Main->setCurrentWidget(ui->page_7);
+    m_pMSGWidget=new MSGWidget(this);
+    m_pMSGWidget->hide();
 }
 
 Widget::~Widget()
@@ -430,3 +435,25 @@ void Widget::CtrlBtnSet(int nIndex, int nData)
     }break;
     }
 }
+
+void Widget::ShowMSGWidget(QString strShowData)
+{
+    if(strShowData.isEmpty())
+        return;
+    if(m_pMSGWidget&&m_pMSGWidget->isHidden())
+    {
+        m_pMSGWidget->SetText(strShowData);
+        QRect parentRect = this->geometry();
+        m_pMSGWidget->move(parentRect.center() - m_pMSGWidget->rect().center());
+        m_pMSGWidget->show();
+    }
+}
+
+void Widget::ClickMSGBtn()
+{
+    if(m_pMSGWidget&&!m_pMSGWidget->isHidden())
+    {
+        m_pMSGWidget->hide();
+        emit signal_ClickMSG();
+    }
+}

+ 18 - 1
Qt/Qt_Test/widget.h

@@ -8,7 +8,7 @@
 #include <QLabel>
 #include <QGraphicsProxyWidget>
 #include <QGraphicsView>
-
+#include "msgwidget.h"
 namespace Ui {
 class Widget;
 }
@@ -77,6 +77,19 @@ public:
     void setSelectStatus(int nIndex);
     void CtrlBtnSet(int nIndex,int nData);
     int nMAXChildIndex;
+
+    //显示msg窗口
+    void ShowMSGWidget(QString strShowData);
+    //是否显示MSG
+    bool isHiddenMSGWidget(){
+        if(m_pMSGWidget)
+            return m_pMSGWidget->isHidden();
+        return false;
+    }
+    //点击任意按钮确认
+    void ClickMSGBtn();
+signals:
+    void signal_ClickMSG();//报警确认
 public:
     Ui::Widget *ui;
 private:
@@ -93,6 +106,10 @@ private:
     QGraphicsView* m_pView;
     int m_nWidth;
     int m_nHeight;
+
+
+    MSGWidget* m_pMSGWidget;//提示界面
+    int nIndexShow;
 };
 
 #endif // WIDGET_H

+ 1 - 1
Qt/Qt_Test/widget.ui

@@ -95,7 +95,7 @@ QLabel
           <item>
            <widget class="QStackedWidget" name="stackedWidget_Main">
             <property name="currentIndex">
-             <number>3</number>
+             <number>0</number>
             </property>
             <widget class="QWidget" name="page_4">
              <layout class="QVBoxLayout" name="verticalLayout_6">

BIN
cust_data/qt/IP/Qt_Test


BIN
cust_data/qt/Qt_Test


BIN
cust_data/qt/rgb_lcd/Qt_Test


+ 1 - 0
pro/src/app.c

@@ -2572,6 +2572,7 @@ static void* shm_thread(void *arg)
                     }
 
                     _globalDeviceManager->g_shm_Data->bPDUSet = 1;
+                    _globalDeviceManager->g_lastAlarmIndex=0;
                 }
                 else
                 { // 小于0 则主程序已析构退出重新等待加载

+ 4 - 0
pro/src/common.h

@@ -509,6 +509,9 @@ typedef struct
     //三项数据
     int bT_ACType;//三相类型
     int nSelectPh;//当前通道的三相ph参数:0:A相 1:B相 2:C相 -1通道总计
+        //报警列表 0表示空,1表示写入,2表示已确认可清空。
+    int nTypeCtrlType[10];
+    char strMSG[10][50];    
 } smartPDU_shm_data;
 
 //消息队列头结构体定义
@@ -1346,6 +1349,7 @@ typedef struct
     struct modbus_slave_read_reg g_modebus_read;
     struct modbus_slave_write_reg g_modebus_write;
     smartPDU_shm_data* g_shm_Data;
+    int                 g_lastAlarmIndex; //最后一次报警索引位置
     pthread_mutex_t     _power_ds;        //定时器锁 
     pthread_mutex_t     _power_update;        //数据刷新锁
     pthread_mutex_t     _sensor_update;        //传感器刷新锁

+ 53 - 1
pro/src/sqlite_handle.c

@@ -2855,6 +2855,53 @@ int dev_update_sensor_over_manage(sqlite3 *db,int product_id,int sensor_id,Globa
     sqlite3_free_table(pResult);
     return 0 ;
 }
+/// @brief 报警信息同步到(小屏幕)
+/// @param arg 
+/// @return 
+static void AlarmToShm(char* strData)
+{
+    GlobalPowerManger* _globalPowerMangerTemp = NULL ;
+    GlobalDeviceManager *_globalDeviceManager = (GlobalDeviceManager *)&__globalDeviceManage;
+    int nSize=strlen(strData);
+    if (nSize>50||nSize<=0)
+    {
+        /* code */
+        return;
+    }
+    
+    if (_globalDeviceManager->g_shm_Data)
+    { // 初始化成功
+        if(_globalDeviceManager->g_shm_Data->bPDUSet)
+        {
+            int isLastIndex=-1;//判断最后一个空闲的索引位置
+            for (size_t i = 0; i < 10; i++)
+            {
+                if (_globalDeviceManager->g_shm_Data->nTypeCtrlType[i] == 0||_globalDeviceManager->g_shm_Data->nTypeCtrlType[i] == 2)
+                {
+                    isLastIndex = i;
+                }
+            }    
+            if (isLastIndex != -1)//全部被占满则使用全局记录的位置进行添加
+            {
+                _globalDeviceManager->g_shm_Data->nTypeCtrlType[_globalDeviceManager->g_lastAlarmIndex]=1;//设置更新了一个报警
+                strcpy(_globalDeviceManager->g_shm_Data->strMSG[_globalDeviceManager->g_lastAlarmIndex], strData);
+                if (_globalDeviceManager->g_lastAlarmIndex < 10 && _globalDeviceManager->g_lastAlarmIndex >= 0)
+                {
+                    _globalDeviceManager->g_lastAlarmIndex++;
+                }
+                else
+                {
+                    _globalDeviceManager->g_lastAlarmIndex = 0;
+                }
+            }else//未被全部占满则使用空闲位置添加
+            {
+                _globalDeviceManager->g_shm_Data->nTypeCtrlType[isLastIndex]=1;//设置更新了一个报警
+                strcpy(_globalDeviceManager->g_shm_Data->strMSG[isLastIndex], strData);
+                _globalDeviceManager->g_lastAlarmIndex=isLastIndex;
+            }            
+        }
+    }
+}
 
 /// @brief 插入一条告警信息
 /// @param db 
@@ -2909,7 +2956,12 @@ int dev_insert_alarm_info(sqlite3* db,int product_id,int alarm_type,time_data_t
     sqlite3_free_table(pResult);
 
     //mail_send();
-
+    //只有是电源 传感器以及网络告警才同步到小屏幕上显示报警信息
+    if (alarm_type==ALARM_TYPE_POWER||alarm_type==ALARM_TYPE_SENSOR||alarm_type==ALARM_TYPE_NETWORK)
+    {
+        AlarmToShm(alarm_content);
+    }
+    
     return alarmNumber;
 }