1、放宽重连条件,防止总是重新登录
authorsnickersun <snickersun@qq.com>
Sun, 16 Feb 2020 10:50:24 +0000 (18:50 +0800)
committersnickersun <snickersun@qq.com>
Sun, 16 Feb 2020 10:50:24 +0000 (18:50 +0800)
2、设置心率检测时间>2才工作,小于等于2就相当于关闭。默认为0,相当于关闭,
3、修正模式1,2,3,4,5的切换机制,解决了之前参数切换后混乱的问题。目前还有小误差,基本满足设定逻辑。
   此逻辑在室内用GPS放大器测试通过,还未在室外复杂环境测试过。

app/src/main/java/com/enqualcomm/support/Config.java
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/LocationClient.java
app/src/main/java/com/enqualcomm/support/NMEAListener.java
app/src/main/java/com/enqualcomm/support/service/KeepAlive.java
app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java
app/version_code.properties

index c0c75d8..fbc4fa6 100644 (file)
@@ -361,7 +361,7 @@ public class Config {
   }\r
 \r
   public static int getPPGTestCycle(Context context){\r
-    return SharPreferenceUtil.getPrefInt(context,KeyPpgTestCycle,30);\r
+    return SharPreferenceUtil.getPrefInt(context,KeyPpgTestCycle,0);\r
   }\r
 \r
 \r
index 4da9a78..095c1c1 100644 (file)
@@ -202,7 +202,7 @@ public class CoreService extends Service {
                     //设置5分钟后结束紧急定位模式\r
                    setEmegencyLocationSTOPAlarm(5);\r
 \r
-                //5秒后开始拨打电话\r
+                //50ms后开始拨打电话\r
                 Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
                     public void call(Long param1Long) {\r
                         trigger_SOS_Call();\r
@@ -692,6 +692,7 @@ public class CoreService extends Service {
                             }else if(ACTION_SEND_EMEGENCY_LOCATION_STOP.equals(paramIntent.getAction())){\r
                                 //stop Emegency location Stop\r
                                 Config.loadModCycleSettings(runtime); //回复之前的 工作模式即可\r
+                                setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位\r
                             }\r
                             this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime);\r
                         }\r
@@ -730,6 +731,7 @@ public class CoreService extends Service {
     }\r
 \r
     public void setHeartRateDetectAlarm(int heartRateDetectAlarmCycle){\r
+        if (heartRateDetectAlarmCycle>2)\r
         AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,heartRateDetectAlarmCycle,ACTION_HEATR_RATE_START);\r
     }\r
 \r
