From ae21cf10b0b52a5949f93322eaf94f2e518ab49e Mon Sep 17 00:00:00 2001 From: 826220679@qq.com <826220679@qq.com> Date: 星期二, 26 八月 2025 23:01:44 +0800 Subject: [PATCH] 习惯 --- src/home/VisualizationPanel.java | 66 +++++++++++++++----------------- src/home/AOAFollowSystem.java | 18 ++++++++- 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/home/AOAFollowSystem.java b/src/home/AOAFollowSystem.java index 6b1c318..432b760 100644 --- a/src/home/AOAFollowSystem.java +++ b/src/home/AOAFollowSystem.java @@ -241,6 +241,7 @@ private JRadioButton hexRadio; private JRadioButton asciiRadio; private JCheckBox hexSendCheckBox; + private JCheckBox pairCheckBox; // 琛ㄦ牸妯″瀷 - 鍙湁1琛� private Object[][] tableData = new Object[1][7]; @@ -302,12 +303,24 @@ ButtonGroup formatGroup = new ButtonGroup(); hexRadio = new JRadioButton(getString("hex"), true); // 榛樿閫変腑HEX asciiRadio = new JRadioButton(getString("ascii")); + + pairCheckBox = new JCheckBox(getString("pair"), false); // 榛樿涓嶅嬀閫� + pairCheckBox.addItemListener(e -> { + if (pairCheckBox.isSelected()) { + sendField.setText("55AA030304F5FF"); + } else { + sendField.setText(""); + } + }); + formatGroup.add(hexRadio); formatGroup.add(asciiRadio); formatPanel.add(hexRadio); formatPanel.add(asciiRadio); + formatPanel.add(pairCheckBox); + // 灏嗘牸寮忛�夋嫨闈㈡澘娣诲姞鍒版棩蹇楅潰鏉跨殑搴曢儴 logPanel.add(formatPanel, BorderLayout.SOUTH); @@ -566,12 +579,12 @@ Dell55AA1FParser.ParseResult result = Dell55AA1FParser.parse(displayText, "127.0.0.1", 0); if (result != null) { updateTable(result); - visualizationPanel.updatePosition(result.distance, result.angle); + 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); + visualizationPanel.updatePosition(result.distance,270,0); visualizationPanel.setTagId(result.tagId); } @@ -718,6 +731,7 @@ hexRadio.setText(getString("hex")); asciiRadio.setText(getString("ascii")); hexSendCheckBox.setText(getString("hex_send")); + pairCheckBox.setText(getString("pair")); // 鏇存柊杈规鏍囬 updateBorderTitles(this); diff --git a/src/home/VisualizationPanel.java b/src/home/VisualizationPanel.java index bde7067..8b24e30 100644 --- a/src/home/VisualizationPanel.java +++ b/src/home/VisualizationPanel.java @@ -24,6 +24,7 @@ private double scaleFactor = 1.0; // 缩放因子 private static final double MIN_SCALE = 0.2; // 最小缩放倍数 private static final double MAX_SCALE = 5.0; // 最大缩放倍数 + private int signalQuality = 0; // 添加信号质量变量 // 使用支持中文的字体 private Font boldFont = new Font("Microsoft YaHei", Font.BOLD, 14); @@ -52,34 +53,15 @@ }); } - public void updatePosition(int distance, int angle) { + public void updatePosition(int distance, int angle,int signalQuality) { // 优化:只有数据变化时才重绘 if (this.distance != distance || this.angle != angle) { this.distance = distance; - // 将角度范围转换为-180到180度,正下方为0度 - this.angle = normalizeAngle(angle); + // 直接使用原始角度值,不进行归一化处理 + this.angle = angle; + this.signalQuality=signalQuality; repaint(); } - } - - // 角度归一化方法,将角度转换为-180到180度范围,正下方为0度 - private int normalizeAngle(int angle) { - // 首先将角度转换为0-360度范围 - angle = angle % 360; - if (angle < 0) { - angle += 360; - } - - // 将0-360度转换为-180到180度,正下方为0度 - // 0度对应正下方,90度对应正左方,180/-180度对应正上方,-90度对应正右方 - int normalizedAngle = angle - 180; - if (normalizedAngle > 180) { - normalizedAngle -= 360; - } else if (normalizedAngle <= -180) { - normalizedAngle += 360; - } - - return normalizedAngle; } public void setAnchorId(String anchorid) { @@ -116,16 +98,22 @@ // 绘制角度刻度线 (-180° 到 180°) g2d.setColor(new Color(150, 150, 150)); for (int i = -180; i <= 180; i += 30) { - // 转换为弧度,正下方为0度 - double rad = Math.toRadians(i); - int x1 = centerX + (int) (maxRadius * Math.sin(rad)); - int y1 = centerY - (int) (maxRadius * Math.cos(rad)); + // 转换为数学坐标系的角度(从正东方向开始,逆时针为正) + double mathAngle = 90 - i; // 导航角度转换为数学角度 + if (mathAngle < 0) mathAngle += 360; + + double rad = Math.toRadians(mathAngle); + int x1 = centerX + (int) (maxRadius * Math.cos(rad)); + int y1 = centerY - (int) (maxRadius * Math.sin(rad)); g2d.setColor(new Color(100, 100, 100)); g2d.drawLine(centerX, centerY, x1, y1); // 绘制角度标签 - int labelX = centerX + (int) ((maxRadius + 15) * Math.sin(rad)); - int labelY = centerY - (int) ((maxRadius + 15) * Math.cos(rad)); + if (i == -180) { + continue; + } + int labelX = centerX + (int) ((maxRadius + 15) * Math.cos(rad)); + int labelY = centerY - (int) ((maxRadius + 15) * Math.sin(rad)); g2d.setColor(Color.blue); g2d.drawString(i + "°", labelX - 10, labelY + 5); } @@ -136,7 +124,7 @@ int radius = maxRadius * i / 5; g2d.drawOval(centerX - radius, centerY - radius, radius * 2, radius * 2); // 修改:将距离标签显示在圆圈正南方中间 - String distanceLabel = (int)(i * 200 / scaleFactor) + "cm"; + String distanceLabel = (int)(i * 200 * scaleFactor) + "cm"; // 修改:乘以scaleFactor而不是除以 int labelWidth = g2d.getFontMetrics().stringWidth(distanceLabel); g2d.drawString(distanceLabel, centerX - labelWidth / 2, centerY + radius + 15); } @@ -152,11 +140,16 @@ // 绘制B点(标签点) if (distance > 0) { // 根据距离计算缩放比例(最大1000厘米) - double scaledDistance = Math.min(distance, 1000) * maxRadius / 1000.0; - double rad = Math.toRadians(angle); - - int bX = centerX + (int) (scaledDistance * Math.sin(rad)); - int bY = centerY - (int) (scaledDistance * Math.cos(rad)); + double scaledDistance = Math.min(distance, 1000) * maxRadius / 1000.0 ; // 修改:添加乘以scaleFactor + + // 将导航角度转换为数学角度(从正东方向开始,逆时针为正) + double mathAngle = 90 - angle; // 导航角度转换为数学角度 + if (mathAngle < 0) mathAngle += 360; + + double rad = Math.toRadians(mathAngle); + int bX = centerX + (int) (scaledDistance * Math.cos(rad)); + int bY = centerY - (int) (scaledDistance * Math.sin(rad)); + // 绘制连接线 g2d.setColor(new Color(0, 100, 200, 150)); g2d.drawLine(centerX, centerY, bX, bY); @@ -182,6 +175,8 @@ // 直接从父框架获取当前语言的字符串 g2d.drawString(parentFrame.getString("distance") + distance + "cm", 10, 40); g2d.drawString(parentFrame.getString("angle") + angle + "°", 10, 70); + // 新增:显示信号质量 + g2d.drawString(parentFrame.getString("signal") + signalQuality, 10, 100); g2d.setFont(normalFont); g2d.setColor(Color.BLUE); g2d.fillOval(bX - 5, bY - 5, 10, 10); @@ -190,6 +185,7 @@ g2d.setFont(titleFont); g2d.drawString(tagid, bX - g2d.getFontMetrics().stringWidth(tagid)/2, bY - 15); g2d.setFont(normalFont); + } // 显示当前缩放比例 -- Gitblit v1.9.3