From ef1e469fd3e885b9238bc1ef5e8d82b3a43bd55b Mon Sep 17 00:00:00 2001
From: liusuyi <13324259@qq.com>
Date: 星期三, 29 十一月 2023 20:07:29 +0800
Subject: [PATCH] 增加雷达跟踪引导上传

---
 src/main/java/com/ard/utils/other/ByteUtils.java |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/ard/utils/other/ByteUtils.java b/src/main/java/com/ard/utils/other/ByteUtils.java
index bda4b8c..0c11f68 100644
--- a/src/main/java/com/ard/utils/other/ByteUtils.java
+++ b/src/main/java/com/ard/utils/other/ByteUtils.java
@@ -30,13 +30,27 @@
      * byte鏁扮粍杞腑鏂囧瓧绗︿覆
      */
     public static String bytesToStringZh(byte[] bytes) {
-        ByteBuffer buffer = ByteBuffer.wrap(bytes); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
+        //ByteBuffer buffer = ByteBuffer.wrap(bytes); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
+        //try {
+        //    return new String(buffer.array(), "GBK");
+        //} catch (UnsupportedEncodingException e) {
+        //    e.printStackTrace();
+        //}
+        //return "";
+        String zhStr = "";
         try {
-            return new String(buffer.array(), "GBK");
+            int position = ByteUtils.findIndexOfDoubleZero(bytes);
+            if (position != -1) {
+                byte[] result = new byte[position];
+                System.arraycopy(bytes, 0, result, 0, position);
+                zhStr = new String(result, "GBK");
+            } else {
+                zhStr = new String(bytes, "GBK");
+            }
         } catch (UnsupportedEncodingException e) {
             e.printStackTrace();
         }
-        return "";
+        return zhStr;
     }
 
     /**
@@ -67,8 +81,13 @@
      * byte鏁扮粍杞暣鍨�
      */
     public static int bytesToDecimal(byte[] byteArray) {
-        ByteBuffer buffer = ByteBuffer.wrap(byteArray); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
-        return buffer.getInt();
+        //ByteBuffer buffer = ByteBuffer.wrap(byteArray); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
+        //return buffer.getInt();
+        int decimalValue = 0;
+        for (int i = 0; i < byteArray.length; i++) {
+            decimalValue = (decimalValue << 8) | (byteArray[i] & 0xFF);
+        }
+        return decimalValue;
     }
 
 

--
Gitblit v1.9.3