|
|
@@ -1,83 +1,159 @@
|
|
|
-using DeviceCenter;
|
|
|
-using log4net;
|
|
|
+using log4net;
|
|
|
using System;
|
|
|
-using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
-using System.Linq;
|
|
|
using System.Runtime.InteropServices;
|
|
|
-using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
|
|
|
namespace DeviceCenter
|
|
|
{
|
|
|
- class AcsDevice : Device
|
|
|
+ public class AcsDevice : Device
|
|
|
{
|
|
|
public static readonly ILog log = LogManager.GetLogger("DeviceCenter");
|
|
|
|
|
|
- public int userId { get; set; }
|
|
|
+ public int _userId { get; set; }
|
|
|
public AcsDevice()
|
|
|
{
|
|
|
type = DeviceType.ACS;
|
|
|
}
|
|
|
|
|
|
- public override void Init()
|
|
|
+ public int userId
|
|
|
{
|
|
|
- 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();
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return _userId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //public override void Init()
|
|
|
+ //{
|
|
|
+ // 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];
|
|
|
|
|
|
- struLoginInfo.bUseAsynLogin = false;
|
|
|
- struLoginInfo.sDeviceAddress = ip;
|
|
|
- struLoginInfo.sUserName = username;
|
|
|
- struLoginInfo.sPassword = password;
|
|
|
- struLoginInfo.wPort = (ushort)port;
|
|
|
+ // int m_userId = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
|
|
|
+ // if (m_userId < 0)
|
|
|
+ // {
|
|
|
+ // status = DeviceStatus.FAIL;
|
|
|
+ // uint nErr = CHCNetSDK.NET_DVR_GetLastError();
|
|
|
+ // if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
|
|
|
+ // {
|
|
|
+ // message = "user name or password error!";
|
|
|
+ // if (1 == struDeviceInfoV40.bySupportLock)
|
|
|
+ // {
|
|
|
+ // string strTemp1 = string.Format(" Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
|
|
|
+ // message += 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);
|
|
|
+ // message = strTemp1;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // message = "net error or dvr is busy!";
|
|
|
+ // }
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // _userId = m_userId;
|
|
|
|
|
|
- struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];
|
|
|
+ // 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)
|
|
|
+ // {
|
|
|
+ // message = "Setup alarm chan failed";
|
|
|
+ // status = DeviceStatus.FAIL;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // message = "";
|
|
|
+ // status = DeviceStatus.CONNECTED;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
- int m_userId = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
|
|
|
- if (m_userId < 0)
|
|
|
+ public override async void Init()
|
|
|
+ {
|
|
|
+ await Task.Run(() =>
|
|
|
{
|
|
|
- uint nErr = CHCNetSDK.NET_DVR_GetLastError();
|
|
|
- if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
|
|
|
+ status = DeviceStatus.CONNECTING;
|
|
|
+ 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)
|
|
|
{
|
|
|
- MessageBox.Show("user name or password error!");
|
|
|
- if (1 == struDeviceInfoV40.bySupportLock)
|
|
|
+ status = DeviceStatus.FAIL;
|
|
|
+ uint nErr = CHCNetSDK.NET_DVR_GetLastError();
|
|
|
+ if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
|
|
|
{
|
|
|
- string strTemp1 = string.Format("Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
|
|
|
- MessageBox.Show(strTemp1);
|
|
|
+ message = "user name or password error!";
|
|
|
+ if (1 == struDeviceInfoV40.bySupportLock)
|
|
|
+ {
|
|
|
+ string strTemp1 = string.Format(" Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
|
|
|
+ message += strTemp1;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else if (nErr == CHCNetSDK.NET_DVR_USER_LOCKED)
|
|
|
- {
|
|
|
- if (1 == struDeviceInfoV40.bySupportLock)
|
|
|
+ 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);
|
|
|
+ message = strTemp1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- string strTemp1 = string.Format("user is locked, the remaining lock time is {0}", struDeviceInfoV40.dwSurplusLockTime);
|
|
|
- MessageBox.Show(strTemp1);
|
|
|
+ message = "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)
|
|
|
+ {
|
|
|
+ message = "Setup alarm chan failed";
|
|
|
+ status = DeviceStatus.FAIL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MessageBox.Show("net error or dvr is busy!");
|
|
|
+ message = "";
|
|
|
+ status = DeviceStatus.CONNECTED;
|
|
|
}
|
|
|
- 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()
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ status = DeviceStatus.IDLE;
|
|
|
}
|
|
|
|
|
|
public void onAlarm(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
|