diff --git a/casic-ship/src/main/java/com/casic/missiles/modular/system/constants/CheckCode.java b/casic-ship/src/main/java/com/casic/missiles/modular/system/constants/CheckCode.java
new file mode 100644
index 0000000..b39b29c
--- /dev/null
+++ b/casic-ship/src/main/java/com/casic/missiles/modular/system/constants/CheckCode.java
@@ -0,0 +1,50 @@
+package com.casic.missiles.modular.system.constants;
+
+/**
+ * CRC16校验码
+ *
+ * @author a203
+ */
+public class CheckCode {
+ public static int[] CRC_HIGH = {
+ 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
+ 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
+ 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
+ 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
+ 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
+ 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40
+ };
+
+ public static int[] CRC_LOW = {
+ 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
+ 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
+ 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
+ 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
+ 0x11, 0xD1, 0xD0, 0x10, 0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 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
+ 0x40
+ };
+}
diff --git a/casic-ship/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java b/casic-ship/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java
index f5b674c..2e787a7 100644
--- a/casic-ship/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java
+++ b/casic-ship/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java
@@ -1,18 +1,14 @@
package com.casic.missiles.modular.system.utils;
+import com.alibaba.fastjson.JSON;
+import com.casic.missiles.modular.system.constants.CheckCode;
import com.casic.missiles.modular.system.model.RobotInfo;
+import com.casic.missiles.modular.system.model.RobotRegion;
+
+import java.util.*;
/**
* 西工大数据解析协议
- *
- * 帧头(1byte) 0x2A
- * 帧长度(1byte) 0x23
- * 帧类型(1byte) 0x01
- * 子类型(1byte) 0x00
- * 机器人ID(1byte) 0x03
- * 帧数据 4D BD 80 CF 0C 5E 28 C2 01 EB EF 5F 5D 13 5D 40 3D 30 B2 25 4E 1B 4E 00 00 9C 42 BD 07 D0 C7
- * CRC16校验码(2byte) 0xC7 0x16
- * 帧尾(1byte) 0x0A
*
* @author a203
*/
@@ -21,12 +17,19 @@
private static final int BITS_OF_HEAD = 0x2A;
private static final int BITS_OF_END = 0x0A;
- public static RobotInfo translate(int[] bytes) {
- RobotInfo robot = new RobotInfo();
+ private static boolean isCorrectData(int[] bytes) {
if (bytes[0] != BITS_OF_HEAD) {
- return robot;
+ return false;
}
- if (bytes[bytes.length - 1] != BITS_OF_END) {
+ return bytes[bytes.length - 1] == BITS_OF_END;
+ }
+
+ /**
+ * 水下机器人信息
+ */
+ public static RobotInfo parseRobotInfo(int[] bytes) {
+ RobotInfo robot = new RobotInfo();
+ if (!isCorrectData(bytes)) {
return robot;
}
robot.setRobotId(bytes[4]);
@@ -89,6 +92,273 @@
}
/**
+ * 区域覆盖
+ */
+ public static RobotRegion parseRobotRegion(int[] bytes) {
+ RobotRegion region = new RobotRegion();
+ if (!isCorrectData(bytes)) {
+ return region;
+ }
+ int count = bytes[4];
+ region.setRobotCount(count);
+
+ int[] idsBytes = new int[count];
+ System.arraycopy(bytes, 5, idsBytes, 0, count);
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < idsBytes.length; i++) {
+ if (i != idsBytes.length - 1) {
+ builder.append(idsBytes[i]).append(",");
+ } else {
+ builder.append(idsBytes[i]);
+ }
+ }
+ region.setRobotIds(builder.toString());
+
+ //经度和纬度,所以需要*2
+ int targetSize = count * 2 * 4;
+ int[] targetBytes = new int[targetSize];
+ //起始4个字节,机器人个数1个字节
+ System.arraycopy(bytes, 5 + idsBytes.length, targetBytes, 0, targetSize);
+ region.setRobotTargets(formatLanLat(targetBytes));
+
+ region.setPointCount(bytes[5 + idsBytes.length + targetBytes.length]);
+
+ int[] radiusBytes = new int[2];
+ System.arraycopy(bytes, 5 + idsBytes.length + targetBytes.length + 1, radiusBytes, 0, 2);
+ region.setRegionRadius(covertTargetDistance(radiusBytes));
+
+ int aByte = bytes[5 + idsBytes.length + targetBytes.length + 1 + radiusBytes.length];
+ if (aByte == 0) {
+ region.setContour("轮廓标志位:多边形," + count + "个轮廓点");
+ } else {
+ region.setContour("轮廓标志位:圆形," + count + "个轮廓点");
+ }
+
+ //经度和纬度,所以需要*2
+ int pointSize = count * 2 * 4;
+ int[] pointBytes = new int[pointSize];
+ System.arraycopy(bytes,
+ 5 + idsBytes.length + targetBytes.length + 1 + radiusBytes.length + 1,
+ pointBytes, 0, pointSize);
+ region.setRobotPoints(formatLanLat(pointBytes));
+ return region;
+ }
+
+ /**
+ * 路径规划
+ */
+ public static String parseRobotRoute(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map routeMap = new HashMap<>(2);
+
+ int count = bytes[4];
+ routeMap.put("routeCount", String.valueOf(count));
+
+ int routeSize = count * 2 * 4;
+ int[] routeBytes = new int[routeSize];
+ System.arraycopy(bytes, 5, routeBytes, 0, routeSize);
+ routeMap.put("robotRoutes", formatLanLat(routeBytes));
+ return JSON.toJSONString(routeMap);
+ }
+
+ /**
+ * 定向任务
+ */
+ public static String parseDirectedTask(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(2);
+ int[] depthBytes = new int[2];
+ System.arraycopy(bytes, 4, depthBytes, 0, 2);
+ taskMap.put("taskDepth", covertDepth(depthBytes) + "m");
+
+ int[] angleBytes = new int[2];
+ System.arraycopy(bytes, 6, angleBytes, 0, 2);
+ taskMap.put("headingAngle", covertHeadingAngle(angleBytes) + "°");
+ return JSON.toJSONString(taskMap);
+ }
+
+ /**
+ * 航路点任务
+ */
+ public static String parseTaskRoute(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(3);
+
+ int[] depthBytes = new int[2];
+ System.arraycopy(bytes, 4, depthBytes, 0, 2);
+ taskMap.put("taskDepth", covertDepth(depthBytes) + "m");
+
+ int count = bytes[6];
+ taskMap.put("routeCount", String.valueOf(count));
+
+ int routeSize = count * 2 * 4;
+ int[] routeBytes = new int[routeSize];
+ System.arraycopy(bytes, 7, routeBytes, 0, routeSize);
+ taskMap.put("robotRoutes", formatLanLat(routeBytes));
+ return JSON.toJSONString(taskMap);
+ }
+
+ /**
+ * 定深直航任务
+ */
+ public static String parseDirectFlightTask(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(3);
+ int[] depthBytes = new int[2];
+ System.arraycopy(bytes, 4, depthBytes, 0, 2);
+ taskMap.put("taskDepth", covertDepth(depthBytes) + "m");
+
+ int[] angleBytes = new int[2];
+ System.arraycopy(bytes, 6, angleBytes, 0, 2);
+ taskMap.put("headingAngle", covertHeadingAngle(angleBytes) + "°");
+
+ int[] timesBytes = new int[2];
+ System.arraycopy(bytes, 8, timesBytes, 0, 2);
+ taskMap.put("time", covertToDec(timesBytes) + "s");
+ return JSON.toJSONString(taskMap);
+ }
+
+ /**
+ * 驻留任务
+ */
+ public static String parseResideTask(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(4);
+ int[] lngBytes = new int[4];
+ System.arraycopy(bytes, 4, lngBytes, 0, 4);
+ taskMap.put("lng", String.valueOf(covertLngLat(lngBytes)));
+
+ int[] latBytes = new int[4];
+ System.arraycopy(bytes, 8, latBytes, 0, 4);
+ taskMap.put("lat", String.valueOf(covertLngLat(latBytes)));
+
+ int[] angleBytes = new int[2];
+ System.arraycopy(bytes, 12, angleBytes, 0, 2);
+ taskMap.put("depth", covertDepth(angleBytes) + "m");
+
+ int[] timesBytes = new int[2];
+ System.arraycopy(bytes, 14, timesBytes, 0, 2);
+ taskMap.put("time", covertToDec(timesBytes) + "min");
+ return JSON.toJSONString(taskMap);
+ }
+
+ /**
+ * 投放任务
+ */
+ public static String parsePutTask(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(4);
+ int[] lngBytes = new int[4];
+ System.arraycopy(bytes, 4, lngBytes, 0, 4);
+ taskMap.put("lng", String.valueOf(covertLngLat(lngBytes)));
+
+ int[] latBytes = new int[4];
+ System.arraycopy(bytes, 8, latBytes, 0, 4);
+ taskMap.put("lat", String.valueOf(covertLngLat(latBytes)));
+
+ int count = bytes[12];
+ taskMap.put("count", String.valueOf(count));
+
+ int[] idsBytes = new int[count];
+ System.arraycopy(bytes, 13, idsBytes, 0, count);
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < idsBytes.length; i++) {
+ if (i != idsBytes.length - 1) {
+ builder.append(idsBytes[i]).append(",");
+ } else {
+ builder.append(idsBytes[i]);
+ }
+ }
+ taskMap.put("ids", builder.toString());
+ return JSON.toJSONString(taskMap);
+ }
+
+ /**
+ * AIS数据请求
+ */
+ public static String parseAISRequest(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(2);
+ int[] depthBytes = new int[2];
+ System.arraycopy(bytes, 4, depthBytes, 0, 2);
+ taskMap.put("radius", covertToDec(depthBytes) + "km");
+
+ taskMap.put("shipCount", String.valueOf(bytes[6]));
+ return JSON.toJSONString(taskMap);
+ }
+
+ /**
+ * 方舱位置
+ */
+ public static String parseShelterPosition(int[] bytes) {
+ if (!isCorrectData(bytes)) {
+ return "";
+ }
+ Map taskMap = new HashMap<>(2);
+ int[] lngBytes = new int[4];
+ System.arraycopy(bytes, 4, lngBytes, 0, 4);
+ taskMap.put("lng", String.valueOf(covertLngLat(lngBytes)));
+
+ int[] latBytes = new int[4];
+ System.arraycopy(bytes, 8, latBytes, 0, 4);
+ taskMap.put("lat", String.valueOf(covertLngLat(latBytes)));
+ return JSON.toJSONString(taskMap);
+ }
+
+ public static String formatLanLat(int[] targetBytes) {
+ List lnglat = new ArrayList<>();
+ for (int i = 0; i < targetBytes.length; i += 4) {
+ int[] target = new int[4];
+ System.arraycopy(targetBytes, i, target, 0, 4);
+
+ //每4个字节转换一次经纬度
+ lnglat.add(covertLngLat(target));
+ }
+ List