From a94ea68c67df83acc450315694f12e4f65ed35e5 Mon Sep 17 00:00:00 2001 From: snickersun Date: Mon, 2 Nov 2020 23:18:13 +0800 Subject: [PATCH] =?utf8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E8=BD=AE=E8=AF=A2?= =?utf8?q?=E6=A3=80=E6=B5=8B=E8=84=B1=E8=85=95=E9=80=BB=E8=BE=91=EF=BC=88?= =?utf8?q?=E4=BD=86=E6=9C=AA=E5=AE=9E=E7=8E=B0=E4=B8=BB=E5=8A=A8=E8=84=B1?= =?utf8?q?=E8=85=95=E6=9F=A5=E8=AF=A2=E5=87=BD=E6=95=B0=EF=BC=89=202?= =?utf8?q?=E3=80=81=E5=AE=9E=E7=8E=B0=E8=93=9D=E7=89=99=E7=9A=84=E7=AC=AC?= =?utf8?q?=E4=BA=8C=E7=A7=8D=E6=89=AB=E6=8F=8F=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?utf8?q?=E5=91=A8=E6=9C=9F=E6=89=AB=E6=8F=8F=E5=B9=B6=E4=B8=8A=E4=BC=A0?= =?utf8?q?=E7=BB=93=E6=9E=9C=E3=80=82=E7=BB=93=E6=9E=9C=E6=9C=89=E6=8E=92?= =?utf8?q?=E5=BA=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/com/enqualcomm/support/Config.java | 25 ++++++ .../com/enqualcomm/support/Constants.java | 6 +- .../com/enqualcomm/support/CoreService.java | 72 ++++++++++++---- .../enqualcomm/support/LocationClient.java | 83 +++++++++++++------ .../enqualcomm/support/adapter/BTHelper.java | 29 ++++++- .../com/enqualcomm/support/bean/BLEInfo.java | 3 + .../support/service/AntiMonitorService.java | 32 +++++-- .../com/ic/protocols/protocolAPIHelper.java | 24 ++++++ .../java/com/ic/protocols/protocol_ic.java | 79 +++++++++++++++++- dNSCache/dNSCache.iml | 6 +- 10 files changed, 297 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 9f028ebb..7b7e7228 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -57,9 +57,16 @@ public class Config { public static boolean noPPGSensor=false; public static boolean needBroadcastAntiAlarm=true; public static boolean disableWiFiScan=false; + public static int BLEScanProtocol=0; /** 0 代表扫描beacon后 自行判断是否在指定区域,需要协议绑定beacon地址。 + * 1 代表扫描beacon后,直接把扫描结果上报即可。 + **/ + public static boolean UsePolingCheckWeared=false; + static { disableWiFiScan=Util.getSystemProperties("persist.sys.disableWiFiLocation","false").equals("true"); disableWristTemp=Util.getSystemProperties("persist.sys.disableWristTemp","false").equals("true"); + BLEScanProtocol=Util.getSystemPropertiesInt("persist.sys.BLEScanProtocol",0); + UsePolingCheckWeared=Util.getSystemProperties("persist.sys.PolingCheckAnti","false").equals("true"); } private static String make() { @@ -131,6 +138,24 @@ public class Config { final static String KeyBPLadust="KeyBPLAdjust"; final static String KeySPo2adust="KeySPo2Adjust"; + final static String KeyPolingCycleCheckAnti="PolingCycleCheckAnti"; + final static String KeyBleScanCycle="BleScanCycle"; + + public static void setCheckAntiPolingCycle(Context context, int cycle){ + SharPreferenceUtil.setPrefInt(context,KeyPolingCycleCheckAnti,cycle); + } + + public static int getCheckAntiPolingCycle(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyPolingCycleCheckAnti,0); + } + + public static void setBleScanCycle(Context context, int cycle){ + SharPreferenceUtil.setPrefInt(context,KeyBleScanCycle,cycle); + } + + public static int getBleScanCycle(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyBleScanCycle,0); + } public static String getSMSPwd(Context context){ return SharPreferenceUtil.getPrefString(context,KeySMSPassword,DefaultSMSPassword); diff --git a/app/src/main/java/com/enqualcomm/support/Constants.java b/app/src/main/java/com/enqualcomm/support/Constants.java index 0b7fedbc..a5343a1c 100644 --- a/app/src/main/java/com/enqualcomm/support/Constants.java +++ b/app/src/main/java/com/enqualcomm/support/Constants.java @@ -14,7 +14,11 @@ public interface Constants { public static final String ACTION_ADDTEST_CONTACTS = "com.enqualcomm.imessage.ACTION_ADDTEST_CONTACTS"; public static final String ACTION_ALARM_ADD_DATAPOINTS = "com.enqualcomm.support.ADD_DATAPOINTS"; - + + + public static final String ACTION_ALARM_BLE_SCAN = "com.ic.Action.ALarm.bleScan"; + public static final String ACTION_ALARM_CHECK_ANTI = "com.ic.Action.ALarm.CheckAnti"; + public static final String ACTION_ALARM_ALARM_CHANGE = "com.enqualcomm.support.ACTION_ALARM_ALARM_CHANGE"; public static final String ACTION_ANTIOFF_ALARM_CHANGE = "com.enqualcomm.support.ACTION_ANTIOFF_ALARM_CHANGE"; diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index cfd600fb..e78b3cf9 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -16,6 +16,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.widget.Toast; +import com.enqualcomm.support.adapter.BTHelper; import com.enqualcomm.support.bean.Contact; import com.enqualcomm.support.bean.ICLocation; import com.enqualcomm.support.bean.SleepInfo; @@ -74,6 +75,8 @@ import java.util.concurrent.TimeUnit; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static com.enqualcomm.support.Constants.ACTION_ALARM_ADD_DATAPOINTS; +import static com.enqualcomm.support.Constants.ACTION_ALARM_BLE_SCAN; +import static com.enqualcomm.support.Constants.ACTION_ALARM_CHECK_ANTI; import static com.enqualcomm.support.Constants.ACTION_CHECK_ANTIOFF_EVENT; import static com.enqualcomm.support.Constants.ACTION_EQC_ALARM; import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; @@ -777,6 +780,8 @@ public class CoreService extends Service { runtime.setNeddReportCutoff(Config.getNeedCutOff(this)); runtime.setNeedAntioff(Config.getNeedAntiOff(this)); + + Config.setHeartBeatCycle(this,5); //临时设置为3分钟,给L03测试用。测试断线问题未解决,取消测试。 //初始化ServerHeartBeat Cycle Config.loadHearBeatSetting(runtime); @@ -909,6 +914,20 @@ public class CoreService extends Service { setTempAlarm(); + + //初始化佩戴检测 + runtime.anti_test_cycle=Config.getCheckAntiPolingCycle(this); + if( runtime.anti_test_cycle>0){ + setAntiAlarm(); + } + + //初始化蓝牙检测 + runtime.bleInfo.bleScanCycle=Config.getBleScanCycle(this); + if(Config.BLEScanProtocol==1 && runtime.bleInfo.bleScanCycle>0) + { + setBleScanAlarm(runtime.bleInfo.bleScanCycle); + } + //设置来电模式 SimSignalUtil.SetRingMode(this, AudioManager.RINGER_MODE_NORMAL,true); @@ -1114,6 +1133,10 @@ public class CoreService extends Service { if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", stringBuilder1.toString()); // this.locationClient.triggerLocationProcess(); + }else if (Constants.ACTION_ALARM_BLE_SCAN.equals(paramIntent.getAction())) { + //循环蓝牙扫描 + setBleScanAlarm(runtime.bleInfo.bleScanCycle); + }else if (Constants.ACTION_PRACTICE_REPORT_ALARM.equals(paramIntent.getAction())) { //alarm是延迟的,所以这个判断主要是给最后一次可能无效的测量 if (Runtime.practising==true) { @@ -1157,18 +1180,19 @@ public class CoreService extends Service { setWakeAlarm(); return Service.START_STICKY; } else if (ANTI_ALARM.equals(paramIntent.getAction())) { + //测试是否佩戴 + antiservice.CheckAntiByPoling(); + if (Config.LOG_TOFILE) + ICLogger.logToFile("alarmCycle", "ANTI_ALARM alarmCycle "); + setAntiAlarm(); - if (this.mKeepAlive != null) { - - if (connection.isServerConnected() && runtime.isServerProtocolConnected()) { - //测试是否佩戴 - - } - setAntiAlarm(); - if (Config.LOG_TOFILE) - ICLogger.logToFile("alarmCycle", "ANTI_ALARM alarmCycle "); - return Service.START_STICKY; - } + return Service.START_STICKY; +// if (this.mKeepAlive != null) { +// +// if (connection.isServerConnected() && runtime.isServerProtocolConnected()) { +// } +// return Service.START_STICKY; +// } } else if (TEMP_ALARM.equals(paramIntent.getAction())) { setTempAlarm(); @@ -1235,6 +1259,7 @@ public class CoreService extends Service { setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位 }else if(ACTION_CHECK_ANTIOFF_EVENT.equals(paramIntent.getAction())){ + //只在中断式检测过程中延时用 antiservice.check_ant_event(); } @@ -1273,6 +1298,21 @@ public class CoreService extends Service { if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString()); } + public void setBleScanAlarm(int cycle){ + if (Config.BLEScanProtocol!=1) { + ICLogger.i("BLEScanProtocol!=1 skip setPolingCheckAntiAlarm"); + return; + } + StringBuilder sb=new StringBuilder(); + if (cycle>1) { + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, cycle, ACTION_ALARM_BLE_SCAN); + } + sb.append("setBleScanAlarm " + cycle); + locationClient.triggerBLEProcess(); + ICLogger.i(sb.toString()); + if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString()); + } + public void setEmegencyLocationSTOPAlarm(int delayTimeInMinutes){ StringBuilder sb=new StringBuilder(); AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,delayTimeInMinutes, ACTION_SEND_EMEGENCY_LOCATION_STOP); @@ -1341,15 +1381,13 @@ public class CoreService extends Service { // int mod=runtime.getLocationInstance().getWorkingMod(); StringBuilder sb=new StringBuilder(); int cycle=runtime.anti_test_cycle; - - //心跳指令默认设置为3分钟 - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,cycle, ANTI_ALARM); + if(cycle>1) { + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, cycle, ANTI_ALARM); + } sb.append(" setHeartAlarm "+ANTI_ALARM+", cycle "+cycle); -// locationClient.triggerLocationProcess(); + ICLogger.i(sb.toString()); FileOutputUtil.fileOutput(runtime.getCacheDir(),"alarmCycle",sb.toString()); - -// AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1, HEART_ALARM); } public void setTempAlarm(){ // int mod=runtime.getLocationInstance().getWorkingMod(); diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index c9a9f34f..8a839eda 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -141,42 +141,47 @@ public class LocationClient { 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() ); - boolean in_area = false; - try { - for (String mac : btNewScanResult) { - ICLogger.i("bt mac " + mac.replace(":", "").toLowerCase() + " " + mac.toLowerCase()); - String tmp = mac.replace(":", "").toLowerCase(); - tmp = tmp.substring(0, tmp.indexOf(",")); - if (runtime.bleInfo.btMacList.contains(tmp)) { - in_area = true; - break; + + + boolean in_area = false; + try { + for (String mac : btNewScanResult) { + ICLogger.i("bt mac " + mac.replace(":", "").toLowerCase() + " " + mac.toLowerCase()); + String tmp = mac.replace(":", "").toLowerCase(); + tmp = tmp.substring(0, tmp.indexOf(",")); + if (runtime.bleInfo.btMacList.contains(tmp)) { + in_area = true; + break; + } } - } - if(in_area == false && ScanBLERetryCount-- > 0){ + if (in_area == false && ScanBLERetryCount-- > 0) { //如果没有扫描到,且扫描次数没有超限,则重新扫描一次。注意要delay 5秒 - Util.mSleep(5000); + Util.mSleep(5000); //Do retry Scan - ICLogger.i("BT BLE not found retry Scan "+ ScanBLERetryCount); + ICLogger.i("BT BLE not found retry Scan " + ScanBLERetryCount); btHelper.scanBLE(); - return ; - }else { - runtime.bleInfo.is_in_area = in_area; - ScanBLERetryCount=maxBLEScanTime; + return; + } else { + runtime.bleInfo.is_in_area = in_area; + ScanBLERetryCount = maxBLEScanTime; + } + + } catch (Exception e) {//如果出错,原来的状态不要变。防止误报,最多延迟一个周期报。 + e.printStackTrace(); + ICLogger.i(e.getMessage()); } - }catch(Exception e){//如果出错,原来的状态不要变。防止误报,最多延迟一个周期报。 - e.printStackTrace(); - ICLogger.i(e.getMessage()); - } + } else { runtime.bleInfo.is_in_area = false; ScanBLERetryCount=maxBLEScanTime; @@ -245,7 +250,21 @@ public class LocationClient { runtime.bleInfo.last_is_in_area=runtime.bleInfo.is_in_area; //扫描结束就清掉scanBLEOnly,保证下次不会被误操作。 scanBLEOnly=false; - + }else{ //Config.BLEScanProtocol==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(":","")); + } + ICLogger.i(sb.toString()); + Deliver.sendLocationMSG(protocolAPIHelper.getBLEScanResult(runtime)); + }else{ + ICLogger.i("未搜到蓝牙设备!"); + } + } } }); @@ -439,13 +458,23 @@ public class LocationClient { startLocationProcess(runtime.getLocationInstance().getWorkingMod()); } }else if (msg.what == msgWhat_StartBLEProcess){ - if (runtime.bleInfo.btMacList.size() > 0) { + if(Config.BLEScanProtocol==0) { + if (runtime.bleInfo.btMacList.size() > 0) { + //有蓝牙搜索要求则 先进行蓝牙扫描 + if (!btHelper.isBtscanning()) { + scanBLEOnly = true; + if (needLocationForBT()) + btHelper.scanBLE(); + } else { + ICLogger.i("BT Scanning skip ScanBLE only!"); + } + } + }else{ //有蓝牙搜索要求则 先进行蓝牙扫描 - if (! btHelper.isBtscanning()) { - scanBLEOnly = true; + if (!btHelper.isBtscanning()) { if (needLocationForBT()) btHelper.scanBLE(); - }else{ + } else { ICLogger.i("BT Scanning skip ScanBLE only!"); } } 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 f89a3fea..ae2ecb2f 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/BTHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/BTHelper.java @@ -7,6 +7,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.net.wifi.ScanResult; import android.os.Handler; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.Config; @@ -14,6 +15,8 @@ import com.enqualcomm.support.utils.ICLogger; import com.enqualcomm.support.utils.Util; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Set; public class BTHelper { @@ -209,12 +212,31 @@ public class BTHelper { disableBT(); hasStopedByFoundBT=true; - if (mCallback != null) + if (mCallback != null) { + resortScanResult(mNewDevicesArray); mCallback.OnScanFinished(mPairedDevicesArray, mNewDevicesArray); + } } } } + private void resortScanResult( ArrayList btlist){ + + Collections.sort(btlist, new Comparator() { + public int compare(String var1, String var2) { + try { + int tmp = var1.indexOf(","); + int rssi1 = Integer.parseInt(var1.substring(tmp + 1)); + tmp = var2.indexOf(","); + int rssi2 = Integer.parseInt(var2.substring(tmp + 1)); + return Math.abs(rssi1) - Math.abs(rssi2); + }catch (Exception e){ + return 0; + } + } + }); + + } private class RunableStopBleScan implements Runnable{ @Override @@ -225,9 +247,10 @@ public class BTHelper { //开始扫描前是关闭的,就关闭它 // if(!enabledBeforScan) disableBT(); - if (mCallback != null) + if (mCallback != null){ + resortScanResult(mNewDevicesArray); mCallback.OnScanFinished(mPairedDevicesArray, mNewDevicesArray); - + } } } diff --git a/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java b/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java index 09d8b7e7..7c957029 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java +++ b/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java @@ -7,10 +7,13 @@ public class BLEInfo { public String ble_area_id=""; public ArrayList btMacList=new ArrayList<>(); + public ArrayList btScanResult=new ArrayList<>(); public String gps_n=""; public String gps_e=""; public boolean is_in_area=false; public boolean last_is_in_area=false; + public static int bleScanCycle=0; + } diff --git a/app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java b/app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java index df9f4e7b..3e63a6a4 100644 --- a/app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java +++ b/app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java @@ -187,6 +187,13 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { ICLogger.i("AntiOff Timeout! send antioff event "+current_anti_status); } + public boolean CheckAntiByPoling(){ + //检查是否佩戴。佩戴返回true + //send_antiof_event(); + return false; + } + + //return 0 表示check 结束, 1表示需要继续check 由coreService中 ACTION_CHECK_ANTIOFF_EVENT进行 public int check_ant_event(){ @@ -194,18 +201,18 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { ICLogger.i("anti_event_receivedTime in "+ (currenttime - anti_event_receivedTime) +"ms ago ,anti_event_count_when_start_timer "+ant_status_event_reported ); - if ((currenttime- anti_event_receivedTime) >= 2000){ + + if ((currenttime - anti_event_receivedTime) >= 2000) { send_antiof_event(); - ant_status_event_reported=0; + ant_status_event_reported = 0; return 0; - }else{ - long restTimeNeedDelay=(2000 + anti_event_receivedTime-currenttime); - ICLogger.i("Still need delay "+restTimeNeedDelay+"ms to check anti_event again!"); - setAntiCheckAlarm((int)restTimeNeedDelay); + } else { + long restTimeNeedDelay = (2000 + anti_event_receivedTime - currenttime); + ICLogger.i("Still need delay " + restTimeNeedDelay + "ms to check anti_event again!"); + setAntiCheckAlarm((int) restTimeNeedDelay); return 1; } - } public void setAntiCheckAlarm(int ms){ @@ -452,11 +459,18 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { mRuntime=paramRuntime; mContext=mRuntime.getContextProxy().context; mConnection=paramConnection; - startSensor(); + if(Config.UsePolingCheckWeared==false) { + ICLogger.i("启用中断式佩戴检测!"); + startSensor(); + }else{ + ICLogger.i("启用循环式佩戴检测!"); + } } @Override public void onDetach(Connection paramConnection, Runtime paramRuntime) { - mSensorManager.unregisterListener(mSensorEventListener); + if(Config.UsePolingCheckWeared==false) { + mSensorManager.unregisterListener(mSensorEventListener); + } } } diff --git a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java index 79d0f1f4..7e21969d 100644 --- a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java +++ b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java @@ -680,4 +680,28 @@ public class protocolAPIHelper { } return ret; } + + public static StringMessage getBLEScanResult(Runtime runtime){ + if (is_protocol_not_Initialled()) return null; + StringMessage ret=null; + switch(Config.protocol_no) + { + case Config.PROTOCOL_JIAI: + ret=null; + break; + case Config.PROTOCOL_BEEHOME: + ret=null; + break; + case Config.PROTOCOL_IC: + ret = protocol_ic.APBR(runtime); + break; + case Config.PROTOCOL_FZD: + ret=null; + break; + case Config.PROTOCOL_MQTT: + ret=null; + break; + } + return ret; + } } diff --git a/app/src/main/java/com/ic/protocols/protocol_ic.java b/app/src/main/java/com/ic/protocols/protocol_ic.java index 7307b558..1c58bc3e 100644 --- a/app/src/main/java/com/ic/protocols/protocol_ic.java +++ b/app/src/main/java/com/ic/protocols/protocol_ic.java @@ -2606,6 +2606,78 @@ public class protocol_ic { } + + public static StringMessage APBT(String id,String cycle) + { + return genStringMessage("APBT",new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APBT)) + .append(CMDSPLIT).append(id) + .append(CMDSPLIT).append(cycle) + .append(CMDEND).toString()); + } + + /*** + * 响应蓝牙扫描周期设定 + * @param connection + * @param runtime + * @param cmd + */ + public void handleBPBT( Connection connection,Runtime runtime,String cmd) { +/*** + * IWBPBT,353456789012345,080835,1# + * 说明:设置蓝牙扫描周期,单位时间分钟 + * IW:标识符 + * BPBT : 命令字符 + * 353456789012345:IMEI号,设备唯一ID + * 080835:指令流水号 + * 1: 扫描周期,对应单位为分钟 + * 设备响应: IWAPBT,080835, 1# + * 080835:指令流水号 + * 1: 剪断开关状态(实际上与下行的命令一致) + */ + + log("BPBT "+cmd); + String[] cmdlist=cmd.split(CMDSPLIT); + if (cmdlist.length==4){ + String id=cmdlist[2]; + String cycle=cmdlist[3].replace("#",""); + connection.send(APBT(id,cycle)); + + if(Util.isNumeric(cycle)){ + int intcycle=Integer.parseInt(cycle); + Config.setBleScanCycle(runtime.getContextProxy().context,intcycle); + runtime.bleInfo.bleScanCycle=intcycle; + ICLogger.i("设置蓝牙扫描周期 "+intcycle+" 分钟"); + CoreService.getInstance().setBleScanAlarm(intcycle); + }else{ + ICLogger.i(" BPBT Format error!"); + } + + }else{ + ICLogger.i(" BPBT Format error!"); + } + } + + /*** + * 发送蓝牙扫描结果 + * @param runtime + * @return + */ + public static StringMessage APBR(Runtime runtime) { + if (runtime.bleInfo.btScanResult.size() > 0) { + StringBuffer sb=new StringBuffer(); + sb.append(runtime.bleInfo.btScanResult.size()); + for(String it:runtime.bleInfo.btScanResult){ + sb.append(CMDSPLIT).append(it); + } + return genStringMessage("APBR", new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APBR)) + .append(CMDSPLIT).append(sb.toString()) + .append(CMDEND).toString()); + + }else{ + return null; + } + } + public boolean handleCmd(CMD_TYPE type, String cmd) { //普通非二进制命令用此函数处理 @@ -2816,13 +2888,16 @@ public class protocol_ic { handleBPDH(mConnection,mRuntime,cmd); break; - case BPTQ: + case BPTQ: //天气下发 handleBPTQ(mConnection,mRuntime,cmd); break; - case BPAT: + case BPAT://剪断开关设定 handleBPAT(mConnection,mRuntime,cmd); break; + case BPBT://蓝牙扫描设置 + handleBPBT(mConnection,mRuntime,cmd); + break; } diff --git a/dNSCache/dNSCache.iml b/dNSCache/dNSCache.iml index 4e8c3eb7..8d78d7a1 100644 --- a/dNSCache/dNSCache.iml +++ b/dNSCache/dNSCache.iml @@ -31,16 +31,16 @@ - + - - + + -- 2.17.1