826220679@qq.com
4 天以前 487a5b943571d6ab57c4baddca1cbcc7b2062e73
src/home/AOAFollowSystem.java
@@ -110,6 +110,12 @@
      case "ascii": return "ASCII";
      case "hex_send": return "HEX发送";
      case "display_format": return "显示格式";
      case "pair_tooltip":
          return currentLocale.equals(Locale.SIMPLIFIED_CHINESE) ?
                 "点击发送后进入20秒配对模式" :
                 "Enter 20-second pairing mode after clicking send";
      case "scale":
            return currentLocale.equals(Locale.SIMPLIFIED_CHINESE) ? "缩放" : "Scale";
      default: return key;
      }
   }
@@ -188,7 +194,10 @@
      // 更新各面板文本
      homePanel.updateLanguage();
      configPanel.updateLanguage();
       // 更新配对复选框的提示信息
       homePanel.updatePairCheckboxTooltip();
   }
   private JButton createNavButton(String text, Color color) {
      JButton button = new JButton(text);
@@ -301,10 +310,26 @@
         formatPanel.add(displayFormatLabel);
         ButtonGroup formatGroup = new ButtonGroup();
         hexRadio = new JRadioButton(getString("hex"), true); // 默认选中HEX
         asciiRadio = new JRadioButton(getString("ascii"));
         asciiRadio = new JRadioButton(getString("ascii"), true); // 默认选中ASCI
         asciiRadio.addItemListener(e -> {
             if (asciiRadio.isSelected()) {
                asciiRadio.setForeground(Color.RED);
             } else {
                asciiRadio.setForeground(null); // 恢复默认颜色
             }
         });
         hexRadio = new JRadioButton(getString("hex"), false); // 默认不选中HEX
         hexRadio.addItemListener(e -> {
             if (hexRadio.isSelected()) {
                 hexRadio.setForeground(Color.RED);
             } else {
                 hexRadio.setForeground(null); // 恢复默认颜色
             }
         });
         pairCheckBox = new JCheckBox(getString("pair"), false); // 默认不勾选
         // 为配对复选框添加提示信息
         pairCheckBox.setToolTipText(getString("pair_tooltip"));
         pairCheckBox.addItemListener(e -> {
             if (pairCheckBox.isSelected()) {
                 sendField.setText("55AA030304F5FF");
@@ -413,7 +438,7 @@
         sendBtn.addActionListener(e -> sendData());
         // 新增:HEX发送复选框
         hexSendCheckBox = new JCheckBox(getString("hex_send"), true); // 默认勾选
         hexSendCheckBox = new JCheckBox(getString("hex_send"), false); // 默认勾选
         sendControlPanel.add(hexSendCheckBox, BorderLayout.WEST);
         sendControlPanel.add(sendBtn, BorderLayout.EAST);
@@ -426,6 +451,11 @@
         // 添加左右面板
         add(leftPanel, BorderLayout.CENTER);
         add(rightPanel, BorderLayout.EAST);
      }
      // 在HomePanel类中添加更新配对复选框提示信息的方法
      public void updatePairCheckboxTooltip() {
          pairCheckBox.setToolTipText(getString("pair_tooltip"));
      }
      private JButton createColoredButton(String text, Color color) {
@@ -566,74 +596,116 @@
      }
      private void processReceivedData(byte[] data) {
         // 优化:重用StringBuilder对象
         hexBuilder.setLength(0);
         for (byte b : data) {
            hexBuilder.append(String.format("%02X", b));
         }
         String displayText = hexBuilder.toString();
         String displayText1 = new String(data).replaceAll("\\s+", "");
         if (displayText.startsWith("55AA1F")) {
            Dell55AA1FParser.ParseResult result = Dell55AA1FParser.parse(displayText, "127.0.0.1", 0);
            if (result != null) {
               updateTable(result);
               visualizationPanel.updatePosition(result.distance, result.angle,result.signalQuality);
               visualizationPanel.setTagId(result.tagId);
            }
         }else if(displayText.startsWith("55AA01")) {
            ParseResult result=Dell55AA01Parser.parse(displayText, "127.0.0.1", 0);
            visualizationPanel.updatePosition(result.distance,270,0);
            visualizationPanel.setTagId(result.tagId);
         }
          // 优化:重用StringBuilder对象
          hexBuilder.setLength(0);
          for (byte b : data) {
              hexBuilder.append(String.format("%02X", b));
          }
          String displayText = hexBuilder.toString();
          String displayText1 = new String(data).replaceAll("\\s+", "");
          // 先检查数据长度是否足够进行解析
          if (displayText.length() < 30) { // 至少需要30个字符(15字节)才能解析基本字段
              appendLog("数据长度不足: " + displayText);
              return;
          }
          if (displayText.startsWith("55AA1F")) {
              Dell55AA1FParser.ParseResult result = Dell55AA1FParser.parse(displayText, "127.0.0.1", 0);
              if (result != null) {
                  updateTable(result);
                  visualizationPanel.updatePosition(result.distance, result.angle, result.signalQuality);
                  visualizationPanel.setTagId(result.tagId);
              } else {
                  appendLog("55AA1F协议解析失败: " + displayText);
              }
          } else if(displayText.startsWith("55AA01")) {
              ParseResult result = Dell55AA01Parser.parse(displayText, "127.0.0.1", 0);
              if (result != null) {
                  visualizationPanel.updatePosition(result.distance, 270, 0);
                  visualizationPanel.setTagId(result.tagId);
              } else {
                  appendLog("55AA01协议解析失败: " + displayText);
              }
          } else if(displayText.startsWith("55AA51")) {
              Dell55AA51Parser.ParseResult result = Dell55AA51Parser.parse(displayText, "127.0.0.1", 0);
              if (result != null) {
                  visualizationPanel.updatePosition(result.distance, result.horizontalAngle, result.signalStrength);
                  visualizationPanel.setTagId(result.tagId);
              } else {
                  appendLog("55AA51协议解析失败: " + displayText);
              }
          } else {
              // 如果不是已知协议,直接记录原始数据
              appendLog("未知协议: " + displayText);
          }
         if (hexRadio.isSelected()) {
            appendLog(displayText);
         } else {
            if (displayText.startsWith("55AA1F")) {
               Dell55AA1FParser.ParseResult result = Dell55AA1FParser.parse(displayText, "127.0.0.1", 0);
               // 优化:重用StringBuilder对象
               displayBuilder.setLength(0);
               displayBuilder.append("1F:")
               .append(result.dataLength)
               .append(",")
               .append(result.messageType)
               .append(",id:")
               .append(result.tagId)
               .append(",Dis:")
               .append(result.distance)
               .append("cm,Angle:")
               .append(result.angle)
               .append("°,Signal:")
               .append(result.signalQuality)
               .append(",Button:")
               .append(result.buttonPressed)
               .append(",Power:")
               .append(result.power);
               appendLog(displayBuilder.toString());
            }else if(displayText.startsWith("55AA01")) {
               ParseResult result=Dell55AA01Parser.parse(displayText, "127.0.0.1", 0);
               // 优化:重用StringBuilder对象
               displayBuilder.setLength(0);
               displayBuilder.append("55AA01 Seq:")
               .append(result.sequenceNum)
               .append(",Tagid:")
               .append(result.tagId)
               .append(",Anchorid:")
               .append(result.anchorId)
               .append(",Distance:")
               .append(result.distance)
               .append(",Power:")
               .append(result.power)
               .append(",Button:")
               .append(result.buttonPressed);
               appendLog(displayBuilder.toString());
            }else {
               appendLog(displayText1);
            }
         }
          if (hexRadio.isSelected()) {
              appendLog(displayText);
          } else {
              if (displayText.startsWith("55AA1F")) {
                  Dell55AA1FParser.ParseResult result = Dell55AA1FParser.parse(displayText, "127.0.0.1", 0);
                  if (result != null) {
                      // 优化:重用StringBuilder对象
                      displayBuilder.setLength(0);
                      displayBuilder.append(result.tagId)
                      .append(",Dis:")
                      .append(result.distance)
                      .append("cm,Angle:")
                      .append(result.angle)
                      .append("°,Signal:")
                      .append(result.signalQuality)
                      .append(",Button:")
                      .append(result.buttonPressed)
                      .append(",Power:")
                      .append(result.power);
                      appendLog(displayBuilder.toString());
                  }
              } else if(displayText.startsWith("55AA01")) {
                  ParseResult result = Dell55AA01Parser.parse(displayText, "127.0.0.1", 0);
                  if (result != null) {
                      // 优化:重用StringBuilder对象
                      displayBuilder.setLength(0);
                      displayBuilder.append("55AA01 Seq:")
                      .append(result.sequenceNum)
                      .append(",Tagid:")
                      .append(result.tagId)
                      .append(",Anchorid:")
                      .append(result.anchorId)
                      .append(",Distance:")
                      .append(result.distance)
                      .append(",Power:")
                      .append(result.power)
                      .append(",Button:")
                      .append(result.buttonPressed);
                      appendLog(displayBuilder.toString());
                  }
              } else if(displayText.startsWith("55AA51")) {
                  Dell55AA51Parser.ParseResult result = Dell55AA51Parser.parse(displayText, "127.0.0.1", 0);
                  if (result != null) {
                      displayBuilder.setLength(0);
                      displayBuilder.append(result.tagId)
                      .append(",Dis:")
                      .append(result.distance)
                      .append("cm,HAngle:")
                      .append(result.horizontalAngle)
                      .append("°,VAngle:")
                      .append(result.verticalAngle)
                      .append("°,Signal:")
                      .append(result.signalStrength)
                      .append("°,ASignal:")
                      .append(result.angleConfidence)
                      .append(",Power:")
                      .append(result.tagBattery)
                      .append("%,Status:")
                      .append(result.deviceStatus);
                      appendLog(displayBuilder.toString());
                  }
              } else {
                  appendLog(displayText1);
              }
          }
      }
      private void appendLog(String message) {
@@ -732,7 +804,8 @@
         asciiRadio.setText(getString("ascii"));
         hexSendCheckBox.setText(getString("hex_send"));
         pairCheckBox.setText(getString("pair"));
         // 更新配对复选框的提示信息
          updatePairCheckboxTooltip();
         // 更新边框标题
         updateBorderTitles(this);