826220679@qq.com
18 小时以前 1bda9524add969e315d870f284046ecf1097f956
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
package dell55AAData;
 
import dell_system.MessageViewPanel;
import dell_targets.Dell_BaseStation;
import publicsWay.EfficientTimeFormatter;
 
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));
    }
 
 
 
 
}