|
@@ -5,7 +5,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.uavps.system.domain.UavpsAlgorithmParameter;
|
|
|
import com.uavps.system.udp.vo.Aircraft;
|
|
|
import com.uavps.system.udp.vo.AircraftFormation;
|
|
|
+import com.uavps.system.udp.vo.PlatformAircraft;
|
|
|
import com.uavps.system.udp.vo.UdpData;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
@@ -18,6 +21,7 @@ import java.util.List;
|
|
|
|
|
|
public class UdpDataUtils {
|
|
|
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(UdpDataUtils.class);
|
|
|
// 真实目标数据包
|
|
|
public static final byte REAL_TARGET_DATA_HEAD_1 = (byte) 0xBB;
|
|
|
public static final byte REAL_TARGET_DATA_HEAD_2 = (byte) 0x14;
|
|
@@ -39,13 +43,14 @@ public class UdpDataUtils {
|
|
|
*/
|
|
|
public static UdpData parseFrame(byte[] frame) {
|
|
|
if (frame == null || frame.length < 4) {
|
|
|
+ logger.warn("parseFrame warn, frame: {}", frame);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
int index = 0;
|
|
|
byte start_1 = frame[index++];
|
|
|
byte start_2 = frame[index++];
|
|
|
-
|
|
|
+ UdpData udpData = new UdpData();
|
|
|
if (start_1 == REAL_TARGET_DATA_HEAD_1 && start_2 == REAL_TARGET_DATA_HEAD_2) {
|
|
|
// 真实目标数据包
|
|
|
index++;
|
|
@@ -57,9 +62,9 @@ public class UdpDataUtils {
|
|
|
formation.setAircrafts(aircrafts);
|
|
|
List<AircraftFormation> targetAircraft = new ArrayList<>();
|
|
|
targetAircraft.add(formation);
|
|
|
- UdpData udpData = new UdpData();
|
|
|
udpData.setBizId(bizId);
|
|
|
udpData.setFinished("false");
|
|
|
+ udpData.setType(UdpData.REAL_TARGET);
|
|
|
udpData.setTargetAircraft(targetAircraft);
|
|
|
return udpData;
|
|
|
} else if (start_1 == NOISE_TARGET_DATA_HEAD_1 && start_2 == NOISE_TARGET_DATA_HEAD_2) {
|
|
@@ -73,9 +78,10 @@ public class UdpDataUtils {
|
|
|
formation.setAircrafts(aircrafts);
|
|
|
List<AircraftFormation> targetAircraft = new ArrayList<>();
|
|
|
targetAircraft.add(formation);
|
|
|
- UdpData udpData = new UdpData();
|
|
|
+
|
|
|
udpData.setBizId(bizId);
|
|
|
udpData.setFinished("false");
|
|
|
+ udpData.setType(UdpData.NOISE_TARGET);
|
|
|
udpData.setTargetAircraft(targetAircraft);
|
|
|
return udpData;
|
|
|
} else if (start_1 == PLATFORM_DATA_HEAD_1 && start_2 == PLATFORM_DATA_HEAD_2) {
|
|
@@ -83,9 +89,18 @@ public class UdpDataUtils {
|
|
|
index++;
|
|
|
// 数据区
|
|
|
byte[] data = Arrays.copyOfRange(frame, index, frame.length - 1);
|
|
|
- parsePlatformData(data);
|
|
|
+
|
|
|
+ PlatformAircraft platformAircraft = parsePlatformData(data);
|
|
|
+ udpData.setBizId(bizId);
|
|
|
+ udpData.setFinished("false");
|
|
|
+ udpData.setType(UdpData.PLANT_UAV);
|
|
|
+ udpData.setPlatformAircraft(platformAircraft);
|
|
|
+ return udpData;
|
|
|
+ } else {
|
|
|
+ logger.warn("parseFrame warn, frame: {}", frame);
|
|
|
+ return null;
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static List<Aircraft> parseTargetData(byte[] data) {
|
|
@@ -150,36 +165,62 @@ public class UdpDataUtils {
|
|
|
return aircrafts;
|
|
|
}
|
|
|
|
|
|
- public static void parsePlatformData(byte[] data) {
|
|
|
+ public static PlatformAircraft parsePlatformData(byte[] data) {
|
|
|
+ PlatformAircraft platformAircraft = new PlatformAircraft();
|
|
|
byte[] xByte = BitUtils.copyFrom(data, 0, 4);
|
|
|
- //System.out.println(BitUtils.toHexString(xByte));
|
|
|
double x = BitUtils.toInt(xByte) * 0.0000001;
|
|
|
- //System.out.println(x);
|
|
|
+ platformAircraft.setLongitude(x);
|
|
|
byte[] yByte = BitUtils.copyFrom(data, 4, 4);
|
|
|
- //System.out.println(BitUtils.toHexString(yByte));
|
|
|
double y = BitUtils.toInt(yByte) * 0.0000001;
|
|
|
- //System.out.println(y);
|
|
|
+ platformAircraft.setLatitude(y);
|
|
|
byte[] hByte = BitUtils.copyFrom(data, 8, 2);
|
|
|
- //System.out.println(BitUtils.toHexString(hByte));
|
|
|
short h = BitUtils.toShort(hByte);
|
|
|
- //System.out.println(h);
|
|
|
- byte[] dvByte = BitUtils.copyFrom(data, 16, 2);
|
|
|
- //System.out.println(BitUtils.toHexString(dvByte));
|
|
|
- double dv = BitUtils.toShort(dvByte) * 0.1;
|
|
|
- //System.out.println(dv);
|
|
|
- byte[] bvByte = BitUtils.copyFrom(data, 18, 2);
|
|
|
- //System.out.println(BitUtils.toHexString(bvByte));
|
|
|
- double bv = BitUtils.toShort(bvByte) * 0.1;
|
|
|
- //System.out.println(bv);
|
|
|
- byte[] tvByte = BitUtils.copyFrom(data, 20, 2);
|
|
|
- //System.out.println(BitUtils.toHexString(tvByte));
|
|
|
- double tv = BitUtils.toShort(tvByte) * 0.1;
|
|
|
- //System.out.println(tv);
|
|
|
- byte[] hjjByte = BitUtils.copyFrom(data, 22, 2);
|
|
|
- //System.out.println(BitUtils.toHexString(hjjByte));
|
|
|
- double hjj = BitUtils.toShort(hjjByte) * 0.01;
|
|
|
- //System.out.println(hjj);
|
|
|
- //System.out.println("x: " + doubleToFloat(x) + " y: " + doubleToFloat(y) + " h: " + h + " dv: " + dv + " bv: " + bv + " tv: " + tv + " hjj: " + hjj);
|
|
|
+ platformAircraft.setAltitude(h);
|
|
|
+
|
|
|
+ byte[] azimuthAngleByte = BitUtils.copyFrom(data, 10, 2);
|
|
|
+ short azimuthAngle = BitUtils.toShort(azimuthAngleByte);
|
|
|
+ platformAircraft.setAzimuthAngle(azimuthAngle);
|
|
|
+
|
|
|
+ byte[] pitchAngleByte = BitUtils.copyFrom(data, 12, 2);
|
|
|
+ short pitchAngle = BitUtils.toShort(pitchAngleByte);
|
|
|
+ platformAircraft.setPitchAngle(pitchAngle);
|
|
|
+
|
|
|
+ byte[] rollAngleByte = BitUtils.copyFrom(data, 14, 2);
|
|
|
+ short rollAngle = BitUtils.toShort(rollAngleByte);
|
|
|
+ platformAircraft.setRollAngle(rollAngle);
|
|
|
+
|
|
|
+ byte[] eastSpeedByte = BitUtils.copyFrom(data, 16, 2);
|
|
|
+ short eastSpeed = BitUtils.toShort(eastSpeedByte);
|
|
|
+ platformAircraft.setEastSpeed(eastSpeed);
|
|
|
+
|
|
|
+ byte[] northSpeedByte = BitUtils.copyFrom(data, 18, 2);
|
|
|
+ short northSpeed = BitUtils.toShort(northSpeedByte);
|
|
|
+ platformAircraft.setNorthSpeed(northSpeed);
|
|
|
+
|
|
|
+ byte[] skySpeedByte = BitUtils.copyFrom(data, 20, 2);
|
|
|
+ short skySpeed = BitUtils.toShort(skySpeedByte);
|
|
|
+ platformAircraft.setSkySpeed(skySpeed);
|
|
|
+
|
|
|
+ byte[] trackAngleByte = BitUtils.copyFrom(data, 22, 2);
|
|
|
+ short trackAngle = BitUtils.toShort(trackAngleByte);
|
|
|
+ platformAircraft.setTrackAngle(trackAngle);
|
|
|
+
|
|
|
+ byte[] yearByte = BitUtils.copyFrom(data, 24, 2);
|
|
|
+ short year = BitUtils.toShort(yearByte);
|
|
|
+ byte[] monthByte = BitUtils.copyFrom(data, 26, 1);
|
|
|
+ int month = BitUtils.toInt(monthByte);
|
|
|
+ byte[] dayByte = BitUtils.copyFrom(data, 27, 1);
|
|
|
+ int day = BitUtils.toInt(dayByte);
|
|
|
+ byte[] hourByte = BitUtils.copyFrom(data, 28, 1);
|
|
|
+ int hour = BitUtils.toInt(hourByte);
|
|
|
+ byte[] minByte = BitUtils.copyFrom(data, 29, 1);
|
|
|
+ int min = BitUtils.toInt(minByte);
|
|
|
+ byte[] secondByte = BitUtils.copyFrom(data, 30, 1);
|
|
|
+ int second = BitUtils.toInt(secondByte);
|
|
|
+ byte[] millisecondByte = BitUtils.copyFrom(data, 31, 1);
|
|
|
+ int millisecond = BitUtils.toInt(millisecondByte);
|
|
|
+ platformAircraft.setUtcTime(String.format("%04d/%02d/%02d %02d:%02d:%02d %03d", year, month, day, hour, min, second, millisecond));
|
|
|
+ return platformAircraft;
|
|
|
}
|
|
|
|
|
|
public static Aircraft parseTargetSubData(byte[] data) {
|