From 445ff37b6554ce413d63e59a2276a685ef591f6a Mon Sep 17 00:00:00 2001 From: pnoker Date: Wed, 19 Aug 2020 23:27:57 +0800 Subject: [PATCH 01/10] . --- .../service/impl/CustomDriverServiceImpl.java | 33 +-------------- .../dc3/driver/service/netty/NettyServer.java | 8 ---- .../service/netty/NettyServerHandler.java | 41 ++++++++++--------- 3 files changed, 24 insertions(+), 58 deletions(-) diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java index 12767949f..4cc9e04a6 100644 --- a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java +++ b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java @@ -16,24 +16,18 @@ package com.dc3.driver.service.impl; -import com.dc3.common.constant.Common; import com.dc3.common.model.Device; import com.dc3.common.model.Point; import com.dc3.common.sdk.bean.AttributeInfo; -import com.dc3.common.sdk.bean.DriverContext; import com.dc3.common.sdk.service.CustomDriverService; -import com.dc3.common.sdk.service.rabbit.DriverService; import com.dc3.driver.service.netty.NettyServer; -import io.netty.channel.Channel; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; /** * @author pnoker @@ -48,10 +42,6 @@ public class CustomDriverServiceImpl implements CustomDriverService { @Resource private NettyServer nettyServer; @Resource - private DriverContext driverContext; - @Resource - private DriverService driverService; - @Resource private ThreadPoolExecutor threadPoolExecutor; @Override @@ -69,31 +59,12 @@ public class CustomDriverServiceImpl implements CustomDriverService { @Override public Boolean write(Map driverInfo, Map pointInfo, Device device, AttributeInfo value) throws Exception { - Long deviceId = device.getId(); - - // TODO 获取设备的Channel,并向下发送数据 - Channel channel = NettyServer.deviceChannelMap.get(deviceId); - if (null != channel) { - channel.writeAndFlush(value.getValue().getBytes(StandardCharsets.UTF_8)); - } - return true; + return false; } @Override public void schedule() { - - /* - TODO:设备状态 - 上传设备状态,可自行灵活拓展,不一定非要在schedule()接口中实现,也可以在read中实现设备状态的设置; - 你可以通过某种判断机制确定设备的状态,然后通过driverService.deviceStatusSender(deviceId,DeviceStatus)接口将设备状态交给SDK管理。 - - 设备状态(DeviceStatus)如下: - ONLINE:在线 - OFFLINE:离线 - MAINTAIN:维护 - FAULT:故障 - */ - driverContext.getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, Common.Device.ONLINE, 1, TimeUnit.HOURS)); + log.info("schedule not implemented"); } } diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServer.java b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServer.java index f5a5d8a20..e24465c16 100644 --- a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServer.java +++ b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServer.java @@ -17,7 +17,6 @@ package com.dc3.driver.service.netty; import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; @@ -29,19 +28,12 @@ import lombok.SneakyThrows; import org.springframework.stereotype.Component; import java.net.InetSocketAddress; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * @author pnoker */ @Component public class NettyServer { - /** - * DeviceId:Channel - * 用于存放设备的 Netty Context Channel - */ - public static Map deviceChannelMap = new ConcurrentHashMap<>(16); @SneakyThrows public void start(int port) { diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java index cc5014f95..783afacdd 100644 --- a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java @@ -112,16 +112,20 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { * * @return PointValue */ - private void customDecode(int start, long deviceId, long pointId, PointValue pointValue) { + private String customDecode(int start, String value) { //信号强度额外处理 if (start == 163) { - String value = that.driverService.convertValue(deviceId, pointId, pointValue.getValue()); int csq = (int) Double.parseDouble(value); if (csq > 0) { csq -= 200; } - pointValue.setValue(String.valueOf(csq)); + value = String.valueOf(csq); } + return value; + } + + private int intDecode(ByteBuf byteBuf) { + return byteBuf.getIntLE(0); } @Override @@ -171,28 +175,27 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { value = that.driverService.convertValue(deviceId, pointId, rawValue); break; case Common.ValueType.INT: - int intValue; - if (length != 4) { - ByteBuf copy = byteBuf.copy(start, length); - int i = length; - while (i < 4) { - copy.writeBytes(new byte[]{0x00}); - i++; - } - intValue = copy.getIntLE(0); - } else { - intValue = byteBuf.getIntLE(start); - } + int intValue = intDecode(byteBuf.copy(start, length)); +// if (length != 4) { +// ByteBuf copy = byteBuf.copy(start, length); +// int i = length; +// while (i < 4) { +// copy.writeBytes(new byte[]{0x00}); +// i++; +// } +// intValue = copy.getIntLE(0); +// } else { +// intValue = byteBuf.getIntLE(start); +// } rawValue = String.valueOf(intValue); value = that.driverService.convertValue(deviceId, pointId, rawValue); break; default: throw new IllegalStateException("Unexpected value: " + type.toLowerCase()); } - PointValue pointValue = new PointValue(pointId, rawValue, value); - customDecode(start, deviceId, pointId, pointValue); - log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length).toUpperCase(), pointValue.getRawValue(), pointValue.getValue()); - return pointValue; + value = customDecode(start, value); + log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length).toUpperCase(), rawValue, value); + return new PointValue(pointId, rawValue, value); } } \ No newline at end of file From 6b6256f02110e2a5fb776f46825f562e636eb8f6 Mon Sep 17 00:00:00 2001 From: pnoker Date: Thu, 20 Aug 2020 00:06:42 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dc3/common/sdk/util/DriverUtils.java | 41 ++++++++++ .../service/netty/NettyServerHandler.java | 81 +++++++++---------- .../com/dc3/gateway/GatewayApplication.java | 1 - 3 files changed, 78 insertions(+), 45 deletions(-) diff --git a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/util/DriverUtils.java b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/util/DriverUtils.java index 5e0cca6e1..eb26a5c94 100644 --- a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/util/DriverUtils.java +++ b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/util/DriverUtils.java @@ -95,6 +95,47 @@ public class DriverUtils { return sb.toString(); } + /** + * byte数组到int的转换(大端) + * + * @param bytes Byte Array + * @return Integer + */ + public static int bytesToInt(byte[] bytes) { + byte[] temp = new byte[4]; + int length = bytes.length; + System.arraycopy(bytes, 0, temp, 0, length); + for (int i = length; i < 4; i++) { + temp[i] = 0x00; + } + int int1 = temp[3] & 0xff; + int int2 = (temp[2] & 0xff) << 8; + int int3 = (temp[1] & 0xff) << 16; + int int4 = (temp[0] & 0xff) << 24; + + return int1 | int2 | int3 | int4; + } + + /** + * byte数组到int的转换(小端) + * + * @param bytes Byte Array + * @return Integer + */ + public static int bytesToIntLE(byte[] bytes) { + byte[] temp = new byte[4]; + int length = bytes.length; + System.arraycopy(bytes, 0, temp, 0, length); + for (int i = length; i < 4; i++) { + temp[i] = 0x00; + } + int int1 = temp[0] & 0xff; + int int2 = (temp[1] & 0xff) << 8; + int int3 = (temp[2] & 0xff) << 16; + int int4 = (temp[3] & 0xff) << 24; + return int1 | int2 | int3 | int4; + } + /** * 将byte[]转成Ascii码 * diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java index 783afacdd..59791f101 100644 --- a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java @@ -107,6 +107,42 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { @Resource private DriverContext driverContext; + /** + * 解析 Point Value 数据 + * + * @param deviceId Device Id + * @param pointId Point Id + * @param infoMap Point Info Map + * @param byteBuf ByteBuf + * @return PointValue + */ + private PointValue pointValueDecode(long deviceId, long pointId, Map infoMap, ByteBuf byteBuf) { + String type = DriverUtils.value(infoMap.get("type").getType(), infoMap.get("type").getValue()); + int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue()); + int length = DriverUtils.value(infoMap.get("length").getType(), infoMap.get("length").getValue()); + + String rawValue, value; + switch (type.toLowerCase()) { + case Common.ValueType.HEX: + rawValue = ByteBufUtil.hexDump(byteBuf.retainedSlice(start, length)).toUpperCase(); + value = that.driverService.convertValue(deviceId, pointId, rawValue); + break; + case Common.ValueType.SHORT: + rawValue = String.valueOf(byteBuf.getShortLE(start)); + value = that.driverService.convertValue(deviceId, pointId, rawValue); + break; + case Common.ValueType.INT: + rawValue = String.valueOf(DriverUtils.bytesToIntLE(ByteBufUtil.getBytes(byteBuf, start, length))); + value = that.driverService.convertValue(deviceId, pointId, rawValue); + break; + default: + throw new IllegalStateException("Unexpected value: " + type.toLowerCase()); + } + value = customDecode(start, value); + log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length).toUpperCase(), rawValue, value); + return new PointValue(pointId, rawValue, value); + } + /** * 自定义报文解析,用于处理特殊位号数据 * @@ -124,10 +160,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { return value; } - private int intDecode(ByteBuf byteBuf) { - return byteBuf.getIntLE(0); - } - @Override public void channelActive(ChannelHandlerContext context) { log.debug("Water 188B Driver Listener({}) accept clint({})", context.channel().localAddress(), context.channel().remoteAddress()); @@ -146,7 +178,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { List pointValues = new ArrayList<>(); Map> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId); for (Long pointId : pointInfoMap.keySet()) { - PointValue pointValue = decodePointValue(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); + PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); pointValues.add(pointValue); } PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS); @@ -159,43 +191,4 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { context.close(); } - private PointValue decodePointValue(long deviceId, long pointId, Map infoMap, ByteBuf byteBuf) { - String type = DriverUtils.value(infoMap.get("type").getType(), infoMap.get("type").getValue()); - int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue()); - int length = DriverUtils.value(infoMap.get("length").getType(), infoMap.get("length").getValue()); - - String rawValue, value; - switch (type.toLowerCase()) { - case Common.ValueType.HEX: - rawValue = ByteBufUtil.hexDump(byteBuf.retainedSlice(start, length)).toUpperCase(); - value = that.driverService.convertValue(deviceId, pointId, rawValue); - break; - case Common.ValueType.SHORT: - rawValue = String.valueOf(byteBuf.getShortLE(start)); - value = that.driverService.convertValue(deviceId, pointId, rawValue); - break; - case Common.ValueType.INT: - int intValue = intDecode(byteBuf.copy(start, length)); -// if (length != 4) { -// ByteBuf copy = byteBuf.copy(start, length); -// int i = length; -// while (i < 4) { -// copy.writeBytes(new byte[]{0x00}); -// i++; -// } -// intValue = copy.getIntLE(0); -// } else { -// intValue = byteBuf.getIntLE(start); -// } - rawValue = String.valueOf(intValue); - value = that.driverService.convertValue(deviceId, pointId, rawValue); - break; - default: - throw new IllegalStateException("Unexpected value: " + type.toLowerCase()); - } - value = customDecode(start, value); - log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length).toUpperCase(), rawValue, value); - return new PointValue(pointId, rawValue, value); - } - } \ No newline at end of file diff --git a/dc3-gateway/src/main/java/com/dc3/gateway/GatewayApplication.java b/dc3-gateway/src/main/java/com/dc3/gateway/GatewayApplication.java index d491902c8..07af3a6e7 100644 --- a/dc3-gateway/src/main/java/com/dc3/gateway/GatewayApplication.java +++ b/dc3-gateway/src/main/java/com/dc3/gateway/GatewayApplication.java @@ -28,7 +28,6 @@ import org.springframework.cloud.client.SpringCloudApplication; @EnableCaching @SpringCloudApplication public class GatewayApplication { - public static void main(String[] args) { SpringApplication.run(GatewayApplication.class, args); } From a30c22acbcbd8b9b4d401720e2e82f5325233d1f Mon Sep 17 00:00:00 2001 From: pnoker Date: Thu, 20 Aug 2020 22:32:15 +0800 Subject: [PATCH 03/10] dev.sh --- dc3/server/dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dc3/server/dev.sh b/dc3/server/dev.sh index 99f62b9e6..14d660958 100755 --- a/dc3/server/dev.sh +++ b/dc3/server/dev.sh @@ -22,5 +22,5 @@ cd ../../ mvn clean -U package # shellcheck disable=SC2164 cd dc3/ -docker-compose build mysql redis mongo rabbitmq register auth monitor manager data -docker-compose up -d mysql redis mongo rabbitmq register auth monitor manager data \ No newline at end of file +docker-compose build mysql redis mongo rabbitmq register auth +docker-compose up -d mysql redis mongo rabbitmq register auth \ No newline at end of file From 7e45756ce1d80c8fa210011bbfa74cdeb72c1361 Mon Sep 17 00:00:00 2001 From: pnoker Date: Fri, 21 Aug 2020 11:31:35 +0800 Subject: [PATCH 04/10] 188b tcp & udp --- .../Dockerfile | 8 +- .../pom.xml | 4 +- .../Water188BTcpDriverApplication.java} | 4 +- .../service/impl/CustomDriverServiceImpl.java | 0 .../dc3/driver/service/netty/NettyServer.java | 0 .../service/netty/NettyServerHandler.java | 0 .../src/main/resources/application.yml | 4 +- .../dc3-driver-water-188b-udp/Dockerfile | 31 +++ dc3-driver/dc3-driver-water-188b-udp/pom.xml | 46 +++++ .../driver/Water188BUdpDriverApplication.java | 35 ++++ .../service/impl/CustomDriverServiceImpl.java | 70 +++++++ .../dc3/driver/service/netty/NettyServer.java | 58 ++++++ .../service/netty/NettyServerHandler.java | 194 ++++++++++++++++++ .../src/main/resources/application.yml | 43 ++++ dc3-driver/pom.xml | 3 +- 15 files changed, 489 insertions(+), 11 deletions(-) rename dc3-driver/{dc3-driver-water-188b => dc3-driver-water-188b-tcp}/Dockerfile (85%) rename dc3-driver/{dc3-driver-water-188b => dc3-driver-water-188b-tcp}/pom.xml (92%) rename dc3-driver/{dc3-driver-water-188b/src/main/java/com/dc3/driver/Water188BDriverApplication.java => dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/Water188BTcpDriverApplication.java} (88%) rename dc3-driver/{dc3-driver-water-188b => dc3-driver-water-188b-tcp}/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java (100%) rename dc3-driver/{dc3-driver-water-188b => dc3-driver-water-188b-tcp}/src/main/java/com/dc3/driver/service/netty/NettyServer.java (100%) rename dc3-driver/{dc3-driver-water-188b => dc3-driver-water-188b-tcp}/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java (100%) rename dc3-driver/{dc3-driver-water-188b => dc3-driver-water-188b-tcp}/src/main/resources/application.yml (89%) create mode 100644 dc3-driver/dc3-driver-water-188b-udp/Dockerfile create mode 100644 dc3-driver/dc3-driver-water-188b-udp/pom.xml create mode 100644 dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/Water188BUdpDriverApplication.java create mode 100644 dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java create mode 100644 dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java create mode 100644 dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java create mode 100644 dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml diff --git a/dc3-driver/dc3-driver-water-188b/Dockerfile b/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile similarity index 85% rename from dc3-driver/dc3-driver-water-188b/Dockerfile rename to dc3-driver/dc3-driver-water-188b-tcp/Dockerfile index 437e5cb36..0219b65ca 100644 --- a/dc3-driver/dc3-driver-water-188b/Dockerfile +++ b/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile @@ -20,12 +20,12 @@ MAINTAINER pnoker ENV JAVA_OPS -server -Xms128m -Xmx512m -XX:CompressedClassSpaceSize=128m -XX:MetaspaceSize=200m -XX:MaxMetaspaceSize=200m RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ - && mkdir -p /dc3-driver/dc3-driver-b188 + && mkdir -p /dc3-driver/dc3-driver-water-188b -WORKDIR /dc3-driver/dc3-driver-b188 +WORKDIR /dc3-driver/dc3-driver-water-188b -ADD ./target/dc3-driver-b188.jar ./ +ADD ./target/dc3-driver-water-188b.jar ./ EXPOSE 8700 -CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-b188.jar +CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-water-188b.jar diff --git a/dc3-driver/dc3-driver-water-188b/pom.xml b/dc3-driver/dc3-driver-water-188b-tcp/pom.xml similarity index 92% rename from dc3-driver/dc3-driver-water-188b/pom.xml rename to dc3-driver/dc3-driver-water-188b-tcp/pom.xml index 63bb530a4..ef0f52bf1 100644 --- a/dc3-driver/dc3-driver-water-188b/pom.xml +++ b/dc3-driver/dc3-driver-water-188b-tcp/pom.xml @@ -23,10 +23,10 @@ 1.0.0 - dc3-driver-water-188b + dc3-driver-water-188b-tcp jar - IOT DC3 平台 188B协议驱动。 + IOT DC3 平台 188B TCP协议驱动。 4.1.46.Final diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/Water188BDriverApplication.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/Water188BTcpDriverApplication.java similarity index 88% rename from dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/Water188BDriverApplication.java rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/Water188BTcpDriverApplication.java index c188febc9..6315ff150 100644 --- a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/Water188BDriverApplication.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/Water188BTcpDriverApplication.java @@ -25,10 +25,10 @@ import org.springframework.cloud.client.SpringCloudApplication; */ @EnableCaching @SpringCloudApplication -public class Water188BDriverApplication { +public class Water188BTcpDriverApplication { public static void main(String[] args) { - SpringApplication.run(Water188BDriverApplication.class, args); + SpringApplication.run(Water188BTcpDriverApplication.class, args); } } diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java similarity index 100% rename from dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServer.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServer.java similarity index 100% rename from dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServer.java rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServer.java diff --git a/dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java similarity index 100% rename from dc3-driver/dc3-driver-water-188b/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java diff --git a/dc3-driver/dc3-driver-water-188b/src/main/resources/application.yml b/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml similarity index 89% rename from dc3-driver/dc3-driver-water-188b/src/main/resources/application.yml rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml index 083301b2d..ddcda6208 100644 --- a/dc3-driver/dc3-driver-water-188b/src/main/resources/application.yml +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml @@ -1,5 +1,5 @@ driver: - name: Water188BDriver + name: Water188BTcpDriver description: @project.description@ custom: socket: @@ -40,4 +40,4 @@ logging: com.dc3.common.sdk: DEBUG com.dc3: DEBUG file: - name: dc3/logs/driver/water/188b/${spring.application.name}.log \ No newline at end of file + name: dc3/logs/driver/water/188b/tcp/${spring.application.name}.log \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/Dockerfile b/dc3-driver/dc3-driver-water-188b-udp/Dockerfile new file mode 100644 index 000000000..4d038c2c7 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/Dockerfile @@ -0,0 +1,31 @@ +# +# Copyright 2018-2020 Pnoker. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM pnoker/alpine-java:1.8.251 +MAINTAINER pnoker + +ENV JAVA_OPS -server -Xms128m -Xmx512m -XX:CompressedClassSpaceSize=128m -XX:MetaspaceSize=200m -XX:MaxMetaspaceSize=200m + +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && mkdir -p /dc3-driver/dc3-driver-water-188b-udp + +WORKDIR /dc3-driver/dc3-driver-water-188b-udp + +ADD ./target/dc3-driver-water-188b-udp.jar ./ + +EXPOSE 8700 + +CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-water-188b-udp.jar diff --git a/dc3-driver/dc3-driver-water-188b-udp/pom.xml b/dc3-driver/dc3-driver-water-188b-udp/pom.xml new file mode 100644 index 000000000..00772edac --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + com.dc3 + dc3-driver + 1.0.0 + + + dc3-driver-water-188b-udp + jar + + IOT DC3 平台 188B UDP协议驱动。 + + + 4.1.46.Final + + + + + + + io.netty + netty-all + ${netty.version} + + + + + \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/Water188BUdpDriverApplication.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/Water188BUdpDriverApplication.java new file mode 100644 index 000000000..523e71055 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/Water188BUdpDriverApplication.java @@ -0,0 +1,35 @@ +/* + * Copyright 2018-2020 Pnoker. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dc3.driver; + +import org.springframework.boot.SpringApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cloud.client.SpringCloudApplication; + +/** + * @author pnoker + */ +@EnableCaching +@SpringCloudApplication +public class Water188BUdpDriverApplication { + + public static void main(String[] args) { + SpringApplication.run(Water188BUdpDriverApplication.class, args); + } + +} + diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java new file mode 100644 index 000000000..4cc9e04a6 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright 2018-2020 Pnoker. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dc3.driver.service.impl; + +import com.dc3.common.model.Device; +import com.dc3.common.model.Point; +import com.dc3.common.sdk.bean.AttributeInfo; +import com.dc3.common.sdk.service.CustomDriverService; +import com.dc3.driver.service.netty.NettyServer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * @author pnoker + */ +@Slf4j +@Service +public class CustomDriverServiceImpl implements CustomDriverService { + + @Value("${driver.custom.socket.port}") + private Integer port; + + @Resource + private NettyServer nettyServer; + @Resource + private ThreadPoolExecutor threadPoolExecutor; + + @Override + public void initial() { + threadPoolExecutor.execute(() -> { + log.debug("Water 188B Driver Starting(::{}) incoming data listener", port); + nettyServer.start(port); + }); + } + + @Override + public String read(Map driverInfo, Map pointInfo, Device device, Point point) throws Exception { + return "nil"; + } + + @Override + public Boolean write(Map driverInfo, Map pointInfo, Device device, AttributeInfo value) throws Exception { + return false; + } + + @Override + public void schedule() { + log.info("schedule not implemented"); + } + +} diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java new file mode 100644 index 000000000..c2ca57ab8 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java @@ -0,0 +1,58 @@ +/* + * Copyright 2018-2020 Pnoker. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dc3.driver.service.netty; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioDatagramChannel; +import io.netty.handler.timeout.WriteTimeoutHandler; +import lombok.SneakyThrows; +import org.springframework.stereotype.Component; + +import java.net.InetSocketAddress; + +/** + * @author pnoker + */ +@Component +public class NettyServer { + + @SneakyThrows + public void start(int port) { + EventLoopGroup group = new NioEventLoopGroup(); + try { + Bootstrap bootstrap = new Bootstrap(); + bootstrap.group(group) + .channel(NioDatagramChannel.class) + .localAddress(new InetSocketAddress(port)) + .handler(new ChannelInitializer() { + @Override + protected void initChannel(Channel channel) { + channel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyServerHandler()); + } + }); + ChannelFuture future = bootstrap.bind().sync(); + future.channel().closeFuture().sync(); + } finally { + group.shutdownGracefully().sync(); + } + } +} \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java new file mode 100644 index 000000000..59791f101 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java @@ -0,0 +1,194 @@ +/* + * Copyright 2018-2020 Pnoker. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dc3.driver.service.netty; + +import com.dc3.common.bean.driver.PointValue; +import com.dc3.common.constant.Common; +import com.dc3.common.exception.ServiceException; +import com.dc3.common.sdk.bean.AttributeInfo; +import com.dc3.common.sdk.bean.DriverContext; +import com.dc3.common.sdk.service.rabbit.DriverService; +import com.dc3.common.sdk.util.DriverUtils; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 报文说明 + * FEFEFE + * 68 + * 10 + * 03221018200673 表号 + * 0081 + * 96 长度 + * 15: 905F 数据标识DI(90 5F) + * 17: 2B2B3600 正向累计量单位(2B),反向累计量单位(2B),瞬时流量单位(36),水压单位(00) + * 21: 18690100 当前正向累计水量 92.440 + * 25: 00000000 当前剩余金额 + * 29: 00000000 当前状态 + * 33: 00 充值识别码 + * 34: 00000000 当前反向累计流量 + * 38: 000000 当前瞬时流量 + * 41: 0000 当前水压 + * 43: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 48: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 53: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 58: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 63: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 68: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 73: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 78: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 83: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 88: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 93: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 98: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 103:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 108:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 113:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 118:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 123:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 128:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 133:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 138:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 143:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 148:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 153:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 158:0A68010073 正向累计流量(0A680100)累加和(73) 92.17 + * 163:B700 信号强度 + * A9 校验和 + * 16 帧尾 + *

+ * ----0--1--2--3--4--5--6--7--8--9--10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51 + * lg:[FE FE FE 68 10 03 22 10 18 20 06 73 00 81 96 90 5F 2B 2B 36 00 18 69 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 B7 00 A9 16] + * lg:[FE FE FE 68 10 06 02 01 07 20 06 36 00 81 96 90 5F 2B 2B 35 00 0E 01 00 00 00 00 00 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F A3 00 1B 16] + * + * @author pnoker + */ +@Slf4j +@Component +@ChannelHandler.Sharable +public class NettyServerHandler extends ChannelInboundHandlerAdapter { + private static final String START_TAG = "fefefe"; + + private static NettyServerHandler that; + + @PostConstruct + public void init() { + that = this; + } + + @Resource + private DriverService driverService; + @Resource + private DriverContext driverContext; + + /** + * 解析 Point Value 数据 + * + * @param deviceId Device Id + * @param pointId Point Id + * @param infoMap Point Info Map + * @param byteBuf ByteBuf + * @return PointValue + */ + private PointValue pointValueDecode(long deviceId, long pointId, Map infoMap, ByteBuf byteBuf) { + String type = DriverUtils.value(infoMap.get("type").getType(), infoMap.get("type").getValue()); + int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue()); + int length = DriverUtils.value(infoMap.get("length").getType(), infoMap.get("length").getValue()); + + String rawValue, value; + switch (type.toLowerCase()) { + case Common.ValueType.HEX: + rawValue = ByteBufUtil.hexDump(byteBuf.retainedSlice(start, length)).toUpperCase(); + value = that.driverService.convertValue(deviceId, pointId, rawValue); + break; + case Common.ValueType.SHORT: + rawValue = String.valueOf(byteBuf.getShortLE(start)); + value = that.driverService.convertValue(deviceId, pointId, rawValue); + break; + case Common.ValueType.INT: + rawValue = String.valueOf(DriverUtils.bytesToIntLE(ByteBufUtil.getBytes(byteBuf, start, length))); + value = that.driverService.convertValue(deviceId, pointId, rawValue); + break; + default: + throw new IllegalStateException("Unexpected value: " + type.toLowerCase()); + } + value = customDecode(start, value); + log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length).toUpperCase(), rawValue, value); + return new PointValue(pointId, rawValue, value); + } + + /** + * 自定义报文解析,用于处理特殊位号数据 + * + * @return PointValue + */ + private String customDecode(int start, String value) { + //信号强度额外处理 + if (start == 163) { + int csq = (int) Double.parseDouble(value); + if (csq > 0) { + csq -= 200; + } + value = String.valueOf(csq); + } + return value; + } + + @Override + public void channelActive(ChannelHandlerContext context) { + log.debug("Water 188B Driver Listener({}) accept clint({})", context.channel().localAddress(), context.channel().remoteAddress()); + } + + @Override + public void channelRead(ChannelHandlerContext context, Object msg) { + ByteBuf byteBuf = (ByteBuf) msg; + if (!START_TAG.equals(ByteBufUtil.hexDump(byteBuf, 0, 3))) { + throw new ServiceException("Start Tag Invalid"); + } + String deviceName = ByteBufUtil.hexDump(byteBuf, 5, 7); + Long deviceId = that.driverContext.getDeviceIdByName(deviceName); + log.info("Receive Device({})[{}] Bytes -> {}", deviceName, context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); + + List pointValues = new ArrayList<>(); + Map> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId); + for (Long pointId : pointInfoMap.keySet()) { + PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); + pointValues.add(pointValue); + } + PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS); + that.driverService.multiPointValueSender(pointValue); + } + + @Override + public void exceptionCaught(ChannelHandlerContext context, Throwable throwable) { + log.error(throwable.getMessage()); + context.close(); + } + +} \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml b/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml new file mode 100644 index 000000000..ea8a9adf7 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml @@ -0,0 +1,43 @@ +driver: + name: Water188BUdpDriver + description: @project.description@ + custom: + socket: + port: 9271 + schedule: + read: + enable: false + corn: '0/30 * * * * ?' + custom: + enable: false + corn: '0/5 * * * * ?' + point-attribute: + - displayName: 起始字节 + name: start + type: int + value: 0 + description: 起始字节,包含该字节 + - displayName: 长度 + name: length + type: int + value: 8 + description: 字节长度 + - displayName: 类型 + name: type + type: string + value: int + description: 解析类型,short、int、long、float、double、boolean、string + +server: + port: 8703 + +spring: + application: + name: @project.artifactId@ + +logging: + level: + com.dc3.common.sdk: DEBUG + com.dc3: DEBUG + file: + name: dc3/logs/driver/water/188b/udp/${spring.application.name}.log \ No newline at end of file diff --git a/dc3-driver/pom.xml b/dc3-driver/pom.xml index 9fcea3ae6..b6cdc3df2 100644 --- a/dc3-driver/pom.xml +++ b/dc3-driver/pom.xml @@ -36,7 +36,8 @@ dc3-driver-opc-ua dc3-driver-mqtt dc3-driver-modbus-tcp - dc3-driver-water-188b + dc3-driver-water-188b-tcp + dc3-driver-water-188b-udp From 2410f2659e18e43b3d0f9ddbd57622a6af49dc69 Mon Sep 17 00:00:00 2001 From: pnoker Date: Fri, 21 Aug 2020 12:15:02 +0800 Subject: [PATCH 05/10] . --- .../dc3-driver-water-188b-tcp/Dockerfile | 8 ++++---- .../service/impl/CustomDriverServiceImpl.java | 10 +++++----- .../{NettyServer.java => NettyTcpServer.java} | 4 ++-- ...andler.java => NettyTcpServerHandler.java} | 4 ++-- .../src/main/resources/application.yml | 2 +- .../service/impl/CustomDriverServiceImpl.java | 10 +++++----- .../{NettyServer.java => NettyUdpServer.java} | 4 ++-- ...andler.java => NettyUdpServerHandler.java} | 19 ++++++------------- .../src/main/resources/application.yml | 2 +- 9 files changed, 28 insertions(+), 35 deletions(-) rename dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/{NettyServer.java => NettyTcpServer.java} (95%) rename dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/{NettyServerHandler.java => NettyTcpServerHandler.java} (98%) rename dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/{NettyServer.java => NettyUdpServer.java} (96%) rename dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/{NettyServerHandler.java => NettyUdpServerHandler.java} (93%) diff --git a/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile b/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile index 0219b65ca..edf270154 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile +++ b/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile @@ -20,12 +20,12 @@ MAINTAINER pnoker ENV JAVA_OPS -server -Xms128m -Xmx512m -XX:CompressedClassSpaceSize=128m -XX:MetaspaceSize=200m -XX:MaxMetaspaceSize=200m RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ - && mkdir -p /dc3-driver/dc3-driver-water-188b + && mkdir -p /dc3-driver/dc3-driver-water-188b-tcp -WORKDIR /dc3-driver/dc3-driver-water-188b +WORKDIR /dc3-driver/dc3-driver-water-188b-tcp -ADD ./target/dc3-driver-water-188b.jar ./ +ADD ./target/dc3-driver-water-188b-tcp.jar ./ EXPOSE 8700 -CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-water-188b.jar +CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-water-188b-tcp.jar diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java index 4cc9e04a6..4ff47185f 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java @@ -20,7 +20,7 @@ import com.dc3.common.model.Device; import com.dc3.common.model.Point; import com.dc3.common.sdk.bean.AttributeInfo; import com.dc3.common.sdk.service.CustomDriverService; -import com.dc3.driver.service.netty.NettyServer; +import com.dc3.driver.service.netty.NettyTcpServer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -36,19 +36,19 @@ import java.util.concurrent.ThreadPoolExecutor; @Service public class CustomDriverServiceImpl implements CustomDriverService { - @Value("${driver.custom.socket.port}") + @Value("${driver.custom.tcp.port}") private Integer port; @Resource - private NettyServer nettyServer; + private NettyTcpServer nettyTcpServer; @Resource private ThreadPoolExecutor threadPoolExecutor; @Override public void initial() { threadPoolExecutor.execute(() -> { - log.debug("Water 188B Driver Starting(::{}) incoming data listener", port); - nettyServer.start(port); + log.debug("Water 188B Tcp Driver Starting(::{}) incoming data listener", port); + nettyTcpServer.start(port); }); } diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServer.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java similarity index 95% rename from dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServer.java rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java index e24465c16..63200b32f 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServer.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java @@ -33,7 +33,7 @@ import java.net.InetSocketAddress; * @author pnoker */ @Component -public class NettyServer { +public class NettyTcpServer { @SneakyThrows public void start(int port) { @@ -46,7 +46,7 @@ public class NettyServer { .childHandler(new ChannelInitializer() { @Override protected void initChannel(SocketChannel socketChannel) { - socketChannel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyServerHandler()); + socketChannel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyTcpServerHandler()); } }); ChannelFuture future = bootstrap.bind().sync(); diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java similarity index 98% rename from dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java rename to dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java index 59791f101..a995487d0 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java @@ -92,10 +92,10 @@ import java.util.concurrent.TimeUnit; @Slf4j @Component @ChannelHandler.Sharable -public class NettyServerHandler extends ChannelInboundHandlerAdapter { +public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { private static final String START_TAG = "fefefe"; - private static NettyServerHandler that; + private static NettyTcpServerHandler that; @PostConstruct public void init() { diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml b/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml index ddcda6208..d6f5b7239 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/application.yml @@ -2,7 +2,7 @@ driver: name: Water188BTcpDriver description: @project.description@ custom: - socket: + tcp: port: 9270 schedule: read: diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java index 4cc9e04a6..3b1b1bbac 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/impl/CustomDriverServiceImpl.java @@ -20,7 +20,7 @@ import com.dc3.common.model.Device; import com.dc3.common.model.Point; import com.dc3.common.sdk.bean.AttributeInfo; import com.dc3.common.sdk.service.CustomDriverService; -import com.dc3.driver.service.netty.NettyServer; +import com.dc3.driver.service.netty.NettyUdpServer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -36,19 +36,19 @@ import java.util.concurrent.ThreadPoolExecutor; @Service public class CustomDriverServiceImpl implements CustomDriverService { - @Value("${driver.custom.socket.port}") + @Value("${driver.custom.udp.port}") private Integer port; @Resource - private NettyServer nettyServer; + private NettyUdpServer nettyUdpServer; @Resource private ThreadPoolExecutor threadPoolExecutor; @Override public void initial() { threadPoolExecutor.execute(() -> { - log.debug("Water 188B Driver Starting(::{}) incoming data listener", port); - nettyServer.start(port); + log.debug("Water 188B Udp Driver Starting(::{}) incoming data listener", port); + nettyUdpServer.start(port); }); } diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java similarity index 96% rename from dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java rename to dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java index c2ca57ab8..25620b885 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServer.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java @@ -33,7 +33,7 @@ import java.net.InetSocketAddress; * @author pnoker */ @Component -public class NettyServer { +public class NettyUdpServer { @SneakyThrows public void start(int port) { @@ -46,7 +46,7 @@ public class NettyServer { .handler(new ChannelInitializer() { @Override protected void initChannel(Channel channel) { - channel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyServerHandler()); + channel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyUdpServerHandler()); } }); ChannelFuture future = bootstrap.bind().sync(); diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java similarity index 93% rename from dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java rename to dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java index 59791f101..dd95495c3 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java @@ -25,9 +25,9 @@ import com.dc3.common.sdk.service.rabbit.DriverService; import com.dc3.common.sdk.util.DriverUtils; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; -import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.socket.DatagramPacket; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -91,11 +91,10 @@ import java.util.concurrent.TimeUnit; */ @Slf4j @Component -@ChannelHandler.Sharable -public class NettyServerHandler extends ChannelInboundHandlerAdapter { +public class NettyUdpServerHandler extends SimpleChannelInboundHandler { private static final String START_TAG = "fefefe"; - private static NettyServerHandler that; + private static NettyUdpServerHandler that; @PostConstruct public void init() { @@ -161,13 +160,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { } @Override - public void channelActive(ChannelHandlerContext context) { - log.debug("Water 188B Driver Listener({}) accept clint({})", context.channel().localAddress(), context.channel().remoteAddress()); - } - - @Override - public void channelRead(ChannelHandlerContext context, Object msg) { - ByteBuf byteBuf = (ByteBuf) msg; + protected void channelRead0(ChannelHandlerContext context, DatagramPacket msg) { + ByteBuf byteBuf = msg.content(); if (!START_TAG.equals(ByteBufUtil.hexDump(byteBuf, 0, 3))) { throw new ServiceException("Start Tag Invalid"); } @@ -190,5 +184,4 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { log.error(throwable.getMessage()); context.close(); } - } \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml b/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml index ea8a9adf7..00e444752 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/application.yml @@ -2,7 +2,7 @@ driver: name: Water188BUdpDriver description: @project.description@ custom: - socket: + udp: port: 9271 schedule: read: From 313f2226cab9ec1cd2821709bbf83f75db28024e Mon Sep 17 00:00:00 2001 From: pnoker Date: Fri, 21 Aug 2020 12:48:34 +0800 Subject: [PATCH 06/10] . --- .../dc3/common/sdk/bean/DriverContext.java | 2 +- .../service/netty/NettyTcpServerHandler.java | 2 +- .../service/netty/NettyUdpServerHandler.java | 4 +- ...on => batch-import-188b-tcp-template.json} | 4 +- .../files/batch-import-188b-udp-template.json | 660 ++++++++++++++++++ 5 files changed, 666 insertions(+), 6 deletions(-) rename dc3/api/files/{batch-import-188b-template.json => batch-import-188b-tcp-template.json} (99%) create mode 100644 dc3/api/files/batch-import-188b-udp-template.json diff --git a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java index 1b1d348c3..d45febd59 100644 --- a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java +++ b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java @@ -89,7 +89,7 @@ public class DriverContext { public Long getDeviceIdByName(String deviceName) { Long deviceId = deviceNameMap.get(deviceName); if (null == deviceId) { - throw new ServiceException("device(" + deviceId + ") does not exist"); + throw new ServiceException("device(" + deviceName + ") does not exist"); } return deviceId; } diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java index a995487d0..de44b51ea 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java @@ -172,10 +172,10 @@ public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { throw new ServiceException("Start Tag Invalid"); } String deviceName = ByteBufUtil.hexDump(byteBuf, 5, 7); - Long deviceId = that.driverContext.getDeviceIdByName(deviceName); log.info("Receive Device({})[{}] Bytes -> {}", deviceName, context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); List pointValues = new ArrayList<>(); + Long deviceId = that.driverContext.getDeviceIdByName(deviceName); Map> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId); for (Long pointId : pointInfoMap.keySet()) { PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java index dd95495c3..44dbd6246 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java @@ -166,10 +166,10 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler {}", deviceName, context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); + log.info("Receive Device({})[{}] Bytes -> {}", deviceName, context.channel(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); List pointValues = new ArrayList<>(); + Long deviceId = that.driverContext.getDeviceIdByName(deviceName); Map> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId); for (Long pointId : pointInfoMap.keySet()) { PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); diff --git a/dc3/api/files/batch-import-188b-template.json b/dc3/api/files/batch-import-188b-tcp-template.json similarity index 99% rename from dc3/api/files/batch-import-188b-template.json rename to dc3/api/files/batch-import-188b-tcp-template.json index 9f678eb0b..fe83380e8 100644 --- a/dc3/api/files/batch-import-188b-template.json +++ b/dc3/api/files/batch-import-188b-tcp-template.json @@ -1,9 +1,9 @@ [ { - "serviceName": "dc3-driver-water-188b", + "serviceName": "dc3-driver-water-188b-tcp", "profiles": [ { - "name": "水表188B协议位号模版", + "name": "Water188B_TCP_Profile", "share": true, "points": [ { diff --git a/dc3/api/files/batch-import-188b-udp-template.json b/dc3/api/files/batch-import-188b-udp-template.json new file mode 100644 index 000000000..471a93201 --- /dev/null +++ b/dc3/api/files/batch-import-188b-udp-template.json @@ -0,0 +1,660 @@ +[ + { + "serviceName": "dc3-driver-water-188b-udp", + "profiles": [ + { + "name": "Water188B_UDP_Profile", + "share": true, + "points": [ + { + "name": "数据标识", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "反向累计量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "瞬时流量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "水压单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计水量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "剩余金额", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "状态", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "充值识别码", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "反向累计流量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "瞬时流量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "水压", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-0点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-1点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-2点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-3点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-4点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-5点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-6点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-7点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-8点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-9点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-10点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-11点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-12点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-13点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-14点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-15点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-16点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-17点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-18点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-19点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-20点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-21点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-22点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-23点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "信号强度", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + } + ], + "pointConfig": { + "数据标识": { + "start": 15, + "length": 2, + "type": "hex" + }, + "正向累计量单位": { + "start": 17, + "length": 1, + "type": "hex" + }, + "反向累计量单位": { + "start": 18, + "length": 1, + "type": "hex" + }, + "瞬时流量单位": { + "start": 19, + "length": 1, + "type": "hex" + }, + "水压单位": { + "start": 20, + "length": 1, + "type": "hex" + }, + "正向累计水量": { + "start": 21, + "length": 4, + "type": "int" + }, + "剩余金额": { + "start": 25, + "length": 4, + "type": "int" + }, + "状态": { + "start": 29, + "length": 4, + "type": "hex" + }, + "充值识别码": { + "start": 33, + "length": 1, + "type": "hex" + }, + "反向累计流量": { + "start": 34, + "length": 4, + "type": "int" + }, + "瞬时流量": { + "start": 38, + "length": 3, + "type": "int" + }, + "水压": { + "start": 41, + "length": 2, + "type": "short" + }, + "正向累计流量-0点": { + "start": 43, + "length": 4, + "type": "int" + }, + "正向累计流量-1点": { + "start": 48, + "length": 4, + "type": "int" + }, + "正向累计流量-2点": { + "start": 53, + "length": 4, + "type": "int" + }, + "正向累计流量-3点": { + "start": 58, + "length": 4, + "type": "int" + }, + "正向累计流量-4点": { + "start": 63, + "length": 4, + "type": "int" + }, + "正向累计流量-5点": { + "start": 68, + "length": 4, + "type": "int" + }, + "正向累计流量-6点": { + "start": 73, + "length": 4, + "type": "int" + }, + "正向累计流量-7点": { + "start": 78, + "length": 4, + "type": "int" + }, + "正向累计流量-8点": { + "start": 83, + "length": 4, + "type": "int" + }, + "正向累计流量-9点": { + "start": 88, + "length": 4, + "type": "int" + }, + "正向累计流量-10点": { + "start": 93, + "length": 4, + "type": "int" + }, + "正向累计流量-11点": { + "start": 98, + "length": 4, + "type": "int" + }, + "正向累计流量-12点": { + "start": 103, + "length": 4, + "type": "int" + }, + "正向累计流量-13点": { + "start": 108, + "length": 4, + "type": "int" + }, + "正向累计流量-14点": { + "start": 113, + "length": 4, + "type": "int" + }, + "正向累计流量-15点": { + "start": 118, + "length": 4, + "type": "int" + }, + "正向累计流量-16点": { + "start": 123, + "length": 4, + "type": "int" + }, + "正向累计流量-17点": { + "start": 128, + "length": 4, + "type": "int" + }, + "正向累计流量-18点": { + "start": 133, + "length": 4, + "type": "int" + }, + "正向累计流量-19点": { + "start": 138, + "length": 4, + "type": "int" + }, + "正向累计流量-20点": { + "start": 143, + "length": 4, + "type": "int" + }, + "正向累计流量-21点": { + "start": 148, + "length": 4, + "type": "int" + }, + "正向累计流量-22点": { + "start": 153, + "length": 4, + "type": "int" + }, + "正向累计流量-23点": { + "start": 158, + "length": 4, + "type": "int" + }, + "信号强度": { + "start": 163, + "length": 2, + "type": "short" + } + }, + "groups": [ + { + "name": "水表", + "devices": [ + { + "name": "06020107200636" + }, + { + "name": "03221018200673" + }, + { + "name": "09451018200637" + } + ] + } + ] + } + ] + } +] \ No newline at end of file From a25cfc6d632bd3a558f9ebee31c6b45ec44d1a8d Mon Sep 17 00:00:00 2001 From: pnoker Date: Fri, 21 Aug 2020 14:35:03 +0800 Subject: [PATCH 07/10] . --- dc3-driver/dc3-driver-modbus-tcp/Dockerfile | 2 +- dc3-driver/dc3-driver-water-188b-tcp/Dockerfile | 3 ++- dc3-driver/dc3-driver-water-188b-udp/Dockerfile | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dc3-driver/dc3-driver-modbus-tcp/Dockerfile b/dc3-driver/dc3-driver-modbus-tcp/Dockerfile index 8bc7111f2..bc858eea8 100644 --- a/dc3-driver/dc3-driver-modbus-tcp/Dockerfile +++ b/dc3-driver/dc3-driver-modbus-tcp/Dockerfile @@ -26,6 +26,6 @@ WORKDIR /dc3-driver/dc3-driver-modbus-tcp ADD ./target/dc3-driver-modbus-tcp.jar ./ -EXPOSE 8702 +EXPOSE 8604 CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-modbus-tcp.jar diff --git a/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile b/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile index edf270154..658b47f42 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile +++ b/dc3-driver/dc3-driver-water-188b-tcp/Dockerfile @@ -26,6 +26,7 @@ WORKDIR /dc3-driver/dc3-driver-water-188b-tcp ADD ./target/dc3-driver-water-188b-tcp.jar ./ -EXPOSE 8700 +EXPOSE 8702 +EXPOSE 9270 CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-water-188b-tcp.jar diff --git a/dc3-driver/dc3-driver-water-188b-udp/Dockerfile b/dc3-driver/dc3-driver-water-188b-udp/Dockerfile index 4d038c2c7..e031973d5 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/Dockerfile +++ b/dc3-driver/dc3-driver-water-188b-udp/Dockerfile @@ -26,6 +26,7 @@ WORKDIR /dc3-driver/dc3-driver-water-188b-udp ADD ./target/dc3-driver-water-188b-udp.jar ./ -EXPOSE 8700 +EXPOSE 8703 +EXPOSE 9271 CMD java ${JAVA_OPS} -Djava.security.egd=file:/dev/./urandom -jar dc3-driver-water-188b-udp.jar From 0b94feb29520423fbf19961f597a33f9745bc5a6 Mon Sep 17 00:00:00 2001 From: pnoker Date: Fri, 21 Aug 2020 22:21:09 +0800 Subject: [PATCH 08/10] . --- .../center/manager/service/impl/BatchServiceImpl.java | 9 --------- .../main/java/com/dc3/common/sdk/bean/DriverContext.java | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java index 3b7350ba2..d21e47d7c 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java @@ -16,7 +16,6 @@ package com.dc3.center.manager.service.impl; -import cn.hutool.core.thread.ThreadUtil; import com.alibaba.fastjson.JSON; import com.dc3.center.manager.service.*; import com.dc3.common.bean.batch.BatchDriver; @@ -37,7 +36,6 @@ import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; /** *

BatchService Impl @@ -137,7 +135,6 @@ public class BatchServiceImpl implements BatchService { } notifyService.notifyDriverProfile(driver, profile.getId(), Operation.Profile.ADD); - ThreadUtil.sleep(500, TimeUnit.MILLISECONDS); } return profile; } @@ -178,7 +175,6 @@ public class BatchServiceImpl implements BatchService { driverInfo = driverInfoService.update(driverInfo.setValue(value)); notifyService.notifyDriverDriverInfo(driverInfo.getId(), driverInfo.getDriverAttributeId(), driverInfo.getProfileId(), Operation.DriverInfo.UPDATE); } - ThreadUtil.sleep(500, TimeUnit.MILLISECONDS); }); } @@ -228,8 +224,6 @@ public class BatchServiceImpl implements BatchService { pointService.update(point); notifyService.notifyDriverPoint(point.getId(), point.getProfileId(), Operation.Point.UPDATE); } - - ThreadUtil.sleep(500, TimeUnit.MILLISECONDS); }); } @@ -263,7 +257,6 @@ public class BatchServiceImpl implements BatchService { throw new ServiceException("Add device failed: " + batchDevice.getName()); } notifyService.notifyDriverDevice(device.getId(), device.getProfileId(), Operation.Device.ADD); - ThreadUtil.sleep(500, TimeUnit.MILLISECONDS); } // Add Point Info @@ -317,8 +310,6 @@ public class BatchServiceImpl implements BatchService { pointInfo = pointInfoService.update(pointInfo.setValue(value)); notifyService.notifyDriverPointInfo(pointInfo.getId(), pointInfo.getPointAttributeId(), pointInfo.getDeviceId(), Operation.PointInfo.UPDATE); } - - ThreadUtil.sleep(500, TimeUnit.MILLISECONDS); }); }); } diff --git a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java index d45febd59..d77e6a0c4 100644 --- a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java +++ b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java @@ -89,7 +89,7 @@ public class DriverContext { public Long getDeviceIdByName(String deviceName) { Long deviceId = deviceNameMap.get(deviceName); if (null == deviceId) { - throw new ServiceException("device(" + deviceName + ") does not exist"); + throw new ServiceException("Device(" + deviceName + ") does not exist"); } return deviceId; } From 51b809da558d869d0c339072e1852c59d26a250e Mon Sep 17 00:00:00 2001 From: pnoker Date: Sun, 23 Aug 2020 23:23:15 +0800 Subject: [PATCH 09/10] . --- .../api/center/manager/feign/BatchClient.java | 17 +- .../manager/hystrix/BatchClientHystrix.java | 10 +- .../com/dc3/center/manager/api/BatchApi.java | 32 +- .../center/manager/service/BatchService.java | 8 +- .../service/impl/BatchServiceImpl.java | 14 +- dc3-common/dc3-base/pom.xml | 8 +- .../java/com/dc3/common/utils/Dc3Util.java | 34 +- .../src/main/resources/bootstrap.yml | 13 +- .../dc3/common/sdk/bean/DriverContext.java | 14 +- .../sdk/service/rabbit/DriverService.java | 17 + .../dc3-sdk/src/main/resources/bootstrap.yml | 12 +- .../driver/service/netty/NettyTcpServer.java | 7 +- .../service/netty/NettyTcpServerHandler.java | 120 +++- .../batch-import-188b-tcp-template.json | 650 ++++++++++++++++++ .../driver/service/netty/NettyUdpServer.java | 7 +- .../service/netty/NettyUdpServerHandler.java | 105 ++- .../batch-import-188b-udp-template.json | 650 ++++++++++++++++++ dc3-driver/pom.xml | 1 + .../files/batch-import-188b-tcp-template.json | 4 +- .../files/batch-import-188b-udp-template.json | 4 +- 20 files changed, 1604 insertions(+), 123 deletions(-) create mode 100644 dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/import/batch-import-188b-tcp-template.json create mode 100644 dc3-driver/dc3-driver-water-188b-udp/src/main/resources/import/batch-import-188b-udp-template.json diff --git a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/BatchClient.java b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/BatchClient.java index fca294d96..a7af1be82 100644 --- a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/BatchClient.java +++ b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/BatchClient.java @@ -18,12 +18,16 @@ package com.dc3.api.center.manager.feign; import com.dc3.api.center.manager.hystrix.BatchClientHystrix; import com.dc3.common.bean.R; +import com.dc3.common.bean.batch.BatchDriver; import com.dc3.common.constant.Common; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + /** *

