From 3be4440f6800e10efd8db51b957d17a6cc3b39df Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期二, 27 六月 2023 16:17:07 +0800 Subject: [PATCH] 增加雷达报警点坐标计算 增加雷达报警数据推送mqtt --- src/main/java/com/ard/alarm/radar/service/impl/ArdEquipRadarServiceImpl.java | 121 +++++ src/main/java/com/ard/alarm/radar/domain/ArdEquipRadar.java | 70 +++ src/main/resources/mapper/ArdEquipRadarMapper.xml | 180 +++++++ src/main/java/com/ard/utils/LonlatConver.java | 294 ++++++++++++ pom.xml | 5 /dev/null | 33 - src/main/java/com/ard/alarm/radar/domain/RadarAlarmInfo.java | 23 + src/main/java/com/ard/utils/tcp/NettyTcpClient.java | 65 +- src/main/java/com/ard/utils/tcp/NettyTcpClientHandler.java | 398 +++++++++------- src/main/java/com/ard/alarm/radar/mapper/ArdEquipRadarMapper.java | 63 ++ src/main/java/com/ard/alarm/radar/service/IArdEquipRadarService.java | 61 ++ src/main/resources/application.yml | 23 src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java | 11 13 files changed, 1,092 insertions(+), 255 deletions(-) diff --git a/pom.xml b/pom.xml index 07bbe5e..0244e01 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,11 @@ <artifactId>commons-lang3</artifactId> <version>3.12.0</version> </dependency> + <dependency> + <groupId>org.gavaghan</groupId> + <artifactId>geodesy</artifactId> + <version>1.1.3</version> + </dependency> </dependencies> <build> diff --git a/src/main/java/com/ard/alarm/radar/domain/ArdEquipRadar.java b/src/main/java/com/ard/alarm/radar/domain/ArdEquipRadar.java new file mode 100644 index 0000000..7d13e4d --- /dev/null +++ b/src/main/java/com/ard/alarm/radar/domain/ArdEquipRadar.java @@ -0,0 +1,70 @@ +package com.ard.alarm.radar.domain; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +/** + * radar瀵硅薄 ard_equip_radar + * + * @author zj + * @date 2023-03-11 + */ +@Data +public class ArdEquipRadar +{ + private static final long serialVersionUID = 1L; + + /** id */ + private String id; + /** 鍚嶇О */ + private String name; + /** 绔彛 */ + private Integer port; + + /** 鎿嶄綔鍛榠d */ + private String operate; + + /** 鍒犻櫎鏍囪 */ + private String delFlag; + + /** 鐢ㄦ埛id */ + private String userId; + + /** 缁忓害 */ + private Double longitude; + + /** 缁村害 */ + private Double latitude; + + /** 楂樼▼ */ + private Double altitude; + + /** 瀹夎鏃堕棿 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date radarDate; + + /** 閮ㄩ棬id */ + private Long deptId; + + /** 淇话瑙� */ + private String pitch; + + /** 濉攊d */ + private String towerId; + private String towerName; + + /** 鍥惧儚瀹藉害 */ + private String imageWidth; + + /** 鍥惧儚楂樺害 */ + private String imageHeight; + + /** 鍨嬪彿 */ + private String type; + + /** ip */ + private String ip; + + +} diff --git a/src/main/java/com/ard/alarm/radar/domain/RadarAlarmInfo.java b/src/main/java/com/ard/alarm/radar/domain/RadarAlarmInfo.java new file mode 100644 index 0000000..4fcd6e6 --- /dev/null +++ b/src/main/java/com/ard/alarm/radar/domain/RadarAlarmInfo.java @@ -0,0 +1,23 @@ +package com.ard.alarm.radar.domain; + +import lombok.Data; + +import java.util.Date; + +/** + * @Description: + * @ClassName: RadarAlarmInfo + * @Author: 鍒樿嫃涔� + * @Date: 2023骞�06鏈�27鏃�15:49 + * @Version: 1.0 + **/ +@Data +public class RadarAlarmInfo { + + Integer id; + String name; + String alarmTime; + Double longitude; + Double lagitude; + +} diff --git a/src/main/java/com/ard/alarm/radar/mapper/ArdEquipRadarMapper.java b/src/main/java/com/ard/alarm/radar/mapper/ArdEquipRadarMapper.java new file mode 100644 index 0000000..2d5755c --- /dev/null +++ b/src/main/java/com/ard/alarm/radar/mapper/ArdEquipRadarMapper.java @@ -0,0 +1,63 @@ +package com.ard.alarm.radar.mapper; + +import java.util.List; +import com.ard.alarm.radar.domain.ArdEquipRadar; +import org.apache.ibatis.annotations.Mapper; + +/** + * radarMapper鎺ュ彛 + * + * @author zj + * @date 2023-03-11 + */ +@Mapper +public interface ArdEquipRadarMapper +{ + /** + * 鏌ヨradar + * + * @param id radar涓婚敭 + * @return radar + */ + public ArdEquipRadar selectArdEquipRadarById(String id); + + /** + * 鏌ヨradar鍒楄〃 + * + * @param ardEquipRadar radar + * @return radar闆嗗悎 + */ + public List<ArdEquipRadar> selectArdEquipRadarList(ArdEquipRadar ardEquipRadar); + + /** + * 鏂板radar + * + * @param ardEquipRadar radar + * @return 缁撴灉 + */ + public int insertArdEquipRadar(ArdEquipRadar ardEquipRadar); + + /** + * 淇敼radar + * + * @param ardEquipRadar radar + * @return 缁撴灉 + */ + public int updateArdEquipRadar(ArdEquipRadar ardEquipRadar); + + /** + * 鍒犻櫎radar + * + * @param id radar涓婚敭 + * @return 缁撴灉 + */ + public int deleteArdEquipRadarById(String id); + + /** + * 鎵归噺鍒犻櫎radar + * + * @param ids 闇�瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteArdEquipRadarByIds(String[] ids); +} diff --git a/src/main/java/com/ard/alarm/radar/service/IArdEquipRadarService.java b/src/main/java/com/ard/alarm/radar/service/IArdEquipRadarService.java new file mode 100644 index 0000000..87889de --- /dev/null +++ b/src/main/java/com/ard/alarm/radar/service/IArdEquipRadarService.java @@ -0,0 +1,61 @@ +package com.ard.alarm.radar.service; + +import java.util.List; +import com.ard.alarm.radar.domain.ArdEquipRadar; + +/** + * radarService鎺ュ彛 + * + * @author zj + * @date 2023-03-11 + */ +public interface IArdEquipRadarService +{ + /** + * 鏌ヨradar + * + * @param id radar涓婚敭 + * @return radar + */ + public ArdEquipRadar selectArdEquipRadarById(String id); + + /** + * 鏌ヨradar鍒楄〃 + * + * @param ardEquipRadar radar + * @return radar闆嗗悎 + */ + public List<ArdEquipRadar> selectArdEquipRadarList(ArdEquipRadar ardEquipRadar); + + /** + * 鏂板radar + * + * @param ardEquipRadar radar + * @return 缁撴灉 + */ + public int insertArdEquipRadar(ArdEquipRadar ardEquipRadar); + + /** + * 淇敼radar + * + * @param ardEquipRadar radar + * @return 缁撴灉 + */ + public int updateArdEquipRadar(ArdEquipRadar ardEquipRadar); + + /** + * 鎵归噺鍒犻櫎radar + * + * @param ids 闇�瑕佸垹闄ょ殑radar涓婚敭闆嗗悎 + * @return 缁撴灉 + */ + public int deleteArdEquipRadarByIds(String[] ids); + + /** + * 鍒犻櫎radar淇℃伅 + * + * @param id radar涓婚敭 + * @return 缁撴灉 + */ + public int deleteArdEquipRadarById(String id); +} diff --git a/src/main/java/com/ard/alarm/radar/service/impl/ArdEquipRadarServiceImpl.java b/src/main/java/com/ard/alarm/radar/service/impl/ArdEquipRadarServiceImpl.java new file mode 100644 index 0000000..2613750 --- /dev/null +++ b/src/main/java/com/ard/alarm/radar/service/impl/ArdEquipRadarServiceImpl.java @@ -0,0 +1,121 @@ +package com.ard.alarm.radar.service.impl; + +import java.util.List; +import com.ard.alarm.radar.domain.ArdEquipRadar; +import com.ard.alarm.radar.mapper.ArdEquipRadarMapper; +import com.ard.alarm.radar.service.IArdEquipRadarService; +import com.ard.utils.tcp.NettyTcpClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; + +/** + * radarService涓氬姟灞傚鐞� + * + * @author zj + * @date 2023-03-11 + */ +@Service +@Slf4j(topic = "radar") +public class ArdEquipRadarServiceImpl implements IArdEquipRadarService +{ + @Autowired + private ArdEquipRadarMapper ardEquipRadarMapper; + + + @Resource + NettyTcpClient nettyTcpClient; + @Value("${spring.netty.tcp.enabled}") + private Boolean tcpClientEnable; + @PostConstruct + public void init() { + if(!tcpClientEnable) + { + return; + } + List<ArdEquipRadar> ardEquipRadars = selectArdEquipRadarList(new ArdEquipRadar()); + for (ArdEquipRadar ardEquipRadar:ardEquipRadars) + { + String host = ardEquipRadar.getIp(); + Integer port = Integer.valueOf(ardEquipRadar.getPort()); + log.info("TCP瀹㈡埛绔皾璇曡繛鎺ワ細"+host+":"+port); + nettyTcpClient.init(ardEquipRadar); + } + } + + /** + * 鏌ヨradar + * + * @param id radar涓婚敭 + * @return radar + */ + @Override + public ArdEquipRadar selectArdEquipRadarById(String id) + { + return ardEquipRadarMapper.selectArdEquipRadarById(id); + } + + + /** + * 鏌ヨradar鍒楄〃 + * + * @param ardEquipRadar radar + * @return radar + */ + @Override + public List<ArdEquipRadar> selectArdEquipRadarList(ArdEquipRadar ardEquipRadar) + { + return ardEquipRadarMapper.selectArdEquipRadarList(ardEquipRadar); + } + + /** + * 鏂板radar + * + * @param ardEquipRadar radar + * @return 缁撴灉 + */ + @Override + public int insertArdEquipRadar(ArdEquipRadar ardEquipRadar) + { + return ardEquipRadarMapper.insertArdEquipRadar(ardEquipRadar); + } + + /** + * 淇敼radar + * + * @param ardEquipRadar radar + * @return 缁撴灉 + */ + @Override + public int updateArdEquipRadar(ArdEquipRadar ardEquipRadar) + { + return ardEquipRadarMapper.updateArdEquipRadar(ardEquipRadar); + } + + /** + * 鎵归噺鍒犻櫎radar + * + * @param ids 闇�瑕佸垹闄ょ殑radar涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deleteArdEquipRadarByIds(String[] ids) + { + return ardEquipRadarMapper.deleteArdEquipRadarByIds(ids); + } + + /** + * 鍒犻櫎radar淇℃伅 + * + * @param id radar涓婚敭 + * @return 缁撴灉 + */ + @Override + public int deleteArdEquipRadarById(String id) + { + return ardEquipRadarMapper.deleteArdEquipRadarById(id); + } +} diff --git a/src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java b/src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java index 3106e6a..a8243d9 100644 --- a/src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java +++ b/src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java @@ -14,8 +14,6 @@ import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * @Description: 绠$嚎娉勬紡鎶ヨ鏈嶅姟 @@ -29,11 +27,10 @@ public class TubeAlarmService { @Resource NettyUdpServer nettyUdpServer; - @Resource - NettyTcpClient nettyTcpClient; - @Value("${spring.netty.port}") + + @Value("${spring.netty.udp.port}") private Integer udpPort; - @Value("${spring.netty.enabled}") + @Value("${spring.netty.udp.enabled}") private String UdpServerEnable; @PostConstruct @@ -43,8 +40,6 @@ } nettyUdpServer.init(udpPort); log.info("UDP鏈嶅姟宸插惎鍔�"); - nettyTcpClient.init("127.0.0.1",1200); - log.info("TCP瀹㈡埛绔凡鍚姩"); } @Async("alarm") diff --git a/src/main/java/com/ard/utils/LonlatConver.java b/src/main/java/com/ard/utils/LonlatConver.java new file mode 100644 index 0000000..ff02333 --- /dev/null +++ b/src/main/java/com/ard/utils/LonlatConver.java @@ -0,0 +1,294 @@ +package com.ard.utils; + +public class LonlatConver { + /** + * a + */ + public final static double a = 6378245.0; + /** + * ee + */ + public final static double ee = 0.00669342162296594323; + + //鍦嗗懆鐜� GCJ_02_To_WGS_84 + public final static double pi = 3.14159265358979324; + /** + * @Description WGS84 to 鐏槦鍧愭爣绯� (GCJ-02) + * @param lon 缁忓害 + * @param lat 绾害 + * @return + */ + public static double[] wgs84_To_Gcj02(double lon, double lat) { + if (outOfChina(lat, lon)) { + return null; + } + double dLat = transformLat(lon - 105.0, lat - 35.0); + double dLon = transformLon(lon - 105.0, lat - 35.0); + double radLat = lat / 180.0 * pi; + double magic = Math.sin(radLat); + magic = 1 - ee * magic * magic; + double sqrtMagic = Math.sqrt(magic); + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); + dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); + double mgLat = lat + dLat; + double mgLon = lon + dLon; + return new double[] { mgLon, mgLat }; + } + + /** + * @Description 鐏槦鍧愭爣绯� (GCJ-02) to WGS84 + * @param lon + * @param lat + * @return + */ + public static double[] gcj02_To_Wgs84(double lon, double lat) { + double[] gps = transform(lat, lon); + double lontitude = lon * 2 - gps[1]; + double latitude = lat * 2 - gps[0]; + return new double[] { lontitude, latitude }; + } + + /** + * @Description 鐏槦鍧愭爣绯� (GCJ-02) to 鐧惧害鍧愭爣绯� (BD-09) + * @param gg_lon + * @param gg_lat + * @return + */ + public static double[] gcj02_To_Bd09(double gg_lon, double gg_lat) { + double x = gg_lon, y = gg_lat; + double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi); + double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi); + double bd_lon = z * Math.cos(theta) + 0.0065; + double bd_lat = z * Math.sin(theta) + 0.006; + return new double[] { bd_lon, bd_lat }; + } + + /** + * @Description 鐧惧害鍧愭爣绯� (BD-09) to 鐏槦鍧愭爣绯� (GCJ-02) + * @param bd_lon + * @param bd_lat + * @return + */ + public static double[] bd09_To_Gcj02(double bd_lon, double bd_lat) { + double x = bd_lon - 0.0065, y = bd_lat - 0.006; + double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi); + double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi); + double gg_lon = z * Math.cos(theta); + double gg_lat = z * Math.sin(theta); + return new double[] { gg_lon, gg_lat }; + } + /** + * @Description 鐧惧害鍧愭爣绯� (BD-09) to WGS84 + * @param bd_lat + * @param bd_lon + * @return + */ + public static double[] bd09_To_Wgs84(double bd_lon,double bd_lat) { + + double[] gcj02 = LonlatConver.bd09_To_Gcj02(bd_lon, bd_lat); + double[] map84 = LonlatConver.gcj02_To_Wgs84(gcj02[0], gcj02[1]); + return map84; + + } + + /** + * @Description 鍒ゆ柇鏄惁鍦ㄤ腑鍥借寖鍥村唴 + * @param lat + * @param lon + * @return + */ + public static boolean outOfChina(double lat, double lon) { + if (lon < 72.004 || lon > 137.8347) + return true; + if (lat < 0.8293 || lat > 55.8271) + return true; + return false; + } + + /** + * @Description transform + * @param lat + * @param lon + * @return + */ + private static double[] transform(double lat, double lon) { + if (outOfChina(lat, lon)) { + return new double[] { lat, lon }; + } + double dLat = transformLat(lon - 105.0, lat - 35.0); + double dLon = transformLon(lon - 105.0, lat - 35.0); + double radLat = lat / 180.0 * pi; + double magic = Math.sin(radLat); + magic = 1 - ee * magic * magic; + double sqrtMagic = Math.sqrt(magic); + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); + dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); + double mgLat = lat + dLat; + double mgLon = lon + dLon; + return new double[] { mgLat, mgLon }; + } + + /** + * @Description transformLat + * @param x + * @param y + * @return + */ + private static double transformLat(double x, double y) { + double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + + 0.2 * Math.sqrt(Math.abs(x)); + ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; + ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0; + ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0; + return ret; + } + + /** + * @Description transformLon + * @param x + * @param y + * @return + */ + public static double transformLon(double x, double y) { + double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 + * Math.sqrt(Math.abs(x)); + ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; + ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0; + ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 + * pi)) * 2.0 / 3.0; + return ret; + } + + /** + * GPS缁忕含搴﹁浆鎹负 搴︼紙3114.1717,12122.1067 鈫� 121.37300779锛�31.23436014锛� + * @param dms 鍧愭爣 + * @param type 鍧愭爣绫诲瀷 E/N + * @return String 瑙f瀽鍚庣殑缁忕含搴� + */ + public static String gpsToWgs84(String dms, String type) { + if (dms == null || dms.equals("")) { + return "0.0"; + } + double result = 0.0D; + String temp = ""; + + if (type.equals("E")) {//缁忓害 + String e1 = dms.substring(0, 3);//鎴彇3浣嶆暟瀛楋紝缁忓害鍏�3浣嶏紝鏈�澶�180搴� + //缁忓害鏄竴浼︽暒涓虹偣浣滃崡鍖椾袱鏋佺殑绾夸负0搴�,鎵�鏈夊線瑗垮拰寰�涓滃悇180搴� + String e2 = dms.substring(3, dms.length());//闇�瑕佽繍绠楃殑灏忔暟 + + result = Double.parseDouble(e1); + /* System.out.println("e2===="+e2); + System.out.println("===="+Double.parseDouble(e2) / 60.0D);*/ + result += (Double.parseDouble(e2) / 60.0D); + temp = String.valueOf(result); + if (temp.length() > 11) { + temp = e1 + temp.substring(temp.indexOf("."), 11); + } + } else if (type.equals("N")) { //绾害锛岀含搴︽槸浠ヨ丹閬撲负鍩哄噯,鐩稿綋浜庢妸鍦扮悆鍒嗕袱鍗�,涓や釜鍗婄悆闈笂鐨勭偣鍜屽钩闈㈠す瑙�0~90搴� + String n1 = dms.substring(0, 2);//鎴彇2浣嶏紝绾害鍏�2浣嶏紝鏈�澶�90搴� + String n2 = dms.substring(2, dms.length()); + + result = Double.parseDouble(n1); + /* System.out.println("n2===="+n2); + System.out.println("===="+Double.parseDouble(n2) / 60.0D);*/ + result += Double.parseDouble(n2) / 60.0D; + temp = String.valueOf(result); + if (temp.length() > 10) { + temp = n1 + temp.substring(temp.indexOf("."), 10); + } + } + return temp; + } + + /** + * + * @title 璁$畻鐐逛笌鐐圭殑璺濈 + * @param pointA + * @param pointB + * @description 娉ㄦ剰pointA,pointB涓殑缁忕含搴﹀潗鏍囬兘鏄伀鏄熷潗鏍� + * @return + * @author huaqunzi + */ + /*public static double distanceToPoint(PointEntity pointA,PointEntity pointB){ + //jts鎻愪緵鐨勫嚑浣曡绱犲伐鍘傜被 + GeometryFactory geometryFactory = new GeometryFactory(); + + //鐏槦鍧愭爣(gcj02)杞珿PS鍧愭爣(WGS84) + double[] wgsPntA = CoordinateUtil.gcj02_To_Wgs84(pointA.x,pointA.y); + double[] wgsPntB = CoordinateUtil.gcj02_To_Wgs84(pointB.x,pointB.y); + + //WGS84->楂樻柉6搴﹀垎甯︽姇褰� + double[] gaussPntA = wgs84_To_Gauss6(wgsPntA[0], wgsPntA[1]); + double[] gaussPntB = wgs84_To_Gauss6(wgsPntB[0], wgsPntB[1]); + + //閫氳繃鍑犱綍瑕佺礌宸ュ巶寰楀埌point瀹炰綋 + Point pntA = geometryFactory.createPoint(new Coordinate(gaussPntA[0], gaussPntA[1])); + Point pntB = geometryFactory.createPoint(new Coordinate(gaussPntB[0], gaussPntB[1])); + + // 涓ょ偣璺濈 + return pntA.distance(pntB); + }*/ + + + + /** + * @Description WGS84 to 楂樻柉鎶曞奖(6搴﹀垎甯�) + * @param longitude 缁忓害 + * @param latitude 绾害 + * @return double[] x y + */ + public static double[] wgs84_To_Gauss6(double longitude, double latitude) { + int ProjNo = 0; + int ZoneWide; // //甯﹀ + double[] output = new double[2]; + double longitude1, latitude1, longitude0, X0, Y0, xval, yval; + double a, f, e2, ee, NN, T, C, A, M, iPI; + iPI = 0.0174532925199433; // //3.1415926535898/180.0; + ZoneWide = 6; //6搴﹀甫瀹� + a = 6378137.0; + f = 1.0 / 298.257223563; //WGS84鍧愭爣绯诲弬鏁� + //a = 6378245.0;f = 1.0 / 298.3; // 54骞村寳浜潗鏍囩郴鍙傛暟 + // //a=6378140.0; f=1/298.257; //80骞磋タ瀹夊潗鏍囩郴鍙傛暟 + ProjNo = (int) (longitude / ZoneWide); + longitude0 = (double)(ProjNo * ZoneWide + ZoneWide / 2); + longitude0 = longitude0 * iPI; + longitude1 = longitude * iPI; // 缁忓害杞崲涓哄姬搴� + latitude1 = latitude * iPI; // 绾害杞崲涓哄姬搴� + e2 = 2 * f - f * f; + ee = e2 / (1.0 - e2); + NN = a + / Math.sqrt(1.0 - e2 * Math.sin(latitude1) + * Math.sin(latitude1)); + T = Math.tan(latitude1) * Math.tan(latitude1); + C = ee * Math.cos(latitude1) * Math.cos(latitude1); + A = (longitude1 - longitude0) * Math.cos(latitude1); + M = a + * ((1 - e2 / 4 - 3 * e2 * e2 / 64 - 5 * e2 * e2 * e2 / 256) + * latitude1 + - (3 * e2 / 8 + 3 * e2 * e2 / 32 + 45 * e2 * e2 * e2 + / 1024) * Math.sin(2 * latitude1) + + (15 * e2 * e2 / 256 + 45 * e2 * e2 * e2 / 1024) + * Math.sin(4 * latitude1) - (35 * e2 * e2 * e2 / 3072) + * Math.sin(6 * latitude1)); + // 鍥犱负鏄互璧ら亾涓篩杞寸殑锛屼笌鎴戜滑鍗楀寳涓篩杞存槸鐩稿弽鐨勶紝鎵�浠y涓庨珮鏂姇褰辩殑鏍囧噯xy姝eソ鐩稿弽; + xval = NN + * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 14 + * C - 58 * ee) + * A * A * A * A * A / 120); + yval = M + + NN + * Math.tan(latitude1) + * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 + - 58 * T + T * T + 270 * C - 330 * ee) + * A * A * A * A * A * A / 720); + X0 = 1000000L * (ProjNo + 1) + 500000L; + Y0 = 0; + xval = xval + X0; + yval = yval + Y0; + output[0] = xval; + output[1] = yval; + return output; + } + +} diff --git a/src/main/java/com/ard/utils/tcp/NettyTcpClient.java b/src/main/java/com/ard/utils/tcp/NettyTcpClient.java index 2d6c324..2eab8e2 100644 --- a/src/main/java/com/ard/utils/tcp/NettyTcpClient.java +++ b/src/main/java/com/ard/utils/tcp/NettyTcpClient.java @@ -1,5 +1,6 @@ package com.ard.utils.tcp; +import com.ard.alarm.radar.domain.ArdEquipRadar; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -11,6 +12,8 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; /** * @Description: @@ -24,33 +27,43 @@ @Slf4j(topic = "radar") public class NettyTcpClient { @Async - public void init(String host, Integer port) { - NioEventLoopGroup group = new NioEventLoopGroup(); - try { - Bootstrap bootstrap = new Bootstrap(); - bootstrap.group(group) - .channel(NioSocketChannel.class) - .handler(new ChannelInitializer<SocketChannel>() { - @Override - protected void initChannel(SocketChannel ch) throws Exception { - ch.pipeline().addLast(new NettyTcpClientHandler()); - } - }); - ChannelFuture future = bootstrap.connect(host, port).sync(); - // 娣诲姞杩炴帴鎴愬姛鐨勭洃鍚櫒 - future.addListener((ChannelFutureListener) future1 -> { - if (future1.isSuccess()) { - log.info("tcp杩炴帴鎴愬姛"+host+":"+port); - } else { - log.info("tcp杩炴帴澶辫触"+host+":"+port); - } - }); - future.channel().closeFuture().sync(); + public void init(ArdEquipRadar ardEquipRadar) { - } catch (Exception ex) { - log.error("nettyTcp瀹㈡埛绔垵濮嬪寲寮傚父:" + ex.getMessage()); - } finally { - group.shutdownGracefully(); + while (true) { + NioEventLoopGroup group = new NioEventLoopGroup(); + try { + Bootstrap bootstrap = new Bootstrap(); + bootstrap.group(group) + .channel(NioSocketChannel.class) + .handler(new ChannelInitializer<SocketChannel>() { + @Override + protected void initChannel(SocketChannel ch) throws Exception { + ch.pipeline().addLast(new NettyTcpClientHandler(ardEquipRadar)); + } + }); + String host = ardEquipRadar.getIp(); + Integer port = ardEquipRadar.getPort(); + ChannelFuture future = bootstrap.connect(host, port).sync(); + // 娣诲姞杩炴帴鎴愬姛鐨勭洃鍚櫒 + future.addListener((ChannelFutureListener) future1 -> { + if (future1.isSuccess()) { + log.info("tcp杩炴帴鎴愬姛" + host + ":" + port); + } else { + log.info("tcp杩炴帴澶辫触" + host + ":" + port); + } + }); + future.channel().closeFuture().sync(); + + } catch (Exception e) { + log.error("nettyTcp瀹㈡埛绔垵濮嬪寲寮傚父:" + e.getMessage()); + try { + TimeUnit.SECONDS.sleep(5); // 绛夊緟5绉掑悗閲嶆柊杩炴帴 + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } finally { + group.shutdownGracefully(); + } } } } diff --git a/src/main/java/com/ard/utils/tcp/NettyTcpClientHandler.java b/src/main/java/com/ard/utils/tcp/NettyTcpClientHandler.java index 626aff8..5a0c7fa 100644 --- a/src/main/java/com/ard/utils/tcp/NettyTcpClientHandler.java +++ b/src/main/java/com/ard/utils/tcp/NettyTcpClientHandler.java @@ -1,17 +1,30 @@ package com.ard.utils.tcp; +import com.alibaba.fastjson2.JSON; +import com.ard.alarm.radar.domain.ArdEquipRadar; +import com.ard.alarm.radar.domain.RadarAlarmInfo; +import com.ard.hiksdk.domain.alarmEventInfo; +import com.ard.utils.LonlatConver; import com.ard.utils.SpringTool; +import com.ard.utils.mqtt.MqttConsumer; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import lombok.extern.slf4j.Slf4j; +import org.gavaghan.geodesy.Ellipsoid; +import org.gavaghan.geodesy.GeodeticCalculator; +import org.gavaghan.geodesy.GlobalCoordinates; import sun.nio.cs.ext.GBK; import javax.xml.bind.DatatypeConverter; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; /** * @Description: tcp瀹㈡埛绔鐞� @@ -23,6 +36,23 @@ @Slf4j(topic = "radar") public class NettyTcpClientHandler extends SimpleChannelInboundHandler<ByteBuf> { + private String host; + private Integer port; + private Double longitude; + private Double lagitude; + private String name; + + public NettyTcpClientHandler(ArdEquipRadar ardEquipRadar) { + this.host = ardEquipRadar.getIp(); + this.port = ardEquipRadar.getPort(); + this.longitude = ardEquipRadar.getLongitude(); + this.lagitude = ardEquipRadar.getLatitude(); + this.name=ardEquipRadar.getName(); + } + + private ChannelHandlerContext context; + private ScheduledFuture<?> heartbeatTask; + @Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) { // 澶勭悊鎺ユ敹鍒扮殑娑堟伅 @@ -30,155 +60,198 @@ msg.getBytes(msg.readerIndex(), byteArray); byte[] bytes = receiveCompletePacket(byteArray); if (bytes != null) { - String hexString = DatatypeConverter.printHexBinary(bytes); - log.info(hexString); + // String hexString = DatatypeConverter.printHexBinary(bytes); + // log.info(hexString); processData(bytes); } } @Override public void channelActive(ChannelHandlerContext ctx) { - // 褰撳鎴风杩炴帴鎴愬姛鍚庯紝鍙戦�佹秷鎭粰鏈嶅姟鍣� - TimerTask timerTask = new TimerTask() { - @Override - public void run() { - ByteBuf message = ctx.alloc().buffer(); - byte[] heart = {0x01, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00, (byte) 0x83, (byte) 0x88, 0x5d, 0x71, 0x01, 0x02, 0x00}; - String hexString = DatatypeConverter.printHexBinary(heart); - log.info("鍙戦�佸績璺�:" + hexString); - message.writeBytes(heart); - ctx.writeAndFlush(message); - } - }; - Timer timer = new Timer(); - // timer.schedule(timerTask, 0, 6000); + context = ctx; + startHeartbeatTask();//寮�濮嬪彂閫佸績璺� + } + + /** + * 寮�濮嬪績璺充换鍔� + */ + private void startHeartbeatTask() { + heartbeatTask = context.executor().scheduleAtFixedRate(() -> { + // 鍙戦�佸績璺虫秷鎭� + ByteBuf message = context.alloc().buffer(); + byte[] heart = {0x01, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00, (byte) 0x83, (byte) 0x88, 0x5d, 0x71, 0x01, 0x02, 0x00}; + String hexString = DatatypeConverter.printHexBinary(heart); + log.info("鍙戦�佸績璺�:" + hexString); + message.writeBytes(heart); + context.writeAndFlush(message); + + }, 0, 5, TimeUnit.SECONDS); + } + + /** + * 鍋滄蹇冭烦浠诲姟 + */ + private void stopHeartbeatTask() { + if (heartbeatTask != null) { + heartbeatTask.cancel(false); + heartbeatTask = null; + } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - log.error("杩炴帴寮傚父"); + log.info("tcp瀹㈡埛绔繛鎺ュ紓甯�"); // 鍙戠敓寮傚父鏃剁殑澶勭悊 cause.printStackTrace(); ctx.close(); + stopHeartbeatTask();//鍋滄蹇冭烦鍙戦�� } - public static void processData(byte[] data) { + /** + * 瑙f瀽鎶ヨ鏁版嵁 + */ + public void processData(byte[] data) { try { - data = transferData(data);//鍘绘帀鍖呭ご鍜屽寘灏惧強杞箟 - String s = DatatypeConverter.printHexBinary(data); - log.info(s); - byte[] type = Arrays.copyOfRange(data, index.type[0], index.type[1]);//鍛戒护绫诲瀷 + data = transferData(data);//鍘绘帀鍖呭ご鍜屽寘灏俱�佹牎楠屽強杞箟 + + byte[] type = Arrays.copyOfRange(data, 0, 1);//鍛戒护绫诲瀷 log.info("鍛戒护绫诲瀷:" + DatatypeConverter.printHexBinary(type)); - byte[] cmdId = Arrays.copyOfRange(data, index.funcc[0], index.funcc[1]);//鍛戒护ID + byte[] cmdId = Arrays.copyOfRange(data, 1, 2);//鍛戒护ID log.info("鍛戒护ID:" + DatatypeConverter.printHexBinary(cmdId)); - byte[] payloadSize = Arrays.copyOfRange(data, index.payloadSize[0], index.payloadSize[1]);//鏈夋晥璐熻浇澶у皬 - // log.info("鏈夋晥璐熻浇澶у皬:" + DatatypeConverter.printHexBinary(payloadSize)); + byte[] payloadSize = Arrays.copyOfRange(data, 2, 4);//鏈夋晥璐熻浇澶у皬 payloadSize = toLittleEndian(payloadSize); - // log.info("鏈夋晥璐熻浇澶у皬(杞皬绔�):" + DatatypeConverter.printHexBinary(payloadSize)); int payloadSizeToDecimal = byteArrayToDecimal(payloadSize); log.info("鏈夋晥璐熻浇澶у皬(杞暣鍨�):" + payloadSizeToDecimal); if (Arrays.equals(cmdId, new byte[]{0x01})) { - byte[] dwTim = Arrays.copyOfRange(data, index.dwTim[0], index.dwTim[1]); - // log.info("鍛ㄨ鍥惧儚鐨勫嚭鐜版椂闂�:" + DatatypeConverter.printHexBinary(dwTim)); + byte[] dwTim = Arrays.copyOfRange(data, 4, 8); dwTim = toLittleEndian(dwTim); - // log.info("鍛ㄨ鍥惧儚鐨勫嚭鐜版椂闂�(杞皬绔�):" + DatatypeConverter.printHexBinary(dwTim)); - // log.info("鍛ㄨ鍥惧儚鐨勫嚭鐜版椂闂�(杞暣鍨�):" + byteArrayToDecimal(dwTim)); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long l = byteArrayToDecimal(dwTim); - String format = sdf.format(l * 1000); - log.info("鍛ㄨ鍥惧儚鐨勫嚭鐜版椂闂�(杞琩ate):" + format); + String alarmTime = sdf.format(l * 1000); + log.info("鍛ㄨ鍥惧儚鐨勫嚭鐜版椂闂�(杞琩ate):" + alarmTime); - byte[] wTargetNum = Arrays.copyOfRange(data, index.wTargetNum[0], index.wTargetNum[1]); + byte[] wTargetNum = Arrays.copyOfRange(data, 8, 10); wTargetNum = toLittleEndian(wTargetNum); - // log.info("鐩爣鎬荤偣鏁�(杞皬绔�):" + DatatypeConverter.printHexBinary(wTargetNum)); int targetNum = byteArrayToDecimal(wTargetNum); log.info("鐩爣鎬荤偣鏁�(杞暣鍨�):" + targetNum); //瑙f瀽NET_TARGET_UNIT(64鏄疦ET_TARGET_HEAD鐨勫瓧鑺傛暟) - int unitIndex = index.acRes[1]; - log.info("鏈夋晥璐熻浇鏃犲ご璧峰浣�:" + unitIndex); - -// byte datum = data[unitIndex]; -// log.info("鏃犲ご璧峰瀛楄妭锛�" + SpringTool.byteToHex(datum)); - int UNITNum = (payloadSizeToDecimal - 64) / targetNum; - log.info("鍗曚釜Unit澶у皬:" + UNITNum); + int uintSize = (payloadSizeToDecimal - 64) / targetNum; + log.info("鍗曟潯鎶ヨ澶у皬:" + uintSize); for (int i = 0; i < targetNum; i++) { - Integer index = unitIndex + UNITNum * i; + + Integer index = 68 + uintSize * i; byte[] dwID = Arrays.copyOfRange(data, index, index + 4); dwID = toLittleEndian(dwID); - // log.info("dwID锛�" + DatatypeConverter.printHexBinary(dwID)); int id = byteArrayToDecimal(dwID); - log.info("鐩爣ID鍙凤細" + id); - - byte[] dwGSum = Arrays.copyOfRange(data, index + 4, index + 8); - dwGSum = toLittleEndian(dwGSum); - int GSum = byteArrayToDecimal(dwGSum); - log.info("鐩爣褰撳墠鍍忕礌鐏板害鍜岋細" + GSum); + // log.info("鐩爣ID鍙凤細" + id); byte[] iDistance = Arrays.copyOfRange(data, index + 8, index + 12); iDistance = toLittleEndian(iDistance); int Distance = byteArrayToDecimal(iDistance); - log.info("鐩爣褰撳墠璺濈(m):" + Distance); - - byte[] iTw = Arrays.copyOfRange(data, index + 12, index + 16); - iTw = toLittleEndian(iTw); - int Tw = byteArrayToDecimal(iTw); - log.info("鐩爣褰撳墠鐨勫儚绱犲搴�:" + Tw); - - byte[] iTh = Arrays.copyOfRange(data, index + 16, index + 20); - iTh = toLittleEndian(iTh); - int Th = byteArrayToDecimal(iTh); - log.info("鐩爣褰撳墠鐨勫儚绱犻珮搴�:" + Th); - - byte[] wPxlArea = Arrays.copyOfRange(data, index + 20, index + 22); - wPxlArea = toLittleEndian(wPxlArea); - int PxlArea = byteArrayToDecimal(wPxlArea); - log.info("鐩爣褰撳墠鍍忕礌闈㈢Н:" + PxlArea); - - byte[] cTrkNum = Arrays.copyOfRange(data, index + 22, index + 23); - cTrkNum = toLittleEndian(cTrkNum); - int TrkNum = byteArrayToDecimal(cTrkNum); - log.info("杞ㄨ抗鐐规暟:" + TrkNum); - - byte[] cStat = Arrays.copyOfRange(data, index + 23, index + 24); - cStat = toLittleEndian(cStat); - int Stat = byteArrayToDecimal(cStat); - log.info("鐩爣褰撳墠鐘舵��:" + Stat); - - byte[] sVx = Arrays.copyOfRange(data, index + 24, index + 26); - sVx = toLittleEndian(sVx); - int Vx = byteArrayToDecimal(sVx); - log.info("鐩爣褰撳墠閫熷害鐭㈤噺(鍍忕礌璺濈)X:" + Vx); - - byte[] sVy = Arrays.copyOfRange(data, index + 26, index + 28); - sVy = toLittleEndian(sVy); - int Vy = byteArrayToDecimal(sVy); - log.info("鐩爣褰撳墠閫熷害鐭㈤噺(鍍忕礌璺濈)Y:" + Vy); - - byte[] sAreaNo = Arrays.copyOfRange(data, index + 28, index + 30); - sAreaNo = toLittleEndian(sAreaNo); - int AreaNo = byteArrayToDecimal(sAreaNo); - log.info("鐩爣褰掑睘鐨勫憡璀﹀尯鍩熷彿:" + AreaNo); - - byte[] cGrp = Arrays.copyOfRange(data, index + 30, index + 31); - cGrp = toLittleEndian(cGrp); - int Grp = byteArrayToDecimal(cGrp); - log.info("鎵�灞炵粍:" + Grp); - + // log.info("鐩爣褰撳墠璺濈(m):" + Distance); + //region 涓嶉渶瑕佺殑瀛楁 +// byte[] dwGSum = Arrays.copyOfRange(data, index + 4, index + 8); +// dwGSum = toLittleEndian(dwGSum); +// int GSum = byteArrayToDecimal(dwGSum); +// log.info("鐩爣褰撳墠鍍忕礌鐏板害鍜岋細" + GSum); +// byte[] iTw = Arrays.copyOfRange(data, index + 12, index + 16); +// iTw = toLittleEndian(iTw); +// int Tw = byteArrayToDecimal(iTw); +// log.info("鐩爣褰撳墠鐨勫儚绱犲搴�:" + Tw); +// +// byte[] iTh = Arrays.copyOfRange(data, index + 16, index + 20); +// iTh = toLittleEndian(iTh); +// int Th = byteArrayToDecimal(iTh); +// log.info("鐩爣褰撳墠鐨勫儚绱犻珮搴�:" + Th); +// +// byte[] wPxlArea = Arrays.copyOfRange(data, index + 20, index + 22); +// wPxlArea = toLittleEndian(wPxlArea); +// int PxlArea = byteArrayToDecimal(wPxlArea); +// log.info("鐩爣褰撳墠鍍忕礌闈㈢Н:" + PxlArea); +// +// byte[] cTrkNum = Arrays.copyOfRange(data, index + 22, index + 23); +// cTrkNum = toLittleEndian(cTrkNum); +// int TrkNum = byteArrayToDecimal(cTrkNum); +// log.info("杞ㄨ抗鐐规暟:" + TrkNum); +// +// byte[] cStat = Arrays.copyOfRange(data, index + 23, index + 24); +// cStat = toLittleEndian(cStat); +// int Stat = byteArrayToDecimal(cStat); +// log.info("鐩爣褰撳墠鐘舵��:" + Stat); +// +// byte[] sVx = Arrays.copyOfRange(data, index + 24, index + 26); +// sVx = toLittleEndian(sVx); +// int Vx = byteArrayToDecimal(sVx); +// log.info("鐩爣褰撳墠閫熷害鐭㈤噺(鍍忕礌璺濈)X:" + Vx); +// +// byte[] sVy = Arrays.copyOfRange(data, index + 26, index + 28); +// sVy = toLittleEndian(sVy); +// int Vy = byteArrayToDecimal(sVy); +// log.info("鐩爣褰撳墠閫熷害鐭㈤噺(鍍忕礌璺濈)Y:" + Vy); +// +// byte[] sAreaNo = Arrays.copyOfRange(data, index + 28, index + 30); +// sAreaNo = toLittleEndian(sAreaNo); +// int AreaNo = byteArrayToDecimal(sAreaNo); +// log.info("鐩爣褰掑睘鐨勫憡璀﹀尯鍩熷彿:" + AreaNo); +// +// byte[] cGrp = Arrays.copyOfRange(data, index + 30, index + 31); +// cGrp = toLittleEndian(cGrp); +// int Grp = byteArrayToDecimal(cGrp); +// log.info("鎵�灞炵粍:" + Grp); + //endregion byte[] szName = Arrays.copyOfRange(data, index + 64, index + 96); - String str = new String(szName, "GBK"); - log.info("鎵�灞炲憡璀﹀尯鍩熷悕绉�:" + str); + int position = findIndexOfDoubleZero(szName); + String alarmPointName = ""; + if (position != -1) { + byte[] result = new byte[position]; + System.arraycopy(szName, 0, result, 0, position); + alarmPointName = new String(result, "GBK"); + } else { + alarmPointName = new String(szName, "GBK"); + } + // log.info("鎵�灞炲憡璀﹀尯鍩熷悕绉�:" + alarmPointName); + byte[] afTx = Arrays.copyOfRange(data, index + 96, index + 100); + afTx = toLittleEndian(afTx); + float fTx = bytesToFloat(afTx); + // log.info("姘村钩瑙掑害:" + fTx); + byte[] afTy = Arrays.copyOfRange(data, index + 112, index + 116); + afTy = toLittleEndian(afTy); + float fTy = bytesToFloat(afTy); + // log.info("鍨傜洿瑙掑害:" + fTy); + log.info("闆疯揪淇℃伅锛�" + host + "銆恜ort銆�" + port + "銆怷銆�" + longitude + "銆怸銆�" + lagitude); + Double[] radarXY = {longitude, lagitude}; + Double[] alarmXY = CalculateCoordinates(radarXY, Distance, (double) fTx); + log.info("鎶ヨ淇℃伅锛�" + "銆恑d銆�" + id + "銆恘ame銆�" + alarmPointName + "銆恆larmTime銆�" + alarmTime + "銆恉istance銆�" + Distance + "銆怭銆�" + fTx + "銆怲銆�" + fTy + "銆怷銆�" + alarmXY[0] + "銆怸銆�" + alarmXY[1]); + RadarAlarmInfo alarmInfo=new RadarAlarmInfo(); + alarmInfo.setId(id); + alarmInfo.setAlarmTime(alarmTime); + alarmInfo.setName(alarmPointName+"("+name+")"); + alarmInfo.setLongitude(alarmXY[0]); + alarmInfo.setLagitude(alarmXY[1]); + MqttConsumer.publish(2, false, "radar", JSON.toJSONString(alarmInfo)); } } } catch (Exception ex) { log.error(ex.getMessage()); } } + /** + * byte鏁扮粍杞琭loat + */ + private float bytesToFloat(byte[] bytes) { + ByteBuffer buffer = ByteBuffer.wrap(bytes); + return buffer.getFloat(); + } - public static int byteArrayToDecimal(byte[] byteArray) { + + /** + * byte鏁扮粍杞暣鍨� + */ + public int byteArrayToDecimal(byte[] byteArray) { int decimalValue = 0; for (int i = 0; i < byteArray.length; i++) { @@ -188,7 +261,10 @@ return decimalValue; } - public static byte[] toLittleEndian(byte[] bigEndianBytes) { + /** + * 澶х杞皬绔� + */ + public byte[] toLittleEndian(byte[] bigEndianBytes) { byte[] littleEndianBytes = new byte[bigEndianBytes.length]; for (int i = 0; i < bigEndianBytes.length; i++) { @@ -200,84 +276,12 @@ } - public static Integer processPayloadSize(String payloadSize) {//瑙f瀽鏈夋晥璐熻浇澶у皬 - Integer payloadSizeInfo = 0; - String[] payloadSizeArr = payloadSize.split(""); - for (int i = 0; i <= payloadSizeArr.length - 1; i++) { - Integer num = null; - switch (payloadSizeArr[i]) { - case "0": - num = 0; - break; - case "1": - num = 1; - break; - case "2": - num = 2; - break; - case "3": - num = 3; - break; - case "4": - num = 4; - break; - case "5": - num = 5; - break; - case "6": - num = 6; - break; - case "7": - num = 7; - break; - case "8": - num = 8; - break; - case "9": - num = 9; - break; - case "a": - num = 10; - break; - case "b": - num = 11; - break; - case "c": - num = 12; - break; - case "d": - num = 13; - break; - case "e": - num = 14; - break; - case "f": - num = 15; - break; - default: - break; - } - if (i % 2 == 0) { - payloadSizeInfo = payloadSizeInfo + num * 16; - } else { - payloadSizeInfo = payloadSizeInfo + num * 256; - } - } - return payloadSizeInfo; - } - - public static Boolean checkPayloadSize(Integer payloadSizeInfo, String data) {//鏍¢獙鏈夋晥璐熻浇澶у皬 - Integer payloadSize = (data.length() - 8 - 8) / 2;//鍘婚櫎鍖呭ご8浣嶅拰鏍¢獙8浣� - if (payloadSize.equals(payloadSizeInfo)) { - return true; - } else { - return false; - } - } - // 鍒涘缓缂撳啿鍖哄垪琛� List<Byte> buffer = new ArrayList<>(); + /** + * 鎺ユ敹瀹屾暣鍖� + */ public byte[] receiveCompletePacket(byte[] receivedData) { // 瀹氫箟鍖呭熬瀛楄妭搴忓垪 byte[] packetEnd = {0x01, 0x02, 0x00}; @@ -302,7 +306,10 @@ return null; } - public static int findPacketEndIndex(List<Byte> buffer, byte[] packetEnd) { + /** + * 鑾峰彇鍖呯粨鏉熺储寮� + */ + public int findPacketEndIndex(List<Byte> buffer, byte[] packetEnd) { for (int i = 0; i <= buffer.size() - packetEnd.length; i++) { boolean isMatch = true; for (int j = 0; j < packetEnd.length; j++) { @@ -318,7 +325,10 @@ return -1; } - public static byte[] extractPacketFromBuffer(List<Byte> buffer, int endIndex) { + /** + * 浠庣紦鍐插尯鎻愬彇鏁版嵁鍖� + */ + public byte[] extractPacketFromBuffer(List<Byte> buffer, int endIndex) { byte[] packet = new byte[endIndex]; for (int i = 0; i < endIndex; i++) { packet[i] = buffer.get(i); @@ -327,8 +337,10 @@ return packet; } - //鍘绘帀鍖呭ご鍜屽寘灏炬牎楠屽強杞箟 - public static byte[] transferData(byte[] data) { + /** + * 鍘绘帀鍖呭ご鍜屽寘灏炬牎楠屽強杞箟 + */ + public byte[] transferData(byte[] data) { data = Arrays.copyOfRange(data, 3, data.length); data = Arrays.copyOfRange(data, 0, data.length - 7); String dataStr = DatatypeConverter.printHexBinary(data); @@ -344,4 +356,32 @@ data = DatatypeConverter.parseHexBinary(dataStr); return data; } + + /** + * 鎵惧埌00鐨勭储寮曚綅缃� + */ + private int findIndexOfDoubleZero(byte[] bytes) { + for (int i = 0; i < bytes.length - 1; i++) { + if (bytes[i] == 0x00) { + return i; + } + } + return -1; + } + + /** + * 閫氳繃A鐐瑰潗鏍囷紝闀垮害鍜孻杞磋搴﹁绠桞鐐瑰潗鏍� + */ + public Double[] CalculateCoordinates(Double[] radarCoordinates, Integer distance, Double angle) { + double[] to_wgs84 = LonlatConver.gcj02_To_Wgs84(radarCoordinates[0], radarCoordinates[1]); + double Ax = to_wgs84[0]; // A 鐐圭殑 X 鍧愭爣 + double Ay = to_wgs84[1]; // A 鐐圭殑 Y 鍧愭爣 + double AB = distance; // AB 鐨勯暱搴� + double angleWithYAxisDegrees = angle; // AB 涓� Y 杞寸殑瑙掑害锛堜互搴︽暟琛ㄧず锛� + GeodeticCalculator calculator = new GeodeticCalculator(); + GlobalCoordinates globalCoordinates = new GlobalCoordinates(Ay, Ax); + GlobalCoordinates globalCoordinates1 = calculator.calculateEndingGlobalCoordinates(Ellipsoid.WGS84, globalCoordinates, angleWithYAxisDegrees, AB); + return new Double[]{globalCoordinates1.getLongitude(), globalCoordinates1.getLatitude()}; + } + } diff --git a/src/main/java/com/ard/utils/tcp/index.java b/src/main/java/com/ard/utils/tcp/index.java deleted file mode 100644 index c4ae70c..0000000 --- a/src/main/java/com/ard/utils/tcp/index.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.ard.utils.tcp; - -/** - * @Description: - * @ClassName: domain - * @Author: 鍒樿嫃涔� - * @Date: 2023骞�06鏈�26鏃�15:21 - * @Version: 1.0 - **/ -public class index { - //header - public static Integer[] type = {0,1}; - public static Integer[] funcc = {1,2}; - public static Integer[] payloadSize = {2,4}; - //NET_TARGET_HEAD - public static Integer[] dwTim = {4,8}; - public static Integer[] wTargetNum = {8,10}; - public static Integer[] acRes = {10,68}; - //NET_TARGET_UNIT -// public static Integer[] dwID = {68,72}; -// public static Integer[] dwGSum = {}; -// public static Integer[] iDistance = 2; -// public static Integer[] cTrkNum = 1; -// public static Integer[] cStat = 1; -// public static Integer[] sVx = 2; -// public static Integer[] sVy = 2; -// public static Integer[] sAreaNo = 2; -// public static Integer[] cGrp = 1; -// public static Integer[] acRes1 = 33; -// public static Integer[] szName = 32; -// public static Integer[] afTx = 16; -// public static Integer[] afTy = 16; -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 82d9d81..2e6ddc4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,12 @@ spring: netty: - port: 40000 - enabled: true + udp: + port: 40000 + enabled: true + tcp: + host: 112.98.126.2 + port: 1200 + enabled: true mqtt: host: tcp://192.168.1.15:1883 clientId: c3 @@ -15,15 +20,15 @@ url: http://iot.zhdk.net:8090/Warning/GetWarning?userName=cy4oil datasource: driver-class-name: org.postgresql.Driver -# url: jdbc:postgresql://111.40.46.199:15432/ry-vue?stringtype=unspecified -# username: postgres -# password: Yykj.2021 - url: jdbc:postgresql://192.168.1.15:5432/ry-vue?stringtype=unspecified + url: jdbc:postgresql://111.40.46.199:15432/ry-vue?stringtype=unspecified username: postgres - password: postgres + password: Yykj.2021 +# url: jdbc:postgresql://192.168.1.15:5432/ry-vue?stringtype=unspecified +# username: postgres +# password: postgres mybatis: - type-aliases-package: com.ard.alarm.camera.domain.ArdCameras - mapper-locations: classpath:/mapper/*.xml + typeAliasesPackage: com.ard.alarm.**.domain + mapperLocations: classpath:/mapper/*.xml # minio閰嶇疆 minio: endpoint: http://192.168.1.15:9001 diff --git a/src/main/resources/mapper/ArdEquipRadarMapper.xml b/src/main/resources/mapper/ArdEquipRadarMapper.xml new file mode 100644 index 0000000..d675849 --- /dev/null +++ b/src/main/resources/mapper/ArdEquipRadarMapper.xml @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.ard.alarm.radar.mapper.ArdEquipRadarMapper"> + + <resultMap type="ArdEquipRadar" id="ArdEquipRadarResult"> + <result property="id" column="id" /> + <result property="name" column="name" /> + <result property="port" column="port" /> + <result property="operate" column="operate" /> + <result property="delFlag" column="del_flag" /> + <result property="userId" column="user_id" /> + <result property="longitude" column="longitude" /> + <result property="latitude" column="latitude" /> + <result property="altitude" column="altitude" /> + <result property="radarDate" column="radar_date" /> + <result property="deptId" column="dept_id" /> + <result property="pitch" column="pitch" /> + <result property="towerId" column="tower_id" /> + <result property="imageWidth" column="image_width" /> + <result property="imageHeight" column="image_height" /> + <result property="type" column="type" /> + <result property="ip" column="ip" /> + <result property="towerName" column="name" /> + </resultMap> + + <sql id="selectArdEquipRadarVo"> + select c.id, + c.name, + c.create_by, + c.port, + c.operate, + c.create_time, + c.update_by, + c.update_time, + c.del_flag, + c.user_id, + c.longitude, + c.latitude, + c.altitude, + c.radar_date, + c.dept_id, + c.pitch, + c.tower_id, + c.image_width, + c.image_height, + c.type, + c.ip + from ard_equip_radar c + </sql> + + <select id="selectArdEquipRadarList" parameterType="ArdEquipRadar" resultMap="ArdEquipRadarResult"> + select c.id,c.name, + c.create_by, + c.port, + c.operate, + c.create_time, + c.update_by, + c.update_time, + c.del_flag, + c.user_id, + c.longitude, + c.latitude, + c.altitude, + c.radar_date, + c.dept_id, + c.pitch, + c.tower_id, + c.image_width, + c.image_height, + c.type, + c.ip, + t.name + from ard_equip_radar c + left join sys_dept d on d.dept_id = c.dept_id + left join sys_user u on u.user_id = c.user_id + left join ard_towers t on t.id = c.tower_id + <where> + <if test="towerId != null and towerId != ''"> and c.tower_id = #{towerId}</if> + <if test="userId != null and userId != ''">and c.user_id = #{userId}</if> + <if test="deptId != null ">and (c.dept_id = #{deptId} OR c.dept_id IN ( SELECT t.dept_id FROM sys_dept t + WHERE cast(#{deptId} as varchar) = any(string_to_array(ancestors,',')) )) + </if> + </where> + </select> + + <select id="selectArdEquipRadarById" parameterType="String" resultMap="ArdEquipRadarResult"> + <include refid="selectArdEquipRadarVo"/> + where id = #{id} + </select> + + <insert id="insertArdEquipRadar" parameterType="ArdEquipRadar"> + insert into ard_equip_radar + <trim prefix="(" suffix=")" suffixOverrides=","> + <if test="id != null">id,</if> + <if test="name != null">name,</if> + <if test="createBy != null">create_by,</if> + <if test="port != null">port,</if> + <if test="operate != null">operate,</if> + <if test="createTime != null">create_time,</if> + <if test="updateBy != null">update_by,</if> + <if test="updateTime != null">update_time,</if> + <if test="delFlag != null">del_flag,</if> + <if test="userId != null">user_id,</if> + <if test="longitude != null">longitude,</if> + <if test="latitude != null">latitude,</if> + <if test="altitude != null">altitude,</if> + <if test="radarDate != null">radar_date,</if> + <if test="deptId != null">dept_id,</if> + <if test="pitch != null">pitch,</if> + <if test="towerId != null">tower_id,</if> + <if test="imageWidth != null">image_width,</if> + <if test="imageHeight != null">image_height,</if> + <if test="type != null">type,</if> + <if test="ip != null">ip,</if> + </trim> + <trim prefix="values (" suffix=")" suffixOverrides=","> + <if test="id != null">#{id},</if> + <if test="name != null">#{name},</if> + <if test="createBy != null">#{createBy},</if> + <if test="port != null">#{port},</if> + <if test="operate != null">#{operate},</if> + <if test="createTime != null">#{createTime},</if> + <if test="updateBy != null">#{updateBy},</if> + <if test="updateTime != null">#{updateTime},</if> + <if test="delFlag != null">#{delFlag},</if> + <if test="userId != null">#{userId},</if> + <if test="longitude != null">#{longitude},</if> + <if test="latitude != null">#{latitude},</if> + <if test="altitude != null">#{altitude},</if> + <if test="radarDate != null">#{radarDate},</if> + <if test="deptId != null">#{deptId},</if> + <if test="pitch != null">#{pitch},</if> + <if test="towerId != null">#{towerId},</if> + <if test="imageWidth != null">#{imageWidth},</if> + <if test="imageHeight != null">#{imageHeight},</if> + <if test="type != null">#{type},</if> + <if test="ip != null">#{ip},</if> + </trim> + </insert> + + <update id="updateArdEquipRadar" parameterType="ArdEquipRadar"> + update ard_equip_radar + <trim prefix="SET" suffixOverrides=","> + <if test="name != null">name = #{name},</if> + <if test="createBy != null">create_by = #{createBy},</if> + <if test="port != null">port = #{port},</if> + <if test="operate != null">operate = #{operate},</if> + <if test="createTime != null">create_time = #{createTime},</if> + <if test="updateBy != null">update_by = #{updateBy},</if> + <if test="updateTime != null">update_time = #{updateTime},</if> + <if test="delFlag != null">del_flag = #{delFlag},</if> + <if test="userId != null">user_id = #{userId},</if> + <if test="longitude != null">longitude = #{longitude},</if> + <if test="latitude != null">latitude = #{latitude},</if> + <if test="altitude != null">altitude = #{altitude},</if> + <if test="radarDate != null">radar_date = #{radarDate},</if> + <if test="deptId != null">dept_id = #{deptId},</if> + <if test="pitch != null">pitch = #{pitch},</if> + <if test="towerId != null">tower_id = #{towerId},</if> + <if test="imageWidth != null">image_width = #{imageWidth},</if> + <if test="imageHeight != null">image_height = #{imageHeight},</if> + <if test="type != null">type = #{type},</if> + <if test="ip != null">ip = #{ip},</if> + </trim> + where id = #{id} + </update> + + <delete id="deleteArdEquipRadarById" parameterType="String"> + delete from ard_equip_radar where id = #{id} + </delete> + + <delete id="deleteArdEquipRadarByIds" parameterType="String"> + delete from ard_equip_radar where id in + <foreach item="id" collection="array" open="(" separator="," close=")"> + #{id} + </foreach> + </delete> +</mapper> \ No newline at end of file -- Gitblit v1.9.3