diff --git a/src/main/java/com/inspect/nvr/controller/DahuaController.java b/src/main/java/com/inspect/nvr/controller/DahuaController.java index 8d033c5..b86ba78 100644 --- a/src/main/java/com/inspect/nvr/controller/DahuaController.java +++ b/src/main/java/com/inspect/nvr/controller/DahuaController.java @@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import java.io.ByteArrayInputStream; + @Controller @RequestMapping("/dahua") public class DahuaController { @@ -30,8 +32,19 @@ public class DahuaController { public String StartRemote(@RequestBody Camera camera) { return dahuaService.StartRemote(camera); } + @PostMapping("/cameraControl") + @CrossOrigin + @ResponseBody + public String cameraControl(@RequestBody Camera camera) { + return dahuaService.cameraControl(camera, 0, 0, 0); + } - + @PostMapping("/Picture") + @CrossOrigin + @ResponseBody + public ByteArrayInputStream Picture(@RequestBody Camera camera) { + return dahuaService.Picture(camera); + } } diff --git a/src/main/java/com/inspect/nvr/controller/InfraredController.java b/src/main/java/com/inspect/nvr/controller/InfraredController.java index fb2a698..9c2b0f1 100644 --- a/src/main/java/com/inspect/nvr/controller/InfraredController.java +++ b/src/main/java/com/inspect/nvr/controller/InfraredController.java @@ -36,8 +36,8 @@ public class InfraredController { */ @PostMapping("/login") @ResponseBody - public void login(@RequestBody NvrInfo nvrInfo) { - hikVisionService.login(nvrInfo); + public AjaxResult login(@RequestBody NvrInfo nvrInfo) { + return hikVisionService.login(nvrInfo); } /** @@ -64,15 +64,16 @@ public class InfraredController { @ResponseBody public AjaxResult cameraAngleJump(@RequestBody Camera camera) { - return hikVisionService.cameraAngleJump(camera); + return hikVisionService.NvrCameraAngleJump(camera); } @PostMapping("/camera") @ResponseBody public AjaxResult camera(@RequestBody Camera camera) throws Exception { - Camera cameraPictrue = hikVisionService.cameraPictrue(camera); - return AjaxResult.success().put("data", cameraPictrue) ; +// Camera cameraPictrue = hikVisionService.cameraPictrue(camera); +// return AjaxResult.success().put("data", cameraPictrue) ; + return hikVisionService.NvrCameraPictrue(camera); } @PostMapping("/cameraHk") @ResponseBody diff --git a/src/main/java/com/inspect/nvr/daHuaCarme/callback/fSnapReceiveCB.java b/src/main/java/com/inspect/nvr/daHuaCarme/callback/fSnapReceiveCB.java new file mode 100644 index 0000000..b85fb4c --- /dev/null +++ b/src/main/java/com/inspect/nvr/daHuaCarme/callback/fSnapReceiveCB.java @@ -0,0 +1,31 @@ +package com.inspect.nvr.daHuaCarme.callback; + + +import com.inspect.nvr.daHuaCarme.jna.NetSDKLib; +import com.sun.jna.Pointer; +import org.springframework.stereotype.Component; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; + +/** + * @program: standard + * @description: 抓图回调函数 + * @author: 刺客 + * @create: 2023-04-07 16:02 + */ +@Component +public class fSnapReceiveCB implements NetSDKLib.fSnapRev { + + + @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); + ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf); + + } + } +} diff --git a/src/main/java/com/inspect/nvr/domain/Infrared/Camera.java b/src/main/java/com/inspect/nvr/domain/Infrared/Camera.java index 75e8ae9..93f122d 100644 --- a/src/main/java/com/inspect/nvr/domain/Infrared/Camera.java +++ b/src/main/java/com/inspect/nvr/domain/Infrared/Camera.java @@ -1,10 +1,12 @@ package com.inspect.nvr.domain.Infrared; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; /** * 摄像头表 t_camera - * + * * @author lightiot * @date 2023-03-15 */ @@ -13,31 +15,37 @@ import lombok.*; @AllArgsConstructor public class Camera { - private String userName; + private String userName; - private String password; + private String password; - private String ip; + private String ip; - private int port; + private int port; - private int PointNum; + private int PointNum; - private int lUserID=1; + private int lUserID = 1; - private String Ulr; + private String Ulr; - private int nvrPort; + private int nvrPort; - private String nvrUserName; + private String nvrUserName; - private String nvrPassword; + private String nvrPassword; - private int channel; + private int channel; - private String status; + private String status; - private String nvrip; + private String nvrip; + + /** + * 相机类别 : 0 :hikVision + * 1 :dahua + */ + private int cameraType; } diff --git a/src/main/java/com/inspect/nvr/service/DahuaService.java b/src/main/java/com/inspect/nvr/service/DahuaService.java index 99b5a4a..c474547 100644 --- a/src/main/java/com/inspect/nvr/service/DahuaService.java +++ b/src/main/java/com/inspect/nvr/service/DahuaService.java @@ -5,10 +5,18 @@ import com.inspect.nvr.domain.Infrared.Camera; import com.inspect.nvr.domain.Infrared.NvrInfo; import com.inspect.nvr.hikVision.utils.AjaxResult; +import java.io.ByteArrayInputStream; + public interface DahuaService { AjaxResult login(NvrInfo nvrInfo); - + //大华测温 String StartRemote(Camera camera); + + //大华预置位跳转 + + String cameraControl(Camera camera,int param1,int param2,int param3); + + ByteArrayInputStream Picture(Camera camera); } diff --git a/src/main/java/com/inspect/nvr/service/impl/DahuaServiceImpl.java b/src/main/java/com/inspect/nvr/service/impl/DahuaServiceImpl.java index 21fef0d..e20d24a 100644 --- a/src/main/java/com/inspect/nvr/service/impl/DahuaServiceImpl.java +++ b/src/main/java/com/inspect/nvr/service/impl/DahuaServiceImpl.java @@ -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]; + } + } + + } diff --git a/src/main/java/com/inspect/nvr/service/impl/IvsCameraServiceImpl.java b/src/main/java/com/inspect/nvr/service/impl/IvsCameraServiceImpl.java index a1463fc..e31483f 100644 --- a/src/main/java/com/inspect/nvr/service/impl/IvsCameraServiceImpl.java +++ b/src/main/java/com/inspect/nvr/service/impl/IvsCameraServiceImpl.java @@ -8,6 +8,7 @@ import com.inspect.nvr.hikVision.utils.AjaxResult; import com.inspect.nvr.hikVision.utils.StringUtils; import com.inspect.nvr.hikVision.utils.jna.HCNetSDK; import com.inspect.nvr.hikVision.utils.jna.HikVisionUtils; +import com.inspect.nvr.service.DahuaService; import com.inspect.nvr.service.IvsCameraService; import com.inspect.nvr.utils.DateUtils; import com.inspect.nvr.utils.StringHexConverter; @@ -47,6 +48,9 @@ public class IvsCameraServiceImpl implements IvsCameraService { @Autowired private HCNetSDK hcNetSDK; + @Autowired + private DahuaService dahuaService; + @Override public IvsPresetListView ptzPresetList(String cameraCode, String domainCode) { if (testMode) { @@ -90,13 +94,15 @@ public class IvsCameraServiceImpl implements IvsCameraService { int pointNum = 210; String username = "admin"; String password = "sshw1234"; + int cameraType = 0; String[] splitArray = param.getAddress().split(":"); - if (splitArray.length == 4) { + if (splitArray.length >= 5) { log.info("PTZ_CONTROL CORRECT CONFIG"); ip = splitArray[0]; port = Integer.parseInt(splitArray[1]); channel = Integer.parseInt(splitArray[2]); pointNum = Integer.parseInt(splitArray[3]); + cameraType = Integer.parseInt(splitArray[4]); } camera.setIp(ip); @@ -106,9 +112,21 @@ public class IvsCameraServiceImpl implements IvsCameraService { camera.setChannel(channel); camera.setPointNum(pointNum); log.info("PTZ_CONTROL ip:" + ip + " port:" + port + "username:" + username + "password" + password + " channel:" + channel + " pointNum:" + pointNum); - log.info("开始登录摄像头 进行跳转预置位"); - lUserID = (Integer) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_userId"); + log.info("PTZ_CONTROL Type" + cameraType); + + + if (ObjectUtil.equals(cameraType, 1)) { + log.info("开始登录大华摄像头 进行跳转预置位"); + String ajaxResult = dahuaService.cameraControl(camera, 0, 0, 0); + + PtzControlResult ptzControlResult = PtzControlResult.builder() + .resultCode(ajaxResult) + .build(); + return ptzControlResult; + } + log.info("开始登录海康摄像头 进行跳转预置位"); + lUserID = (Integer) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_userId"); if (ObjectUtil.isEmpty(lUserID)) { NvrInfo nvrInfo = new NvrInfo(); nvrInfo.setNvrIp(camera.getIp()); @@ -218,13 +236,25 @@ public class IvsCameraServiceImpl implements IvsCameraService { cameraAddressInfos[2], cameraAddressInfos[3], cameraAddressInfos[4], - cameraAddressInfos[5]); + cameraAddressInfos[5], + cameraAddressInfos[6]); camera.setIp(cameraAddressInfos[0]); camera.setPort(Integer.parseInt(cameraAddressInfos[1])); camera.setChannel(Integer.parseInt(cameraAddressInfos[2])); camera.setPointNum(Integer.parseInt(cameraAddressInfos[3])); - camera.setUserName(cameraAddressInfos[4]); - camera.setPassword(cameraAddressInfos[5]); + camera.setCameraType(Integer.parseInt(cameraAddressInfos[4])); + camera.setUserName(cameraAddressInfos[5]); + camera.setPassword(cameraAddressInfos[6]); + + + if (ObjectUtil.equals(camera.getCameraType(), 1)){ + log.info("大华相机拍照"); + ByteArrayInputStream picture = dahuaService.Picture(camera); + + + } + + //从redis中获取lUserID(存在时间200) lUserID = (Integer) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_userId"); @@ -287,7 +317,7 @@ public class IvsCameraServiceImpl implements IvsCameraService { public AjaxResult login_V40(NvrInfo nvrInfo) { - log.info("nvrIP: "+nvrInfo.getNvrIp() + "serverPort: "+nvrInfo.getServerPort()+"account: "+nvrInfo.getAccount()+"password: "+nvrInfo.getPassword() ); + log.info("nvrIP: " + nvrInfo.getNvrIp() + "serverPort: " + nvrInfo.getServerPort() + "account: " + nvrInfo.getAccount() + "password: " + nvrInfo.getPassword()); HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = HikVisionUtils.login_V40(nvrInfo.getNvrIp(), nvrInfo.getServerPort().shortValue(), nvrInfo.getAccount(), nvrInfo.getPassword());//设备登录信息 HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息