@@ -744,7 +746,7 @@ public class CoreService extends Service {
     public void setLocationAlarm(int mod) {\r
 //        int mod=runtime.getLocationInstance().getWorkingMod();\r
         StringBuilder sb=new StringBuilder();\r
-        int cycle=1;\r
+        int cycle=60;\r
         switch(mod){\r
             case EMERGNECY_MOD:\r
             case REALTIME_MOD:\r
@@ -861,6 +863,7 @@ public class CoreService extends Service {
         }\r
     }\r
 \r
+\r
     public void ReConnectToServer(){\r
 \r
         if (SimSignalUtil.checkNet(runtime.getContextProxy().context) ) {\r
index 3406084..e63d891 100644 (file)
@@ -14,6 +14,7 @@ import android.telephony.SmsManager;
 import android.telephony.SmsMessage;\r
 import android.widget.Toast;\r
 \r
+import com.enqualcomm.support.bean.ICLocation;\r
 import com.enqualcomm.support.bean.Runtime;\r
 import com.enqualcomm.support.utils.APNUtil;\r
 import com.enqualcomm.support.utils.DeviceInfoUtil;\r
@@ -243,9 +244,25 @@ public class ICSmsManager {
                                 e.printStackTrace();\r
                             }\r
                             if(mod<6&& mod>0 && cycle>=30 ){\r
+                                switch(mod){\r
+                                    case ICLocation.NORMAL_MOD:\r
+                                        cycle=60*15;\r
+                                        break;\r
+                                    case ICLocation.LOWPOWER_MOD:\r
+                                        cycle=60*60;\r
+                                        break;\r
+                                    case ICLocation.REALTIME_MOD:\r
+                                    case ICLocation.EMERGNECY_MOD:\r
+                                        cycle=60;\r
+                                        break;\r
+                                }\r
+                                LocationClient.setForceLocation(1); //短信设置的至少强制执行第一次定位。否则NORMAL_MOD和LOWPOWER_MOD如果没有运动就无法正常定位\r
                                 runtime.getLocationInstance().setLocation_cycle(cycle);\r
                                 runtime.getLocationInstance().setWorkingMod(mod);\r
                                 CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
+                                if (mod == 4){\r
+                                    CoreService.getInstance().setEmegencyLocationSTOPAlarm(5);\r
+                                }\r
                                 sendSMS(phonenumber, "set to Location Mode="+runtime.getLocationInstance().getWorkingMod()+", Cycle="+runtime.getLocationInstance().getLocation_cycle());\r
                             }else{\r
                                 sendSMS(phonenumber, "set to Location Failed ,value range should be 1<= Mode <=5 and cycle >=30!");\r
index bc05c38..1c1a410 100644 (file)
@@ -217,13 +217,20 @@ public class LocationClient {
 //  public void EqcAlgorithmInterfaceMethod2() {\r
     public void startGpsLocate() {\r
       Logger.i("开启GPS扫描");\r
-    Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true);\r
+      runtime.getLocationInstance().setLocationStat( ICLocation.LOCATION_STAT.LOCATION_OPEN); //此处为了检测是否定位时可以正确识别状态,以防一直处于GPS定位成功状态\r
+      Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true);\r
     Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
           public void call(Object param1Object) { LocationClient.this.nmeaListener.startListen(); }\r
         });\r
 \r
   }\r
 \r
+  public void clearGPSlocateStat(){\r
+    Logger.i("clearGPSlocateStat");\r
+      stopGpsLocate();\r
+      runtime.getLocationInstance().setLocationStat( ICLocation.LOCATION_STAT.LOCATION_CLOSED);//此处为了检测是否定位时可以正确识别状态,以防一直处于GPS定位成功状态\r
+  }\r
+\r
   public void startCheckResult(){\r
       checktimes=0;\r
       timeout=false;\r
@@ -291,7 +298,7 @@ public class LocationClient {
             //GPS 优先的话多给些时间(10秒)\r
             if (checktimes> 50) timeout=true;\r
 \r
-            if ((lbs_ok && timeout==true) ||(lbs_ok && ( gps_ok || startSOSLocation==true ) && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){\r
+            if ((lbs_ok && timeout==true) ||( gps_ok )||(lbs_ok && ( gps_ok ) )||(lbs_ok && ( gps_ok || startSOSLocation==true ) && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){\r
 \r
 \r
               if (startSOSLocation==true){\r
@@ -374,10 +381,10 @@ public class LocationClient {
 \r
 //  public void EqcAlgorithmInterfaceMethod3() {\r
   public void stopGpsLocate() {\r
-    if (Deliver.is_active_location) {\r
-      Deliver.is_active_location = false;\r
-      getLocationWakeLock();\r
-    }\r
+//    if (Deliver.is_active_location) {\r
+//      Deliver.is_active_location = false;\r
+//      getLocationWakeLock();\r
+//    }\r
     Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, false);\r
     Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
           public void call(Object param1Object) { LocationClient.this.nmeaListener.stopListen(); }\r
@@ -428,7 +435,7 @@ public void updateCellInfo() {
     }\r
 \r
     // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过\r
-    if ( !(( forceLocation == 1 ) ||  ( mod == ICLocation.REALTIME_MOD ) || (mod == ICLocation.CUSTOM_MOD)) && ( runtime.getLastStepCount() == runtime.getTotalStepCount())  ){\r
+    if ( ( forceLocation != 1 ) &&  ( mod != ICLocation.REALTIME_MOD )&&  ( mod != ICLocation.EMERGNECY_MOD ) && (mod != ICLocation.CUSTOM_MOD) && ( runtime.getLastStepCount() == runtime.getTotalStepCount())  ){\r
       Logger.i("No Move ,skip location!");\r
       return ;\r
     }\r
@@ -448,15 +455,26 @@ public void updateCellInfo() {
         }else{\r
           nmeaListener.setNoStop(false);\r
         }\r
+        startGpsLocate();\r
+        break;\r
       case ICLocation.EMERGNECY_MOD:\r
       case ICLocation.REALTIME_MOD:\r
+        nmeaListener.setNoStop(false);//保证从Custom切换回来的时候不至于不关闭gps\r
         startGpsLocate();\r
         break;\r
+      case ICLocation.LOWPOWER_MOD:\r
+      case ICLocation.NORMAL_MOD:\r
+      default:\r
+        clearGPSlocateStat(); //如果wifi优先,则确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。\r
+        break;\r
     }\r
 \r
       startCheckResult();\r
   }\r
 \r
+  public static void setForceLocation(int _forcelocation){\r
+    forceLocation=_forcelocation;\r
+  }\r
   private static int forceLocation=0;\r
   public void onReceive(StringMessage paramStringMessage) {\r
 \r
@@ -466,13 +484,15 @@ public void updateCellInfo() {
     if ("StartLocate".equals(paramStringMessage.cmd())  ){\r
       forceLocation=1;\r
       this.startLocationProcess(runtime.getLocationInstance().getWorkingMod());\r
-    }\r
-    if ("setWorkMod".equals(paramStringMessage.cmd())) {\r
+    }else  if ("setWorkMod".equals(paramStringMessage.cmd())) {\r
+      //此处不负责给工作模式赋值,在API接收的位置能够直接拿到变量,可以直接赋值较方便。\r
       int mod = runtime.getLocationInstance().getWorkingMod();\r
       Logger.i("Set WorkMODE  "+mod +" and reset Location AlarmCycle");\r
-      CoreService.getInstance().setLocationAlarm(mod);\r
-      forceLocation=1;\r
-      this.startLocationProcess(mod);\r
+      CoreService.getInstance().setLocationAlarm(mod); //默认设置好Alarm后会触发一次定位,无需后面再触发定位了。\r
+      forceLocation=1; //不管是什么模式,都强制定位一次,然后再说其他情况\r
+      if(mod==ICLocation.EMERGNECY_MOD)\r
+        CoreService.getInstance().setEmegencyLocationSTOPAlarm(5);//Emergency模式5分钟自动停止\r
+//      this.startLocationProcess(mod);\r
 \r
     }\r
   }\r
index 1379b86..4f19b6c 100644 (file)
@@ -166,12 +166,11 @@ public class NMEAListener implements NmeaListener, LocationListener {
          */\r
         runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED);\r
 \r
-      }else if (message.what== MSG_WHAT_GPS_FIXED_NO_STOP){\r
-        runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED);\r
-        return true;\r
       }\r
 \r
-      NMEAListener.this.stopListen();\r
+      if (!noStop){\r
+        NMEAListener.this.stopListen();\r
+      }\r
       return true;\r
     }\r
   });\r
@@ -236,22 +235,23 @@ public class NMEAListener implements NmeaListener, LocationListener {
       }\r
     }\r
 \r
-    if (searchCout>SearchTimeout){\r
-      sb2.append(" 搜索"+searchCout+"次未定位,超过"+SearchTimeout+"限制退出GPS定位");\r
-      gpsMode=GPS_CURRENT_STATUS.GPS_TIMEOUT;\r
-      runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT);\r
+    if(!noStop) {\r
+      if (searchCout > SearchTimeout) {\r
+        sb2.append(" 搜索" + searchCout + "次未定位,超过" + SearchTimeout + "限制退出GPS定位");\r
+        gpsMode = GPS_CURRENT_STATUS.GPS_TIMEOUT;\r
+        runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT);\r
 \r
-      stop(MSG_WHAT_GPS_TIMEOUT);\r
-    }\r
-    if (noSignalCount> 10){\r
-      sb2.append(" 搜索"+searchCout+"次,超过"+noSignalCount+"次没有收到星,退出GPS定位");\r
-      gpsMode=GPS_CURRENT_STATUS.GPS_NOSINGAL;\r
-      runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT);\r
+        stop(MSG_WHAT_GPS_TIMEOUT);\r
+      }\r
+      if (noSignalCount > 10) {\r
+        sb2.append(" 搜索" + searchCout + "次,超过" + noSignalCount + "次没有收到星,退出GPS定位");\r
+        gpsMode = GPS_CURRENT_STATUS.GPS_NOSINGAL;\r
+        runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT);\r
 \r
-      stop(MSG_WHAT_GPS_NOSTAR);\r
+        stop(MSG_WHAT_GPS_NOSTAR);\r
+      }\r
     }\r
     if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb2.toString());\r
