package jiexi;
|
|
import home.SatelliteDataPanel;
|
|
import java.util.Vector;
|
|
public class Dell_GNGGA {
|
|
public static Vector<Dell_GNSS> GpsDevices = new Vector<>();
|
|
|
public static Dell_GNSS findGpsDeviceById(String tagid) {
|
Dell_GNSS dellGnss = null;
|
for (Dell_GNSS gpsDevice : GpsDevices) {
|
String deviceId = gpsDevice.getDeviceId();
|
if (deviceId.equals(tagid)) {
|
return gpsDevice;
|
}
|
}
|
return dellGnss;
|
}
|
|
public static void run(byte[] bytes,String ip,int port) {
|
String receivedData = new String(bytes);
|
// ´¦Àí¿ÉÄܵÄÁ¬°üÇé¿ö
|
String[] messages = receivedData.split("\\$");
|
|
for (String message : messages) {
|
if (message.isEmpty()) continue;
|
// ÖØÐÂÌí¼Ó$·ûºÅÒÔ±ãͳһ´¦Àí
|
String fullMessage = "$" + message;
|
processMessage(fullMessage,ip,port);
|
}
|
}
|
|
private static void processMessage(String message,String ip,int port) {
|
String[] fields = message.split(",");
|
|
// ¼ì²é°üÍ·ÊÇ·ñÕýÈ·
|
if (fields[0].equals("$GNGGA")) {
|
// ¼ì²é×Ö¶ÎÊýÁ¿ÊÇ·ñÍêÕû
|
if (fields.length != 21) {
|
return;
|
}
|
dell_gngga(fields,ip,port);
|
} else if (fields[0].equals("$XTB")) {
|
if (fields.length<7){
|
return;
|
}
|
dell_xtb(ip, port, fields);
|
}
|
|
|
}
|
|
private static void dell_xtb(String ip, int port, String[] fields) {
|
String tagid = fields[1];
|
String power = fields[2];
|
String version = fields[3];
|
String CCID = fields[4];
|
String button = fields[5];
|
String rtcmFrom = fields[6];
|
Dell_GNSS gpsDeviceById = findGpsDeviceById(tagid);
|
if (gpsDeviceById==null){
|
gpsDeviceById = new Dell_GNSS();
|
gpsDeviceById.setDeviceId(tagid);
|
gpsDeviceById.setPower(power);
|
gpsDeviceById.setCardNumber(CCID);
|
gpsDeviceById.setIpaddr(ip);
|
gpsDeviceById.setPort(port);
|
GpsDevices.add(gpsDeviceById);
|
SatelliteDataPanel.addDataRow(gpsDeviceById);
|
}else {
|
gpsDeviceById.setPower(power);
|
gpsDeviceById.setCardNumber(CCID);
|
gpsDeviceById.setIpaddr(ip);
|
gpsDeviceById.setPort(port);
|
}
|
}
|
|
private static void dell_gngga(String[] fields,String ip,int port) {
|
String upperCase = fields[1].toUpperCase();//UTCʱ¼ä
|
String upperCase1 = fields[2].toUpperCase();//γ¶È
|
String upperCase2 = fields[3].toUpperCase();//γ¶È°ëÇò
|
String upperCase3 = fields[4].toUpperCase();//¾¶È
|
String upperCase4 = fields[5].toUpperCase();//¾¶È°ëÇò
|
String upperCase5 = fields[6].toUpperCase();//¶¨Î»ÖÊÁ¿Ö¸Ê¾
|
String upperCase6 = fields[7].toUpperCase();//ÎÀÐÇÊýÁ¿
|
String upperCase7 = fields[8].toUpperCase();//ˮƽ¾«¶ÈÒò×Ó
|
String upperCase8 = fields[9].toUpperCase();//º£°Î¸ß¶È
|
String upperCase9 = fields[10].toUpperCase();//º£°Î¸ß¶Èµ¥Î»
|
String upperCase10 = fields[11].toUpperCase();//´óµØË®×¼Ãæ¸ß¶È
|
String upperCase11 = fields[12].toUpperCase();//´óµØË®×¼Ãæ¸ß¶Èµ¥Î»
|
String upperCase12 = fields[13].toUpperCase();//²î·Öʱ¼ä
|
String upperCase13 = fields[14].toUpperCase();//УÑéºÍ
|
String upperCase14 = fields[15].toUpperCase();//É豸±àºÅ
|
String upperCase15 = fields[16].toUpperCase();//É豸µçÁ¿
|
String upperCase16 = fields[17].toUpperCase();//ÎÀÐÇÐźÅÇ¿¶È
|
String upperCase17 = fields[18].toUpperCase();//±£Áôλ1
|
String upperCase18 = fields[19].toUpperCase();//±£Áôλ2
|
String upperCase19 = fields[20].toUpperCase();//±£Áôλ3
|
|
Dell_GNSS gpsDeviceById = findGpsDeviceById(upperCase14);
|
if (gpsDeviceById == null) {
|
gpsDeviceById = new Dell_GNSS();
|
gpsDeviceById.setDeviceId(upperCase14);
|
gpsDeviceById.setUtcTime(upperCase);
|
gpsDeviceById.setLatitude(upperCase1);
|
gpsDeviceById.setLongitude(upperCase3);
|
gpsDeviceById.setQuality(upperCase5);
|
gpsDeviceById.setSatelliteCount(upperCase6);
|
gpsDeviceById.setAltitude(upperCase8 + "m");
|
gpsDeviceById.setGeoidHeight(upperCase10 + "m");
|
gpsDeviceById.setDiffTime(upperCase12);
|
gpsDeviceById.setPower(upperCase15);
|
gpsDeviceById.setIpaddr(ip);
|
gpsDeviceById.setPort(port);
|
GpsDevices.add(gpsDeviceById);
|
SatelliteDataPanel.addDataRow(gpsDeviceById);
|
} else {
|
gpsDeviceById.setDeviceId(upperCase14);
|
gpsDeviceById.setUtcTime(upperCase);
|
gpsDeviceById.setLatitude(upperCase1);
|
gpsDeviceById.setLongitude(upperCase3);
|
gpsDeviceById.setQuality(upperCase5);
|
gpsDeviceById.setSatelliteCount(upperCase6);
|
gpsDeviceById.setAltitude(upperCase8 + "m");
|
gpsDeviceById.setGeoidHeight(upperCase10 + "m");
|
gpsDeviceById.setDiffTime(upperCase12);
|
gpsDeviceById.setPower(upperCase15);
|
gpsDeviceById.setIpaddr(ip);
|
gpsDeviceById.setPort(port);
|
}
|
}
|
|
}
|