批量导入 FeignClient * @@ -36,9 +40,18 @@ public interface BatchClient { * 批量导入 All, 包含:驱动->模版->驱动配置->位号->设备->位号配置 * * @param multipartFile MultipartFile - * @return + * @return Boolean */ @PostMapping("/import") - R batchImport(@RequestParam(value = "file") MultipartFile multipartFile); + R batchImportFile(@RequestParam(value = "file") MultipartFile multipartFile); + + /** + * 批量导入 All, 包含:驱动->模版->驱动配置->位号->设备->位号配置 + * + * @param batchDrivers List + * @return Boolean + */ + @PostMapping("/import/batchDriver") + R batchImportBatchDriver(@RequestBody List batchDrivers); } diff --git a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/BatchClientHystrix.java b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/BatchClientHystrix.java index ec8da5553..635bb296b 100644 --- a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/BatchClientHystrix.java +++ b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/BatchClientHystrix.java @@ -18,11 +18,14 @@ package com.dc3.api.center.manager.hystrix; import com.dc3.api.center.manager.feign.BatchClient; import com.dc3.common.bean.R; +import com.dc3.common.bean.batch.BatchDriver; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + /** *

ImportClientHystrix * @@ -40,7 +43,12 @@ public class BatchClientHystrix implements FallbackFactory { return new BatchClient() { @Override - public R batchImport(MultipartFile multipartFile) { + public R batchImportFile(MultipartFile multipartFile) { + return R.fail(message); + } + + @Override + public R batchImportBatchDriver(List batchDrivers) { return R.fail(message); } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/BatchApi.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/BatchApi.java index 54be2524a..3f6e75e40 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/BatchApi.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/BatchApi.java @@ -16,16 +16,21 @@ package com.dc3.center.manager.api; +import com.alibaba.fastjson.JSON; import com.dc3.api.center.manager.feign.BatchClient; import com.dc3.center.manager.service.BatchService; import com.dc3.common.bean.R; +import com.dc3.common.bean.batch.BatchDriver; import com.dc3.common.constant.Common; +import com.dc3.common.exception.ServiceException; +import com.dc3.common.utils.Dc3Util; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.util.List; /** *

批量导入 Client 接口实现 @@ -41,9 +46,32 @@ public class BatchApi implements BatchClient { @Override - public R batchImport(MultipartFile multipartFile) { + public R batchImportFile(MultipartFile multipartFile) { try { - return batchService.batchImport(multipartFile) ? R.ok() : R.fail(); + if (multipartFile.isEmpty()) { + throw new ServiceException("Import file is empty"); + } + // Convert json file to ImportAll object + List batchDrivers = JSON.parseArray( + Dc3Util.inputStreamToString(multipartFile.getInputStream()), + BatchDriver.class + ); + if (null == batchDrivers) { + throw new ServiceException("Import file is blank"); + } + return batchService.batchImport(batchDrivers) ? R.ok() : R.fail(); + } catch (Exception e) { + return R.fail(e.getMessage()); + } + } + + @Override + public R batchImportBatchDriver(List batchDrivers) { + try { + if (null == batchDrivers) { + throw new ServiceException("Import file is blank"); + } + return batchService.batchImport(batchDrivers) ? R.ok() : R.fail(); } catch (Exception e) { return R.fail(e.getMessage()); } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/BatchService.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/BatchService.java index 889354e76..ee5c5c98c 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/BatchService.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/BatchService.java @@ -16,7 +16,9 @@ package com.dc3.center.manager.service; -import org.springframework.web.multipart.MultipartFile; +import com.dc3.common.bean.batch.BatchDriver; + +import java.util.List; /** *

BatchService Interface @@ -28,9 +30,9 @@ public interface BatchService { /** * 批量导入 All, 包含:驱动->模版->驱动配置->位号->设备->位号配置 * - * @param multipartFile MultipartFile + * @param batchDrivers List * @return */ - Boolean batchImport(MultipartFile multipartFile); + Boolean batchImport(List batchDrivers); } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java index d21e47d7c..5c39d1d47 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java @@ -69,20 +69,8 @@ public class BatchServiceImpl implements BatchService { @Override @Transactional - public Boolean batchImport(MultipartFile multipartFile) { - if (multipartFile.isEmpty()) { - throw new ServiceException("Import file is empty"); - } + public Boolean batchImport(List batchDrivers) { try { - // Convert json file to ImportAll object - List batchDrivers = JSON.parseArray( - Dc3Util.inputStreamToString(multipartFile.getInputStream()), - BatchDriver.class - ); - if (null == batchDrivers) { - throw new ServiceException("Import file is blank"); - } - batchDrivers.forEach(batchDriver -> { if (StringUtils.isBlank(batchDriver.getServiceName())) { throw new ServiceException("Driver service name is blank"); diff --git a/dc3-common/dc3-base/pom.xml b/dc3-common/dc3-base/pom.xml index 27297632a..59cf2f8cb 100644 --- a/dc3-common/dc3-base/pom.xml +++ b/dc3-common/dc3-base/pom.xml @@ -49,7 +49,7 @@ validation-api - + io.jsonwebtoken jjwt @@ -62,6 +62,12 @@ slf4j-api + + + commons-fileupload + commons-fileupload + + com.google.guava diff --git a/dc3-common/dc3-base/src/main/java/com/dc3/common/utils/Dc3Util.java b/dc3-common/dc3-base/src/main/java/com/dc3/common/utils/Dc3Util.java index 955b889ad..d3da04205 100644 --- a/dc3-common/dc3-base/src/main/java/com/dc3/common/utils/Dc3Util.java +++ b/dc3-common/dc3-base/src/main/java/com/dc3/common/utils/Dc3Util.java @@ -22,10 +22,13 @@ import com.dc3.common.constant.Common; import com.dc3.common.dto.NodeDto; import com.google.common.base.Charsets; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.*; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; @@ -237,6 +240,31 @@ public class Dc3Util { } } + /** + * File 转 MultipartFile + * + * @param fileInputStream FileInputStream + * @return MultipartFile + */ + public static MultipartFile fileInputStreamToMultipartFile(FileInputStream fileInputStream) { + FileItemFactory factory = new DiskFileItemFactory(16, null); + String textFieldName = "file"; + FileItem item = factory.createItem(textFieldName, "text/plain", true, "Dc3MultipartFile"); + try { + int length = 0; + byte[] buffer = new byte[1024]; + OutputStream outputStream = item.getOutputStream(); + while ((length = fileInputStream.read(buffer)) > -1) { + outputStream.write(buffer, 0, length); + } + outputStream.close(); + fileInputStream.close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + return new CommonsMultipartFile(item); + } + /** * 两层循环实现建树 * diff --git a/dc3-common/dc3-config/src/main/resources/bootstrap.yml b/dc3-common/dc3-config/src/main/resources/bootstrap.yml index 928e8f5d8..088277247 100644 --- a/dc3-common/dc3-config/src/main/resources/bootstrap.yml +++ b/dc3-common/dc3-config/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ server: thread: prefix: dc3-thread- core-pool-size: 4 - maximum-pool-size: 512 + maximum-pool-size: 1024 keep-alive-time: 10 spring: @@ -95,7 +95,7 @@ management: feign: hystrix: - enabled: true + enabled: false httpclient: enabled: false okhttp: @@ -103,7 +103,6 @@ feign: compression: request: enabled: true - mime-types: application/json response: enabled: true use-gzip-decoder: true @@ -112,16 +111,12 @@ hystrix: command: default: execution: - timeout: - enable: true isolation: thread: - timeout-in-milliseconds: 5000 + timeoutInMilliseconds: 30000 threadpool: default: - core-size: 20 - max-queue-size: 100 - queue-size-rejection-threshold: 80 + coreSize: 1024 eureka: instance: diff --git a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java index d77e6a0c4..21e4a9b55 100644 --- a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java +++ b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/bean/DriverContext.java @@ -75,7 +75,7 @@ public class DriverContext { public Device getDevice(Long deviceId) { Device device = deviceMap.get(deviceId); if (null == device) { - throw new ServiceException("device(" + deviceId + ") does not exist"); + throw new ServiceException("Device(" + deviceId + ") does not exist"); } return device; } @@ -104,11 +104,11 @@ public class DriverContext { public Point getDevicePoint(Long deviceId, Long pointId) { Map map = profilePointMap.get(getDevice(deviceId).getProfileId()); if (null == map) { - throw new ServiceException("device(" + deviceId + ") profile does not exist"); + throw new ServiceException("Device(" + deviceId + ") profile does not exist"); } Point point = map.get(pointId); if (null == point) { - throw new ServiceException("device(" + pointId + ") point does not exist"); + throw new ServiceException("Point(" + pointId + ") point does not exist"); } return point; } @@ -123,11 +123,11 @@ public class DriverContext { public Long getDevicePointIdByName(Long deviceId, String pointName) { Map map = devicePointNameMap.get(deviceId); if (null == map) { - throw new ServiceException("device(" + deviceId + ") does not exist"); + throw new ServiceException("Device(" + deviceId + ") does not exist"); } Long pointId = map.get(pointName); if (null == pointId) { - throw new ServiceException("point(" + pointId + ") does not exist"); + throw new ServiceException("Point(" + pointName + ") does not exist"); } return pointId; } @@ -152,11 +152,11 @@ public class DriverContext { public Map getDevicePointInfo(Long deviceId, Long pointId) { Map> tmpMap = devicePointInfoMap.get(deviceId); if (null == tmpMap) { - throw new ServiceException("device(" + deviceId + ") does not exist"); + throw new ServiceException("Device(" + deviceId + ") does not exist"); } Map infoMap = tmpMap.get(pointId); if (null == infoMap) { - throw new ServiceException("point(" + pointId + ") info does not exist"); + throw new ServiceException("Point(" + pointId + ") info does not exist"); } return infoMap; } diff --git a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/service/rabbit/DriverService.java b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/service/rabbit/DriverService.java index 8470466fe..aee14daa8 100644 --- a/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/service/rabbit/DriverService.java +++ b/dc3-common/dc3-sdk/src/main/java/com/dc3/common/sdk/service/rabbit/DriverService.java @@ -17,6 +17,9 @@ package com.dc3.common.sdk.service.rabbit; import cn.hutool.core.convert.Convert; +import com.dc3.api.center.manager.feign.BatchClient; +import com.dc3.common.bean.R; +import com.dc3.common.bean.batch.BatchDriver; import com.dc3.common.bean.driver.DeviceStatus; import com.dc3.common.bean.driver.PointValue; import com.dc3.common.constant.Common; @@ -45,6 +48,20 @@ public class DriverService { private DriverContext driverContext; @Resource private RabbitTemplate rabbitTemplate; + @Resource + private BatchClient batchClient; + + /** + * 批量导入 + * 可通过解析配置文件实现 + * + * @param batchDrivers List + * @return boolean + */ + public boolean batchImportBatchDriver(List batchDrivers) { + R batchDriver = batchClient.batchImportBatchDriver(batchDrivers); + return batchDriver.isOk(); + } /** * 发送设备状态 diff --git a/dc3-common/dc3-sdk/src/main/resources/bootstrap.yml b/dc3-common/dc3-sdk/src/main/resources/bootstrap.yml index 074163cf6..902cab255 100644 --- a/dc3-common/dc3-sdk/src/main/resources/bootstrap.yml +++ b/dc3-common/dc3-sdk/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ server: thread: prefix: dc3-thread- core-pool-size: 4 - maximum-pool-size: 512 + maximum-pool-size: 1024 keep-alive-time: 10 spring: @@ -64,7 +64,7 @@ management: feign: hystrix: - enabled: true + enabled: false httpclient: enabled: false okhttp: @@ -80,16 +80,12 @@ hystrix: command: default: execution: - timeout: - enable: true isolation: thread: - timeout-in-milliseconds: 5000 + timeoutInMilliseconds: 30000 threadpool: default: - core-size: 20 - max-queue-size: 100 - queue-size-rejection-threshold: 80 + coreSize: 1024 eureka: instance: diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java index 63200b32f..396ae1c31 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServer.java @@ -23,6 +23,7 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import lombok.SneakyThrows; import org.springframework.stereotype.Component; @@ -46,7 +47,11 @@ public class NettyTcpServer { .childHandler(new ChannelInitializer() { @Override protected void initChannel(SocketChannel socketChannel) { - socketChannel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyTcpServerHandler()); + socketChannel.pipeline().addLast( + new WriteTimeoutHandler(30), + new ReadTimeoutHandler(30), + new NettyTcpServerHandler() + ); } }); ChannelFuture future = bootstrap.bind().sync(); diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java index de44b51ea..56fcbb103 100644 --- a/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/java/com/dc3/driver/service/netty/NettyTcpServerHandler.java @@ -16,6 +16,9 @@ package com.dc3.driver.service.netty; +import com.alibaba.fastjson.JSON; +import com.dc3.common.bean.batch.BatchDevice; +import com.dc3.common.bean.batch.BatchDriver; import com.dc3.common.bean.driver.PointValue; import com.dc3.common.constant.Common; import com.dc3.common.exception.ServiceException; @@ -23,6 +26,7 @@ import com.dc3.common.sdk.bean.AttributeInfo; import com.dc3.common.sdk.bean.DriverContext; import com.dc3.common.sdk.service.rabbit.DriverService; import com.dc3.common.sdk.util.DriverUtils; +import com.dc3.common.utils.Dc3Util; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandler; @@ -33,6 +37,8 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -95,11 +101,11 @@ import java.util.concurrent.TimeUnit; public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { private static final String START_TAG = "fefefe"; - private static NettyTcpServerHandler that; + private static NettyTcpServerHandler nettyTcpServerHandler; @PostConstruct public void init() { - that = this; + nettyTcpServerHandler = this; } @Resource @@ -107,6 +113,75 @@ public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { @Resource private DriverContext driverContext; + @Override + public void channelActive(ChannelHandlerContext context) { + log.debug("Water 188B Driver Listener({}) accept clint({})", context.channel().localAddress(), context.channel().remoteAddress()); + } + + @Override + public void channelRead(ChannelHandlerContext context, Object msg) { + ByteBuf byteBuf = (ByteBuf) msg; + decode(context, byteBuf); + } + + @Override + public void exceptionCaught(ChannelHandlerContext context, Throwable throwable) { + log.error(throwable.getMessage(), throwable); + context.close(); + } + + /** + * 自注册设备 + * + * @param deviceName + * @throws IOException + */ + private void autoRegister(String deviceName) throws IOException { + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("import/batch-import-188b-tcp-template.json"); + if (null == inputStream) { + inputStream = this.getClass().getResourceAsStream("import/batch-import-188b-tcp-template.json"); + } + List batchDrivers = JSON.parseArray( + Dc3Util.inputStreamToString(inputStream), + BatchDriver.class + ); + BatchDevice batchDevice = new BatchDevice(); + batchDevice.setName(deviceName); + batchDrivers.get(0).getProfiles().get(0).getGroups().get(0).getDevices().add(batchDevice); + nettyTcpServerHandler.driverService.batchImportBatchDriver(batchDrivers); + } + + public void decode(ChannelHandlerContext context, ByteBuf byteBuf) { + if (!START_TAG.equals(ByteBufUtil.hexDump(byteBuf, 0, 3))) { + throw new ServiceException("Start Tag Invalid"); + } + String deviceName = ByteBufUtil.hexDump(byteBuf, 5, 7); + log.info("Receive Device({})[{}] Bytes -> {}", deviceName, context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); + + List pointValues = new ArrayList<>(); + Long deviceId; + try { + deviceId = nettyTcpServerHandler.driverContext.getDeviceIdByName(deviceName); + } catch (Exception ignored) { + log.info("Auto register device : {}", deviceName); + try { + autoRegister(deviceName); + } catch (IOException e) { + log.error("Auto register device({}) error {}", deviceName, e.getMessage(), e); + return; + } + deviceId = nettyTcpServerHandler.driverContext.getDeviceIdByName(deviceName); + } + + Map> pointInfoMap = nettyTcpServerHandler.driverContext.getDevicePointInfoMap().get(deviceId); + for (Long pointId : pointInfoMap.keySet()) { + PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); + pointValues.add(pointValue); + } + PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS); + nettyTcpServerHandler.driverService.multiPointValueSender(pointValue); + } + /** * 解析 Point Value 数据 * @@ -116,7 +191,7 @@ public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { * @param byteBuf ByteBuf * @return PointValue */ - private PointValue pointValueDecode(long deviceId, long pointId, Map infoMap, ByteBuf byteBuf) { + public PointValue pointValueDecode(long deviceId, long pointId, Map infoMap, ByteBuf byteBuf) { String type = DriverUtils.value(infoMap.get("type").getType(), infoMap.get("type").getValue()); int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue()); int length = DriverUtils.value(infoMap.get("length").getType(), infoMap.get("length").getValue()); @@ -125,15 +200,15 @@ public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { switch (type.toLowerCase()) { case Common.ValueType.HEX: rawValue = ByteBufUtil.hexDump(byteBuf.retainedSlice(start, length)).toUpperCase(); - value = that.driverService.convertValue(deviceId, pointId, rawValue); + value = nettyTcpServerHandler.driverService.convertValue(deviceId, pointId, rawValue); break; case Common.ValueType.SHORT: rawValue = String.valueOf(byteBuf.getShortLE(start)); - value = that.driverService.convertValue(deviceId, pointId, rawValue); + value = nettyTcpServerHandler.driverService.convertValue(deviceId, pointId, rawValue); break; case Common.ValueType.INT: rawValue = String.valueOf(DriverUtils.bytesToIntLE(ByteBufUtil.getBytes(byteBuf, start, length))); - value = that.driverService.convertValue(deviceId, pointId, rawValue); + value = nettyTcpServerHandler.driverService.convertValue(deviceId, pointId, rawValue); break; default: throw new IllegalStateException("Unexpected value: " + type.toLowerCase()); @@ -148,7 +223,7 @@ public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { * * @return PointValue */ - private String customDecode(int start, String value) { + public String customDecode(int start, String value) { //信号强度额外处理 if (start == 163) { int csq = (int) Double.parseDouble(value); @@ -160,35 +235,4 @@ public class NettyTcpServerHandler extends ChannelInboundHandlerAdapter { return value; } - @Override - public void channelActive(ChannelHandlerContext context) { - log.debug("Water 188B Driver Listener({}) accept clint({})", context.channel().localAddress(), context.channel().remoteAddress()); - } - - @Override - public void channelRead(ChannelHandlerContext context, Object msg) { - ByteBuf byteBuf = (ByteBuf) msg; - if (!START_TAG.equals(ByteBufUtil.hexDump(byteBuf, 0, 3))) { - throw new ServiceException("Start Tag Invalid"); - } - String deviceName = ByteBufUtil.hexDump(byteBuf, 5, 7); - log.info("Receive Device({})[{}] Bytes -> {}", deviceName, context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); - - List pointValues = new ArrayList<>(); - Long deviceId = that.driverContext.getDeviceIdByName(deviceName); - Map> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId); - for (Long pointId : pointInfoMap.keySet()) { - PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); - pointValues.add(pointValue); - } - PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS); - that.driverService.multiPointValueSender(pointValue); - } - - @Override - public void exceptionCaught(ChannelHandlerContext context, Throwable throwable) { - log.error(throwable.getMessage()); - context.close(); - } - } \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/import/batch-import-188b-tcp-template.json b/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/import/batch-import-188b-tcp-template.json new file mode 100644 index 000000000..a31a248e5 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-tcp/src/main/resources/import/batch-import-188b-tcp-template.json @@ -0,0 +1,650 @@ +[ + { + "serviceName": "dc3-driver-water-188b-tcp", + "profiles": [ + { + "name": "Water_188B_Tcp_Profile", + "share": true, + "points": [ + { + "name": "数据标识", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "反向累计量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "瞬时流量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "水压单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计水量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "剩余金额", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "状态", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "充值识别码", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "反向累计流量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "瞬时流量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "水压", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-0点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-1点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-2点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-3点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-4点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-5点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-6点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-7点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-8点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-9点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-10点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-11点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-12点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-13点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-14点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-15点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-16点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-17点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-18点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-19点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-20点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-21点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-22点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-23点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "信号强度", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + } + ], + "pointConfig": { + "数据标识": { + "start": 15, + "length": 2, + "type": "hex" + }, + "正向累计量单位": { + "start": 17, + "length": 1, + "type": "hex" + }, + "反向累计量单位": { + "start": 18, + "length": 1, + "type": "hex" + }, + "瞬时流量单位": { + "start": 19, + "length": 1, + "type": "hex" + }, + "水压单位": { + "start": 20, + "length": 1, + "type": "hex" + }, + "正向累计水量": { + "start": 21, + "length": 4, + "type": "int" + }, + "剩余金额": { + "start": 25, + "length": 4, + "type": "int" + }, + "状态": { + "start": 29, + "length": 4, + "type": "hex" + }, + "充值识别码": { + "start": 33, + "length": 1, + "type": "hex" + }, + "反向累计流量": { + "start": 34, + "length": 4, + "type": "int" + }, + "瞬时流量": { + "start": 38, + "length": 3, + "type": "int" + }, + "水压": { + "start": 41, + "length": 2, + "type": "short" + }, + "正向累计流量-0点": { + "start": 43, + "length": 4, + "type": "int" + }, + "正向累计流量-1点": { + "start": 48, + "length": 4, + "type": "int" + }, + "正向累计流量-2点": { + "start": 53, + "length": 4, + "type": "int" + }, + "正向累计流量-3点": { + "start": 58, + "length": 4, + "type": "int" + }, + "正向累计流量-4点": { + "start": 63, + "length": 4, + "type": "int" + }, + "正向累计流量-5点": { + "start": 68, + "length": 4, + "type": "int" + }, + "正向累计流量-6点": { + "start": 73, + "length": 4, + "type": "int" + }, + "正向累计流量-7点": { + "start": 78, + "length": 4, + "type": "int" + }, + "正向累计流量-8点": { + "start": 83, + "length": 4, + "type": "int" + }, + "正向累计流量-9点": { + "start": 88, + "length": 4, + "type": "int" + }, + "正向累计流量-10点": { + "start": 93, + "length": 4, + "type": "int" + }, + "正向累计流量-11点": { + "start": 98, + "length": 4, + "type": "int" + }, + "正向累计流量-12点": { + "start": 103, + "length": 4, + "type": "int" + }, + "正向累计流量-13点": { + "start": 108, + "length": 4, + "type": "int" + }, + "正向累计流量-14点": { + "start": 113, + "length": 4, + "type": "int" + }, + "正向累计流量-15点": { + "start": 118, + "length": 4, + "type": "int" + }, + "正向累计流量-16点": { + "start": 123, + "length": 4, + "type": "int" + }, + "正向累计流量-17点": { + "start": 128, + "length": 4, + "type": "int" + }, + "正向累计流量-18点": { + "start": 133, + "length": 4, + "type": "int" + }, + "正向累计流量-19点": { + "start": 138, + "length": 4, + "type": "int" + }, + "正向累计流量-20点": { + "start": 143, + "length": 4, + "type": "int" + }, + "正向累计流量-21点": { + "start": 148, + "length": 4, + "type": "int" + }, + "正向累计流量-22点": { + "start": 153, + "length": 4, + "type": "int" + }, + "正向累计流量-23点": { + "start": 158, + "length": 4, + "type": "int" + }, + "信号强度": { + "start": 163, + "length": 2, + "type": "short" + } + }, + "groups": [ + { + "name": "Water_188B_Tcp_Group", + "devices": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java index 25620b885..903c6555c 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java @@ -23,6 +23,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioDatagramChannel; +import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import lombok.SneakyThrows; import org.springframework.stereotype.Component; @@ -46,7 +47,11 @@ public class NettyUdpServer { .handler(new ChannelInitializer() { @Override protected void initChannel(Channel channel) { - channel.pipeline().addLast(new WriteTimeoutHandler(30), new NettyUdpServerHandler()); + channel.pipeline().addLast( + new WriteTimeoutHandler(30), + new ReadTimeoutHandler(30), + new NettyUdpServerHandler() + ); } }); ChannelFuture future = bootstrap.bind().sync(); diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java index 44dbd6246..f54b0f2e4 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServerHandler.java @@ -16,6 +16,9 @@ package com.dc3.driver.service.netty; +import com.alibaba.fastjson.JSON; +import com.dc3.common.bean.batch.BatchDevice; +import com.dc3.common.bean.batch.BatchDriver; import com.dc3.common.bean.driver.PointValue; import com.dc3.common.constant.Common; import com.dc3.common.exception.ServiceException; @@ -23,6 +26,7 @@ import com.dc3.common.sdk.bean.AttributeInfo; import com.dc3.common.sdk.bean.DriverContext; import com.dc3.common.sdk.service.rabbit.DriverService; import com.dc3.common.sdk.util.DriverUtils; +import com.dc3.common.utils.Dc3Util; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; @@ -33,6 +37,8 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -94,11 +100,11 @@ import java.util.concurrent.TimeUnit; public class NettyUdpServerHandler extends SimpleChannelInboundHandler { private static final String START_TAG = "fefefe"; - private static NettyUdpServerHandler that; + private static NettyUdpServerHandler nettyUdpServerHandler; @PostConstruct public void init() { - that = this; + nettyUdpServerHandler = this; } @Resource @@ -106,6 +112,70 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler batchDrivers = JSON.parseArray( + Dc3Util.inputStreamToString(inputStream), + BatchDriver.class + ); + BatchDevice batchDevice = new BatchDevice(); + batchDevice.setName(deviceName); + batchDrivers.get(0).getProfiles().get(0).getGroups().get(0).getDevices().add(batchDevice); + nettyUdpServerHandler.driverService.batchImportBatchDriver(batchDrivers); + } + + public void decode(ChannelHandlerContext context, ByteBuf byteBuf) { + if (!START_TAG.equals(ByteBufUtil.hexDump(byteBuf, 0, 3))) { + throw new ServiceException("Start Tag Invalid"); + } + String deviceName = ByteBufUtil.hexDump(byteBuf, 5, 7); + log.info("Receive Device({})[{}] Bytes -> {}", deviceName, context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); + + List pointValues = new ArrayList<>(); + Long deviceId; + try { + deviceId = nettyUdpServerHandler.driverContext.getDeviceIdByName(deviceName); + } catch (Exception ignored) { + log.info("Auto register device : {}", deviceName); + try { + autoRegister(deviceName); + } catch (IOException e) { + log.error("Auto register device({}) error {}", deviceName, e.getMessage(), e); + return; + } + deviceId = nettyUdpServerHandler.driverContext.getDeviceIdByName(deviceName); + } + + Map> pointInfoMap = nettyUdpServerHandler.driverContext.getDevicePointInfoMap().get(deviceId); + for (Long pointId : pointInfoMap.keySet()) { + PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); + pointValues.add(pointValue); + } + PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS); + nettyUdpServerHandler.driverService.multiPointValueSender(pointValue); + } + /** * 解析 Point Value 数据 * @@ -124,15 +194,15 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler {}", deviceName, context.channel(), ByteBufUtil.hexDump(byteBuf).toUpperCase()); - - List pointValues = new ArrayList<>(); - Long deviceId = that.driverContext.getDeviceIdByName(deviceName); - Map> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId); - for (Long pointId : pointInfoMap.keySet()) { - PointValue pointValue = pointValueDecode(deviceId, pointId, pointInfoMap.get(pointId), byteBuf); - pointValues.add(pointValue); - } - PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS); - that.driverService.multiPointValueSender(pointValue); - } - - @Override - public void exceptionCaught(ChannelHandlerContext context, Throwable throwable) { - log.error(throwable.getMessage()); - context.close(); - } } \ No newline at end of file diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/import/batch-import-188b-udp-template.json b/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/import/batch-import-188b-udp-template.json new file mode 100644 index 000000000..5af0882c2 --- /dev/null +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/resources/import/batch-import-188b-udp-template.json @@ -0,0 +1,650 @@ +[ + { + "serviceName": "dc3-driver-water-188b-udp", + "profiles": [ + { + "name": "Water_188B_Udp_Profile", + "share": true, + "points": [ + { + "name": "数据标识", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "反向累计量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "瞬时流量单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "水压单位", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计水量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "剩余金额", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "状态", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "充值识别码", + "type": "string", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "反向累计流量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "瞬时流量", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "水压", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-0点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-1点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-2点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-3点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-4点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-5点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-6点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-7点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-8点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-9点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-10点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-11点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-12点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-13点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-14点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-15点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-16点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-17点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-18点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-19点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-20点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-21点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-22点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "正向累计流量-23点", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 0.001, + "accrue": false, + "format": "%.3f", + "unit": "-" + }, + { + "name": "信号强度", + "type": "float", + "rw": 0, + "base": 0, + "minimum": -999999, + "maximum": 999999, + "multiple": 1, + "accrue": false, + "format": "%.3f", + "unit": "-" + } + ], + "pointConfig": { + "数据标识": { + "start": 15, + "length": 2, + "type": "hex" + }, + "正向累计量单位": { + "start": 17, + "length": 1, + "type": "hex" + }, + "反向累计量单位": { + "start": 18, + "length": 1, + "type": "hex" + }, + "瞬时流量单位": { + "start": 19, + "length": 1, + "type": "hex" + }, + "水压单位": { + "start": 20, + "length": 1, + "type": "hex" + }, + "正向累计水量": { + "start": 21, + "length": 4, + "type": "int" + }, + "剩余金额": { + "start": 25, + "length": 4, + "type": "int" + }, + "状态": { + "start": 29, + "length": 4, + "type": "hex" + }, + "充值识别码": { + "start": 33, + "length": 1, + "type": "hex" + }, + "反向累计流量": { + "start": 34, + "length": 4, + "type": "int" + }, + "瞬时流量": { + "start": 38, + "length": 3, + "type": "int" + }, + "水压": { + "start": 41, + "length": 2, + "type": "short" + }, + "正向累计流量-0点": { + "start": 43, + "length": 4, + "type": "int" + }, + "正向累计流量-1点": { + "start": 48, + "length": 4, + "type": "int" + }, + "正向累计流量-2点": { + "start": 53, + "length": 4, + "type": "int" + }, + "正向累计流量-3点": { + "start": 58, + "length": 4, + "type": "int" + }, + "正向累计流量-4点": { + "start": 63, + "length": 4, + "type": "int" + }, + "正向累计流量-5点": { + "start": 68, + "length": 4, + "type": "int" + }, + "正向累计流量-6点": { + "start": 73, + "length": 4, + "type": "int" + }, + "正向累计流量-7点": { + "start": 78, + "length": 4, + "type": "int" + }, + "正向累计流量-8点": { + "start": 83, + "length": 4, + "type": "int" + }, + "正向累计流量-9点": { + "start": 88, + "length": 4, + "type": "int" + }, + "正向累计流量-10点": { + "start": 93, + "length": 4, + "type": "int" + }, + "正向累计流量-11点": { + "start": 98, + "length": 4, + "type": "int" + }, + "正向累计流量-12点": { + "start": 103, + "length": 4, + "type": "int" + }, + "正向累计流量-13点": { + "start": 108, + "length": 4, + "type": "int" + }, + "正向累计流量-14点": { + "start": 113, + "length": 4, + "type": "int" + }, + "正向累计流量-15点": { + "start": 118, + "length": 4, + "type": "int" + }, + "正向累计流量-16点": { + "start": 123, + "length": 4, + "type": "int" + }, + "正向累计流量-17点": { + "start": 128, + "length": 4, + "type": "int" + }, + "正向累计流量-18点": { + "start": 133, + "length": 4, + "type": "int" + }, + "正向累计流量-19点": { + "start": 138, + "length": 4, + "type": "int" + }, + "正向累计流量-20点": { + "start": 143, + "length": 4, + "type": "int" + }, + "正向累计流量-21点": { + "start": 148, + "length": 4, + "type": "int" + }, + "正向累计流量-22点": { + "start": 153, + "length": 4, + "type": "int" + }, + "正向累计流量-23点": { + "start": 158, + "length": 4, + "type": "int" + }, + "信号强度": { + "start": 163, + "length": 2, + "type": "short" + } + }, + "groups": [ + { + "name": "Water_188B_Udp_Group", + "devices": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/dc3-driver/pom.xml b/dc3-driver/pom.xml index b6cdc3df2..827c89feb 100644 --- a/dc3-driver/pom.xml +++ b/dc3-driver/pom.xml @@ -82,6 +82,7 @@ src/main/resources **/application.yml + **/*.json true diff --git a/dc3/api/files/batch-import-188b-tcp-template.json b/dc3/api/files/batch-import-188b-tcp-template.json index fe83380e8..76193609e 100644 --- a/dc3/api/files/batch-import-188b-tcp-template.json +++ b/dc3/api/files/batch-import-188b-tcp-template.json @@ -3,7 +3,7 @@ "serviceName": "dc3-driver-water-188b-tcp", "profiles": [ { - "name": "Water188B_TCP_Profile", + "name": "Water188B_Tcp_Profile", "share": true, "points": [ { @@ -640,7 +640,7 @@ }, "groups": [ { - "name": "水表", + "name": "Water_Tcp_Group", "devices": [ { "name": "06020107200636" diff --git a/dc3/api/files/batch-import-188b-udp-template.json b/dc3/api/files/batch-import-188b-udp-template.json index 471a93201..258658137 100644 --- a/dc3/api/files/batch-import-188b-udp-template.json +++ b/dc3/api/files/batch-import-188b-udp-template.json @@ -3,7 +3,7 @@ "serviceName": "dc3-driver-water-188b-udp", "profiles": [ { - "name": "Water188B_UDP_Profile", + "name": "Water188B_Udp_Profile", "share": true, "points": [ { @@ -640,7 +640,7 @@ }, "groups": [ { - "name": "水表", + "name": "Water_Udp_Group", "devices": [ { "name": "06020107200636" From bc66237a731c094eefd84708a2bd694613ed29ec Mon Sep 17 00:00:00 2001 From: pnoker Date: Mon, 24 Aug 2020 20:44:35 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=8F=96=E6=B6=88=20udp=20read=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/dc3/driver/service/netty/NettyUdpServer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java index 903c6555c..fd05d9d01 100644 --- a/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java +++ b/dc3-driver/dc3-driver-water-188b-udp/src/main/java/com/dc3/driver/service/netty/NettyUdpServer.java @@ -23,7 +23,6 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioDatagramChannel; -import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import lombok.SneakyThrows; import org.springframework.stereotype.Component; @@ -49,7 +48,6 @@ public class NettyUdpServer { protected void initChannel(Channel channel) { channel.pipeline().addLast( new WriteTimeoutHandler(30), - new ReadTimeoutHandler(30), new NettyUdpServerHandler() ); }