From: snickersun Date: Tue, 20 Oct 2020 10:08:30 +0000 (+0800) Subject: release V665 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=fbde9b7690dd5d4184bb0d537ab5e8601d84c69a;p=protocol_srv.git release V665 优化蓝牙扫描,解决扫描有时扫不到beacon的问题。 --- diff --git a/app/release/ICSer_V664_2010192321_release.apk b/app/release/ICSer_V665_2010201758_release.apk similarity index 78% rename from app/release/ICSer_V664_2010192321_release.apk rename to app/release/ICSer_V665_2010201758_release.apk index ad509c60..f00316ce 100644 Binary files a/app/release/ICSer_V664_2010192321_release.apk and b/app/release/ICSer_V665_2010201758_release.apk differ diff --git a/app/release/output.json b/app/release/output.json index 0c0f357d..c57fa4c4 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":664,"versionName":"2010192321","enabled":true,"outputFile":"ICSer_V664_2010192321_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V664_2010192321_release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":665,"versionName":"2010201758","enabled":true,"outputFile":"ICSer_V665_2010201758_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V665_2010201758_release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 35fdd1c2..091b001d 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -27,7 +27,7 @@ public class Config { private static String json; public static int defaultHeartbeatCycle=5; public static int sw_release_no = -1; - public static int bleScanTimeout=10; + public static boolean forceMoveCheck=true; public static boolean forceWearCheck=true; diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 505db868..52d32b68 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -708,7 +708,7 @@ public class CoreService extends Service { if (Config.getConfigInitFlag(this)==0) { Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); - Config.forceMoveCheck=false; + Config.forceMoveCheck=false; //即爱对gps不进行运动检测,此变量专门为了给其他协议进行强制运动检测用的。 Config.setConfigInitFlag(this, 1); } }else{ diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index 31cdb689..14d0320f 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -119,10 +119,9 @@ public class LocationClient { private boolean scanBLEOnly=false; //如果未扫到,重试扫描的次数。 - private int maxBLEScanTime=2; + private int maxBLEScanTime=1; private int ScanBLERetryCount=maxBLEScanTime; - - + private int OneBLEScanTimeOUT=15; private static LocationClient gLocationCline=null; // private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() { @@ -138,7 +137,7 @@ public class LocationClient { public LocationClient(Connection paramNettyConnection, Runtime paramRuntime) { connection = paramNettyConnection; runtime = paramRuntime; - btHelper=BTHelper.getInstance(paramRuntime.getContextProxy().context, new BTHelper.BTScanCallback() { + btHelper=BTHelper.CreateInstance(paramRuntime, new BTHelper.BTScanCallback() { @Override public void OnScanFinished(ArrayList btPairedScanResult, ArrayList btNewScanResult) { @@ -250,6 +249,8 @@ public class LocationClient { } }); + + btHelper.setBLEScanTimeout(OneBLEScanTimeOUT); gLocationCline=this; //GPS 监听管理初始化 this.nmeaListener = new NMEAListener(paramRuntime.getContextProxy().getLocationManager(), paramRuntime); @@ -833,6 +834,7 @@ public void updateCellInfo() { (Config.forceMoveCheck==true) && (NoMoveTimeout) && (skipMoveCheck ==false )){ ICLogger.i("No Move ,skip BT location!"); + return false; } ICLogger.i("BT NoMoveTimeout "+NoMoveTimeout+", forceLocation="+forceLocation+", Config.forceMoveCheck="+Config.forceMoveCheck+", skipMoveCheck="+skipMoveCheck); diff --git a/app/src/main/java/com/enqualcomm/support/MainActivity.java b/app/src/main/java/com/enqualcomm/support/MainActivity.java index a20bb6ee..658df9e0 100644 --- a/app/src/main/java/com/enqualcomm/support/MainActivity.java +++ b/app/src/main/java/com/enqualcomm/support/MainActivity.java @@ -124,7 +124,7 @@ public class MainActivity extends Activity { private void testBLE(){ - btHelper= BTHelper.getInstance(MainActivity.this, new BTHelper.BTScanCallback() { + btHelper= BTHelper.CreateInstance(CoreService.getInstance().runtime, new BTHelper.BTScanCallback() { @Override public void OnScanFinished(ArrayList btPairedScanResult, ArrayList btNewScanResult) { diff --git a/app/src/main/java/com/enqualcomm/support/adapter/BTHelper.java b/app/src/main/java/com/enqualcomm/support/adapter/BTHelper.java index eb8146cc..87efb599 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/BTHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/BTHelper.java @@ -8,7 +8,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Handler; - +import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.Config; import com.enqualcomm.support.utils.ICLogger; @@ -23,13 +23,34 @@ public class BTHelper { private Context mContext=null; private BTScanCallback mCallback=null; private static BTHelper mBThelper=null; - private int BLETimeoutForOneScan=6; + private int BLETimeoutForOneScan=10; private static boolean btscanning=false; + private static Runtime mRuntime; private boolean enabledBeforScan=false; + private Handler mHandler=null; BTHelper(){ } + public void setBLEScanTimeout(int timeout){ + BLETimeoutForOneScan=timeout; + } + private boolean isBeaconFounded(String beaconAddr){ + + String tmp = beaconAddr.replace(":", "").toLowerCase(); + if(tmp.contains(",")) + tmp = tmp.substring(0, tmp.indexOf(",")); + + for (String beacon:mRuntime.bleInfo.btMacList){ +// ICLogger.i(beacon +" ==? "+tmp); + if (tmp.equals(beacon)) { + ICLogger.i("bt mac " + tmp + " " + beaconAddr.toLowerCase()); + return true; + } + } +// ICLogger.i(" false "); + return false; + } //enableBT public void enableBT() { ICLogger.i("BT enableBT()"); @@ -54,12 +75,12 @@ public class BTHelper { //disableBT public void disableBT(){ ICLogger.i( "BT disableBT()"); - btscanning=false; - if (mBtAdapter.isEnabled()) { + if (mBtAdapter.isEnabled()) { mBtAdapter.disable(); // Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); // mContext.startActivity(enableIntent); } + btscanning=false; } //初始化 BTHlper @@ -78,19 +99,24 @@ public class BTHelper { // Get the local Bluetooth adapter mBtAdapter = BluetoothAdapter.getDefaultAdapter(); + mHandler = new Handler(); + lecallback = new BLeScanCallback(); } + //获取实例 - public static BTHelper getInstance(Context context , BTScanCallback callback){ + public static BTHelper CreateInstance(Runtime runtime , BTScanCallback callback){ + mRuntime=runtime; if (mBThelper==null) { ICLogger.i( "BT getInstance "); mBThelper = new BTHelper(); - mBThelper.Init(context,callback); + mBThelper.Init(runtime.getContextProxy().context,callback); } return mBThelper; } + // // The BroadcastReceiver that listens for discovered devices and // // changes the title when discovery is finished // private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -159,6 +185,12 @@ public class BTHelper { // // } + + private BLeScanCallback lecallback =null; + + private RunableStopBleScan mRunable_stopBleScan=new RunableStopBleScan(); + + private static boolean hasStopedByFoundBT=false; public boolean isBtscanning(){ return btscanning; } @@ -184,44 +216,12 @@ public class BTHelper { // mBtAdapter.startDiscovery(); - - mBtAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_NONE, Config.bleScanTimeout); - LeScanCallback lecallback = new LeScanCallback() { - - @Override - public void onLeScan(BluetoothDevice bluetoothDevice, int rssi, byte[] scanRecode) { -// ICLogger.i( "BT onLeScan "+bluetoothDevice.getName()+" "+bluetoothDevice.getAddress()+" rssi "+rssi); -// ICLogger.logToFile("LBS","BT onLeScan "+bluetoothDevice.getName()+" "+bluetoothDevice.getAddress()+" rssi "+rssi ); - boolean found = false; - for (String dev : mNewDevicesArray) { - if (dev.contains(bluetoothDevice.getAddress())) { - found = true; - break; - } - } - if (!found) - mNewDevicesArray.add(bluetoothDevice.getAddress() + "," + rssi); - } - }; +// mBtAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_NONE, BLETimeoutForOneScan); ICLogger.i("BT startLeScan"); mBtAdapter.startLeScan(lecallback); + mHandler.postDelayed(mRunable_stopBleScan, BLETimeoutForOneScan*1000); - - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - ICLogger.i("BT stopLeScan"); - mBtAdapter.stopLeScan(lecallback); - - //开始扫描前是关闭的,就关闭它 -// if(!enabledBeforScan) - disableBT(); - - if (mCallback != null) - mCallback.OnScanFinished(mPairedDevicesArray, mNewDevicesArray); - } - }, BLETimeoutForOneScan*1000); }else{ ICLogger.i("BT Scanning skip Scan!"); } @@ -271,8 +271,64 @@ public class BTHelper { } } + private class BLeScanCallback implements LeScanCallback{ + + @Override + public void onLeScan(BluetoothDevice bluetoothDevice, int rssi, byte[] scanRecode) { +// ICLogger.i( "BT onLeScan "+bluetoothDevice.getName()+" "+bluetoothDevice.getAddress()+" rssi "+rssi); +// ICLogger.logToFile("LBS","BT onLeScan "+bluetoothDevice.getName()+" "+bluetoothDevice.getAddress()+" rssi "+rssi ); + boolean found = false; + for (String dev : mNewDevicesArray) { + if (dev.contains(bluetoothDevice.getAddress())) { + found = true; + break; + } + } + + if (!found) { + mNewDevicesArray.add(bluetoothDevice.getAddress() + "," + rssi); + } + + if(isBeaconFounded(bluetoothDevice.getAddress())){ + + hasStopedByFoundBT=true; + mHandler.removeCallbacks(mRunable_stopBleScan); + + ICLogger.i("BT stopLeScan"); + mBtAdapter.stopLeScan(this); + + //开始扫描前是关闭的,就关闭它 + // if(!enabledBeforScan) + disableBT(); + + if (mCallback != null) + mCallback.OnScanFinished(mPairedDevicesArray, mNewDevicesArray); + } + } + } + + private class RunableStopBleScan implements Runnable{ + + @Override + public void run() { + ICLogger.i("BT stopLeScan"); + + if(hasStopedByFoundBT) { + hasStopedByFoundBT=false; + ICLogger.i(" BT has Stoped !"); + + }else{ + mBtAdapter.stopLeScan(lecallback); + //开始扫描前是关闭的,就关闭它 + // if(!enabledBeforScan) + disableBT(); + if (mCallback != null) + mCallback.OnScanFinished(mPairedDevicesArray, mNewDevicesArray); + } + } + } + public interface BTScanCallback{ void OnScanFinished(ArrayList btPairedScanResult,ArrayList btNewScanResult); - } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java index 2f253a41..d13dbc31 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java @@ -242,6 +242,7 @@ public class DeviceInfoUtil { .append("\n Srv [P").append(Config.protocol_no).append(" ").append(runtime.getHost()).append(":").append(runtime.getPort()).append("]").append(KeepAlive.isConnected).append(" , HBcycle ").append(runtime.getHeartBeatCycle()) .append("\n ServerConnected is ").append(runtime.isServerProtocolConnected()) // .append(",Temp ").append(String.format("%1$.2f",wrist_temp)).append(",Body ").append(String.format("%1$.2f",TemperatureUtil.getBodyTemp(wrist_temp,26.0f))) + .append(",BTIn ").append(runtime.bleInfo.is_in_area) .append(" \n Bat ").append(runtime.getBattery()).append(",").append(runtime.getBatteryVotage()) .append(" charged ").append(runtime.isPowerConnected()) .append(" StepCount ").append(runtime.getTotalStepCount()) @@ -279,6 +280,7 @@ public class DeviceInfoUtil { .append(",C").append(runtime.getLocationInstance().getLocation_cycle()) .append(",T").append(runtime.getLocationInstance().getLocationType()) .append(",").append(runtime.getLocationInstance().getLocationTime()) + .append(",BTIn").append(runtime.bleInfo.is_in_area) .append("]\nPPG[C").append(runtime.getPpgTestCycle()) // .append(",P").append(runtime.getHRS().getPPG()) // .append(",H").append(runtime.getHRS().getBPH()) diff --git a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java index 0ec4627b..3e1b2950 100644 --- a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java +++ b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java @@ -175,14 +175,7 @@ public class protocolAPIHelper { ret=protocol_beehome.APTP(temp_adusted,body_temp); break; case Config.PROTOCOL_IC: - if(Config.getProtocolServerHost(runtime.getContextProxy().context).equals(protocol_jiai.defaultServerIP)) - { - //为了兼容即爱的服务器而设定。 - ret=null; - }else { - ret=protocol_ic.APTP(temp_adusted,body_temp); - } - + ret=protocol_ic.APTP(temp_adusted,body_temp); break; case Config.PROTOCOL_FZD: ret=protocol_fzd.temp(body_temp); diff --git a/app/src/main/java/com/ic/protocols/protocol_mqtt.java b/app/src/main/java/com/ic/protocols/protocol_mqtt.java index 190abd58..c656afd4 100644 --- a/app/src/main/java/com/ic/protocols/protocol_mqtt.java +++ b/app/src/main/java/com/ic/protocols/protocol_mqtt.java @@ -6,6 +6,7 @@ import android.text.TextUtils; import com.enqualcomm.support.Config; import com.enqualcomm.support.CoreService; +import com.enqualcomm.support.adapter.BTHelper; import com.enqualcomm.support.bean.Contact; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; diff --git a/app/version_code.properties b/app/version_code.properties index efdcf2d1..a8878261 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Mon Oct 19 23:21:23 CST 2020 -VERSION_CODE=664 +#Tue Oct 20 17:58:06 CST 2020 +VERSION_CODE=665