From: snickersun Date: Thu, 17 Sep 2020 09:26:26 +0000 (+0800) Subject: release V618 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=19c9efc04b31a571a2dca7aebb59e121ad6bf0f9;p=protocol_srv.git release V618 protocol_fzd 添加自定义协议PRACTICE 是H88A 项目的 自由锻炼 需求,开始锻炼后1分钟记录一次步数,心率,血压,血氧,体温,30分钟上传一次 PRACTICE --- diff --git a/app/app.iml b/app/app.iml index df83372d..e442bebb 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,4 +1,4 @@ - + @@ -18,8 +18,8 @@ @@ -101,15 +101,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/app/release/ICSer_V616_2009151746_release.apk b/app/release/ICSer_V618_2009171715_release.apk similarity index 78% rename from app/release/ICSer_V616_2009151746_release.apk rename to app/release/ICSer_V618_2009171715_release.apk index 711bc170..57404bc5 100644 Binary files a/app/release/ICSer_V616_2009151746_release.apk and b/app/release/ICSer_V618_2009171715_release.apk differ diff --git a/app/release/output.json b/app/release/output.json index a07cd8e2..1a4c58af 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":617,"versionName":"2009160733","enabled":true,"outputFile":"ICSer_V617_2009160733_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V617_2009160733_release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":618,"versionName":"2009171715","enabled":true,"outputFile":"ICSer_V618_2009171715_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V618_2009171715_release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 549c3107..b716572b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -122,6 +122,7 @@ + diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 4d6968e6..6633aa3a 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -105,7 +105,9 @@ public class Config { final static String KeyContactsList="ContactsList"; final static String KeySOSNumbersList="SOSNumbersList"; - final static String KeyIMEI="IMEI"; + + final static String KeyIMEI = "persist.sys.protocol_IMEI"; + final static String KeyPractiseState = "persist.sys.practising"; final static String KeyHeartBeatCycle="ServerHeartBeatCycle"; @@ -234,13 +236,11 @@ public class Config { } public static void setIMEI(Context context, String imei){ -// SharPreferenceUtil.setPrefString(context,KeyIMEI,imei); - SharPreferenceUtil.setPrefStringPublic(context,KeyIMEI,imei); + Util.setSystemProperties(KeyIMEI,imei); } public static String getIMEI(Context context){ -// return SharPreferenceUtil.getPrefString(context,KeyIMEI,""); - return SharPreferenceUtil.getPrefStringPublic(context,KeyIMEI,""); + return Util.getSystemProperties(KeyIMEI,""); } public static String getProtocolServerHost(Context context){ diff --git a/app/src/main/java/com/enqualcomm/support/Constants.java b/app/src/main/java/com/enqualcomm/support/Constants.java index 72efe0f9..eed0c6c7 100644 --- a/app/src/main/java/com/enqualcomm/support/Constants.java +++ b/app/src/main/java/com/enqualcomm/support/Constants.java @@ -107,7 +107,12 @@ public interface Constants { public static final String ACTION_WAKEUP_ALARM = "com.eqc.deliverWakeupAlarm.action"; public static final String ACTION_YUN_ALARM_CHANGE = "com.eqc.deskclock.YUN_ALARM_CHANGE"; - + + public static final String ACTION_PRACTICE_REPORT_ALARM = "com.enqualcomm.support.PRACTICE_ALARM"; + + public final static String ACTION_START_PRACTISE = "com.ic.action_start_practice"; + public final static String KeyPractice = "cmd"; + public static final int ALARM_UPDATE_NOTICE = 206; public static final int CALL_RECORD_CHANGED = 103; diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 6789d04d..c87a0318 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -4,6 +4,7 @@ import android.app.AlarmManager; import android.app.Notification; import android.app.PendingIntent; import android.app.Service; +import android.content.IClipboard; import android.content.Intent; import android.media.AudioManager; import android.os.Handler; @@ -23,6 +24,7 @@ import com.enqualcomm.support.service.AntiMonitorService; import com.enqualcomm.support.utils.CellInfoUtil; import com.enqualcomm.support.utils.Connection; import com.enqualcomm.support.utils.DeviceInfoUtil; +import com.enqualcomm.support.utils.ICHttpUtil; import com.enqualcomm.support.utils.LedUtil; import com.enqualcomm.support.utils.StorageUtils; import com.enqualcomm.support.utils.TemperatureUtil; @@ -77,6 +79,7 @@ import static com.enqualcomm.support.Constants.ACTION_EQC_ALARM; import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; import static com.enqualcomm.support.Constants.ACTION_LOCAL_SOS_ACTION; import static com.enqualcomm.support.Constants.ACTION_LOCATION_ALARM; +import static com.enqualcomm.support.Constants.ACTION_PRACTICE_REPORT_ALARM; import static com.enqualcomm.support.Constants.ACTION_SEND_EMEGENCY_LOCATION_START; import static com.enqualcomm.support.Constants.ACTION_SEND_EMEGENCY_LOCATION_STOP; import static com.enqualcomm.support.Constants.ANTI_ALARM; @@ -240,6 +243,49 @@ public class CoreService extends Service { e.printStackTrace(); } } + + private BroadcastReceiver broadcastPracticeCMDReceiver = new BroadcastReceiver() { + public void onReceive(Context param1Context, Intent param1Intent) { + if(param1Intent.getAction().equals(Constants.ACTION_START_PRACTISE)) + { + int cmd=param1Intent.getIntExtra(Constants.KeyPractice,0); + if (cmd==1){ + //开始自由锻炼 + Runtime.practising=true; + Util.setSystemProperties( Config.KeyPractiseState,"true"); + Runtime.healthInfo.reset(); + Runtime.healthInfo.resetBuffer(); + setPracticeAlarm(); + + }else{ + //停止自由锻炼,恢复正常 + Runtime.practising=false; + Util.setSystemProperties( Config.KeyPractiseState,"false"); + HeartRateManager.stopPPGtest(); + + //最后检测是否还有数据需要发送 + if(Runtime.healthInfo.check_info_item_finished()){ + Runtime.healthInfo.appendBuffer(Runtime.healthInfo.getHealthInfoString()); + Runtime.healthInfo.reset(); + } + if(Runtime.healthInfo.getInfoCount()>=0){ + //超过30次发送数据给服务器 + ICLogger.i("自由锻炼结束,发送数据给服务器 "+Runtime.healthInfo.getBufferData().length); + new Handler().post(new Runnable() { + @Override + public void run() { + //ICHttpUtil.uploadData(Runtime.healthInfo.getBufferDataStr(),runtime,TimeUtil.getSystemTime2(),null); + Deliver.sendLocationMSG(protocolAPIHelper.getPRACTICE()); + //发送过后重置 + Runtime.healthInfo.resetBuffer(); + } + }); + } + + } + } + } + }; private static class ServerHandler implements ConnectionListener { private final WeakReference mReference; @@ -355,6 +401,7 @@ public class CoreService extends Service { } }; + private int startAlarmCount = 0; UpLoadDataPoints upLoadDataPoints; @@ -449,6 +496,34 @@ public class CoreService extends Service { // AlarmHelper.setTimeAlarm(this, 6, (new Random()).nextInt(40) + 20, WEATHER_ALARM); } + + private void setPracticeAlarm() { + + ICLogger.i("setPracticeAlarm "+Runtime.practice_cycle+ " seconds!"); + //只有周期大于1才有效,否则就等于单次测量 + if (Runtime.practice_cycle>1) + AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context,Runtime.practice_cycle,Constants.ACTION_PRACTICE_REPORT_ALARM); + + new Thread(new Runnable() { + @Override + public void run() { + //获取并设置当前步数 + ICLogger.i("自由锻炼中,设置步数 "+runtime.getTotalStepCount()); + Runtime.healthInfo.setStepCount(runtime.getTotalStepCount()); + //开启定位 + // locationClient.triggerLocationProcess(); + //开启测温 + TemperatureUtil.DoTempTest(); + + //开启测量PPG + HeartRateManager.triggerPPGtest(); + + + } + }).start(); + + + } private void checkconnection(){ if (!this.connection.isServerConnected()) @@ -664,6 +739,10 @@ public class CoreService extends Service { intentFilter.addAction(ACTION_LOCAL_SOS_ACTION); registerReceiver(broadcastSOSReceiver,intentFilter); + //添加自由锻炼 接收 + intentFilter = new IntentFilter(); + intentFilter.addAction(Constants.ACTION_START_PRACTISE); + registerReceiver(broadcastPracticeCMDReceiver,intentFilter); //初始化Sim信号 this.mSignalUtil = SimSignalUtil.getInstance(this); @@ -693,6 +772,7 @@ public class CoreService extends Service { batteryUtil.registerBroadReceiver(); + //设置计步清零时间。 setCleanStepCountAlarm(); @@ -918,6 +998,12 @@ public class CoreService extends Service { if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", stringBuilder1.toString()); // this.locationClient.triggerLocationProcess(); + }else if (Constants.ACTION_PRACTICE_REPORT_ALARM.equals(paramIntent.getAction())) { + //alarm是延迟的,所以这个判断主要是给最后一次可能无效的测量 + if (Runtime.practising==true) { + //开始下一轮健康测量 + setPracticeAlarm(); + } }else if (Constants.ACTION_CHECK_SERVER_RESPONSE.equals(paramIntent.getAction())) { //暂时还使用 ScheduledThreadPoolExecutor , 时间要求不是那么的严格 }else if (Constants.ACTION_RETRY_SERVER_CONNECT.equals(paramIntent.getAction())) { @@ -971,7 +1057,12 @@ public class CoreService extends Service { if (this.mKeepAlive != null) { if (connection.isServerConnected() && runtime.isServerProtocolConnected()) { //测试温度并上报 - TemperatureUtil.doTempTestInThread(); + + if (Runtime.practising==true) { + ICLogger.i("自由锻炼中,跳过原有的循环温度检测!"); + }else { + TemperatureUtil.doTempTestInThread(); + } // double wrist_temp=TemperatureUtil.get_temp_value_adjusted(); // double body_temp=TemperatureUtil.getBodyTemp(wrist_temp,26.0f); // String temperatureMsg=getTemperatureMSG(wrist_temp,body_temp); @@ -1099,6 +1190,11 @@ public class CoreService extends Service { sb.append(" setLocationAlarm "+ACTION_LOCATION_ALARM+" mod "+mod+", cycle in Seconds "+cycle); ICLogger.i(sb.toString()); if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(),"alarmCycle",sb.toString()); + +// if (Runtime.practising==true) { +// ICLogger.i("自由锻炼中,跳过原有的循环定位!"); +// return; +// } locationClient.triggerLocationProcess(); } diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index 16a6cdcf..27a9c7bf 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -147,7 +147,7 @@ public class LocationClient { if ( runtime.bleInfo.last_is_in_area==true) { //只有上一次在区域内,这次出区域才需要报警 StringMessage AL_CMD = protocolAPIHelper.getWarningMSG(runtime); - Deliver.sendLocationMSG(AL_CMD); + DeliverMessage(AL_CMD); } } }else { @@ -158,7 +158,7 @@ public class LocationClient { ICLogger.i("BT 在区域内,直接发送区域坐标即可!"); runtime.updateFZDDevStatusEscape(false); StringMessage AP01_CMD = protocolAPIHelper.getGPSLocationMSG(runtime); - Deliver.sendLocationMSG(AP01_CMD); + DeliverMessage(AP01_CMD); } } @@ -427,16 +427,16 @@ public class LocationClient { ){ if (startSOSLocation==true){ StringMessage AP10_CMD = protocolAPIHelper.getWarningMSG(runtime); - Deliver.sendLocationMSG(AP10_CMD); + DeliverMessage(AP10_CMD); startSOSLocation=false; }else { if (gps_ok) { StringMessage AP01_CMD = protocolAPIHelper.getGPSLocationMSG(runtime); - Deliver.sendLocationMSG(AP01_CMD); + DeliverMessage(AP01_CMD); }else{ StringMessage AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime); - Deliver.sendLocationMSG(AP02_CMD); + DeliverMessage(AP02_CMD); } } @@ -501,12 +501,12 @@ public class LocationClient { if (startSOSLocation==true){ StringMessage AP10_CMD = protocolAPIHelper.getWarningMSG(runtime); - Deliver.sendLocationMSG(AP10_CMD); + DeliverMessage(AP10_CMD); startSOSLocation=false; }else { StringMessage AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime); - Deliver.sendLocationMSG(AP02_CMD); + DeliverMessage(AP02_CMD); } stopCheckLocationResult(); @@ -542,6 +542,30 @@ public class LocationClient { } } + private void DeliverMessage(StringMessage msg){ + +// if(Runtime.practising==true){ +// if(msg==null){ +// ICLogger.i("msg is null skip!"); +// } +// ICLogger.i("自由锻炼中,定位缓存再发送!"); +// Runtime.healthInfo.setLocationData(msg.isFromCache()); +// +// //因为心率和定位用时都比温度多,但是定位和心率不一定谁用时多,所以两个都需要检测是否结束 +// 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); +// //发送过后重置 +// Runtime.healthInfo.resetBuffer(); +// } +// }else { + Deliver.sendLocationMSG(msg); +// } + } public void stopCheckLocationResult(){ ICLogger.i("stopCheckLocationResult!"); // if (mTimer!=null){ diff --git a/app/src/main/java/com/enqualcomm/support/MainActivity.java b/app/src/main/java/com/enqualcomm/support/MainActivity.java index 69d1ce1a..a20bb6ee 100644 --- a/app/src/main/java/com/enqualcomm/support/MainActivity.java +++ b/app/src/main/java/com/enqualcomm/support/MainActivity.java @@ -259,15 +259,15 @@ public class MainActivity extends Activity { }; - public void tesetSharedKey(){ - Config.setSleepScore(this,344); - Config.setSleepDate(this,TimeUtil.getSystemTime3()); - Config.setKeepSitRangeInMinutes(this,3); - ICLogger.d("SHAREKEY_SETTING_SLEEP_SCORE_DATE "+ SharPreferenceUtil.getPrefStringPublic(this,Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE,"")); - ICLogger.d("SHAREKEY_SETTING_SLEEP_SCORE "+ SharPreferenceUtil.getPrefIntPublic(this,Constants.SHAREKEY_SETTING_SLEEP_SCORE,0)); - ICLogger.d("SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES "+ SharPreferenceUtil.getPrefIntPublic(this,Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES,0)); - - } +// public void tesetSharedKey(){ +// Config.setSleepScore(this,344); +// Config.setSleepDate(this,TimeUtil.getSystemTime3()); +// Config.setKeepSitRangeInMinutes(this,3); +// ICLogger.d("SHAREKEY_SETTING_SLEEP_SCORE_DATE "+ SharPreferenceUtil.getPrefStringPublic(this,Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE,"")); +// ICLogger.d("SHAREKEY_SETTING_SLEEP_SCORE "+ SharPreferenceUtil.getPrefIntPublic(this,Constants.SHAREKEY_SETTING_SLEEP_SCORE,0)); +// ICLogger.d("SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES "+ SharPreferenceUtil.getPrefIntPublic(this,Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES,0)); +// +// } diff --git a/app/src/main/java/com/enqualcomm/support/bean/HealthInfo.java b/app/src/main/java/com/enqualcomm/support/bean/HealthInfo.java new file mode 100644 index 00000000..da2fad0b --- /dev/null +++ b/app/src/main/java/com/enqualcomm/support/bean/HealthInfo.java @@ -0,0 +1,85 @@ +package com.enqualcomm.support.bean; + +import com.enqualcomm.support.utils.TimeUtil; + +public class HealthInfo { + private String LocationState=""; + private String PPG_ECG_State=""; + private String Temperature_State=""; + private String StepCount_Stat=""; + private StringBuffer infoBuffer=new StringBuffer(); + private int infoCount=0; + public void reset(){ + StepCount_Stat=LocationState=PPG_ECG_State=Temperature_State=""; + } + public void resetBuffer(){ + infoBuffer.delete(0,infoBuffer.length()); + infoCount=0; + } + public int getInfoCount(){ + return infoCount; + } + public void setLocationData(String location){ + LocationState=location; + } + + public void setPPGECGData(String ppg,String bph,String bpl, String spo2){ +// PPG_ECG_State="ppg="+ppg+",bph="+bph+",bpl="+bpl+",spo2="+spo2; + PPG_ECG_State=ppg+","+bph+","+bpl+","+spo2; + } + public void setPPGECGData(int ppg,int bph,int bpl, int spo2){ +// PPG_ECG_State="ppg="+ppg+",bph="+bph+",bpl="+bpl+",spo2="+spo2; + PPG_ECG_State=ppg+","+bph+","+bpl+","+spo2; + } + public void setTemperatureData(double temp){ +// Temperature_State="temp="+String.format("%.1f",temp); + Temperature_State=String.format("%.1f",temp); + } + + public void setStepCount(int stepcount){ +// StepCount_Stat="stepcount="+stepcount; + StepCount_Stat=String.valueOf(stepcount); + } + + public boolean check_info_item_finished(){ +// if (!LocationState.trim().isEmpty() && !PPG_ECG_State.trim().isEmpty() && !Temperature_State.trim().isEmpty()|!StepCount_Stat.trim().isEmpty()) + if ( !PPG_ECG_State.trim().isEmpty() && !Temperature_State.trim().isEmpty()|!StepCount_Stat.trim().isEmpty()) + { + return true; + }else + return false; + } + + public void appendBuffer(String data){ + if(infoCount>0){ + //第二个起,要添加分隔符 | + infoBuffer.append("|").append(data); + }else { + //第一个直接添加到后面 + infoBuffer.append(data); + } + infoCount++; + } + + public String getBufferDataStr(){ + return new StringBuilder().append(infoCount).append(",").append(infoBuffer.toString()).toString(); +// return infoBuffer.toString(); + } + public byte[] getBufferData(){ + return new StringBuilder().append(infoCount).append(",").append(infoBuffer.toString()).toString().getBytes(); +// return infoBuffer.toString().getBytes(); + } + public String getHealthInfoString(){ + if (check_info_item_finished()==true){ + return new StringBuilder() + .append("").append(TimeUtil.getSystemTime3()).append(",") +// .append(LocationState.trim()).append(";") + .append(PPG_ECG_State.trim()).append(",") + .append(Temperature_State.trim()).append(",") + .append(StepCount_Stat.trim()) + .toString(); + }else{ + return ""; + } + } +} 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 1015ce3b..f9847fae 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -2,6 +2,7 @@ package com.enqualcomm.support.bean; import android.content.Context; +import android.support.constraint.solver.widgets.Helper; import com.enqualcomm.support.adapter.LBSHelper; import com.enqualcomm.support.utils.ContextProxy; @@ -931,6 +932,14 @@ public class Runtime { public static String lastSitCheckTiimeyyyyMMddHHmmss=""; public static long lastSitCheckStepCount=-1; + public static HealthInfo healthInfo=null; + static { + healthInfo=new HealthInfo(); + healthInfo.reset(); + } + + public static boolean practising=false; + public static int practice_cycle=60; } diff --git a/app/src/main/java/com/enqualcomm/support/service/Deliver.java b/app/src/main/java/com/enqualcomm/support/service/Deliver.java index d1bedaa3..8d793f01 100644 --- a/app/src/main/java/com/enqualcomm/support/service/Deliver.java +++ b/app/src/main/java/com/enqualcomm/support/service/Deliver.java @@ -265,6 +265,8 @@ public class Deliver extends AbstractConnectionService { if(!ServiceUtil.offerQueue(Msg)) { ICLogger.i(" MessageQueue 已满,数据将被丢弃," + Msg.cmd()+" "+Msg.isFromCache()); if (Config.LOG_TOFILE)ICLogger.logToFile( "APILog", " queueFullskip " + Msg.cmd()+" "+Msg.isFromCache()); + }else{ + if (Config.LOG_TOFILE)ICLogger.logToFile( "APILog", " queueCMD " + Msg.cmd()+" "+Msg.isFromCache()); } // if(queue.size()>5) //测试queue 发送逻辑用 triggerSendThread(); 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 f901c653..0142d800 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -18,6 +18,7 @@ import com.enqualcomm.support.Config; import com.enqualcomm.support.Constants; import com.enqualcomm.support.CoreService; 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; @@ -113,25 +114,50 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se //只有检测PPG成功,且网络连接中才发送数据 if (runtime.getHRS().getHeartrateWorkingStat() == heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS) { runtime.getHRS().setLastTestTime(TimeUtil.getSystemTime3()); - StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(runtime); - 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); + + if(Runtime.practising==true){ + ICLogger.i("自由锻炼中,设置测量心率! "+runtime.getHRS().getPPG()+","+runtime.getHRS().getBPH()+","+runtime.getHRS().getBPL()+","+runtime.getHRS().getSpo2()); + Runtime.healthInfo.setPPGECGData(runtime.getHRS().getPPG(),runtime.getHRS().getBPH(),runtime.getHRS().getBPL(),runtime.getHRS().getSpo2()); + + //因为心率和定位用时都比温度多,但是定位和心率不一定谁用时多,所以两个都需要检测是否结束 + if(Runtime.healthInfo.check_info_item_finished()){ + Runtime.healthInfo.appendBuffer(Runtime.healthInfo.getHealthInfoString()); + ICLogger.i("自由锻炼中,测量完成,添加一条记录! 当前条数 "+Runtime.healthInfo.getInfoCount()); + 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 { + StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(runtime); + 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); + Deliver.sendLocationMSG(oxd); checkWarning(); - }else { - Deliver.sendLocationMSG( PPGDATA); + } else { + Deliver.sendLocationMSG(PPGDATA); ICLogger.i("Send PPG " + PPGDATA.isFromCache()); checkWarning(); } - + } } else { ICLogger.i("PPG Failed for Timeout!"); @@ -203,10 +229,11 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se boolean isWared ; boolean isPPGTesting ; static boolean isTimerStarted; - static heartRateStatus.HEARTRATE_WORKINGSTAT currentStat; + 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秒 @@ -245,8 +272,15 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se 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--; @@ -294,6 +328,7 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_OPEN; delayCount = 4;//检测成功后4秒发送数据 notWaredCount = 5; //初始化没有佩戴的检测次数5,连续5秒没有佩戴则取消检测 + noPPGCount = 30;//即使佩戴了,但是30秒没有出结果,也认为无效 testCount = MAX_TESTTIMES;//测试MAX_TESTTIMES后没有结果也要强制退出 isTimerStarted = true; getPPGWakeLock(); @@ -304,7 +339,8 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se } else { - ICJniUtils.enablePPG(); + int ret=ICJniUtils.enablePPG(); + ICLogger.i("Start PPG test ret="+ret); timerPPG = new ScheduledThreadPoolExecutor(10); timerPPG.scheduleAtFixedRate(new Runnable() { @Override @@ -372,7 +408,11 @@ public class HeartRateManager extends AbstractInvokeHandlerService implements Se // stringBuilder.append("number == "); // stringBuilder.append(str1); ICLogger.i(stringBuilder.toString()); - //do something + //周期测量执行 + if (Runtime.practising==true) { + ICLogger.i("自由锻炼中,跳过原有的循环心率检测!"); + return false; + } startPPG(); } return false; @@ -382,7 +422,9 @@ 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) { @@ -412,23 +454,45 @@ public static void triggerPPGtest(){ } + if(Runtime.practising==true){ + ICLogger.i("自由锻炼中,设置测量心率!"); + Runtime.healthInfo.setPPGECGData(ppg,bph,bpl,spo2); - 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()); + //因为心率和定位用时都比温度多,但是定位和心率不一定谁用时多,所以两个都需要检测是否结束 + 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(); } + }); - callback(message.replyTo, Constants.RESULT_OK); + } + }else { + 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()); + } + } + callback(message.replyTo, Constants.RESULT_OK); default: break; 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 2fcbcbc2..d812954b 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java @@ -11,6 +11,7 @@ import android.os.Build; import android.os.Environment; import android.os.PowerManager; import android.provider.Settings; +import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import com.enqualcomm.support.Config; @@ -51,16 +52,20 @@ public class DeviceInfoUtil { public static boolean updateImei(Runtime runtime){ String imei= Config.getIMEI(runtime.getContextProxy().context); + String cellphoneNumb= DeviceInfoUtil.getNumber(runtime.getContextProxy().context); + ICLogger.i("get CellPhoneNumber "+cellphoneNumb); + String cid=""; if (imei.isEmpty()){ //如果配置里有IMEI,优先选配置里的,没有则选择系统的 imei= PhoneUtils.getIMEI(runtime.getContextProxy().context); + cid=PhoneUtils.getIMSI(runtime.getContextProxy().context); if(imei==null) { return false; }else{ - runtime.setImeiAndCid(imei, ""); + runtime.setImeiAndCid(imei, cid); } } else{ - runtime.setImeiAndCid(imei,""); + runtime.setImeiAndCid(imei,cid); } return true; diff --git a/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java b/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java index 3dcb7c2c..0e0e0ab3 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java @@ -24,7 +24,52 @@ import java.util.zip.ZipOutputStream; import static android.content.ContentValues.TAG; public class ICHttpUtil { + public static boolean uploadData(String filebuf, Runtime runtime, String logtime, Handler mhandler) { + String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath(); + String filename=sdcard+File.separator+"tmp.txt"; + String zipfile=sdcard+File.separator+"tmp.zip"; + boolean compressSuccess=false; + try { + + CheckedOutputStream out=new CheckedOutputStream(new FileOutputStream(filename),new CRC32()); + out.write(filebuf.getBytes()); + out.close(); + + File srcfile=new File(filename); + if (Util.zipFile(srcfile, "", + new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32())) + , filename)) { + compressSuccess=true; + } + srcfile.delete(); + }catch (Exception e){ + e.printStackTrace(); + compressSuccess=false; + } + if (compressSuccess==false) { + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + return false; + } + String server= Config.getLogServerIP(runtime.getContextProxy().context); + int port= Config.getLogServerPort(runtime.getContextProxy().context); + String product=DeviceInfoUtil.getModule(); + String pkgver=DeviceInfoUtil.getSWVersionDisplayName(); + String imei=runtime.IMEI(); + if (server.startsWith("http://")){ + server=server.replace("http://",""); + } + //为了兼容之前的只设置ip和端口的设置方式 + String actionUrl = "http://"+server+":"+port + "/UploadFile.jsp?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; + if (server.contains("/")){ //此时说明不是ip地址,而是个url + actionUrl= "http://"+server+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; + } + + ICLogger.i("url="+actionUrl+"\nfile="+zipfile); + return upLoadFile(actionUrl, new File(zipfile),mhandler); + + } public static boolean uploadFile(String filename, Runtime runtime, String logtime, Handler mhandler) { String zipfile=filename; diff --git a/app/src/main/java/com/enqualcomm/support/utils/SharPreferenceUtil.java b/app/src/main/java/com/enqualcomm/support/utils/SharPreferenceUtil.java index 07e610c7..9e66f474 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/SharPreferenceUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/SharPreferenceUtil.java @@ -57,23 +57,23 @@ public class SharPreferenceUtil { PreferenceManager.getDefaultSharedPreferences(context).edit().putString(key, value).commit(); } - - public static String getPrefStringPublic(Context context, String key, String value) { - SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_READABLE); - return sp.getString(key, value); - } - public static void setPrefStringPublic(Context context, String key, String value) { - SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_WRITEABLE); - sp.edit().putString(key, value).commit(); - } - public static void setPrefIntPublic(Context context, String key, int value) { - SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_WRITEABLE); - sp.edit().putInt(key, value).commit(); - } - public static int getPrefIntPublic(Context context, String key, int value) { - SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_READABLE); - return sp.getInt(key, value); - } +// +// public static String getPrefStringPublic(Context context, String key, String value) { +// SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_READABLE); +// return sp.getString(key, value); +// } +// public static void setPrefStringPublic(Context context, String key, String value) { +// SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_WRITEABLE); +// sp.edit().putString(key, value).commit(); +// } +// public static void setPrefIntPublic(Context context, String key, int value) { +// SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_WRITEABLE); +// sp.edit().putInt(key, value).commit(); +// } +// public static int getPrefIntPublic(Context context, String key, int value) { +// SharedPreferences sp=context.getSharedPreferences("icprotocolconfig",Context.MODE_WORLD_READABLE); +// return sp.getInt(key, value); +// } //// 其他应用读取写入访问的方法 // public static String getPrefStringPublic(Context context, String key, String value) { 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 46d11c86..7f62045a 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/TemperatureUtil.java @@ -9,7 +9,9 @@ import com.enqualcomm.support.Constants; import com.enqualcomm.support.CoreService; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; +import com.enqualcomm.support.bean.heartRateStatus; import com.enqualcomm.support.service.Deliver; +import com.enqualcomm.support.service.HeartRateManager; import com.ic.jni.ICJniUtils; import com.ic.protocols.protocolAPIHelper; @@ -52,48 +54,72 @@ public class TemperatureUtil { @Override public void run() { - if (ICJniUtils.isTemperatureDevAvailable() >ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) { - ICJniUtils.enableTemperature(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - - double wrist_temp, body_temp; - - wrist_temp = TemperatureUtil.get_temp_value_adjusted(); - body_temp = TemperatureUtil.getBodyTemp(wrist_temp, 26.0f); - StringMessage temperatureMsg = protocolAPIHelper.getTemperatureMSG(wrist_temp, body_temp, null); - Deliver.sendLocationMSG(temperatureMsg); - if (temperatureMsg!=null) ICLogger.i("发送体温测量值 " + temperatureMsg.isFromCache()); - - Runtime runtime = CoreService.getInstance().getRuntime(); - runtime.tempInfo.setTemp(body_temp, wrist_temp); - ICJniUtils.disableTemperature(); - - - if (Config.needTemperature_abnormal_alarm) { - switch (runtime.tempInfo.isBodyTempAbnormal()) { - case 0: - break; - case 1: - runtime.setAlarmType(Runtime.AlarmType.ALARM_TEMP_HIGH); - //trigger AP10 报警定位 - Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - break; - case 2: - runtime.setAlarmType(Runtime.AlarmType.ALARM_TEMP_LOW); - //trigger AP10 报警定位 - Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - break; - } - } + DoTempTest(); + } + },500); + } + + public static void DoTempTest(){ + if (ICJniUtils.isTemperatureDevAvailable() >ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) { + + ICJniUtils.enableTemperature(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + double wrist_temp, body_temp; + + wrist_temp = TemperatureUtil.get_temp_value_adjusted(); + if(wrist_temp< 0.001f){ + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); } + ICLogger.i("retry read temp for 0"); + wrist_temp = TemperatureUtil.get_temp_value_adjusted(); } - },500); + if(ICJniUtils.isTemperatureDevAvailable()==ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_IC68.ordinal()){ + //如果是IC68,只有体温,没有腕温 + body_temp=wrist_temp; + }else { + body_temp = TemperatureUtil.getBodyTemp(wrist_temp, 26.0f); + } + if(Runtime.practising==true){ + ICLogger.i("自由锻炼中,设置测量体温!" +String.format("%.1f",body_temp)); + Runtime.healthInfo.setTemperatureData(body_temp); + }else { + StringMessage temperatureMsg = protocolAPIHelper.getTemperatureMSG(wrist_temp, body_temp, null); + Deliver.sendLocationMSG(temperatureMsg); + if (temperatureMsg!=null) ICLogger.i("发送体温测量值 " + temperatureMsg.isFromCache()); + } + + Runtime runtime = CoreService.getInstance().getRuntime(); + runtime.tempInfo.setTemp(body_temp, wrist_temp); + ICJniUtils.disableTemperature(); + + //体温异常报警检测开启的会进行异常报警 + if (Config.needTemperature_abnormal_alarm) { + switch (runtime.tempInfo.isBodyTempAbnormal()) { + case 0: + break; + case 1: + runtime.setAlarmType(Runtime.AlarmType.ALARM_TEMP_HIGH); + //trigger AP10 报警定位 + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + break; + case 2: + runtime.setAlarmType(Runtime.AlarmType.ALARM_TEMP_LOW); + //trigger AP10 报警定位 + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + break; + } + } + + + } } } diff --git a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java index 9c9e0d0e..d727af54 100644 --- a/app/src/main/java/com/ic/protocols/protocolAPIHelper.java +++ b/app/src/main/java/com/ic/protocols/protocolAPIHelper.java @@ -629,4 +629,28 @@ public class protocolAPIHelper { } return ret; } + + public static StringMessage getPRACTICE(){ + 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 = null; + break; + case Config.PROTOCOL_FZD: + ret=protocol_fzd.PRACTICE(Runtime.healthInfo); + break; + case Config.PROTOCOL_MQTT: + ret=null; + break; + } + return ret; + } } diff --git a/app/src/main/java/com/ic/protocols/protocol_fzd.java b/app/src/main/java/com/ic/protocols/protocol_fzd.java index 1f5eff12..c4f309e5 100644 --- a/app/src/main/java/com/ic/protocols/protocol_fzd.java +++ b/app/src/main/java/com/ic/protocols/protocol_fzd.java @@ -12,6 +12,7 @@ import com.enqualcomm.support.CoreService; import com.enqualcomm.support.bean.Alarm; import com.enqualcomm.support.bean.Contact; import com.enqualcomm.support.bean.Content; +import com.enqualcomm.support.bean.HealthInfo; import com.enqualcomm.support.bean.ICLocation; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; @@ -95,6 +96,7 @@ public class protocol_fzd { oxygen,//血氧上传 blood,//血压上传 heart,//心率上传 + PRACTICE,//自由锻炼数据上传 UNKNOWN_CMD, } @@ -143,6 +145,7 @@ public class protocol_fzd { cmdMap.put(CMD_TYPE.oxygen, "oxygen"); cmdMap.put(CMD_TYPE.blood, "blood"); cmdMap.put(CMD_TYPE.heart, "heart"); + cmdMap.put(CMD_TYPE.PRACTICE, "PRACTICE"); } private Connection mConnection=null; @@ -709,6 +712,13 @@ public class protocol_fzd { dev.getContextProxy().context.startActivity(intent); } + public static StringMessage PRACTICE(HealthInfo healthInfo){ + if (healthInfo!=null && healthInfo.getInfoCount()>0) + return genFZDCMD(cmdMap.get(CMD_TYPE.PRACTICE),String.valueOf(healthInfo.getBufferDataStr())); + else + return null; + } + public boolean handleCmd(CMD_TYPE type, String cmd , String data) { //普通非二进制命令用此函数处理 diff --git a/app/version_code.properties b/app/version_code.properties index fdaed858..aa67d5ac 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Wed Sep 16 07:33:12 CST 2020 -VERSION_CODE=617 +#Thu Sep 17 17:15:58 CST 2020 +VERSION_CODE=618