Esempio n. 1
0
        private void ProcessCommAlarm_RULE(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser, string commType)
        {
            CHCNetSDK.NET_VCA_RULE_ALARM struRuleAlarmInfo = new CHCNetSDK.NET_VCA_RULE_ALARM();
            struRuleAlarmInfo = (CHCNetSDK.NET_VCA_RULE_ALARM)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_RULE_ALARM));

            //报警信息
            string stringAlarm = "";
            uint   dwSize      = (uint)Marshal.SizeOf(struRuleAlarmInfo.struRuleInfo.uEventParam);

            switch (struRuleAlarmInfo.struRuleInfo.wEventTypeEx)
            {
            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_TRAVERSE_PLANE:
                IntPtr ptrTraverseInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrTraverseInfo, false);
                m_struTraversePlane = (CHCNetSDK.NET_VCA_TRAVERSE_PLANE)Marshal.PtrToStructure(ptrTraverseInfo, typeof(CHCNetSDK.NET_VCA_TRAVERSE_PLANE));
                stringAlarm         = "穿越警戒面,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //警戒面边线起点坐标: (m_struTraversePlane.struPlaneBottom.struStart.fX, m_struTraversePlane.struPlaneBottom.struStart.fY)
                //警戒面边线终点坐标: (m_struTraversePlane.struPlaneBottom.struEnd.fX, m_struTraversePlane.struPlaneBottom.struEnd.fY)
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_ENTER_AREA:
                IntPtr ptrEnterInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrEnterInfo, false);
                m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrEnterInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm   = "目标进入区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_EXIT_AREA:
                IntPtr ptrExitInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrExitInfo, false);
                m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrExitInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm   = "目标离开区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_INTRUSION:
                IntPtr ptrIntrusionInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrIntrusionInfo, false);
                m_struIntrusion = (CHCNetSDK.NET_VCA_INTRUSION)Marshal.PtrToStructure(ptrIntrusionInfo, typeof(CHCNetSDK.NET_VCA_INTRUSION));

                int    i         = 0;
                string strRegion = "";
                for (i = 0; i < m_struIntrusion.struRegion.dwPointNum; i++)
                {
                    strRegion = strRegion + "(" + m_struIntrusion.struRegion.struPos[i].fX + "," + m_struIntrusion.struRegion.struPos[i].fY + ")";
                }
                stringAlarm = "周界入侵,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID + ",区域范围:" + strRegion;
                //m_struIntrusion.struRegion 多边形区域坐标
                break;

            default:
                stringAlarm = "其他行为分析报警,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                break;
            }

            //报警图片保存
            if (struRuleAlarmInfo.dwPicDataLen > 0)
            {
                FileStream fs   = new FileStream(m_OutputDir + "行为分析报警抓图.jpg", FileMode.Create);
                int        iLen = (int)struRuleAlarmInfo.dwPicDataLen;
                byte[]     by   = new byte[iLen];
                Marshal.Copy(struRuleAlarmInfo.pImage, by, 0, iLen);
                fs.Write(by, 0, iLen);
                fs.Close();
            }

            //报警时间:年月日时分秒
            string strTimeYear   = ((struRuleAlarmInfo.dwAbsTime >> 26) + 2000).ToString();
            string strTimeMonth  = ((struRuleAlarmInfo.dwAbsTime >> 22) & 15).ToString("d2");
            string strTimeDay    = ((struRuleAlarmInfo.dwAbsTime >> 17) & 31).ToString("d2");
            string strTimeHour   = ((struRuleAlarmInfo.dwAbsTime >> 12) & 31).ToString("d2");
            string strTimeMinute = ((struRuleAlarmInfo.dwAbsTime >> 6) & 63).ToString("d2");
            string strTimeSecond = ((struRuleAlarmInfo.dwAbsTime >> 0) & 63).ToString("d2");
            string strTime       = strTimeYear + "-" + strTimeMonth + "-" + strTimeDay + " " + strTimeHour + ":" + strTimeMinute + ":" + strTimeSecond;

            //报警设备IP地址
            string strIP = struRuleAlarmInfo.struDevInfo.struDevIP.sIpV4;

            //将报警信息添加进列表
            if (NoticeAlarmEvent != null)
            {
                string ccommType    = ObjectCopier.Clone <string>(commType);
                string cstrIP       = ObjectCopier.Clone <string>(strIP);
                string cstrTime     = ObjectCopier.Clone <string>(strTime);
                string cstringAlarm = ObjectCopier.Clone <string>(stringAlarm);

                NoticeAlarmEvent(ccommType, cstrTime, cstrIP, cstringAlarm);
            }
        }
