From c8678bc0a05f68447eabf2b32a384104d7adb230 Mon Sep 17 00:00:00 2001 From: fengyarnom Date: Wed, 9 Jul 2025 15:31:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=8C=E4=BF=AE=E5=A4=8Df9p=E7=94=9F?= =?UTF-8?q?=E4=BA=A71005=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executor/D331RtcmMessageExecutor.java | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java index bbf9a1ab..50cf172a 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/executor/D331RtcmMessageExecutor.java @@ -518,28 +518,33 @@ public class D331RtcmMessageExecutor implements Executor } if (insertIndex != -1) { - ByteBuf newBuf = Unpooled.buffer(); - newBuf.writeBytes(originalData, 0, insertIndex / 2); - - // 使用f9p坐标生成1005消息 - double[] ecef = new double[3]; - // 修复:确保坐标值不为null,并正确处理Double类型 + // 检查基站是否有有效的ECEF坐标 Double ecefX = deviceBs.getEcefx(); Double ecefY = deviceBs.getEcefy(); Double ecefZ = deviceBs.getEcefz(); - ecef[0] = ecefX != null ? ecefX.doubleValue() : 0.0; - ecef[1] = ecefY != null ? ecefY.doubleValue() : 0.0; - ecef[2] = ecefZ != null ? ecefZ.doubleValue() : 0.0; + // 验证坐标有效性 + if (isValidEcefCoordinates(ecefX, ecefY, ecefZ)) { + ByteBuf newBuf = Unpooled.buffer(); + newBuf.writeBytes(originalData, 0, insertIndex / 2); - String rtcm1005 = Rtcm1005.generateRtcm1005Hex(ecef, 0); - if (rtcm1005 != null) { - byte[] rtcm1005Bytes = ByteUtil.hexStringTobyte(rtcm1005); - newBuf.writeBytes(rtcm1005Bytes); + double[] ecef = new double[3]; + ecef[0] = ecefX.doubleValue(); + ecef[1] = ecefY.doubleValue(); + ecef[2] = ecefZ.doubleValue(); + + String rtcm1005 = Rtcm1005.generateRtcm1005Hex(ecef, 0); + if (rtcm1005 != null && !rtcm1005.isEmpty()) { + byte[] rtcm1005Bytes = ByteUtil.hexStringTobyte(rtcm1005); + newBuf.writeBytes(rtcm1005Bytes); + } + + newBuf.writeBytes(originalData, insertIndex / 2, originalData.length - insertIndex / 2); + buf = newBuf; + } else { + logger.warn("Base station {} has invalid ECEF coordinates, skipping RTCM 1005 generation for device {}", + deviceBs.getDeviceId(), deviceId); } - - newBuf.writeBytes(originalData, insertIndex / 2, originalData.length - insertIndex / 2); - buf = newBuf; } lastD300ForwardTimeMap.put(deviceId, currentTime); @@ -787,29 +792,21 @@ public class D331RtcmMessageExecutor implements Executor } /** - * 打印当前基站和设备状态(用于调试) + * 验证ECEF坐标是否有效 */ - @Scheduled(fixedRate = 300000) // 5分钟执行一次 - public void printStatusSummary() { - if (logger.isInfoEnabled() && !baseStationStatusMap.isEmpty()) { - StringBuilder summary = new StringBuilder(); - summary.append("\n=== Base Station Status Summary ===\n"); - - for (BaseStationStatus status : baseStationStatusMap.values()) { - summary.append(String.format("Base Station: %s, Status: %s, Last Active: %s, Serving Devices: %d\n", - status.getBaseStationId(), - status.getStatus(), - status.getLastActiveTime(), - status.getServingDevices().size())); - } - - summary.append("=== Device Base Mapping ===\n"); - for (Map.Entry entry : deviceCurrentBaseMap.entrySet()) { - summary.append(String.format("Device: %s -> Base Station: %s\n", - entry.getKey(), entry.getValue())); - } - - logger.info(summary.toString()); + private boolean isValidEcefCoordinates(Double x, Double y, Double z) { + if (x == null || y == null || z == null) { + return false; } + + // 检查是否为零坐标 + if (x == 0.0 && y == 0.0 && z == 0.0) { + return false; + } + + // 检查坐标是否在地球表面合理范围内(大致6.3M到6.4M米) + double distance = Math.sqrt(x * x + y * y + z * z); + return distance >= 6300000 && distance <= 6400000; } + } \ No newline at end of file