HkUtils.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.gzlh.config.hksdk;
  2. import cn.hutool.log.StaticLog;
  3. import com.sun.jna.Pointer;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.stereotype.Component;
  6. @Component
  7. @Slf4j
  8. public class HkUtils {
  9. public int Login_V40(String ip, short port, String user, String psw,HCNetSDK hCNetSDK) {
  10. //注册
  11. HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
  12. HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
  13. String m_sDeviceIP = ip;//设备ip地址
  14. m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
  15. System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
  16. String m_sUsername = user;//设备用户名
  17. m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
  18. System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
  19. String m_sPassword = psw;//设备密码
  20. m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
  21. System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
  22. m_strLoginInfo.wPort = port;
  23. m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是
  24. // m_strLoginInfo.byLoginMode=1; //ISAPI登录
  25. m_strLoginInfo.write();
  26. int iUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
  27. if (iUserID == -1) {
  28. StaticLog.error("登录失败,{},{},{},{} 错误码为,{}" ,ip,port,user,psw, hCNetSDK.NET_DVR_GetLastError());
  29. return iUserID;
  30. } else {
  31. StaticLog.error("登录成功,{},{}" ,ip,port);
  32. return iUserID;
  33. }
  34. }
  35. static int[] lAlarmHandle = new int[]{-1, -1, -1, -1, -1};//报警布防句柄
  36. /**
  37. * 设置布防
  38. * @param hCNetSDK
  39. * @param userId
  40. */
  41. public void SetAlarm(HCNetSDK hCNetSDK,int userId) {
  42. //报警布防参数设置
  43. HCNetSDK.NET_DVR_SETUPALARM_PARAM m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
  44. m_strAlarmInfo.dwSize = m_strAlarmInfo.size();
  45. m_strAlarmInfo.byLevel = 0; //布防等级
  46. m_strAlarmInfo.byAlarmInfoType = 1; // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT)
  47. m_strAlarmInfo.byDeployType = 0; //布防类型:0-客户端布防,1-实时布防
  48. m_strAlarmInfo.write();
  49. int result = hCNetSDK.NET_DVR_SetupAlarmChan_V41(userId, m_strAlarmInfo);
  50. if (result == -1) {
  51. log.error("布防失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
  52. } else {
  53. log.info("========布防成功==========:{}",userId);
  54. }
  55. }
  56. public boolean handlerUp(HCNetSDK hCNetSDK,int userId){
  57. HCNetSDK.NET_DVR_BARRIERGATE_CFG net_dvr_barriergate_cfg=new HCNetSDK.NET_DVR_BARRIERGATE_CFG();
  58. net_dvr_barriergate_cfg.dwSize=net_dvr_barriergate_cfg.size();
  59. net_dvr_barriergate_cfg.dwChannel=1;
  60. net_dvr_barriergate_cfg.byLaneNo=1;
  61. net_dvr_barriergate_cfg.byBarrierGateCtrl=1;
  62. net_dvr_barriergate_cfg.byUnlock=0;
  63. net_dvr_barriergate_cfg.byEntranceNo=1;
  64. net_dvr_barriergate_cfg.byRes[0]=0;
  65. Pointer pointer= net_dvr_barriergate_cfg.getPointer();
  66. net_dvr_barriergate_cfg.write();
  67. boolean result= hCNetSDK.NET_DVR_RemoteControl(userId,HCNetSDK.NET_DVR_BARRIERGATE_CTRL,pointer,net_dvr_barriergate_cfg.size());
  68. log.error("抬杆结果:{},{}" ,userId, result);
  69. log.error("操作结果码" + hCNetSDK.NET_DVR_GetLastError());
  70. return result;
  71. }
  72. public boolean getStatus(HCNetSDK hCNetSDK,int userId){
  73. HCNetSDK.NET_DVR_BARRIERGATE_CFG net_dvr_barriergate_cfg=new HCNetSDK.NET_DVR_BARRIERGATE_CFG();
  74. net_dvr_barriergate_cfg.dwSize=net_dvr_barriergate_cfg.size();
  75. net_dvr_barriergate_cfg.dwChannel=1;
  76. net_dvr_barriergate_cfg.byLaneNo=1;
  77. net_dvr_barriergate_cfg.byBarrierGateCtrl=1;
  78. net_dvr_barriergate_cfg.byUnlock=0;
  79. net_dvr_barriergate_cfg.byEntranceNo=1;
  80. net_dvr_barriergate_cfg.byRes[0]=0;
  81. Pointer pointer= net_dvr_barriergate_cfg.getPointer();
  82. net_dvr_barriergate_cfg.write();
  83. boolean result= hCNetSDK.NET_DVR_RemoteControl(userId,HCNetSDK.NET_DVR_CHECK_USER_STATUS,pointer,net_dvr_barriergate_cfg.size());
  84. // log.error("检测结果:{},{}" ,userId, result);
  85. return result;
  86. }
  87. /**
  88. * 解析时间日期
  89. * @param time
  90. * @return
  91. */
  92. public String parseTime(int time)
  93. {
  94. int year=(time>>26)+2000;
  95. int month=(time>>22)&15;
  96. int day=(time>>17)&31;
  97. int hour=(time>>12)&31;
  98. int min=(time>>6)&63;
  99. int second=(time)&63;
  100. return year+"-"+month+"-"+day+"-"+hour+":"+min+":"+second;
  101. }
  102. }