浏览代码

更新tcp相关修改

weizhengliang 3 年之前
父节点
当前提交
93c5592adf

+ 4 - 4
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/TcpClient.java

@@ -70,7 +70,7 @@ public class TcpClient {
                     protected void initChannel(SocketChannel socketChannel) throws Exception {
                         // 这里将LengthFieldBasedFrameDecoder添加到pipeline的首位,因为其需要对接收到的数据
                         // 进行长度字段解码,这里也会对数据进行粘包和拆包处理
-                        socketChannel.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024, 0, 2, 0, 2));
+                        socketChannel.pipeline().addLast(new LengthFieldBasedFrameDecoder(2048, 0, 2, 0, 2));
                         // LengthFieldPrepender是一个编码器,主要是在响应字节数据前面添加字节长度字段
                         socketChannel.pipeline().addLast(new LengthFieldPrepender(2));
                         //心跳包应当小于服务器间隔
@@ -105,7 +105,7 @@ public class TcpClient {
         }
         connecting = true;
 
-        System.out.println("connect start");
+        System.out.println("tcp connect start");
         ChannelFuture future = bootstrap.connect().addListener(new ChannelFutureListener() {
             @Override
             public void operationComplete(ChannelFuture channelFuture) throws Exception {
@@ -114,11 +114,11 @@ public class TcpClient {
                     isRunning = true;
                     channel = channelFuture.channel();
                     retryTimes = 1;
-                    System.out.println("connect success");
+                    System.out.println("tcp connect success");
                 } else {
                     //连接失败时的处理
                     isRunning = false;
-                    System.out.println("connect retry : " + retryTimes);
+                    System.out.println("tcp connect retry : " + retryTimes);
                     channelFuture.channel().eventLoop().schedule(new Runnable() {
                         @Override
                         public void run() {

+ 7 - 6
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/TcpClientHandler.java

@@ -67,11 +67,13 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
         }else {
             TcpModel tcpModel = TcpModel.getModelByJson(source);
 
-            TcpModel responseTcpModel = DeviceChannel.handleTcpReceived(tcpModel);
-            if (responseTcpModel!=null){
-                ctx.writeAndFlush(responseTcpModel.toJson());
-            } else {
-                ReferenceCountUtil.release(source);
+            if (tcpModel != null) {
+                TcpModel responseTcpModel = DeviceChannel.handleTcpReceived(tcpModel);
+                if (responseTcpModel != null) {
+                    ctx.writeAndFlush(responseTcpModel.toJson());
+                } else {
+                    ReferenceCountUtil.release(source);
+                }
             }
         }
 
@@ -89,7 +91,6 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
                 ctx.close();
             } else if (event.state() == IdleState.ALL_IDLE) {
                 Log.i(TAG, "TcpClientHandler ===> ALL_IDLE");
-
             }
         }
     }

+ 11 - 1
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/channel/DeviceUtil.java

@@ -1,5 +1,9 @@
 package com.wdkl.ncs.android.middleware.tcp.channel;
 
+import android.os.Build;
+
+import com.wdkl.ncs.android.middleware.BuildConfig;
+import com.wdkl.ncs.android.middleware.tcp.dto.DeviceConnectDTO;
 import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel;
 import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction;
 import com.wdkl.ncs.android.middleware.tcp.enums.TcpType;
@@ -7,9 +11,15 @@ import com.wdkl.ncs.android.middleware.tcp.enums.TcpType;
 public class DeviceUtil {
     public static TcpModel deviceConnect(String mac){
         TcpModel tcpModel = new TcpModel();
+        DeviceConnectDTO connectDTO = new DeviceConnectDTO();
+        connectDTO.setIdentification(mac);
+        connectDTO.setHardware_version(Build.PRODUCT.toLowerCase());
+        connectDTO.setSoftware_version("V"+ BuildConfig.VERSION_NAME);
+        connectDTO.setModel(Build.MODEL);
+        connectDTO.setCode(Build.SERIAL);
         tcpModel.setType(TcpType.DEVICE);
         tcpModel.setAction(TcpAction.DeviceAction.CONNECT);
-        tcpModel.setData(mac);
+        tcpModel.setData(connectDTO);
         return tcpModel;
     }
 }

+ 73 - 0
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/dto/DeviceConnectDTO.java

@@ -0,0 +1,73 @@
+package com.wdkl.ncs.android.middleware.tcp.dto;
+
+import java.io.Serializable;
+
+/**
+ * @author wuyunfeng
+ * 2021-12-07 16:29
+ */
+public class DeviceConnectDTO implements Serializable {
+
+    /**设备唯一标识 */
+    private String identification;
+
+    /**
+     * 软件版本,客户端运行的app 版本号
+     */
+    private String software_version;
+
+    /**
+     * 固件版本号
+     */
+    private String hardware_version;
+
+    /**
+     * 设备型号
+     */
+    private String model;
+
+    /**
+     * 设备序列号
+     */
+    private String code;
+
+    public String getIdentification() {
+        return identification;
+    }
+
+    public void setIdentification(String identification) {
+        this.identification = identification;
+    }
+
+    public String getSoftware_version() {
+        return software_version;
+    }
+
+    public void setSoftware_version(String software_version) {
+        this.software_version = software_version;
+    }
+
+    public String getHardware_version() {
+        return hardware_version;
+    }
+
+    public void setHardware_version(String hardware_version) {
+        this.hardware_version = hardware_version;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+}

+ 54 - 19
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/enums/TcpAction.java

@@ -16,7 +16,7 @@ public interface TcpAction {
     enum CallbackAction implements TcpAction {
         SUCCESS("同步"),
         FAILED("失败");
-        private String description;
+        private final String description;
         CallbackAction(String description){
             this.description = description;
         }
@@ -50,7 +50,7 @@ public interface TcpAction {
         CANCEL("取消");
 
 
-        private String description;
+        private final String description;
         PhoneAction(String description){
             this.description = description;
         }
@@ -77,6 +77,7 @@ public interface TcpAction {
 
     enum VoiceAction implements TcpAction {
         CALL("呼叫"),
+        VCALL("视频呼叫"),
         ACCEPT("接受呼叫"),
         ACCEPTED("已接听"),
         REJECT("拒绝"),
@@ -86,13 +87,13 @@ public interface TcpAction {
         CANCEL("取消"),
         PCALLING("已经通话中"),
         VOICE_OFF("通话被接听"),
-        CANCEL_BY_DOOR("门口机取消分机呼叫"),
         RS485CALL("485界面发起呼叫"),
         RS485CANCEL("485界面呼叫取消"),
         RS485CANCEL_BY_DOOR("485门口机取消房间内的呼叫"),
         RS485HANDOFF("485界面挂断"),
         RS485ACCEPT("485界面接听"),
         RS485REJECT("485界面拒绝"),
+        CANCEL_BY_DOOR("门口机取消分机呼叫"),
         SUCCESS("呼叫成功"),
         FAILED("呼叫失败"),
         GAIN_CALL("应答"),
@@ -101,7 +102,7 @@ public interface TcpAction {
         GAINED("呼叫被应答");
 
 
-        private String description;
+        private final String description;
         VoiceAction(String description){
             this.description = description;
         }
@@ -140,7 +141,7 @@ public interface TcpAction {
         SUCCESS("呼叫成功"),
         FAILED("呼叫失败");
 
-        private String description;
+        private final String description;
         VideoAction(String description){
             this.description = description;
         }
@@ -172,17 +173,24 @@ public interface TcpAction {
         TRANSFER("转接"),
         ALARM_TEST("测试报警"),
         ALARM_INTRUSION("侵入报警"),
+        ALARM_INFRARED_NO_TRIGGER("红外报警"),
         ALARM_ON_EIGHT_HOURS("八小时无人报警"),
         ALARM_ON_TWELVE_HOURS("十二小时无人报警"),
         ALARM_ON_TWENTY_FOUR_HOURS("二十四小时无人报警"),
         ALARM_DISASSEMBLE("防拆报警"),
         ALARM_FAULT("故障报警"),
         ALARM_DOOR_LOCK("门磁报警"),
+        ALARM_RESTRAINT_BAND("约束带报警"),
         ALARM_SMOKE("烟感报警"),
         ALARM_GAS("燃气报警"),
-        ALARM_WATER_OVERFLOW("浸水报警");
-
-        private String description;
+        ALARM_WATER_OVERFLOW("浸水报警"),
+        ALARM_LOW_VOLTAGE("低电压报警"),
+        ALARM_TEMPERATURE("温度报警"),
+        ALARM_FALL("跌到报警"),
+        ALARM_VITAL("体征报警"),
+        AlARM_BUTTON("紧急按钮");
+
+        private final String description;
         SOSAction(String description){
             this.description = description;
         }
@@ -211,7 +219,7 @@ public interface TcpAction {
         CALL("增援"),
         RESPONSED("已响应");
 
-        private String description;
+        private final String description;
         ReinforceAction(String description){
             this.description = description;
         }
@@ -242,7 +250,7 @@ public interface TcpAction {
         MSG_READ("语音留言已读"),
         RECEIVED("客户端收到确认");
 
-        private String description;
+        private final String description;
         IMAction(String description){
             this.description = description;
         }
@@ -273,7 +281,7 @@ public interface TcpAction {
         MSG_READ("语音留言已读"),
         RECEIVED("接收端收到确认");
 
-        private String description;
+        private final String description;
         CHANNELIMAction(String description){
             this.description = description;
         }
@@ -306,9 +314,10 @@ public interface TcpAction {
         DEVICE_REFRESH("设备刷新"),
         SYSTEM_SETTING("系统设置"),
         DEVICE_CHANGE("设备更换"),
-        USER_CHANGE("用户绑定");
+        USER_CHANGE("用户绑定"),
+        SERVER_CHANGE("设备ip地址更换");
 
-        private String description;
+        private final String description;
         DeviceAction(String description){
             this.description = description;
         }
@@ -339,7 +348,7 @@ public interface TcpAction {
         CANCEL("取消"),
         CANCEL_CONFIRM("接收端确认收到取消"),
         COMPLETED("完成");
-        private String description;
+        private final String description;
         EventAction(String description){
             this.description = description;
         }
@@ -371,7 +380,7 @@ public interface TcpAction {
         SOS_CANCEL("取消"),
         NURSING("护理"),
         NURSING_END("护理结束");
-        private String description;
+        private final String description;
         SideAction(String description){
             this.description = description;
         }
@@ -400,7 +409,7 @@ public interface TcpAction {
     enum DataAction implements TcpAction {
         REFRESH("刷新数据"),
         INTERACTION("刷新交互列表");
-        private String description;
+        private final String description;
         DataAction(String description){
             this.description = description;
         }
@@ -427,7 +436,7 @@ public interface TcpAction {
     enum BroadcastAction implements TcpAction {
         START("开始"),
         STOP("停止");
-        private String description;
+        private final String description;
         BroadcastAction(String description){
             this.description = description;
         }
@@ -453,7 +462,7 @@ public interface TcpAction {
 
     enum TimeAction implements TcpAction {
         SYNC("同步");
-        private String description;
+        private final String description;
         TimeAction(String description){
             this.description = description;
         }
@@ -491,7 +500,7 @@ public interface TcpAction {
         FAILED("连接失败");
 
 
-        private String description;
+        private final String description;
 
         EntraceGuardAction(String description) {
             this.description = description;
@@ -516,4 +525,30 @@ public interface TcpAction {
         }
     }
 
+    enum LocationAction implements TcpAction {
+        ASK("主动询问"),
+        UPDATE("上传数据");
+        private final String description;
+        LocationAction(String description){
+            this.description = description;
+        }
+        public String getDescription() {
+            return description;
+        }
+
+        public String getName(){
+            return this.name();
+        }
+
+        private final static Map<String , LocationAction> ENUM_MAP = new HashMap<String, LocationAction>();
+        static {
+            for(LocationAction v : values()) {
+                ENUM_MAP.put(v.toString() , v);
+            }
+        }
+        public static LocationAction fromString(String v) {
+            LocationAction userOptionEnum = ENUM_MAP.get(v);
+            return userOptionEnum == null ? ASK :userOptionEnum;
+        }
+    }
 }