Browse Source

1.进入护理和退出护理时发送对应tcp
2.收到restart action时重启app

weizhengliang 3 years ago
parent
commit
7662a0d7ef

+ 18 - 1
callingdoor/src/main/java/com/wdkl/app/ncs/callingdoor/activity/CallingdoorActivity.kt

@@ -40,6 +40,7 @@ import com.wdkl.ncs.android.middleware.model.vo.DeviceRoomInfoVO
 import com.wdkl.ncs.android.middleware.model.vo.FrameBedVO
 import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
 import com.wdkl.ncs.android.middleware.tcp.TcpClient
+import com.wdkl.ncs.android.middleware.tcp.channel.OtherUtil
 import com.wdkl.ncs.android.middleware.tcp.channel.VoiceUtil
 import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
 import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
@@ -175,11 +176,17 @@ class CallingdoorActivity :BaseActivity<CallingdoorActivityPresenter, Callingdoo
                 SerialPortHelper.setDoorLight(1, "111") //白色
                 room_action_nurse.text = "进入护理"
                 room_action_nurse.setBackgroundResource(R.mipmap.bg_bottom_btn)
+                if (Constant.DEVICE_ID != -1) {
+                    OtherUtil.sendNursingEnd(Constant.DEVICE_ID)
+                }
             } else {
                 Constant.inNursing = true
                 SerialPortHelper.setDoorLight(1, "010") //绿色
                 room_action_nurse.text = "退出护理"
                 room_action_nurse.setBackgroundResource(R.mipmap.ic_bottom_btn_bg)
+                if (Constant.DEVICE_ID != -1) {
+                    OtherUtil.sendNursing(Constant.DEVICE_ID)
+                }
             }
         }
 
@@ -617,7 +624,13 @@ class CallingdoorActivity :BaseActivity<CallingdoorActivityPresenter, Callingdoo
                         } else if (tcpModel.action == TcpAction.DeviceAction.SYSTEM_SETTING) {
                             presenter.loadPartSettings(Constant.PART_ID)
                         } else if (tcpModel.action == TcpAction.DeviceAction.RESTART) {
-                            initDevice()
+                            //initDevice()
+                            //收到重启app指令,若当前处于正常待机状态则直接重启app,否则等待通话结束再重启
+                            if (Constant.CALL_STATE == Constant.CALL_STANDBY) {
+                                AppUpdateHelper.restartApp(activity)
+                            } else {
+                                Constant.LATER_RESTART = true
+                            }
                         }
                     } else if (tcpModel.action == TcpAction.DataAction.REFRESH) {
                         //重新加载数据
@@ -765,6 +778,10 @@ class CallingdoorActivity :BaseActivity<CallingdoorActivityPresenter, Callingdoo
                     } else {
                         view_title_layout_tv_point.setBackgroundResource(R.color.red_color)
                     }
