From: snickersun Date: Sun, 15 Nov 2020 00:37:37 +0000 (+0800) Subject: 优化SOS和定位扫描逻辑。 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=e7112d1ef0a35f5f249f40947dc61babea3c4c75;p=protocol_srv.git 优化SOS和定位扫描逻辑。 1、BLE扫描 protocol 0 时,第一次进入,或者第一次走出 绑定ble圈都上报一次报警 2、BLE ScanOnly,SOSLocation,NormalLocation 尝试分开处理。 --- diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index 5eda9bc1..3d723410 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -115,6 +115,8 @@ public class LocationClient { private NMEAListener nmeaListener; private boolean startSOSLocation=false; + private boolean startNomalLocation=false; + private int preLbsCid; int preNetworkTypeNomber; @@ -139,19 +141,19 @@ public class LocationClient { public LocationClient(Connection paramNettyConnection, Runtime paramRuntime) { connection = paramNettyConnection; runtime = paramRuntime; - btHelper=BTHelper.CreateInstance(paramRuntime, new BTHelper.BTScanCallback() { + btHelper = BTHelper.CreateInstance(paramRuntime, new BTHelper.BTScanCallback() { @Override public void OnScanFinished(ArrayList btPairedScanResult, ArrayList btNewScanResult) { - if(Config.BLEScanProtocol==0) { //扫描并判定是否在区域内。 - if (btNewScanResult!=null && btNewScanResult.size() > 0) { - StringBuilder sb=new StringBuilder(); - sb.append("found bt mac ").append(btNewScanResult.size() ); - sb.append(" bounding BeaconMacList ").append(runtime.bleInfo.btMacList.size() ); - runtime.bleInfo.btScanResult.clear(); - for(String mac:runtime.bleInfo.btMacList){ - sb.append(" ").append(mac); - } - ICLogger.i( sb.toString() ); + if (Config.BLEScanProtocol == 0) { //扫描并判定是否在区域内。 + if (btNewScanResult != null && btNewScanResult.size() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append("found bt mac ").append(btNewScanResult.size()); + sb.append(" bounding BeaconMacList ").append(runtime.bleInfo.btMacList.size()); + runtime.bleInfo.btScanResult.clear(); + for (String mac : runtime.bleInfo.btMacList) { + sb.append(" ").append(mac); + } + ICLogger.i(sb.toString()); boolean in_area = false; @@ -183,87 +185,102 @@ public class LocationClient { } - } else { - runtime.bleInfo.is_in_area = false; - ScanBLERetryCount=maxBLEScanTime; - } - ICLogger.i("Bt Dev Is in Area " + runtime.bleInfo.is_in_area); - - if(scanBLEOnly==true){ - //只扫描蓝牙,不做定位 - if (runtime.bleInfo.is_in_area == false ) { - runtime.updateFZDDevStatusEscape(true); - ICLogger.i("BT 不在区域内"); - if ( runtime.bleInfo.last_is_in_area==true) { - //只有上一次在区域内,这次出区域才需要报警 - ICLogger.i("BT 不在区域内,且上次在区域内,报警!"); - //如果需要报警定位,则强制进行sos定位,不能通过triggerSOS,因为函数中调用了BLEScan会造成循环调用 + } else { + runtime.bleInfo.is_in_area = false; + ScanBLERetryCount = maxBLEScanTime; + } + ICLogger.i("Bt Dev Is in Area " + runtime.bleInfo.is_in_area); + + if (scanBLEOnly == true) { + //只扫描蓝牙,不做定位 + if (runtime.bleInfo.is_in_area == false) { + runtime.updateFZDDevStatusEscape(true); + ICLogger.i("BT 不在区域内"); + if (runtime.bleInfo.last_is_in_area == true) { + //只有上一次在区域内,这次出区域才需要报警 + ICLogger.i("BT 不在区域内,且上次在区域内,报警!"); + //如果需要报警定位,则强制进行sos定位,不能通过triggerSOS,因为函数中调用了BLEScan会造成循环调用 + StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); + DeliverMessage(AL_CMD); + } + } else { + ICLogger.i("BT 在区域内!"); + runtime.updateFZDDevStatusEscape(false); + if (runtime.bleInfo.last_is_in_area == false) { + //上一次不在区域内,这次进区域要报警 + ICLogger.i("BT 进入区域内,且上次不在区域内,报警!"); + //如果需要报警定位,则强制进行sos定位,不能通过triggerSOS,因为函数中调用了BLEScan会造成循环调用 StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); DeliverMessage(AL_CMD); + } } - }else{ - ICLogger.i("BT 在区域内!"); - runtime.updateFZDDevStatusEscape(false); - } - }else { - //定位前的蓝牙扫描 - if (runtime.bleInfo.is_in_area == false) { - ICLogger.i("BT 不在区域内,开启定位流程"); - runtime.updateFZDDevStatusEscape(true); - if ( runtime.bleInfo.last_is_in_area==true) { - //只有上一次在区域内,这次出区域才需要报警 - ICLogger.i("BT 不在区域内,且上次在区域内,报警!"); + } else { + //定位前的蓝牙扫描 + if (runtime.bleInfo.is_in_area == false) { + ICLogger.i("BT 不在区域内,开启定位流程"); + runtime.updateFZDDevStatusEscape(true); + if (runtime.bleInfo.last_is_in_area == true) { + //只有上一次在区域内,这次出区域才需要报警 + ICLogger.i("BT 不在区域内,且上次在区域内,报警!"); StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); DeliverMessage(AL_CMD); - startSOSLocation=false; - - }else { - - if (startSOSLocation) { + startSOSLocation = false; //如果已经报警,后面就不用再报了 + } - StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); - DeliverMessage(AL_CMD); - startSOSLocation=false; + if (startSOSLocation) { + StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); + DeliverMessage(AL_CMD); + startSOSLocation = false; + } + if (startNomalLocation) { + startLocationProcess(runtime.getLocationInstance().getWorkingMod()); + } - } else { - startLocationProcess(runtime.getLocationInstance().getWorkingMod()); - } + } else { + ICLogger.i("BT 在区域内,直接发送区域坐标即可!"); + runtime.updateFZDDevStatusEscape(false); + if (runtime.bleInfo.last_is_in_area == false) { + //上一次不在区域内,这次进区域要报警 + ICLogger.i("BT 进入区域内,且上次不在区域内,报警!"); + //如果需要报警定位,则强制进行sos定位,不能通过triggerSOS,因为函数中调用了BLEScan会造成循环调用 + StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); + DeliverMessage(AL_CMD); + startSOSLocation = false;//如果已经报警,后面就不用再报了 + } - } - } else { - ICLogger.i("BT 在区域内,直接发送区域坐标即可!"); - runtime.updateFZDDevStatusEscape(false); - if(startSOSLocation) { - StringMessage AP01_CMD = protocolAPIHelper.getWarningMSG(runtime); - DeliverMessage(AP01_CMD); - startSOSLocation=false; - }else { + if (startSOSLocation) { + StringMessage AP01_CMD = protocolAPIHelper.getWarningMSG(runtime); + DeliverMessage(AP01_CMD); + startSOSLocation = false; + } + if (startNomalLocation) { //已经通过蓝牙定位,则清除 forceLocation=0 - forceLocation=0; + forceLocation = 0; + startNomalLocation = false; //蓝牙定位,直接发GPS坐标 StringMessage AP01_CMD = protocolAPIHelper.getGPSLocationMSG(runtime); DeliverMessage(AP01_CMD); + } } } - } - //处理过此次数据后,把当前状态赋值给上次检测状态 - runtime.bleInfo.last_is_in_area=runtime.bleInfo.is_in_area; - //扫描结束就清掉scanBLEOnly,保证下次不会被误操作。 - scanBLEOnly=false; - }else{ + //处理过此次数据后,把当前状态赋值给上次检测状态 + runtime.bleInfo.last_is_in_area = runtime.bleInfo.is_in_area; + //扫描结束就清掉scanBLEOnly,保证下次不会被误操作。 + scanBLEOnly = false; + } else { //Config.BLEScanProtocol == 1 - if (btNewScanResult!=null && btNewScanResult.size() > 0) { + if (btNewScanResult != null && btNewScanResult.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append("found bt mac ").append(btNewScanResult.size()); runtime.bleInfo.btScanResult.clear(); for (String mac : btNewScanResult) { sb.append("\n").append(mac); - runtime.bleInfo.btScanResult.add(mac.replace(":","")); + runtime.bleInfo.btScanResult.add(mac.replace(":", "")); } ICLogger.i(sb.toString()); Deliver.sendLocationMSG(protocolAPIHelper.getBLEScanResult(runtime)); - }else{ + } else { ICLogger.i("未搜到蓝牙设备!"); } } @@ -271,7 +288,7 @@ public class LocationClient { }); btHelper.setBLEScanTimeout(OneBLEScanTimeOUT); - gLocationCline=this; + gLocationCline = this; //GPS 监听管理初始化 this.nmeaListener = new NMEAListener(paramRuntime.getContextProxy().getLocationManager(), paramRuntime); // 初始化同时开启计步(硬件计步器,比较省电,全程开启计步功能) @@ -446,6 +463,7 @@ public class LocationClient { public void call(Object param1Object) { waitAndSendLocation(); } }); }else if (msg.what == msgWhat_StartLocationProcess) { + startNomalLocation=true; if (Config.BLEScanProtocol == 0 && runtime.bleInfo.btMacList.size() > 0) { if(scanBLEOnly && btHelper.isBtscanning()){ //如果正在进行独立蓝牙扫描,则强制切换为正常扫描。 @@ -487,7 +505,6 @@ public class LocationClient { } }else if (msg.what == msgWhat_StartSOSLocationProcess){ - if (runtime !=null) { //更新lbs信息 CellInfoUtil.getCellInfo(runtime.getContextProxy().getTelephonyManager(),runtime); @@ -591,8 +608,10 @@ public class LocationClient { StringMessage AP10_CMD = protocolAPIHelper.getWarningMSG(runtime); DeliverMessage(AP10_CMD); startSOSLocation=false; - }else { + } + if(startNomalLocation=true){ + startNomalLocation=false; if (gps_ok) { StringMessage AP01_CMD = protocolAPIHelper.getGPSLocationMSG(runtime); DeliverMessage(AP01_CMD); @@ -665,8 +684,9 @@ public class LocationClient { StringMessage AP10_CMD = protocolAPIHelper.getWarningMSG(runtime); DeliverMessage(AP10_CMD); startSOSLocation=false; - - }else { + } + if(startNomalLocation=true){ + startNomalLocation=false; StringMessage AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime); DeliverMessage(AP02_CMD); }