From 38eaaa87743252da53851047bd15b089ccf9697b Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期四, 07 三月 2024 11:00:40 +0800 Subject: [PATCH] SDK云台控制和setptz增加错误码返回 增加部门和相机按角色数据权限查询 --- ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/lib/ToolKits.java | 194 ++++++++++++++++++++++++------------------------ 1 files changed, 97 insertions(+), 97 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/lib/ToolKits.java b/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/lib/ToolKits.java index cbdfe1f..a8a2d28 100644 --- a/ard-work/src/main/java/com/ruoyi/utils/sdk/dhsdk/lib/ToolKits.java +++ b/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(); } } - + // 灏哖ointer鍊艰浆涓篵yte[] - 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涓嬶紝灏咷BK String绫诲瀷鐨勮浆涓篜ointer - 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); } } -- Gitblit v1.9.3