fix: 尝试修复断联问题

This commit is contained in:
yarnom 2025-10-28 15:55:57 +08:00
parent 69b1ccdfee
commit 11ef555eea
3 changed files with 36 additions and 4 deletions

View File

@ -122,14 +122,21 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
deviceBs.setGeoidSeparation(gga.getGeoidSeparation());
}
// 添加NTRIP处理
// 添加NTRIP处理 + rtkCluster 推送
if(deviceBs.getForwardToNtrip()) {
byte[] srcdata = message.getSrcData();
String rtcm = ByteUtil.bytesToHexString(srcdata);
sendToNtrip(id, rtcm);
String hex = ByteUtil.bytesToHexString(srcdata);
// 1) NTRIP发送提取后的 RTCM
sendToNtrip(id, hex);
// 2) rtkCluster优先发送干净的 RTCM 去除任何封装退化时发送原始数据
try {
rtkClusterService.sendRtcm(id, rtcm);
String rtcmsHex = RtcmGgaUtil.getRtcms(hex).toString();
if (rtcmsHex != null && !rtcmsHex.isEmpty()) {
rtkClusterService.sendRtcmBytes(id, ByteUtil.hexStringTobyte(rtcmsHex));
} else {
rtkClusterService.sendRtcmBytes(id, srcdata);
}
} catch (Exception e) {
logger.debug("send to rtkCluster failed for {}: {}", id, e.getMessage());
}

View File

@ -55,6 +55,13 @@ public class RtkrcvConfigService {
replaced = replaceValueLine(replaced, "inpstr2-path", nz(profile.getInpstr2Path()));
replaced = replaceValueLine(replaced, "inpstr3-path", nz(profile.getInpstr3Path()));
replaced = replaceValueLine(replaced, "outstr1-path", nz(profile.getOutstr1Path()));
// If local tcp endpoints are used (e.g., 127.0.0.1:port), force type to tcpcli
if (looksLikeTcpEndpoint(profile.getInpstr1Path())) {
replaced = replaceValueLine(replaced, "inpstr1-type", "tcpcli");
}
if (looksLikeTcpEndpoint(profile.getOutstr1Path())) {
replaced = replaceValueLine(replaced, "outstr1-type", "tcpcli");
}
Integer outHeight = profile.getOutHeight();
int heightValue = (outHeight == null) ? 1 : (outHeight == 0 ? 0 : 1);
replaced = replaceValueLine(replaced, "out-height", String.valueOf(heightValue));
@ -94,6 +101,13 @@ public class RtkrcvConfigService {
return s == null ? "" : s;
}
private boolean looksLikeTcpEndpoint(String path) {
if (path == null) return false;
String p = path.trim();
// Plain host:port without '@' credentials or path '/' considered tcp endpoint
return p.contains(":") && !p.contains("@") && !p.contains("/");
}
/**
* Replace the value of a line like: "key = value # comment" while preserving spacing and comment.
*/

View File

@ -156,6 +156,13 @@ public class RtkClusterService implements ApplicationRunner {
ep.enqueueRtcm(data);
}
public void sendRtcmBytes(String deviceId, byte[] data) {
if (data == null || data.length == 0) return;
DeviceEndpoint ep = endpoints.get(deviceId);
if (ep == null) return;
ep.enqueueRtcm(data);
}
static class DeviceEndpoint {
private final int port;
private final ExecutorService exec;
@ -215,12 +222,16 @@ public class RtkClusterService implements ApplicationRunner {
if (n > 0 && isLikelyText(probe, n)) {
// OUT connection (NMEA etc.)
closeQuietly(outConn);
s.setTcpNoDelay(true);
s.setKeepAlive(true);
outConn = s;
LOGGER.debug("Endpoint {} OUT connected", port);
pumpOut(outConn, probe, n);
} else {
// IN connection (RTCM sink)
closeQuietly(inConn);
s.setTcpNoDelay(true);
s.setKeepAlive(true);
inConn = s;
LOGGER.debug("Endpoint {} IN connected", port);
}