Quellcode durchsuchen

增加报警数据长度到64

chenyuanjie vor 1 Jahr
Ursprung
Commit
a26cf50eff
4 geänderte Dateien mit 37 neuen und 13 gelöschten Zeilen
  1. 11 3
      Qt/Qt_Test/dataupdatethread.cpp
  2. 1 1
      Qt/Qt_Test/dataupdatethread.h
  3. 1 1
      pro/src/common.h
  4. 24 8
      pro/src/sqlite_handle.c

+ 11 - 3
Qt/Qt_Test/dataupdatethread.cpp

@@ -351,9 +351,11 @@ void DataUpdateThread::ReadMSG()
                     {
                         qDebug()<<nIndexMSG<<"=MSGCtrl_Write";
                         isHaveMSG=true;
-                        QString strShow=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
+                        QString strShow=QString::fromUtf8(m_shmData->strMSG[nIndexMSG]);
+                        QString strShow8bit=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
                         qDebug()<<"MSG_Update char*MSG="<<m_shmData->strMSG[nIndexMSG];
-                        qDebug()<<"MSG_Update strMSG="<<strShow;
+                        qDebug()<<"MSG_Update fromUtf8="<<strShow;
+                        qDebug()<<"MSG_Update fromLocal8bit="<<strShow8bit;
                         ShowMSGWidget(strShow);
                         break;
                     }else
@@ -369,9 +371,15 @@ void DataUpdateThread::ReadMSG()
             break;
             case MSGCtrl_Write://存在已写入的数据
             {
-                QString strShow=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
+                /*QString strShow=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
                 qDebug()<<"MSG_Update char*MSG="<<m_shmData->strMSG[nIndexMSG];
                 qDebug()<<"MSG_Update strMSG="<<strShow;
+                ShowMSGWidget(strShow);*/
+                QString strShow=QString::fromUtf8(m_shmData->strMSG[nIndexMSG]);
+                QString strShow8bit=QString::fromLocal8Bit(m_shmData->strMSG[nIndexMSG]);
+                qDebug()<<"MSG_Update char*MSG="<<m_shmData->strMSG[nIndexMSG];
+                qDebug()<<"MSG_Update fromUtf8="<<strShow;
+                qDebug()<<"MSG_Update fromLocal8bit="<<strShow8bit;
                 ShowMSGWidget(strShow);
             }
             break;

+ 1 - 1
Qt/Qt_Test/dataupdatethread.h

@@ -32,7 +32,7 @@ struct smartPDU_shm_data
     int nSelectPh;//当前通道的三相ph参数:0:A相 1:B相 2:C相 -1通道总计
     //报警列表 0表示空,1表示写入,2表示已确认可清空。
     int nTypeCtrlType[10];
-    char strMSG[10][50];
+    char strMSG[10][64];
 };
 enum MSGCtrlType
 {

+ 1 - 1
pro/src/common.h

@@ -511,7 +511,7 @@ typedef struct
     int nSelectPh;//当前通道的三相ph参数:0:A相 1:B相 2:C相 -1通道总计
         //报警列表 0表示空,1表示写入,2表示已确认可清空。
     int nTypeCtrlType[10];
-    char strMSG[10][50];    
+    char strMSG[10][64];    
 } smartPDU_shm_data;
 
 //消息队列头结构体定义

+ 24 - 8
pro/src/sqlite_handle.c

@@ -2860,15 +2860,25 @@ int dev_update_sensor_over_manage(sqlite3 *db,int product_id,int sensor_id,Globa
 /// @return 
 static void AlarmToShm(char* strData)
 {
+    int nMAXLens=64;
+    char strSave[64];
     GlobalPowerManger* _globalPowerMangerTemp = NULL ;
     GlobalDeviceManager *_globalDeviceManager = (GlobalDeviceManager *)&__globalDeviceManage;
     int nSize=strlen(strData);
-    if (nSize>50||nSize<=0)
+    if (nSize<=0)
     {
         /* code */
         return;
     }
-    
+    if(nSize>=nMAXLens)
+    {
+        memset(strSave,0,nMAXLens);
+        memcpy(strSave,strData,nMAXLens-1);
+        strSave[63]='\0';
+    }else{
+        memset(strSave,0,nMAXLens);
+        memcpy(strSave,strData,nSize);
+    }
     if (_globalDeviceManager->g_shm_Data)
     { // 初始化成功
         if(_globalDeviceManager->g_shm_Data->bPDUSet)
@@ -2884,7 +2894,8 @@ static void AlarmToShm(char* strData)
             if (isLastIndex != -1)//全部被占满则使用全局记录的位置进行添加
             {
                 _globalDeviceManager->g_shm_Data->nTypeCtrlType[_globalDeviceManager->g_lastAlarmIndex]=1;//设置更新了一个报警
-                strcpy(_globalDeviceManager->g_shm_Data->strMSG[_globalDeviceManager->g_lastAlarmIndex], strData);
+                memset(_globalDeviceManager->g_shm_Data->strMSG[_globalDeviceManager->g_lastAlarmIndex],0,nMAXLens);
+                strcpy(_globalDeviceManager->g_shm_Data->strMSG[_globalDeviceManager->g_lastAlarmIndex], strSave);
                 if (_globalDeviceManager->g_lastAlarmIndex < 10 && _globalDeviceManager->g_lastAlarmIndex >= 0)
                 {
                     _globalDeviceManager->g_lastAlarmIndex++;
@@ -2896,7 +2907,7 @@ static void AlarmToShm(char* strData)
             }else//未被全部占满则使用空闲位置添加
             {
                 _globalDeviceManager->g_shm_Data->nTypeCtrlType[isLastIndex]=1;//设置更新了一个报警
-                strcpy(_globalDeviceManager->g_shm_Data->strMSG[isLastIndex], strData);
+                strcpy(_globalDeviceManager->g_shm_Data->strMSG[isLastIndex], strSave);
                 _globalDeviceManager->g_lastAlarmIndex=isLastIndex;
             }            
         }
@@ -2947,6 +2958,11 @@ int dev_insert_alarm_info(sqlite3* db,int product_id,int alarm_type,time_data_t
             product_id,
             alarm_content);
     }
+    // 只有是电源 传感器以及网络告警才同步到小屏幕上显示报警信息
+    if (alarm_type == ALARM_TYPE_POWER || alarm_type == ALARM_TYPE_SENSOR || alarm_type == ALARM_TYPE_NETWORK)
+    {
+        AlarmToShm(alarm_content);
+    }
 
     res = sqlite_SQL_RUN(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
@@ -2957,10 +2973,10 @@ int dev_insert_alarm_info(sqlite3* db,int product_id,int alarm_type,time_data_t
 
     //mail_send();
     //只有是电源 传感器以及网络告警才同步到小屏幕上显示报警信息
-    if (alarm_type==ALARM_TYPE_POWER||alarm_type==ALARM_TYPE_SENSOR||alarm_type==ALARM_TYPE_NETWORK)
-    {
-        AlarmToShm(alarm_content);
-    }
+    //if (alarm_type == ALARM_TYPE_POWER || alarm_type == ALARM_TYPE_SENSOR || alarm_type == ALARM_TYPE_NETWORK)
+    //{
+    //    AlarmToShm(alarm_content);
+    //}
     
     return alarmNumber;
 }