From cbedc19286ed56ca8a523b58d5282e5455ed161a Mon Sep 17 00:00:00 2001 From: TrillGates Date: Sat, 17 Jul 2021 15:28:32 +0800 Subject: [PATCH] restore limit value from database. --- .../java/com/enqualcomm/support/Config.java | 27 +++-- .../com/enqualcomm/support/CoreService.java | 102 ++++++++++++++++-- .../support/service/HeartRateManager.java | 18 +++- .../java/com/ic/protocols/protocol_s123.java | 7 ++ 4 files changed, 135 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 19e7ad52..3d7e835b 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -42,7 +42,7 @@ public class Config { //如果重试都失败,则丢弃命令不进行盲点续传 public static boolean discard_cmd_after_retryfailed = true; - public static boolean enableDataRoaming=false; + public static boolean enableDataRoaming = false; public static boolean forceMoveCheck = true; public static boolean forceWearCheck = true; @@ -92,6 +92,22 @@ public class Config { public static boolean needBroadcastCutoffAlarm = true; + //add by TrillGates=================start + //各种阀值:血压,血氧,心率,体温 + //以下值的赋值时机: + //1、服务起来的时候,从数据库中读取记录阀值 + //2、当阀值更新的时候,更新数据的同时,也更新以下的值 + //保存到这里来,方便使用,不需要每次去查询 + public static int LIMIT_VALUE_PPGH = 0; + public static int LIMIT_VALUE_PPGL = 0; + public static int LIMIT_VALUE_BPH_H = 0; + public static int LIMIT_VALUE_BPH_L = 0; + public static int LIMIT_VALUE_BPL_H = 0; + public static int LIMIT_VALUE_BPL_L = 0; + public static int LIMIT_VALUE_OXYGEN = 0; + //add by TrillGates=================end + + //定位是否使用wifi的配置。 public static boolean disableWiFiScan = false; @@ -336,7 +352,7 @@ public class Config { } public static void loadHearBeatSetting(Runtime runtime) { - if(Config.protocol_no == Config.PROTOCOL_UNKNOWN){ + if (Config.protocol_no == Config.PROTOCOL_UNKNOWN) { Config.HeartBeatAlarmCycle = 65535; //不识别的协议,就设置一个很大的数据相当于没有心跳,这样更省电 } runtime.setHeartBeatCycle(Config.getHeartBeatCycle(runtime.getContextProxy().context)); @@ -606,7 +622,7 @@ public class Config { break; default: ICLogger.i("协议版本 目前支持0,1,2,3,4,5,6,7"); - ret=PROTOCOL_UNKNOWN; + ret = PROTOCOL_UNKNOWN; break; } } else { @@ -702,7 +718,6 @@ public class Config { public static int getSleepScore(Context context) { - return Util.getSystemPropertiesInt("persist.sys." + Constants.SHAREKEY_SETTING_SLEEP_SCORE, 0); } @@ -912,7 +927,7 @@ public class Config { noPPGSensor = false; noTempSensor = false; L004_BroadCastActionStrip = true; - enableDataRoaming=true; + enableDataRoaming = true; Config.forceMoveCheck = false; //即爱对gps不进行运动检测,此变量专门为了给其他协议进行强制运动检测用的。 } else if (Config.custom_name.equals("l005")) { @@ -934,7 +949,7 @@ public class Config { noPPGSensor = true; noTempSensor = true; L004_BroadCastActionStrip = true; - enableDataRoaming=true; + enableDataRoaming = true; forceMoveCheck = false; //即爱对gps不进行运动检测,此变量专门为了给其他协议进行强制运动检测用的。 } else if (custom_name.equals("YQ") || custom_name.equals("YQ_EN")) { ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true); diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index b9b69589..ba62c20d 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -21,6 +21,7 @@ import android.os.Messenger; import android.os.PowerManager; import android.os.SystemClock; import android.support.annotation.Nullable; +import android.text.TextUtils; import android.util.Log; import android.widget.Toast; @@ -33,7 +34,6 @@ import com.enqualcomm.support.bean.StringMessage; import com.enqualcomm.support.bean.heartRateStatus; import com.enqualcomm.support.provider.ICDatabaseHelper; import com.enqualcomm.support.provider.WeTalkMessageProvider; -import com.enqualcomm.support.provider.ICGlobalSettingsProvider; import com.enqualcomm.support.service.AntiMonitorService; import com.enqualcomm.support.service.CheckSIM; import com.enqualcomm.support.service.Deliver; @@ -110,6 +110,7 @@ import static com.enqualcomm.support.bean.ICLocation.EMERGNECY_MOD; import static com.enqualcomm.support.bean.ICLocation.LOWPOWER_MOD; import static com.enqualcomm.support.bean.ICLocation.NORMAL_MOD; import static com.enqualcomm.support.bean.ICLocation.REALTIME_MOD; +import static com.enqualcomm.support.provider.ICGlobalSettingsProvider.SETTINGS; public class CoreService extends Service { @@ -661,6 +662,13 @@ public class CoreService extends Service { handlerThread.start(); mHandler = new Handler(handlerThread.getLooper()); } + //add by TrillGates =====start + // 加载阀值,异步加载即可 + mHandler.post(() -> { + ICLogger.d("loadLimitValue..."); + loadLimitValue(); + }); + //add by TrillGates =====end server_starting = true; String curProcessName = getProcessName(this, android.os.Process.myPid()); Log.d(TAG, "---> onCreate...."); @@ -902,20 +910,92 @@ public class CoreService extends Service { Deliver.resetCMDReocrdsDB(); - if(Config.custom_name.equals("l004pt")||Config.custom_name.equals("l004")||Config.custom_name.equals("l005")) - { + if (Config.custom_name.equals("l004pt") || Config.custom_name.equals("l004") || Config.custom_name.equals("l005")) { mHandler.postDelayed(new Runnable() { @Override public void run() { //L004PT ,L005 默认开启roaming以及默认使用以下apn - APNUtil.selectAPN("240","07","NXT17.NET",CoreService.getInstance()); + APNUtil.selectAPN("240", "07", "NXT17.NET", CoreService.getInstance()); } - },5000); + }, 5000); } ReConnectToServer(); } + /** + * 异步执行 + * 服务创建的时候,加载各种阀值:温度,心率,血氧,血压 + * 值保存到config里去 + */ + private void loadLimitValue() { + String heartRateBottomLimitValue = + getICSettingsValue("heart_rate_bottom_limit_value"); + ICLogger.d("heartRateBottomLimitValue == > " + + heartRateBottomLimitValue); + if (!TextUtils.isEmpty(heartRateBottomLimitValue)) { + Config.LIMIT_VALUE_PPGH = Integer.parseInt(heartRateBottomLimitValue); + } + String heartRateTopLimitValue = + getICSettingsValue("heart_rate_top_limit_value"); + ICLogger.d("heartRateTopLimitValue == > " + heartRateTopLimitValue); + if (!TextUtils.isEmpty(heartRateTopLimitValue)) { + Config.LIMIT_VALUE_PPGL = Integer.parseInt(heartRateTopLimitValue); + } + String bloodPressureHighTopLimitValue = + getICSettingsValue("blood_pressure_high_top_limit_value"); + ICLogger.d("bloodPressureHighTopLimitValue == > " + + bloodPressureHighTopLimitValue); + if (!TextUtils.isEmpty(bloodPressureHighTopLimitValue)) { + Config.LIMIT_VALUE_BPH_H = Integer.parseInt(bloodPressureHighTopLimitValue); + } + String bloodPressureHighBottomLimitValue = + getICSettingsValue("blood_pressure_high_bottom_limit_value"); + ICLogger.d("bloodPressureHighBottomLimitValue == > " + + bloodPressureHighBottomLimitValue); + if (!TextUtils.isEmpty(bloodPressureHighBottomLimitValue)) { + Config.LIMIT_VALUE_BPH_L = Integer.parseInt(bloodPressureHighBottomLimitValue); + } + String bloodPressureLowTopLimitValue = + getICSettingsValue("blood_pressure_low_top_limit_value"); + ICLogger.d("bloodPressureLowTopLimitValue == > " + + bloodPressureLowTopLimitValue); + if (!TextUtils.isEmpty(bloodPressureLowTopLimitValue)) { + Config.LIMIT_VALUE_BPL_H = Integer.parseInt(bloodPressureLowTopLimitValue); + } + String bloodPressureLowBottomLimitValue = + getICSettingsValue("blood_pressure_low_bottom_limit_value"); + ICLogger.d("bloodPressureLowBottomLimitValue == > " + + bloodPressureLowBottomLimitValue); + if (!TextUtils.isEmpty(bloodPressureLowBottomLimitValue)) { + Config.LIMIT_VALUE_BPL_L = Integer.parseInt(bloodPressureLowBottomLimitValue); + } + String bloodOxygenLimitValue = + getICSettingsValue("blood_oxygen_limit_value"); + ICLogger.d("bloodOxygenLimitValue == > " + bloodOxygenLimitValue); + if (!TextUtils.isEmpty(bloodOxygenLimitValue)) { + Config.LIMIT_VALUE_OXYGEN = Integer.parseInt(bloodOxygenLimitValue); + } + } + + private String getICSettingsValue(String key) { + ContentResolver contentResolver = getContentResolver(); + Cursor query = contentResolver.query(Uri.parse(SETTINGS), + new String[]{ICDatabaseHelper.sValue}, + ICDatabaseHelper.sKey + "=?", + new String[]{key}, + null); + if (query != null) { + if (query.moveToNext()) { + String value = query.getString(0); + ICLogger.d("value is == > " + value); + return value; + } + query.close(); + } + return null; + } + private void test() { ICLogger.i("周一清除所有睡眠数据Record"); runtime.getDbHelper().deleteSleepData(); @@ -1118,7 +1198,7 @@ public class CoreService extends Service { } else if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())) { ICLogger.d("收到定位闹钟..."); //如果设置项是关的,那么就return掉,如果设置项开了,直接去设置闹钟 - Cursor query = runtime.getContextProxy().getResolver().query(Uri.parse(ICGlobalSettingsProvider.SETTINGS), + Cursor query = runtime.getContextProxy().getResolver().query(Uri.parse(SETTINGS), new String[]{ICDatabaseHelper.sValue}, ICDatabaseHelper.sKey + "=?", new String[]{"BPSW"}, null); @@ -1702,7 +1782,7 @@ public class CoreService extends Service { public void getContacts() { //获取联系人 StringMessage cmdmMembers = protocolAPIHelper.requestVideoCallContact(runtime); - //获取佰锐ID + //获取佰锐ID connection.send(cmdmMembers); ICLogger.d("get contacts..."); } @@ -1719,7 +1799,7 @@ public class CoreService extends Service { @Override public void rejectCallInCome(String remoteId, int type) { //拒绝来电 - StringMessage rejectMsg = protocolAPIHelper.rejectVideoCall(runtime,remoteId, type); + StringMessage rejectMsg = protocolAPIHelper.rejectVideoCall(runtime, remoteId, type); connection.send(rejectMsg); ICLogger.d("reject remote call request..." + remoteId + "..." + type); } @@ -1727,7 +1807,7 @@ public class CoreService extends Service { @Override public void requireCall(int type, int remoteUserId) { //请求与对方通话 - StringMessage talk = protocolAPIHelper.dialVideoCall(runtime,type, remoteUserId); + StringMessage talk = protocolAPIHelper.dialVideoCall(runtime, type, remoteUserId); connection.send(talk); ICLogger.d("require call == > type is " + type + " remote user id is == > " + remoteUserId); } @@ -1743,7 +1823,7 @@ public class CoreService extends Service { public void setUpEnvState(int state) { ICLogger.d("update bairui env state..." + state); - protocolAPIHelper.updateEnvState(runtime,state); + protocolAPIHelper.updateEnvState(runtime, state); } @@ -1760,7 +1840,7 @@ public class CoreService extends Service { @Override public void unbindFriends(String remoteFriendId) { ICLogger.d("unbindFriends == > " + remoteFriendId); - StringMessage ppr = protocolAPIHelper.unbindFriends(runtime,remoteFriendId); + StringMessage ppr = protocolAPIHelper.unbindFriends(runtime, remoteFriendId); //解除朋友 connection.send(ppr); } 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 011890d6..62346331 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -161,10 +161,11 @@ public class HeartRateManager extends AbstractInvokeHandlerService { ICLogger.d("result invalidate..."); return; } - //TODO:BY TrillGates + //BY TrillGates //判断是否有超出阀值 //如果超出的话,插入一条警告通知 - //TODO: + //如果数据为0,不处理 + checkHeartRateValue(heartRate); runtime.getHRS().setHeartrateStat(heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS); runtime.getHRS().setLastHeartrate(heartRate.getHeartRate(), heartRate.getBloodHeight(), heartRate.getBloodLow(), heartRate.getOxygen()); uploadResult(); @@ -186,6 +187,19 @@ public class HeartRateManager extends AbstractInvokeHandlerService { } }; + private void checkHeartRateValue(HeartRate heartRate) { + + + + + int oxygenValue = heartRate.getOxygen(); + int heartRateValue = heartRate.getHeartRate(); + int bloodHeightValue = heartRate.getBloodHeight(); + int bloodLowValue = heartRate.getBloodLow(); + //TODO: + + } + private void uploadResult() { //只有检测PPG成功,且网络连接中才发送数据 diff --git a/app/src/main/java/com/ic/protocols/protocol_s123.java b/app/src/main/java/com/ic/protocols/protocol_s123.java index 9aa58172..7cb497de 100644 --- a/app/src/main/java/com/ic/protocols/protocol_s123.java +++ b/app/src/main/java/com/ic/protocols/protocol_s123.java @@ -1897,6 +1897,13 @@ public class protocol_s123 { updateIcSettingsValue("blood_pressure_high_bottom_limit_value", BPH_L); updateIcSettingsValue("blood_pressure_high_top_limit_value", BPH_H); updateIcSettingsValue("blood_oxygen_limit_value", OXYGEN); + Config.LIMIT_VALUE_PPGH = Integer.parseInt(PPGH); + Config.LIMIT_VALUE_PPGL = Integer.parseInt(PPGL); + Config.LIMIT_VALUE_BPH_H = Integer.parseInt(BPH_H); + Config.LIMIT_VALUE_BPH_L = Integer.parseInt(BPH_L); + Config.LIMIT_VALUE_BPL_H = Integer.parseInt(BPL_H); + Config.LIMIT_VALUE_BPL_L = Integer.parseInt(BPL_L); + Config.LIMIT_VALUE_OXYGEN = Integer.parseInt(OXYGEN); } else { ICLogger.i("BP89 format error!"); } -- 2.17.1