123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package com.gzlh.config.hksdk;
- import cn.hutool.log.StaticLog;
- import com.sun.jna.Pointer;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Component;
- @Component
- @Slf4j
- public class HkUtils {
- public int Login_V40(String ip, short port, String user, String psw,HCNetSDK hCNetSDK) {
- //注册
- HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
- HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
- String m_sDeviceIP = ip;//设备ip地址
- m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
- System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
- String m_sUsername = user;//设备用户名
- m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
- System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
- String m_sPassword = psw;//设备密码
- m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
- System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
- m_strLoginInfo.wPort = port;
- m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是
- // m_strLoginInfo.byLoginMode=1; //ISAPI登录
- m_strLoginInfo.write();
- int iUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
- if (iUserID == -1) {
- StaticLog.error("登录失败,{},{},{},{} 错误码为,{}" ,ip,port,user,psw, hCNetSDK.NET_DVR_GetLastError());
- return iUserID;
- } else {
- StaticLog.error("登录成功,{},{}" ,ip,port);
- return iUserID;
- }
- }
- static int[] lAlarmHandle = new int[]{-1, -1, -1, -1, -1};//报警布防句柄
- /**
- * 设置布防
- * @param hCNetSDK
- * @param userId
- */
- public void SetAlarm(HCNetSDK hCNetSDK,int userId) {
- //报警布防参数设置
- HCNetSDK.NET_DVR_SETUPALARM_PARAM m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
- m_strAlarmInfo.dwSize = m_strAlarmInfo.size();
- m_strAlarmInfo.byLevel = 0; //布防等级
- m_strAlarmInfo.byAlarmInfoType = 1; // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT)
- m_strAlarmInfo.byDeployType = 0; //布防类型:0-客户端布防,1-实时布防
- m_strAlarmInfo.write();
- int result = hCNetSDK.NET_DVR_SetupAlarmChan_V41(userId, m_strAlarmInfo);
- if (result == -1) {
- log.error("布防失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
- } else {
- log.info("========布防成功==========:{}",userId);
- }
- }
- public boolean handlerUp(HCNetSDK hCNetSDK,int userId){
- HCNetSDK.NET_DVR_BARRIERGATE_CFG net_dvr_barriergate_cfg=new HCNetSDK.NET_DVR_BARRIERGATE_CFG();
- net_dvr_barriergate_cfg.dwSize=net_dvr_barriergate_cfg.size();
- net_dvr_barriergate_cfg.dwChannel=1;
- net_dvr_barriergate_cfg.byLaneNo=1;
- net_dvr_barriergate_cfg.byBarrierGateCtrl=1;
- net_dvr_barriergate_cfg.byUnlock=0;
- net_dvr_barriergate_cfg.byEntranceNo=1;
- net_dvr_barriergate_cfg.byRes[0]=0;
- Pointer pointer= net_dvr_barriergate_cfg.getPointer();
- net_dvr_barriergate_cfg.write();
- boolean result= hCNetSDK.NET_DVR_RemoteControl(userId,HCNetSDK.NET_DVR_BARRIERGATE_CTRL,pointer,net_dvr_barriergate_cfg.size());
- log.error("抬杆结果:{},{}" ,userId, result);
- log.error("操作结果码" + hCNetSDK.NET_DVR_GetLastError());
- return result;
- }
- public boolean getStatus(HCNetSDK hCNetSDK,int userId){
- HCNetSDK.NET_DVR_BARRIERGATE_CFG net_dvr_barriergate_cfg=new HCNetSDK.NET_DVR_BARRIERGATE_CFG();
- net_dvr_barriergate_cfg.dwSize=net_dvr_barriergate_cfg.size();
- net_dvr_barriergate_cfg.dwChannel=1;
- net_dvr_barriergate_cfg.byLaneNo=1;
- net_dvr_barriergate_cfg.byBarrierGateCtrl=1;
- net_dvr_barriergate_cfg.byUnlock=0;
- net_dvr_barriergate_cfg.byEntranceNo=1;
- net_dvr_barriergate_cfg.byRes[0]=0;
- Pointer pointer= net_dvr_barriergate_cfg.getPointer();
- net_dvr_barriergate_cfg.write();
- boolean result= hCNetSDK.NET_DVR_RemoteControl(userId,HCNetSDK.NET_DVR_CHECK_USER_STATUS,pointer,net_dvr_barriergate_cfg.size());
- // log.error("检测结果:{},{}" ,userId, result);
- return result;
- }
- /**
- * 解析时间日期
- * @param time
- * @return
- */
- public String parseTime(int time)
- {
- int year=(time>>26)+2000;
- int month=(time>>22)&15;
- int day=(time>>17)&31;
- int hour=(time>>12)&31;
- int min=(time>>6)&63;
- int second=(time)&63;
- return year+"-"+month+"-"+day+"-"+hour+":"+min+":"+second;
- }
- }
|