| | |
| | | package dell55AAData; |
| | | |
| | | import dell_system.MessageViewPanel; |
| | | |
| | | public class Dell55AA12HighPerf { |
| | | |
| | | // 协议常量 |
| | |
| | | private static final int MIN_LENGTH = 34; // 最小数据长度 |
| | | private static final ThreadLocal<ParseResult> RESULT_CACHE = // 解析结果缓存 |
| | | ThreadLocal.withInitial(ParseResult::new); |
| | | // 重用StringBuilder减少内存分配 |
| | | private static final ThreadLocal<StringBuilder> hexDataBuilder = |
| | | ThreadLocal.withInitial(() -> new StringBuilder(64)); |
| | | |
| | | // 解析结果类 |
| | | public static class ParseResult { |
| | |
| | | * @param message 原始16进制字符串 |
| | | * @return 解析结果对象(线程安全) |
| | | */ |
| | | public static ParseResult parse(String message) { |
| | | public static ParseResult parse(String message,String ip,int port) { |
| | | // 长度校验 |
| | | if (message == null || message.length() < MIN_LENGTH) { |
| | | return null; |
| | |
| | | // 解析锚点信息 |
| | | parseAnchorInfo(chars, result); |
| | | |
| | | if (MessageViewPanel.isWindowVisible) { |
| | | // 组装基站信息 |
| | | StringBuilder ids = new StringBuilder(); |
| | | StringBuilder dists = new StringBuilder(); |
| | | StringBuilder powers = new StringBuilder(); |
| | | for (int i = 0; i < result.anchorCount; i++) { |
| | | if (i > 0) { |
| | | ids.append(','); |
| | | dists.append(','); |
| | | powers.append(','); |
| | | } |
| | | ids.append(result.anchorIds[i]); |
| | | dists.append(result.distances[i]); |
| | | powers.append(result.anchorPowers[i]); |
| | | } |
| | | StringBuilder sb = hexDataBuilder.get(); |
| | | sb.append("55AA12 ,Seq:").append(result.sequenceNum) |
| | | .append(",Tagid:").append(result.tagId) |
| | | .append(",Power: ").append(result.power).append("%") |
| | | .append(",button:").append(result.sosButtonPressed) |
| | | .append(",Static:").append(result.isStatic ) |
| | | .append(",Sleep:").append(result.isSleeping ) |
| | | .append(",State:").append(result.vibrationState ) |
| | | .append(",TagRemoved:").append(result.tagRemoved) |
| | | .append(",TagHeight:").append(result.tagHeight) |
| | | .append(",AncNum:").append(result.anchorCount) |
| | | .append(",AncIds:[").append(ids) |
| | | .append("],Dis:[").append(dists) |
| | | .append("],AncPowers:[").append(powers).append("]").append('\n'); |
| | | MessageViewPanel.showData(sb.toString(), ip, port, 0, "UDPA", "55AA12",result.tagId); |
| | | } |
| | | return result; |
| | | } |
| | | |