+
+                    if (Constant.LATER_RESTART && Constant.CALL_STATE == Constant.CALL_STANDBY) {
+                        AppUpdateHelper.restartApp(activity)
+                    }
                 } else if (TextUtils.isEmpty(Constant.TCP_SERVER_URL)) {
                     //还未连接tcp服务器
                     presenter.loadTcpServerHost()

+ 17 - 0
callingdoor/src/main/java/com/wdkl/app/ncs/callingdoor/helper/AppUpdateHelper.java

@@ -1,5 +1,7 @@
 package com.wdkl.app.ncs.callingdoor.helper;
 
+import android.app.AlarmManager;
+import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
@@ -11,6 +13,8 @@ import android.os.Environment;
 import android.support.v4.content.FileProvider;
 import android.util.Log;
 
+import com.wdkl.ncs.android.component.welcome.activity.WelcomeActivity;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStreamReader;
@@ -217,6 +221,19 @@ public class AppUpdateHelper {
 
     }
 
+    public static void restartApp(Context context) {
+        //重新启动app
+        Intent mStartActivity = new Intent(context.getApplicationContext(), WelcomeActivity.class);
+        mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        int mPendingIntentId = 123456;
+        PendingIntent mPendingIntent = PendingIntent.getActivity(context.getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
+        AlarmManager mgr = (AlarmManager) context.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
+        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1500, mPendingIntent);
+
+        android.os.Process.killProcess(android.os.Process.myPid());
+        System.exit(0);
+    }
+
     public interface UpdateCallBack {
         void onFailed();
         void onSuccess();

+ 4 - 1
middleware/src/main/code/com/wdkl/ncs/android/middleware/common/Constant.java

@@ -19,6 +19,9 @@ public class Constant {
     //TCP连接是否成功
     public static boolean TCP_CONNECTED = false;
 
+    //延时重启app
+    public static boolean LATER_RESTART = false;
+
     //语音留言上传地址
     public static final String UPLOAD_VOICE_MSG_URL = "/ncs/upload/File";
 
@@ -52,7 +55,7 @@ public class Constant {
     public static String LOCAL_MAC = "";
 
     //设备ID
-    public static Integer DEVICE_ID;
+    public static Integer DEVICE_ID = -1;
 
     //房间ID
     public static Integer FRAME_ID = -1;

+ 30 - 4
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/channel/OtherUtil.java

@@ -7,7 +7,7 @@ import com.wdkl.ncs.android.middleware.tcp.enums.TcpType;
 
 public class OtherUtil {
     //分机SOS呼叫,不需要传toId
-    public static TcpModel SOSCall(Integer fromId){
+    public static TcpModel sosCall(Integer fromId){
         TcpModel tcpModel = new TcpModel();
         tcpModel.setType(TcpType.SOS);
         tcpModel.setAction(TcpAction.SOSAction.CALL);
@@ -15,7 +15,7 @@ public class OtherUtil {
         return tcpModel;
     }
 
-    public static TcpModel SOSCancel(Integer fromId, Integer toId){
+    public static TcpModel sosCancel(Integer fromId, Integer toId){
         TcpModel tcpModel = new TcpModel();
         tcpModel.setType(TcpType.SOS);
         tcpModel.setAction(TcpAction.SOSAction.CANCEL);
@@ -24,14 +24,40 @@ public class OtherUtil {
         return tcpModel;
     }
 
+    public static TcpModel nursing(Integer fromId){
+        TcpModel tcpModel = new TcpModel();
+        tcpModel.setType(TcpType.SIDE);
+        tcpModel.setAction(TcpAction.SideAction.NURSING);
+        tcpModel.setFromId(fromId);
+        return tcpModel;
+    }
+
+    public static TcpModel nursingEnd(Integer fromId){
+        TcpModel tcpModel = new TcpModel();
+        tcpModel.setType(TcpType.SIDE);
+        tcpModel.setAction(TcpAction.SideAction.NURSING_END);
+        tcpModel.setFromId(fromId);
+        return tcpModel;
+    }
+
     //发送sos相关tcp
     public static void sendSosCall(Integer fromId) {
-        TcpModel tcpModel = OtherUtil.SOSCall(fromId);
+        TcpModel tcpModel = OtherUtil.sosCall(fromId);
         TcpClient.getInstance().sendMsg(tcpModel.toJson());
     }
 
     public static void cancelSosCall(Integer fromId, Integer toId) {
-        TcpModel tcpModel = OtherUtil.SOSCancel(fromId, toId);
+        TcpModel tcpModel = OtherUtil.sosCancel(fromId, toId);
+        TcpClient.getInstance().sendMsg(tcpModel.toJson());
+    }
+
+    public static void sendNursing(Integer fromId) {
+        TcpModel tcpModel = OtherUtil.nursing(fromId);
+        TcpClient.getInstance().sendMsg(tcpModel.toJson());
+    }
+
+    public static void sendNursingEnd(Integer fromId) {
+        TcpModel tcpModel = OtherUtil.nursingEnd(fromId);
         TcpClient.getInstance().sendMsg(tcpModel.toJson());
     }
 }

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

@@ -43,13 +43,23 @@ public interface TcpAction {
     enum VoiceAction implements TcpAction {
         CALL("呼叫"),
         ACCEPT("接受呼叫"),
+        ACCEPTED("已接听"),
         REJECT("拒绝"),
         CALLING("通话中"),
         TRANSFER("转接"),
         HANDOFF("挂断"),
         CANCEL("取消"),
+        RS485CALL("485界面发起呼叫"),
+        RS485CANCEL("485界面呼叫取消"),
+        RS485HANDOFF("485界面挂断"),
+        RS485ACCEPT("485界面接听"),
+        RS485REJECT("485界面拒绝"),
         SUCCESS("呼叫成功"),
-        FAILED("呼叫失败");
+        FAILED("呼叫失败"),
+        GAIN_CALL("应答"),
+        GAIN_OK("应答成功"),
+        GAIN_FAIL("应答失败"),
+        GAINED("呼叫被应答");
 
 
         private String description;
@@ -240,7 +250,7 @@ public interface TcpAction {
     enum SideAction implements TcpAction {
         CALL("呼叫"),
         ACCEPT("接听"),
-        CANCEL("挂断"),
+        CANCEL("结束"),
         SOS_CALL("紧急呼叫"),
         SOS_CANCEL("取消"),
         NURSING("护理"),
@@ -356,13 +366,14 @@ public interface TcpAction {
         LOCKDOOR("锁门"),
         UNLOCKDOOR("开门"),
         ACCEPT("主机接受视频"),//通话空闲时自动接受
-        REJECT("主机拒绝视频"), // 通话忙时自动拒接
+        REJECT("拒绝"), // 通话忙时自动拒接
         OPENSPEAKER("打开麦克风"),//护士主机打开麦克风,门禁机也打开,双方停止等待音乐,打开后可以通话,默认只有视频界面,没有声音
         CLOSESPEAKER("关闭麦克风"),//关闭音频
         SUCCESS("连接主机成功"),
-        HANGUP("主机挂断,不开门"),
-        TIMEOUT("主机超时未响应"),
-        FAILED("连接主机失败");
+        HANGUP("挂断"),
+        TIMEOUT("响应超时"),
+        FAILED("连接失败");
+
 
         private String description;
 
@@ -388,4 +399,5 @@ public interface TcpAction {
             return userOptionEnum;
         }
     }
+
 }