wu
2024-12-31 1edefcae08fe7c8df6a177e5dbbc8ab8f8194187
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package toTcp;
 
import java.util.Arrays;
 
import static java.lang.Integer.parseInt;
import static java.lang.Integer.toHexString;
 
public class gethex {
    public static byte[] hexStrToBinaryStr(String hexString) {
 
 
//        if (TextUtils.isEmpty(hexString)) {
//            return null;
//        }
 
        hexString = hexString.replaceAll(" ", "");
 
        int len = hexString.length();
        int index = 0;
 
        byte[] bytes = new byte[len / 2];
 
        while (index < len) {
 
            String sub = hexString.substring(index, index + 2);
 
            bytes[index/2] = (byte)Integer.parseInt(sub,16);
 
            index += 2;
        }
 
        //BinaryToHexString(bytes);
        return bytes;
    }
    public static String BinaryToHexString(byte[] bytes) {
        String hexStr = "0123456789ABCDEF";
        String result = "";
        String hex = "";
        for (byte b : bytes) {
            hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4));
            hex += String.valueOf(hexStr.charAt(b & 0x0F));
            result += hex + " ";
        }
      // System.out.println("------");
        //System.out.println(result);
        return result;
    }
 
    public static double toSqlElectric(String DLT645) {
        String[] data=DLT645.split(" ");
        int start = 0;
        int end = data.length - 1;
 
        while (start < end) {
            String temp = data[start];
            data[start] = data[end];
            data[end] = temp;
 
            start++;
            end--;
        }
        int num1 = Integer.parseInt("33", 16);
        String result="";
        for (int i = 2; i <6; i++) {
 
            int num2 = Integer.parseInt(data[i], 16);
            int num3 = num2 - num1 ;
            int num4=Integer.parseInt(Integer.toHexString(num3));
            result+=String.format("%02d", num4);
        }
        return Math.round(Float.valueOf(result)) * 0.01d;
    }
 
    public static void main(String[] args) {
        String DLT645="68 23 01 00 91 03 57 68 91 08 33 33 34 33 37 8A 34 33 6D 16";
        toSqlElectric(DLT645);
    }
}