|
@@ -1,28 +1,223 @@
|
|
|
using DeviceCenter;
|
|
using DeviceCenter;
|
|
|
|
|
+using log4net;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
+using System.Runtime.InteropServices;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
|
+using System.Windows;
|
|
|
|
|
|
|
|
namespace DeviceCenter
|
|
namespace DeviceCenter
|
|
|
{
|
|
{
|
|
|
class AcsDevice : Device
|
|
class AcsDevice : Device
|
|
|
{
|
|
{
|
|
|
|
|
+ public static readonly ILog log = LogManager.GetLogger("DeviceCenter");
|
|
|
|
|
|
|
|
|
|
+ public int userId { get; set; }
|
|
|
public AcsDevice()
|
|
public AcsDevice()
|
|
|
{
|
|
{
|
|
|
- this.type = Device.Type.ACS;
|
|
|
|
|
|
|
+ type = Device.Type.ACS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public override void Init()
|
|
public override void Init()
|
|
|
{
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
|
|
|
|
+ CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
|
|
|
|
|
+ CHCNetSDK.NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
|
|
|
|
|
+
|
|
|
|
|
+ struLoginInfo.bUseAsynLogin = false;
|
|
|
|
|
+ struLoginInfo.sDeviceAddress = ip;
|
|
|
|
|
+ struLoginInfo.sUserName = username;
|
|
|
|
|
+ struLoginInfo.sPassword = password;
|
|
|
|
|
+ struLoginInfo.wPort = (ushort)port;
|
|
|
|
|
+
|
|
|
|
|
+ struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];
|
|
|
|
|
+
|
|
|
|
|
+ int m_userId = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
|
|
|
|
|
+ if (m_userId < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ uint nErr = CHCNetSDK.NET_DVR_GetLastError();
|
|
|
|
|
+ if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
|
|
|
|
|
+ {
|
|
|
|
|
+ MessageBox.Show("user name or password error!");
|
|
|
|
|
+ if (1 == struDeviceInfoV40.bySupportLock)
|
|
|
|
|
+ {
|
|
|
|
|
+ string strTemp1 = string.Format("Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
|
|
|
|
|
+ MessageBox.Show(strTemp1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (nErr == CHCNetSDK.NET_DVR_USER_LOCKED)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (1 == struDeviceInfoV40.bySupportLock)
|
|
|
|
|
+ {
|
|
|
|
|
+ string strTemp1 = string.Format("user is locked, the remaining lock time is {0}", struDeviceInfoV40.dwSurplusLockTime);
|
|
|
|
|
+ MessageBox.Show(strTemp1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ MessageBox.Show("net error or dvr is busy!");
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ userId = m_userId;
|
|
|
|
|
+
|
|
|
|
|
+ CHCNetSDK.NET_DVR_SETUPALARM_PARAM struSetupAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
|
|
|
|
|
+ struSetupAlarmParam.dwSize = (uint)Marshal.SizeOf(struSetupAlarmParam);
|
|
|
|
|
+ struSetupAlarmParam.byLevel = 1;
|
|
|
|
|
+ struSetupAlarmParam.byAlarmInfoType = 1;
|
|
|
|
|
+ struSetupAlarmParam.byDeployType = 1;
|
|
|
|
|
+ int handle = CHCNetSDK.NET_DVR_SetupAlarmChan_V41(m_userId, ref struSetupAlarmParam);
|
|
|
|
|
+ if (-1 == handle)
|
|
|
|
|
+ {
|
|
|
|
|
+ MessageBox.Show("Setup alarm chan failed");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public override void dispose()
|
|
public override void dispose()
|
|
|
{
|
|
{
|
|
|
throw new NotImplementedException();
|
|
throw new NotImplementedException();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void onAlarm(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
|
|
|
|
|
+ {
|
|
|
|
|
+ CHCNetSDK.NET_DVR_ACS_ALARM_INFO struAcsAlarmInfo = new CHCNetSDK.NET_DVR_ACS_ALARM_INFO();
|
|
|
|
|
+ struAcsAlarmInfo = (CHCNetSDK.NET_DVR_ACS_ALARM_INFO)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_DVR_ACS_ALARM_INFO));
|
|
|
|
|
+ CHCNetSDK.NET_DVR_LOG_V30 struFileInfo = new CHCNetSDK.NET_DVR_LOG_V30();
|
|
|
|
|
+ struFileInfo.dwMajorType = struAcsAlarmInfo.dwMajor;
|
|
|
|
|
+ struFileInfo.dwMinorType = struAcsAlarmInfo.dwMinor;
|
|
|
|
|
+ char[] csTmp = new char[256];
|
|
|
|
|
+
|
|
|
|
|
+ if (CHCNetSDK.MAJOR_ALARM == struFileInfo.dwMajorType)
|
|
|
|
|
+ {
|
|
|
|
|
+ TypeMap.AlarmMinorTypeMap(struFileInfo, csTmp);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (CHCNetSDK.MAJOR_OPERATION == struFileInfo.dwMajorType)
|
|
|
|
|
+ {
|
|
|
|
|
+ TypeMap.OperationMinorTypeMap(struFileInfo, csTmp);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (CHCNetSDK.MAJOR_EXCEPTION == struFileInfo.dwMajorType)
|
|
|
|
|
+ {
|
|
|
|
|
+ TypeMap.ExceptionMinorTypeMap(struFileInfo, csTmp);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (CHCNetSDK.MAJOR_EVENT == struFileInfo.dwMajorType)
|
|
|
|
|
+ {
|
|
|
|
|
+ TypeMap.EventMinorTypeMap(struFileInfo, csTmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String szInfo = new String(csTmp).TrimEnd('\0');
|
|
|
|
|
+ String szInfoBuf = null;
|
|
|
|
|
+ szInfoBuf = szInfo;
|
|
|
|
|
+ /**************************************************/
|
|
|
|
|
+ String name = System.Text.Encoding.UTF8.GetString(struAcsAlarmInfo.sNetUser).TrimEnd('\0');
|
|
|
|
|
+ for (int i = 0; i < struAcsAlarmInfo.sNetUser.Length; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (struAcsAlarmInfo.sNetUser[i] == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ name = name.Substring(0, i);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /**************************************************/
|
|
|
|
|
+
|
|
|
|
|
+ szInfoBuf = string.Format("{0} time:{1,4}-{2:D2}-{3} {4:D2}:{5:D2}:{6:D2}, [{7}]({8})", szInfo, struAcsAlarmInfo.struTime.dwYear, struAcsAlarmInfo.struTime.dwMonth,
|
|
|
|
|
+ struAcsAlarmInfo.struTime.dwDay, struAcsAlarmInfo.struTime.dwHour, struAcsAlarmInfo.struTime.dwMinute, struAcsAlarmInfo.struTime.dwSecond,
|
|
|
|
|
+ struAcsAlarmInfo.struRemoteHostAddr.sIpV4, name);
|
|
|
|
|
+
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.byCardNo[0] != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Card Number:" + System.Text.Encoding.UTF8.GetString(struAcsAlarmInfo.struAcsEventInfo.byCardNo).TrimEnd('\0');
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] szCardType = { "normal card", "disabled card", "blacklist card", "night watch card", "stress card", "super card", "guest card" };
|
|
|
|
|
+ byte byCardType = struAcsAlarmInfo.struAcsEventInfo.byCardType;
|
|
|
|
|
+
|
|
|
|
|
+ if (byCardType != 0 && byCardType <= szCardType.Length)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Card Type:" + szCardType[byCardType - 1];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwCardReaderNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Card Reader Number:" + struAcsAlarmInfo.struAcsEventInfo.dwCardReaderNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwDoorNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Door Number:" + struAcsAlarmInfo.struAcsEventInfo.dwDoorNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwVerifyNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Multiple Card Authentication Serial Number:" + struAcsAlarmInfo.struAcsEventInfo.dwVerifyNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwAlarmInNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Alarm Input Number:" + struAcsAlarmInfo.struAcsEventInfo.dwAlarmInNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwAlarmOutNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Alarm Output Number:" + struAcsAlarmInfo.struAcsEventInfo.dwAlarmOutNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwCaseSensorNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Event Trigger Number:" + struAcsAlarmInfo.struAcsEventInfo.dwCaseSensorNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwRs485No != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+RS485 Channel Number:" + struAcsAlarmInfo.struAcsEventInfo.dwRs485No;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwMultiCardGroupNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+Multi Recombinant Authentication ID:" + struAcsAlarmInfo.struAcsEventInfo.dwMultiCardGroupNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.byCardReaderKind != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+CardReaderKind:" + struAcsAlarmInfo.struAcsEventInfo.byCardReaderKind.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.wAccessChannel >= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+wAccessChannel:" + struAcsAlarmInfo.struAcsEventInfo.wAccessChannel;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.dwEmployeeNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+EmployeeNo:" + struAcsAlarmInfo.struAcsEventInfo.dwEmployeeNo;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.byDeviceNo != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+byDeviceNo:" + struAcsAlarmInfo.struAcsEventInfo.byDeviceNo.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.wLocalControllerID >= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+wLocalControllerID:" + struAcsAlarmInfo.struAcsEventInfo.wLocalControllerID;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.byInternetAccess >= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+byInternetAccess:" + struAcsAlarmInfo.struAcsEventInfo.byInternetAccess.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.byType >= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+byType:" + struAcsAlarmInfo.struAcsEventInfo.byType.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (struAcsAlarmInfo.struAcsEventInfo.bySwipeCardType != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "+bySwipeCardType:" + struAcsAlarmInfo.struAcsEventInfo.bySwipeCardType.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ //其它消息先不罗列了......
|
|
|
|
|
+ if (struAcsAlarmInfo.dwPicDataLen > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ string path = null;
|
|
|
|
|
+ Random rand = new Random(unchecked((int)DateTime.Now.Ticks));
|
|
|
|
|
+ path = string.Format(@"{0}Picture/ACS_LocalTime{1}_{2}.bmp", AppDomain.CurrentDomain.BaseDirectory, szInfo, rand.Next());
|
|
|
|
|
+ using (FileStream fs = new FileStream(path, FileMode.Create))
|
|
|
|
|
+ {
|
|
|
|
|
+ int iLen = (int)struAcsAlarmInfo.dwPicDataLen;
|
|
|
|
|
+ byte[] by = new byte[iLen];
|
|
|
|
|
+ Marshal.Copy(struAcsAlarmInfo.pPicData, by, 0, iLen);
|
|
|
|
|
+ fs.Write(by, 0, iLen);
|
|
|
|
|
+ fs.Close();
|
|
|
|
|
+ }
|
|
|
|
|
+ szInfoBuf = szInfoBuf + "SavePath:" + path;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.Info(szInfoBuf);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|