dataLinkedList = createDataHead("03");
+
+ //短信内容
+ byte[] msgBytes = data.getBytes();
+ for (byte msgByte : msgBytes) {
+ dataLinkedList.add(hex(msgByte));
+ }
+
+ //重新设置数据长度,不包括CRC16数据长度但需要加上帧尾长度(1字节)
+ int length = dataLinkedList.size() + 1;
+ dataLinkedList.set(1, hex(length));
+
+ //计算CRC16校验码
+ int crc = CRC16(dataLinkedList);
+ int[] crcBytes = crc16ToHex(crc);
+ for (int crcByte : crcBytes) {
+ dataLinkedList.add(hex(crcByte));
+ }
+
+ //帧尾
+ dataLinkedList.add("0A");
return formatData(dataLinkedList);
}
@@ -711,4 +761,43 @@
tempBytes[3] = (per) & 0xFF;
return tempBytes;
}
+
+ /**
+ * 经纬度转弧度
+ */
+ 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