From 6799351be12deb2f713f2c0a2b4c467a6d1098c3 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 02 十二月 2025 19:51:00 +0800
Subject: [PATCH] 2025122
---
src/udpdell/UDPServer.java | 69 ++++++++++++----------------------
1 files changed, 24 insertions(+), 45 deletions(-)
diff --git a/src/udpdell/UDPServer.java b/src/udpdell/UDPServer.java
index ee7b975..1ee1bde 100644
--- a/src/udpdell/UDPServer.java
+++ b/src/udpdell/UDPServer.java
@@ -69,7 +69,26 @@
}
}
+ public static void processIncomingMessage(String message) {
+ String[] fields = message.split(",");
+ // 妫�鏌ュ瓧娈垫暟閲忔槸鍚﹀畬鏁�
+ if (fields.length != 21) {
+ System.err.println("Invalid message format, expected 21 fields but got " + fields.length);
+ return;
+ }
+ // 妫�鏌ュ寘澶存槸鍚︽纭�
+ if (!fields[0].equals("$GNGGA")) {
+ System.err.println("Invalid message header: " + fields[0]);
+ return;
+ }
+ System.out.println("鏀跺埌浜嗗樊鍒嗘暟鎹細" + message);
+ Coordinate.parseGNGGAToCoordinateList(message);
+ int count = Coordinate.coordinates.size();
+ System.out.println("savenum:" + count);
+
+ Device.updateFromGNGGA(message, fields[15]);
+ }
private static class PacketProcessor implements Runnable {
private final DatagramPacket packet;
@@ -78,60 +97,20 @@
this.packet = packet;
}
+ @Override
public void run() {
String receivedData = new String(packet.getData(), 0, packet.getLength());
// 澶勭悊鍙兘鐨勮繛鍖呮儏鍐�
String[] messages = receivedData.split("\\$");
for (String message : messages) {
- if (message.isEmpty()) continue;
+ if (message.isEmpty()) {
+ continue;
+ }
// 閲嶆柊娣诲姞$绗﹀彿浠ヤ究缁熶竴澶勭悊
String fullMessage = "$" + message;
- processMessage(fullMessage);
+ processIncomingMessage(fullMessage);
}
}
-
- private void processMessage(String message) {
- String[] fields = message.split(",");
- // 妫�鏌ュ瓧娈垫暟閲忔槸鍚﹀畬鏁�
- if (fields.length != 21) {
- System.err.println("Invalid message format, expected 21 fields but got " + fields.length);
- return;
- }
-
- // 妫�鏌ュ寘澶存槸鍚︽纭�
- if (!fields[0].equals("$GNGGA")) {
- System.err.println("Invalid message header: " + fields[0]);
- return;
- }
- System.out.println("鏀跺埌浜嗗樊鍒嗘暟鎹細"+message);
- Coordinate.parseGNGGAToCoordinateList(message);
- int count= Coordinate.coordinates.size();
- System.out.println("savenum:"+count);
-
- Device.updateFromGNGGA(message, fields[15]);
- // // 鎵撳嵃瑙f瀽鍚庣殑鏁版嵁
- // System.out.println("UTC鏃堕棿: " + fields[1].toUpperCase());
- // System.out.println("绾害: " + fields[2].toUpperCase());
- // System.out.println("绾害鍗婄悆: " + fields[3].toUpperCase());
- // System.out.println("缁忓害: " + fields[4].toUpperCase());
- // System.out.println("缁忓害鍗婄悆: " + fields[5].toUpperCase());
- // System.out.println("瀹氫綅璐ㄩ噺鎸囩ず: " + fields[6].toUpperCase());
- // System.out.println("鍗槦鏁伴噺: " + fields[7].toUpperCase());
- // System.out.println("姘村钩绮惧害鍥犲瓙: " + fields[8].toUpperCase());
- // System.out.println("娴锋嫈楂樺害: " + fields[9].toUpperCase());
- // System.out.println("娴锋嫈楂樺害鍗曚綅: " + fields[10].toUpperCase());
- // System.out.println("澶у湴姘村噯闈㈤珮搴�: " + fields[11].toUpperCase());
- // System.out.println("澶у湴姘村噯闈㈤珮搴﹀崟浣�: " + fields[12].toUpperCase());
- // System.out.println("宸垎鏃堕棿: " + fields[13].toUpperCase());
- // System.out.println("鏍¢獙鍜�: " + fields[14].toUpperCase());
- // System.out.println("璁惧缂栧彿: " + fields[15].toUpperCase());
- // System.out.println("璁惧鐢甸噺: " + fields[16].toUpperCase());
- // System.out.println("鍗槦淇″彿寮哄害: " + fields[17].toUpperCase());
- // System.out.println("淇濈暀浣�1: " + fields[18].toUpperCase());
- // System.out.println("淇濈暀浣�2: " + fields[19].toUpperCase());
- // System.out.println("淇濈暀浣�3: " + fields[20].toUpperCase());
- // System.out.println("----------------------------------------");
- }
}
}
\ No newline at end of file
--
Gitblit v1.10.0