AscDemoPublic.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Web.Script.Serialization;
  8. namespace DeviceCenter
  9. {
  10. public enum SynInfoCommand
  11. {
  12. NO_DEFINE,
  13. CARD_INFO_SYN,
  14. USER_INFO_SYN
  15. }
  16. public class UserInfo
  17. {
  18. public string memberNo { get; set; }
  19. public string memberName { get; set; }
  20. public string cardNum { get; set; }
  21. public string fingerPrintNum { get; set; }
  22. public CardInfo[] cards { get; set; }
  23. }
  24. public class CardInfo
  25. {
  26. public string cardSerialNumber { get; set; }
  27. public string cardNumber { get; set; }
  28. public string cardType { get; set; }
  29. public string cardPassword { get; set; }
  30. public string cardValidityPeriod { get; set; }
  31. public string fingerSerialNumber { get; set; }
  32. public string fingerPrintDescriptions { get; set; }
  33. }
  34. /// <summary>
  35. /// before using System.Web.Script.Serialization,need to add System.Web.Extensions program repository
  36. /// </summary>
  37. public class JsonConvert_test
  38. {
  39. public static string Serializer<T>(T t)
  40. {
  41. JavaScriptSerializer jsonSerialize = new JavaScriptSerializer();
  42. return jsonSerialize.Serialize(t);
  43. }
  44. public static T Deserialize<T>(string jsonString)
  45. {
  46. JavaScriptSerializer jsonSerialize = new JavaScriptSerializer();
  47. return (T)jsonSerialize.Deserialize<T>(jsonString);
  48. }
  49. // runtime using like following
  50. //[DataContract]
  51. //public class test
  52. //{
  53. // [DataMember(Name = "d1")]
  54. // public string d1 { get; set; }
  55. // [DataMember(Name = "d2")]
  56. // public string d2 { get; set; }
  57. // [DataMember(Name = "d3")]
  58. // public string d3 { get; set; }
  59. //}
  60. //using System.Runtime.Serialization.Json;
  61. //public static string SerializerIO<T>(T t)
  62. //{
  63. // DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
  64. // using (MemoryStream ms = new MemoryStream())
  65. // {
  66. // ser.WriteObject(ms, t);
  67. // string jsonString = Encoding.UTF8.GetString(ms.ToArray());
  68. // ms.Close();
  69. // return jsonString;
  70. // }
  71. //}
  72. //public static T DeserializeIO<T>(string jsonString)
  73. //{
  74. // DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
  75. // using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
  76. // {
  77. // T obj = (T)ser.ReadObject(ms);
  78. // return obj;
  79. // }
  80. //}
  81. }
  82. public class AcsDemoPublic
  83. {
  84. public static readonly string[] strDoorStatus = { "invalid", "sleep", "Normally open", "Normally close" };
  85. public static readonly string[] strVerify = {"invalid", "sleep", "card and password", "card", "card or password", "fingerprint", "fingerprint and password", "fingerprint or card",
  86. "fingerprint and card", "fingerprint and card and password","face or fingerprint or card or password","face and fingerprint",
  87. "face and password", "face and card", "face", "work number and password", "fingerprint or password", "work number and fingerprint",
  88. "work number and fingerprint and password", "face and fingerprint and card", "face and password and fingerprint", "work number and face",
  89. "face or face and swipe card"};
  90. public static readonly string[] strFingerType = { "Common fingerprint", "Stress fingerprint", "Patrol fingerprint", "Super fingerprint", "Dismissing fingerprint" };
  91. public static readonly string[] strCardType = { "unknown", "ordinary card", "disabled card", "black list card", "patrol card", "stress card", "super card", "guest card", "remove card",
  92. "employee card", "emergency card","emergency management card"};
  93. public const int MAX_DEVICES = 512;//max device number
  94. //bmp status
  95. public const int TREE_ALL = 0;//device list
  96. public const int DEVICE_LOGOUT = 1;//device not log in
  97. public const int DEVICE_LOGIN = 2;//device login
  98. public const int DEVICE_FORTIFY = 3;//on guard
  99. public const int DEVICE_ALARM = 4;//alarm on device
  100. public const int DEVICE_FORTIFY_ALARM = 5;//onguard & alarm on device
  101. public const int DOOR_COLSED = 6;
  102. public const int DOOR_OPEN = 7;
  103. public const int CARD_ON_LINE = 8; //preview & record & alarm
  104. public const int CARD_OFF_LINE = 9; //channel off-line
  105. public const int DOOR_ALWAYSCOLSED = 6;
  106. public const int DOOR_ALWAYSOPEN = 7;
  107. public const int CHAN_ORIGINAL = 6;//no preview, no record
  108. public const int CHAN_PLAY = 7; //preview
  109. public const int CHAN_RECORD = 8; //record
  110. public const int CHAN_PLAY_RECORD = 9; //preview and record
  111. public const int CHAN_ALARM = 10; //no preview, no record, only alarm
  112. public const int CHAN_PLAY_ALARM = 11; //review, no record, with alarm info
  113. public const int CHAN_PLAY_RECORD_ALARM = 12; //preview & record & alarm
  114. public const int CHAN_OFF_LINE = 13; //channel off-line
  115. public const int ALARM_INFO_T = 0;
  116. public const int OPERATION_SUCC_T = 1;
  117. public const int OPERATION_FAIL_T = 2;
  118. public const int PLAY_SUCC_T = 3;
  119. public const int PLAY_FAIL_T = 4;
  120. public const int REGIONTYPE = 0;
  121. public const int DEVICETYPE = 2;
  122. public const int CHANNELTYPE = 3;
  123. public const int DOORTYPE = 4;
  124. public const int CARDREADERTYPE = 6;
  125. public const int USERTYPE = 5;
  126. //batch
  127. public const int ZERO_CHAN_INDEX = 500;
  128. public const int MIRROR_CHAN_INDEX = 400;
  129. [StructLayout(LayoutKind.Sequential)]
  130. public struct LOCAL_LOG_INFO
  131. {
  132. public int iLogType;
  133. public string strTime;
  134. public string strLogInfo;
  135. public string strDevInfo;
  136. public string strErrInfo;
  137. public string strSavePath;
  138. }
  139. [StructLayout(LayoutKind.Sequential)]
  140. public struct PREVIEW_IFNO
  141. {
  142. public int iDeviceIndex; //device index
  143. public int iChanIndex; //channel index
  144. public byte PanelNo;
  145. public int lRealHandle;
  146. public IntPtr hPlayWnd;
  147. }
  148. public enum DEMO_CHANNEL_TYPE
  149. {
  150. DEMO_CHANNEL_TYPE_INVALID = -1,
  151. DEMO_CHANNEL_TYPE_ANALOG = 0,
  152. DEMO_CHANNEL_TYPE_IP = 1,
  153. DEMO_CHANNEL_TYPE_MIRROR = 2
  154. }
  155. [StructLayout(LayoutKind.Sequential)]
  156. public struct PASSIVEDECODE_CHANINFO
  157. {
  158. public Int32 lPassiveHandle;
  159. public Int32 lRealHandle;
  160. public Int32 lUserID;
  161. public Int32 lSel;
  162. public IntPtr hFileThread;
  163. public IntPtr hFileHandle;
  164. public IntPtr hExitThread;
  165. public IntPtr hThreadExit;
  166. public string strRecordFilePath;
  167. public void init()
  168. {
  169. lPassiveHandle = -1;
  170. lRealHandle = -1;
  171. lUserID = -1;
  172. lSel = -1;
  173. hFileThread = IntPtr.Zero;
  174. hFileHandle = IntPtr.Zero;
  175. hExitThread = IntPtr.Zero;
  176. hThreadExit = IntPtr.Zero;
  177. strRecordFilePath = null;
  178. }
  179. }
  180. [StructLayout(LayoutKind.Sequential)]
  181. public struct STRU_CHANNEL_INFO
  182. {
  183. public int iDeviceIndex; //device index
  184. public int iChanIndex; //channel index
  185. public DEMO_CHANNEL_TYPE iChanType;
  186. public int iChannelNO; //channel NO.
  187. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)]
  188. public string chChanName; //channel name
  189. public uint dwProtocol; //network protocol
  190. public uint dwStreamType; //stream type,0-main stream,1-sub code stream,2-code stream 3,
  191. public uint dwLinkMode;//Stream connection: 0:TCP,1:UDP,2:multicast,3 - RTP,4-RTP/RTSP,5-RSTP/HTTP
  192. public bool bPassbackRecord; //0- disable the video comes back,1 enable the video comes back
  193. public uint dwPreviewMode; //Preview mode 0-normal 1-delay
  194. public int iPicResolution; //resolution
  195. public int iPicQuality; //image quality
  196. public Int32 lRealHandle; //preview handle
  197. public bool bLocalManualRec; //manual record
  198. public bool bAlarm; //alarm
  199. public bool bEnable; //enable
  200. public uint dwImageType; //channel status icon
  201. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 16)]
  202. public string chAccessChanIP; //ip addr of IP channel
  203. public uint nPreviewProtocolType; //stream protocol type 0-proprietary protocol 1-RTSP protocol
  204. public IntPtr pNext;
  205. public void init()
  206. {
  207. iDeviceIndex = -1;
  208. iChanIndex = -1;
  209. iChannelNO = -1;
  210. iChanType = DEMO_CHANNEL_TYPE.DEMO_CHANNEL_TYPE_INVALID;
  211. chChanName = null;
  212. dwProtocol = 0;
  213. dwStreamType = 0;
  214. dwLinkMode = 0;
  215. iPicResolution = 0;
  216. iPicQuality = 2;
  217. lRealHandle = -1;
  218. bLocalManualRec = false;
  219. bAlarm = false;
  220. bEnable = false;
  221. dwImageType = CHAN_ORIGINAL;
  222. chAccessChanIP = null;
  223. pNext = IntPtr.Zero;
  224. dwPreviewMode = 0;
  225. bPassbackRecord = false;
  226. nPreviewProtocolType = 0;
  227. }
  228. }
  229. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  230. public struct STRU_DEVICE_INFO
  231. {
  232. public int iDeviceIndex; //device index
  233. public Int32 lLoginID; //ID
  234. public uint dwDevSoftVer; //erserved
  235. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)]
  236. public string chLocalNodeName; //local device node
  237. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)]
  238. public string chDeviceName; //device name
  239. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 130)]
  240. public string chDeviceIP; //device IP: IP,pppoe address, or network gate address, etc
  241. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 130)]
  242. public string chDeviceIPInFileName; //if chDeviceIP includes ':'(IPV6),change it to '.', for '.'is not allowed in window's file name
  243. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = CHCNetSDK.NAME_LEN)]
  244. public string chLoginUserName; //login user name
  245. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = CHCNetSDK.NAME_LEN)]
  246. public string chLoginPwd; //password
  247. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 130)]
  248. public string chDeviceMultiIP; //multi-cast group address
  249. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 50)]
  250. public string chSerialNumber; //SN
  251. public int iDeviceChanNum; //channel numder (analog + ip)
  252. public int iStartChan; //start channel number
  253. public int iStartDChan; //start IP channel number
  254. public int iDeviceType; //device type
  255. public int iDiskNum; //HD number
  256. public Int32 lDevicePort; //port number
  257. public int iAlarmInNum; //alarm in number
  258. public int iAlarmOutNum; //alarm out number
  259. public int iAudioNum; //voice talk number
  260. public int iAnalogChanNum; //analog channel number
  261. public int iIPChanNum; //IP channel number
  262. public int iGroupNO; //IP Group NO.
  263. public bool bCycle; //if this device is on cycle recording
  264. public bool bPlayDevice; //will be added later
  265. public bool bVoiceTalk; //on voice talkor not
  266. [MarshalAs(UnmanagedType.ByValArray, SizeConst = CHCNetSDK.MAX_AUDIO_V40)]
  267. public Int32[] lAudioHandle; //voicebroadcast handle
  268. [MarshalAs(UnmanagedType.ByValArray, SizeConst = CHCNetSDK.MAX_AUDIO_V40)]
  269. public bool[] bCheckBroadcast; //Add to broad cast group
  270. public Int32 lFortifyHandle; //on guard handle
  271. public bool bAlarm; //whether there is alarm
  272. public int iDeviceLoginType; //register mode 0 - fix IP 1- IPSERVER mode 2 - domain name
  273. public uint dwImageType; //device status icon
  274. public bool bIPRet; //support IP conection
  275. public int iEnableChanNum; //valid channel number
  276. public bool bDVRLocalAllRec; //local recording
  277. [MarshalAs(UnmanagedType.ByValArray, SizeConst = CHCNetSDK.MAX_AUDIO_V40)]
  278. public Int32[] lVoiceCom; //voice transmit
  279. public Int32 lFirstEnableChanIndex; //first enabled channel index
  280. public Int32 lTranHandle; //232 transparent channel handle
  281. public byte byZeroChanNum; //Zero channel number
  282. public byte byMainProto; //main stream protocol type 0-Private, 1-rtp/tcp, 2-rtp/rtsp
  283. public byte bySubProto; //sub stream protocol type 0-Private, 1-rtp/tcp, 2-rtp/rtsp
  284. public byte bySupport; //ability
  285. public byte byStartDTalkChan;
  286. public byte byAudioInputChanNum;
  287. public byte byStartAudioInputChanNo;
  288. public byte byLanguageType;
  289. [MarshalAs(UnmanagedType.ByValArray, SizeConst = CHCNetSDK.MAX_CHANNUM_V40, ArraySubType = UnmanagedType.Struct)]
  290. public STRU_CHANNEL_INFO[] pStruChanInfo; //channel structure
  291. public CHCNetSDK.NET_DVR_IPPARACFG_V40[] pStruIPParaCfgV40; //IP channel parameters
  292. public CHCNetSDK.NET_DVR_IPALARMINCFG struAlarmInCfg;
  293. public CHCNetSDK.NET_DVR_IPALARMINCFG_V40 pStruIPAlarmInCfgV40; // IP alarm In parameters
  294. public CHCNetSDK.NET_DVR_IPALARMOUTCFG_V40 pStruIPAlarmOutCfgV40; // IP alarm Out parameters
  295. public CHCNetSDK.NET_DVR_IPALARMOUTCFG struAlarmOutCfg;
  296. public IntPtr pNext;
  297. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16, ArraySubType = UnmanagedType.Struct)]
  298. public STRU_CHANNEL_INFO[] struZeroChan;
  299. [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 16)]
  300. public string sSecretKey;
  301. public int iAudioEncType;
  302. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256, ArraySubType = UnmanagedType.Struct)]
  303. public PASSIVEDECODE_CHANINFO[] struPassiveDecode;
  304. public byte bySupport1; //ability,0-no support,1-support
  305. // bySupport1 & 0x1, indicates whether or not the support with snmp v30
  306. //bySupport1 & 0x2, support to distinguish the playback and download
  307. //bySupport1 & 0x4, support fortify priority
  308. //bySupport1 & 0x8, smart devices support protection period extension
  309. //bySupport1 & 0x10, indicates whether or not the support multiple disk number (more than 33)
  310. //bySupport1 & 0x40 indicates whether or not the delay support preview
  311. public byte bySupport2; //ability to set extended, and 0-no support,1-support
  312. //bySupport2 & 0x1, indicates whether the decoder support via the URL decoding
  313. //bySupport2 & 0x2, is support FTPV40
  314. //bySupport2 & 0x4, is support ANR (broken network video)
  315. public byte byStartIPAlarmOutNo; //starting IP number alarm output
  316. public byte byMirrorChanNum; //image channel number(recorded in the host is used to represent a director channel)
  317. public ushort wStartMirrorChanNo; //The initial image channel number
  318. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16, ArraySubType = UnmanagedType.Struct)]
  319. public STRU_CHANNEL_INFO[] struMirrorChan;
  320. public byte bySupport5;
  321. public byte bySupport7;// bySupport7 & 0x2 indicates whether the device supports the IPC HVT model extension
  322. public byte byCharaterEncodeType;
  323. public bool bInit;
  324. public byte byPanelNo; //
  325. public int iDoorNum;
  326. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3 * CHCNetSDK.MAX_DOOR_NUM_256, ArraySubType = UnmanagedType.I1)]
  327. public int[] iDoorStatus;
  328. [MarshalAs(UnmanagedType.ByValArray, SizeConst = CHCNetSDK.MAX_DOOR_NUM_256, ArraySubType = UnmanagedType.ByValTStr)]
  329. public string[] sDoorName; // door name
  330. public void Init()
  331. {
  332. iGroupNO = -1;
  333. iDeviceIndex = -1;
  334. lLoginID = -1;
  335. dwDevSoftVer = 0;
  336. chLocalNodeName = null;
  337. chDeviceName = null;
  338. chDeviceIP = null;
  339. chDeviceIPInFileName = null;
  340. //chDevNetCard1IP[0] = '\0';
  341. chLoginUserName = null;
  342. chLoginPwd = null;
  343. chDeviceMultiIP = null;
  344. chSerialNumber = null;
  345. iDeviceChanNum = -1;
  346. iDoorNum = -1;
  347. iDoorStatus = new int[3 * CHCNetSDK.MAX_DOOR_NUM_256];
  348. sDoorName = new string[CHCNetSDK.MAX_DOOR_NUM_256];
  349. iStartChan = 0;
  350. iDeviceType = 0;
  351. iDiskNum = 0;
  352. lDevicePort = 8000;
  353. iAlarmInNum = 0;
  354. iAlarmOutNum = 0;
  355. iAnalogChanNum = 0;
  356. iIPChanNum = 0;
  357. byAudioInputChanNum = 0;
  358. byStartAudioInputChanNo = 0;
  359. bCycle = false;
  360. bPlayDevice = false;
  361. bVoiceTalk = false;
  362. //lAudioHandle = new Int32[CHCNetSDK.MAX_AUDIO_V40];
  363. //bCheckBroadcast = new bool[CHCNetSDK.MAX_AUDIO_V40];
  364. lFortifyHandle = -1;
  365. bAlarm = false;
  366. iDeviceLoginType = 0;
  367. dwImageType = DEVICE_LOGOUT;
  368. bIPRet = false;
  369. pNext = IntPtr.Zero;
  370. //lVoiceCom = new Int32[CHCNetSDK.MAX_AUDIO_V40];
  371. //for (int i = 0; i < lVoiceCom.Length; i++)
  372. //{
  373. // lVoiceCom[i] = -1;
  374. //}
  375. lFirstEnableChanIndex = 0;
  376. lTranHandle = -1;
  377. byZeroChanNum = 0;
  378. //lAudioHandle[0] = -1;
  379. //lAudioHandle[1] = -1;
  380. //pStruChanInfo = new STRU_CHANNEL_INFO[CHCNetSDK.MAX_CHANNUM_V40];
  381. //struZeroChan = new STRU_CHANNEL_INFO[16];
  382. //struMirrorChan = new STRU_CHANNEL_INFO[16];
  383. //pStruIPAlarmInCfgV40 = new CHCNetSDK.NET_DVR_IPALARMINCFG_V40();
  384. //pStruIPAlarmOutCfgV40 = new CHCNetSDK.NET_DVR_IPALARMOUTCFG_V40();
  385. //struAlarmInCfg = new CHCNetSDK.NET_DVR_IPALARMINCFG();
  386. //struAlarmOutCfg = new CHCNetSDK.NET_DVR_IPALARMOUTCFG();
  387. sSecretKey = "StreamNotEncrypt";
  388. iAudioEncType = 0;
  389. bySupport1 = 0;
  390. bySupport2 = 0;
  391. bySupport5 = 0;
  392. bySupport7 = 0;
  393. byStartDTalkChan = 0;
  394. byLanguageType = 0;
  395. byCharaterEncodeType = 0;
  396. bInit = true;
  397. byPanelNo = 4;
  398. }
  399. }
  400. public static bool CheckState(CHCNetSDK.NET_DVR_DATE struItem)
  401. {
  402. if (struItem.wYear < 1970 || struItem.byMonth > 12 || struItem.byDay > 31)
  403. {
  404. return false;
  405. }
  406. return true;
  407. }
  408. public static bool CheckDate(CHCNetSDK.NET_DVR_SIMPLE_DAYTIME struItem)
  409. {
  410. if (struItem.byHour > 24 || struItem.byMinute > 59 || struItem.bySecond > 59)
  411. {
  412. return false;
  413. }
  414. return true;
  415. }
  416. public static void WriteBytesToFile(byte[] bytes, int len, string strPath)
  417. {
  418. try
  419. {
  420. using (FileStream fs = new FileStream(strPath, FileMode.OpenOrCreate))
  421. {
  422. BinaryWriter objBinaryWrite = new BinaryWriter(fs);
  423. fs.Write(bytes, 0, len);
  424. fs.Close();
  425. }
  426. }
  427. catch (Exception e)
  428. {
  429. //MessageBox.Show("Write file exception details{}" + e.Data.ToString());
  430. return;
  431. }
  432. }
  433. }
  434. public class ISAPIRemoteConfig
  435. {
  436. public ISAPIRemoteConfig(Int32 UserID, int commandCode, string url)
  437. {
  438. this.url = url;
  439. this.cmd = commandCode;
  440. this.remoteConfigHandle = -1;
  441. this.listener = null;
  442. this.lUserID = UserID;
  443. }
  444. public ISAPIRemoteConfig(Int32 UserID, int commandCode, string url, CHCNetSDK.RemoteConfigCallback callback)
  445. {
  446. this.url = url;
  447. this.cmd = commandCode;
  448. this.listener = callback;
  449. this.remoteConfigHandle = -1;
  450. this.lUserID = UserID;
  451. }
  452. public void SetListener(CHCNetSDK.RemoteConfigCallback callback)
  453. {
  454. this.listener = callback;
  455. }
  456. public bool start()
  457. {
  458. Debug.Assert(remoteConfigHandle == -1);
  459. if (remoteConfigHandle == -1)
  460. {
  461. Debug.Assert(url != null);
  462. IntPtr ptrURL = Marshal.StringToHGlobalAnsi(url);
  463. remoteConfigHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(lUserID, (uint)cmd, ptrURL, url.Length, listener, IntPtr.Zero);
  464. Marshal.FreeHGlobal(ptrURL);
  465. if (-1 == remoteConfigHandle)
  466. {
  467. return false;
  468. }
  469. return true;
  470. }
  471. return false;
  472. }
  473. public void stop()
  474. {
  475. if (remoteConfigHandle != -1)
  476. {
  477. CHCNetSDK.NET_DVR_StopRemoteConfig(remoteConfigHandle);
  478. remoteConfigHandle = -1;
  479. }
  480. }
  481. public bool send(string input)
  482. {
  483. Debug.Assert(input != null);
  484. Debug.Assert(remoteConfigHandle != -1);
  485. Encoding utf8 = null;
  486. int inputlen = 0;
  487. try
  488. {
  489. utf8 = System.Text.Encoding.GetEncoding("utf-8");//转换编码
  490. inputlen = utf8.GetByteCount(input);
  491. }
  492. catch
  493. {
  494. // do something
  495. }
  496. IntPtr ptrData = Marshal.AllocHGlobal(inputlen + 1);
  497. for (int i = 0; i < inputlen + 1; i++)
  498. {
  499. Marshal.WriteByte(ptrData, i, 0);
  500. }
  501. Marshal.Copy(utf8.GetBytes(input), 0, ptrData, inputlen);
  502. if (!CHCNetSDK.NET_DVR_SendRemoteConfig(remoteConfigHandle, (int)CHCNetSDK.LONG_CFG_SEND_DATA_TYPE_ENUM.ENUM_SEND_JSON_DATA, ptrData, (uint)inputlen))
  503. {
  504. Marshal.FreeHGlobal(ptrData);
  505. return false;
  506. }
  507. Marshal.FreeHGlobal(ptrData);
  508. return true;
  509. }
  510. private CHCNetSDK.RemoteConfigCallback listener;
  511. private string url;
  512. private int cmd;
  513. public int remoteConfigHandle;
  514. private Int32 lUserID;
  515. }
  516. public class DeviceInfoList
  517. {
  518. public List<CDevice> Devices { get; set; }
  519. }
  520. public class CDevice
  521. {
  522. public int iDeviceIndex { get; set; } //device index
  523. public string chLocalNodeName { get; set; } //local device node
  524. public string chDeviceName { get; set; } //device name
  525. public string chDeviceIP { get; set; } //device IP: IP,pppoe address, or network gate address, etc
  526. public string chLoginUserName { get; set; } //login user name
  527. public string chLoginPwd { get; set; } //password
  528. public string chSerialNumber { get; set; } //SN
  529. public int iDeviceType { get; set; } //device type
  530. public int lDevicePort { get; set; } //port number
  531. public byte byCharaterEncodeType { get; set; }
  532. public int iDoorNum { get; set; }
  533. //public int[] iDoorStatus { get; set; }
  534. //public string[] sDoorName { get; set; } // door name
  535. public int iDeviceChanNum { get; set; }
  536. }
  537. public class CResponseStatus
  538. {
  539. public string requestURL { get; set; }
  540. public int statusCode { get; set; }
  541. public string statusString { get; set; }
  542. public string subStatusCode { get; set; }
  543. public int errorCode { get; set; }
  544. public string errorMsg { get; set; }
  545. }
  546. public class CRegion
  547. {
  548. public float height { get; set; }
  549. public float width { get; set; }
  550. public float x { get; set; }
  551. public float y { get; set; }
  552. }
  553. public class CPoint
  554. {
  555. public float x { get; set; }
  556. public float y { get; set; }
  557. }
  558. }