-\r
     Logger.i( sb2.toString());\r
     getBestLocation(locationManager,status);\r
 \r
@@ -274,16 +274,13 @@ public class NMEAListener implements NmeaListener, LocationListener {
   }\r
   private void delaystop(){\r
 \r
-    if (noStop){\r
-      NMEAListener.this.temHandler.sendEmptyMessageDelayed(MSG_WHAT_GPS_FIXED_NO_STOP, 3000L);\r
-    }else {\r
     /*\r
         只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。\r
         延迟三秒后才设置runtime的定位标志,以便稳定坐标值。\r
          */\r
       //发送停止消息\r
       NMEAListener.this.temHandler.sendEmptyMessageDelayed(MSG_WHAT_GPS_FIXED, 3000L);\r
-    }\r
+\r
   }\r
   boolean isFrist = true;\r
 \r
@@ -358,6 +355,9 @@ public class NMEAListener implements NmeaListener, LocationListener {
 \r
             if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb.toString());\r
             runtime.getLocationInstance().setLocation(latitude,longitude,speed,0,status.getMaxSatellites());\r
+            if (noStop){//如果是不停止gps,那么每次确认定位的数据都设置标志位,以便其他线程能及时更新数据\r
+              runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED);\r
+            }\r
           }\r
 \r
         }\r
