|
@@ -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;
|
|
|
+ }
|
|
|
+}
|