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));
|
}
|
|
|
|
|
}
|