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