index 205707b..844d3a4 100644 (file)
@@ -87,22 +87,19 @@ public class KeepAlive extends AbstractConnectionService {
 \r
     long l = SystemClock.elapsedRealtime();\r
 \r
-    //如果 没有连接成功 或者 时间超过了11分钟 ,则进行重新连接服务\r
-    if (!isConnected || l - this.idleTimeMillis > 660000L) {\r
-      StringBuilder stringBuilder = new StringBuilder();\r
-      stringBuilder.append("重连");\r
-      stringBuilder.append(isConnected);\r
-      Logger.i(stringBuilder.toString());\r
-      if (!isConnected && this.firstReConnected) {\r
-        this.reConnectionNumber++;\r
-        this.firstReConnected = false;\r
-      } \r
-//      if (paramRuntime.getLockSimInfo()) {\r
-//        paramConnection.disconnect();\r
-//        return;\r
+//    //如果 没有连接成功 或者 时间超过了11分钟 ,则进行重新连接服务\r
+//    if (!isConnected || l - this.idleTimeMillis > 660000L) {\r
+//      StringBuilder stringBuilder = new StringBuilder();\r
+//      stringBuilder.append("重连");\r
+//      stringBuilder.append(isConnected);\r
+//      Logger.i(stringBuilder.toString());\r
+//      if (!isConnected && this.firstReConnected) {\r
+//        this.reConnectionNumber++;\r
+//        this.firstReConnected = false;\r
 //      }\r
-      CoreService.getInstance().ReConnectToServer();\r
-    } \r
+//\r
+//      CoreService.getInstance().ReConnectToServer();\r
+//    }\r
   }\r
   \r
   public void onAttach(final Connection connection, final Runtime runtime) {\r
@@ -205,6 +202,8 @@ public class KeepAlive extends AbstractConnectionService {
       paramRuntime.getContextProxy().sendBroadcast(isConnected);\r
       LauncherCtrl.getInstance(this.mContext).setStatusBarIcon("server_connected", STATUS_BAR_STATE_SERVER_CONNECTED_ON);\r
 //      Deliver.triggerSendThread(); //链接上就尝试清除 buffer中的数据\r
+      CoreService.getInstance().stopConnectionRetryTimer();\r
+\r
     }\r
     return false;\r
   }\r
index e1162ed..af5d14c 100644 (file)
@@ -84,9 +84,8 @@ public class NettyConnection implements Connection {
                                 break;\r
                             case BP33:\r
                                 //设置工作模式\r
-                                DeliverCMDMessageToSystem("setWorkMod",cmd);//通知下面线程状态变化\r
-                                DeliverCMDMessageToSystem("AP33",cmd);//通知下面线程状态变化\r
                                 API.handleBP33(NettyConnection.this,runtime,cmd);\r
+                                DeliverCMDMessageToSystem("setWorkMod",cmd);//通知下面线程状态变化\r
 \r
                                 break;\r
                             case BP16:\r
index 0bb413a..6e9cb49 100644 (file)
@@ -1,2 +1,2 @@
-#Wed Feb 12 23:18:01 CST 2020\r
-VERSION_CODE=351\r
+#Sun Feb 16 18:44:00 CST 2020\r
+VERSION_CODE=354\r