Browse Source

获取海康相机预置位列表

master
wangxun 5 months ago
parent
commit
6f4eafba30
5 changed files with 139 additions and 2 deletions
  1. +36
    -0
      src/main/java/com/inspect/nvr/controller/CameraController.java
  2. +5
    -2
      src/main/java/com/inspect/nvr/domain/Infrared/Camera.java
  3. +25
    -0
      src/main/java/com/inspect/nvr/domain/camera/CameraPresetPoint.java
  4. +3
    -0
      src/main/java/com/inspect/nvr/service/HikVisionService.java
  5. +70
    -0
      src/main/java/com/inspect/nvr/service/impl/HikVisionServiceImpl.java

+ 36
- 0
src/main/java/com/inspect/nvr/controller/CameraController.java View File

@ -0,0 +1,36 @@
package com.inspect.nvr.controller;
import com.inspect.nvr.domain.Infrared.Camera;
import com.inspect.nvr.service.HikVisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@Controller
@RequestMapping
public class CameraController {
@Resource
private HikVisionService cameraService;
//获取相机预置位列表--海康相机
@PostMapping("/hw/cameraYzwHikVision")
@ResponseBody
public String cameraYzw(@RequestBody Camera camera)
{
return cameraService.cameraYzwHikVision(camera);
}
//同步相机信息
// @PostMapping("/getChannelList")
// @ResponseBody
// public AjaxResult getChannlList(@RequestBody NvrInfo nvrInfo){
// return cameraService.getChannelList(nvrInfo);
// }
}

+ 5
- 2
src/main/java/com/inspect/nvr/domain/Infrared/Camera.java View File

@ -27,8 +27,6 @@ public class Camera {
private String Ulr;
private String NvrIp;
private int nvrPort;
private String nvrUserName;
@ -37,4 +35,9 @@ public class Camera {
private int channel;
private String status;
private String nvrip;
}

+ 25
- 0
src/main/java/com/inspect/nvr/domain/camera/CameraPresetPoint.java View File

@ -0,0 +1,25 @@
package com.inspect.nvr.domain.camera;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CameraPresetPoint
{
private static final long serialVersionUID = 1L;
/** id */
private Integer id;
/** 相机预置位(预置位名称+冒号+预置位) */
private String position;
/** 相机ip */
private String cameraIp;
/** nvrIp */
private String nvrIp;
/** 相机通道号 */
private Integer channel;
}

+ 3
- 0
src/main/java/com/inspect/nvr/service/HikVisionService.java View File

@ -22,6 +22,9 @@ public interface HikVisionService {
//相机跳转到预置位
AjaxResult cameraAngleJump(Camera camera);
//相机预置位列表集合-海康相机
String cameraYzwHikVision(Camera camera);
//摄像头设备抓图
public Camera cameraPictrue(Camera camera) throws Exception;


+ 70
- 0
src/main/java/com/inspect/nvr/service/impl/HikVisionServiceImpl.java View File

@ -12,6 +12,7 @@ import com.inspect.nvr.domain.algorithm.in.AnalyseRequest;
import com.inspect.nvr.domain.algorithm.out.AnalyseResItem;
import com.inspect.nvr.domain.algorithm.out.AnalyseResPoint;
import com.inspect.nvr.domain.algorithm.out.AnalyseResult;
import com.inspect.nvr.domain.camera.CameraPresetPoint;
import com.inspect.nvr.hikVision.utils.AjaxResult;
import com.inspect.nvr.hikVision.utils.StringUtils;
import com.inspect.nvr.hikVision.utils.jna.HCNetSDK;
@ -22,6 +23,7 @@ import com.inspect.nvr.tempCount.TempCount;
import com.inspect.nvr.utils.DateUtils;
import com.inspect.nvr.utils.redis.RedisService;
import com.inspect.nvr.utils.sftp.SftpClient;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import okhttp3.*;
@ -33,6 +35,7 @@ import org.apache.commons.net.ftp.FTPSClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@ -43,6 +46,8 @@ import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -95,6 +100,10 @@ public class HikVisionServiceImpl implements HikVisionService {
// @Value("${file.produceEnvironment:true}")
private Boolean produceEnvironment = true;
@Autowired
private RedisTemplate redisTemplate;
@Resource
private SftpClient sftpClient;
@ -1145,4 +1154,65 @@ public class HikVisionServiceImpl implements HikVisionService {
return AjaxResult.success();
}
//预置位获取-海康
@Override
public String cameraYzwHikVision(Camera camera) {
CameraPresetPoint cameraPreset = new CameraPresetPoint();
int lUserID = (int) redisTemplate.opsForValue().get(camera.getNvrip() + "_userId");
HCNetSDK.NET_DVR_PRESET_NAME[] presetNames = new HCNetSDK.NET_DVR_PRESET_NAME[HCNetSDK.MAX_PRESET_V30];
for (int i = 0; i < presetNames.length; i++) {
presetNames[i] = new HCNetSDK.NET_DVR_PRESET_NAME();
presetNames[i].dwSize = presetNames[i].size();
presetNames[i].write();
}
Pointer lpOutBuffer = new Memory(presetNames.length * presetNames[0].size());
int dwOutBufferSize = presetNames.length * presetNames[0].size();
IntByReference lpBytesReturned = new IntByReference(0);
//boolean NET_DVR_GetDVRConfig(int lUserID, int dwCommand, int lChannel, Pointer lpOutBuffer, int dwOutBufferSize, IntByReference lpBytesReturned);
boolean presetList = hcNetSDK.NET_DVR_GetDVRConfig(lUserID, HCNetSDK.NET_DVR_GET_PRESET_NAME, camera.getChannel(), lpOutBuffer, dwOutBufferSize, lpBytesReturned);
if (!presetList) {
System.out.println("获取预置位数据失败,错误码:" + hcNetSDK.NET_DVR_GetLastError());
} else {
ByteBuffer byteBuffer = lpOutBuffer.getByteBuffer(0, lpBytesReturned.getValue());
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // 设置字节顺序
String presetName = "";
for (int i = 0; i < HCNetSDK.MAX_PRESET_V30; i++) {
HCNetSDK.NET_DVR_PRESET_NAME presetNameStruct = new HCNetSDK.NET_DVR_PRESET_NAME();
presetNameStruct.dwSize = byteBuffer.getInt();
presetNameStruct.wPresetNum = byteBuffer.getShort();
byteBuffer.get(presetNameStruct.byRes1); // 读取保留字节
byteBuffer.get(presetNameStruct.byName); // 读取名称
presetNameStruct.wPanPos = byteBuffer.getShort();//水平参数
presetNameStruct.wTiltPos = byteBuffer.getShort();//垂直参数
presetNameStruct.wZoomPos = byteBuffer.getShort();//变倍参数
byteBuffer.get(presetNameStruct.byRes); // 读取保留字节
if (presetNameStruct.wPresetNum != 0)
// 输出预置位数据
{
try {
if (Integer.valueOf(presetNameStruct.wPanPos) != 0 && Integer.valueOf(presetNameStruct.wTiltPos) != 0) {
presetName = presetName + new String(presetNameStruct.byName, "GBK").trim() + ":" + presetNameStruct.wPresetNum + ",";
}
System.out.println("预置位 " + presetNameStruct.wPresetNum + " 名称:" + new String(presetNameStruct.byName, "GBK").trim());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
return "";
}
}

Loading…
Cancel
Save