From: snickersun Date: Sat, 19 Sep 2020 09:04:13 +0000 (+0800) Subject: 所有Alarm消息都通过配置文件进行控制,不同项目可以通过变量进行设置。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=a7a3b31518d15ebffac9bad39f0cdb0f1fa83981;p=protocol_srv.git 所有Alarm消息都通过配置文件进行控制,不同项目可以通过变量进行设置。 Sleep 消息也通过 Config进行配置,目前只有AK项目开启。 --- diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 6633aa3a..26c949a7 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -19,6 +19,9 @@ import org.json.JSONException; import org.json.JSONStringer; import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; import static com.enqualcomm.support.utils.Util.connectWifiByReflectMethod; @@ -635,9 +638,77 @@ public class Config { return Util.getSystemPropertiesInt("persist.sys."+Constants.SHAREKEY_SETTING_SLEEP_SCORE,0); } + + public static boolean enableSleep=false; /** * 参考数据,平均每分钟步数来判断,大于 KeepSitJudgementRefValue 认为没有坐着。小于等于这个值认为坐着。 */ public static int KeepSitJudgementRefValue=30; + + /*** + * persist.sys.alarmConfig=ALARM_SOS,ALARM_LOWBATTERY,ALARM_ANTIOFF,ALARM_WEARED,ALARM_CUTOFF,ALARM_FALL,ALARM_ABNORMAL_HEART_RATE,ALARM_HEART_RATE_HIGH,ALARM_HEART_RATE_LOW,ALARM_BPH_HIGH,ALARM_BPH_LOW,ALARM_BPL_HIGH,ALARM_BPL_LOW,ALARM_SEDENTARY,ALARM_ILLEGAL_CUTOFF,ALARM_LOCK_WATCH,ALARM_TEMP_HIGH,ALARM_TEMP_LOW,ALARM_POWER_OFF,ALARM_ESCAPE,ALARM_NONE + * 配在里面的表示开启,没配的表示关闭。 默认ALARM_SOS,ALARM_LOWBATTERY,ALARM_POWER_OFF开启 + * ALARM_ILLEGAL_CUTOFF,ALARM_FALL,ALARM_ABNORMAL_HEART_RATE 没有使用,设置了也没有用 + */ + public static void loadAlarmConfig(){ + String configvalues=Util.getSystemProperties("persist.sys.alarmConfig",""); + String[] values=configvalues.split(","); + if (values.length>0){ + for (int i=0; i< values.length;i++) + { + for (Runtime.AlarmType at: Runtime.AlarmType.values()) { + if (values[i].trim().equals(at.name())){ + ConfigAlarm(at,true); + break; + } + } + } + } + dumpAlarmConfig(); + } + + public static void ConfigAlarm(Runtime.AlarmType alarmType,boolean enabled){ + AlarmConfiglist.put(alarmType.ordinal(),enabled); + } + private static void dumpAlarmConfig(){ + for (int i=0;i AlarmConfiglist; + static { + AlarmConfiglist=new HashMap(); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_SOS.ordinal(),true); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOWBATTERY.ordinal(),true); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ANTIOFF.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_WEARED.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_CUTOFF.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_FALL.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ABNORMAL_HEART_RATE.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_HIGH.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_LOW.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_HIGH.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_LOW.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_HIGH.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_LOW.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_SEDENTARY.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOCK_WATCH.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_HIGH.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_LOW.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_POWER_OFF.ordinal(),true); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ESCAPE.ordinal(),false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_NONE.ordinal(),false); + } + + public static boolean isAlarmTypeEnabled(Runtime.AlarmType alarmType){ + + boolean en=false; + if (AlarmConfiglist.containsKey(alarmType)){ + en=AlarmConfiglist.get(alarmType); + } + return en; + } + } diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index c87a0318..993e17bc 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -626,6 +626,8 @@ public class CoreService extends Service { Config.setPPGTestCycle(this, 60); Config.setTemperatureTestCycle(runtime, 60 * 60); Config.setConfigInitFlag(this, 1); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED,true); } }else if (Config.custom_branch_name.equals("l004")) { if (Config.getConfigInitFlag(this) == 0) { @@ -634,12 +636,16 @@ public class CoreService extends Service { Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH,true); } }else if (Config.custom_branch_name.equals("AK")) { if (Config.getConfigInitFlag(this)==0) { Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); + Config.enableSleep=true; // int contactcount=runtime.getDbHelper().getContactCount(getContentResolver()); // ICLogger.i("=====Contact count "+contactcount); // if(contactcount==0){ //如果没有SOS @@ -649,13 +655,17 @@ public class CoreService extends Service { // runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true); // } } - }else if (Config.custom_branch_name.equals("SGL")) { + }else if (Config.custom_branch_name.equals("SGL")) { //C5项目 if (Config.getConfigInitFlag(this)==0) { Config.setLocationMode(this, CUSTOM_MOD8_GPS); Config.setLocationCycle(this, 1800); Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ESCAPE,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH,true); // int contactcount=runtime.getDbHelper().getContactCount(getContentResolver()); // ICLogger.i("=====Contact count "+contactcount); // if(contactcount==0){ //如果没有SOS @@ -682,6 +692,9 @@ public class CoreService extends Service { Config.loadCustomServerAddr(this); Config.loadServerSettings(runtime); + //读取Alarm环境配置,项目不需要的Alarm不要发送, 目前环境变量配置优先。默认值会被覆盖。 + Config.loadAlarmConfig(); + Config.enable_NTP_Server(this,!Config.disable_ntp_server); @@ -877,6 +890,11 @@ public class CoreService extends Service { //提醒后 重置 lastCheckSitTime 以及 lastSitCheckStepCount , 重新计时 Runtime.lastSitCheckStepCount=runtime.getTotalStepCount(); Runtime.lastSitCheckTiimeyyyyMMddHHmmss=TimeUtil.getSystemTime3(); + + if(Config.isAlarmTypeEnabled(Runtime.AlarmType.ALARM_SEDENTARY)){ + runtime.setAlarmType(Runtime.AlarmType.ALARM_SEDENTARY); + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + } }else{ //只要 平均每分钟活动数大于参考值,则重置 lastCheckSitTime 以及 lastSitCheckStepCount ICLogger.i("SitCheck 平均每分钟活动数大于参考值,则重置 lastCheckSitTime 以及 lastSitCheckStepCount"); @@ -932,7 +950,11 @@ public class CoreService extends Service { + " light " + si.getLightsleep_minutes() + " score " + si.getScore() ); - Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance(),runtime)); + if (Config.enableSleep) { + Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance(), runtime)); + }else{ + ICLogger.i(" 没有开启睡眠协议,skip send message!"); + } // } // }); @@ -1182,7 +1204,11 @@ public class CoreService extends Service { cycle=runtime.getLocationInstance().getLocation_cycle(); break; } - + if(cycle == 0) + { + ICLogger.i("locationCycle == 0 stop Location !"); + Config.noLocationCycle=true; + } if (Config.noLocationCycle==false) AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context,cycle, ACTION_LOCATION_ALARM); else diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 3929b1ec..9ef58550 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -906,6 +906,41 @@ public class ICSmsManager extends BroadcastReceiver { cell_number_to_reply=phonenumber; broadCastStartFotaUpdate(mContext); sendSMS(phonenumber, "start fota update !"); + } else if (sms.equals(ENCRYPED_HEADER+"#FotaUpdateWiFi#=")){ + String tmp[] = sms.split("="); + if (tmp.length == 2) { + String tmplist[]=tmp[1].split(","); + if (tmplist.length==3){ + + String SSID=tmplist[0]; + String PWD=tmplist[1]; + String encyptType=tmplist[2]; + Config.setWiFiSSID(mContext,SSID); + Config.setWiFiPasswd(mContext,PWD); + runtime.setNoTurnOffOnScreenOff(true); + StringBuilder sb=new StringBuilder(); + if ( !Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)){ + Util.turnOnWifiForConnect(runtime.getContextProxy().context,runtime); + } + sb.append("connect to Wifi SSID " + Config.getWiFiSSID(mContext) +", WiFiPassword "+Config.getWiFiPasswd(mContext)+ ", encryptType "+encyptType+"!"); + sb.append(" And start to Update"); + cell_number_to_reply=phonenumber; + sendSMS(phonenumber, sb.toString()); + //connect to wifi + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + Deliver.connectToWifi(SSID,PWD,encyptType); + broadCastStartFotaUpdate(mContext); + } + }, 500); + }else { + sendSMS(phonenumber, "FotaUpdateWiFi Control format error!"); + } + } else { + sendSMS(phonenumber, "FotaUpdateWiFi Control format error!"); + } + }else if (sms.startsWith(ENCRYPED_HEADER+"#nolocationcycle#=")&& sms.endsWith("#")) { String tmp[] = sms.split("="); diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index 27a9c7bf..63ac23d6 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -37,6 +37,18 @@ import static com.enqualcomm.support.Config.GPSLocationTimeoutInSeconds; import static com.enqualcomm.support.Config.WiFiLocationTimeoutInSeconds; import static com.enqualcomm.support.Constants.ACTION_CHECK_LOCATION_RESULT; +/*** + * 周期定位:按周期进行,如果正在定位,则skip此次定位。 + * 强制定位:随机根据指令执行,如果正在定位,强制停止当前定位,立即执行新的定位。 + * 1、模式1 WiFi+LBS定位、15分钟一次,WiFi扫描3次如果都没有结果,20秒内返回LBS定位 + * 2、模式2 WiFi+LBS模式,1小时1一次,WiFi扫描3次如果都没有结果,20秒内返回LBS定位 + * 3、模式3 GPS定位模式,1分钟一次定位,GPS常开,超时返回WiFi定位。GPS 15秒内信号很差的话会提前关闭,返回wifi+LBS定位。 + * 4、模式4 GPS定位模式,1分钟定位一次,GPS常开,超时返回WiFi定位,GPS 15秒内信号很差的话会提前关闭,返回wifi+LBS定位。5分钟后自动工作在模式1上。 + * 5、模式5、8 GPS定位模式,客户自定义定位时间, 1分钟以内含1分钟,GPS常开,超时返回WiFi+LBS定位,1分钟以上的,GPS超2分钟时会关闭,GPS 15秒内信号很差的话也会提前关闭,返回wifi+LBS定位。 + * 6、模式9 WiFi模式,客户自定义定位时间,WiFi扫描3次如果都没有结果,20秒内返回LBS定位 + * 7、即时定位返回当前模式的定位方式,会强制进行定位。 + * 8、每次切换定位模式,会执行一次强制定位。 + */ public class LocationClient { private static final String TAG = LocationClient.class.getSimpleName(); private static final long CHANGENETMODETIME = 43200000L; diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index f9847fae..92227b82 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -4,6 +4,7 @@ package com.enqualcomm.support.bean; import android.content.Context; import android.support.constraint.solver.widgets.Helper; +import com.enqualcomm.support.Config; import com.enqualcomm.support.adapter.LBSHelper; import com.enqualcomm.support.utils.ContextProxy; import com.enqualcomm.support.utils.DBHelper; @@ -196,10 +197,14 @@ public class Runtime { * 07:心率异常, 08:心率过高, 09:心率过低,10:收缩压过高,11:收缩压过低,12:舒张压过高,13:舒张压过低, * 14:久坐提醒,15:非法解锁(剪断报警),16:锁定提醒(佩戴提醒),17:体温过高,18体温过低) 19 关机事件(非服务器指令关机), 20,escape逃跑事件(离开蓝牙管控范围) */ - public void setAlarmType(AlarmType alarm){ + public boolean setAlarmType(AlarmType alarm){ // if ( !fall && !lowbattery && !sos && antioff) g_alarm=alarm; + if (Config.isAlarmTypeEnabled(alarm) == false){ + ICLogger.i(alarm.name()+" is disabled, skip!"); + return false; + } //同时更新防走丢设备状态标志 setFZDDevStatus(alarm); @@ -280,7 +285,7 @@ public class Runtime { alarmType="00"; break; } - + return true; } 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 17ce616d..c26feae5 100644 --- a/app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java +++ b/app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java @@ -99,9 +99,10 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { send_cutoff_event_broadcast(0); } mRuntime.Cut_off_flag = 0; - mRuntime.setAlarmType(Runtime.AlarmType.ALARM_LOCK_WATCH); - StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime); - Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + if(mRuntime.setAlarmType(Runtime.AlarmType.ALARM_LOCK_WATCH)) { + StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime); + Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + } // try { // sleep(1000); @@ -118,9 +119,10 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { send_cutoff_event_broadcast(1); } mRuntime.Cut_off_flag=1; - mRuntime.setAlarmType(Runtime.AlarmType.ALARM_CUTOFF); - StringMessage msg=protocolAPIHelper.getWarningMSG(mRuntime); - Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + if(mRuntime.setAlarmType(Runtime.AlarmType.ALARM_CUTOFF)) { + StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime); + Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + } // try { // sleep(1000); // } catch (InterruptedException e) { @@ -136,10 +138,10 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { send_anti_event_broadcast(0); } mRuntime.Anti_off_flag = 0; - mRuntime.setAlarmType(Runtime.AlarmType.ALARM_WEARED); - StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime); - Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! - + if(mRuntime.setAlarmType(Runtime.AlarmType.ALARM_WEARED)) { + StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime); + Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + } // try { // sleep(1000); // } catch (InterruptedException e) { @@ -155,9 +157,10 @@ public class AntiMonitorService extends AbstractInvokeHandlerService { send_anti_event_broadcast(1); } mRuntime.Anti_off_flag=1; - mRuntime.setAlarmType(Runtime.AlarmType.ALARM_ANTIOFF); - StringMessage msg=protocolAPIHelper.getWarningMSG(mRuntime); - Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + if(mRuntime.setAlarmType(Runtime.AlarmType.ALARM_ANTIOFF)) { + StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime); + Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送! + } // try { // sleep(1000); // } catch (InterruptedException e) { diff --git a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java index 03a7fd71..0a5a1e54 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -60,41 +60,46 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se //ppg if(runtime.getHRS().ppg_threshold_max>0 && runtime.getHRS().getPPG() >runtime.getHRS().ppg_threshold_max){ - runtime.setAlarmType(Runtime.AlarmType.ALARM_HEART_RATE_HIGH); - //trigger AP10 报警定位 - Deliver.sendLocationMSG( protocolAPIHelper.getWarningMSG(runtime)); + if(runtime.setAlarmType(Runtime.AlarmType.ALARM_HEART_RATE_HIGH)) { + //trigger AP10 报警定位 + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + } }else if ( runtime.getHRS().ppg_threshold_min>0 && runtime.getHRS().getPPG()0 && runtime.getHRS().getBPH() >runtime.getHRS().bph_threshold_max){ - runtime.setAlarmType(Runtime.AlarmType.ALARM_BPH_HIGH); - //trigger AP10 报警定位 - Deliver.sendLocationMSG( protocolAPIHelper.getWarningMSG(runtime)); + if(runtime.setAlarmType(Runtime.AlarmType.ALARM_BPH_HIGH)) { + //trigger AP10 报警定位 + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + } }else if ( runtime.getHRS().bph_threshold_min>0 && runtime.getHRS().getBPH()0 && runtime.getHRS().getBPL() >runtime.getHRS().bpl_threshold_max){ - runtime.setAlarmType(Runtime.AlarmType.ALARM_BPL_HIGH); - //trigger AP10 报警定位 - Deliver.sendLocationMSG( protocolAPIHelper.getWarningMSG(runtime)); + if(runtime.setAlarmType(Runtime.AlarmType.ALARM_BPL_HIGH)) { + //trigger AP10 报警定位 + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + } }else if ( runtime.getHRS().bpl_threshold_min>0 && runtime.getHRS().getBPL()