From 0ef993f9f974e248efa3ce75d8298a42540263fc Mon Sep 17 00:00:00 2001 From: yarnom Date: Wed, 29 Oct 2025 12:39:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=92=E6=9F=A5TCP=20SERVER=20?= =?UTF-8?q?=E5=8F=91=E5=B8=83RTCM=E6=B6=88=E6=81=AF=E7=9A=84=E6=96=AD?= =?UTF-8?q?=E8=81=94=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtkcluster/RtkClusterService.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java index 2c4f3f25..57c22beb 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java @@ -177,9 +177,9 @@ public class RtkClusterService implements ApplicationRunner { private final ExecutorService exec; private volatile boolean started = false; private volatile ServerSocket server; - // 命名按你的语义: - // IN = rtkrcv -> server(我们读取解算/NMEA) - // OUT = server -> rtkrcv(我们向其发送RTCM) + // 命名按你的语义(用于日志呈现): + // RTKRCV-OUT = rtkrcv -> server(我们读取解算/NMEA) + // RTKRCV-IN = server -> rtkrcv(我们向其发送RTCM) private volatile Socket inConn; // source we READ (solution/NMEA) private volatile Socket outConn; // sink we WRITE RTCM private final java.util.Set liveConns = java.util.Collections.newSetFromMap(new java.util.concurrent.ConcurrentHashMap<>()); @@ -254,7 +254,7 @@ public class RtkClusterService implements ApplicationRunner { boolean looksSolution = head.startsWith("% ") || head.startsWith("$GP") || head.startsWith("$GN") || head.startsWith("$GPGGA") || head.startsWith("$GNGGA"); if (looksHttpGet || looksSolution) { - // 这是 rtkrcv -> 我们 的连接(IN:我们读取) + // 这是 rtkrcv -> 我们 的连接(RTKRCV-OUT:我们读取) inConn = s; if (looksHttpGet) { // 若像 NTRIP GET,请求一个最小应答保持连接 @@ -265,19 +265,19 @@ public class RtkClusterService implements ApplicationRunner { : "ICY 200 OK\r\n\r\n"; os.write(resp.getBytes(StandardCharsets.US_ASCII)); os.flush(); - LOGGER.info("[IN:{}] handshake responded: {}", port, resp.trim()); + LOGGER.info("[OUT:{}] handshake responded: {}", port, resp.trim()); } catch (Exception ignore) {} } // OUT 不能与 IN 相同 if (outConn == s) outConn = null; - LOGGER.info("Endpoint {} IN established", port); + LOGGER.info("Endpoint {} RTKRCV OUT established", port); } } String preview = new String(buf, 0, read, StandardCharsets.US_ASCII).replaceAll("\n", "\\n"); if (inConn == s) { - LOGGER.info("[IN:{}] {}", port, preview); - } else if (outConn == s) { LOGGER.info("[OUT:{}] {}", port, preview); + } else if (outConn == s) { + LOGGER.info("[IN:{}] {}", port, preview); } else { LOGGER.info("[UNK:{}] {}", port, preview); } @@ -286,8 +286,8 @@ public class RtkClusterService implements ApplicationRunner { LOGGER.debug("Connection reader closed on {}: {}", port, e.getMessage()); } finally { liveConns.remove(s); - if (inConn == s) { inConn = null; LOGGER.info("Endpoint {} IN disconnected", port); } - if (outConn == s) { outConn = null; LOGGER.info("Endpoint {} OUT disconnected", port); } + if (inConn == s) { inConn = null; LOGGER.info("Endpoint {} RTKRCV OUT disconnected", port); } + if (outConn == s) { outConn = null; LOGGER.info("Endpoint {} RTKRCV IN disconnected", port); } closeQuietly(s); ensureOutCandidate(); } @@ -295,13 +295,13 @@ public class RtkClusterService implements ApplicationRunner { } private void ensureOutCandidate() { - // 如果当前 OUT 不可用或与 IN 相同,则从存活连接里挑选一个非 IN 的作为 OUT(RTCM 写入端) + // 如果当前 OUT 不可用或与 IN 相同,则从存活连接里挑选一个非 IN 的作为 OUT(RTKRCV-IN:RTCM 写入端) Socket current = outConn; if (current != null && !current.isClosed() && current != inConn) return; for (Socket c : liveConns) { if (c != null && !c.isClosed() && c != inConn) { outConn = c; - LOGGER.debug("Endpoint {} OUT set (live={})", port, liveConns.size()); + LOGGER.debug("Endpoint {} RTKRCV IN set (live={})", port, liveConns.size()); return; } } @@ -314,8 +314,8 @@ public class RtkClusterService implements ApplicationRunner { try { Socket sink = outConn; if (sink == null || sink.isClosed() || sink == inConn) { - // 等待有效的 OUT 连接(我们往其写 RTCM),且不能与 IN 相同 - LOGGER.info("Endpoint {} waiting for OUT to be ready before sending RTCM", port); + // 等待有效的 RTKRCV-IN 连接(我们往其写 RTCM),且不能与 RTKRCV-OUT 相同 + LOGGER.info("Endpoint {} waiting for RTKRCV IN to be ready before sending RTCM", port); ensureOutCandidate(); Thread.sleep(50); continue;