Przeglądaj źródła

上传文件至 'ytDHCamCore'

hanzhengyi 4 lat temu
rodzic
commit
985d416237

+ 45 - 0
ytDHCamCore/ytDHCamCore.pro

@@ -0,0 +1,45 @@
+QT -= gui
+
+QT += network sql
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+TARGET = ytDHCamCore
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as 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 you use 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 \
+    ytdhcamcore.cpp \
+    databasethread.cpp \
+    logthread.cpp \
+    camthread.cpp \
+    ttsthreads.cpp \
+    wechartthreads.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+HEADERS += \
+    ytdhcamshm.h \
+    ytdhcam.h \
+    ytdhcamcore.h \
+    databasethread.h \
+    logthread.h \
+    camthread.h \
+    ttsthreads.h \
+    wechartthreads.h
+
+LIBS += -ldhnetsdk

+ 174 - 0
ytDHCamCore/ytdhcamcore.cpp

@@ -0,0 +1,174 @@
+#include "ytdhcamcore.h"
+#include "ytdhcam.h"
+#include "dhinc/dhnetsdk.h"
+
+#define UN_REFERENCED_PARAMETER(x) {(x) = (x);}
+
+int ServiceCallBack(LLONG lHandle, char *pIp, WORD wPort, LONG lCommand, void *pParam, DWORD dwParamLen, LDWORD dwUserData)
+{
+    int i;
+    UN_REFERENCED_PARAMETER(lHandle);
+    UN_REFERENCED_PARAMETER(dwParamLen);
+    printf("IP:%s\n",pIp);
+    if(lCommand == DH_DVR_SERIAL_RETURN){
+        QDateTime t = QDateTime::currentDateTime();
+        QString deviceId = QString((char *)pParam);
+        ytDHCamCore *core = (ytDHCamCore *)dwUserData;
+        if(lCommand==DH_DVR_SERIAL_RETURN){
+            for(i=0;i<102400;i++){
+                if(sysConfShm->deviceInfo[i].Enabled==0x01){
+                    if(QString::compare(deviceId,QString::fromUtf8(sysConfShm->deviceInfo[i].Device_Code))==0){
+                        if(sysConfShm->deviceInfo[i].RegistStatus==0x01){
+                            if(sysConfShm->deviceInfo[i].keepThread==0x00){
+                                sprintf(sysConfShm->deviceInfo[i].Ip,"%s",pIp);
+                                sysConfShm->deviceInfo[i].Port = wPort;
+                                sysConfShm->deviceInfo[i].lastCommTime = t.toTime_t();
+                                sysConfShm->deviceInfo[i].LoginStatus = 0x00;
+                                core->appendLOg(QString("[ %1 %2 ] new connect").arg(t.toString("yyyy-MM-dd HH:mm:ss.zzz")).arg(QString(pIp)));
+                                core->getNewDev(i);
+                            }
+                        }else{
+                            sysConfShm->deviceInfo[i].RegistStatus = 0x01;
+                            sprintf(sysConfShm->deviceInfo[i].Ip,"%s",pIp);
+                            sysConfShm->deviceInfo[i].Port = wPort;
+                            sysConfShm->deviceInfo[i].lastCommTime = t.toTime_t();
+                            sysConfShm->deviceInfo[i].LoginStatus = 0x00;
+                            core->appendLOg(QString("[ %1 %2 ] new connect").arg(t.toString("yyyy-MM-dd HH:mm:ss.zzz")).arg(QString(pIp)));
+                            core->getNewDev(i);
+                        }
+                        break;
+                    }
+                }
+            }
+        }else if(lCommand==DH_DVR_DISCONNECT){
+            for(i=0;i<102400;i++){
+                if(sysConfShm->deviceInfo[i].Enabled==0x01){
+                    if(QString::compare(deviceId,QString::fromUtf8(sysConfShm->deviceInfo[i].Device_Code))==0){
+                        if(sysConfShm->deviceInfo[i].keepThread!=0x00){
+                            sysConfShm->deviceInfo[i].RegistStatus = 0x00;
+                            sysConfShm->deviceInfo[i].LoginStatus = 0x00;
+                            sysConfShm->deviceInfo[i].Port = 0;
+                            bzero(sysConfShm->deviceInfo[i].Ip,sizeof (sysConfShm->deviceInfo[i].Ip));
+                            sysConfShm->deviceInfo[i].keepThread = 0x00;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return 0;
+}
+
+void CALLBACK DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser)
+{
+    UN_REFERENCED_PARAMETER(nDVRPort);
+    int i;
+    if(dwUser!=0){
+        QDateTime t = QDateTime::currentDateTime();
+        ytDHCamCore *core = (ytDHCamCore *)dwUser;
+        core->appendLOg(QString::fromUtf8("[ %1 %2 ] Disconnect").arg(t.toString("yyyy-MM-dd HH:mm:ss.zzz")).arg(pchDVRIP));
+        for(i=0;i<102400;i++){
+            if(sysConfShm->deviceInfo[i].Enabled==0x01){
+                if((sysConfShm->deviceInfo[i].RegistStatus==0x01)&&(sysConfShm->deviceInfo[i].LoginHandle==lLoginID)){
+                    if(QString::compare(QString(sysConfShm->deviceInfo[i].Ip),QString(pchDVRIP))==0){
+                        sysConfShm->deviceInfo[i].RegistStatus = 0x00;
+                        sysConfShm->deviceInfo[i].LoginStatus = 0x00;
+                        sysConfShm->deviceInfo[i].Port = 0;
+                        bzero(sysConfShm->deviceInfo[i].Ip,sizeof (sysConfShm->deviceInfo[i].Ip));
+                        sysConfShm->deviceInfo[i].keepThread = 0x00;
+                    }
+                }
+            }
+        }
+    }
+}
+
+ytDHCamCore::ytDHCamCore(QObject *parent) : QObject(parent)
+{
+    lListenHandle = 0;
+    logThread = new LogThread(this);
+    logThread->start();
+    dbThread = new DatabaseThread(this);
+//    connect(dbThread,SIGNAL(SqlAction(QString)),this,SLOT(appendLOg(QString)));
+    connect(dbThread,&DatabaseThread::AlarmReport,this,&ytDHCamCore::AlarmReport);
+    dbThread->start();
+    timer = new QTimer(this);
+    connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
+    for(quint16 i=0;i<8;i++){
+        wxThreads[i] = new WechartThreads(this,i,"47.98.201.73","/jdxf/wxapp2.php/Home/GeneralPush/voice");
+        wssThread[i] = new ttsThreads(this,i,"47.98.201.73","/report",55125);
+        wxThreads[i]->start();
+        wssThread[i]->start();
+    }
+    CLIENT_Init(DisConnectFunc,(LDWORD)this);
+}
+
+ytDHCamCore::~ytDHCamCore()
+{
+    if(lListenHandle!=0){
+        CLIENT_StopListenServer(lListenHandle);
+        lListenHandle = 0;
+    }
+    CLIENT_Cleanup();
+}
+
+void ytDHCamCore::getNewDev(int idx)
+{
+    QDateTime t = QDateTime::currentDateTime();
+    logThread->appendData(QString("[ %1 %2 ] port: %3, id: %4")
+                          .arg(t.toString("yyyy-MM-dd HH:mm:ss.zzz")).arg(sysConfShm->deviceInfo[idx].Ip)
+                          .arg(sysConfShm->deviceInfo[idx].Port).arg(sysConfShm->deviceInfo[idx].Device_Code));
+    CamThread *thread = new CamThread(idx,this);
+    connect(thread,&CamThread::finished,thread,&CamThread::quit);
+    connect(thread,&CamThread::CamMsg,this,&ytDHCamCore::appendLOg);
+    connect(thread,&CamThread::CamAlarm,this,&ytDHCamCore::CamAlarm);
+    thread->start();
+}
+
+void ytDHCamCore::start()
+{
+    QDateTime t = QDateTime::currentDateTime();
+    timer->start(1000);
+    lListenHandle = CLIENT_ListenServer("172.19.198.166",9500,10000,ServiceCallBack,(LDWORD)this);
+    if(lListenHandle==0){
+        logThread->appendData(QString("[ %1 %2 ] start port(9500) open failed").arg(t.toString("yyyy-MM-dd HH:mm:ss.zzz")).arg("172.19.198.166"));
+    }else{
+        logThread->appendData(QString("[ %1 %2 ] start port(9500) open success").arg(t.toString("yyyy-MM-dd HH:mm:ss.zzz")).arg("172.19.198.166"));
+    }
+}
+
+void ytDHCamCore::appendLOg(QString log)
+{
+    logThread->appendData(log);
+}
+
+void ytDHCamCore::timeout()
+{
+
+}
+
+void ytDHCamCore::CamAlarm(QString deviceid, QString alarmtype, QString picpath, QString alarmtime){
+    dbThread->appendAlarm(AlarmRep(deviceid,QString::fromUtf8("insert into sp_video2017 (id,port,device_code,time,status,address,ncmd,data1,data2,data3,data4,data5,clsj,clr,clnr,clwb,cllxr,cldh,clzt,cllx,video) values (NULL,'%1','%2','%3','%4','','%5','%6','%7','%8','电动车禁入/区域入侵告警','','1970-01-01 08:00:00','','','','','',0,'','')")
+                                   .arg(2).arg(deviceid).arg(alarmtime).arg(1)
+                                   .arg(301).arg(1).arg(picpath).arg(""),
+                                   QString("10%1").arg(alarmtype),alarmtime));
+}
+
+void ytDHCamCore::AlarmReport(QString addr, quint64 insertid, QString type, QString time, QString companycode, QString phonelist)
+{
+    QString alarmtype = QString::fromUtf8("电动车禁入/区域入侵告警");
+    QString rep2 = QString("{\"SubType\":16,\"DeviceId\":\"%1\",\"InsertId\":%2,\"Confirmed\":0,\"CompanyCode\":\"%3\",\"evt_name\":\"%4\",\"evt\":0,\"alarm_time\":\"%5\"}")
+                    .arg(addr).arg(insertid).arg(companycode).arg(alarmtype).arg(time);
+    logThread->appendData(rep2);
+    wssThread[repcur]->appendData(rep2);
+    repcur++;
+    repcur &= 0x07;
+    if(phonelist.length()>0){
+        QString data = QString("evt_name=%1&device_code=%2&phone=%3&insert_id=%4&time=%5&bz=%1").arg(alarmtype).arg(addr).arg(phonelist).arg(insertid).arg(time)
+                .replace(",","%2C").replace(":","%3A").replace(" ","+");
+        logThread->appendData(data);
+        wxThreads[wxcur]->appendData(data);
+        wxcur++;
+        wxcur &= 0x07;
+    }
+}

+ 38 - 0
ytDHCamCore/ytdhcamcore.h

@@ -0,0 +1,38 @@
+#ifndef YTDHCAMCORE_H
+#define YTDHCAMCORE_H
+
+#include <QObject>
+#include <QTimer>
+#include "logthread.h"
+#include "databasethread.h"
+#include "camthread.h"
+#include "ttsthreads.h"
+#include "wechartthreads.h"
+
+class ytDHCamCore : public QObject
+{
+    Q_OBJECT
+public:
+    explicit ytDHCamCore(QObject *parent = nullptr);
+    ~ytDHCamCore();
+    void start();
+    void getNewDev(int idx);
+
+signals:
+
+public slots:
+    void timeout();
+    void appendLOg(QString log);
+    void CamAlarm(QString deviceid, QString alarmtype, QString picpath, QString alarmtime);
+    void AlarmReport(QString addr, quint64 insertid, QString type, QString time, QString companycode, QString phonelist);
+private:
+    LogThread *logThread;
+    DatabaseThread *dbThread;
+    QTimer *timer;
+    long lListenHandle;
+    ttsThreads *wssThread[8];
+    WechartThreads *wxThreads[8];
+    int repcur,wxcur;
+};
+
+#endif // YTDHCAMCORE_H

+ 56 - 0
ytDHCamCore/ytdhcamshm.h

@@ -0,0 +1,56 @@
+#ifndef YTDHCAMSHM_H
+#define YTDHCAMSHM_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/shm.h>
+#include <sys/ipc.h>
+#include <stdlib.h>
+
+#define SHM_PATH        "/"
+#define SHM_PORT        8812
+
+typedef struct {
+    unsigned char Enabled;
+    unsigned long Idx;
+    unsigned long ParentId;
+    char CompanyCode[40];
+}CompanyInfo;//10240
+
+typedef struct {
+    unsigned char Enabled;
+    char CompanyCode[40];
+    char CellPhone[20];
+    unsigned long Idx;
+    unsigned long long InfoChecked;
+}UserInfo;//102400
+
+typedef struct {
+    unsigned char Enabled;
+    unsigned char RegistStatus;
+    unsigned char LoginStatus;
+    unsigned char keepThread;
+    char Device_Code[40];
+    char Device_Name[200];
+    char Device_Info[500];
+    char Device_Type[100];
+    char Company_Code[40];
+    char LoginName[50];
+    char Password[50];
+    char Ip[50];
+    unsigned short Port;
+    unsigned long Push_Param[4];
+    long LoginHandle;
+    long SubscribeHandle;
+    unsigned int lastCommTime;
+    char UnUsed[256];
+}DeviceInfo;//102400
+
+typedef struct {
+    CompanyInfo companyInfo[10240];
+    UserInfo userInfo[102400];
+    DeviceInfo deviceInfo[102400];
+}SysConfShm;
+
+#endif // YTDHCAMSHM_H