zsh_root
2025-12-10 8d662de2fd262b3a485f16e197cb4d0ca2a61cdf
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
package jiexi;
 
 
 
public class Dell55AA02Parser {
    private static final int SYNC_STATUS_START = 12;  // 同步状态起始位置(第5字节)
    private static final int PRESSURE_START = 14;     // 气压值起始位置(第6字节)
    private static final int MIN_MESSAGE_LENGTH = 22; // 最小有效数据长度
 
    // 重用StringBuilder减少内存分配
    private static final ThreadLocal<StringBuilder> hexDataBuilder = 
            ThreadLocal.withInitial(() -> new StringBuilder(64));
 
    /**
     * 高效解析55AA02格式的基站数据
     * @param message 接收到的数据(十六进制字符串)
     */
    public static void parse(String message, String ip, int port) {
        // 1. 基础校验
        if (message == null || message.length() < MIN_MESSAGE_LENGTH) {
            return;
        }
 
        // 2. 解析标签ID (位置8-11, 小端序)
        char c8 = message.charAt(8);
        char c9 = message.charAt(9);
        char c10 = message.charAt(10);
        char c11 = message.charAt(11);
 
        // 直接构建baseId字符串
        String baseId = new String(new char[]{c10, c11, c8, c9});
 
        // 3. 解析同步状态(1字节)
        char syncStatusChar = message.charAt(SYNC_STATUS_START + 1);
        String syncStatus = (syncStatusChar == '0') ? "0" : "1";
 
        // 4. 高效解析气压值(4字节小端序)
        int pressure = 0;
        for (int i = 0; i < 8; i += 2) {
            int idx = PRESSURE_START + i;
            // 使用HexUtils的快速转换方法
            int byteValue = HexUtils.fastHexToByte(message.charAt(idx), message.charAt(idx + 1));
            pressure |= (byteValue << (i * 4)); // 小端合并
        }
 
 
        /*// 5. 更新基站数据
        if (MessageViewPanel.isWindowVisible) {
            StringBuilder sb = hexDataBuilder.get();
            sb.setLength(0);
            sb.append("55AA02 AnchorHeart,Anchorid:")
            .append(baseId)
            .append(",SyncStatus:")
            .append(syncStatus)
            .append(",Pressure:")
            .append(pressure);
            MessageViewPanel.showData(sb.toString(), ip, port, 0, "UDPA", "55AA02", baseId);
        }
 
        // 延迟创建时间字符串直到必要时刻
        String time = EfficientTimeFormatter.getCurrentTimeFormatted();
 
        // 使用预分配字符串常量减少内存分配
        Dell_BaseStation.updateBaseStationProperty(baseId, "ipAddress", ip);
        Dell_BaseStation.updateBaseStationProperty(baseId, "port", Integer.toString(port));
        Dell_BaseStation.updateBaseStationProperty(baseId, "status", "1");
        Dell_BaseStation.updateBaseStationProperty(baseId, "onlineTime", time);
        Dell_BaseStation.updateBaseStationProperty(baseId, "syncStatus", syncStatus);
        Dell_BaseStation.updateBaseStationProperty(baseId, "barometerReading", Integer.toString(pressure));*/
    }
 
 
 
 
}