From: snickersun Date: Sat, 28 Nov 2020 17:54:30 +0000 (+0800) Subject: release L02protocolV2 V717 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=f99858b9251bec01bb4a606e7f605d27fee812fe;p=protocol_srv.git release L02protocolV2 V717 脱腕 心率,体温不检测 --- diff --git a/app/release/ICSer_V715_2011251709_release.apk b/app/release/ICSer_V717_2011290053_release.apk similarity index 78% rename from app/release/ICSer_V715_2011251709_release.apk rename to app/release/ICSer_V717_2011290053_release.apk index 2a40b345..3be90def 100644 Binary files a/app/release/ICSer_V715_2011251709_release.apk and b/app/release/ICSer_V717_2011290053_release.apk differ diff --git a/app/release/output.json b/app/release/output.json index d1040a24..e2081b6c 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":715,"versionName":"2011251709","enabled":true,"outputFile":"ICSer_V715_2011251709_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V715_2011251709_release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":717,"versionName":"2011290053","enabled":true,"outputFile":"ICSer_V717_2011290053_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V717_2011290053_release.apk","properties":{}}] \ No newline at end of file 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 81169beb..66d28215 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -1,583 +1,590 @@ -package com.enqualcomm.support.service; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.Messenger; -import android.os.PowerManager; -import android.util.Log; - -import com.enqualcomm.support.Config; -import com.enqualcomm.support.Constants; -import com.enqualcomm.support.CoreService; -import com.enqualcomm.support.LocationClient; -import com.enqualcomm.support.bean.StringMessage; -import com.enqualcomm.support.utils.ICHttpUtil; -import com.enqualcomm.support.utils.Util; -import com.ic.jni.ICJniUtils; -import com.ic.protocols.protocolAPIHelper; -import com.enqualcomm.support.bean.Runtime; -import com.enqualcomm.support.bean.heartRateStatus; -import com.enqualcomm.support.service.base.AbstractInvokeHandlerService; -import com.enqualcomm.support.utils.Connection; -import com.enqualcomm.support.utils.ICLogger; -import com.enqualcomm.support.utils.NettyConnection; -import com.enqualcomm.support.utils.SimSignalUtil; -import com.enqualcomm.support.utils.TimeUtil; - -import java.util.Random; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import static android.content.Context.SENSOR_SERVICE; -import static com.enqualcomm.support.Constants.ACTION_BROADCAST_PPG; -import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; -import static com.enqualcomm.support.Constants.MSG_WHAT_PPG; -import static com.enqualcomm.support.Constants.key_bph; -import static com.enqualcomm.support.Constants.key_bpl; -import static com.enqualcomm.support.Constants.key_ppg; -import static com.enqualcomm.support.Constants.key_spo2; - -public class HeartRateManager extends AbstractInvokeHandlerService implements SensorEventListener { - private int mNetworkType; - - private SimSignalUtil mSignalUtil; - - private Runtime runtime; - private Connection connection; - - private ScheduledThreadPoolExecutor timerPPG=null; - private static Handler mHandler=null; - - private void checkWarning(){ - //ppg - if(runtime.getHRS().ppg_threshold_max>0 && runtime.getHRS().getPPG() >runtime.getHRS().ppg_threshold_max){ - - if(runtime.setAlarmType(Runtime.AlarmType.ALARM_HEART_RATE_HIGH)) { - //trigger AP10 报警定位 -// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - ICLogger.i("triggerSOSLocationProcess "); - LocationClient.getInstance().triggerSOSLocationProcess(); - } - - }else if ( runtime.getHRS().ppg_threshold_min>0 && runtime.getHRS().getPPG()0 && runtime.getHRS().getBPH() >runtime.getHRS().bph_threshold_max){ - - if(runtime.setAlarmType(Runtime.AlarmType.ALARM_BPH_HIGH)) { - //trigger AP10 报警定位 - ICLogger.i("triggerSOSLocationProcess "); - LocationClient.getInstance().triggerSOSLocationProcess(); -// 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){ - - if(runtime.setAlarmType(Runtime.AlarmType.ALARM_BPL_HIGH)) { - //trigger AP10 报警定位 - ICLogger.i("triggerSOSLocationProcess "); - LocationClient.getInstance().triggerSOSLocationProcess(); -// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - } - - }else if ( runtime.getHRS().bpl_threshold_min>0 && runtime.getHRS().getBPL()=(30-1)){ - //超过30次发送数据给服务器 - ICLogger.i("自由锻炼中,发送数据给服务器 "+Runtime.healthInfo.getBufferData().length); - mHandler.post(new Runnable() { - @Override - public void run() { -// ICHttpUtil.uploadData(Runtime.healthInfo.getBufferDataStr(),runtime,TimeUtil.getSystemTime2(),null); - Deliver.sendLocationMSG(protocolAPIHelper.getPRACTICE()); - //发送过后重置 - Runtime.healthInfo.resetBuffer(); - } - }); - } - }else { - StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(runtime); - //发送给EQC服务器的 - sendBroadcastPPGResult(); - //因为协议中没有时间变量,所以只能实时传输,如果恰巧没有网络也只能丢弃,有时间变量的话,可以考虑通过deliver的buffer来进行缓存发送 - if (PPGDATA == null) { - StringMessage ppgd = protocolAPIHelper.getPPG_MSG(runtime.getHRS().getPPG(), runtime); - StringMessage bloodd = protocolAPIHelper.getBlood_MSG(runtime.getHRS().getBPH(), runtime.getHRS().getBPL(), runtime); - StringMessage oxd = protocolAPIHelper.getOxygen_MSG(runtime.getHRS().getSpo2(), runtime); - Deliver.sendLocationMSG(ppgd); - Deliver.sendLocationMSG(bloodd); - Deliver.sendLocationMSG(oxd); - - checkWarning(); - - } else { - Deliver.sendLocationMSG(PPGDATA); - ICLogger.i("Send PPG " + PPGDATA.isFromCache()); - checkWarning(); - } - } - - } else { - ICLogger.i("PPG Failed for Timeout!"); - } - stopPPG(); - } - break; - case 200: { - startPPG(); - } - break; - case 300: { - stopPPG(); - } - break; - } - return false; - } - }); - - } - - - private void sendBroadcastPPGResult(){ - Intent intent=new Intent(ACTION_BROADCAST_PPG); - intent.putExtra("ppg",runtime.getHRS().getPPG()); - intent.putExtra("bph",runtime.getHRS().getBPH()); - intent.putExtra("bpl",runtime.getHRS().getBPL()); - intent.putExtra("spo2",runtime.getHRS().getSpo2()); - intent.putExtra("time",runtime.getHRS().getTestTime()); - runtime.getContextProxy().context.sendBroadcast(intent); - } - - private SensorManager mSensorManager; - private Sensor mHeartRate; - int PPG; - int BPH; - int BPL; - int SPo2; - boolean isWared ; - boolean isPPGTesting ; - static boolean isTimerStarted; - public static heartRateStatus.HEARTRATE_WORKINGSTAT currentStat; - static int delayCount; - static int testCount; - static int notWaredCount; - static int noPPGCount; - private final int MAX_TESTTIMES=30000;//最大延迟测试时间为30秒 - - public int randomOxygenValue() { - int min = 95; - int max = 99; - int ret=min + ((int) (new Random().nextFloat() * (max - min))); - return ret; - } - - public void doPPGtest(){ - - int hrsType=ICJniUtils.isPPGavailable(); - if (hrsType>0 && hrsType != ICJniUtils.PPG_EGC_SensorType.PPG_EGC_TYPE_IC66.ordinal()) { - PPG = ICJniUtils.getPPG();//调用底层函数保证状态更新。 - BPH = ICJniUtils.getHighBloodPressure(); - BPL = ICJniUtils.getLowBloodPressure(); - SPo2 = ICJniUtils.getSPO2(); - if(SPo2==0){ - SPo2=randomOxygenValue(); - } - isWared = (ICJniUtils.isWeared() == 1); - isPPGTesting = (ICJniUtils.isPPGStarted() == 1); - }else{ - isPPGTesting=true; - } - ICLogger.i("PPG TESTING="+isPPGTesting+", isWared="+isWared+", PPG="+PPG+", BPH="+BPH+", BPL="+BPL+", SPo2="+SPo2); - if (isPPGTesting){ - if (isWared ) { - if (PPG > 0) { - currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS; - } else { - currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_WARED_AND_TESTING; - } - }else{ - currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_NOTWARED; - } - }else{ - currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_CLOSED; - } - - - if (currentStat== heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_NOTWARED){ - notWaredCount--; - if( notWaredCount <0){ //没有佩戴次数到限制后,停止检测 - ICLogger.i("HEARTRATE_NOTWARED 超过时限,取消检测报告!"); - stopPPG(); - } - }else if (currentStat== heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_WARED_AND_TESTING){ - noPPGCount--; - if( noPPGCount <0){ //没有佩戴次数到限制后,停止检测 - ICLogger.i("HEARTRATE WARED And Testing (Wared=1 PPG=0)超过时限,取消检测报告!"); - stopPPG(); - } - } - - - if (currentStat==heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS){ - runtime.getHRS().setLastHeartrate(PPG,BPH,BPL,SPo2); - delayCount--; - if (delayCount<0) //达到延迟时间后,停止检测并发送数据 - sendAndStopPPG(); - - }else{ - runtime.getHRS().setLastHeartrate(0,0,0,0); - } - runtime.getHRS().setHeartrateStat(currentStat); - - - - - testCount--; - if (testCount<0) - { - ICLogger.i("PPG 超过 "+MAX_TESTTIMES+"秒 未能得出结果,取消检测报告!"); - stopPPG(); - } - - } - - private void sendAndStopPPG(){ - //结束和发送数据 - mHandler.sendEmptyMessage(100); - } - PowerManager.WakeLock mWakeLock=null; - public PowerManager.WakeLock getPPGWakeLock() { - mWakeLock = ((PowerManager)(runtime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, HeartRateManager.class.getSimpleName()); - mWakeLock.acquire(30000L); - return mWakeLock; - } - - public void releaseWakeLock(){ - if (mWakeLock!=null && mWakeLock.isHeld()){ - mWakeLock.release(); - } - mWakeLock=null; - } - public void startPPG(){ - - int hrsType=ICJniUtils.isPPGavailable(); - if ( hrsType > 0 && (isTimerStarted == false) ) { - currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_OPEN; - delayCount = 4;//检测成功后4秒发送数据 - notWaredCount = 5; //初始化没有佩戴的检测次数5,连续5秒没有佩戴则取消检测 - noPPGCount = 30;//即使佩戴了,但是30秒没有出结果,也认为无效 - testCount = MAX_TESTTIMES;//测试MAX_TESTTIMES后没有结果也要强制退出 - isTimerStarted = true; - getPPGWakeLock(); - if (hrsType == ICJniUtils.PPG_EGC_SensorType.PPG_EGC_TYPE_IC66.ordinal()) { - - boolean ret = mSensorManager.registerListener(this, mHeartRate, SensorManager.SENSOR_DELAY_UI); - ICLogger.i( "Heart Rate PPG_EGC_TYPE_IC66 opened ret :: " + ret); - - } else { - - int ret=ICJniUtils.enablePPG(); - ICLogger.i("Start PPG test ret="+ret); - timerPPG = new ScheduledThreadPoolExecutor(10); - timerPPG.scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - doPPGtest(); - } - }, 0, 1000, TimeUnit.MILLISECONDS); //1 秒更新一次数据 - - } - } - } - - public void stopPPG(){ - if( isTimerStarted ) - { - - int hrsType=ICJniUtils.isPPGavailable(); - if (hrsType == ICJniUtils.PPG_EGC_SensorType.PPG_EGC_TYPE_IC66.ordinal()) { - mSensorManager.unregisterListener(this); - ICLogger.i( "Heart Rate PPG_EGC_TYPE_IC66 closed"); - }else { - timerPPG.shutdownNow(); - timerPPG.purge(); - ICJniUtils.disablePPG(); - } - isTimerStarted=false; - } - - releaseWakeLock(); - } - - private void callback(Messenger paramMessenger, int paramInt) { - if (paramMessenger != null) - try { - paramMessenger.send(Message.obtain(null, paramInt)); - return; - } catch (Exception e) { - e.printStackTrace(); - } - } - - private BroadcastReceiver PPGStartReceiver = new BroadcastReceiver() { - public void onReceive(Context param1Context, Intent param1Intent) { - if (ACTION_HEATR_RATE_START.equals(param1Intent.getAction())) { - - //此消息来源于BroadCaset,收到开始测试的消息。 - //此时需要重置HeartRateDetect Timer - //倘若有 参数 PPGTestCycle,则根据这个数值进行设置 - int ppgtestCycle=param1Intent.getIntExtra("PPGTestCycle",-1); - if (ppgtestCycle >0){ - Config.setPPGTestCycle(runtime.getContextProxy().context,ppgtestCycle); - runtime.setPpgTestCycle(Config.getPPGTestCycle(runtime.getContextProxy().context)); - ICLogger.i("get and set PPGTestCycle "+ppgtestCycle); - } - ICLogger.i("PPGStartReceiver ACTION_HEATR_RATE_START "+ppgtestCycle); - CoreService.getInstance().setHeartRateDetectAlarm(runtime.getPpgTestCycle()); -// HeartRateManager.this.startPPG(); - } - - - } - }; - public void regReceiver(){ - //注册“ACTION_HEATR_RATE_START”的广播接收器,接收来自协议的设置广播 - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(ACTION_HEATR_RATE_START); - runtime.getContextProxy().context.registerReceiver(PPGStartReceiver, intentFilter); - } - - public void unRegReceiver(){ - runtime.getContextProxy().context.unregisterReceiver(PPGStartReceiver); - } - - public void onAlarmClock(Connection paramConnection, Runtime paramRuntime) {} - - public void onAttach(Connection paramConnection, Runtime paramRuntime) { - -// this.mSignalUtil = SimSignalUtil.getInstance((paramRuntime.getContextProxy()).context); - regReceiver(); - } - - public void onDetach(Connection paramConnection, Runtime paramRuntime) { - unRegReceiver(); - } - - public boolean onUserRequest(Intent paramIntent, Connection paramConnection, final Runtime runtime) { -// String str = paramIntent.getAction(); -// if (ACTION_HEATR_RATE_START.equals(str)) { -//// this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context); -//// str = paramIntent.getStringExtra("filepath"); -//// String str1 = paramIntent.getStringExtra("number"); -// StringBuilder stringBuilder = new StringBuilder(); -// stringBuilder.append("PPG Started on Action "+ACTION_HEATR_RATE_START); -//// stringBuilder.append(str); -//// stringBuilder.append("number == "); -//// stringBuilder.append(str1); -// ICLogger.i(stringBuilder.toString()); -// //周期测量执行 -// if (Runtime.practising==true) { -// ICLogger.i("自由锻炼中,跳过原有的循环心率检测!"); -// return false; -// } -// startPPG(); -// } - return false; - } - -public static void triggerPPGtest(){ - if (mHandler !=null) mHandler.sendEmptyMessage(200); -} - - public static void stopPPGtest(){ - if (mHandler !=null) mHandler.sendEmptyMessage(300); - } - - public boolean onUserRequest(Message message, Connection connection, final Runtime runtime) { - - - int i = 1; - switch (message.what) { - case MSG_WHAT_PPG: - - //接收UI测试后的结果,直接发送到服务器。 - Bundle bundle3 = message.getData(); - String ppg = bundle3.getString(key_ppg); - String bph = bundle3.getString(key_bph); - String bpl = bundle3.getString(key_bpl); - String spo2 = bundle3.getString(key_spo2); - - ICLogger.i("get MSG_WHAT_PPG ppg "+ppg + " , bph "+bph + " , bpl "+bpl + " , spo2 "+spo2); - if (ppg == null || bph == null || bpl==null ||ppg.isEmpty()||bph.isEmpty()||bpl.isEmpty()) { - ICLogger.i("MSG_WHAT_PPG Data is null or empty ! Skip!"); - callback(message.replyTo, Constants.RESULT_ERROR); - - return true; - } - if (spo2==null || - (spo2!=null && - ( (!Util.isNumeric(spo2.trim() )) || - (Util.isNumeric(spo2.trim() )&& Integer.parseInt(spo2.trim())<=0) - ) - ) - ) - { - - int randomint = randomOxygenValue(); - spo2=String.valueOf(randomint); - } - - - if(Runtime.practising==true){ - ICLogger.i("自由锻炼中,设置测量心率!"); - Runtime.healthInfo.setPPGECGData(ppg,bph,bpl,spo2); - - //因为心率和定位用时都比温度多,但是定位和心率不一定谁用时多,所以两个都需要检测是否结束 - if(Runtime.healthInfo.check_info_item_finished()){ - Runtime.healthInfo.appendBuffer(Runtime.healthInfo.getHealthInfoString()); - Runtime.healthInfo.reset(); - } - if(Runtime.healthInfo.getInfoCount()>=(30-1)){ - //超过30次发送数据给服务器 - ICLogger.i("发送数据给服务器 "+Runtime.healthInfo.getBufferData().length); - mHandler.post(new Runnable() { - @Override - public void run() { -// ICHttpUtil.uploadData(Runtime.healthInfo.getBufferDataStr(),runtime,TimeUtil.getSystemTime2(),null); - Deliver.sendLocationMSG(protocolAPIHelper.getPRACTICE()); - //发送过后重置 - Runtime.healthInfo.resetBuffer(); - } - }); - - - } - }else { - try { - StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(Integer.parseInt(ppg), Integer.parseInt(bph), Integer.parseInt(bpl), Integer.parseInt(spo2), runtime); - if (PPGDATA == null) { - StringMessage ppgd = protocolAPIHelper.getPPG_MSG(Integer.parseInt(ppg), runtime); - StringMessage bloodd = protocolAPIHelper.getBlood_MSG(Integer.parseInt(bph), Integer.parseInt(bpl), runtime); - StringMessage oxd = protocolAPIHelper.getOxygen_MSG(Integer.parseInt(spo2), runtime); - Deliver.sendLocationMSG(ppgd); - Deliver.sendLocationMSG(bloodd); - Deliver.sendLocationMSG(oxd); - } else { - Deliver.sendLocationMSG(PPGDATA); - ICLogger.i("Send PPG " + PPGDATA.isFromCache()); - } - }catch (Exception e){ - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - } - } - callback(message.replyTo, Constants.RESULT_OK); - - default: - break; - } - - return true; - } - - @Override - public void onSensorChanged(SensorEvent sensorEvent) { - float values[]=sensorEvent.values; - int length = values.length; - ICLogger.i( "onSensorChanged() is called "+length - +" PPG = "+values[0] - +", BPH = "+values[1] - +", BPL = "+values[2] - +", spo2 = "+values[3] - +" , Weared = "+values[4] - ); - PPG = (int)values[0];//调用底层函数保证状态更新。 - BPH = (int)values[1]; - BPL = (int)values[2]; - SPo2 = (int)values[3]; - isWared = ((int)values[4] == 2); - isPPGTesting = true;// (ICJniUtils.isPPGStarted() == 1); - doPPGtest(); - /*[0]---心率;[1]---血压高压;[2]---血压低压;[3]---血氧;[4]---佩戴检测(1--脱手,2--上手);*/ - } - - @Override - public void onAccuracyChanged(Sensor sensor, int i) { - ICLogger.i("onAccuracyChanged() is called "+sensor.getName()+" accuracy="+i); - } -} - +package com.enqualcomm.support.service; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.Messenger; +import android.os.PowerManager; +import android.util.Log; + +import com.enqualcomm.support.Config; +import com.enqualcomm.support.Constants; +import com.enqualcomm.support.CoreService; +import com.enqualcomm.support.LocationClient; +import com.enqualcomm.support.bean.StringMessage; +import com.enqualcomm.support.utils.ICHttpUtil; +import com.enqualcomm.support.utils.Util; +import com.ic.jni.ICJniUtils; +import com.ic.protocols.protocolAPIHelper; +import com.enqualcomm.support.bean.Runtime; +import com.enqualcomm.support.bean.heartRateStatus; +import com.enqualcomm.support.service.base.AbstractInvokeHandlerService; +import com.enqualcomm.support.utils.Connection; +import com.enqualcomm.support.utils.ICLogger; +import com.enqualcomm.support.utils.NettyConnection; +import com.enqualcomm.support.utils.SimSignalUtil; +import com.enqualcomm.support.utils.TimeUtil; + +import java.util.Random; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import static android.content.Context.SENSOR_SERVICE; +import static com.enqualcomm.support.Constants.ACTION_BROADCAST_PPG; +import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; +import static com.enqualcomm.support.Constants.MSG_WHAT_PPG; +import static com.enqualcomm.support.Constants.key_bph; +import static com.enqualcomm.support.Constants.key_bpl; +import static com.enqualcomm.support.Constants.key_ppg; +import static com.enqualcomm.support.Constants.key_spo2; + +public class HeartRateManager extends AbstractInvokeHandlerService implements SensorEventListener { + private int mNetworkType; + + private SimSignalUtil mSignalUtil; + + private Runtime runtime; + private Connection connection; + + private ScheduledThreadPoolExecutor timerPPG=null; + private static Handler mHandler=null; + + private void checkWarning(){ + //ppg + if(runtime.getHRS().ppg_threshold_max>0 && runtime.getHRS().getPPG() >runtime.getHRS().ppg_threshold_max){ + + if(runtime.setAlarmType(Runtime.AlarmType.ALARM_HEART_RATE_HIGH)) { + //trigger AP10 报警定位 +// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); + } + + }else if ( runtime.getHRS().ppg_threshold_min>0 && runtime.getHRS().getPPG()0 && runtime.getHRS().getBPH() >runtime.getHRS().bph_threshold_max){ + + if(runtime.setAlarmType(Runtime.AlarmType.ALARM_BPH_HIGH)) { + //trigger AP10 报警定位 + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); +// 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){ + + if(runtime.setAlarmType(Runtime.AlarmType.ALARM_BPL_HIGH)) { + //trigger AP10 报警定位 + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); +// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + } + + }else if ( runtime.getHRS().bpl_threshold_min>0 && runtime.getHRS().getBPL()=(30-1)){ + //超过30次发送数据给服务器 + ICLogger.i("自由锻炼中,发送数据给服务器 "+Runtime.healthInfo.getBufferData().length); + mHandler.post(new Runnable() { + @Override + public void run() { +// ICHttpUtil.uploadData(Runtime.healthInfo.getBufferDataStr(),runtime,TimeUtil.getSystemTime2(),null); + Deliver.sendLocationMSG(protocolAPIHelper.getPRACTICE()); + //发送过后重置 + Runtime.healthInfo.resetBuffer(); + } + }); + } + }else { + StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(runtime); + //发送给EQC服务器的 + sendBroadcastPPGResult(); + //因为协议中没有时间变量,所以只能实时传输,如果恰巧没有网络也只能丢弃,有时间变量的话,可以考虑通过deliver的buffer来进行缓存发送 + if (PPGDATA == null) { + StringMessage ppgd = protocolAPIHelper.getPPG_MSG(runtime.getHRS().getPPG(), runtime); + StringMessage bloodd = protocolAPIHelper.getBlood_MSG(runtime.getHRS().getBPH(), runtime.getHRS().getBPL(), runtime); + StringMessage oxd = protocolAPIHelper.getOxygen_MSG(runtime.getHRS().getSpo2(), runtime); + Deliver.sendLocationMSG(ppgd); + Deliver.sendLocationMSG(bloodd); + Deliver.sendLocationMSG(oxd); + + checkWarning(); + + } else { + Deliver.sendLocationMSG(PPGDATA); + ICLogger.i("Send PPG " + PPGDATA.isFromCache()); + checkWarning(); + } + } + + } else { + ICLogger.i("PPG Failed for Timeout!"); + } + stopPPG(); + } + break; + case 200: { + startPPG(); + } + break; + case 300: { + stopPPG(); + } + break; + } + return false; + } + }); + + } + + + private void sendBroadcastPPGResult(){ + Intent intent=new Intent(ACTION_BROADCAST_PPG); + intent.putExtra("ppg",runtime.getHRS().getPPG()); + intent.putExtra("bph",runtime.getHRS().getBPH()); + intent.putExtra("bpl",runtime.getHRS().getBPL()); + intent.putExtra("spo2",runtime.getHRS().getSpo2()); + intent.putExtra("time",runtime.getHRS().getTestTime()); + runtime.getContextProxy().context.sendBroadcast(intent); + } + + private SensorManager mSensorManager; + private Sensor mHeartRate; + int PPG; + int BPH; + int BPL; + int SPo2; + boolean isWared ; + boolean isPPGTesting ; + static boolean isTimerStarted; + public static heartRateStatus.HEARTRATE_WORKINGSTAT currentStat; + static int delayCount; + static int testCount; + static int notWaredCount; + static int noPPGCount; + private final int MAX_TESTTIMES=30000;//最大延迟测试时间为30秒 + + public int randomOxygenValue() { + int min = 95; + int max = 99; + int ret=min + ((int) (new Random().nextFloat() * (max - min))); + return ret; + } + + public void doPPGtest(){ + + int hrsType=ICJniUtils.isPPGavailable(); + if (hrsType>0 && hrsType != ICJniUtils.PPG_EGC_SensorType.PPG_EGC_TYPE_IC66.ordinal()) { + PPG = ICJniUtils.getPPG();//调用底层函数保证状态更新。 + BPH = ICJniUtils.getHighBloodPressure(); + BPL = ICJniUtils.getLowBloodPressure(); + SPo2 = ICJniUtils.getSPO2(); + if(SPo2==0){ + SPo2=randomOxygenValue(); + } + isWared = (ICJniUtils.isWeared() == 1); + isPPGTesting = (ICJniUtils.isPPGStarted() == 1); + }else{ + isPPGTesting=true; + } + ICLogger.i("PPG TESTING="+isPPGTesting+", isWared="+isWared+", PPG="+PPG+", BPH="+BPH+", BPL="+BPL+", SPo2="+SPo2); + if (isPPGTesting){ + if (isWared ) { + if (PPG > 0) { + currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS; + } else { + currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_WARED_AND_TESTING; + } + }else{ + currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_NOTWARED; + } + }else{ + currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_CLOSED; + } + + + if (currentStat== heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_NOTWARED){ + notWaredCount--; + if( notWaredCount <0){ //没有佩戴次数到限制后,停止检测 + ICLogger.i("HEARTRATE_NOTWARED 超过时限,取消检测报告!"); + stopPPG(); + } + }else if (currentStat== heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_WARED_AND_TESTING){ + noPPGCount--; + if( noPPGCount <0){ //没有佩戴次数到限制后,停止检测 + ICLogger.i("HEARTRATE WARED And Testing (Wared=1 PPG=0)超过时限,取消检测报告!"); + stopPPG(); + } + } + + + if (currentStat==heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS){ + runtime.getHRS().setLastHeartrate(PPG,BPH,BPL,SPo2); + delayCount--; + if (delayCount<0) //达到延迟时间后,停止检测并发送数据 + sendAndStopPPG(); + + }else{ + runtime.getHRS().setLastHeartrate(0,0,0,0); + } + runtime.getHRS().setHeartrateStat(currentStat); + + + + + testCount--; + if (testCount<0) + { + ICLogger.i("PPG 超过 "+MAX_TESTTIMES+"秒 未能得出结果,取消检测报告!"); + stopPPG(); + } + + } + + private void sendAndStopPPG(){ + //结束和发送数据 + mHandler.sendEmptyMessage(100); + } + PowerManager.WakeLock mWakeLock=null; + public PowerManager.WakeLock getPPGWakeLock() { + mWakeLock = ((PowerManager)(runtime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, HeartRateManager.class.getSimpleName()); + mWakeLock.acquire(30000L); + return mWakeLock; + } + + public void releaseWakeLock(){ + if (mWakeLock!=null && mWakeLock.isHeld()){ + mWakeLock.release(); + } + mWakeLock=null; + } + public void startPPG(){ + + int hrsType=ICJniUtils.isPPGavailable(); + if ( hrsType > 0 && (isTimerStarted == false) ) { + currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_OPEN; + delayCount = 4;//检测成功后4秒发送数据 + notWaredCount = 5; //初始化没有佩戴的检测次数5,连续5秒没有佩戴则取消检测 + noPPGCount = 30;//即使佩戴了,但是30秒没有出结果,也认为无效 + testCount = MAX_TESTTIMES;//测试MAX_TESTTIMES后没有结果也要强制退出 + isTimerStarted = true; + getPPGWakeLock(); + if (hrsType == ICJniUtils.PPG_EGC_SensorType.PPG_EGC_TYPE_IC66.ordinal()) { + + boolean ret = mSensorManager.registerListener(this, mHeartRate, SensorManager.SENSOR_DELAY_UI); + ICLogger.i( "Heart Rate PPG_EGC_TYPE_IC66 opened ret :: " + ret); + + } else { + + int ret=ICJniUtils.enablePPG(); + ICLogger.i("Start PPG test ret="+ret); + timerPPG = new ScheduledThreadPoolExecutor(10); + timerPPG.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + doPPGtest(); + } + }, 0, 1000, TimeUnit.MILLISECONDS); //1 秒更新一次数据 + + } + } + } + + public void stopPPG(){ + if( isTimerStarted ) + { + + int hrsType=ICJniUtils.isPPGavailable(); + if (hrsType == ICJniUtils.PPG_EGC_SensorType.PPG_EGC_TYPE_IC66.ordinal()) { + mSensorManager.unregisterListener(this); + ICLogger.i( "Heart Rate PPG_EGC_TYPE_IC66 closed"); + }else { + timerPPG.shutdownNow(); + timerPPG.purge(); + ICJniUtils.disablePPG(); + } + isTimerStarted=false; + } + + releaseWakeLock(); + } + + private void callback(Messenger paramMessenger, int paramInt) { + if (paramMessenger != null) + try { + paramMessenger.send(Message.obtain(null, paramInt)); + return; + } catch (Exception e) { + e.printStackTrace(); + } + } + + private BroadcastReceiver PPGStartReceiver = new BroadcastReceiver() { + public void onReceive(Context param1Context, Intent param1Intent) { + if (ACTION_HEATR_RATE_START.equals(param1Intent.getAction())) { + + //此消息来源于BroadCaset,收到开始测试的消息。 + //此时需要重置HeartRateDetect Timer + //倘若有 参数 PPGTestCycle,则根据这个数值进行设置 + int ppgtestCycle=param1Intent.getIntExtra("PPGTestCycle",-1); + if (ppgtestCycle >0){ + Config.setPPGTestCycle(runtime.getContextProxy().context,ppgtestCycle); + runtime.setPpgTestCycle(Config.getPPGTestCycle(runtime.getContextProxy().context)); + ICLogger.i("get and set PPGTestCycle "+ppgtestCycle); + } + ICLogger.i("PPGStartReceiver ACTION_HEATR_RATE_START "+ppgtestCycle); + CoreService.getInstance().setHeartRateDetectAlarm(runtime.getPpgTestCycle()); +// HeartRateManager.this.startPPG(); + } + + + } + }; + public void regReceiver(){ + //注册“ACTION_HEATR_RATE_START”的广播接收器,接收来自协议的设置广播 + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(ACTION_HEATR_RATE_START); + runtime.getContextProxy().context.registerReceiver(PPGStartReceiver, intentFilter); + } + + public void unRegReceiver(){ + runtime.getContextProxy().context.unregisterReceiver(PPGStartReceiver); + } + + public void onAlarmClock(Connection paramConnection, Runtime paramRuntime) {} + + public void onAttach(Connection paramConnection, Runtime paramRuntime) { + +// this.mSignalUtil = SimSignalUtil.getInstance((paramRuntime.getContextProxy()).context); + regReceiver(); + } + + public void onDetach(Connection paramConnection, Runtime paramRuntime) { + unRegReceiver(); + } + + public boolean onUserRequest(Intent paramIntent, Connection paramConnection, final Runtime runtime) { +// String str = paramIntent.getAction(); +// if (ACTION_HEATR_RATE_START.equals(str)) { +//// this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context); +//// str = paramIntent.getStringExtra("filepath"); +//// String str1 = paramIntent.getStringExtra("number"); +// StringBuilder stringBuilder = new StringBuilder(); +// stringBuilder.append("PPG Started on Action "+ACTION_HEATR_RATE_START); +//// stringBuilder.append(str); +//// stringBuilder.append("number == "); +//// stringBuilder.append(str1); +// ICLogger.i(stringBuilder.toString()); +// //周期测量执行 +// if (Runtime.practising==true) { +// ICLogger.i("自由锻炼中,跳过原有的循环心率检测!"); +// return false; +// } +// startPPG(); +// } + return false; + } + +public static void triggerPPGtest(){ + if(CoreService.getInstance()!=null) + { + if (CoreService.getInstance().getRuntime().Anti_off_flag==1) { + ICLogger.i("未佩戴,取消 triggerPPGtest!"); + return; + } + } + if (mHandler !=null) mHandler.sendEmptyMessage(200); +} + + public static void stopPPGtest(){ + if (mHandler !=null) mHandler.sendEmptyMessage(300); + } + + public boolean onUserRequest(Message message, Connection connection, final Runtime runtime) { + + + int i = 1; + switch (message.what) { + case MSG_WHAT_PPG: + + //接收UI测试后的结果,直接发送到服务器。 + Bundle bundle3 = message.getData(); + String ppg = bundle3.getString(key_ppg); + String bph = bundle3.getString(key_bph); + String bpl = bundle3.getString(key_bpl); + String spo2 = bundle3.getString(key_spo2); + + ICLogger.i("get MSG_WHAT_PPG ppg "+ppg + " , bph "+bph + " , bpl "+bpl + " , spo2 "+spo2); + if (ppg == null || bph == null || bpl==null ||ppg.isEmpty()||bph.isEmpty()||bpl.isEmpty()) { + ICLogger.i("MSG_WHAT_PPG Data is null or empty ! Skip!"); + callback(message.replyTo, Constants.RESULT_ERROR); + + return true; + } + if (spo2==null || + (spo2!=null && + ( (!Util.isNumeric(spo2.trim() )) || + (Util.isNumeric(spo2.trim() )&& Integer.parseInt(spo2.trim())<=0) + ) + ) + ) + { + + int randomint = randomOxygenValue(); + spo2=String.valueOf(randomint); + } + + + if(Runtime.practising==true){ + ICLogger.i("自由锻炼中,设置测量心率!"); + Runtime.healthInfo.setPPGECGData(ppg,bph,bpl,spo2); + + //因为心率和定位用时都比温度多,但是定位和心率不一定谁用时多,所以两个都需要检测是否结束 + if(Runtime.healthInfo.check_info_item_finished()){ + Runtime.healthInfo.appendBuffer(Runtime.healthInfo.getHealthInfoString()); + Runtime.healthInfo.reset(); + } + if(Runtime.healthInfo.getInfoCount()>=(30-1)){ + //超过30次发送数据给服务器 + ICLogger.i("发送数据给服务器 "+Runtime.healthInfo.getBufferData().length); + mHandler.post(new Runnable() { + @Override + public void run() { +// ICHttpUtil.uploadData(Runtime.healthInfo.getBufferDataStr(),runtime,TimeUtil.getSystemTime2(),null); + Deliver.sendLocationMSG(protocolAPIHelper.getPRACTICE()); + //发送过后重置 + Runtime.healthInfo.resetBuffer(); + } + }); + + + } + }else { + try { + StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(Integer.parseInt(ppg), Integer.parseInt(bph), Integer.parseInt(bpl), Integer.parseInt(spo2), runtime); + if (PPGDATA == null) { + StringMessage ppgd = protocolAPIHelper.getPPG_MSG(Integer.parseInt(ppg), runtime); + StringMessage bloodd = protocolAPIHelper.getBlood_MSG(Integer.parseInt(bph), Integer.parseInt(bpl), runtime); + StringMessage oxd = protocolAPIHelper.getOxygen_MSG(Integer.parseInt(spo2), runtime); + Deliver.sendLocationMSG(ppgd); + Deliver.sendLocationMSG(bloodd); + Deliver.sendLocationMSG(oxd); + } else { + Deliver.sendLocationMSG(PPGDATA); + ICLogger.i("Send PPG " + PPGDATA.isFromCache()); + } + }catch (Exception e){ + e.printStackTrace(); + ICLogger.e(e.getMessage(),e); + } + } + callback(message.replyTo, Constants.RESULT_OK); + + default: + break; + } + + return true; + } + + @Override + public void onSensorChanged(SensorEvent sensorEvent) { + float values[]=sensorEvent.values; + int length = values.length; + ICLogger.i( "onSensorChanged() is called "+length + +" PPG = "+values[0] + +", BPH = "+values[1] + +", BPL = "+values[2] + +", spo2 = "+values[3] + +" , Weared = "+values[4] + ); + PPG = (int)values[0];//调用底层函数保证状态更新。 + BPH = (int)values[1]; + BPL = (int)values[2]; + SPo2 = (int)values[3]; + isWared = ((int)values[4] == 2); + isPPGTesting = true;// (ICJniUtils.isPPGStarted() == 1); + doPPGtest(); + /*[0]---心率;[1]---血压高压;[2]---血压低压;[3]---血氧;[4]---佩戴检测(1--脱手,2--上手);*/ + } + + @Override + public void onAccuracyChanged(Sensor sensor, int i) { + ICLogger.i("onAccuracyChanged() is called "+sensor.getName()+" accuracy="+i); + } +} + diff --git a/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java b/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java index 23842fe0..9c7432a6 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java @@ -77,6 +77,14 @@ public class TemperatureUtil { CoreService.getInstance().sendBroadcast(pedIntent); } public static void DoTempTest(){ + + if(CoreService.getInstance()!=null) + { + if (CoreService.getInstance().getRuntime().Anti_off_flag==1) { + ICLogger.i("未佩戴,取消TempTest!"); + return; + } + } if (ICJniUtils.isTemperatureDevAvailable() >ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) { ICJniUtils.enableTemperature(); diff --git a/app/version_code.properties b/app/version_code.properties index 85f27af7..49cb6a7c 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Wed Nov 25 17:09:17 CST 2020 -VERSION_CODE=715 +#Sun Nov 29 00:53:27 CST 2020 +VERSION_CODE=717