|
|
|
@ -1,32 +1,44 @@ |
|
|
|
package com.inspect.nvr.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.inspect.nvr.daHuaCarme.callback.fSnapReceiveCB; |
|
|
|
import com.inspect.nvr.daHuaCarme.jna.NetSDKLib; |
|
|
|
import com.inspect.nvr.daHuaCarme.jna.NetSDKLib.LLong; |
|
|
|
import com.inspect.nvr.daHuaCarme.jna.dahua.ToolKits; |
|
|
|
import com.inspect.nvr.daHuaCarme.utils.jna.DahuaUtils; |
|
|
|
import com.inspect.nvr.domain.Infrared.Camera; |
|
|
|
import com.inspect.nvr.domain.Infrared.NvrInfo; |
|
|
|
import com.inspect.nvr.hikVision.utils.AjaxResult; |
|
|
|
import com.inspect.nvr.service.DahuaService; |
|
|
|
import com.inspect.nvr.utils.redis.RedisService; |
|
|
|
import com.sun.jna.Pointer; |
|
|
|
import com.sun.jna.ptr.IntByReference; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class DahuaServiceImpl implements DahuaService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private NetSDKLib dhNetSDK; |
|
|
|
@Resource |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public AjaxResult login(NvrInfo nvrInfo) { |
|
|
|
|
|
|
|
// dhNetSDK.CLIENT_Logout(); |
|
|
|
private LLong m_hLoginHandle; |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
@Autowired |
|
|
|
private fSnapReceiveCB snapReceiveCB; |
|
|
|
|
|
|
|
@Override |
|
|
|
public String StartRemote(Camera camera) { |
|
|
|
public AjaxResult login(NvrInfo nvrInfo) { |
|
|
|
|
|
|
|
//入参 |
|
|
|
NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam = new NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY(); |
|
|
|
@ -34,10 +46,10 @@ public class DahuaServiceImpl implements DahuaService { |
|
|
|
// pstInParam.szUserName=camera.getUserName().getBytes(); |
|
|
|
// pstInParam.szPassword=camera.getPassword().getBytes(); |
|
|
|
|
|
|
|
pstInParam.szIP = camera.getIp().getBytes(); |
|
|
|
pstInParam.nPort = camera.getPort(); |
|
|
|
pstInParam.szUserName = camera.getUserName().getBytes(); |
|
|
|
pstInParam.szPassword = camera.getPassword().getBytes(); |
|
|
|
pstInParam.szIP = nvrInfo.getNvrIp().getBytes(); |
|
|
|
pstInParam.nPort = nvrInfo.getServerPort(); |
|
|
|
pstInParam.szUserName = nvrInfo.getAccount().getBytes(); |
|
|
|
pstInParam.szPassword = nvrInfo.getPassword().getBytes(); |
|
|
|
|
|
|
|
//出参 |
|
|
|
NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY(); |
|
|
|
@ -54,81 +66,52 @@ public class DahuaServiceImpl implements DahuaService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
// // 入参 |
|
|
|
// NetSDKLib.NET_IN_RADIOMETRY_GETTEMPER netInRadiometryGettemper = new NetSDKLib.NET_IN_RADIOMETRY_GETTEMPER(); |
|
|
|
// // 入参结构体 |
|
|
|
// NetSDKLib.NET_RADIOMETRY_CONDITION netRadiometryCondition = new NetSDKLib.NET_RADIOMETRY_CONDITION(); |
|
|
|
// // 预置位编号 |
|
|
|
// netRadiometryCondition.nPresetId = 1; |
|
|
|
// // 规则编号 |
|
|
|
// netRadiometryCondition.nRuleId = 1; |
|
|
|
// // 测光类型 |
|
|
|
// netRadiometryCondition.nMeterType = 3; |
|
|
|
// // 通道号 |
|
|
|
// netRadiometryCondition.nChannel = camera.getChannel(); |
|
|
|
// System.out.println("通道号 :" + netRadiometryCondition.nChannel); |
|
|
|
|
|
|
|
// netRadiometryCondition.szName = "A1热成像".getBytes(); |
|
|
|
// netRadiometryCondition.reserved = new byte[256]; |
|
|
|
|
|
|
|
// |
|
|
|
// netInRadiometryGettemper.dwSize = netRadiometryCondition.size(); |
|
|
|
// netInRadiometryGettemper.stCondition = netRadiometryCondition; |
|
|
|
|
|
|
|
// //出参 |
|
|
|
// NetSDKLib.NET_OUT_RADIOMETRY_GETTEMPER netOutRadiometryGettemper = new NetSDKLib.NET_OUT_RADIOMETRY_GETTEMPER(); |
|
|
|
// //出参结构体 |
|
|
|
// NetSDKLib.NET_RADIOMETRYINFO netRadiometryinfo = new NetSDKLib.NET_RADIOMETRYINFO(); |
|
|
|
// |
|
|
|
// netInRadiometryGettemper.stCondition = netRadiometryCondition; |
|
|
|
// |
|
|
|
// Pointer pInBuf = new Memory(netRadiometryCondition.size()); |
|
|
|
// pInBuf.write(0, netInRadiometryGettemper.getPointer().getByteArray(0, netInRadiometryGettemper.size()), 0, netInRadiometryGettemper.size()); |
|
|
|
// |
|
|
|
// Pointer pOutBuf = new Memory(netOutRadiometryGettemper.size()); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String StartRemote(Camera camera) { |
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(m_hLoginHandle)) { |
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
login(nvrInfo); |
|
|
|
m_hLoginHandle = (LLong) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_m_hLoginHandle"); |
|
|
|
|
|
|
|
log.info("相机:m_hLoginHandle" + camera.getIp() + "m_hLoginHandle" + m_hLoginHandle); |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 初始化输入结构体 |
|
|
|
System.out.println("[DEBUG] 初始化NET_IN_RADIOMETRY_GETTEMPER结构体"); |
|
|
|
|
|
|
|
NetSDKLib.NET_IN_RADIOMETRY_GETTEMPER netIn = new NetSDKLib.NET_IN_RADIOMETRY_GETTEMPER(); |
|
|
|
|
|
|
|
System.out.println("[DEBUG] 初始化NET_RADIOMETRY_CONDITION结构体"); |
|
|
|
// netIn.stCondition = new NetSDKLib.NET_RADIOMETRY_CONDITION(); |
|
|
|
// 关键:写入结构体数据 |
|
|
|
System.out.println("[DEBUG] 调用netIn.write()前 dwSize: " + netIn.dwSize); |
|
|
|
|
|
|
|
// 设置条件参数 |
|
|
|
netIn.stCondition.nPresetId = 1; |
|
|
|
netIn.stCondition.nRuleId = 1; |
|
|
|
netIn.stCondition.nMeterType = NetSDKLib.NET_RADIOMETRY_METERTYPE.NET_RADIOMETRY_METERTYPE_AREA; |
|
|
|
netIn.stCondition.nChannel = camera.getChannel(); |
|
|
|
|
|
|
|
System.out.println("[DEBUG] 结构体参数设置完成 - " + |
|
|
|
|
|
|
|
log.info("[DEBUG] 结构体参数设置完成 - " + |
|
|
|
"PresetId: " + netIn.stCondition.nPresetId + |
|
|
|
", RuleId: " + netIn.stCondition.nRuleId + |
|
|
|
", MeterType: " + netIn.stCondition.nMeterType + |
|
|
|
", Channel: " + netIn.stCondition.nChannel); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("[DEBUG] 调用netIn.write()后 dwSize: " + netIn.dwSize); |
|
|
|
System.out.println("[DEBUG] netIn结构体大小: " + netIn.size()); |
|
|
|
|
|
|
|
// 2. 输出结构体 |
|
|
|
System.out.println("[DEBUG] 初始化NET_OUT_RADIOMETRY_GETTEMPER结构体"); |
|
|
|
NetSDKLib.NET_OUT_RADIOMETRY_GETTEMPER netOut = new NetSDKLib.NET_OUT_RADIOMETRY_GETTEMPER(); |
|
|
|
NetSDKLib.NET_RADIOMETRYINFO netRadiometryinfo = new NetSDKLib.NET_RADIOMETRYINFO(); |
|
|
|
netOut.stTempInfo = netRadiometryinfo; |
|
|
|
System.out.println("[DEBUG] netOut结构体大小: " + netOut.size()); |
|
|
|
|
|
|
|
System.out.println("netIn.getPointer() :" +netIn.getPointer()); |
|
|
|
|
|
|
|
|
|
|
|
; |
|
|
|
netIn.write(); |
|
|
|
netOut.write(); |
|
|
|
// 3. 调用接口 |
|
|
|
System.out.println("[DEBUG] 准备调用CLIENT_QueryDevInfo..."); |
|
|
|
log.info("[DEBUG] 准备调用CLIENT_QueryDevInfo..."); |
|
|
|
boolean success = dhNetSDK.CLIENT_QueryDevInfo( |
|
|
|
m_hLoginHandle, |
|
|
|
dhNetSDK.NET_QUERY_DEV_RADIOMETRY_TEMPER, |
|
|
|
@ -137,8 +120,7 @@ public class DahuaServiceImpl implements DahuaService { |
|
|
|
null, |
|
|
|
5000 |
|
|
|
); |
|
|
|
|
|
|
|
System.out.println("[DEBUG] CLIENT_QueryDevInfo调用..."+ success); |
|
|
|
log.info("[DEBUG] CLIENT_QueryDevInfo调用..." + success); |
|
|
|
|
|
|
|
// 4. 读取结果 |
|
|
|
if (success) { |
|
|
|
@ -154,4 +136,86 @@ public class DahuaServiceImpl implements DahuaService { |
|
|
|
System.out.println("大华-获取设备参数失败,错误码:" + ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); |
|
|
|
return "获取温度失败"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public String cameraControl(Camera camera, int param1, int param2, int param3) { |
|
|
|
if (ObjectUtil.isEmpty(m_hLoginHandle)) { |
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
login(nvrInfo); |
|
|
|
m_hLoginHandle = (LLong) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_m_hLoginHandle"); |
|
|
|
|
|
|
|
log.info("相机:m_hLoginHandle" + camera.getIp() + "m_hLoginHandle" + m_hLoginHandle); |
|
|
|
} |
|
|
|
String ctr = "GOTO_PRESET"; |
|
|
|
boolean dResult = dhNetSDK.CLIENT_DHPTZControlEx2(m_hLoginHandle, camera.getChannel() - 1, DahuaUtils.PTZCommand(ctr), 0, camera.getPointNum(), 0, 0, null); |
|
|
|
if (!dResult) { |
|
|
|
// System.out.println("CLIENT_DHPTZControlEx Failed!" + ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); |
|
|
|
// return AjaxResult.error(ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); |
|
|
|
log.info("CLIENT_DHPTZControlEx Failed!!"+ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); |
|
|
|
return "-1"; |
|
|
|
} else { |
|
|
|
// System.out.println("CLIENT_DHPTZControlEx success"); |
|
|
|
log.info("CLIENT_DHPTZControlEx success"); |
|
|
|
// return AjaxResult.success(); |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ByteArrayInputStream Picture(Camera camera) { |
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(m_hLoginHandle)) { |
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
login(nvrInfo); |
|
|
|
m_hLoginHandle = (LLong) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_m_hLoginHandle"); |
|
|
|
|
|
|
|
log.info("相机:m_hLoginHandle" + camera.getIp() + "m_hLoginHandle" + m_hLoginHandle); |
|
|
|
} |
|
|
|
|
|
|
|
NetSDKLib.SNAP_PARAMS snapParams = new NetSDKLib.SNAP_PARAMS(); |
|
|
|
snapParams.Channel = camera.getChannel() - 1; // channel |
|
|
|
snapParams.mode = 0; // capture picture mode |
|
|
|
snapParams.Quality = 3; // picture quality |
|
|
|
snapParams.InterSnap = 0; // timer capture picture time interval |
|
|
|
snapParams.CmdSerial = 0; // request serial |
|
|
|
|
|
|
|
IntByReference intByReference = new IntByReference(camera.getChannel() - 1); |
|
|
|
if (!dhNetSDK.CLIENT_SnapPictureEx(m_hLoginHandle, snapParams, intByReference)) { |
|
|
|
// System.out.println("CLIENT_SnapPictureEx Failed!" + ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); |
|
|
|
log.error("CLIENT_SnapPictureEx Failed!" + ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); |
|
|
|
return null; |
|
|
|
} else { |
|
|
|
System.out.println("CLIENT_SnapPictureEx success"); |
|
|
|
|
|
|
|
dhNetSDK.CLIENT_SetSnapRevCallBack(snapReceiveCB,null); |
|
|
|
|
|
|
|
final ByteArrayInputStream[] byteArrInput = new ByteArrayInputStream[1]; |
|
|
|
new fSnapReceiveCB() { |
|
|
|
@Override |
|
|
|
public void invoke(NetSDKLib.LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) { |
|
|
|
|
|
|
|
BufferedImage bufferedImage = null; |
|
|
|
if (pBuf != null && RevLen > 0) { |
|
|
|
byte[] buf = pBuf.getByteArray(0, RevLen); |
|
|
|
byteArrInput[0] = new ByteArrayInputStream(buf); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
return byteArrInput[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |