ard-work/src/main/java/com/ruoyi/alarm/radar/service/impl/ArdRadarServiceImpl.java
@@ -4,6 +4,7 @@ import com.ruoyi.alarm.radar.domain.ArdAlarmRadar; import com.ruoyi.alarm.radar.domain.RadarAlarmData; import com.ruoyi.alarm.radar.service.ArdRadarService; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.device.camera.domain.CameraCmd; @@ -69,12 +70,7 @@ ptzMap.put("t", t); ptzMap.put("z", cameraPTZ[2]); cmd.setPtzMap(ptzMap); boolean res = iCameraSdkService.setPtz(cmd); if (res) { log.debug("强制引导成功"); } else { log.debug("强制引导失败"); } iCameraSdkService.setPtz(cmd); } else { log.debug("未获取到雷达塔上的光电"); } @@ -127,4 +123,4 @@ log.error("雷达追踪引导异常:" + ex.getMessage()); } } } } ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
@@ -7,6 +7,7 @@ import com.ruoyi.common.constant.CameraConstants; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.device.camera.domain.CameraCmd; import com.ruoyi.device.camera.domain.DeptAndCamerasDto; import com.ruoyi.device.camera.service.IArdCamerasService; import com.ruoyi.device.camera.service.ICameraSdkService; import com.ruoyi.common.utils.poi.ExcelUtil; @@ -193,7 +194,12 @@ Map deptAndCamera = ardCamerasService.getChildDeptAndCamera(true); return AjaxResult.success(deptAndCamera); } @GetMapping("/getDeptAndCamera1") @ApiOperation("获取部门和相机1") public AjaxResult getDeptAndCamera1() { List<DeptAndCamerasDto> deptAndCamera = ardCamerasService.getChildDeptAndCamera(); return AjaxResult.success(deptAndCamera); } @GetMapping("/getDeptAndCameraWithCheckBox") @ApiOperation("获取部门和相机(开启复选框)") public AjaxResult getDeptAndCameraWithCheckBox() { ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java
@@ -94,7 +94,7 @@ public @ResponseBody AjaxResult PTZControlWithSpeed(@RequestBody CameraCmd cmd) { cmd.setOperator(SecurityUtils.getUserId()); return toAjax(cameraSdkService.pTZControl(cmd)); return cameraSdkService.pTZControl(cmd); } @ApiOperation("调用预置点") @@ -167,7 +167,7 @@ public @ResponseBody AjaxResult setPTZ(@RequestBody CameraCmd cmd) { cmd.setOperator(SecurityUtils.getUserId()); return toAjax(cameraSdkService.setPtz(cmd)); return cameraSdkService.setPtz(cmd); } @ApiOperation("指向目标") ard-work/src/main/java/com/ruoyi/device/camera/domain/DeptAndCamerasDto.java
New file @@ -0,0 +1,18 @@ package com.ruoyi.device.camera.domain; import com.ruoyi.common.core.domain.entity.SysDept; import lombok.Data; import java.util.List; /** * @Description: * @ClassName: deptAndCamerasDto * @Author: 刘苏义 * @Date: 2024年03月05日8:21:22 **/ @Data public class DeptAndCamerasDto { SysDept sysDept; List<ArdCameras> ardCamerasList; } ard-work/src/main/java/com/ruoyi/device/camera/factory/CameraSDK.java
@@ -1,5 +1,6 @@ package com.ruoyi.device.camera.factory; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.device.camera.domain.CameraCmd; import com.ruoyi.device.channel.domain.ArdChannel; @@ -26,7 +27,7 @@ boolean isOnLine(CameraCmd cmd); //云台控制 boolean pTZControl(CameraCmd cmd); AjaxResult pTZControl(CameraCmd cmd); //设置聚焦值 boolean setFocusPos(CameraCmd cmd); @@ -78,10 +79,10 @@ Map<String, Object> getPtzScope(CameraCmd cmd); //设置ptz1(不支持2通道的Z值设置和获取) boolean setPtz1(CameraCmd cmd); AjaxResult setPtz1(CameraCmd cmd); //设置ptz(高精度ptz设置) boolean setPtz(CameraCmd cmd); AjaxResult setPtz(CameraCmd cmd); //设置零方位角 boolean setZeroPtz(CameraCmd cmd); ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
@@ -8,19 +8,20 @@ import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.device.camera.domain.CameraCmd; import com.ruoyi.device.camera.domain.DeptAndCamerasDto; import com.ruoyi.scheduling.domian.SchedulingParam; /** * 相机设备Service接口 * * * @author 刘苏义 * @date 2023-02-11 */ public interface IArdCamerasService public interface IArdCamerasService { /** * 查询相机设备 * * * @param id 相机设备主键 * @return 相机设备 */ @@ -28,7 +29,7 @@ /** * 查询相机设备列表 * * * @param ardCameras 相机设备 * @return 相机设备集合 */ @@ -42,7 +43,7 @@ public List<ArdCameras> selectArdCamerasListNoDataScope(ArdCameras ardCameras); /** * 新增相机设备 * * * @param ardCameras 相机设备 * @return 结果 */ @@ -50,7 +51,7 @@ /** * 修改相机设备 * * * @param ardCameras 相机设备 * @return 结果 */ @@ -58,7 +59,7 @@ /** * 批量删除相机设备 * * * @param ids 需要删除的相机设备主键集合 * @return 结果 */ @@ -66,7 +67,7 @@ /** * 删除相机设备信息 * * * @param id 相机设备主键 * @return 结果 */ @@ -106,7 +107,7 @@ * @修改人和其它信息 */ public Map getChildDeptAndCamera(Boolean disabled); public List<DeptAndCamerasDto> getChildDeptAndCamera(); public TreeMap getNearCamerasBycoordinate(CameraCmd cmd); ard-work/src/main/java/com/ruoyi/device/camera/service/ICameraSdkService.java
@@ -19,7 +19,7 @@ boolean isOnLine(CameraCmd cmd); //云台控制 boolean pTZControl(CameraCmd cmd); AjaxResult pTZControl(CameraCmd cmd); //设置聚焦值 boolean setFocusPos(CameraCmd cmd); @@ -76,7 +76,7 @@ Map<String, Object> getPtzScope(CameraCmd cmd); //设置ptz boolean setPtz(CameraCmd cmd); AjaxResult setPtz(CameraCmd cmd); //设置零方位角 boolean setZeroPtz(CameraCmd cmd); ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -17,10 +17,12 @@ import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.device.camera.domain.CameraCmd; import com.ruoyi.device.camera.domain.DeptAndCamerasDto; import com.ruoyi.device.channel.domain.ArdChannel; import com.ruoyi.device.channel.mapper.ArdChannelMapper; import com.ruoyi.media.service.IVtduService; import com.ruoyi.scheduling.domian.SchedulingParam; import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.utils.gis.GisUtil; import com.ruoyi.utils.tools.ArdTool; import com.ruoyi.device.camera.domain.ArdCameras; @@ -52,7 +54,8 @@ private SysDeptMapper sysDeptMapper; @Resource private RedisCache redisCache; @Autowired private ISysDeptService deptService; @Resource private ArdChannelMapper ardChannelMapper; @Resource @@ -306,7 +309,6 @@ * @创建时间 2023/6/2 10:58 * @修改人和其它信息 */ @Override public Map getChildDeptAndCamera(Boolean disabled) { Long deptId = SecurityUtils.getDeptId(); @@ -315,6 +317,11 @@ return map; } @Override public List<DeptAndCamerasDto> getChildDeptAndCamera() { List<SysDept> depts = deptService.selectDeptList(new SysDept()); return fetchChildDepartments(depts); } /** * @描述 递归查询 * @参数 [sysDept] @@ -354,7 +361,26 @@ } map.put("children", childList); return map; } /** * 获取所有部门及部门下的相机 * 刘苏义 * 2024/3/4 14:45:03 */ public List<DeptAndCamerasDto> fetchChildDepartments(List<SysDept> sysDepts) { List<DeptAndCamerasDto> deptAndCamerasList = sysDepts.stream() .map(sysDept -> { List<ArdCameras> ardCameras = ardCamerasMapper.selectArdCamerasByDeptId(sysDept.getDeptId()); DeptAndCamerasDto deptAndCamerasDto = new DeptAndCamerasDto(); deptAndCamerasDto.setSysDept(sysDept); deptAndCamerasDto.setArdCamerasList(ardCameras); return deptAndCamerasDto; }) .collect(Collectors.toList()); return deptAndCamerasList; } /** ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java
@@ -130,20 +130,15 @@ //云台控制 @Override public boolean pTZControl(CameraCmd cmd) { try { boolean result = false; String cameraId = cmd.getCameraId(); ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); if (ardCamera != null) { String factory = ardCamera.getFactory(); CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); result = cameraSDK.pTZControl(cmd); } return result; } catch (Exception ex) { log.error("ptz控制异常:" + ex.getMessage()); return false; public AjaxResult pTZControl(CameraCmd cmd) { String cameraId = cmd.getCameraId(); ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); if (ardCamera != null) { String factory = ardCamera.getFactory(); CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); return cameraSDK.pTZControl(cmd); } else { return AjaxResult.error("摄像头不存在"); } } @@ -403,9 +398,7 @@ String gdtype = ardCamera.getGdtype(); if (gdtype.equals("1")) { map = cameraSDK.getPtz(cmd); } else { } else { map = cameraSDK.getPtz1(cmd); } } @@ -435,27 +428,27 @@ //设置ptz @Override public boolean setPtz(CameraCmd cmd) { boolean result = false; public AjaxResult setPtz(CameraCmd cmd) { try { String cameraId = cmd.getCameraId(); ArdCameras ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); if (ardCamera != null) { String factory = ardCamera.getFactory(); CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory); String gdtype = ardCamera.getGdtype(); if (gdtype.equals("1")) { //大光电使用高精度ptz设置 result = cameraSDK.setPtz(cmd); } else { result = cameraSDK.setPtz1(cmd); } if (ardCamera == null) { return AjaxResult.error("摄像头不存在"); } CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(ardCamera.getFactory()); String gdtype = ardCamera.getGdtype(); if (gdtype.equals("1")) { //大光电使用高精度ptz设置 return cameraSDK.setPtz(cmd); } else { return cameraSDK.setPtz1(cmd); } } catch (Exception ex) { log.error("设置ptz异常:" + ex.getMessage()); AjaxResult.error("设置ptz异常:" + ex.getMessage()); } return result; return AjaxResult.success(); } //设置零方位角 @@ -529,8 +522,7 @@ cmd.setCameraId(cameraId); //获取最近相机的对象 Optional<ArdWellGuideCamera> first = ardWellGuideCameraList.stream().filter(s -> s.getCameraId().equals(cameraId)).findFirst(); if(first.isPresent()) { if (first.isPresent()) { ArdWellGuideCamera ardWellGuideCamera = first.get(); Map<String, Double> ptzMap = null; //通过通道获取预置位 @@ -557,11 +549,7 @@ if (ptzMap != null) { //使用ptz引导 cmd.setPtzMap(ptzMap); boolean res = setPtz(cmd); if (!res) { return AjaxResult.error("ptz引导失败", "cameraId:" + cameraId); } return AjaxResult.success("ptz引导成功", "cameraId:" + cameraId); return setPtz(cmd); } } ard-work/src/main/java/com/ruoyi/utils/sdk/common/SdkErrorCodeEnum.java
New file @@ -0,0 +1,73 @@ package com.ruoyi.utils.sdk.common; import com.ruoyi.common.utils.StringUtils; /** * sdk错误码枚举 * 刘苏义 * 2024/3/7 10:50:52 */ public enum SdkErrorCodeEnum { NET_DVR_PASSWORD_ERROR(1, "用户名密码错误。注册时输入的用户名或者密码错误"), NET_DVR_NOINIT(3, "SDK未初始化"), NET_DVR_NETWORK_FAIL_CONNECT(7, "连接设备失败。设备不在线或网络原因引起的连接超时等"); /** * 枚举码 */ private Integer code; /** * 枚举描述 */ private String desc; private SdkErrorCodeEnum(Integer code, String desc) { this.code = code; this.desc = desc; } public Integer getCode() { return code; } public String getDesc() { return desc; } /** * 根据枚举码获取枚举 * * @param code 枚举码 * @return 枚举 */ public static final SdkErrorCodeEnum getByCode(Integer code) { if (StringUtils.isNull(code)) { return null; } for (SdkErrorCodeEnum item : SdkErrorCodeEnum.values()) { if (item.getCode() == code) { return item; } } return null; } /** * 根据枚举码获取枚举描述 * * @param code 枚举码 * @return 枚举描述 */ public static final String getDescByCode(Integer code) { if (StringUtils.isNull(code)) { return "错误码为空"; } for (SdkErrorCodeEnum item : SdkErrorCodeEnum.values()) { if (item.getCode() == code) { return item.getDesc(); } } return "找不到错误码对应的错误描述,请联系管理员"; } } ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/controller/DhSdkController.java
@@ -47,7 +47,7 @@ public @ResponseBody AjaxResult pTZControl(@RequestBody CameraCmd cmd) { cmd.setOperator(SecurityUtils.getUserId()); return toAjax(sdk.pTZControl(cmd)); return sdk.pTZControl(cmd); } @ApiOperation("获取PTZ") @@ -79,7 +79,7 @@ public @ResponseBody AjaxResult setPTZ(@RequestBody CameraCmd cmd) { cmd.setOperator(SecurityUtils.getUserId()); return toAjax(sdk.setPtz(cmd)); return sdk.setPtz(cmd); } @ApiOperation("设置零方位角") @@ -124,4 +124,4 @@ String url = sdk.recordStopToMinio(cmd); return AjaxResult.success(url); } } } ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/lib/ToolKits.java
@@ -32,7 +32,7 @@ public class ToolKits { static NetSDKLib netsdkapi = NetSDKLib.NETSDK_INSTANCE; static NetSDKLib configapi = NetSDKLib.CONFIG_INSTANCE; /*************************************************************************************************** * 工具方法 * ***************************************************************************************************/ @@ -48,7 +48,7 @@ pJavaStu.size()); pJavaStu.read(); } public static void GetPointerDataToStructArr(Pointer pNativeData, Structure []pJavaStuArr) { long offset = 0; for (int i=0; i<pJavaStuArr.length; ++i) @@ -57,10 +57,10 @@ offset += pJavaStuArr[i].size(); } } /** * 将结构体数组拷贝到内存 * @param pNativeData * @param pNativeData * @param pJavaStuArr */ public static void SetStructArrToPointerData(Structure []pJavaStuArr, Pointer pNativeData) { @@ -70,41 +70,41 @@ offset += pJavaStuArr[i].size(); } } public static void SetStructDataToPointer(Structure pJavaStu, Pointer pNativeData, long OffsetOfpNativeData){ pJavaStu.write(); Pointer pJavaMem = pJavaStu.getPointer(); pNativeData.write(OffsetOfpNativeData, pJavaMem.getByteArray(0, pJavaStu.size()), 0, pJavaStu.size()); } public static void savePicture(byte[] pBuf, String sDstFile) throws IOException { FileOutputStream fos=null; try { fos = new FileOutputStream(sDstFile); fos.write(pBuf); fos.write(pBuf); } catch (Exception e){ e.printStackTrace(); }finally{ fos.close(); fos.close(); } } public static void savePicture(byte[] pBuf, int dwBufOffset, int dwBufSize, String sDstFile) throws IOException { FileOutputStream fos=null; try { { fos = new FileOutputStream(sDstFile); fos.write(pBuf, dwBufOffset, dwBufSize); } catch (Exception e){ e.printStackTrace(); }finally{ fos.close(); fos.close(); } } public static void savePicture(Pointer pBuf, int dwBufSize, String sDstFile) throws IOException { FileOutputStream fos=null; @@ -115,10 +115,10 @@ } catch (Exception e){ e.printStackTrace(); }finally{ fos.close(); fos.close(); } } public static void savePicture(Pointer pBuf, int dwBufOffset, int dwBufSize, String sDstFile) throws IOException { FileOutputStream fos=null; @@ -129,12 +129,12 @@ } catch (Exception e){ e.printStackTrace(); }finally{ fos.close(); fos.close(); } } // 将Pointer值转为byte[] public static String GetPointerDataToByteArr(Pointer pointer) { public static String GetPointerDataToByteArr(Pointer pointer) { String str = ""; if(pointer == null) { return str; @@ -143,14 +143,14 @@ int length = 0; byte[] bufferPlace = new byte[1]; for(int i = 0; i < 2048; i++) { pointer.read(i, bufferPlace, 0, 1); for(int i = 0; i < 2048; i++) { pointer.read(i, bufferPlace, 0, 1); if(bufferPlace[0] == '\0') { length = i; break; } } if(length > 0) { byte[] buffer = new byte[length]; pointer.read(0, buffer, 0, length); @@ -159,58 +159,58 @@ } catch (UnsupportedEncodingException e) { return str; } } } return str; } // 获取当前时间 public static String getDate() { SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = simpleDate.format(new java.util.Date()).replace(" ", "_").replace(":", "-"); return date; } // 获取当前时间 public static String getDay() { SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd"); String date = simpleDate.format(new java.util.Date()); String date = simpleDate.format(new java.util.Date()); return date; } // 限制JTextField 长度,以及内容 public static void limitTextFieldLength(final JTextField jTextField, final int size) { jTextField.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { String number = "0123456789" + (char)8; public void keyTyped(KeyEvent e) { String number = "0123456789" + (char)8; if(number.indexOf(e.getKeyChar()) < 0 || jTextField.getText().trim().length() >= size) { e.consume(); return; } } } @Override public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) { } }); } // 获取当前窗口 public static JFrame getFrame(ActionEvent e) { JButton btn = (JButton)e.getSource(); JFrame frame = (JFrame)btn.getRootPane().getParent(); return frame; } // 获取操作平台信息 public static String getLoadLibrary(String library) { String path = ""; @@ -223,7 +223,7 @@ return (path + library); } public static String getOsName() { String osName = ""; String os = System.getProperty("os.name"); @@ -232,10 +232,10 @@ } else if(os.toLowerCase().startsWith("linux")) { osName = "linux"; } return osName; } /** * 读取图片大小 * @param filePath 图片路径 @@ -251,13 +251,13 @@ return 0; } } /** * 读取图片数据 * @param file 图片路径 * @param memory 图片数据缓存 * @param memory 图片数据缓存 * @return * @throws IOException * @throws IOException */ public static boolean ReadAllFileToMemory(String file, Memory memory) throws IOException { if (memory != Memory.NULL) @@ -273,7 +273,7 @@ if (infile.canRead()) { in = new FileInputStream(infile); int buffLen = 1024; int buffLen = 1024; byte[] buffer = new byte[buffLen]; long currFileLen = 0; int readLen = 0; @@ -282,7 +282,7 @@ readLen = in.read(buffer); memory.write(currFileLen, buffer, 0, readLen); currFileLen += readLen; } } return true; } else @@ -297,17 +297,17 @@ }finally{ if(in!=null){ in.close(); } } } } return false; } static class JPGFilter extends FileFilter { public boolean accept(File f) { if(f.getName().toLowerCase().endsWith(".JPG") || f.getName().toLowerCase().endsWith(".jpg") || f.getName().toLowerCase().endsWith(".jpg") || f.isDirectory()) { return true; } @@ -319,19 +319,19 @@ return "*.jpg; *.JPG"; } } /* * 用选择器选择图片, 获取图片路径,并在界面显示 */ public static String openPictureFile(PaintPanel paintPanel) { public static String openPictureFile(PaintPanel paintPanel) { try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception e) { e.printStackTrace(); } } String picPath = ""; // 读取图片 JFileChooser jfc = new JFileChooser("d:/"); jfc.setMultiSelectionEnabled(false); // 不可以拖选多个文件 @@ -341,10 +341,10 @@ JPGFilter filter = new JPGFilter(); jfc.addChoosableFileFilter(filter); jfc.setFileFilter(filter); if( jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { picPath = jfc.getSelectedFile().getAbsolutePath(); /* * 读取本地图片, 并在面板上显示 */ @@ -352,22 +352,22 @@ if(picPath == null || picPath.equals("")) { return ""; } File file = new File(picPath); if(!file.exists()) { return ""; } try { bufferedImage = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); } if(bufferedImage == null) { paintPanel.setOpaque(true); paintPanel.repaint(); System.err.println("打开图片失败,请重新选择!"); return ""; } else { @@ -376,19 +376,19 @@ paintPanel.repaint(); } } try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } } return picPath; } /* * 传入图片路径, 打开图片, 并在面板显示 */ public static File openPictureFile(String picPath, PaintPanel paintPanel) { public static File openPictureFile(String picPath, PaintPanel paintPanel) { /* * 读取本地图片, 并在面板上显示 */ @@ -396,22 +396,22 @@ if(picPath == null || picPath.equals("")) { return null; } File file = new File(picPath); if(!file.exists()) { return null; } try { bufferedImage = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); } if(bufferedImage == null) { paintPanel.setOpaque(true); paintPanel.repaint(); System.err.println("打开图片失败,请重新选择!"); return null; } else { @@ -419,24 +419,24 @@ paintPanel.setImage(bufferedImage); paintPanel.repaint(); } return file; } /** * 读取图片 * @return 图片缓存 * @throws IOException * @throws IOException */ public static Memory readPictureFile(String picPath) throws IOException { int nPicBufLen = 0; Memory memory = null; /* * 读取本地图片大小 */ nPicBufLen = (int)ToolKits.GetFileSize(picPath); nPicBufLen = (int)ToolKits.GetFileSize(picPath); // 读取文件大小失败 if (nPicBufLen <= 0) { System.err.println("读取图片大小失败,请重新选择!"); @@ -448,46 +448,46 @@ */ memory = new Memory(nPicBufLen); // 申请缓存 memory.clear(); if (!ToolKits.ReadAllFileToMemory(picPath, memory)) { System.err.println("读取图片数据,请重新选择!"); return null; } return memory; } /** * 登录设备设备错误状态, 用于界面显示 */ public static String getErrorCodeShow() { return ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()); } /** * 获取接口错误码和错误信息,用于打印 * @return */ public static String getErrorCodePrint() { return "\n{error code: (0x80000000|" + (LoginModule.netsdk.CLIENT_GetLastError() & 0x7fffffff) +").参考 NetSDKLib.java }" + " - {error info:" + ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()) + "}\n"; return "Error Code: (0x80000000|" + (LoginModule.netsdk.CLIENT_GetLastError() & 0x7fffffff) +")" + " Error Info:" + ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError()) + ""; } /** * 获取单个配置 * @param hLoginHandle 登陆句柄 * @param nChn 通道号,-1 表示全通道 * @param strCmd 配置名称 * @param cmdObject 配置对应的结构体对象 * @return 成功返回 true * @return 成功返回 true */ public static boolean GetDevConfig(LLong hLoginHandle, int nChn, String strCmd, Structure cmdObject) { boolean result = false; IntByReference error = new IntByReference(0); int nBufferLen = 2*1024*1024; byte[] strBuffer = new byte[nBufferLen]; if(netsdkapi.CLIENT_GetNewDevConfig( hLoginHandle, strCmd , nChn, strBuffer, nBufferLen,error,3000)) { if(netsdkapi.CLIENT_GetNewDevConfig( hLoginHandle, strCmd , nChn, strBuffer, nBufferLen,error,3000)) { cmdObject.write(); if (configapi.CLIENT_ParseData(strCmd, strBuffer, cmdObject.getPointer(), cmdObject.size(), null)) { @@ -501,10 +501,10 @@ System.err.printf("Get %s Config Failed!Last Error = %s\n" , strCmd , getErrorCodePrint()); result = false; } return result; } /** * 设置单个配置 * @param hLoginHandle 登陆句柄 @@ -519,11 +519,11 @@ byte szBuffer[] = new byte[nBufferLen]; for(int i=0; i<nBufferLen; i++)szBuffer[i]=0; IntByReference error = new IntByReference(0); IntByReference restart = new IntByReference(0); IntByReference restart = new IntByReference(0); cmdObject.write(); if (configapi.CLIENT_PacketData(strCmd, cmdObject.getPointer(), cmdObject.size(), szBuffer, nBufferLen)) { szBuffer, nBufferLen)) { cmdObject.read(); if( netsdkapi.CLIENT_SetNewDevConfig(hLoginHandle, strCmd , nChn , szBuffer, nBufferLen, error, restart, 3000)) { result = true; @@ -535,38 +535,38 @@ System.err.println("Packet " + strCmd + " Config Failed!" + getErrorCodePrint()); result = false; } return result; } // Win下,将GBK String类型的转为Pointer public static Pointer GetGBKStringToPointer(String src) { public static Pointer GetGBKStringToPointer(String src) { Pointer pointer = null; try { byte[] b = src.getBytes("GBK"); pointer = new Memory(b.length+1); pointer.clear(b.length+1); pointer.write(0, b, 0, b.length); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return pointer; } /** * 字符串拷贝,用于先获取,再设置(src → dst) * @param src * @param src * @param dst */ public static void StringToByteArray(String src, byte[] dst) { for(int i = 0; i < dst.length; i++) { dst[i] = 0; } System.arraycopy(src.getBytes(), 0, dst, 0, src.getBytes().length); } /** * 数组拷贝, 用于先获取,再设置(src → dst) * @param src @@ -576,7 +576,7 @@ for(int i = 0; i < dst.length; i++) { dst[i] = 0; } System.arraycopy(src, 0, dst, 0, src.length); } } ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/service/impl/DahuaSDK.java
@@ -4,6 +4,7 @@ import com.ruoyi.alarm.global.domain.GuideTask; import com.ruoyi.alarm.global.service.impl.QueueHandler; import com.ruoyi.common.annotation.SdkOperate; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.file.MimeTypeUtils; import com.ruoyi.common.utils.spring.SpringUtils; @@ -19,6 +20,7 @@ import com.ruoyi.utils.gis.GisUtil; import com.ruoyi.utils.minio.MinioUtil; import com.ruoyi.utils.sdk.common.GlobalVariable; import com.ruoyi.utils.sdk.dhsdk.common.ErrorCode; import com.ruoyi.utils.sdk.dhsdk.lib.NetSDKLib; import com.ruoyi.utils.sdk.dhsdk.lib.enumeration.EM_NEW_CONFIG; import com.ruoyi.utils.sdk.dhsdk.lib.enumeration.NET_EM_CFG_OPERATE_TYPE; @@ -317,14 +319,14 @@ */ @Override @SdkOperate public boolean pTZControl(CameraCmd cmd) { public AjaxResult pTZControl(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); Integer chanNo = cmd.getChanNo(); Integer speed = cmd.getSpeed(); Integer code = cmd.getCode(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; return AjaxResult.error("设备未登录"); } NetSDKLib.LLong loginId = (NetSDKLib.LLong) GlobalVariable.loginMap.get(cameraId); int dwStop; @@ -391,8 +393,9 @@ boolean bool = PtzControlModule.ptzControl(loginId, chanNo - 1, dwPTZCommand, speed, speed, 0, dwStop); if (!bool) { log.error("控制失败,请稍后重试" + getErrorCodePrint()); return AjaxResult.error(ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError())); } return bool; return AjaxResult.success(); } /** @@ -429,7 +432,7 @@ } @Override public boolean setPtz1(CameraCmd cmd) { public AjaxResult setPtz1(CameraCmd cmd) { return setPtz(cmd) ; } @@ -443,12 +446,12 @@ */ @Override @SdkOperate public boolean setPtz(CameraCmd cmd) { public AjaxResult setPtz(CameraCmd cmd) { String cameraId = cmd.getCameraId(); Integer chanNo = cmd.getChanNo(); Map<String, Double> ptz = cmd.getPtzMap(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; return AjaxResult.error("设备未登录"); } LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId); try { @@ -460,11 +463,12 @@ boolean bool = netsdk.CLIENT_DHPTZControlEx(loginId, chanNo - 1, NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_EXACTGOTO, p, t, z, 0); if (!bool) { log.error("控制失败,请稍后重试" + getErrorCodePrint()); return AjaxResult.error(ErrorCode.getErrorCode(LoginModule.netsdk.CLIENT_GetLastError())); } return bool; return AjaxResult.success(); } catch (Exception ex) { log.error(ex.getMessage()); return false; return AjaxResult.error(ex.getMessage()); } } ard-work/src/main/java/com/ruoyi/utils/sdk/hiksdk/controller/HikSdkController.java
@@ -85,7 +85,7 @@ public @ResponseBody AjaxResult PTZControlWithSpeed(@RequestBody CameraCmd cmd) { cmd.setOperator(SecurityUtils.getUserId()); return toAjax(sdk.pTZControl(cmd)); return sdk.pTZControl(cmd); } @ApiOperation("调用预置点") @@ -158,7 +158,7 @@ public @ResponseBody AjaxResult setPTZ(@RequestBody CameraCmd cmd) { cmd.setOperator(SecurityUtils.getUserId()); return toAjax(sdk.setPtz(cmd)); return sdk.setPtz(cmd); } @ApiOperation("指向目标") ard-work/src/main/java/com/ruoyi/utils/sdk/hiksdk/service/impl/HikvisionSDK.java
@@ -4,6 +4,7 @@ import com.ruoyi.alarm.global.domain.GuideTask; import com.ruoyi.alarm.global.service.impl.QueueHandler; import com.ruoyi.common.annotation.SdkOperate; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.file.MimeTypeUtils; import com.ruoyi.common.utils.spring.SpringUtils; @@ -19,6 +20,7 @@ import com.ruoyi.utils.gis.GisUtil; import com.ruoyi.utils.minio.MinioUtil; import com.ruoyi.utils.sdk.common.GlobalVariable; import com.ruoyi.utils.sdk.common.SdkErrorCodeEnum; import com.ruoyi.utils.sdk.hiksdk.lib.ExceptionCallBack; import com.ruoyi.utils.sdk.hiksdk.lib.HCNetSDK; import com.sun.jna.NativeLong; @@ -220,7 +222,10 @@ //同步登录 int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo); if (lUserID < 0) { log.debug("Login Failed 【 " + camera.getIp() + ":" + camera.getPort() + " 】,Error Code:" + hCNetSDK.NET_DVR_GetLastError()); int errorCode = hCNetSDK.NET_DVR_GetLastError(); log.debug("Login Failed 【 " + camera.getIp() + ":" + camera.getPort() + " 】," + "Error Code:" + errorCode + " " + "Error Info:" + SdkErrorCodeEnum.getDescByCode(errorCode)); camera.setChanNum(0); camera.setLoginId(-1); camera.setState("0"); @@ -376,14 +381,14 @@ */ @Override @SdkOperate public boolean pTZControl(CameraCmd cmd) { public AjaxResult pTZControl(CameraCmd cmd) { String cameraId = cmd.getCameraId(); boolean enable = cmd.isEnable(); Integer channelNum = cmd.getChanNo(); Integer speed = cmd.getSpeed(); Integer code = cmd.getCode(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; return AjaxResult.error("相机未登录"); } Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId); int dwStop; @@ -452,8 +457,9 @@ if (!bool) { int errorCode = hCNetSDK.NET_DVR_GetLastError(); log.error("控制失败,请稍后重试" + errorCode); return AjaxResult.error("errorCode:" + errorCode + "errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode)); } return bool; return AjaxResult.success(); } /** @@ -992,12 +998,12 @@ */ @Override @SdkOperate public boolean setPtz1(CameraCmd cmd) { public AjaxResult setPtz1(CameraCmd cmd) { String cameraId = cmd.getCameraId(); Integer channelNum = cmd.getChanNo(); Map<String, Double> ptz = cmd.getPtzMap(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; return AjaxResult.error("设备未登录"); } Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId); NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS(); @@ -1013,13 +1019,14 @@ m_ptzPosCurrent.write(); boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_PTZPOS, channelNum, point, m_ptzPosCurrent.size()); if (!bool) { int code = hCNetSDK.NET_DVR_GetLastError(); log.error("设置PTZ参数失败,请稍后重试:" + code); int errorCode = hCNetSDK.NET_DVR_GetLastError(); log.error("设置PTZ参数失败,请稍后重试:" + errorCode); return AjaxResult.error("errorCode:" + errorCode + "errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode)); } return bool; return AjaxResult.success(); } catch (Exception ex) { log.error(ex.getMessage()); return false; return AjaxResult.error("设置PTZ参数异常:" + ex.getMessage()); } } @@ -1033,13 +1040,13 @@ */ @Override @SdkOperate public boolean setPtz(CameraCmd cmd) { public AjaxResult setPtz(CameraCmd cmd) { try { String cameraId = cmd.getCameraId(); Integer chanNo = cmd.getChanNo(); Map<String, Double> ptz = cmd.getPtzMap(); if (!GlobalVariable.loginMap.containsKey(cameraId)) { return false; return AjaxResult.error("设备未登录"); } Integer lUserID = (Integer) GlobalVariable.loginMap.get(cameraId); IntByReference pchannel = new IntByReference(chanNo); @@ -1071,14 +1078,15 @@ lpConfigParam6697.write(); boolean bool = hCNetSDK.NET_DVR_SetSTDConfig(lUserID, NET_DVR_SET_PTZABSOLUTEEX, lpConfigParam6697); if (!bool) { int code = hCNetSDK.NET_DVR_GetLastError(); log.error("设置高精度PTZ参数失败,请稍后重试:" + code); int errorCode = hCNetSDK.NET_DVR_GetLastError(); log.error("设置高精度PTZ参数失败,请稍后重试:" + errorCode); return AjaxResult.error("errorCode:" + errorCode + "errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode)); } return bool; return AjaxResult.success(); } catch (Exception ex) { log.error("设置高精度PTZ参数异常", ex); return false; return AjaxResult.error("设置高精度PTZ参数异常:" + ex); } }