resultMap = new HashMap<>(8);
- resultMap.put("code", 200);
- resultMap.put("type", type);
- resultMap.put("message", "请求成功");
- resultMap.put("success", true);
- return resultMap;
- }
-
- /**
- * 经纬度转弧度
- */
- private static double lnglatToRadian(double d) {
- return d * Math.PI / 180.0;
- }
-
- /**
- * 经纬度距离计算
- */
- private static double distance(double lonA, double latA, double lonB, double latB) {
- double aLng = lnglatToRadian(lonA);
- double aLat = lnglatToRadian(latA);
- double bLng = lnglatToRadian(lonB);
- double bLat = lnglatToRadian(latB);
-
- double dist = DistanceUtils.distHaversineRAD(aLat, aLng, bLat, bLng) * EARTH_RADIUS;
- DecimalFormat df = new DecimalFormat("#.00");
- return Double.parseDouble(df.format(dist));
- }
-
- /**
- * 方位角
- *
- * https://blog.csdn.net/dulingwen/article/details/96868530
- */
- private static int azimuth(double lonA, double latA, double lonB, double latB) {
- double deltaLng = lonB - lonA;
-
- double y = Math.sin(deltaLng) * Math.cos(latB);
- double x = Math.cos(latA) * Math.sin(latB) - Math.sin(latA) * Math.cos(latB) * Math.cos(deltaLng);
-
- double bearing = Math.atan2(y, x);
- bearing = Math.toDegrees(bearing);
- bearing = (bearing + 360) % 360;
-
- return (int) bearing;
- }
-}
\ No newline at end of file
diff --git a/casic-shelter/pom.xml b/casic-shelter/pom.xml
index c1dc630..3c096f1 100644
--- a/casic-shelter/pom.xml
+++ b/casic-shelter/pom.xml
@@ -57,6 +57,10 @@
spatial4j
0.8
+
+ io.netty
+ netty-all
+
diff --git a/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/Constant.java b/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/Constant.java
index 4af70db..ea31852 100644
--- a/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/Constant.java
+++ b/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/Constant.java
@@ -6,31 +6,9 @@
* @author a203
*/
public class Constant {
- public static final int[] DATA = new int[]{
- 0x2A,//帧头
- 0x23,//帧长度
- 0x01,//帧类型
- 0x00,//子类型
- 0x03,//机器人ID
- 0x4D, 0xBD, 0x80, 0xCF,//位置经度
- 0x0C, 0x5E, 0x28, 0xC2,//位置纬度
- 0x01, //航行状态
- 0xEB, //仪表电压
- 0xEF, //动力电压
- 0x5F, //仪表电余量
- 0x5D, //动力电余量
- 0x13, 0x5D, //俯仰角
- 0x40, 0x3D, //横滚角
- 0x30, 0xB2, //航向角
- 0x25, 0x4E, //浮力值
- 0x1B, 0x4E, //滑块位置
- 0x00, //探测状态
- 0x00, 0x9C, //目标距离
- 0x42, 0xBD, //目标方位
- 0x07, 0xD0, //目标频率
- 0xC7, 0x16, //CRC16校验码
- 0x0A //帧尾
- };
+
+ public static final int BITS_OF_HEAD = 0x2A;
+ public static final int BITS_OF_END = 0x0A;
/**
* 洋流相关常量
diff --git a/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java b/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java
deleted file mode 100644
index dc6ab54..0000000
--- a/casic-shelter/src/main/java/com/casic/missiles/modular/system/utils/DataParser.java
+++ /dev/null
@@ -1,609 +0,0 @@
-package com.casic.missiles.modular.system.utils;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.TypeReference;
-import com.casic.missiles.modular.system.dto.AisDTO;
-import com.casic.missiles.modular.system.dto.EnvironmentDTO;
-import com.casic.missiles.modular.system.dto.OceanDetailDTO;
-import com.casic.missiles.modular.system.dto.remote.OceanDetailRemoteData;
-import com.casic.missiles.modular.system.model.RobotInfo;
-import org.locationtech.spatial4j.distance.DistanceUtils;
-
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 西工大数据解析协议
- *
- * @author a203
- */
-public class DataParser {
-
- private static final int BITS_OF_HEAD = 0x2A;
- private static final int BITS_OF_END = 0x0A;
- //赤道半径(单位km)
- private static final double EARTH_RADIUS = 6371.393;
-
- private static boolean isCorrectData(int[] bytes) {
- if (bytes[0] != BITS_OF_HEAD) {
- return false;
- }
- return bytes[bytes.length - 1] == BITS_OF_END;
- }
-
- /**
- * 水下机器人信息
- */
- public static RobotInfo decodeRobotInfo(int[] bytes) {
- RobotInfo robot = new RobotInfo();
- if (!isCorrectData(bytes)) {
- return robot;
- }
- robot.setRobotId(bytes[4]);
-
- int[] lngBytes = new int[4];
- System.arraycopy(bytes, 5, lngBytes, 0, 4);
- robot.setLng(covertLngLat(lngBytes));
-
- int[] latBytes = new int[4];
- System.arraycopy(bytes, 9, latBytes, 0, 4);
- robot.setLat(covertLngLat(latBytes));
-
- robot.setNavigateState(covertState(bytes[13]));
- robot.setInstrumentV((float) (bytes[14] * 0.1));
- robot.setPowerV((float) bytes[15]);
- robot.setInstrumentE((float) (bytes[16]));
- robot.setPowerE((float) (bytes[17]));
-
- int[] pitchAngleBytes = new int[2];
- System.arraycopy(bytes, 18, pitchAngleBytes, 0, 2);
- robot.setPitchAngle(covertPitchAngle(pitchAngleBytes));
-
- int[] rollAngleBytes = new int[2];
- System.arraycopy(bytes, 20, rollAngleBytes, 0, 2);
- robot.setRollAngle(covertRollAngle(rollAngleBytes));
-
- int[] headingAngleBytes = new int[2];
- System.arraycopy(bytes, 22, headingAngleBytes, 0, 2);
- robot.setHeadingAngle(covertHeadingAngle(headingAngleBytes));
-
- int[] buoyancyBytes = new int[2];
- System.arraycopy(bytes, 24, buoyancyBytes, 0, 2);
- robot.setBuoyancy(covertBuoyancy(buoyancyBytes));
-
- int[] positionBytes = new int[2];
- System.arraycopy(bytes, 26, positionBytes, 0, 2);
- //滑块位置算法和浮力算法一样
- robot.setPosition(covertBuoyancy(positionBytes));
-
- int status = bytes[28];
- if (status == 0) {
- robot.setDetectStatus("没有目标");
- } else {
- robot.setDetectStatus("发现目标");
- }
-
- int[] targetDisBytes = new int[2];
- System.arraycopy(bytes, 29, targetDisBytes, 0, 2);
- robot.setTargetDistance(covertTargetDistance(targetDisBytes));
-
- int[] targetDirBytes = new int[2];
- System.arraycopy(bytes, 31, targetDirBytes, 0, 2);
- //目标方位算法和航向角算法一样
- robot.setTargetDirection(covertHeadingAngle(targetDirBytes));
-
- int[] targetHzBytes = new int[2];
- System.arraycopy(bytes, 33, targetHzBytes, 0, 2);
- robot.setTargetHertz(covertTargetHertz(targetHzBytes));
- return robot;
- }
-
- /**
- * 区域覆盖
- */
- public static String decodeRobotRegion(int[] bytes) {
- if (!isCorrectData(bytes)) {
- return "";
- }
- Map regionMap = new HashMap<>();
- int count = bytes[4];
- regionMap.put("count", String.valueOf(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]);
- }
- }
- regionMap.put("robotIds", builder.toString());
-
- //经度和纬度,所以需要*2
- int targetSize = count * 2 * 4;
- int[] targetBytes = new int[targetSize];
- //起始4个字节,机器人个数1个字节
- System.arraycopy(bytes, 5 + idsBytes.length, targetBytes, 0, targetSize);
- regionMap.put("robotTargets", formatLanLat(targetBytes));
-
- regionMap.put("pointCount", String.valueOf(bytes[5 + idsBytes.length + targetBytes.length]));
-
- int[] radiusBytes = new int[2];
- System.arraycopy(bytes, 5 + idsBytes.length + targetBytes.length + 1, radiusBytes, 0, 2);
- regionMap.put("regionRadius", covertTargetDistance(radiusBytes));
-
- int aByte = bytes[5 + idsBytes.length + targetBytes.length + 1 + radiusBytes.length];
- if (aByte == 0) {
- regionMap.put("contour", "轮廓标志位:多边形," + count + "个轮廓点");
- } else {
- regionMap.put("contour", "轮廓标志位:圆形," + 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);
- regionMap.put("robotPoints", formatLanLat(pointBytes));
- return JSON.toJSONString(regionMap);
- }
-
- /**
- * 路径规划
- */
- public static String decodeRobotRoute(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 decodeDirectedTask(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 decodeTaskRoute(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 decodeDirectFlightTask(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 decodeResideTask(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 decodePutTask(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);
- }
-
- /**
- * 短信内容
- */
- public static String decodeSMS(int[] bytes) {
- //帧头、帧长度、帧类型、子类型、机器人ID,CRC16校验码、帧尾总长度=8
- int dataLen = bytes.length - 8;
-
- int[] dataBytes = new int[dataLen];
- System.arraycopy(bytes, 5, dataBytes, 0, dataLen);
- StringBuilder builder = new StringBuilder();
- for (int dataByte : dataBytes) {
- builder.append((char) dataByte);
- }
- return builder.toString();
- }
-
- /**
- * AIS数据请求
- */
- public static String decodeAISRequest(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);
- }
-
- /**
- * 方舱位置
- * 编码encode
- * 解码decode
- */
- public static String decodeShelterPosition(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