From 6f59464fc6e12a525ba3004864eceb1bc1573a31 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 11 十二月 2025 17:43:45 +0800
Subject: [PATCH] 20251211
---
src/gecaoji/Device.java | 103 ++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 88 insertions(+), 15 deletions(-)
diff --git a/src/gecaoji/Device.java b/src/gecaoji/Device.java
index 0a54671..ee13487 100644
--- a/src/gecaoji/Device.java
+++ b/src/gecaoji/Device.java
@@ -72,6 +72,8 @@
// 鍗槦鍙暟
private String differentialAge;
// 宸垎鏃堕棿
+ private String selfCheckStatus = "-1";
+ // 鍓茶崏鏈鸿嚜妫�鐘舵��
private static final double METERS_PER_DEGREE_LAT = 111320.0d;
@@ -131,6 +133,7 @@
target.positioningStatus = properties.getProperty("positioningStatus", "-1");
target.satelliteCount = properties.getProperty("satelliteCount", "-1");
target.differentialAge = properties.getProperty("differentialAge", "-1");
+ target.selfCheckStatus = properties.getProperty("selfCheckStatus", "-1");
}
private void applyDefaults(Device target) {
@@ -162,6 +165,7 @@
target.positioningStatus = "-1";
target.satelliteCount = "-1";
target.differentialAge = "-1";
+ target.selfCheckStatus = "-1";
}
public static synchronized Device initializeActiveDevice(String mowerId) { // 鏍规嵁璁惧ID鍒濆鍖栨椿璺冭澶�
@@ -260,6 +264,9 @@
case "differentialAge":
this.differentialAge = value;
return true;
+ case "selfCheckStatus":
+ this.selfCheckStatus = value;
+ return true;
default:
System.err.println("鏈煡瀛楁: " + fieldName);
return false;
@@ -274,6 +281,14 @@
device.applyGNGGAUpdate(gnggaData, deviceId);
}
+ public static synchronized void updateFromSerialGNGGA(String gnggaData) { // 涓插彛鏁版嵁鏇存柊璺緞锛堟棤闇�璁惧缂栧彿鍖归厤锛�
+ Device device = gecaoji;
+ if (device == null) {
+ return;
+ }
+ device.chuankouGNGGAUpdate(gnggaData);
+ }
+
private void applyGNGGAUpdate(String gnggaData, String deviceId) { // 鎵цGNGGA鏇存柊閫昏緫
if (gnggaData == null) {
return;
@@ -297,10 +312,7 @@
return;
}
}
- if (hasMeaningfulValue(mowerNumber) && hasMeaningfulValue(incomingDeviceId) && !mowerNumber.equals(incomingDeviceId)) {
- return;
- }
- if (hasMeaningfulValue(incomingDeviceId)) {
+ if (hasMeaningfulValue(incomingDeviceId) && !incomingDeviceId.equals(mowerNumber)) {
mowerNumber = incomingDeviceId;
}
@@ -309,9 +321,19 @@
String longitudeValue = sanitizeField(fields, 4);
String longitudeHemisphere = sanitizeField(fields, 5);
- realtimeLatitude = defaultIfEmpty(combineCoordinate(latitudeValue, latitudeHemisphere));
- realtimeLongitude = defaultIfEmpty(combineCoordinate(longitudeValue, longitudeHemisphere));
- realtimeAltitude = defaultIfEmpty(sanitizeField(fields, 9));
+ String combinedLatitude = combineCoordinate(latitudeValue, latitudeHemisphere);
+ if (hasMeaningfulValue(combinedLatitude)) {
+ realtimeLatitude = combinedLatitude;
+ }
+ String combinedLongitude = combineCoordinate(longitudeValue, longitudeHemisphere);
+ if (hasMeaningfulValue(combinedLongitude)) {
+ realtimeLongitude = combinedLongitude;
+ }
+
+ String altitudeValue = sanitizeField(fields, 9);
+ if (hasMeaningfulValue(altitudeValue)) {
+ realtimeAltitude = altitudeValue;
+ }
positioningStatus = defaultIfEmpty(sanitizeField(fields, 6));
satelliteCount = defaultIfEmpty(sanitizeField(fields, 7));
@@ -324,28 +346,68 @@
updateRelativeCoordinates(latitudeValue, latitudeHemisphere, longitudeValue, longitudeHemisphere);
}
+
+ /**涓插彛鏇存柊GNGGA鏁版嵁*/
+ private void chuankouGNGGAUpdate(String gnggaData) { // 鎵цGNGGA鏇存柊閫昏緫
+ if (gnggaData == null) {
+ return;
+ }
+
+ String trimmed = gnggaData.trim();
+ if (trimmed.isEmpty() || !trimmed.startsWith("$GNGGA")) {
+ return;
+ }
+
+ String[] fields = trimmed.split(",");
+ if (fields.length < 15) {
+ System.err.println("GNGGA瀛楁鏁伴噺涓嶈冻: " + fields.length);
+ return;
+ }
+
+
+ String latitudeValue = sanitizeField(fields, 2);
+ String latitudeHemisphere = sanitizeField(fields, 3);
+ String longitudeValue = sanitizeField(fields, 4);
+ String longitudeHemisphere = sanitizeField(fields, 5);
+
+ String combinedLatitude = combineCoordinate(latitudeValue, latitudeHemisphere);
+ if (hasMeaningfulValue(combinedLatitude)) {
+ realtimeLatitude = combinedLatitude;
+ }
+ String combinedLongitude = combineCoordinate(longitudeValue, longitudeHemisphere);
+ if (hasMeaningfulValue(combinedLongitude)) {
+ realtimeLongitude = combinedLongitude;
+ }
+
+ String altitudeValue = sanitizeField(fields, 9);
+ if (hasMeaningfulValue(altitudeValue)) {
+ realtimeAltitude = altitudeValue;
+ }
+
+ positioningStatus = defaultIfEmpty(sanitizeField(fields, 6));
+ satelliteCount = defaultIfEmpty(sanitizeField(fields, 7));
+ differentialAge = defaultIfEmpty(sanitizeField(fields, 13));
+ realtimeSpeed ="0";
+ GupdateTime = String.valueOf(System.currentTimeMillis());
+
+ updateRelativeCoordinates(latitudeValue, latitudeHemisphere, longitudeValue, longitudeHemisphere);
+ }
private void updateRelativeCoordinates(String latValue, String latHemisphere,
String lonValue, String lonHemisphere) { // 璁$畻鐩稿鍧愭爣
if (!hasMeaningfulValue(latValue) || !hasMeaningfulValue(lonValue)
|| !hasMeaningfulValue(latHemisphere) || !hasMeaningfulValue(lonHemisphere)) {
- realtimeX = "-1";
- realtimeY = "-1";
return;
}
double mowerLat = toDecimalDegrees(latValue, latHemisphere);
double mowerLon = toDecimalDegrees(lonValue, lonHemisphere);
if (Double.isNaN(mowerLat) || Double.isNaN(mowerLon)) {
- realtimeX = "-1";
- realtimeY = "-1";
return;
}
double[] baseLatLon = resolveBaseStationLatLon();
if (baseLatLon == null) {
- realtimeX = "-1";
- realtimeY = "-1";
return;
}
@@ -357,8 +419,10 @@
double eastMeters = deltaLonDeg * metersPerLon;
double northMeters = deltaLatDeg * METERS_PER_DEGREE_LAT;
- realtimeX = formatMeters(eastMeters);
- realtimeY = formatMeters(northMeters);
+ if (Double.isFinite(eastMeters) && Double.isFinite(northMeters)) {
+ realtimeX = formatMeters(eastMeters);
+ realtimeY = formatMeters(northMeters);
+ }
}
private double[] resolveBaseStationLatLon() { // 瑙f瀽鍩虹珯缁忕含搴�
@@ -639,6 +703,14 @@
this.differentialAge = differentialAge;
}
+ public String getSelfCheckStatus() { // 鑾峰彇鑷鐘舵��
+ return selfCheckStatus;
+ }
+
+ public void setSelfCheckStatus(String selfCheckStatus) { // 璁剧疆鑷鐘舵��
+ this.selfCheckStatus = selfCheckStatus;
+ }
+
@Override
public String toString() { // 杈撳嚭瀵硅薄淇℃伅
return "Device{" +
@@ -666,6 +738,7 @@
", positioningStatus='" + positioningStatus + '\'' +
", satelliteCount='" + satelliteCount + '\'' +
", differentialAge='" + differentialAge + '\'' +
+ ", selfCheckStatus='" + selfCheckStatus + '\'' +
'}';
}
}
\ No newline at end of file
--
Gitblit v1.10.0