Esempio n. 2
0
        private void ProcessCommAlarm_RULE(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
        {
            CHCNetSDK.NET_VCA_RULE_ALARM struRuleAlarmInfo = new CHCNetSDK.NET_VCA_RULE_ALARM();
            struRuleAlarmInfo = (CHCNetSDK.NET_VCA_RULE_ALARM)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_RULE_ALARM));

            //报警信息
            string stringAlarm = "";
            uint   dwSize      = (uint)Marshal.SizeOf(struRuleAlarmInfo.struRuleInfo.uEventParam);

            switch (struRuleAlarmInfo.struRuleInfo.wEventTypeEx)
            {
            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_TRAVERSE_PLANE:
                IntPtr ptrTraverseInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrTraverseInfo, false);
                m_struTraversePlane = (CHCNetSDK.NET_VCA_TRAVERSE_PLANE)Marshal.PtrToStructure(ptrTraverseInfo, typeof(CHCNetSDK.NET_VCA_TRAVERSE_PLANE));
                stringAlarm         = "穿越警戒面,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //警戒面边线起点坐标: (m_struTraversePlane.struPlaneBottom.struStart.fX, m_struTraversePlane.struPlaneBottom.struStart.fY)
                //警戒面边线终点坐标: (m_struTraversePlane.struPlaneBottom.struEnd.fX, m_struTraversePlane.struPlaneBottom.struEnd.fY)
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_ENTER_AREA:
                IntPtr ptrEnterInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrEnterInfo, false);
                m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrEnterInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm   = "目标进入区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_EXIT_AREA:
                IntPtr ptrExitInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrExitInfo, false);
                m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrExitInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm   = "目标离开区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_INTRUSION:
                IntPtr ptrIntrusionInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrIntrusionInfo, false);
                m_struIntrusion = (CHCNetSDK.NET_VCA_INTRUSION)Marshal.PtrToStructure(ptrIntrusionInfo, typeof(CHCNetSDK.NET_VCA_INTRUSION));
                stringAlarm     = "周界入侵,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struIntrusion.struRegion 多边形区域坐标
                break;

            default:
                stringAlarm = "其他行为分析报警,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                break;
            }


            //报警图片保存
            if (struRuleAlarmInfo.dwPicDataLen > 0)
            {
                FileStream fs   = new FileStream("行为分析报警抓图.jpg", FileMode.Create);
                int        iLen = (int)struRuleAlarmInfo.dwPicDataLen;
                byte[]     by   = new byte[iLen];
                Marshal.Copy(struRuleAlarmInfo.pImage, by, 0, iLen);
                fs.Write(by, 0, iLen);
                fs.Close();
            }

            //报警时间:年月日时分秒
            string strTimeYear   = ((struRuleAlarmInfo.dwAbsTime >> 26) + 2000).ToString();
            string strTimeMonth  = ((struRuleAlarmInfo.dwAbsTime >> 22) & 15).ToString("d2");
            string strTimeDay    = ((struRuleAlarmInfo.dwAbsTime >> 17) & 31).ToString("d2");
            string strTimeHour   = ((struRuleAlarmInfo.dwAbsTime >> 12) & 31).ToString("d2");
            string strTimeMinute = ((struRuleAlarmInfo.dwAbsTime >> 6) & 63).ToString("d2");
            string strTimeSecond = ((struRuleAlarmInfo.dwAbsTime >> 0) & 63).ToString("d2");
            string strTime       = strTimeYear + "-" + strTimeMonth + "-" + strTimeDay + " " + strTimeHour + ":" + strTimeMinute + ":" + strTimeSecond;

            //报警设备IP地址
            string strIP = struRuleAlarmInfo.struDevInfo.struDevIP.sIpV4;

            //将报警信息添加进列表
            if (InvokeRequired)
            {
                object[] paras = new object[3];
                paras[0] = strTime;
                paras[1] = strIP;
                paras[2] = stringAlarm;
                listViewAlarmInfo.BeginInvoke(new UpdateListBoxCallback(UpdateClientList), paras);
            }
            else
            {
                //创建该控件的主线程直接更新信息列表
                UpdateClientList(strTime, strIP, stringAlarm);
            }
        }
        /// <summary>
        /// 越界侦测用的报警
        /// </summary>
        /// <param name="pAlarmer"></param>
        /// <param name="pAlarmInfo"></param>
        /// <param name="dwBufLen"></param>
        /// <param name="pUser"></param>
        private void ProcessCommAlarm_RULE(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
        {
            string strNvrIp = pAlarmer.sDeviceIP;//报警nvrIp地址

            CHCNetSDK.NET_VCA_RULE_ALARM struRuleAlarmInfo = new CHCNetSDK.NET_VCA_RULE_ALARM();
            //看下报警信息里面有没有通道号,
            struRuleAlarmInfo = (CHCNetSDK.NET_VCA_RULE_ALARM)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_RULE_ALARM));
            byte channel = struRuleAlarmInfo.struDevInfo.byChannel;
            //报警设备IP地址
            string strIP = struRuleAlarmInfo.struDevInfo.struDevIP.sIpV4;
            //报警信息
            string stringAlarm = "";
            uint   dwSize      = (uint)Marshal.SizeOf(struRuleAlarmInfo.struRuleInfo.uEventParam);

            switch (struRuleAlarmInfo.struRuleInfo.wEventTypeEx)
            {
            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_TRAVERSE_PLANE:
                IntPtr ptrTraverseInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrTraverseInfo, false);
                CHCNetSDK.NET_VCA_TRAVERSE_PLANE m_struTraversePlane = (CHCNetSDK.NET_VCA_TRAVERSE_PLANE)Marshal.PtrToStructure(ptrTraverseInfo, typeof(CHCNetSDK.NET_VCA_TRAVERSE_PLANE));
                stringAlarm = "穿越警戒面,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //警戒面边线起点坐标: (m_struTraversePlane.struPlaneBottom.struStart.fX, m_struTraversePlane.struPlaneBottom.struStart.fY)
                //警戒面边线终点坐标: (m_struTraversePlane.struPlaneBottom.struEnd.fX, m_struTraversePlane.struPlaneBottom.struEnd.fY)
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_ENTER_AREA:
                IntPtr ptrEnterInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrEnterInfo, false);
                CHCNetSDK.NET_VCA_AREA m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrEnterInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm = "目标进入区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_EXIT_AREA:
                IntPtr ptrExitInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrExitInfo, false);
                m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrExitInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm   = "目标离开区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_INTRUSION:
                IntPtr ptrIntrusionInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrIntrusionInfo, false);
                CHCNetSDK.NET_VCA_INTRUSION m_struIntrusion = (CHCNetSDK.NET_VCA_INTRUSION)Marshal.PtrToStructure(ptrIntrusionInfo, typeof(CHCNetSDK.NET_VCA_INTRUSION));
                stringAlarm = "周界入侵,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struIntrusion.struRegion 多边形区域坐标
                break;

            default:
                stringAlarm = "其他行为分析报警,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                break;
            }


            //报警图片保存
            if (struRuleAlarmInfo.dwPicDataLen > 0)
            {
                FileStream fs   = new FileStream("行为分析报警抓图.jpg", FileMode.Create);
                int        iLen = (int)struRuleAlarmInfo.dwPicDataLen;
                byte[]     by   = new byte[iLen];
                Marshal.Copy(struRuleAlarmInfo.pImage, by, 0, iLen);
                fs.Write(by, 0, iLen);
                fs.Close();
            }

            //报警时间:年月日时分秒
            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            string theone   = "0";
            string name     = "";
            string position = "";

            try
            {
                //根据数据库找到theone、摄像头名称等内容
                //找到了目前这个函数通道所在的NVR,
                //然后根据通道号跟NVRip地址,找到摄像头
                string    srtSql = "IP地址 ='" + strIP + "'";
                DataRow[] dr     = StaticData.g_dtCamera.Select(srtSql);
                if (dr.Length > 0)
                {
                    theone   = dr[0]["theone"].ToString();
                    name     = dr[0]["摄像头名称"].ToString();
                    position = dr[0]["坐标"].ToString();
                }
                else
                {
                    // 处理获取非指定camaras错误回调后所产生的数据为空的异常情况
                    // 异常eg:  发现了非列表中的未知nvrip = “10.1.12.51”的设备
                    return;
                }
            }
            catch (Exception)
            {
                StaticUtils.ShowEventMsg("HikvisionAlarmCallBackFun.class-ProcessCommAlarm_RULE : 报警回调函数出现异常!\n");
                //throw;
            }

            //读取事件数据库,判断数据库是否存在该事件,且时间是否2分钟以上差别,存在且是的话插入新事件
            //不是的话更新endtime字段为当前时间
            //不存在的话直接插入数据,还需要插入个摄像头的位置,名称
            string[] paras = new string[2]
            {
                time, strNvrIp
            };
            string str_channel = Convert.ToString(channel);

            CheckEvent(name, theone, stringAlarm, DateTime.Now.ToString().Replace('/', '-'), position, name, paras, str_channel);
        }