Quellcode durchsuchen

柜锁代码 定义编码规范

liubo vor 2 Jahren
Ursprung
Commit
76fb20ab06

+ 22 - 38
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/netty/NettyServerHandler.java

@@ -9,15 +9,13 @@ import com.zd.laboratory.domain.LabHardware;
 import com.zd.laboratory.domain.vo.LabHardwareVO;
 import com.zd.laboratory.mapper.LabAbnormalMapper;
 import com.zd.laboratory.mapper.LabHardwareMapper;
+import com.zd.laboratory.socket.constant.SocketTypes;
 import com.zd.laboratory.socket.runner.TCPServer;
 import com.zd.laboratory.utils.CRCCHECK;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandler;
 import lombok.extern.slf4j.Slf4j;
 
-import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executors;
@@ -41,32 +39,15 @@ public class NettyServerHandler implements ChannelInboundHandler {
         if(data.equals("6862")){
             return;
         }
+        // 采集器规范定义 hex发送  结构  31 11 01 01  后两位递增方式增加
+        String relayCode = data.substring(0, 8);
 
-        log.info("netty服务端接受消息转10进制为:" + ByteBuffer.wrap(msg).getLong());
-//        if(data.startsWith(SocketTypes.LOCK_PREFIX)){
-//        if(data.startsWith("33")){
-//        323020333320333320323020333320333320
-        String relayCode = data.substring(0, 36);
-//        33 31 20 33 30 20 36 33 20 33 36 20 36 34 20 33 37 20 33 36 20 33 33 20 33 31 20 33 35 20 33 31 20 33 35 20 33 30 20 36 33 20 33 33 20 33 35 20 33 32 20 33 37 20
-
-//        05 05 00 01 ee 00 d0 2e
-
+        if(relayCode.startsWith(SocketTypes.SZZQ_PREFIX)){
             // 将通道加入ChannelMap
-            ChannelMap.getChannelMap().put(data, channelHandlerContext);
-//        }else {
-//            if(data.length() != 12){
-//                log.info("netty柜锁回调指令非状态指令!" + data);
-//                return;
-//            }
+            if(relayCode.length() == data.length()){
+                ChannelMap.getChannelMap().put(data, channelHandlerContext);
 
-//            AtomicReference<String> relayCode = new AtomicReference<>("");
-//            ChannelMap.getChannelMap().entrySet().forEach(a -> {
-//                if(a.getValue() == channelHandlerContext){
-//                    relayCode.set(a.getKey());
-//                }
-//            });
-
-            if(data.length() > relayCode.length()) {
+            }else if(data.length() > relayCode.length()) {
                 data = data.replaceAll(relayCode, "");
                 // 柜锁bit 位
                 long bit = CRCCHECK.getBitByCommand(data);
@@ -84,6 +65,9 @@ public class NettyServerHandler implements ChannelInboundHandler {
                 RedisService redisService = SpringUtils.getBean(RedisService.class);
                 redisService.setCacheObject(relayCode + ":" + bit, status, 3 * 60L, TimeUnit.SECONDS);
             }
+        }
+
+
 
     }
 
@@ -94,18 +78,18 @@ public class NettyServerHandler implements ChannelInboundHandler {
     @Override
     public void channelReadComplete(ChannelHandlerContext channelHandlerContext) throws Exception {
 
-        log.info("netty服务端数据发送数据:" + NettyServer.inetPort);
-        ChannelFuture channelFuture = channelHandlerContext.writeAndFlush(NettyServer.inetPort);
-        channelFuture.addListener(new ChannelFutureListener() {
-            @Override
-            public void operationComplete(ChannelFuture channelFuture) throws Exception {
-                if(channelFuture.isSuccess()){
-                    log.info("服务端数据发送成功");
-                }else{
-                    log.info("服务端数据发送失败");
-                }
-            }
-        });
+//        log.info("netty服务端数据发送数据:" + NettyServer.inetPort);
+//        ChannelFuture channelFuture = channelHandlerContext.writeAndFlush(NettyServer.inetPort);
+//        channelFuture.addListener(new ChannelFutureListener() {
+//            @Override
+//            public void operationComplete(ChannelFuture channelFuture) throws Exception {
+//                if(channelFuture.isSuccess()){
+//                    log.info("服务端数据发送成功");
+//                }else{
+//                    log.info("服务端数据发送失败");
+//                }
+//            }
+//        });
     }
 
     /**

+ 5 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/socket/constant/SocketTypes.java

@@ -20,4 +20,9 @@ public class SocketTypes {
      * 柜锁数据
      */
     public static final String LOCK_PREFIX = "28";
+
+    /**
+     * 深圳智嵌采集器器
+     */
+    public static final String SZZQ_PREFIX = "3111";
 }