diff --git a/SlnMesnac.Business/AutoModeBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs index 2f3ccf6..e9c6574 100644 --- a/SlnMesnac.Business/AutoModeBusiness.cs +++ b/SlnMesnac.Business/AutoModeBusiness.cs @@ -407,5 +407,15 @@ namespace SlnMesnac.Business _log.Info($"工作模式:取消;写入PLC成功;VD1536写0"); } + + public void SendCameraAlarmToPlc() + { + if (!_plc.writeInt32ByAddress("VD1550", 1)) + { + throw new ArgumentException($"相机避障报警写入PLC失败;VD1550写1"); + } + + _log.Info($"相机避障报警写入PLC成功;VD1550写1"); + } } } diff --git a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs index 87e6e8f..76d7a81 100644 --- a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs @@ -10,6 +10,7 @@ using SlnMesnac.Model.dto; using SlnMesnac.Serilog; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -54,6 +55,7 @@ namespace SlnMesnac.WPF.ViewModel private AppConfig _appConfig; private CHCNetSDK.RemoteConfigCallback _callback; + private CHCNetSDK.MSGCallBack_V31 m_falarmData_V31; public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo; private bool m_bInitSDK = false; @@ -72,6 +74,7 @@ namespace SlnMesnac.WPF.ViewModel { _log = App.ServiceProvider.GetService(); _callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback); + m_falarmData_V31 = new CHCNetSDK.MSGCallBack_V31(MsgCallback_V31); _appConfig = App.ServiceProvider.GetService(); autoModeBusiness = App.ServiceProvider.GetService(); inspModeBusiness = App.ServiceProvider.GetService(); @@ -88,9 +91,10 @@ namespace SlnMesnac.WPF.ViewModel inspModeBusiness.GimbaRotationControlEvent += GimbaRotationControl; RefreshTrackMotorAddress(); - }catch (Exception ex) + } + catch (Exception ex) { - _log.Error("巡检控制系统初始化失败",ex); + _log.Error("巡检控制系统初始化失败", ex); MessageBox.Show($"巡检控制系统初始化失败:{ex.Message}"); } } @@ -191,6 +195,38 @@ namespace SlnMesnac.WPF.ViewModel return; } + /// + /// 报警布防 + /// + + //设置透传报警信息类型 + CHCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struLocalCfg = new CHCNetSDK.NET_DVR_LOCAL_GENERAL_CFG(); + struLocalCfg.byAlarmJsonPictureSeparate = 1;//控制JSON透传报警数据和图片是否分离,0-不分离(COMM_VCA_ALARM返回),1-分离(分离后走COMM_ISAPI_ALARM回调返回) + + Int32 nSize = Marshal.SizeOf(struLocalCfg); + IntPtr ptrLocalCfg = Marshal.AllocHGlobal(nSize); + Marshal.StructureToPtr(struLocalCfg, ptrLocalCfg, false); + + if (!CHCNetSDK.NET_DVR_SetSDKLocalCfg(17, ptrLocalCfg)) //NET_DVR_LOCAL_CFG_TYPE_GENERAL + { + MessageBox.Show("NET_DVR_SetSDKLocalCfg failed, error code= " + CHCNetSDK.NET_DVR_GetLastError()); + } + Marshal.FreeHGlobal(ptrLocalCfg); + + CHCNetSDK.NET_DVR_SETUPALARM_PARAM struAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM(); + struAlarmParam.dwSize = (uint)Marshal.SizeOf(struAlarmParam); + struAlarmParam.byLevel = 1; //0- 一级布防,1- 二级布防 + struAlarmParam.byAlarmInfoType = 1;//智能交通设备有效,新报警信息类型 + struAlarmParam.byFaceAlarmDetection = 1;//1-人脸侦测 + + var m_lAlarmHandle = CHCNetSDK.NET_DVR_SetupAlarmChan_V41(m_lUserID, ref struAlarmParam); + if (m_lAlarmHandle < 0) + { + _log.Info("布防失败,错误号::" + CHCNetSDK.NET_DVR_GetLastError()); + } + + + var res = CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(m_falarmData_V31, IntPtr.Zero); } }); @@ -211,7 +247,7 @@ namespace SlnMesnac.WPF.ViewModel public void GetThermInfoCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData) { var ret = Marshal.PtrToStructure(lpBuffer); - + this.RealTemperature = new RealTemperatureInfo() { fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1), @@ -531,7 +567,7 @@ namespace SlnMesnac.WPF.ViewModel } } - public void GimbaRotationControl(string wPanPos,string wTiltPos,string wZoomPos) + public void GimbaRotationControl(string wPanPos, string wTiltPos, string wZoomPos) { try { @@ -565,7 +601,8 @@ namespace SlnMesnac.WPF.ViewModel //Marshal.FreeHGlobal(ptrPtzCfg); } - }catch(Exception ex) + } + catch (Exception ex) { _log.Info($"云台旋转控制异常:{ex.Message}"); } @@ -631,7 +668,7 @@ namespace SlnMesnac.WPF.ViewModel public void Stop_PointMode() { - fixedPointBusiness.EndFixedPoint(null,true); + fixedPointBusiness.EndFixedPoint(null, true); autoModeBusiness.ClearPlcMode(); } @@ -652,7 +689,7 @@ namespace SlnMesnac.WPF.ViewModel } double speed = autoModeBusiness.GetDeviceSpeed(); - RealDeviceSpeed = Math.Round(speed,2); + RealDeviceSpeed = Math.Round(speed, 2); string deviceStatus = autoModeBusiness.GetDeviceStatus(); RealDeviceStatus = deviceStatus; Task.Delay(1000).Wait(); @@ -660,5 +697,51 @@ namespace SlnMesnac.WPF.ViewModel }); } + public bool MsgCallback_V31(int lCommand, ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) + { + AlarmMessageHandle(lCommand, ref pAlarmer, pAlarmInfo, dwBufLen, pUser); + + return true; + } + + public void AlarmMessageHandle(int lCommand, ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) + { + switch (lCommand) + { + case CHCNetSDK.COMM_ISAPI_ALARM://ISAPI报警信息上传 + ProcessCommAlarm_ISAPIAlarm(ref pAlarmer, pAlarmInfo, dwBufLen, pUser); + break; + default: + { + string strIP = System.Text.Encoding.UTF8.GetString(pAlarmer.sDeviceIP).TrimEnd('\0'); + + string stringAlarm = "报警上传,信息类型:0x" + Convert.ToString(lCommand, 16); + + Console.WriteLine(stringAlarm); + } + break; + } + } + + private void ProcessCommAlarm_ISAPIAlarm(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) + { + try + { + CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO struISAPIAlarm = new CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO(); + uint dwSize = (uint)Marshal.SizeOf(struISAPIAlarm); + struISAPIAlarm = (CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO)); + + string stringAlarm = $"ISAPI报警信息,byDataType:{struISAPIAlarm.byDataType}"; + + _log.Info($"云台避障报警:{stringAlarm}"); + + autoModeBusiness.SendCameraAlarmToPlc(); + }catch(Exception e) + { + _log.Info($"云台避障报警逻辑处理异常:{e.Message}"); + } + + } + } } diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 6b88f47..338d741 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -29,8 +29,8 @@ { "configId": 1, "plcType": "SiemensPlc", - "plcIp": "127.0.0.1", - //"plcIp": "192.168.2.1", + //"plcIp": "127.0.0.1", + "plcIp": "192.168.2.1", "plcPort": 102, "plcKey": "iot", "isFlage": "true"