diff --git a/device_cars/pom.xml b/device_cars/pom.xml index ac4909f..abbca68 100644 --- a/device_cars/pom.xml +++ b/device_cars/pom.xml @@ -388,6 +388,11 @@ easyexcel 3.3.2 + + com.xr + onvif-hk + 3.2.0 + diff --git a/device_cars/src/main/java/com/xr/device_car/config/utils/AnalysisXml.java b/device_cars/src/main/java/com/xr/device_car/config/utils/AnalysisXml.java deleted file mode 100644 index 3d41049..0000000 --- a/device_cars/src/main/java/com/xr/device_car/config/utils/AnalysisXml.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.xr.device_car.config.utils; - - -import com.xr.device_car.modules.analysis.entity.BallheadPT; -import org.apache.commons.lang.StringEscapeUtils; -import org.dom4j.Document; -import org.dom4j.Element; -import org.dom4j.io.SAXReader; - -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class AnalysisXml { - - - /** - * 解析xml[Profiles] 获取 token - * @param resultStr - * @return - */ - public static List analysisTokens(String resultStr){ - // 解析body - // 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移 - String xmlStr = StringEscapeUtils.unescapeXml(resultStr); - SAXReader reader = new SAXReader(); - try { - Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); - Element root = document.getRootElement(); - List elements = root.element("Body").element("GetProfilesResponse").elements("Profiles"); - return elements.stream().map(element -> element.attribute("token").getText()).collect(Collectors.toList()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - /** - * 解析xml[ProfilesName] 获取 token - * @param resultStr - * @return - */ - public static List analysisProfiles(String resultStr){ - // 解析body - // 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移 - String xmlStr = StringEscapeUtils.unescapeXml(resultStr); - SAXReader reader = new SAXReader(); - try { - Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); - Element root = document.getRootElement(); - List elements = root.element("Body").element("GetProfilesResponse").elements("Preset"); - return elements.stream().map(element -> element.element("Name").getText() - ).collect(Collectors.toList()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - /** - * 解析xml[MediaUri] 获取 token - * @param resultStr - * @return - */ - public static String analysisSnapshotUrl(String resultStr){ - // 解析body - // 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移 - String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); - SAXReader reader = new SAXReader(); - try { - Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); - Element rootElement = document.getRootElement(); - Element element = rootElement.element("Body").element("GetSnapshotUriResponse").element("MediaUri"); - List elements=element.elements("Uri"); - return String.valueOf(elements.get(0).getData()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - - /** - * 解析xml[MediaUri] 获取 streamUrl - * @param resultStr - * @return - */ - public static String analysisStreamUrl(String resultStr){ - // 解析body - // 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移 - String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); - SAXReader reader = new SAXReader(); - try { - Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); - Element rootElement = document.getRootElement(); - Element element = rootElement.element("Body").element("GetStreamUriResponse").element("MediaUri"); - List elements=element.elements("Uri"); - return String.valueOf(elements.get(0).getData()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static List getBallheadPTs(String resultStr){ - List ballheadPTS=new ArrayList<>(); - String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); - SAXReader reader = new SAXReader(); - try { - Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); - Element root = document.getRootElement(); - List elements = root.element("Body").element("GetPresetsResponse").elements("Preset"); - for(Element element:elements){ - BallheadPT pt=new BallheadPT(); - String id = element.attribute(0).getValue(); - pt.setId(id); - String name = String.valueOf(element.element("Name").getText()); - pt.setName(name); - List ele=element.elements("PTZPosition"); - pt.setX(String.valueOf(ele.get(0).element("PanTilt").attribute(0).getValue())); - pt.setY(String.valueOf(ele.get(0).element("PanTilt").attribute(1).getValue())); - pt.setZ(String.valueOf(ele.get(0).element("Zoom").attribute(0).getValue())); - ballheadPTS.add(pt); - } - } catch (Exception e) { - e.printStackTrace(); - } - return ballheadPTS; - } - - public static BallheadPT getStatus(String resultStr){ - String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); - SAXReader reader = new SAXReader(); - try { - Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); - Element root = document.getRootElement(); - Element element = root.element("Body").element("GetStatusResponse").element("PTZStatus").element("Position"); - String x=String.valueOf(element.element("PanTilt").attribute(0).getValue()); - String y=String.valueOf(element.element("PanTilt").attribute(1).getValue()); - String z=String.valueOf(element.element("Zoom").attribute(0).getValue()); - BallheadPT pt=new BallheadPT(); - pt.setX(x); - pt.setY(y); - pt.setZ(z); - return pt; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - -} diff --git a/device_cars/src/main/java/com/xr/device_car/config/utils/HkComUtil.java b/device_cars/src/main/java/com/xr/device_car/config/utils/HkComUtil.java deleted file mode 100644 index c03d80a..0000000 --- a/device_cars/src/main/java/com/xr/device_car/config/utils/HkComUtil.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.xr.device_car.config.utils; - -import com.xr.device_car.modules.analysis.entity.BallheadPT; -import com.xr.device_car.modules.analysis.entity.DeviceCamera; -import com.xr.device_car.modules.analysis.entity.OnvifAuthBean; -import com.xr.device_car.modules.analysis.entity.OnvifBean; -import org.springframework.util.CollectionUtils; - -import java.awt.image.BufferedImage; -import java.util.List; - -public class HkComUtil { - - public static BufferedImage getBole(DeviceCamera device) throws Exception{ //拉取枪机图片 - OnvifAuthBean onvifBean= new OnvifAuthBean(device.getDeviceIp(),80,device.getAccount(),device.getPassword()); - String url= OnvifBean.getRequestUrl(onvifBean); - String auth = OnvifUtils.getAuthorization("digest",onvifBean,"digest/GetProfiles.wsdl", url); - System.out.println("鉴权:"+auth); - //获取Token - List profileTokens = OnvifUtils.getProfileTokens(onvifBean,auth); - System.out.println("Token:"+profileTokens); - onvifBean.setAuth(auth); - if(!CollectionUtils.isEmpty(profileTokens)){ - String snapshotUrl=null; - String token = profileTokens.get(0); - BallheadPT ballheadPT=OnvifUtils.getPtzStatus(token,onvifBean); - //如果类型是球机转换指定点位 - if(device.getDeviceType().equals("3") && OnvifUtils.ptzCamera(token,onvifBean,device.getX(),device.getY(),device.getZ())){ - Thread.sleep(1000); - //拉取图片 - snapshotUrl = OnvifUtils.getSnapshotUrl(token,onvifBean); - if(snapshotUrl!=null){ - //转回原来位置 - OnvifUtils.ptzCamera(token,onvifBean,ballheadPT.getX(),ballheadPT.getY(),ballheadPT.getZ()); - } - //如果类型是固定枪机,直接获取图片 - }else{ - snapshotUrl = OnvifUtils.getSnapshotUrl(token,onvifBean); - } - //返回图片地址 - return Files.urlByImages(snapshotUrl,device.getAccount(),device.getPassword()); - } - return null; - } -} - - - - - - - diff --git a/device_cars/src/main/java/com/xr/device_car/config/utils/OnvifUtils.java b/device_cars/src/main/java/com/xr/device_car/config/utils/OnvifUtils.java deleted file mode 100644 index beab0ce..0000000 --- a/device_cars/src/main/java/com/xr/device_car/config/utils/OnvifUtils.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.xr.device_car.config.utils; - -import com.xr.device_car.config.common.RESTClient; -import com.xr.device_car.modules.analysis.entity.BallheadPT; -import com.xr.device_car.modules.analysis.entity.DigestBean; -import com.xr.device_car.modules.analysis.entity.OnvifAuthBean; -import com.xr.device_car.modules.analysis.entity.OnvifBean; -import org.springframework.core.io.ClassPathResource; -import org.springframework.util.StringUtils; - -import java.util.List; - -import static com.xr.device_car.config.common.Const.HEADERS_ONVIF_WWW_AUTHENTICATE; - - -public class OnvifUtils { - - - /** - * 获取鉴权 - * @param authType - * @param requestOnvifBean - * @param wsdl - * @param requestUrl - * @return - */ - public static String getAuthorization(String authType, OnvifBean requestOnvifBean, String wsdl, String requestUrl) { - //参数 - // 读取GetProfiles.wsdl - String getProfiles = FileUtil.fileReader(new ClassPathResource(wsdl)); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, getProfiles); - //如果是401的话 获取WWW-Authenticate 重新请求 - if (HttpResponseBean.isUnAuthorzied(httpResponseBean)) { - DigestBean digestBean = new DigestBean().getDigestBean(authType,requestOnvifBean, httpResponseBean.getFirstHeader(HEADERS_ONVIF_WWW_AUTHENTICATE).getValue()); - return digestBean.getToken(); - } - return null; - } - - - /** - * 获取Token - * @param requestOnvifBean - * @param auth - * @return - */ - public static List getProfileTokens(OnvifBean requestOnvifBean, String auth) { - //请求url - String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); - //参数 - // 读取GetProfiles.wsdl - String getProfiles = FileUtil.fileReader(new ClassPathResource("digest/GetProfiles.wsdl")); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, getProfiles,auth); - if(httpResponseBean != null) { - String resultStr = httpResponseBean.getBody(); - if (HttpResponseBean.isSuccess(httpResponseBean) && StringUtils.hasLength(resultStr)) { - return AnalysisXml.analysisTokens(resultStr); - } - - } - return null; - } - - - - - /** - * 获取截图地址 - * @param profileToken token - * @param requestOnvifBean - * @return - */ - public static String getSnapshotUrl(String profileToken, OnvifAuthBean requestOnvifBean) { - String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); - //参数 - // 读取GetProfiles.wsdl - String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/GetSnapshotUrl.wsdl")); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, String.format(snapshotUrlWsdl,profileToken),requestOnvifBean.getAuth()); - String resultStr = httpResponseBean.getBody(); - if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { - return AnalysisXml.analysisSnapshotUrl(resultStr); - } - return null; - } - //绝对位置转动球机 - public static boolean ptzCamera(String profileToken,OnvifAuthBean requestOnvifBean,String x,String y,String z){ - String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); - String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/AbsoluteMove.wsdl")); - String wsdl = String.format(snapshotUrlWsdl,profileToken,x,y,z); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); - String resultStr = httpResponseBean.getBody(); - if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { - return true; - } - return false; - } - //获取球机当前位置 - public static BallheadPT getPtzStatus(String token,OnvifAuthBean requestOnvifBean){ - String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); - String snap = FileUtil.fileReader(new ClassPathResource("digest/GetStatus.wsdl")); - String wsdl = String.format(snap,token); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); - String resultStr = httpResponseBean.getBody(); - if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { - return AnalysisXml.getStatus(resultStr); - } - return null; - } - //获取所有预置点 - public static List getBallHeadPts(String profileToken,OnvifAuthBean requestOnvifBean){ - String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); - String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/GetPresets.wsdl")); - String wsdl = String.format(snapshotUrlWsdl,profileToken); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); - String resultStr = httpResponseBean.getBody(); - if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { - return AnalysisXml.getBallheadPTs(resultStr); - } - return null; - } - - //前往指定预置点 - public static boolean gotoBallHeadPts(String profileToken, OnvifAuthBean requestOnvifBean, BallheadPT ballheadPT){ - String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); - String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/GotoPreset.wsdl")); - String wsdl = String.format(snapshotUrlWsdl,profileToken,ballheadPT.getId()); - HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() - .postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); - String resultStr = httpResponseBean.getBody(); - if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { - return true; - } - return false; - } -} diff --git a/device_cars/src/main/java/com/xr/device_car/config/utils/PythonExecutor.java b/device_cars/src/main/java/com/xr/device_car/config/utils/PythonExecutor.java index 67d6302..d9a46f8 100644 --- a/device_cars/src/main/java/com/xr/device_car/config/utils/PythonExecutor.java +++ b/device_cars/src/main/java/com/xr/device_car/config/utils/PythonExecutor.java @@ -4,7 +4,6 @@ import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xr.device_car.modules.analysis.entity.MeterInitialization; import com.xr.device_car.modules.analysis.service.IMeterInitializationService; -import com.xr.device_car.modules.analysis.service.MeterConfigService; import com.xr.device_car.modules.analysis.service.impl.MeterInitializationServiceImpl; import java.io.*; diff --git a/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterConfigController.java b/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterConfigController.java index 4e1b234..72294b2 100644 --- a/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterConfigController.java +++ b/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterConfigController.java @@ -13,6 +13,10 @@ import com.xr.device_car.modules.analysis.scheduled.TaskScheduler; import com.xr.device_car.modules.analysis.service.*; import com.xr.device_car.modules.analysis.vo.MeterMaxMinSaveVo; import com.xr.device_car.modules.system.entity.UserInfo; +import com.xr.onvifhk.entity.BallheadPT; +import com.xr.onvifhk.entity.DeviceInfo; +import com.xr.onvifhk.entity.OnvifAuthBean; +import com.xr.onvifhk.util.HkComUtil; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import lombok.RequiredArgsConstructor; @@ -406,6 +410,89 @@ public class MeterConfigController { return Result.OK(map1); } + @RequestMapping("/getStreamForthis") + public Result getStreamForthis(Integer id){ + MeterConfig config = meterConfigService.getById(id); + try{ + DeviceCamera deviceCamera = deviceCameraService.getById(config.getCameraId()); + DeviceInfo info=getDeviceInfo(deviceCamera); + if(StringUtils.isNotEmpty(config.getCameraX()) && + StringUtils.isNotEmpty(config.getCameraY())&& + StringUtils.isNotEmpty(config.getCameraZ())){ + playPtz(config,deviceCamera); + String url = HkComUtil.getRtspUrl(info); + config.setUrl(url); + }else{ + BallheadPT ballheadPT = HkComUtil.getBallhead(info); + if(ballheadPT!=null){ + float x = Float.valueOf(ballheadPT.getX()); + float y = Float.valueOf(ballheadPT.getY()); + float z = Float.valueOf(ballheadPT.getZ()); + config.setCameraX(String.format("%.1f",x)); + config.setCameraY(String.format("%.1f",y)); + config.setCameraZ(String.format("%.1f",z)); + String url = HkComUtil.getRtspUrl(info); + config.setUrl(url); + } + } + }catch (Exception e){ + e.printStackTrace(); + return Result.error(e.getMessage()); + } + return Result.OK(config); + } + + @RequestMapping("/playPtz") + public Result playPtz(MeterConfig config){ + try { + MeterConfig meterConfig = meterConfigService.getById(config.getId()); + DeviceCamera camera = deviceCameraService.getById(meterConfig.getCameraId()); + playPtz(config,camera); + }catch (Exception e){ + e.printStackTrace(); + return Result.error(e.getMessage()); + } + return Result.OK(); + } + + @RequestMapping("/savePoint") + public Result savePoint(MeterConfig config){ + MeterConfig config1 = meterConfigService.getById(config.getId()); + config1.setCameraZ(config.getCameraZ()); + config1.setCameraY(config.getCameraY()); + config1.setCameraX(config.getCameraX()); + meterConfigService.updateById(config1); + return Result.OK(); + } + + + + private void playPtz(MeterConfig config,DeviceCamera camera){ + DeviceInfo info=new DeviceInfo(); + info.setAccount(camera.getAccount()); + info.setIp(camera.getDeviceIp()); + info.setPassword(camera.getPassword()); + info.setPort(camera.getDevicePort()); + BallheadPT ballheadPT = new BallheadPT(); + float x = Float.valueOf(config.getCameraX()); + float y = Float.valueOf(config.getCameraY()); + float z = Float.valueOf(config.getCameraZ()); + ballheadPT.setX(String.format("%.1f",x)); + ballheadPT.setY(String.format("%.1f",y)); + ballheadPT.setZ(String.format("%.1f",z)); + OnvifAuthBean onvifAuthBean=HkComUtil.getOnvifAuthBean(info); + HkComUtil.ptzCamera(ballheadPT,onvifAuthBean); + } + + private DeviceInfo getDeviceInfo(DeviceCamera camera){ + DeviceInfo info=new DeviceInfo(); + info.setAccount(camera.getAccount()); + info.setIp(camera.getDeviceIp()); + info.setPassword(camera.getPassword()); + info.setPort(camera.getDevicePort()); + return info; + } + diff --git a/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/BallheadPT.java b/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/BallheadPT.java deleted file mode 100644 index 73d3d85..0000000 --- a/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/BallheadPT.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.xr.device_car.modules.analysis.entity; - -import lombok.Data; - -@Data -public class BallheadPT { - private String id; - - private String name; - - private String x; - - private String y; - - private String z; - -} diff --git a/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/DeviceCamera.java b/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/DeviceCamera.java index 652df1a..4d2a5cf 100644 --- a/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/DeviceCamera.java +++ b/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/DeviceCamera.java @@ -52,7 +52,7 @@ public class DeviceCamera implements Serializable { * 端口 */ @ExcelProperty(value = "端口") - private String devicePort; + private Integer devicePort; /** * 账号 diff --git a/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/MeterConfig.java b/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/MeterConfig.java index 172cb72..a86fb72 100644 --- a/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/MeterConfig.java +++ b/device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/MeterConfig.java @@ -35,6 +35,14 @@ public class MeterConfig implements Serializable { */ private String owningInterval; + + private String cameraX; + + private String cameraY; + + private String cameraZ; + + /** * 识别间隔 */ @@ -71,6 +79,9 @@ public class MeterConfig implements Serializable { @TableField(exist = false) private String cameraName; + @TableField(exist = false) + private String url; + /** * 表计类型配置编号 */ diff --git a/device_cars/src/main/resources/application-jiangcdev.yml b/device_cars/src/main/resources/application-jiangcdev.yml index 9c9fdbf..c1082bb 100644 --- a/device_cars/src/main/resources/application-jiangcdev.yml +++ b/device_cars/src/main/resources/application-jiangcdev.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-jiangcprod.yml b/device_cars/src/main/resources/application-jiangcprod.yml index 0f46cea..25506ce 100644 --- a/device_cars/src/main/resources/application-jiangcprod.yml +++ b/device_cars/src/main/resources/application-jiangcprod.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-jiaocdev.yml b/device_cars/src/main/resources/application-jiaocdev.yml index f7e4b91..8ebff65 100644 --- a/device_cars/src/main/resources/application-jiaocdev.yml +++ b/device_cars/src/main/resources/application-jiaocdev.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-jiaocprod.yml b/device_cars/src/main/resources/application-jiaocprod.yml index 9326b18..a392647 100644 --- a/device_cars/src/main/resources/application-jiaocprod.yml +++ b/device_cars/src/main/resources/application-jiaocprod.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-ppdev.yml b/device_cars/src/main/resources/application-ppdev.yml index 064934b..1856992 100644 --- a/device_cars/src/main/resources/application-ppdev.yml +++ b/device_cars/src/main/resources/application-ppdev.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-ppprod.yml b/device_cars/src/main/resources/application-ppprod.yml index 3bb5e95..37af787 100644 --- a/device_cars/src/main/resources/application-ppprod.yml +++ b/device_cars/src/main/resources/application-ppprod.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-psdev.yml b/device_cars/src/main/resources/application-psdev.yml index c8a9121..ec16c0d 100644 --- a/device_cars/src/main/resources/application-psdev.yml +++ b/device_cars/src/main/resources/application-psdev.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-psprod.yml b/device_cars/src/main/resources/application-psprod.yml index be5d576..f00d32f 100644 --- a/device_cars/src/main/resources/application-psprod.yml +++ b/device_cars/src/main/resources/application-psprod.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-sbdev.yml b/device_cars/src/main/resources/application-sbdev.yml index 90e4aae..bcbbdb4 100644 --- a/device_cars/src/main/resources/application-sbdev.yml +++ b/device_cars/src/main/resources/application-sbdev.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/application-sbprod.yml b/device_cars/src/main/resources/application-sbprod.yml index c7344e9..bae85c7 100644 --- a/device_cars/src/main/resources/application-sbprod.yml +++ b/device_cars/src/main/resources/application-sbprod.yml @@ -83,7 +83,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka minio: url: http://192.168.1.210:9000 accessKey: minioadmin diff --git a/device_cars/src/main/resources/digest/AbsoluteMove.wsdl b/device_cars/src/main/resources/digest/AbsoluteMove.wsdl deleted file mode 100644 index 7bb64b3..0000000 --- a/device_cars/src/main/resources/digest/AbsoluteMove.wsdl +++ /dev/null @@ -1,12 +0,0 @@ - - - - - %s - - - - - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetDeviceInformation.wsdl b/device_cars/src/main/resources/digest/GetDeviceInformation.wsdl deleted file mode 100644 index 9b65996..0000000 --- a/device_cars/src/main/resources/digest/GetDeviceInformation.wsdl +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetPTZ.wsdl b/device_cars/src/main/resources/digest/GetPTZ.wsdl deleted file mode 100644 index 5de3704..0000000 --- a/device_cars/src/main/resources/digest/GetPTZ.wsdl +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetPresets.wsdl b/device_cars/src/main/resources/digest/GetPresets.wsdl deleted file mode 100644 index de30d8c..0000000 --- a/device_cars/src/main/resources/digest/GetPresets.wsdl +++ /dev/null @@ -1,8 +0,0 @@ - - - - - %s - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetProfiles.wsdl b/device_cars/src/main/resources/digest/GetProfiles.wsdl deleted file mode 100644 index 92dc2cd..0000000 --- a/device_cars/src/main/resources/digest/GetProfiles.wsdl +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetSnapshotUrl.wsdl b/device_cars/src/main/resources/digest/GetSnapshotUrl.wsdl deleted file mode 100644 index 3b6f76a..0000000 --- a/device_cars/src/main/resources/digest/GetSnapshotUrl.wsdl +++ /dev/null @@ -1,8 +0,0 @@ - - - - - %s - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetStatus.wsdl b/device_cars/src/main/resources/digest/GetStatus.wsdl deleted file mode 100644 index 15f1e73..0000000 --- a/device_cars/src/main/resources/digest/GetStatus.wsdl +++ /dev/null @@ -1,8 +0,0 @@ - - - - - %s - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GetStreamUri.wsdl b/device_cars/src/main/resources/digest/GetStreamUri.wsdl deleted file mode 100644 index b8fae91..0000000 --- a/device_cars/src/main/resources/digest/GetStreamUri.wsdl +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - %s - %s - %s - %s - - - - - - - - RTP-Unicast - - %s - - - %s - - - \ No newline at end of file diff --git a/device_cars/src/main/resources/digest/GotoPreset.wsdl b/device_cars/src/main/resources/digest/GotoPreset.wsdl deleted file mode 100644 index 330014e..0000000 --- a/device_cars/src/main/resources/digest/GotoPreset.wsdl +++ /dev/null @@ -1,9 +0,0 @@ - - - - - %s - %s - - - \ No newline at end of file diff --git a/device_display/src/main/resources/application-dev.yml b/device_display/src/main/resources/application-dev.yml index 41f90b4..0c8072a 100644 --- a/device_display/src/main/resources/application-dev.yml +++ b/device_display/src/main/resources/application-dev.yml @@ -104,4 +104,4 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka \ No newline at end of file + defaultZone: http://localhost:8184/eureka \ No newline at end of file diff --git a/device_eureka/src/main/resources/application.yml b/device_eureka/src/main/resources/application.yml index 8fbe257..95b2dad 100644 --- a/device_eureka/src/main/resources/application.yml +++ b/device_eureka/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8084 + port: 8184 eureka: diff --git a/device_gateway/src/main/resources/application.yml b/device_gateway/src/main/resources/application.yml index 1f55d79..058cb3a 100644 --- a/device_gateway/src/main/resources/application.yml +++ b/device_gateway/src/main/resources/application.yml @@ -60,7 +60,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka server: port: 8090 servlet: diff --git a/device_gather/pom.xml b/device_gather/pom.xml index 7388ac8..061ead1 100644 --- a/device_gather/pom.xml +++ b/device_gather/pom.xml @@ -136,6 +136,16 @@ onvif-hk 3.1.0 + + io.netty + netty-all + 4.1.65.Final + + + + org.springframework.boot + spring-boot-starter-websocket + diff --git a/device_gather/src/main/java/com/xr/device/DeviceGatherApplication.java b/device_gather/src/main/java/com/xr/device/DeviceGatherApplication.java index 26f8c70..b9b1667 100644 --- a/device_gather/src/main/java/com/xr/device/DeviceGatherApplication.java +++ b/device_gather/src/main/java/com/xr/device/DeviceGatherApplication.java @@ -1,19 +1,38 @@ package com.xr.device; +import com.xr.device.netty.NettyServer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @EnableScheduling//开启定时任务 @SpringBootApplication @EnableDiscoveryClient @EnableFeignClients -public class DeviceGatherApplication { +@EnableAsync//开启异步 +public class DeviceGatherApplication implements CommandLineRunner { + + private final NettyServer nettyServer; + + @Autowired + public DeviceGatherApplication(NettyServer nettyServer) { + this.nettyServer = nettyServer; + } public static void main(String[] args) { SpringApplication.run(DeviceGatherApplication.class, args); } + @Async + @Override + public void run(String... args) throws Exception { + nettyServer.start(); + } + } diff --git a/device_gather/src/main/java/com/xr/device/netty/DeviceHandler.java b/device_gather/src/main/java/com/xr/device/netty/DeviceHandler.java new file mode 100644 index 0000000..1e200d6 --- /dev/null +++ b/device_gather/src/main/java/com/xr/device/netty/DeviceHandler.java @@ -0,0 +1,60 @@ +package com.xr.device.netty; + +import com.xr.device.websocket.DeviceWebSocketHandler; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.util.ReferenceCountUtil; + +public class DeviceHandler extends ChannelInboundHandlerAdapter { + + private final HeartbeatService heartbeatService; + + private final DeviceWebSocketHandler deviceWebSocketHandler; + + public DeviceHandler(HeartbeatService heartbeatService,DeviceWebSocketHandler deviceWebSocketHandler) { + this.heartbeatService = heartbeatService; + this.deviceWebSocketHandler = deviceWebSocketHandler; + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + heartbeatService.addChannel(ctx.channel()); + super.channelActive(ctx); + } + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + heartbeatService.removeChannel(ctx.channel()); + super.channelInactive(ctx); + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + ByteBuf in = (ByteBuf) msg; + try { + String deviceId = ""; // 从消息中提取设备ID + String data = ""; // 从消息中提取其他数据 + + while (in.isReadable()) { + deviceId += (char) in.readByte(); + } + + + + // 通过WebSocket实时更新状态 + deviceWebSocketHandler.sendMessageToAll("Device " + deviceId); + + System.out.print(data); + System.out.flush(); + } finally { + ReferenceCountUtil.release(msg); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + cause.printStackTrace(); + ctx.close(); + } +} diff --git a/device_gather/src/main/java/com/xr/device/netty/HeartbeatService.java b/device_gather/src/main/java/com/xr/device/netty/HeartbeatService.java new file mode 100644 index 0000000..afe0fc9 --- /dev/null +++ b/device_gather/src/main/java/com/xr/device/netty/HeartbeatService.java @@ -0,0 +1,34 @@ +package com.xr.device.netty; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelId; +import io.netty.util.CharsetUtil; +import io.netty.buffer.Unpooled; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Service +public class HeartbeatService { + + private final Map channels = new ConcurrentHashMap<>(); + + @Scheduled(fixedRate = 5000) + public void sendHeartbeat() { + for (Channel channel : channels.values()) { + if (channel.isOpen()) { + channel.writeAndFlush(Unpooled.copiedBuffer("Heartbeat", CharsetUtil.UTF_8)); + } + } + } + + public void addChannel(Channel channel) { + channels.put(channel.id(), channel); + } + + public void removeChannel(Channel channel) { + channels.remove(channel.id()); + } +} diff --git a/device_gather/src/main/java/com/xr/device/netty/NettyConfig.java b/device_gather/src/main/java/com/xr/device/netty/NettyConfig.java new file mode 100644 index 0000000..3d15615 --- /dev/null +++ b/device_gather/src/main/java/com/xr/device/netty/NettyConfig.java @@ -0,0 +1,18 @@ +package com.xr.device.netty; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class NettyConfig { + + @Bean + public HeartbeatService heartbeatService() { + return new HeartbeatService(); + } + + @Bean + public NettyServer nettyServer(HeartbeatService heartbeatService) { + return new NettyServer(heartbeatService); + } +} diff --git a/device_gather/src/main/java/com/xr/device/netty/NettyServer.java b/device_gather/src/main/java/com/xr/device/netty/NettyServer.java new file mode 100644 index 0000000..2f6957e --- /dev/null +++ b/device_gather/src/main/java/com/xr/device/netty/NettyServer.java @@ -0,0 +1,45 @@ +package com.xr.device.netty; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; + +public class NettyServer { + + private final int port = 8520; + private final HeartbeatService heartbeatService; + + public NettyServer(HeartbeatService heartbeatService) { + this.heartbeatService = heartbeatService; + } + + public void start() throws InterruptedException { + EventLoopGroup bossGroup = new NioEventLoopGroup(1); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + ServerBootstrap bootstrap = new ServerBootstrap(); + bootstrap.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ChannelInitializer() { + @Override + protected void initChannel(SocketChannel ch) { + ch.pipeline().addLast(new DeviceHandler(heartbeatService)); + } + }) + .option(ChannelOption.SO_BACKLOG, 128) + .childOption(ChannelOption.SO_KEEPALIVE, true); + + ChannelFuture f = bootstrap.bind(port).sync(); + f.channel().closeFuture().sync(); + } finally { + workerGroup.shutdownGracefully(); + bossGroup.shutdownGracefully(); + } + } +} diff --git a/device_gather/src/main/java/com/xr/device/websocket/DeviceWebSocketHandler.java b/device_gather/src/main/java/com/xr/device/websocket/DeviceWebSocketHandler.java new file mode 100644 index 0000000..179cb36 --- /dev/null +++ b/device_gather/src/main/java/com/xr/device/websocket/DeviceWebSocketHandler.java @@ -0,0 +1,45 @@ +package com.xr.device.websocket; + +import org.springframework.stereotype.Component; +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; +import org.springframework.web.socket.TextMessage; + +import java.util.concurrent.ConcurrentHashMap; + +@Component +public class DeviceWebSocketHandler extends TextWebSocketHandler { + + private final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + sessions.put(session.getId(), session); + } + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + // 处理来自客户端的消息 + } + + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { + sessions.remove(session.getId()); + } + + public void sendMessageToAll(String message) throws Exception { + for (WebSocketSession session : sessions.values()) { + if (session.isOpen()) { + session.sendMessage(new TextMessage(message)); + } + } + } + + public void sendMessageToSession(String sessionId, String message) throws Exception { + WebSocketSession session = sessions.get(sessionId); + if (session != null && session.isOpen()) { + session.sendMessage(new TextMessage(message)); + } + } +} diff --git a/device_gather/src/main/java/com/xr/device/websocket/WebSocketConfig.java b/device_gather/src/main/java/com/xr/device/websocket/WebSocketConfig.java new file mode 100644 index 0000000..0b321c6 --- /dev/null +++ b/device_gather/src/main/java/com/xr/device/websocket/WebSocketConfig.java @@ -0,0 +1,22 @@ +package com.xr.device.websocket; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; + +@Configuration +@EnableWebSocket +public class WebSocketConfig implements WebSocketConfigurer { + + private final DeviceWebSocketHandler deviceWebSocketHandler; + + public WebSocketConfig(DeviceWebSocketHandler deviceWebSocketHandler) { + this.deviceWebSocketHandler = deviceWebSocketHandler; + } + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(deviceWebSocketHandler, "/websocket/device"); + } +} diff --git a/device_gather/src/main/resources/application-jcDev.yml b/device_gather/src/main/resources/application-jcDev.yml index 743d432..6532e94 100644 --- a/device_gather/src/main/resources/application-jcDev.yml +++ b/device_gather/src/main/resources/application-jcDev.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 2 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-jcProd.yml b/device_gather/src/main/resources/application-jcProd.yml index 743d432..6532e94 100644 --- a/device_gather/src/main/resources/application-jcProd.yml +++ b/device_gather/src/main/resources/application-jcProd.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 2 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-jiangcDev.yml b/device_gather/src/main/resources/application-jiangcDev.yml index d7de24c..3760513 100644 --- a/device_gather/src/main/resources/application-jiangcDev.yml +++ b/device_gather/src/main/resources/application-jiangcDev.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 5 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-jiangcProd.yml b/device_gather/src/main/resources/application-jiangcProd.yml index d7de24c..3760513 100644 --- a/device_gather/src/main/resources/application-jiangcProd.yml +++ b/device_gather/src/main/resources/application-jiangcProd.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 5 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-ppDev.yml b/device_gather/src/main/resources/application-ppDev.yml index 608eee6..a85e0da 100644 --- a/device_gather/src/main/resources/application-ppDev.yml +++ b/device_gather/src/main/resources/application-ppDev.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 4 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-ppProd.yml b/device_gather/src/main/resources/application-ppProd.yml index 608eee6..a85e0da 100644 --- a/device_gather/src/main/resources/application-ppProd.yml +++ b/device_gather/src/main/resources/application-ppProd.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 4 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-psDev.yml b/device_gather/src/main/resources/application-psDev.yml index 1f57926..e94900a 100644 --- a/device_gather/src/main/resources/application-psDev.yml +++ b/device_gather/src/main/resources/application-psDev.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 3 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-psProd.yml b/device_gather/src/main/resources/application-psProd.yml index 1f57926..e94900a 100644 --- a/device_gather/src/main/resources/application-psProd.yml +++ b/device_gather/src/main/resources/application-psProd.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 3 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-sbDev.yml b/device_gather/src/main/resources/application-sbDev.yml index e5545f4..ca96545 100644 --- a/device_gather/src/main/resources/application-sbDev.yml +++ b/device_gather/src/main/resources/application-sbDev.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 1 \ No newline at end of file diff --git a/device_gather/src/main/resources/application-sbProd.yml b/device_gather/src/main/resources/application-sbProd.yml index e5545f4..ca96545 100644 --- a/device_gather/src/main/resources/application-sbProd.yml +++ b/device_gather/src/main/resources/application-sbProd.yml @@ -77,6 +77,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka station: id: 1 \ No newline at end of file diff --git a/device_iec104/src/main/resources/application-dev.yml b/device_iec104/src/main/resources/application-dev.yml index 2407832..bcaee21 100644 --- a/device_iec104/src/main/resources/application-dev.yml +++ b/device_iec104/src/main/resources/application-dev.yml @@ -53,6 +53,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 \ No newline at end of file diff --git a/device_iec104/src/main/resources/application-prod.yml b/device_iec104/src/main/resources/application-prod.yml index 13e7eaf..d12cb79 100644 --- a/device_iec104/src/main/resources/application-prod.yml +++ b/device_iec104/src/main/resources/application-prod.yml @@ -53,6 +53,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 \ No newline at end of file diff --git a/device_iec61850clent/src/main/resources/application-dev.yml b/device_iec61850clent/src/main/resources/application-dev.yml index 507aa08..00765e6 100644 --- a/device_iec61850clent/src/main/resources/application-dev.yml +++ b/device_iec61850clent/src/main/resources/application-dev.yml @@ -76,7 +76,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 diff --git a/device_iec61850clent/src/main/resources/application-prod.yml b/device_iec61850clent/src/main/resources/application-prod.yml index 317334c..f3cdcb2 100644 --- a/device_iec61850clent/src/main/resources/application-prod.yml +++ b/device_iec61850clent/src/main/resources/application-prod.yml @@ -76,7 +76,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 diff --git a/device_iec61850clent/src/main/resources/application-test.yml b/device_iec61850clent/src/main/resources/application-test.yml index 8b01f66..564ba31 100644 --- a/device_iec61850clent/src/main/resources/application-test.yml +++ b/device_iec61850clent/src/main/resources/application-test.yml @@ -76,6 +76,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 \ No newline at end of file diff --git a/device_iec61850server/src/main/resources/application-dev.yml b/device_iec61850server/src/main/resources/application-dev.yml index f89e542..37b6a5f 100644 --- a/device_iec61850server/src/main/resources/application-dev.yml +++ b/device_iec61850server/src/main/resources/application-dev.yml @@ -53,7 +53,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 diff --git a/device_iec61850server/src/main/resources/application-prod.yml b/device_iec61850server/src/main/resources/application-prod.yml index 4d4823f..1bc5a14 100644 --- a/device_iec61850server/src/main/resources/application-prod.yml +++ b/device_iec61850server/src/main/resources/application-prod.yml @@ -53,6 +53,6 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 \ No newline at end of file diff --git a/device_iec61850server/src/main/resources/application-test.yml b/device_iec61850server/src/main/resources/application-test.yml index 6131f1b..988f421 100644 --- a/device_iec61850server/src/main/resources/application-test.yml +++ b/device_iec61850server/src/main/resources/application-test.yml @@ -53,7 +53,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka device: deviceId: 3 diff --git a/device_modbus/src/main/resources/application-dev.yml b/device_modbus/src/main/resources/application-dev.yml index 2d0f3c0..ead32d5 100644 --- a/device_modbus/src/main/resources/application-dev.yml +++ b/device_modbus/src/main/resources/application-dev.yml @@ -54,7 +54,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka iec61850: path: D://iec61850//iec61850.cid diff --git a/device_modbus/src/main/resources/application-prod.yml b/device_modbus/src/main/resources/application-prod.yml index 7c32753..696e6e7 100644 --- a/device_modbus/src/main/resources/application-prod.yml +++ b/device_modbus/src/main/resources/application-prod.yml @@ -54,7 +54,7 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka + defaultZone: http://localhost:8184/eureka iec61850: path: /app/project/IEC61850/iec61850.cid diff --git a/device_udpclent/src/main/resources/application-dev.yml b/device_udpclent/src/main/resources/application-dev.yml index 71ae995..bc91260 100644 --- a/device_udpclent/src/main/resources/application-dev.yml +++ b/device_udpclent/src/main/resources/application-dev.yml @@ -104,4 +104,4 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka \ No newline at end of file + defaultZone: http://localhost:8184/eureka \ No newline at end of file diff --git a/device_udpclent/src/main/resources/application-prod.yml b/device_udpclent/src/main/resources/application-prod.yml index a3b5238..2368de0 100644 --- a/device_udpclent/src/main/resources/application-prod.yml +++ b/device_udpclent/src/main/resources/application-prod.yml @@ -104,4 +104,4 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka \ No newline at end of file + defaultZone: http://localhost:8184/eureka \ No newline at end of file diff --git a/device_udpclent/src/main/resources/application-sn.yml b/device_udpclent/src/main/resources/application-sn.yml index ba10faf..a735eab 100644 --- a/device_udpclent/src/main/resources/application-sn.yml +++ b/device_udpclent/src/main/resources/application-sn.yml @@ -104,4 +104,4 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka \ No newline at end of file + defaultZone: http://localhost:8184/eureka \ No newline at end of file diff --git a/device_udpserver/src/main/resources/application-dev.yml b/device_udpserver/src/main/resources/application-dev.yml index 2ef071f..4c0c9f2 100644 --- a/device_udpserver/src/main/resources/application-dev.yml +++ b/device_udpserver/src/main/resources/application-dev.yml @@ -91,4 +91,4 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka \ No newline at end of file + defaultZone: http://localhost:8184/eureka \ No newline at end of file diff --git a/device_udpserver/src/main/resources/application-prod.yml b/device_udpserver/src/main/resources/application-prod.yml index 2511ec6..32cdb77 100644 --- a/device_udpserver/src/main/resources/application-prod.yml +++ b/device_udpserver/src/main/resources/application-prod.yml @@ -91,4 +91,4 @@ eureka: healthcheck: enabled: true service-url: - defaultZone: http://localhost:8084/eureka \ No newline at end of file + defaultZone: http://localhost:8184/eureka \ No newline at end of file diff --git a/drone_data/pom.xml b/drone_data/pom.xml index 758fffd..d06ac17 100644 --- a/drone_data/pom.xml +++ b/drone_data/pom.xml @@ -102,7 +102,11 @@ segment 0.3.0 - + + commons-net + commons-net + 3.8.0 + diff --git a/drone_data/src/main/java/com/xr/drone/DroneDataApplication.java b/drone_data/src/main/java/com/xr/drone/DroneDataApplication.java index 384a89d..47d0d22 100644 --- a/drone_data/src/main/java/com/xr/drone/DroneDataApplication.java +++ b/drone_data/src/main/java/com/xr/drone/DroneDataApplication.java @@ -3,6 +3,7 @@ package com.xr.drone; import com.xr.drone.aliyun.common.emqx.MqttConfiguration; import com.xr.drone.aliyun.common.emqx.MqttConnect; import com.xr.drone.clent.MqttClent; +import com.xr.drone.ntp.NtpService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -20,8 +21,13 @@ import org.springframework.web.filter.CorsFilter; //@EnableConfigurationProperties(MqttConfiguration.class) public class DroneDataApplication implements CommandLineRunner { - @Autowired - MqttConfiguration mqttConfiguration; + private final NtpService ntpService; + private final MqttConfiguration mqttConfiguration; + + public DroneDataApplication(NtpService ntpService,MqttConfiguration mqttConfiguration) { + this.ntpService = ntpService; + this.mqttConfiguration=mqttConfiguration; + } public static void main(String[] args) { try{ @@ -52,6 +58,7 @@ public class DroneDataApplication implements CommandLineRunner { mqttClent.start(); // MqttConnect mqttConnect = new MqttConnect(mqttConfiguration); // mqttConnect.start(); + ntpService.start(); } } diff --git a/drone_data/src/main/java/com/xr/drone/demo/Demo.java b/drone_data/src/main/java/com/xr/drone/demo/Demo.java deleted file mode 100644 index e69efde..0000000 --- a/drone_data/src/main/java/com/xr/drone/demo/Demo.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.xr.drone.demo; - -import java.io.IOException; -import java.text.SimpleDateFormat; - -import com.jnrsmcu.sdk.netdevice.IDataListener; -import com.jnrsmcu.sdk.netdevice.LoginData; -import com.jnrsmcu.sdk.netdevice.NodeData; -import com.jnrsmcu.sdk.netdevice.ParamData; -import com.jnrsmcu.sdk.netdevice.ParamIdsData; -import com.jnrsmcu.sdk.netdevice.ParamItem; -import com.jnrsmcu.sdk.netdevice.RSServer; -import com.jnrsmcu.sdk.netdevice.RealTimeData; -import com.jnrsmcu.sdk.netdevice.StoreData; -import com.jnrsmcu.sdk.netdevice.TelecontrolAck; -import com.jnrsmcu.sdk.netdevice.TimmingAck; -import com.jnrsmcu.sdk.netdevice.TransDataAck; -import com.jnrsmcu.sdk.netdevice.WriteParamAck; - -public class Demo { - - public static void main(String[] args) throws IOException, - InterruptedException { - //RSServer rsServer = RSServer.Initiate(2404);// 初始化 - RSServer rsServer = RSServer.Initiate(2404,"C:\\Users\\PC\\Desktop\\JavaSDKV2.2.2\\param.dat"); - rsServer.addDataListener(new IDataListener() {// 添加监听 - @Override - public void receiveTimmingAck(TimmingAck data) {// 校时指令应答处理 - System.out.println("校时应答->设备编号:" + data.getDeviceId() - + "\t执行结果:" + data.getStatus()); - } - - @Override - public void receiveTelecontrolAck(TelecontrolAck data) {// 遥控指令应答处理 - System.out.println("遥控应答->设备编号:" + data.getDeviceId() - + "\t继电器编号:" + data.getRelayId() + "\t执行结果:" - + data.getStatus()); - } - - @Override - public void receiveStoreData(StoreData data) {// 已存储数据接收处理 - // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 - for (NodeData nd : data.getNodeList()) { - SimpleDateFormat sdf = new SimpleDateFormat( - "yy-MM-dd HH:mm:ss"); - String str = sdf.format(nd.getRecordTime()); - System.out.println("存储数据->设备地址:" + data.getDeviceId() - + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem() - + "\t湿度:" + nd.getHum() + "\t存储时间:" + str); - } - - } - - @Override - public void receiveRealtimeData(RealTimeData data) {// 实时数据接收处理 - // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 - for (NodeData nd : data.getNodeList()) { - System.out.println("实时数据->设备地址:" + data.getDeviceId() - + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem() - + "\t湿度:" + nd.getHum() + "\t经度:" + data.getLng() - + "\t纬度:" + data.getLat() + "\t坐标类型:" - + data.getCoordinateType() + "\t继电器状态:" - + data.getRelayStatus()); - } - - } - - @Override - public void receiveLoginData(LoginData data) {// 登录数据接收处理 - System.out.println("登录->设备地址:" + data.getDeviceId()); - - } - - @Override - public void receiveParamIds(ParamIdsData data) { - String str = "设备参数编号列表->设备编号:" + data.getDeviceId() - + "\t参数总数量:" + data.getTotalCount() + "\t本帧参数数量:" - + data.getCount() + "\r\n"; - for (int paramId : data.getPararmIdList())// 遍历设备中参数id编号 - { - str += paramId + ","; - } - System.out.println(str); - - } - - @Override - public void receiveParam(ParamData data) { - String str = "设备参数->设备编号:" + data.getDeviceId() + "\r\n"; - - for (ParamItem pararm : data.getParameterList()) { - str += "参数编号:" - + pararm.getParamId() - + "\t参数描述:" - + pararm.getDescription() - + "\t参数值:" - + (pararm.getValueDescription() == null ? pararm - .getValue() : pararm.getValueDescription() - .get(pararm.getValue())) + "\r\n"; - } - System.out.println(str); - - } - - @Override - public void receiveWriteParamAck(WriteParamAck data) { - String str = "下载设备参数->设备编号:" + data.getDeviceId() + "\t参数数量:" - + data.getCount() + "\t" - + (data.isSuccess() ? "下载成功" : "下载失败"); - System.out.println(str); - - } - - @Override - public void receiveTransDataAck(TransDataAck data) { - String str = "数据透传->设备编号:" + data.getDeviceId() + "\t响应结果:" - + data.getData() + "\r\n字节数:" + data.getTransDataLen(); - System.out.println(str); - - } - }); - rsServer.start(); - - } - -} diff --git a/drone_data/src/main/java/com/xr/drone/ntp/NtpService.java b/drone_data/src/main/java/com/xr/drone/ntp/NtpService.java new file mode 100644 index 0000000..26e4d85 --- /dev/null +++ b/drone_data/src/main/java/com/xr/drone/ntp/NtpService.java @@ -0,0 +1,93 @@ +package com.xr.drone.ntp; + +import org.apache.commons.net.ntp.NTPUDPClient; +import org.apache.commons.net.ntp.TimeInfo; +import org.springframework.stereotype.Service; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.nio.ByteBuffer; +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Arrays; + +@Service +public class NtpService implements Runnable { + + private static final int NTP_PORT = 1123; + private static final long NTP_TIMESTAMP_OFFSET = 2208988800L; + + public void start() { + new Thread(this).start(); + } + + @Override + public void run() { + try (DatagramSocket socket = new DatagramSocket(NTP_PORT)) { + byte[] buffer = new byte[48]; + while (true) { + DatagramPacket requestPacket = new DatagramPacket(buffer, buffer.length); + socket.receive(requestPacket); + + long currentTime = System.currentTimeMillis() / 1000 + NTP_TIMESTAMP_OFFSET; + ByteBuffer responseBuffer = ByteBuffer.allocate(48); + Arrays.fill(responseBuffer.array(), (byte) 0); + + responseBuffer.put(0, (byte) 0x24); // LI, Version, Mode + responseBuffer.put(1, (byte) 1); // Stratum + responseBuffer.put(2, (byte) 0); // Poll + responseBuffer.put(3, (byte) -20); // Precision + + responseBuffer.putInt(4, 0); // Root Delay + responseBuffer.putInt(8, 0); // Root Dispersion + responseBuffer.putInt(12, 0x4C4F434C); // Reference Identifier ("LOCL") + + responseBuffer.putLong(16, currentTime << 32); // Reference Timestamp + responseBuffer.putLong(24, ByteBuffer.wrap(requestPacket.getData(), 40, 8).getLong()); // Originate Timestamp + responseBuffer.putLong(32, currentTime << 32); // Receive Timestamp + responseBuffer.putLong(40, currentTime << 32); // Transmit Timestamp + + DatagramPacket responsePacket = new DatagramPacket( + responseBuffer.array(), + responseBuffer.array().length, + requestPacket.getAddress(), + requestPacket.getPort() + ); + socket.send(responsePacket); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static void main(String[] args) { + String serverAddress = "192.168.1.83"; // 替换为你的NTP服务器IP + int port = 1123; // 使用端口1123 + + try { + NTPUDPClient client = new NTPUDPClient(); + client.setDefaultTimeout(10000); + client.open(); + + InetAddress hostAddr = InetAddress.getByName(serverAddress); + TimeInfo info = client.getTime(hostAddr, port); + + // 处理时间信息 + long returnTime = info.getReturnTime(); + long receiveTime = info.getMessage().getReceiveTimeStamp().getTime(); + long transmitTime = info.getMessage().getTransmitTimeStamp().getTime(); + + System.out.println("NTP Server Time: " + receiveTime); + System.out.println("Local Return Time: " + returnTime); + System.out.println("Transmit Time: " + transmitTime); + + client.close(); + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/drone_data/src/main/resources/application-dev.yml b/drone_data/src/main/resources/application-dev.yml index a5587af..e307e96 100644 --- a/drone_data/src/main/resources/application-dev.yml +++ b/drone_data/src/main/resources/application-dev.yml @@ -33,7 +33,7 @@ spring: mqtt: username: admin password: admin123 - url: tcp://116.196.120.81:1883 + url: tcp://192.168.1.83:1883 client: id: 123456 default: