diff --git a/android/app/build.gradle b/android/app/build.gradle index f911635e..66a7f0cd 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -135,6 +135,7 @@ dependencies { // Native Dependency implementation "org.jetbrains.anko:anko-commons:0.10.4" implementation 'com.github.kittinunf.fuel:fuel:2.3.0' //for JVM + implementation project(':blesdk_2301') implementation 'com.github.kittinunf.fuel:fuel-android:2.3.0' implementation 'com.google.android.gms:play-services-location:17.1.0'//for Android implementation 'com.google.android.gms:play-services-basement:17.5.0' diff --git a/android/blesdk_2301/build.gradle b/android/blesdk_2301/build.gradle new file mode 100644 index 00000000..1177acf0 --- /dev/null +++ b/android/blesdk_2301/build.gradle @@ -0,0 +1,52 @@ +apply plugin: 'com.android.library' + + +android { + compileSdkVersion 33 + + lintOptions{ + abortOnError false + } + + defaultConfig { + + minSdkVersion 18 + targetSdkVersion 33 + versionCode 3 + versionName "3.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + consumerProguardFiles 'proguard-rules.pro' + } + debug { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + consumerProguardFiles 'proguard-rules.pro' + } + } + task makejar(type: Jar) { + from file('build/intermediates/javac/debug/classes') + archiveName = '2301sdk' + defaultConfig.versionName + '.jar' + destinationDir = file('build/libs') + include "com/jstyle/blesdk2301/**" + + + } + makejar.dependsOn(build) + +} + + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/android/blesdk_2301/java_pid10828.hprof b/android/blesdk_2301/java_pid10828.hprof new file mode 100644 index 00000000..506d22d2 Binary files /dev/null and b/android/blesdk_2301/java_pid10828.hprof differ diff --git a/android/blesdk_2301/src/androidTest/java/com/jstyle/blesdk2301/ExampleInstrumentedTest.java b/android/blesdk_2301/src/androidTest/java/com/jstyle/blesdk2301/ExampleInstrumentedTest.java new file mode 100644 index 00000000..84547b8a --- /dev/null +++ b/android/blesdk_2301/src/androidTest/java/com/jstyle/blesdk2301/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.jstyle.blesdk2301; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.jstyle.blesdk.test", appContext.getPackageName()); + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/Util/BleSDK.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/Util/BleSDK.java new file mode 100644 index 00000000..3ab7053e --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/Util/BleSDK.java @@ -0,0 +1,1006 @@ +package com.jstyle.blesdk2301.Util; + +import android.text.TextUtils; + +import com.jstyle.blesdk2301.callback.DataListener2301; +import com.jstyle.blesdk2301.constant.BleConst; +import com.jstyle.blesdk2301.constant.DeviceConst; + +import com.jstyle.blesdk2301.constant.DeviceKey; +import com.jstyle.blesdk2301.model.AutoMode; +import com.jstyle.blesdk2301.model.AutoTestMode; +import com.jstyle.blesdk2301.model.MyAutomaticHRMonitoring; +import com.jstyle.blesdk2301.model.MyPersonalInfo; +import com.jstyle.blesdk2301.model.MyDeviceTime; +import com.jstyle.blesdk2301.other.ResolveUtil; + +import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * Created by Administrator on 2018/4/9. + */ + +public class BleSDK { + public static final int DATA_READ_START = 0; + public static final int DATA_READ_CONTINUE = 2; + public static final int DATA_DELETE = 99; + public static final byte DistanceMode_MILE = (byte) 0x81; + public static final byte DistanceMode_KM = (byte) 0x80; + public static final byte TimeMode_12h = (byte) 0x81; + public static final byte TimeMode_24h = (byte) 0x80; + public static final byte WristOn_Enable = (byte) 0x81; + public static final byte WristOn_DisEnable = (byte) 0x80; + public static final byte TempUnit_C = (byte) 0x80; + public static final byte TempUnit_F = (byte) 0x81; + + public static final String TAG = "BleSDK"; + public static boolean isruning = false; + + private static byte[] getByteArray(float f) { + int intbits = Float.floatToIntBits(f);//将float里面的二进制串解释为int整数 + return getByteArrays(intbits); + } + + public static byte[] getByteArrays(int i) { + byte[] b = new byte[4]; + b[3] = (byte) ((i & 0xff000000) >> 24); + b[2] = (byte) ((i & 0x00ff0000) >> 16); + b[1] = (byte) ((i & 0x0000ff00) >> 8); + b[0] = (byte) (i & 0x000000ff); + return b; + } + + + public static void DataParsingWithData(byte[] value, final DataListener2301 dataListener) { + Map map = new HashMap<>(); + switch (value[0]) { + + case DeviceConst.CMD_Set_UseInfo: + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.SetPersonalInfo)); + break; + case DeviceConst.CMD_Set_Auto: + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.SetAutomatic)); + break; + case DeviceConst.CMD_Set_DeviceID: + dataListener.dataCallback(ResolveUtil.setMacSuccessful()); + break; + case DeviceConst.CMD_SET_TIME: + dataListener.dataCallback(ResolveUtil.setTimeSuccessful(value)); + break; + + case DeviceConst.CMD_GET_TIME: + dataListener.dataCallback(ResolveUtil.getDeviceTime(value)); + break; + case DeviceConst.CMD_GET_USERINFO: + dataListener.dataCallback(ResolveUtil.getUserInfo(value)); + break; + case DeviceConst.CMD_Enable_Activity: + dataListener.dataCallback(ResolveUtil.getActivityData(value)); + break; + case DeviceConst.CMD_Get_BatteryLevel: + dataListener.dataCallback(ResolveUtil.getDeviceBattery(value)); + break; + case DeviceConst.CMD_Get_Address: + dataListener.dataCallback(ResolveUtil.getDeviceAddress(value)); + break; + case DeviceConst.CMD_Get_Version: + dataListener.dataCallback(ResolveUtil.getDeviceVersion(value)); + break; + case DeviceConst.CMD_Get_Auto: + dataListener.dataCallback(ResolveUtil.getAutoHeart(value)); + break; + case DeviceConst.CMD_Reset: + dataListener.dataCallback(ResolveUtil.Reset()); + break; + case DeviceConst.CMD_Mcu_Reset: + dataListener.dataCallback(ResolveUtil.MCUReset()); + break; + case DeviceConst.CMD_Get_TotalData: + if (GetTotalActivityDataWithMode) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.Delete_GetTotalActivityData)); + } else { + dataListener.dataCallback(ResolveUtil.getTotalStepData(value)); + } + break; + case DeviceConst.CMD_Get_DetailData: + if (GetDetailActivityDataWithMode) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.deleteGetDetailActivityDataWithMode)); + } else { + dataListener.dataCallback(ResolveUtil.getDetailData(value)); + } + break; + case DeviceConst.CMD_Get_SleepData: + if (Delete_GetDetailSleepData) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.Delete_GetDetailSleepData)); + } else { + dataListener.dataCallback(ResolveUtil.getSleepData(value)); + } + break; + case DeviceConst.CMD_Get_HeartData: + if (GetDynamicHRWithMode) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.Delete_GetDynamicHR)); + } else { + dataListener.dataCallback(ResolveUtil.getHeartData(value)); + } + + break; + case DeviceConst.CMD_Get_OnceHeartData: + if (GetStaticHRWithMode) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.Delete_GetStaticHR)); + } else { + dataListener.dataCallback(ResolveUtil.getOnceHeartData(value)); + } + + break; + case DeviceConst.CMD_Get_HrvTestData: + if (readhrv) { + dataListener.dataCallback(ResolveUtil.getHrvTestData(value)); + } else { + dataListener.dataCallback(ResolveUtil.DeleteHrv()); + } + break; + case DeviceConst.ReadTempHisrory: + if (GetTemperature_historyDataWithMode) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.deleteGetTemperature_historyDataWithMode)); + } else { + dataListener.dataCallback(ResolveUtil.getTempData(value)); + } + break; + case DeviceConst.Oxygen_data: + if (Obtain_The_data_of_manual_blood_oxygen_test) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.Delete_Obtain_The_data_of_manual_blood_oxygen_test)); + } else { + dataListener.dataCallback(ResolveUtil.GetAutomaticSpo2Monitoring(value)); + } + break; + case DeviceConst.CMD_HeartPackageFromDevice: + dataListener.dataCallback(ResolveUtil.getActivityExerciseData(value)); + break; + case DeviceConst.CMD_Set_Name: + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.CMD_Set_Name)); + break; + case DeviceConst.CMD_Get_Name: + dataListener.dataCallback(ResolveUtil.getDeviceName(value)); + break; + case DeviceConst.CMD_Get_SPORTData: + if (GetActivityModeDataWithMode) { + dataListener.dataCallback(ResolveUtil.setMethodSuccessful(BleConst.Delete_ActivityModeData)); + } else { + dataListener.dataCallback(ResolveUtil.getExerciseData(value)); + } + break; + case DeviceConst.MeasurementWithType: + if (StartDeviceMeasurementWithType) { + Map vv = new HashMap<>(); + switch (value[1]) { + case 1://hrv + vv.put(DeviceKey.DataType, BleConst.MeasurementHrvCallback); + vv.put(DeviceKey.End, true); + Map lm = new HashMap<>(); + lm.put(DeviceKey.Type, ResolveUtil.getValue(value[1], 0) + ""); + lm.put(DeviceKey.HeartRate, ResolveUtil.getValue(value[2], 0) + ""); + lm.put(DeviceKey.Blood_oxygen, ResolveUtil.getValue(value[3], 0) + ""); + lm.put(DeviceKey.HRV, ResolveUtil.getValue(value[4], 0) + ""); + lm.put(DeviceKey.Stress, ResolveUtil.getValue(value[5], 0) + ""); + lm.put(DeviceKey.HighPressure, ResolveUtil.getValue(value[6], 0) + ""); + lm.put(DeviceKey.LowPressure, ResolveUtil.getValue(value[7], 0) + ""); + vv.put(DeviceKey.Data, lm); + dataListener.dataCallback(vv); + break; + case 2://heart + vv.put(DeviceKey.DataType, BleConst.MeasurementHeartCallback); + vv.put(DeviceKey.End, true); + Map lmB = new HashMap<>(); + lmB.put(DeviceKey.Type, ResolveUtil.getValue(value[1], 0) + ""); + lmB.put(DeviceKey.HeartRate, ResolveUtil.getValue(value[2], 0) + ""); + lmB.put(DeviceKey.Blood_oxygen, ResolveUtil.getValue(value[3], 0) + ""); + lmB.put(DeviceKey.HRV, ResolveUtil.getValue(value[4], 0) + ""); + lmB.put(DeviceKey.Stress, ResolveUtil.getValue(value[5], 0) + ""); + lmB.put(DeviceKey.HighPressure, ResolveUtil.getValue(value[6], 0) + ""); + lmB.put(DeviceKey.LowPressure, ResolveUtil.getValue(value[7], 0) + ""); + vv.put(DeviceKey.Data, lmB); + dataListener.dataCallback(vv); + break; + case 3://0xy + vv.put(DeviceKey.DataType, BleConst.MeasurementOxygenCallback); + vv.put(DeviceKey.End, true); + Map lmC = new HashMap<>(); + lmC.put(DeviceKey.Type, ResolveUtil.getValue(value[1], 0) + ""); + lmC.put(DeviceKey.HeartRate, ResolveUtil.getValue(value[2], 0) + ""); + lmC.put(DeviceKey.Blood_oxygen, ResolveUtil.getValue(value[3], 0) + ""); + lmC.put(DeviceKey.HRV, ResolveUtil.getValue(value[4], 0) + ""); + lmC.put(DeviceKey.Stress, ResolveUtil.getValue(value[5], 0) + ""); + lmC.put(DeviceKey.HighPressure, ResolveUtil.getValue(value[6], 0) + ""); + lmC.put(DeviceKey.LowPressure, ResolveUtil.getValue(value[7], 0) + ""); + vv.put(DeviceKey.Data, lmC); + dataListener.dataCallback(vv); + break; + } + } else { + Map vv = new HashMap<>(); + switch (value[1]) { + case 1://hrv + vv.put(DeviceKey.DataType, BleConst.StopMeasurementHrvCallback); + vv.put(DeviceKey.End, true); + vv.put(DeviceKey.Data, new HashMap<>()); + dataListener.dataCallback(vv); + break; + case 2://heart + vv.put(DeviceKey.DataType, BleConst.StopMeasurementHeartCallback); + vv.put(DeviceKey.End, true); + vv.put(DeviceKey.Data, new HashMap<>()); + dataListener.dataCallback(vv); + break; + case 3://0xy + vv.put(DeviceKey.DataType, BleConst.StopMeasurementOxygenCallback); + vv.put(DeviceKey.End, true); + vv.put(DeviceKey.Data, new HashMap<>()); + dataListener.dataCallback(vv); + break; + } + } + break; + case DeviceConst.CMD_Get_Bloodsugar: + if (startBloodsugar) {//只有开始测量才返回状态 + Map vv = new HashMap<>(); + vv.put(DeviceKey.DataType, BleConst.Blood_glucose_status); + vv.put(DeviceKey.End, true); + Map lm = new HashMap<>(); + lm.put(DeviceKey.Type, ResolveUtil.getValue(value[1], 0) + ""); + vv.put(DeviceKey.Data, lm); + dataListener.dataCallback(vv); + } + break; + case DeviceConst.Bloodsugar_data: + Map vv = new HashMap<>(); + vv.put(DeviceKey.DataType, BleConst.Blood_glucose_data); + vv.put(DeviceKey.End, false); + Map lm = new HashMap<>(); + lm.put(DeviceKey.Time, getFormatTimeString(System.currentTimeMillis(), "yyyy.MM.dd HH:mm:ss")); + List simplePpg = new ArrayList<>(); + if (value.length == 153) {//新血糖解析 + byte[] valueer = new byte[value.length - 3]; + System.arraycopy(value, 3, valueer, 0, valueer.length); + for (int i = 0; i < valueer.length / 3; i++) { + int valuedata = ResolveUtil.getValue(valueer[3 * i], 2) + + ResolveUtil.getValue(valueer[3 * i + 1], 1) + + ResolveUtil.getValue(valueer[3 * i + 2], 0); + simplePpg.add(valuedata); + } + lm.put(DeviceKey.PPG, Arrays.toString(simplePpg.toArray())); + } + vv.put(DeviceKey.Data, lm); + dataListener.dataCallback(vv); + break; + + case DeviceConst.CMD_Start_EXERCISE: + if(FindActivityMode){ + Map mapEXERCISE = new HashMap<>(); + mapEXERCISE.put(DeviceKey.DataType, BleConst.FindActivityMode); + mapEXERCISE.put(DeviceKey.End, true); + Map mapsx = new HashMap<>(); + mapsx.put(DeviceKey.Type, ResolveUtil.getValue(value[1], 0) + ""); + mapsx.put(DeviceKey.Status, ResolveUtil.getValue(value[2], 0) + ""); + mapEXERCISE.put(DeviceKey.Data, mapsx); + dataListener.dataCallback(mapEXERCISE); + }else{ + Map mapEXERCISE = new HashMap<>(); + mapEXERCISE.put(DeviceKey.DataType, BleConst.EnterActivityMode); + mapEXERCISE.put(DeviceKey.End, true); + Map mapsx = new HashMap<>(); + mapsx.put(DeviceKey.enterActivityModeSuccess, ResolveUtil.getValue(value[1], 0) + ""); + mapEXERCISE.put(DeviceKey.Data, mapsx); + dataListener.dataCallback(mapEXERCISE); + } + break; + + + } + // return map; + } + + protected static boolean Delete_GetDetailSleepData = false; + + public static byte[] GetDetailSleepDataWithMode(byte mode, String dateOfLastData) { + Delete_GetDetailSleepData = ((byte) 0x99 == mode); + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_SleepData; + value[1] = mode; + insertDateValue(value, dateOfLastData); + crcValue(value); + return value; + } + + + /** + * 开始实时计步 + * + * @return + */ + public static byte[] RealTimeStep(boolean enable, boolean tempEnable) { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Enable_Activity; + value[1] = (byte) (enable ? 1 : 0); + value[2] = (byte) (tempEnable ? 1 : 0); + crcValue(value); + return value; + } + + + /** + * 设置个人信息 + * + * @param + * @return + */ + public static byte[] SetPersonalInfo(MyPersonalInfo info) { + byte[] value = new byte[16]; + int male = info.getSex(); + int age = info.getAge(); + int height = info.getHeight(); + int weight = info.getWeight(); + int stepLength = info.getStepLength(); + value[0] = DeviceConst.CMD_Set_UseInfo; + value[1] = (byte) male; + value[2] = (byte) age; + value[3] = (byte) height; + value[4] = (byte) weight; + value[5] = (byte) stepLength; + crcValue(value); + + return value; + } + + + /** + * 获取个人信息 + * + * @return + */ + public static byte[] GetPersonalInfo() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_GET_USERINFO; + crcValue(value); + return value; + } + + + /** + * 设置设备时间 + * + * @param + * @return + */ + public static byte[] SetDeviceTime(MyDeviceTime time) { + byte[] value = new byte[16]; + String timeZone = ResolveUtil.getCurrentTimeZone(); + String zone = timeZone.substring(3); + byte zoneValue = 0; + if (zone.contains("-")) { + zone = zone.replace("-", ""); + zoneValue = Byte.valueOf(String.valueOf(zone)); + } else { + zoneValue = (byte) (Byte.valueOf(zone) + 0x80); + } + int year = time.getYear(); + int month = time.getMonth(); + int day = time.getDay(); + int hour = time.getHour(); + int min = time.getMinute(); + int second = time.getSecond(); + value[0] = DeviceConst.CMD_SET_TIME; + value[1] = ResolveUtil.getTimeValue(year); + value[2] = ResolveUtil.getTimeValue(month); + value[3] = ResolveUtil.getTimeValue(day); + value[4] = ResolveUtil.getTimeValue(hour); + value[5] = ResolveUtil.getTimeValue(min); + value[6] = ResolveUtil.getTimeValue(second); + value[8] = zoneValue; + crcValue(value); + + return value; + } + + + /** + * 获取设备时间 + * + * @return + */ + public static byte[] GetDeviceTime() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_GET_TIME; + crcValue(value); + return value; + } + + + /** + * 99: 删除步数详细数据 , + * 0:读最近的步数详细数据。 + * 1:读指定位置的步数详细数据。 + * 2:继续上次读的位置下一段数据 + * + * @param + * @return * dateOfLastData "yyyy-MM-dd HH:mm:ss or yyyy.MM.dd HH:mm:ss" + */ + private static boolean GetDetailActivityDataWithMode = false; + + public static byte[] GetDetailActivityDataWithMode(byte mode, String dateOfLastData) { + GetDetailActivityDataWithMode = ((byte) 0x99 == mode); + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_DetailData; + value[1] = (byte) mode; + insertDateValue(value, dateOfLastData); + crcValue(value); + return value; + } + + /** + * 99: 删除温度数据 , + * 0:读最近的温度详细数据。 + * 1:读指定位置的步数详细数据。 + * 2:继续上次读的位置下一段数据 + * + * @param + * @return + */ + protected static boolean GetTemperature_historyDataWithMode; + + public static byte[] GetTemperature_historyData(byte mode, String dateOfLastData) { + GetTemperature_historyDataWithMode = ((byte) 0x99 == mode); + byte[] value = new byte[16]; + value[0] = DeviceConst.ReadTempHisrory; + value[1] = mode; + insertDateValue(value, dateOfLastData); + crcValue(value); + return value; + } + + public static boolean StartDeviceMeasurementWithType = false; + + public static byte[] SetDeviceMeasurementWithType(AutoTestMode dataType, long second, boolean open) { + StartDeviceMeasurementWithType = open; + byte[] value = new byte[16]; + value[0] = DeviceConst.MeasurementWithType; + switch (dataType) { + case AutoHeartRate: + value[1] = (byte) 0x02; + break; + case AutoSpo2: + value[1] = (byte) 0x03; + break; + + } + value[2] = open ? (byte) 0x01 : (byte) 0x00; + value[3] = (byte) ((second) & 0xff); + value[4] = (byte) ((second >> 8) & 0xff); + crcValue(value); + return value; + } + + public static byte[] SetAutomaticHRMonitoring(MyAutomaticHRMonitoring autoHeart, AutoMode type) { + byte[] value = new byte[16]; + int time = autoHeart.getTime(); + value[0] = DeviceConst.CMD_Set_Auto; + value[1] = (byte) autoHeart.getOpen(); + value[2] = ResolveUtil.getTimeValue(autoHeart.getStartHour()); + value[3] = ResolveUtil.getTimeValue(autoHeart.getStartMinute()); + value[4] = ResolveUtil.getTimeValue(autoHeart.getEndHour()); + value[5] = ResolveUtil.getTimeValue(autoHeart.getEndMinute()); + value[6] = (byte) autoHeart.getWeek(); + value[7] = (byte) (time & 0xff); + value[8] = (byte) ((time >> 8) & 0xff); + if (null == type) { + value[9] = (byte) 0x01; + } else { + switch (type) { + case AutoHeartRate: + value[9] = (byte) 0x01; + break; + case AutoSpo2: + value[9] = (byte) 0x02; + break; + case AutoTemp: + value[9] = (byte) 0x03; + break; + case AutoHrv: + value[9] = (byte) 0x04; + break; + } + } + crcValue(value); + return value; + } + + + public static byte[] GetAutomatic(AutoMode type) { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Auto; + if (null == type) { + value[1] = (byte) 0x01; + } else { + switch (type) { + case AutoHeartRate: + value[1] = (byte) 0x01; + break; + case AutoSpo2: + value[1] = (byte) 0x02; + break; + case AutoTemp: + value[1] = (byte) 0x03; + break; + case AutoHrv: + value[1] = (byte) 0x04; + break; + } + } + crcValue(value); + return value; + } + + + /** + * 获取某天总数据 + * 0 + * + * @param mode 0:表⽰是从最新的位置开始读取(最多50组数据) 2:表⽰接着读取(当数据总数⼤于50的时候) 0x99:表⽰删除所有运 + * 动数据 + * @return + */ + protected static boolean GetTotalActivityDataWithMode; + + public static byte[] GetTotalActivityDataWithMode(byte mode, String dateOfLastData) { + GetTotalActivityDataWithMode = (byte) 0x99 == mode; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_TotalData; + value[1] = mode; + insertDateValueNoH(value, dateOfLastData); + crcValue(value); + return value; + } + + + /** + * 获取设备版本号 + * + * @return + */ + public static byte[] GetDeviceVersion() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Version; + crcValue(value); + return value; + } + + + /** + * 恢复出厂设置 + * + * @return + */ + public static byte[] Reset() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Reset; + crcValue(value); + return value; + } + + + /** + * 获取设备mac地址 + * + * @return + */ + public static byte[] GetDeviceMacAddress() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Address; + crcValue(value); + return value; + } + + + /** + * 获取设备电量 + * + * @return + */ + public static byte[] GetDeviceBatteryLevel() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_BatteryLevel; + crcValue(value); + return value; + } + + + /** + * 重启设备 + * + * @return + */ + public static byte[] MCUReset() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Mcu_Reset; + crcValue(value); + return value; + } + + + private static boolean readhrv = false; + + public static byte[] GetHRVDataWithMode(byte mode, String dateOfLastData) { + readhrv = (byte) 0x99 != mode; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_HrvTestData; + value[1] = mode; + insertDateValue(value, dateOfLastData); + crcValue(value); + return value; + } + + + protected static boolean GetStaticHRWithMode; + + public static byte[] GetStaticHRWithMode(byte mode, String dateOfLastData) { + GetStaticHRWithMode = ((byte) 0x99 == mode); + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_OnceHeartData; + value[1] = mode; + insertDateValue(value, dateOfLastData); + crcValue(value); + return value; + } + + + protected static boolean GetDynamicHRWithMode; + + public static byte[] GetDynamicHRWithMode(byte Number, String dateOfLastData) { + GetDynamicHRWithMode = (byte) 0x99 == Number; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_HeartData; + value[1] = (byte) Number; + insertDateValue(value, dateOfLastData); + crcValue(value); + return value; + } + + + public static byte[] SetDeviceID(String deviceId) { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Set_DeviceID; + for (int i = 0; i < 6; i++) { + value[i + 1] = (byte) deviceId.charAt(i); + } + crcValue(value); + return value; + } + + + public static byte[] intTobyte(int num) { + return new byte[]{(byte) ((num >> 8) & 0xff), (byte) (num & 0xff)}; + } + + public static int byteArrayToInt(byte[] arr) { + short targets = (short) ((arr[1] & 0xff) | ((arr[0] << 8) & 0xff00)); + + return targets; + } + + + public static byte[] getInfoValue(String info, int maxLength) { + byte[] nameBytes = null; + try { + nameBytes = info.getBytes("UTF-8"); + if (nameBytes.length >= maxLength) {//两条命令总共32个字节,内容只占24个字节(32-2*(1cmd+1消息类型+1长度+1校验)) + byte[] real = new byte[maxLength]; + char[] chars = info.toCharArray(); + int length = 0; + for (int i = 0; i < chars.length; i++) { + String s = String.valueOf(chars[i]); + byte[] nameB = s.getBytes("UTF-8"); + ; + if (length + nameB.length == maxLength) { + System.arraycopy(nameBytes, 0, real, 0, real.length); + return real; + } else if (length + nameB.length > maxLength) {//大于24会导致有个字节发不到下位机导致乱码 + System.arraycopy(nameBytes, 0, real, 0, length); + return real; + } + length += nameB.length; + } + } + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return nameBytes; + } + + public static void crcValue(byte[] value) { + byte crc = 0; + for (int i = 0; i < value.length - 1; i++) { + crc += value[i]; + } + value[value.length - 1] = (byte) (crc & 0xff); + } + + + public static void insertDateValue(byte[] value, String time) { + if (!TextUtils.isEmpty(time) && time.length() > 8) { + String[] timeArray = time.split(" "); + String INDEX; + if (time.contains("-")) { + INDEX = "-"; + } else { + INDEX = "\\."; + } + int year = Integer.parseInt(timeArray[0].split(INDEX)[0]); + int month = Integer.parseInt(timeArray[0].split(INDEX)[1]); + int day = Integer.parseInt(timeArray[0].split(INDEX)[2]); + int hour = Integer.parseInt(timeArray[1].split(":")[0]); + int min = Integer.parseInt(timeArray[1].split(":")[1]); + int second = Integer.parseInt(timeArray[1].split(":")[2]); + value[4] = ResolveUtil.getTimeValue(year); + value[5] = ResolveUtil.getTimeValue(month); + value[6] = ResolveUtil.getTimeValue(day); + value[7] = ResolveUtil.getTimeValue(hour); + value[8] = ResolveUtil.getTimeValue(min); + value[9] = ResolveUtil.getTimeValue(second); + } + + } + + + public static void insertDateValueNoH(byte[] value, String time) { + if (!TextUtils.isEmpty(time) && time.contains("-")) { + String[] timeArray = time.split(" "); + String INDEX; + if (time.contains("-")) { + INDEX = "-"; + } else { + INDEX = "\\."; + } + int year = Integer.parseInt(timeArray[0].split(INDEX)[0]); + int month = Integer.parseInt(timeArray[0].split(INDEX)[1]); + int day = Integer.parseInt(timeArray[0].split(INDEX)[2]); + value[4] = ResolveUtil.getTimeValue(year); + value[5] = ResolveUtil.getTimeValue(month); + value[6] = ResolveUtil.getTimeValue(day); + } + + + } + + + /** + * 转十六进制字符串 + * + * @param data + * @return + */ + public static String byte2Hex(byte[] data) { + if (data != null && data.length > 0) { + StringBuilder sb = new StringBuilder(data.length); + for (byte tmp : data) { + sb.append(String.format("%02X ", tmp)); + } + return sb.toString(); + } + return "no data"; + } + + + /** + * OObtain automated test oximetry data + * 获得自动测试血氧数据 + */ + protected static boolean Obtain_The_data_of_manual_blood_oxygen_test; + + public static byte[] Oxygen_data(byte Number) { + Obtain_The_data_of_manual_blood_oxygen_test = ((byte) 0x99 == Number); + byte[] value = new byte[16]; + value[0] = DeviceConst.Oxygen_data; + value[1] = (byte) Number; + crcValue(value); + return value; + } + + public static byte[] EnterActivityMode(int time, int activityMode, int WorkMode) { + FindActivityMode=false; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Start_EXERCISE; + value[1] = (byte) WorkMode; + value[2] = (byte) activityMode; + value[4] = (byte) time; + crcValue(value); + return value; + } + + private static boolean FindActivityMode=false; + public static byte[] FindActivityMode() { + FindActivityMode=true; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Start_EXERCISE; + value[1] = (byte) 0x05; + crcValue(value); + return value; + } + + /** + * @param status 级别 0,1,2 + * @param time 分钟 + * @param WorkMode START=1;PAUSE=2;CONTUINE=3;FINISH=4; + * @return + */ + public static byte[] setExerciseModeByBreath(int status, int time, int WorkMode) { + FindActivityMode=false; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Start_EXERCISE; + value[1] = (byte) WorkMode; + value[2] = (byte) 0x06; + value[3] = (byte) status; + value[4] = (byte) time; + crcValue(value); + return value; + } + + public static byte[] sendHeartPackage(float distance, int space, int rssi) { + byte[] value = new byte[16]; + byte[] distanceValue = getByteArray(distance); + int min = space / 60; + int second = space % 60; + value[0] = DeviceConst.CMD_heart_package; + System.arraycopy(distanceValue, 0, value, 1, distanceValue.length); + value[5] = (byte) min; + value[6] = (byte) second; + value[7] = (byte) rssi; + crcValue(value); + return value; + } + + /** + * 设置设备名字 + * + * @param + * @return + */ + public static byte[] SetDeviceName(String strDeviceName) { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Set_Name; + int length = strDeviceName.length() > 14 ? 14 : strDeviceName.length(); + for (int i = 0; i < length; i++) { + value[i + 1] = (byte) strDeviceName.charAt(i); + } + crcValue(value); + return value; + } + + + /** + * 获取设备名字 + * + * @return + */ + public static byte[] GetDeviceName() { + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Name; + crcValue(value); + return value; + } + + + /** + * 获取多模式运动数据 + * + * @param mode 0:表⽰是从最新的位置开始读取(最多50组数据) 2:表⽰接着读取(当数据总数⼤于50的时候) 0x99:表⽰删除所有 + * GPS数据 + * @return + */ + protected static boolean GetActivityModeDataWithMode; + + public static byte[] GetActivityModeDataWithMode(byte mode) { + GetActivityModeDataWithMode = ((byte) 0x99 == mode); + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_SPORTData; + value[1] = mode; + crcValue(value); + return value; + } + + + /** + * 开始血氧测量 + * Start blood oxygen measurement + */ + public static boolean startBloodsugar = false; + + public static byte[] startBloodsugar() { + startBloodsugar = true; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Bloodsugar; + value[1] = (byte) 0x01; + crcValue(value); + return value; + } + + /** + * 停止血氧测量 + * Stop blood oxygen measurement + */ + public static byte[] BloodsugarStop() { + startBloodsugar = false; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Bloodsugar; + value[1] = (byte) 0x05; + crcValue(value); + return value; + } + + /** + * 血氧测量停止信号采集 + * Blood oxygen measurement stop signal acquisition + */ + public static byte[] BloodsugarStopSiss() { + startBloodsugar = false; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Bloodsugar; + value[1] = (byte) 0x03; + crcValue(value); + return value; + } + + + /** + * 血氧测量进度更新 + * Blood oxygen measurement progress update + */ + public static byte[] BloodsugarProgress(int Progress) { + startBloodsugar = false; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Bloodsugar; + value[1] = (byte) 0x04; + value[2] = (byte) Progress;//0-100 + crcValue(value); + return value; + } + + /** + * 血氧测量结果 + * Send blood glucose results to the device + * status 1低 2中 3高 0测试失败 + * Status 1 low 2 3 high 0 test failed + */ + public static byte[] SendBloodGlucoseResultsToTheDevice(int status) { + startBloodsugar = false; + byte[] value = new byte[16]; + value[0] = DeviceConst.CMD_Get_Bloodsugar; + value[1] = (byte) 0x02; + value[2] = (byte) status; + crcValue(value); + return value; + } + + + /** + * 获取指定格式的日期字符串 + */ + public static synchronized String getFormatTimeString(long time, String formatString) { + SimpleDateFormat format = new SimpleDateFormat(formatString); + String data = ""; + try { + data = format.format(new Date(time)); + } catch (Exception E) { + E.printStackTrace(); + } + return data; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/Util/PDFCreate.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/Util/PDFCreate.java new file mode 100644 index 00000000..72307c52 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/Util/PDFCreate.java @@ -0,0 +1,244 @@ +package com.jstyle.blesdk2301.Util; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.Rect; +import android.graphics.pdf.PdfDocument; +import android.text.TextUtils; + +import com.jstyle.blesdk2301.model.UserInfo; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; + +public class PDFCreate { + private static final String TAG = "PDFCreate"; + final static int maxXSize = 5120; + static float length = 20; + static float totalWidth = 1070; + static int startX = 35; + static float endX = startX + 1000; + static float startY ; + private static float endY; + private static float height ; + private static float width ; + private static int strokeWidthTime; + private static int strokeWidthLine; + private static float totalHeight; + + public static void createPdf(String path, Context context, List data, UserInfo userInfo) { + int size = data.size(); + float col = size % maxXSize == 0 ? size / maxXSize : size / maxXSize + 1;//一次画5120个点,分多少次画 + length=dip2px(context,10); + height=length; + width=length; + startX=dip2px(context,20); + endX=startX+50*length; + totalWidth=endX+startX; + totalHeight = col * height * 5 + dip2px(context,130);//一次需要5个高度 + PdfDocument pdfDocument = new PdfDocument(); + + PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder((int) totalWidth, (int) totalHeight, 1) + // .setContentRect(new Rect(0,0,(int)totalWidth,(int)totalHeight)) + .create(); + + PdfDocument.Page page = pdfDocument.startPage(pageInfo); + Canvas canvas = page.getCanvas(); + Paint paint = new Paint(); + strokeWidthTime = dip2px(context, 1.5f); + strokeWidthLine = dip2px(context, 0.5f); + drawReportInfo(context, canvas, paint,userInfo); + Path pathCanvas = new Path(); + endY = startY + col * height * 5; + paint.setTextSize(dip2px(context, 15)); + drawAxes(pathCanvas, canvas, paint, col); + drawTimeLine(pathCanvas, canvas, paint); + drawDataLine(context,pathCanvas, canvas, paint, col, data); + pdfDocument.finishPage(page); + File file = new File(path); + FileOutputStream outputStream = null; + try { + outputStream = new FileOutputStream(file); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + try { + pdfDocument.writeTo(outputStream); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + /**用户信息 + * @param context + * @param canvas + * @param paint + * @param + */ + private static void drawReportInfo(Context context, Canvas canvas, Paint paint,UserInfo userInfo) { + paint.setTextSize(dip2px(context,15)); + paint.setColor(Color.BLACK); + paint.setStyle(Paint.Style.FILL); + if(null!=userInfo){ + if(!TextUtils.isEmpty(userInfo.getEcgTitle())){ + String title=userInfo.getEcgTitle(); + Rect rect = new Rect(); + paint.getTextBounds(title, 0, title.length(), rect); + int heightTitle = rect.height(); + float startTextY=heightTitle+dip2px(context,8); + float marginTop=dip2px(context,4); + float marginRight=dip2px(context,8); + //标题 + canvas.drawText(title, totalWidth / 2 - 150, startTextY, paint); + //提醒 + paint.setTextSize(dip2px(context, 12)); + int widthTips = rect.width(); + int heightTips = rect.height(); + if(!TextUtils.isEmpty(userInfo.getEcgReportTips())) { + + String tips = userInfo.getEcgReportTips(); + float tipsTextY = startTextY + heightTitle + marginTop; + paint.getTextBounds(tips, 0, tips.length(), rect); + canvas.drawText(tips, totalWidth - widthTips - marginRight, tipsTextY, paint); + } + + float tipsTextY=startTextY+heightTitle+marginTop; + + + String name = userInfo.getName(); + String genderString = userInfo.getGender(); + String age = userInfo.getAge(); + + + String userWeight = userInfo.getWeight(); + String userHeight = userInfo.getHeight(); + //个人信息 + float infoTextY=tipsTextY+heightTips+marginTop; + @SuppressLint("StringFormatMatches") + String info=name+" "+genderString+" "+age+" "+ userHeight+" "+userWeight; + paint.getTextBounds(info, 0, info.length(), rect); + int heightInfo = rect.height(); + int widthInfo = rect.width(); + canvas.drawText(info, totalWidth / 2 - (widthInfo >> 1), infoTextY, paint); + //时间 + float dateTextY=infoTextY+heightInfo+marginTop; + String dateString=userInfo.getDate(); + paint.getTextBounds(dateString, 0, dateString.length(), rect); + int widthDate=rect.width(); + int heightDate=rect.height(); + canvas.drawText(dateString, totalWidth - widthDate-marginRight, dateTextY, paint); + startY=dateTextY+heightDate+marginTop; + } + + + + + } + + } + + /** + * 画网格 + * + * @param pathCanvas + * @param canvas + * @param paint + * @param col + */ + private static void drawAxes(Path pathCanvas, Canvas canvas, Paint paint, float col) { + //画网格竖线 + int colorLine = Color.rgb(243, 119, 99); + paint.setColor(colorLine); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(strokeWidthLine); + paint.setAlpha(200); + for (int i = 0; i <51; i++) { + pathCanvas.moveTo(i * width + startX, startY); + pathCanvas.lineTo(i * width + startX, endY); + } + //画网格横线 + for (int i = 0; i <= col * 5; i++) { + pathCanvas.moveTo(startX - (strokeWidthTime >> 1), i * height + startY); + pathCanvas.lineTo(endX + (strokeWidthTime >> 1), i * height + startY); + } + canvas.drawPath(pathCanvas, paint); + pathCanvas.reset(); + } + + /** + * 加粗时间线 + * + * @param pathCanvas + * @param canvas + * @param paint + */ + private static void drawTimeLine(Path pathCanvas, Canvas canvas, Paint paint) { + paint.setColor(Color.BLACK); + paint.setStrokeWidth(strokeWidthTime); + paint.setStyle(Paint.Style.FILL); + Rect rect=new Rect(); + for (int i = 0; i < 11; i++) { + pathCanvas.moveTo(i * 5 * width + startX, startY); + pathCanvas.lineTo(i * 5 * width + startX, endY + 20); + String time=i+"s"; + paint.getTextBounds(time, 0, time.length(), rect); + int widthTime=rect.width(); + canvas.drawText(time, i * 5 * width + startX - (widthTime >> 1), endY + 50, paint); + } + int colorS = Color.rgb(255, 119, 99); + paint.setColor(colorS); + paint.setAlpha(255); + paint.setStyle(Paint.Style.STROKE); + canvas.drawPath(pathCanvas, paint); + pathCanvas.reset(); + } + + /** + * 画数据 + * + * @param pathCanvas + * @param canvas + * @param paint + * @param col + * @param data + */ + private static void drawDataLine(Context context,Path pathCanvas, Canvas canvas, Paint paint, float col, List data) { + int size = data.size(); + paint.setStrokeWidth(strokeWidthLine); + paint.setColor(Color.BLACK); + out: + for (int i = 0; i < col; i++) { + int startPoint = i * maxXSize; + in: for (int j = 0; j = size) break out; + Integer y = data.get(startPoint + j); + if (j == 0) pathCanvas.moveTo(startX, i * height * 5 + getCanvasY(y,context)); + pathCanvas.lineTo(startX + x * (endX - startX) / maxXSize, i * height * 5 + getCanvasY(y,context)); + } + } + + canvas.drawPath(pathCanvas, paint); + } + + private static float getCanvasY(double value,Context context) { + double height = 5 * 10 / 16000f; + return dip2px (context,(float) (height * (8000 - value))) + startY; + } + + /** + * 根据手机的分辨率从 dp 的单位 转成为 px(像素) + */ + public static int dip2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dpValue * scale + 0.5f); + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/BleConnectionListener.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/BleConnectionListener.java new file mode 100644 index 00000000..ee6db91d --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/BleConnectionListener.java @@ -0,0 +1,10 @@ +package com.jstyle.blesdk2301.callback; + +public interface BleConnectionListener { + void BleStatus(int status,int newState);//蓝牙4.0连接状态 Bluetooth 4.0 connection status + void ConnectionSucceeded();//连接设备成功 Successfully connected the device + void Connecting();//设备连接中 Device is connected + void ConnectionFailed();//设备连接失败 Device connection failed + void OnReconnect();//重新连接中 Reconnecting + void BluetoothSwitchIsTurnedOff();//蓝牙开关被关闭 Bluetooth switch is turned off +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/DataListener2301.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/DataListener2301.java new file mode 100644 index 00000000..bb8a8920 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/DataListener2301.java @@ -0,0 +1,13 @@ +package com.jstyle.blesdk2301.callback; + +import java.util.Map; + +/** + * Created by Administrator on 2018/4/10. + */ + +public interface DataListener2301 { + void dataCallback(Map maps); + void dataCallback(byte[] value); + +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/OnScanResults.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/OnScanResults.java new file mode 100644 index 00000000..98a00c64 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/callback/OnScanResults.java @@ -0,0 +1,9 @@ +package com.jstyle.blesdk2301.callback; + + +import com.jstyle.blesdk2301.model.Device; + +public interface OnScanResults { + void Success(Device date); + void Fail(int code); +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/cmdenum/YhDeviceData.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/cmdenum/YhDeviceData.java new file mode 100644 index 00000000..47e53161 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/cmdenum/YhDeviceData.java @@ -0,0 +1,42 @@ +package com.jstyle.blesdk2301.cmdenum; + +import java.io.Serializable; + +public class YhDeviceData implements Serializable { + int dataType;// is index + String data="";//data object + boolean dataEnd=false; //Is it over? + + public boolean isDataEnd() { + return dataEnd; + } + + public void setDataEnd(boolean dataEnd) { + this.dataEnd = dataEnd; + } + + public int getDataType() { + return dataType; + } + + public void setDataType(int dataType) { + this.dataType = dataType; + } + + public String getData() { + return data==null?"":data; + } + + public void setData(String data) { + this.data = data; + } + + @Override + public String toString() { + return "YhDeviceData{" + + "dataType=" + dataType + + ", data=" + data + + ", dataEnd=" + dataEnd + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/BleConst.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/BleConst.java new file mode 100644 index 00000000..567e0fa5 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/BleConst.java @@ -0,0 +1,135 @@ +package com.jstyle.blesdk2301.constant; + +/** + * Created by Administrator on 2020/4/9. + */ + +public class BleConst { + public static final String GetDeviceTime="0"; + public static final String SetDeviceTime="1"; + public static final String GetPersonalInfo="2"; + public static final String SetPersonalInfo="3"; + public static final String GetDeviceInfo="4"; + public static final String SetDeviceInfo="5";//设置手环基本参数 + public static final String CMD_Set_Mac="6"; + public static final String GetStepGoal="7"; + public static final String SetStepGoal="8"; + public static final String GetDeviceBatteryLevel="9"; + public static final String GetDeviceMacAddress="10"; + public static final String GetDeviceVersion="11"; + public static final String CMD_Reset="12"; + public static final String CMD_MCUReset="13"; + public static final String SetMotorVibrationWithTimes ="14"; + public static final String GetDeviceName="15"; + public static final String GetAutomatic="16"; + public static final String SetAutomatic="17"; + public static final String GetAlarmClock="18"; + public static final String SetAlarmClockWithAllClock="19"; + public static final String Notify="20"; + public static final String GetSedentaryReminder="21"; + public static final String SetSedentaryReminder="22"; + public static final String RealTimeStep="23"; + public static final String GetTotalActivityData="24"; + public static final String GetDetailActivityData="25"; + public static final String GetDetailSleepData="26"; + public static final String GetDynamicHR="27"; + public static final String GetStaticHR="28"; + public static final String GetActivityModeData="29"; + public static final String EnterActivityMode="30"; + public static final String DeviceSendDataToAPP="31"; + public static final String BackHomeView="35"; + public static final String GetTempHistoryData="36"; + public static final String ECGDATA="37"; + public static final String EcgppGstatus="38"; + public static final String EcgppG="39"; + public static final String GPSControlCommand="40"; + public static final String Gps="41";//手环发送给app + public static final String GetHRVData="42"; + public static final String CMD_Set_TemperatureCorrection="43"; + public static final String Weather="44"; + public static final String Braceletdial="45"; + public static final String Braceletdialok="46"; + public static final String SportMode="47"; + public static final String GetSportMode="48"; + public static final String CMD_Set_WorkOutReminder="49"; + public static final String CMD_Get_WorkOutReminder="50"; + public static final String ReadSerialNumber="51"; + public static final String ECG="53"; + public static final String Clear_Bracelet_data="54"; + public static final String Blood_oxygen="55"; + public static final String SocialdistanceGetting="56"; + public static final String SocialdistanceSetting="57"; + public static final String Sos="58"; + public static final String Temperature_history="59"; + public static final String SetDialinterface="60"; + public static final String HeartBeatpacket="61"; + public static final String GetAxillaryTemperatureDataWithMode="62"; + public static final String GetMAC="63"; + public static final String Getppg="64"; + public static final String CloseECGPPG="65"; + public static final String GetEcgPpgStatus="66"; + public static final String ECGdata="67"; + public static final String GetAutomaticSpo2Monitoring="68"; + public static final String SetSpo2="69"; + public static final String GEtSpo2="70"; + public static final String DeleteECGdata="71"; + public static final String DeleteHrv="72"; + public static final String MeasurementHrvCallback="73"; + public static final String MeasurementHeartCallback="74"; + public static final String MeasurementOxygenCallback="75"; + public static final String StopMeasurementHrvCallback="76"; + public static final String StopMeasurementHeartCallback="77"; + public static final String StopMeasurementOxygenCallback="78"; + public static final String ExitQRcode="79"; + public static final String EnterQRcode="80"; + public static final String QRcodebandBack="81"; + public static final String SportData="82"; + public static final String Delete_Obtain_The_data_of_manual_blood_oxygen_test="83"; + public static final String Delete_Blood_oxygen="84"; + public static final String Delete_GetTotalActivityData="85"; + public static final String Delete_AlarmClock="87"; + public static final String Delete_ActivityModeData="88"; + public static final String Delete_GetStaticHR="89"; + public static final String Delete_GetDynamicHR="90"; + public static final String deleteGetTemperature_historyDataWithMode="91"; + public static final String deleteGetAxillaryTemperatureDataWithMode="92"; + public static final String deleteGetDetailActivityDataWithMode="93"; + public static final String Delete_GetDetailSleepData="94"; + public static final String Enter_photo_mode="95"; + public static final String openRRInterval="96"; + public static final String closeRRInterval="97"; + public static final String realtimeRRIntervalData="98"; + public static final String realtimePPGData="99"; + public static final String realtimePPIData="100"; + + public static final String ppgWithMode="101"; + public static final String ppgStartSucessed="102"; + public static final String ppgStartFailed="103"; + public static final String ppgStop="104"; + public static final String ppgQuit="105"; + public static final String ppgMeasurementProgress="106"; + public static final String ppgResult="107"; + public static final String SetBloodpressure_calibration="108"; + public static final String GetBloodpressure_calibration="109"; + public static final String SetWomenHealth="110"; + public static final String GetWomenHealth="111"; + + public static final String SetPregnancyCycle="112"; + public static final String GetPregnancyCycle="113"; + public static final String Getpeisu="114"; + public static final String GetpeisuER="115"; + public static final String CMD_Set_Name="116"; + public static final String CMD_Get_Name="117"; + public static final String Blood_glucose_status="118"; + public static final String Blood_glucose_data="119"; + public static final String FindActivityMode="120"; + + + + public static final String FindMobilePhoneMode="FindMobilePhoneMode"; + public static final String RejectTelMode ="RejectTelMode"; + public static final String TelMode ="TelMode"; + public static final String ECGResult="ECGResult"; + public static final String ENTERECG="ENTERECG"; + +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/DeviceConst.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/DeviceConst.java new file mode 100644 index 00000000..0f09b9be --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/DeviceConst.java @@ -0,0 +1,41 @@ +package com.jstyle.blesdk2301.constant; + +/** + * Created by Administrator on 2018/1/17. + */ + +public class DeviceConst { + public static final byte CMD_SET_TIME = (byte)0x01; + public static final byte CMD_GET_TIME = (byte)0x41; + public static final byte CMD_Set_UseInfo = (byte)0x02; + public static final byte CMD_GET_USERINFO = (byte) 0x42; + public static final byte CMD_Set_DeviceID = (byte)0x05; + public static final byte CMD_Enable_Activity = (byte)0x09;// + public static final byte CMD_Get_BatteryLevel = (byte)0x13;// + public static final byte CMD_Get_Address = (byte)0x22; + public static final byte CMD_Get_Version = (byte)0x27; + public static final byte CMD_Reset = (byte)0x12; + public static final byte CMD_Mcu_Reset = (byte)0x2e; + public static final byte CMD_Set_Auto = (byte)0x2a; + public static final byte CMD_Get_Auto = (byte)0x2b; + public static final byte CMD_Get_TotalData = (byte)0x51;// + public static final byte CMD_Get_DetailData = (byte)0x52; + public static final byte CMD_Get_SleepData = (byte)0x53; + public static final byte CMD_Get_HeartData = (byte)0x54; + public static final byte CMD_Get_OnceHeartData = (byte)0x55; + public static final byte CMD_Get_HrvTestData = (byte)0x56;// + public static final byte ReadTempHisrory= (byte)0x62; + public static final byte MeasurementWithType= (byte)0x28; + public static final byte Oxygen_data= (byte)0x66; + + public static final byte CMD_Start_EXERCISE = (byte)0x19; + public static final byte CMD_heart_package= (byte)0x17; + public static final byte CMD_HeartPackageFromDevice = (byte)0x18;// + public static final byte CMD_Set_Name = (byte)0x3d; + public static final byte CMD_Get_Name = (byte)0x3e; + + public static final byte CMD_Get_SPORTData = (byte)0x5C; + + public static final byte CMD_Get_Bloodsugar = (byte)0x78; + public static final byte Bloodsugar_data=(byte)0x3a;//血糖数据 +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/DeviceKey.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/DeviceKey.java new file mode 100644 index 00000000..3bcdbcf1 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/constant/DeviceKey.java @@ -0,0 +1,413 @@ +package com.jstyle.blesdk2301.constant; + +/** + * Created by Administrator on 2018/4/10. + */ + +public class DeviceKey { + public static final String heartValue = "heartValue"; + public static final String hrvValue = "hrvValue"; + public static final String Quality = "Quality"; + + public static final String HangUp = "HangUp"; + public static final String Telephone = "Telephone"; + public static final String Photograph = "Photograph"; + public static final String CanclePhotograph = "CanclePhotograph"; + public static final String type = "type"; + public static final String Play = "Play"; + public static final String Suspend = "Suspend"; + public static final String LastSong = "LastSong"; + public static final String NextSong = "NextSong"; + public static final String VolumeReduction = "VolumeReduction"; + public static final String VolumeUp = "VolumeUp"; + public static final String FindYourPhone = "FindYourPhone"; + public static final String Cancle_FindPhone = "Cancle_FindPhone"; + public static final String SOS = "SOS"; + public static final String DataType = "dataType"; + public static final String enterActivityModeSuccess = "enterActivityModeSuccess"; + public static final String Type = "Type"; + public static final String Status = "Status"; + public static final String RRIntervalData = "RRIntervalData"; + public static final String Manual = "Manual"; + public static final String automatic = "automatic"; + public static final String Data = "dicData"; + public static final String End = "dataEnd"; + public static final String index = "index"; + public static final String scanInterval = "scanInterval"; + public static final String scanTime = "scanTime"; + public static final String signalStrength = "signalStrength"; + public static final String arrayX = "arrayX"; + public static final String arrayY = "arrayY"; + public static final String arrayZ = "arrayZ"; + public static final String arrayPpgRawData = "arrayPpgRawData"; + public static final String KGpsResCheck0 = "KGpsResCheck0"; // 设备时间 GET_DEVICE_Time + public static final String KGpsResCheck1 = "KGpsResCheck1"; // 设备时间 + public static final String Band = "Band"; + public static final String KFinishFlag = "finish"; + public static final String DeviceTime = "strDeviceTime"; // 设备时间 GET_DEVICE_Time + public static final String GPSTime = "gpsExpirationTime"; // 设备时间 GET_DEVICE_Time + public static final String TimeZone = "TimeZone"; // 设备时间 GET_DEVICE_Time + + + public static final String KHrvBloodHighPressure = "KHrvBloodHighPressure"; + public static final String KHrvBloodLowPressure = "KHrvBloodLowPressure"; + /* + * GET_PERSONAL_INFO + * sex 性别 + * Age 年龄 + * Height 身高 + * Weight 体重 + * stepLength 步长 + * deviceId 设备ID + */ + public static final String Gender = "MyGender"; + public static final String Age = "MyAge"; + public static final String Height = "MyHeight"; + public static final String Weight = "MyWeight"; + public static final String Stride = "MyStride"; + public static final String KUserDeviceId = "deviceId"; + + + /* + * GET_DEVICE_INFO + * distanceUnit 距离单位 + * hourState 12小时24小时显示 + * handleEnable 抬手检查使能标志 + * handleSign 抬手检测左右手标志 + * screenState 横竖屏显示 + * anceEnable ANCS使能开关 + */ + public static final String DistanceUnit = "distancUnit"; + public static final String TimeUnit = "timeUnit"; + public static final String TempUnit = "temperatureUnit"; + public static final String WristOn = "wristOn"; + public static final String TemperatureUnit = "TemperatureUnit"; + public static final String NightMode = "NightMode"; + public static final String LeftOrRight = "handleSign"; + //public static final String ScreenShow = "screenState"; + public static final String Dialinterface = "dialinterface"; + public static final String SocialDistancedwitch = "SocialDistancedwitch"; + public static final String ChineseOrEnglish= "ChineseOrEnglish"; + public static final String Lauage= "Lauage"; + public static final String ScreenBrightness = "dcreenBrightness"; + public static final String KBaseHeart = "baseHeartRate"; + public static final String isHorizontalScreen = "isHorizontalScreen"; + + public static final String Year = "Year"; + public static final String Month = "Month"; + public static final String Day = "Day"; + public static final String MenstrualPeriod_Lenth = "MenstrualPeriod_Lenth"; + public static final String MenstrualPeriod_Period = "MenstrualPeriod_Period"; + + /* + * SET_STEP_MODEL + *totalSteps 总步数 + *calories 卡路里 + *distance 距离 + *time 时间 + *heartValue 心率值 + */ + + public static final String Step = "step"; + public static final String Calories = "calories"; + public static final String Distance = "distance"; + public static final String ExerciseMinutes = "exerciseMinutes"; + public static final String HeartRate = "heartRate"; + public static final String ActiveMinutes = "ExerciseTime"; + public static final String TempData = "TempData"; + public static final String StepGoal = "stepGoal"; // 目标步数值 GET_GOAL + public static final String BatteryLevel = "batteryLevel"; // 电量级别 READ_DEVICE_BATTERY + public static final String Chargingstate = "Chargingstate"; // 充电状态 + public static final String Voltage_value = "VoltageValue"; // 电压值 + public static final String MacAddress = "macAddress"; // MAC地址 READ_MAC_ADDRESS + public static final String DeviceVersion = "deviceVersion"; // 版本号 READ_VERSION + public static final String DeviceName = "deviceName"; // 设备名称 GET_DEVICE_NAME + public static final String TemperatureCorrectionValue = "TemperatureCorrectionValue"; // 设备名称 GET_DEVICE_NAME + + /* + * GET_AUTOMIC_HEART + *workModel 工作模式 + *heartStartHour 开始运动时间的小时 + *heartStartMinter 开始运动时间的分钟 + *heartEndHour 结束运动时间的小时 + *heartEndMinter 结束运动时间的分钟 + *heartWeek 星期使能 + *workTime 工作模式时间 + */ + public static final String WorkMode = "workModel"; + public static final String StartTime = "heartStartHour"; + public static final String KHeartStartMinter = "heartStartMinter"; + public static final String EndTime = "heartEndHour"; + public static final String KHeartEndMinter = "heartEndMinter"; + public static final String Weeks = "weekValue"; + public static final String IntervalTime = "intervalTime"; + public static final String Time = "Time"; + public static final String PPG = "PPG"; + + + /* + * READ_SPORT_PERIOD + *StartTimeHour 开始运动时间的小时 + *StartTimeMin 开始运动时间的分钟 + *EndTimeHour 结束运动时间的小时 + *EndTimeMin 结束运动时间的分钟 + *Week 星期使能 + *KSportNotifierTime 运动提醒周期 + */ + public static final String StartTimeHour = "sportStartHour"; + public static final String StartTimeMin = "sportStartMinter"; + public static final String EndTimeHour = "sportEndHour"; + public static final String EndTimeMin = "sportEndMinter"; + + public static final String LeastSteps = "leastSteps"; + + /* + * GET_STEP_DATA + *historyDate 日期:年月日 + *historySteps 步数 + *historyTime 运动时间 + *historyDistance 距离 + *Calories 卡路里 + *historyGoal 目标 + */ + public static final String Date = "date"; + public static final String Size = "size"; + public static final String Goal = "goal"; + + + + /* + * GET_STEP_DETAIL + *Date 日期:年月日时分秒 + *ArraySteps 步数 + *Calories 卡路里 + *Distance 距离 + *KDetailMinterStep 10分钟内每一分钟的步数 + */ + + public static final String ArraySteps = "arraySteps"; + + public static final String KDetailMinterStep = "detailMinterStep"; + public static final String temperature = "temperature"; + public static final String axillaryTemperature = "axillaryTemperature"; + + /* + * GET_SLEEP_DETAIL + *Date 日期:年月日时分秒 + *KSleepLength 睡眠数据的长度 + *ArraySleep 5分钟的睡眠质量 (总共24个数据,每一个数据代表五分钟) + */ + + public static final String KSleepLength = "sleepLength"; + public static final String ArraySleep = "arraySleepQuality"; + public static final String sleepUnitLength = "sleepUnitLength";//是不是一分钟的睡眠数据 1为1分钟数据 0为5分钟数据 + + /* + * GET_HEART_DATA + *Date 日期:年月日时分秒 + *ArrayDynamicHR 10秒一个心率值,总共12个心率值 + */ + + public static final String ArrayDynamicHR = "arrayDynamicHR"; + public static final String Blood_oxygen = "Blood_oxygen"; + + + + /* + * GET_ONCE_HEARTDATA + *Date 日期:年月日时分秒 + *StaticHR 心率值 + */ + + public static final String StaticHR = "onceHeartValue"; + + /* + * GET_HRV_DATA + *Date 日期:年月日时分秒 + *HRV HRV值 + *VascularAging 血管老化度值 + *HeartRate 心率值 + *Stress 疲劳度 + */ + + public static final String HRV = "hrv"; + public static final String VascularAging = "vascularAging"; + public static final String Fatiguedegree = "fatigueDegree"; + + public static final String Stress = "stress"; + public static final String HighPressure = "highPressure"; + public static final String LowPressure = "lowPressure"; + public static final String highBP = "highBP"; + public static final String lowBP = "lowBP"; + + /* + *GET_ALARM + *KAlarmId 0到4闹钟编号 + *ClockType 闹钟类型 + *ClockTime 闹钟时间的小时 + *KAlarmMinter 闹钟时间的分钟 + *Week 星期使能 + *KAlarmLength 长度 + *KAlarmContent 文本的内容 + */ + public static final String KAlarmId = "alarmId"; + public static final String OpenOrClose = "clockOpenOrClose"; + public static final String ClockType = "clockType"; + public static final String ClockTime = "alarmHour"; + public static final String KAlarmMinter = "alarmMinter"; + public static final String Week = "weekValue"; + public static final String KAlarmLength = "alarmLength"; + public static final String KAlarmContent = "dicClock"; + + + /***********************GET_HRV_TESTDATA***************************************************/ + /* + *KBloodTestLength 数据长度 + *KBloodTestProgress 进度 + *KBloodTestValue 本次PPG获得的值 + *KBolldTestCurve 本次波型的高度 + */ + public static final String KBloodTestLength = "bloodTestLength"; + public static final String KBloodTestProgress = "bloodTestProgress"; + public static final String KBloodTestValue = "bloodTestValue"; + public static final String KBloodTestCurve = "bloodTestCurve"; + + /* + *KBloodResultPercent 反弹的百分比 + *KBloodResultRebound 平均反弹高度 + *KBloodResultMax 最大高度 + *KBloodResultRank 结果级别(1到6) + */ + public static final String KBloodResultPercent = "bloodPercent"; + public static final String KBloodResultRebound = "bloodRebound"; + public static final String KBloodResultMax = "bloodResultMax"; + public static final String KBloodResultRank = "bloodResultRank"; + + + /* + *KHrvTestProgress 进度 + *KHrvTestWidth 本次心跳的宽度 + *KHrvTestValue 心率值 + */ + public static final String KHrvTestProgress = "hrvTestProgress"; + public static final String KHrvTestWidth = "hrvTestWidth"; + public static final String KHrvTestValue = "hrvTestValue"; + + /* + *KHrvResultState SDNN结果 如果是0,说明检测失败 + *KHrvResultAvg SDNN平均值 + *KHrvResultTotal 总SDNN结果 + *KHrvResultCount 有效数据个数 + *KHrvResultTired 疲劳指数据 + *KHrvResultValue 心率值 + */ + public static final String KHrvResultState = "hrvResultState"; + public static final String KHrvResultAvg = "hrvResultAvg"; + public static final String KHrvResultTotal = "hrvResultTotal"; + public static final String KHrvResultCount = "hrvResultCount"; + public static final String KHrvResultTired = "hrvResultTired"; + public static final String KHrvResultValue = "hrvResultValue"; + + + /* + *KDisturbState 1:开始运动 0:停止运动 + *KSlipHand 1: 带在手上 0;脱手。 + *KPPGData PPG的波型值 + */ + public static final String KDisturbState = "disturbState"; + public static final String KSlipHand = "slipHand"; + public static final String KPPGData = "ppgData"; + public static final String KPPIData = "ppiData"; + + public static final String ppgResult = "ppgResult"; + + public static final String ppgStartSucessed="ppgStartSucessed"; + public static final String ppgStartFailed="ppgStartFailed"; + public static final String ppgStop="ppgStop"; + public static final String ppgQuit="ppgQuit"; + public static final String ppgMeasurementProgress="ppgMeasurementProgress"; + + + + + + /* + *@param Date 时间:年月日时分秒 + *@param Latitude 纬度数据 + *@param Longitude 经度数据 + */ + + + public static final String Latitude = "locationLatitude"; + public static final String Longitude = "locationLongitude"; + + public static final String KActivityLocationTime = "ActivityLocationTIme"; + public static final String KActivityLocationLatitude = "ActivityLocationLatitude"; + public static final String KActivityLocationLongitude = "ActivityLocationLongitude"; + public static final String KActivityLocationCount = "KActivityLocationCount"; +/* + * GET_SPORTMODEL_DATA + *@param Date 时间:年月日时分秒 + *@param ActivityMode 运动类型 + 0=Run, + 1=Cycling, + 2=Swimming, + 3=Badminton, + 4=Football, + 5=Tennis, + 6=Yoga, + 7=Medication, + 8=Dance + + *@param HeartRate 心率 + *@param ActiveMinutes 运动时间 + *@param Step 运动步数 + *@param Pace 运动速度 + *@param Calories 卡路里 + *@param Distance 距离 + */ + + + public static final String ActivityMode = "sportModel"; + public static final String Pace = "sportModelSpeed"; + + public static final String KDataID = "KDataID"; + public static final String KPhoneDataLength = "KPhoneDataLength"; + public static final String KClockLast = "KClockLast"; + + + public static final String TakePhotoMode = "TakePhotoMode"; + public static final String KFunction_tel = "TelMode"; + public static final String KFunction_reject_tel = "RejectTelMode"; + + public static final String FindMobilePhoneMode = "FindMobilePhoneMode"; + public static final String KEnable_exercise = "KEnable_exercise"; + public static final String ECGQualityValue = "ECGQualityValue"; + + public static final String ECGResultValue = "ECGResultVALUE"; + public static final String ECGHrvValue = "ECGHrvValue"; + public static final String ECGAvBlockValue = "ECGAvBlockValue"; + public static final String ECGHrValue = "ECGHrValue"; + public static final String PPGHrValue = "PPGHrValue"; + public static final String ECGStreesValue = "ECGStreesValue"; + public static final String ECGhighBpValue = "ECGhighBpValue"; + public static final String ECGLowBpValue = "ECGLowBpValue"; + public static final String ECGMoodValue = "ECGMoodValue"; + public static final String ECGBreathValue = "ECGBreathValue"; + public static final String KEcgDataString = "KEcgDataString"; // ecg + public static final String ECGValue = "ECGValue"; + public static final String PPGValue = "PPGValue"; + public static final String EcgStatus = "EcgStatus"; + public static final String EcgSBP = "PPGSBP"; + public static final String EcgDBP = "PPGDBP"; + public static final String EcgHR = "PPGHR"; + public static final String WaveformDownTime = "WaveformDownTime"; + public static final String WaveformRiseTime = "WaveformRiseTime"; + + public static final String EcgGender = "Gender"; + public static final String EcgAge = "Age"; + public static final String EcgHeight = "Height"; + public static final String EcgWeight = "Weight"; + + +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/AutoMode.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/AutoMode.java new file mode 100644 index 00000000..63ab1b1a --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/AutoMode.java @@ -0,0 +1,5 @@ +package com.jstyle.blesdk2301.model; + +public enum AutoMode { + AutoHeartRate, AutoSpo2,AutoTemp,AutoHrv +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/AutoTestMode.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/AutoTestMode.java new file mode 100644 index 00000000..a5dfae77 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/AutoTestMode.java @@ -0,0 +1,5 @@ +package com.jstyle.blesdk2301.model; + +public enum AutoTestMode { + AutoHeartRate, AutoSpo2, +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Clock.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Clock.java new file mode 100644 index 00000000..cc98963b --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Clock.java @@ -0,0 +1,87 @@ +package com.jstyle.blesdk2301.model; + +import java.io.Serializable; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class Clock extends SendData implements Serializable { + + int number; + int type; + int hour; + int minute; + byte week; + String content; + boolean enable; + + public boolean isEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getHour() { + return hour; + } + + public void setHour(int hour) { + this.hour = hour; + } + + public int getMinute() { + return minute; + } + + public void setMinute(int minute) { + this.minute = minute; + } + + public int getWeek() { + return week; + } + + public void setWeek(byte week) { + this.week = week; + } + + @Override + public String toString() { + return "Clock{" + + "number=" + number + + ", type=" + type + + ", hour=" + hour + + ", minute=" + minute + + ", week=" + week + + ", content='" + content + '\'' + + ", enable=" + enable + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Device.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Device.java new file mode 100644 index 00000000..451a61d2 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Device.java @@ -0,0 +1,103 @@ +package com.jstyle.blesdk2301.model; + +import android.bluetooth.BluetoothDevice; + +import java.io.Serializable; +import java.util.concurrent.ScheduledThreadPoolExecutor; + + +public class Device implements Serializable{ + String name;//设备名字 + String mac;//设备的mac + int productID;//产品id,预留 + BluetoothDevice getBluetoothDevice;//蓝牙 + boolean isconted=false;//蓝牙是否连接 + boolean IsPaired=false;//是否是配对设备 + boolean isdfu=false;//是否直接升级 + int riss=100; + + public int getRiss() { + return riss; + } + + public void setRiss(int riss) { + this.riss = riss; + } + + ScheduledThreadPoolExecutor time=null;//每一个设备轮询器 + + public boolean isIsdfu() { + return isdfu; + } + + public void setIsdfu(boolean isdfu) { + this.isdfu = isdfu; + } + + public ScheduledThreadPoolExecutor getTime() { + return time; + } + + public void setTime(ScheduledThreadPoolExecutor time) { + this.time = time; + } + public boolean isPaired() { + return IsPaired; + } + + public void setPaired(boolean paired) { + IsPaired = paired; + } + + public boolean isIsconted() { + return isconted; + } + + public void setIsconted(boolean isconted) { + this.isconted = isconted; + } + + public String getName() { + return name==null?"":this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMac() { + return mac==null?"":this.mac; + } + + public void setMac(String mac) { + this.mac = mac; + } + + public int getProductID() { + return productID; + } + + public void setProductID(int productID) { + this.productID = productID; + } + + public BluetoothDevice getBluetoothDevice() { + return getBluetoothDevice; + } + + public void setBluetoothDevice(BluetoothDevice bluetoothDevice) { + this.getBluetoothDevice = bluetoothDevice; + } + + + @Override + public String toString() { + return "Device{" + + "name='" + name + '\'' + + ", mac='" + mac + '\'' + + ", productID=" + productID + + ", getBluetoothDevice=" + getBluetoothDevice + + ", isconted=" + isconted + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/DeviceBean.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/DeviceBean.java new file mode 100644 index 00000000..a761263e --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/DeviceBean.java @@ -0,0 +1,29 @@ +package com.jstyle.blesdk2301.model; + +import java.util.List; +import java.util.Map; + +/** + * Created by Administrator on 2018/4/28. + */ + +public class DeviceBean { + List>dataList; + boolean finish; + + public List> getDataList() { + return dataList; + } + + public void setDataList(List> dataList) { + this.dataList = dataList; + } + + public boolean isFinish() { + return finish; + } + + public void setFinish(boolean finish) { + this.finish = finish; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/DeviceName.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/DeviceName.java new file mode 100644 index 00000000..708cfeb5 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/DeviceName.java @@ -0,0 +1,17 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/4/9. + */ + +public class DeviceName extends SendData{ + String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/ExerciseMode.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/ExerciseMode.java new file mode 100644 index 00000000..d91859a7 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/ExerciseMode.java @@ -0,0 +1,56 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/8/2. + */ + +public class ExerciseMode extends SendData { + public static final int Status_START=1; + public static final int Status_PAUSE=2; + public static final int Status_CONTUINE=3; + public static final int Status_FINISH=4; + + public static final int Mode_RUN=0; + public static final int Mode_CYCLING=1; + public static final int Mode_BADMINTON=2; + public static final int Mode_FOOTBALL=3; + public static final int Mode_TENNIS=4; + public static final int Mode_YOGA=5; + public static final int Mode_BREATH=6; + public static final int Mode_DANCE=7; + public static final int Mode_BASKETBALL=8; + public static final int Mode_Walk=9; + public static final int Mode_workout=10; + public static final int Mode_Cricket=11; + public static final int Mode_Hiking=12; + public static final int Mode_Aerobics=13; + public static final int Mode_PingPong=14; + public static final int Mode_RopeJump=15; + public static final int Mode_Situps=16; + public static final int Volleyball=17; + + + public static int[]modes=new int[]{Mode_RUN,Mode_CYCLING,Mode_BADMINTON,Mode_FOOTBALL, + Mode_TENNIS,Mode_YOGA,Mode_BREATH,Mode_DANCE,Mode_BASKETBALL,Mode_Walk,Mode_workout + ,Mode_Cricket,Mode_Hiking,Mode_Aerobics,Mode_PingPong, Mode_RopeJump,Mode_Situps,Volleyball}; + int exerciseMode; + int enableStatus; + public int getExerciseMode(int position){ + return modes[position]; + } + public int getExerciseMode() { + return exerciseMode; + } + + public void setExerciseMode(int exerciseMode) { + this.exerciseMode = exerciseMode; + } + + public int getEnableStatus() { + return enableStatus; + } + + public void setEnableStatus(int enableStatus) { + this.enableStatus = enableStatus; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/ExtendedBluetoothDevice.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/ExtendedBluetoothDevice.java new file mode 100644 index 00000000..b27b5a2e --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/ExtendedBluetoothDevice.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, Nordic Semiconductor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jstyle.blesdk2301.model; + +import android.bluetooth.BluetoothDevice; + + +public class ExtendedBluetoothDevice { + /* package */public static final int NO_RSSI = -1000; + public final BluetoothDevice device; + /** The name is not parsed by some Android devices, f.e. Sony Xperia Z1 with Android 4.3 (C6903). It needs to be parsed manually. */ + public String name; + public int rssi; + + + public ExtendedBluetoothDevice(BluetoothDevice device, String name, int rssi) { + this.device = device; + this.name = name; + this.rssi=rssi; + } + + public ExtendedBluetoothDevice(final BluetoothDevice device) { + this.device = device; + this.name = device.getName(); + this.rssi = NO_RSSI; + } + + public boolean matches(final BluetoothDevice mdevice) { + return device.getAddress().equals(mdevice.getAddress()); + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/GetData.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/GetData.java new file mode 100644 index 00000000..e970b018 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/GetData.java @@ -0,0 +1,22 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/4/9. + */ + +public class GetData extends SendData{ + public final static byte DataNum_Delete= (byte) 0x99; + public final static int DataNum_Last=0; + /** + * 99删除数据,0获取数据 + */ + int dataNum=DataNum_Last; + + public int getDataNum() { + return dataNum; + } + + public void setDataNum(int dataNum) { + this.dataNum = dataNum; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyAutomaticHRMonitoring.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyAutomaticHRMonitoring.java new file mode 100644 index 00000000..e2f5d95c --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyAutomaticHRMonitoring.java @@ -0,0 +1,85 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class MyAutomaticHRMonitoring extends SendData{ + int open;//1 开启整个时间段都测量 2时间段内间隔测量 0关闭 + // 1. Enable measurement throughout the entire time period 2. Measure intervals within the time period 0. Close + int startHour;//开始小时 Starting hours + int startMinute;//开始分钟 Start minute + int endHour;//结束小时 End Hour + int endMinute;//结束分钟 End minute + int week;//星期一到星期日 开启选择 Monday to Sunday open selection + int time;//多少时间测试一次,单位是分钟。 How many times does it take to test, in minutes. + + public int getTime() { + return time; + } + + public void setTime(int time) { + this.time = time; + } + + public int getOpen() { + return open; + } + + public void setOpen(int open) { + this.open = open; + } + + public int getStartHour() { + return startHour; + } + + public void setStartHour(int startHour) { + this.startHour = startHour; + } + + public int getStartMinute() { + return startMinute; + } + + public void setStartMinute(int startMinute) { + this.startMinute = startMinute; + } + + public int getEndHour() { + return endHour; + } + + public void setEndHour(int endHour) { + this.endHour = endHour; + } + + public int getEndMinute() { + return endMinute; + } + + public void setEndMinute(int endMinute) { + this.endMinute = endMinute; + } + + public int getWeek() { + return week; + } + + public void setWeek(int week) { + this.week = week; + } + + @Override + public String toString() { + return "MyAutomaticHRMonitoring{" + + "open=" + open + + ", startHour=" + startHour + + ", startMinute=" + startMinute + + ", endHour=" + endHour + + ", endMinute=" + endMinute + + ", week=" + week + + ", time=" + time + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyDeviceInfo.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyDeviceInfo.java new file mode 100644 index 00000000..2de5df25 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyDeviceInfo.java @@ -0,0 +1,117 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/4/9. + */ + +public class MyDeviceInfo extends SendData{ + + boolean DistanceUnit;//1 mile(true),0km(false) + boolean is12Hour;//1(12小时)(true),0(24小时制)(false) + boolean Bright_screen;//1 turn on the bright screen, 0 turn off the bright screen + boolean Fahrenheit_or_centigrade;//Fahrenheit or centigrade + boolean isHorizontalScreen;//1 Horizontal screen, 0 Vertical screen + boolean Night_mode;//夜间模式 + boolean Temperature_unit;//夜间模式 + boolean Social_distance_switch;//社交距离开关 Social distance switch + int LauageNumber=-1;//中英文切换 Chinese_English_switch + int baseheart=60;//Basic heart rate + int ScreenBrightness=-1;//Screen brightness 屏幕亮度0-5 + int Dialinterface=-1;//表盘更换 Dial replacement 0-10 + + public boolean isTemperature_unit() { + return Temperature_unit; + } + + public void setTemperature_unit(boolean temperature_unit) { + Temperature_unit = temperature_unit; + } + + public int getLauageNumber() { + return LauageNumber; + } + + public void setLauageNumber(int lauageNumber) { + LauageNumber = lauageNumber; + } + + public boolean isSocial_distance_switch() { + return Social_distance_switch; + } + + public void setSocial_distance_switch(boolean social_distance_switch) { + Social_distance_switch = social_distance_switch; + } + + public boolean isNight_mode() { + return Night_mode; + } + + public void setNight_mode(boolean night_mode) { + Night_mode = night_mode; + } + + public boolean isDistanceUnit() { + return DistanceUnit; + } + + public void setDistanceUnit(boolean distanceUnit) { + DistanceUnit = distanceUnit; + } + + public boolean isIs12Hour() { + return is12Hour; + } + + public void setIs12Hour(boolean is12Hour) { + this.is12Hour = is12Hour; + } + + public boolean isBright_screen() { + return Bright_screen; + } + + public void setBright_screen(boolean bright_screen) { + Bright_screen = bright_screen; + } + + public boolean isFahrenheit_or_centigrade() { + return Fahrenheit_or_centigrade; + } + + public void setFahrenheit_or_centigrade(boolean fahrenheit_or_centigrade) { + Fahrenheit_or_centigrade = fahrenheit_or_centigrade; + } + + public boolean isHorizontalScreen() { + return isHorizontalScreen; + } + + public void setHorizontalScreen(boolean horizontalScreen) { + isHorizontalScreen = horizontalScreen; + } + + public int getBaseheart() { + return baseheart; + } + + public void setBaseheart(int baseheart) { + this.baseheart = baseheart; + } + + public int getScreenBrightness() { + return ScreenBrightness; + } + + public void setScreenBrightness(int screenBrightness) { + ScreenBrightness = screenBrightness; + } + + public int getDialinterface() { + return Dialinterface; + } + + public void setDialinterface(int dialinterface) { + Dialinterface = dialinterface; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyDeviceTime.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyDeviceTime.java new file mode 100644 index 00000000..0adc63f1 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyDeviceTime.java @@ -0,0 +1,86 @@ +package com.jstyle.blesdk2301.model; + +import java.util.Calendar; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class MyDeviceTime extends SendData{ + int year; + int month; + int day; + int hour; + int minute; + int second; + + public MyDeviceTime() { + Calendar calendar=Calendar.getInstance(); + this.year=calendar.get(Calendar.YEAR); + this.month=calendar.get(Calendar.MONTH)+1; + this.day=calendar.get(Calendar.DAY_OF_MONTH); + this.hour=calendar.get(Calendar.HOUR_OF_DAY); + this.minute=calendar.get(Calendar.MINUTE); + this.second=calendar.get(Calendar.SECOND); + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public int getHour() { + return hour; + } + + public void setHour(int hour) { + this.hour = hour; + } + + public int getMinute() { + return minute; + } + + public void setMinute(int minute) { + this.minute = minute; + } + + public int getSecond() { + return second; + } + + public void setSecond(int second) { + this.second = second; + } + + @Override + public String toString() { + return "MyDeviceTime{" + + "year=" + year + + ", month=" + month + + ", day=" + day + + ", hour=" + hour + + ", minute=" + minute + + ", second=" + second + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyPersonalInfo.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyPersonalInfo.java new file mode 100644 index 00000000..ffabc810 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MyPersonalInfo.java @@ -0,0 +1,66 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class MyPersonalInfo extends SendData{ + int sex;//1 male,0female + int age; + int height; + int weight; + int stepLength=70; + + + + public int getSex() { + return sex; + } + + public void setSex(int sex) { + this.sex = sex; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public int getStepLength() { + return stepLength; + } + + public void setStepLength(int stepLength) { + this.stepLength = stepLength; + } + + @Override + public String toString() { + return "MyPersonalInfo{" + + "sex=" + sex + + ", age=" + age + + ", height=" + height + + ", weight=" + weight + + ", stepLength=" + stepLength + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MySedentaryReminder.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MySedentaryReminder.java new file mode 100644 index 00000000..f2259639 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/MySedentaryReminder.java @@ -0,0 +1,94 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class MySedentaryReminder extends SendData{ + int startHour; + int startMinute; + int endHour; + int endMinute; + int week; + int intervalTime; + int leastStep; + boolean enable; + + public boolean isEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + + public int getStartHour() { + return startHour; + } + + public void setStartHour(int startHour) { + this.startHour = startHour; + } + + public int getStartMinute() { + return startMinute; + } + + public void setStartMinute(int startMinute) { + this.startMinute = startMinute; + } + + public int getEndHour() { + return endHour; + } + + public void setEndHour(int endHour) { + this.endHour = endHour; + } + + public int getEndMinute() { + return endMinute; + } + + public void setEndMinute(int endMinute) { + this.endMinute = endMinute; + } + + public int getWeek() { + return week; + } + + public void setWeek(int week) { + this.week = week; + } + + public int getIntervalTime() { + return intervalTime; + } + + public void setIntervalTime(int intervalTime) { + this.intervalTime = intervalTime; + } + + public int getLeastStep() { + return leastStep; + } + + public void setLeastStep(int leastStep) { + this.leastStep = leastStep; + } + + @Override + public String toString() { + return "MySedentaryReminder{" + + "startHour=" + startHour + + ", startMinute=" + startMinute + + ", endHour=" + endHour + + ", endMinute=" + endMinute + + ", week=" + week + + ", intervalTime=" + intervalTime + + ", leastStep=" + leastStep + + ", enable=" + enable + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Notifier.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Notifier.java new file mode 100644 index 00000000..f89f0096 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/Notifier.java @@ -0,0 +1,58 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class Notifier extends SendData{ + public static final int Data_Tel=0; + public static final int Data_Sms=1; + public static final int Data_WeChat=2; + public static final int Data_Facebook=3; + public static final int Data_Instagram=4; + public static final int Data_Skype=5; + public static final int Data_Telegram=6; + public static final int Data_Twitter=7; + public static final int Data_Vkclient=8; + public static final int Data_WhatApp=9; + public static final int Data_QQ=10; + public static final int Data_IN=11; + public static final int Data_Stop_Tel=0xff; + + int type; + String info=""; + String title=""; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + @Override + public String toString() { + return "Notifier{" + + "type=" + type + + ", info='" + info + '\'' + + ", title='" + title + '\'' + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/PregnancyCycle.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/PregnancyCycle.java new file mode 100644 index 00000000..6b17ae2a --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/PregnancyCycle.java @@ -0,0 +1,86 @@ +package com.jstyle.blesdk2301.model; + + + +/** + * 怀孕周期 + * 算法 开始到生产 280天 每7天算一周 + */ + +public class PregnancyCycle { + String address=""; + String userId=""; + String MenstrualPeriod_StartTime="1990-01-01";//经期开始时间 yyyy-MM-dd + String DueDateTime="";//预产期 + long MenstrualPeriod_Period=30;//经期周期,默认30天 21-35 + + + public PregnancyCycle() { + } + + + public PregnancyCycle(String address, String userId, + String MenstrualPeriod_StartTime, String DueDateTime, + long MenstrualPeriod_Period) { + this.address = address; + this.userId = userId; + this.MenstrualPeriod_StartTime = MenstrualPeriod_StartTime; + this.DueDateTime = DueDateTime; + this.MenstrualPeriod_Period = MenstrualPeriod_Period; + } + + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getMenstrualPeriod_StartTime() { + return MenstrualPeriod_StartTime; + } + + public void setMenstrualPeriod_StartTime(String menstrualPeriod_StartTime) { + MenstrualPeriod_StartTime = menstrualPeriod_StartTime; + } + + public String getDueDateTime() { + return DueDateTime; + } + + public void setDueDateTime(String dueDateTime) { + DueDateTime = dueDateTime; + } + + public long getMenstrualPeriod_Period() { + return MenstrualPeriod_Period; + } + + public void setMenstrualPeriod_Period(long menstrualPeriod_Period) { + MenstrualPeriod_Period = menstrualPeriod_Period; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + return "PregnancyCycle{" + + "address='" + address + '\'' + + ", userId='" + userId + '\'' + + ", MenstrualPeriod_StartTime='" + MenstrualPeriod_StartTime + '\'' + + ", DueDateTime='" + DueDateTime + '\'' + + ", MenstrualPeriod_Period=" + MenstrualPeriod_Period + + '}'; + } +} + + + diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/SendData.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/SendData.java new file mode 100644 index 00000000..12414ad3 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/SendData.java @@ -0,0 +1,8 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/4/8. + */ + +public class SendData { +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/SportPeriod.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/SportPeriod.java new file mode 100644 index 00000000..4ba7cb24 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/SportPeriod.java @@ -0,0 +1,89 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/1/16. + */ + +public class SportPeriod extends SendData { + int startHour; + int startMinute; + int endHour; + int endMinute; + int week; + int days; + int intervalTime; + int leastStep; + boolean enable; + + public boolean isEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + + public int getStartHour() { + return startHour; + } + + public void setStartHour(int startHour) { + this.startHour = startHour; + } + + public int getStartMinute() { + return startMinute; + } + + public void setStartMinute(int startMinute) { + this.startMinute = startMinute; + } + + public int getEndHour() { + return endHour; + } + + public void setEndHour(int endHour) { + this.endHour = endHour; + } + + public int getEndMinute() { + return endMinute; + } + + public void setEndMinute(int endMinute) { + this.endMinute = endMinute; + } + + public int getWeek() { + return week; + } + + public void setWeek(int week) { + this.week = week; + } + + public int getIntervalTime() { + return intervalTime; + } + + public void setIntervalTime(int intervalTime) { + this.intervalTime = intervalTime; + } + + public int getLeastStep() { + return leastStep; + } + + public void setLeastStep(int leastStep) { + this.leastStep = leastStep; + } + + public int getDays() { + return days; + } + + public void setDays(int days) { + this.days = days; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/StepModel.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/StepModel.java new file mode 100644 index 00000000..f40b862d --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/StepModel.java @@ -0,0 +1,25 @@ +package com.jstyle.blesdk2301.model; + +/** + * Created by Administrator on 2018/4/9. + */ + +public class StepModel extends SendData{ + boolean stepState;//true开启实时计步,false停止实时计步 + + public boolean isStepState() { + return stepState; + } + + public void setStepState(boolean stepState) { + this.stepState = stepState; + } + + + @Override + public String toString() { + return "StepModel{" + + "stepState=" + stepState + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/UserInfo.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/UserInfo.java new file mode 100644 index 00000000..b2049d4b --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/UserInfo.java @@ -0,0 +1,107 @@ +package com.jstyle.blesdk2301.model; + + +/** + * Created by Administrator on 2022/2/18. + */ +public class UserInfo { + + String phone=""; + String name=""; + String gender;//0男,1女 + String age="";//18 + String height="";//175 + String weight="";//75 + String ecgTitle=""; + String ecgReportTips=""; + String date=""; + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getAge() { + return age; + } + + public void setAge(String age) { + this.age = age; + } + + public String getHeight() { + return height; + } + + public void setHeight(String height) { + this.height = height; + } + + public String getWeight() { + return weight; + } + + public void setWeight(String weight) { + this.weight = weight; + } + + public String getEcgTitle() { + return ecgTitle; + } + + public void setEcgTitle(String ecgTitle) { + this.ecgTitle = ecgTitle; + } + + public String getEcgReportTips() { + return ecgReportTips; + } + + public void setEcgReportTips(String ecgReportTips) { + this.ecgReportTips = ecgReportTips; + } + + @Override + public String toString() { + return "UserInfo{" + + "phone='" + phone + '\'' + + ", name='" + name + '\'' + + ", gender='" + gender + '\'' + + ", age='" + age + '\'' + + ", height='" + height + '\'' + + ", weight='" + weight + '\'' + + ", ecgTitle='" + ecgTitle + '\'' + + ", ecgReportTips='" + ecgReportTips + '\'' + + ", date='" + date + '\'' + + '}'; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/WeatherData.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/WeatherData.java new file mode 100644 index 00000000..4bfa8621 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/WeatherData.java @@ -0,0 +1,49 @@ +package com.jstyle.blesdk2301.model; + +public class WeatherData { + int tempNow; + int tempHigh; + int tempLow; + String cityName=""; + int weatherId; + + public int getTempNow() { + return tempNow; + } + + public void setTempNow(int tempNow) { + this.tempNow = tempNow; + } + + public int getTempHigh() { + return tempHigh; + } + + public void setTempHigh(int tempHigh) { + this.tempHigh = tempHigh; + } + + public int getTempLow() { + return tempLow; + } + + public void setTempLow(int tempLow) { + this.tempLow = tempLow; + } + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public int getWeatherId() { + return weatherId; + } + + public void setWeatherId(int weatherId) { + this.weatherId = weatherId; + } +} diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/WomenHealth.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/WomenHealth.java new file mode 100644 index 00000000..c5a3a274 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/model/WomenHealth.java @@ -0,0 +1,264 @@ +package com.jstyle.blesdk2301.model; + +/** + * 女性健康 + */ +public class WomenHealth { + String userId=""; + String address=""; + String MenstrualPeriod_StartTime="1990-01-01";//经期开始时间 yyyy-MM-dd + long MenstrualPeriod_Lenth=7;//经期长度,默认7天,2-8 + long MenstrualPeriod_Period=30;//经期周期,默认30天 21-35 + long FlowRate=-1;//流量 -1没有数据 0-4等级 + long Dysmenorrhea=-1;//痛经 -1没有数据 0-4等级 + boolean Love=false;//爱爱 + long mood=-1;//心情 -1没有数据 0-4等级 + boolean start=false;//是否是第一个日期 + boolean yuejinqi=false;//是否是月经期 经期七天 + boolean yuceyuejinqi=false;//预测月经期 经期前3天 + + boolean yiyunqi=false;//是否是易孕期 经期七天后10天的日期 + boolean yuceyiyunqi=false;//预测易孕期 易孕期前3天 + boolean pailuanqi=false;//是否是排卵期 开始15后的一天 + + boolean up=false;//上升期还是下降器 + + + boolean edidt=false;//是否被编辑过 + int day=0;//每次循环的第几天 + + int[] Menstrual_symptoms = new int[32];//经期症状 + + + + public WomenHealth() { + } + + public WomenHealth(String userId, String address, + String MenstrualPeriod_StartTime, long MenstrualPeriod_Lenth, + long MenstrualPeriod_Period, long FlowRate, long Dysmenorrhea, + boolean Love, long mood, boolean start, boolean yuejinqi, + boolean yuceyuejinqi, boolean yiyunqi, boolean yuceyiyunqi, + boolean pailuanqi, boolean up, boolean edidt, int day, + int[] Menstrual_symptoms) { + this.userId = userId; + this.address = address; + this.MenstrualPeriod_StartTime = MenstrualPeriod_StartTime; + this.MenstrualPeriod_Lenth = MenstrualPeriod_Lenth; + this.MenstrualPeriod_Period = MenstrualPeriod_Period; + this.FlowRate = FlowRate; + this.Dysmenorrhea = Dysmenorrhea; + this.Love = Love; + this.mood = mood; + this.start = start; + this.yuejinqi = yuejinqi; + this.yuceyuejinqi = yuceyuejinqi; + this.yiyunqi = yiyunqi; + this.yuceyiyunqi = yuceyiyunqi; + this.pailuanqi = pailuanqi; + this.up = up; + this.edidt = edidt; + this.day = day; + this.Menstrual_symptoms = Menstrual_symptoms; + } + + + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public boolean isUp() { + return up; + } + + public void setUp(boolean up) { + this.up = up; + } + + public boolean isYuceyuejinqi() { + return yuceyuejinqi; + } + + public void setYuceyuejinqi(boolean yuceyuejinqi) { + this.yuceyuejinqi = yuceyuejinqi; + } + + public boolean isYuceyiyunqi() { + return yuceyiyunqi; + } + + public void setYuceyiyunqi(boolean yuceyiyunqi) { + this.yuceyiyunqi = yuceyiyunqi; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public boolean isStart() { + return start; + } + + public boolean isYuejinqi() { + return yuejinqi; + } + + public void setYuejinqi(boolean yuejinqi) { + this.yuejinqi = yuejinqi; + } + + public boolean isEdidt() { + return edidt; + } + + public void setEdidt(boolean edidt) { + this.edidt = edidt; + } + + public boolean isYiyunqi() { + return yiyunqi; + } + + public void setYiyunqi(boolean yiyunqi) { + this.yiyunqi = yiyunqi; + } + + public boolean isPailuanqi() { + return pailuanqi; + } + + public void setPailuanqi(boolean pailuanqi) { + this.pailuanqi = pailuanqi; + } + + public void setStart(boolean start) { + this.start = start; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getMenstrualPeriod_StartTime() { + return MenstrualPeriod_StartTime; + } + + public void setMenstrualPeriod_StartTime(String menstrualPeriod_StartTime) { + MenstrualPeriod_StartTime = menstrualPeriod_StartTime; + } + + public long getMenstrualPeriod_Lenth() { + return MenstrualPeriod_Lenth; + } + + public void setMenstrualPeriod_Lenth(long menstrualPeriod_Lenth) { + MenstrualPeriod_Lenth = menstrualPeriod_Lenth; + } + + public long getMenstrualPeriod_Period() { + return MenstrualPeriod_Period; + } + + public void setMenstrualPeriod_Period(long menstrualPeriod_Period) { + MenstrualPeriod_Period = menstrualPeriod_Period; + } + + public long getFlowRate() { + return FlowRate; + } + + public void setFlowRate(long flowRate) { + FlowRate = flowRate; + } + + public long getDysmenorrhea() { + return Dysmenorrhea; + } + + public void setDysmenorrhea(long dysmenorrhea) { + Dysmenorrhea = dysmenorrhea; + } + + public boolean isLove() { + return Love; + } + + public void setLove(boolean love) { + Love = love; + } + + public long getMood() { + return mood; + } + + public void setMood(long mood) { + this.mood = mood; + } + + public int[] getMenstrual_symptoms() { + return Menstrual_symptoms; + } + + public void setMenstrual_symptoms(int[] menstrual_symptoms) { + Menstrual_symptoms = menstrual_symptoms; + } + + + public boolean getLove() { + return this.Love; + } + + public boolean getStart() { + return this.start; + } + + public boolean getYuejinqi() { + return this.yuejinqi; + } + + public boolean getYiyunqi() { + return this.yiyunqi; + } + + public boolean getPailuanqi() { + return this.pailuanqi; + } + + public boolean getEdidt() { + return this.edidt; + } + + + public boolean getYuceyuejinqi() { + return this.yuceyuejinqi; + } + + public boolean getYuceyiyunqi() { + return this.yuceyiyunqi; + } + + + + public boolean getUp() { + return this.up; + } + + + +} + + + diff --git a/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/other/ResolveUtil.java b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/other/ResolveUtil.java new file mode 100644 index 00000000..d1e46066 --- /dev/null +++ b/android/blesdk_2301/src/main/java/com/jstyle/blesdk2301/other/ResolveUtil.java @@ -0,0 +1,1704 @@ +package com.jstyle.blesdk2301.other; + + +import android.util.Log; + +import com.jstyle.blesdk2301.Util.BleSDK; +import com.jstyle.blesdk2301.constant.BleConst; +import com.jstyle.blesdk2301.constant.DeviceConst; +import com.jstyle.blesdk2301.constant.DeviceKey; +import com.jstyle.blesdk2301.model.DeviceBean; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.TimeZone; + +/** + * Created by Administrator on 2018/1/17. + */ + +public class ResolveUtil { + + public static int getBcd(String value) { + return Integer.parseInt(value, 16); + } + /** + * crc校验 + * + * @param value + */ + public static void crcValue(byte[] value) { + byte crc = 0; + for (int i = 0; i < value.length - 1; i++) { + crc += value[i]; + } + value[value.length - 1] = (byte) (crc & 0xff); + } + + public static byte getTimeValue(int value) { + String data = value + ""; + Integer m = Integer.parseInt(data, 16); + return (byte) m.intValue(); + } + + + public static String bcd2String(byte bytes) { + StringBuffer temp = new StringBuffer(); + temp.append((byte) ((bytes & 0xf0) >>> 4)); + temp.append((byte) (bytes & 0x0f)); + return temp.toString(); + } + + /** + * 设备时间 + * + * @param value + * @return + */ + public static Map getDeviceTime(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDeviceTime); + maps.put(DeviceKey.End,true); + + MapmapData=new HashMap<>(); + String date = "20"+ByteToHexString(value[1]) + "-" + + ByteToHexString(value[2]) + "-" + ByteToHexString(value[3]) + " " + + ByteToHexString(value[4]) + ":" + ByteToHexString(value[5]) + ":" + ByteToHexString(value[6]); + String gpsDate = ByteToHexString(value[9]) + "." + + ByteToHexString(value[10]) + "." + ByteToHexString(value[11]) ; + mapData.put(DeviceKey.DeviceTime, date); + mapData.put(DeviceKey.GPSTime, gpsDate); + maps.put(DeviceKey.Data, mapData); + return maps; + } + public static String getGpsTime(byte[] value) { + + String gpsDate = ByteToHexString(value[9]) + "." + + ByteToHexString(value[10]) + "." + ByteToHexString(value[11]) ; + + return gpsDate; + } + + /** + * 用户信息 + * + * @param value + * @return + */ + public static Map getUserInfo(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetPersonalInfo); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + String[] userInfo = new String[6]; + for (int i = 0; i < 5; i++) { + userInfo[i] = String.valueOf(getValue(value[i + 1], 0)); + } + String deviceId = ""; + for (int i = 6; i < 12; i++) { + if (value[i] == 0) + continue; + deviceId += (char) getValue(value[i], 0); + } + userInfo[5] = deviceId; + mapData.put(DeviceKey.Gender, userInfo[0]); + mapData.put(DeviceKey.Age, userInfo[1]); + mapData.put(DeviceKey.Height, userInfo[2]); + mapData.put(DeviceKey.Weight, userInfo[3]); + mapData.put(DeviceKey.Stride, userInfo[4]); + mapData.put(DeviceKey.KUserDeviceId, userInfo[5]); + return maps; + } + + public static Map GetAutomaticSpo2Monitoring(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetAutomaticSpo2Monitoring); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 10; + int length = value.length; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if (value[length-1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date = "20"+ByteToHexString(value[3 + i * count]) + "." + + ByteToHexString(value[4 + i * count]) + "." + ByteToHexString(value[5 + i * count]) + " " + + ByteToHexString(value[6 + i * count]) + ":" + ByteToHexString(value[7 + i * count]) + ":" + ByteToHexString(value[8 + i * count]); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.Blood_oxygen, String.valueOf(getValue(value[9 + i * count], 0))); + list.add(hashMap); + } + + return maps; + } + /** + * 设备信息 + * + * @param value + * @return + */ + public static Map getDeviceInfo(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDeviceInfo); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + mapData.put(DeviceKey.DistanceUnit, String.valueOf(getValue(value[ 1], 0))); + mapData.put(DeviceKey.TimeUnit, String.valueOf(getValue(value[ 2], 0))); + mapData.put(DeviceKey.WristOn, String.valueOf(getValue(value[ 3], 0))); + mapData.put(DeviceKey.TempUnit, String.valueOf(getValue(value[ 4], 0))); + mapData.put(DeviceKey.NightMode, String.valueOf(getValue(value[ 5], 0))); + mapData.put(DeviceKey.KBaseHeart, String.valueOf(getValue(value[ 9], 0))); + mapData.put(DeviceKey.ScreenBrightness, String.valueOf(getValue(value[ 11], 0))); + mapData.put(DeviceKey.Dialinterface, String.valueOf(getValue(value[12], 0))); + mapData.put(DeviceKey.SocialDistancedwitch, String.valueOf(getValue(value[13], 0))); + mapData.put(DeviceKey.Lauage, String.valueOf(getValue(value[14], 0))); + return maps; + } + + /** + * 实时计步信息 + * + * @param value + * @return + */ + public static Map getActivityData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.RealTimeStep); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + String[] activityData = new String[6]; + int step = 0; + float cal = 0; + float distance = 0; + int time = 0; + int heart = 0; + int exerciseTime = 0; + for (int i = 1; i < 5; i++) { + step += getValue(value[i], i - 1); + } + for (int i = 5; i < 9; i++) { + cal += getValue(value[i], i - 5); + } + for (int i = 9; i < 13; i++) { + distance += getValue(value[i], i - 9); + } + for (int i = 13; i < 17; i++) { + time += getValue(value[i], i - 13); + } + for (int i = 17; i < 21; i++) { + exerciseTime += getValue(value[i], i - 17); + } + heart = getValue(value[21], 0); + int temp = getValue(value[22], 0)+getValue(value[23],1); + NumberFormat numberFormat = getNumberFormat(1); + BigDecimal bigDecimal=new BigDecimal(String.valueOf(cal/100)); + BigDecimal bigDecimaCal= bigDecimal.setScale(1, RoundingMode.HALF_DOWN); + activityData[0] = String.valueOf(step); + activityData[1] = bigDecimaCal.floatValue()+""; + numberFormat.setMinimumFractionDigits(2); + activityData[2] = numberFormat.format(distance / 100); + activityData[3] = String.valueOf(time/60); + activityData[4] = String.valueOf(heart); + activityData[5] = String.valueOf(exerciseTime); + mapData.put(DeviceKey.Step, activityData[0]); + mapData.put(DeviceKey.Calories, activityData[1]); + mapData.put(DeviceKey.Distance, activityData[2]); + mapData.put(DeviceKey.ExerciseMinutes, activityData[3]); + mapData.put(DeviceKey.HeartRate, activityData[4]); + mapData.put(DeviceKey.ActiveMinutes, activityData[5]); + numberFormat.setMinimumFractionDigits(1); + mapData.put(DeviceKey.TempData,numberFormat.format(temp*0.1f)); + mapData.put(DeviceKey.Blood_oxygen, String.valueOf(getValue(value[24], 0))); + return maps; + } + + public static Map get3d(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetMAC); + maps.put(DeviceKey.End,true); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + for(int i=0;i hashMap = new HashMap<>(); + int valueddd = i * 6; + int data = getValue(value[1 + valueddd], 0) + getValue(value[2 + valueddd], 1); + int data2 = getValue(value[3 + valueddd], 0) + getValue(value[4 + valueddd], 1); + int data3 = getValue(value[5 + valueddd], 0) + getValue(value[6 + valueddd], 1); + hashMap.put(DeviceKey.arrayX, data); + hashMap.put(DeviceKey.arrayY, data2); + hashMap.put(DeviceKey.arrayZ, data3); + list.add(hashMap); + } + return maps; + } + + + public static Map getPPG(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.Getppg); + maps.put(DeviceKey.End,true); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + byte[] bs = new byte[value.length-3]; + System.arraycopy(value, 3, bs, 0, bs.length); + for(int i=0;i hashMap = new HashMap<>(); + int valueddd = i * 2; + int data = getValue(value[valueddd], 0) + getValue(value[valueddd+1], 1); + hashMap.put(DeviceKey.DataType, value[1]); + hashMap.put(DeviceKey.arrayPpgRawData, data); + list.add(hashMap); + } + return maps; + } + + + + /** + * 步数目标 + * + * @param value + * @return + */ + public static Map getGoal(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetStepGoal); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + int goal = 0; + for (int i = 0; i < 4; i++) { + goal += getValue(value[i + 1], i); + } + mapData.put(DeviceKey.StepGoal, String.valueOf(goal)); + return maps; + } + + /** + * 设备电量 + * + * @param value + * @return + */ + public static Map getDeviceBattery(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDeviceBatteryLevel); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + int battery = getValue(value[1], 0); + /*int Chargingstate = getValue(value[2], 0); + int Voltage_value = getValue(value[3 ], 0) + getValue(value[4 ], 1);*/ + mapData.put(DeviceKey.BatteryLevel, String.valueOf(battery)); + /* mapData.put(DeviceKey.Chargingstate, String.valueOf(Chargingstate)); + mapData.put(DeviceKey.Voltage_value, String.valueOf(Voltage_value));*/ + return maps; + } + + /** + * 设备mac地址 + * + * @param value + * @return + */ + public static Map getDeviceAddress(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDeviceMacAddress); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + StringBuilder sb = new StringBuilder(); + for (int i = 1; i < 7; i++) { + sb.append(String.format("%02X", value[i])).append(":"); + } + String address = sb.toString(); + mapData.put(DeviceKey.MacAddress, address.substring(0, address.lastIndexOf(":"))); + return maps; + } + + /** + * 设备版本号 + * + * @param value + * @return + */ + public static Map getDeviceVersion(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDeviceVersion); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 1; i < 5; i++) { + stringBuffer.append(String.format("%X", value[i])).append(i == 4 ? "" : "."); + } + mapData.put(DeviceKey.DeviceVersion, stringBuffer.toString()); + return maps; + } + + + + public static Map Reset() { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.CMD_Reset); + maps.put(DeviceKey.Data, new HashMap<>()); + maps.put(DeviceKey.End,true); + return maps; + } + public static Map MCUReset() { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.CMD_MCUReset); + maps.put(DeviceKey.Data, new HashMap<>()); + maps.put(DeviceKey.End,true); + return maps; + } + + public static Map Notify() { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.Notify); + maps.put(DeviceKey.Data, new HashMap<>()); + maps.put(DeviceKey.End,true); + return maps; + } + + /** + * 设备名字 + * + * @param value + * @return + */ + public static Map getDeviceName(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.CMD_Get_Name); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + String name = ""; + for (int i = 1; i < 15; i++) { + int charValue=getValue(value[i],0); + if(charValue==0||charValue>127)continue; + name += (char) charValue; + } + mapData.put(DeviceKey.DeviceName, name); + return maps; + } + + public static String getByteString(byte b) { + byte[] array = new byte[8]; + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i <= 6; i++) { + array[i] = (byte) (b & 1); + b = (byte) (b >> 1); + stringBuffer.append(String.valueOf(array[i])).append(i == 6 ? "" : "-"); + } + return stringBuffer.toString(); + } + + public static String getByteArray(byte b) { + byte[] array = new byte[8]; + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i <= 7; i++) { + array[i] = (byte) (b & 1); + b = (byte) (b >> 1); + stringBuffer.append(String.valueOf(array[i])); + } + return stringBuffer.toString(); + } + + /** + * 自动测量心率时间段 + * + * @param value + * @return + */ + public static Map getAutoHeart(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetAutomatic); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + String[] autoHeart = new String[7]; + int enable = getValue(value[1], 0); + String startHour = ByteToHexString(value[2]); + String startMin = ByteToHexString(value[3]); + String stopHour = ByteToHexString(value[4]); + String stopMin = ByteToHexString(value[5]); + String week = getByteString(value[6]); + int time = getValue(value[7], 0) + getValue(value[8], 1); + autoHeart[0] = String.valueOf(enable); + autoHeart[1] = startHour; + autoHeart[2] = startMin; + autoHeart[3] = stopHour; + autoHeart[4] = stopMin; + autoHeart[5] = week; + autoHeart[6] = String.valueOf(time); + mapData.put(DeviceKey.WorkMode, autoHeart[0]); + mapData.put(DeviceKey.StartTime, autoHeart[1]); + mapData.put(DeviceKey.KHeartStartMinter, autoHeart[2]); + mapData.put(DeviceKey.EndTime, autoHeart[3]); + mapData.put(DeviceKey.KHeartEndMinter, autoHeart[4]); + mapData.put(DeviceKey.Weeks, autoHeart[5]); + mapData.put(DeviceKey.IntervalTime, autoHeart[6]); + return maps; + } + + /** + * 读取血压校准 + * + */ + public static Map ReadOxy(byte[] value) { + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.DataType, BleConst.GetBloodpressure_calibration); + hashMap.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + hashMap.put(DeviceKey.Data, mapData); + mapData.put(DeviceKey.KHrvBloodLowPressure, getValue(value[1],0)+10+""); + mapData.put(DeviceKey. KHrvBloodHighPressure, getValue(value[3],0)+10+""); + return hashMap; + } + + public static Map getSpo2(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GEtSpo2); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); //29 01 01 39 01 30 01 30 7F 00 00 00 00 00 00 45 + String time = ByteToHexString(value[3]); + String startHour = ByteToHexString(value[4]); + String startMin = ByteToHexString(value[5]); + String stopHour = ByteToHexString(value[6]); + String stopMin = ByteToHexString(value[7]); + String week = getByteString(value[8]); + mapData.put(DeviceKey.StartTime, startHour); + mapData.put(DeviceKey.KHeartStartMinter, startMin); + mapData.put(DeviceKey.EndTime, stopHour); + mapData.put(DeviceKey.KHeartEndMinter, stopMin); + mapData.put(DeviceKey.Weeks, week); + mapData.put(DeviceKey.IntervalTime, time); + return maps; + } + + /** + * 运动提醒 + * + * @param value + * @return + */ + public static Map getActivityAlarm(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetSedentaryReminder); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + String[] activityAlarm = new String[7]; + String startHour = ByteToHexString(value[1]); + String startMin = ByteToHexString(value[2]); + String stopHour = ByteToHexString(value[3]); + String stopMin = ByteToHexString(value[4]); + String week = getByteString(value[5]); + int time = getValue(value[6], 0); + int step = getValue(value[7], 0); + activityAlarm[0] = startHour; + activityAlarm[1] = startMin; + activityAlarm[2] = stopHour; + activityAlarm[3] = stopMin; + activityAlarm[4] = week; + activityAlarm[5] = String.valueOf(time); + activityAlarm[6] = String.valueOf(step); + mapData.put(DeviceKey.StartTimeHour, activityAlarm[0]); + mapData.put(DeviceKey.StartTimeMin, activityAlarm[1]); + mapData.put(DeviceKey.EndTimeHour, activityAlarm[2]); + mapData.put(DeviceKey.EndTimeMin, activityAlarm[3]); + mapData.put(DeviceKey.Week, activityAlarm[4]); + mapData.put(DeviceKey.IntervalTime, activityAlarm[5]); + mapData.put(DeviceKey.LeastSteps, activityAlarm[6]); + return maps; + } + + /** + * 总运动数据 + * + * @param value + * @return + */ + public static Map getTotalStepData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetTotalActivityData); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = getStepCount(value); + int length = value.length; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + NumberFormat numberFormat =NumberFormat.getNumberInstance(Locale.ENGLISH); + numberFormat.setMinimumFractionDigits(2); + numberFormat.setGroupingUsed(false); + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if (flag < length && value[flag] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date ="20"+ByteToHexString(value[2 + i * count]) + "." + + ByteToHexString(value[3 + i * count]) + "." + ByteToHexString(value[4 + i * count]); + int step = 0; + int time = 0; + float cal = 0; + float distance = 0; + + for (int j = 0; j < 4; j++) { + step += getValue(value[5 + j + i * count], j); + } + for (int j = 0; j < 4; j++) { + time += getValue(value[9 + j + i * count], j); + } + for (int j = 0; j < 4; j++) { + distance += getValue(value[13 + j + i * count], j); + } + for (int j = 0; j < 4; j++) { + cal += getValue(value[17 + j + i * count], j); + } + int exerciseTime = 0; + int goal = count==26?getValue(value[21 + i * count], 0):(getValue(value[21 + i * count], 0)+getValue(value[22 + i * count], 1)); + + for (int j = 0; j < 4; j++) { + exerciseTime += getValue(value[count-4 + j + i * count], j); + } + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.Step, String.valueOf(step)); + hashMap.put(DeviceKey.ExerciseMinutes, String.valueOf(time)); + hashMap.put(DeviceKey.Calories, numberFormat.format(cal / 100)); + hashMap.put(DeviceKey.Distance, numberFormat.format(distance / 100)); + hashMap.put(DeviceKey.Goal, String.valueOf(goal)); + hashMap.put(DeviceKey.ActiveMinutes, String.valueOf(exerciseTime)); + list.add(hashMap); + } + + return maps; + } + + private static int getStepCount(byte[]value){ + int goal=27; + int length=value.length; + if(length!=2){ + if(length%26==0){ + goal=26; + }else if(length%27==0){ + goal=27; + }else{ + if((length-2)%26==0){ + goal=26; + }else if((length-2)%27==0){ + goal=27; + } + } + } + return goal; + } + /** + * 详细运动数据 + * + * @param value + * @return + */ + public static Map getDetailData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDetailActivityData); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 25; + int length = value.length; + int size = length / count; + DeviceBean deviceBean = new DeviceBean(); + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH); + numberFormat.setMaximumFractionDigits(2); + numberFormat.setGroupingUsed(false); + for (int i = 0; i < size; i++) { + Map hashMap = new HashMap<>(); + int flag = 1 + (i + 1) * count; + if ( value[length-1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + String date ="20"+ByteToHexString(value[3 + i * 25]) + "." + + ByteToHexString(value[4 + i * 25]) + "." + ByteToHexString(value[5 + i * 25]) + " " + + ByteToHexString(value[6 + i * 25]) + ":" + ByteToHexString(value[7 + i * 25]) + ":" + ByteToHexString(value[8 + i * 25]); + int step = 0; + float cal = 0; + float distance = 0; + StringBuffer stringBuffer = new StringBuffer(); + for (int j = 0; j < 2; j++) { + step += getValue(value[9 + j + i * 25], j); + } + for (int j = 0; j < 2; j++) { + cal += getValue(value[11 + j + i * 25], j); + } + for (int j = 0; j < 2; j++) { + distance += getValue(value[13 + j + i * 25], j); + } + for (int j = 0; j < 10; j++) { + stringBuffer.append(String.valueOf(getValue(value[15 + j + i * 25], 0))).append(j == 9 ? "" : " "); + } + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.KDetailMinterStep, String.valueOf(step)); + hashMap.put(DeviceKey.Calories, numberFormat.format(cal / 100)); + hashMap.put(DeviceKey.Distance, numberFormat.format(distance / 100)); + hashMap.put(DeviceKey.ArraySteps, stringBuffer.toString()); + list.add(hashMap); + } + + return maps; + } + + /** + * 睡眠数据 + * + * @param value + * @return + */ + public static Map getSleepData(byte[] value) { + int length = value.length; + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDetailSleepData); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + boolean end=value[value.length - 1] == (byte) 0xff&& value[value.length - 2] ==DeviceConst.CMD_Get_SleepData; + if (end) { maps.put(DeviceKey.End,true);} + if(130==length||(end&&132 == length)){//一分钟睡眠数据 + Map hashMap = new HashMap<>(); + String date = "20" + bcd2String(value[3]) + "-" + bcd2String(value[4]) + "-" + bcd2String(value[5]) + " " + + bcd2String(value[6]) + ":" + bcd2String(value[7]) + ":" + bcd2String(value[8]); + hashMap.put(DeviceKey.Date, date); + int sleepLength = getValue(value[9], 0); + StringBuilder stringBuffer = new StringBuilder(); + for (int j = 0; j < sleepLength; j++) { + stringBuffer.append(getValue(value[10 + j], 0)).append(j == sleepLength ? "" : " "); + } + hashMap.put(DeviceKey.ArraySleep, stringBuffer.toString()); + hashMap.put(DeviceKey.sleepUnitLength,"1"); + list.add(hashMap); + }else{ + int count = 34; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.Data, list); + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + Map hashMap = new HashMap<>(); + String date = "20" + bcd2String(value[3 + i * 34]) + "-" + + bcd2String(value[4 + i * 34]) + "-" + bcd2String(value[5 + i * 34]) + " " + + bcd2String(value[6 + i * 34]) + ":" + bcd2String(value[7 + i * 34]) + ":" + bcd2String(value[8 + i * 34]); + hashMap.put(DeviceKey.Date, date); + int sleepLength = getValue(value[9 + i * 34], 0); + StringBuilder stringBuffer = new StringBuilder(); + try{ + for (int j = 0; j < sleepLength; j++) { + stringBuffer.append(getValue(value[10 + j + i * 34], 0)).append(j == sleepLength ?"":" "); + } + }catch (ArrayIndexOutOfBoundsException E){E.fillInStackTrace(); } + hashMap.put(DeviceKey.ArraySleep, stringBuffer.toString()); + hashMap.put(DeviceKey.sleepUnitLength,"5"); + list.add(hashMap); + } + } + return maps; + } + + + /** + * 历史心率数据 + * + * @param value + * @return + */ + public static Map getBloodoxygen(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.Blood_oxygen); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 10; + int length = value.length; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if (value[length-1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date = "20"+ByteToHexString(value[3 + i * count]) + "." + + ByteToHexString(value[4 + i * count]) + "." + ByteToHexString(value[5 + i * count]) + " " + + ByteToHexString(value[6 + i * count]) + ":" + ByteToHexString(value[7 + i * count]) + ":" + ByteToHexString(value[8 + i * count]); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.Blood_oxygen, String.valueOf(getValue(value[9 + i * 10], 0))); + list.add(hashMap); + } + + return maps; + } + + + + + + /** + * 历史心率数据 + * + * @param value + * @return + */ + public static Map getHeartData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetDynamicHR); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 24; + int length = value.length; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + if (value[length-1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date = "20"+ByteToHexString(value[3 + i * count]) + "." + + ByteToHexString(value[4 + i * count]) + "." + ByteToHexString(value[5 + i * count]) + " " + + ByteToHexString(value[6 + i * count]) + ":" + ByteToHexString(value[7 + i * count]) + ":" + ByteToHexString(value[8 + i * count]); + + + StringBuffer stringBuffer = new StringBuffer(); + for (int j = 0; j < 15; j++) { + stringBuffer.append(String.valueOf(getValue(value[9 + j + i * count], 0))).append(j == 14 ? "" : " "); + } + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.ArrayDynamicHR, stringBuffer.toString()); + list.add(hashMap); + } + + return maps; + } + + + /** + * 单次历史心率数据 + * + * @param value + * @return + */ + public static Map getOnceHeartData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetStaticHR); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 10; + int length = value.length; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if ( value[length-1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date ="20"+ByteToHexString(value[3 + i * 10]) + "." + + ByteToHexString(value[4 + i * 10]) + "." + ByteToHexString(value[5 + i * 10]) + " " + + ByteToHexString(value[6 + i * 10]) + ":" + ByteToHexString(value[7 + i * 10]) + ":" + ByteToHexString(value[8 + i * 10]); + String heart = String.valueOf(getValue(value[9 + i * 10], 0)); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.StaticHR, heart); + list.add(hashMap); + } + return maps; + } + /** + * htv测试数据 + * + * @param + * @return + */ + public static Map DeleteHrv() { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.DeleteHrv); + maps.put(DeviceKey.End,true); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + return maps; + } + /** + * htv测试数据 + * + * @param value + * @return + */ + public static Map getHrvTestData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetHRVData); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 15; + int length = value.length; + int size = length / count; + + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + if(value[value.length-1]== (byte) 0xff) maps.put(DeviceKey.End,true);; + for (int i = 0; i < size; i++) { + + Map hashMap = new HashMap<>(); + String date ="20"+ByteToHexString(value[3 + i * count]) + "." + + ByteToHexString(value[4 + i * count]) + "." + ByteToHexString(value[5 + i * count]) + " " + + ByteToHexString(value[6 + i * count]) + ":" + ByteToHexString(value[7 + i * count]) + ":" + ByteToHexString(value[8 + i * count]); + String hrv = String.valueOf(getValue(value[9 + i * count], 0)); + String blood = String.valueOf(getValue(value[10 + i * count], 0)); + String heart = String.valueOf(getValue(value[11 + i * count], 0)); + String Tired = String.valueOf(getValue(value[12 + i * count], 0)); + + String moodValue = String.valueOf(getValue(value[13 + i * count], 0)); + String breathRate = String.valueOf(getValue(value[14 + i * count], 0)); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.HRV, hrv); + hashMap.put(DeviceKey.VascularAging, blood); + hashMap.put(DeviceKey.Stress, Tired); + hashMap.put(DeviceKey.highBP, moodValue); + hashMap.put(DeviceKey.lowBP, breathRate); + hashMap.put(DeviceKey.HeartRate, heart); + list.add(hashMap); + } + + return maps; + } + + /** + * 闹钟数据 + * + * @param value + * @return + */ + public static Map getClockData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetAlarmClock); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 41; + int length = value.length; + int size = length / count; + + DeviceBean deviceBean = new DeviceBean(); + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if (flag < length && value[flag] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String id = String.valueOf(getValue(value[4 + i * count], 0)); + String enable = String.valueOf(getValue(value[5 + i * count], 0)); + String type = String.valueOf(getValue(value[6 + i * count], 0)); + String hour = ByteToHexString(value[7 + i * count]); + String min = ByteToHexString(value[8 + i * count]); + String week = getByteString(value[9 + i * count]); + int lengthS = getValue(value[10 + i * count], 0); + String content = ""; + for (int J = 0; J < lengthS; J++) { + if (value[11 + i * count] == 0) + continue; + content += (char) getValue(value[11 + J + i * count], 0); + } + hashMap.put(DeviceKey.KAlarmId, id); + hashMap.put(DeviceKey.OpenOrClose, enable); + hashMap.put(DeviceKey.ClockType, type); + hashMap.put(DeviceKey.ClockTime, hour); + hashMap.put(DeviceKey.KAlarmMinter, min); + hashMap.put(DeviceKey.Week, week); + hashMap.put(DeviceKey.KAlarmContent, content); + hashMap.put(DeviceKey.KAlarmLength, String.valueOf(lengthS)); + list.add(hashMap); + } + + return maps; + } + + private static final String TAG = "ResolveUtil"; + +/* public static Map getHistoryGpsData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetGPSData); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 59; + int length = value.length; + int size = length / count; + + + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if (flag < length && i==size-1&&value[flag] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + int id=getValue(value[1+i*count],0)+getValue(value[2+i*count],1); + String date = ByteToHexString(value[3 + i * count]) + "." + + ByteToHexString(value[4 + i * count]) + "." + ByteToHexString(value[5 + i * count]) + " " + + ByteToHexString(value[6 + i * count]) + ":" + ByteToHexString(value[7 + i * count]) + ":" + ByteToHexString(value[8 + i * count]); + byte[] valueLatitude = new byte[4]; + byte[] valueLongitude = new byte[4]; + StringBuffer stringBufferLatitude = new StringBuffer(); + StringBuffer stringBufferLongitude = new StringBuffer(); + for (int k = 0; k < 6; k++) { + for (int j = 0; j < 4; j++) { + valueLatitude[3 - j] = value[9 + j + i * count + k * 8]; + valueLongitude[3 - j] = value[13 + j + i * count + k * 8]; + } + String Latitude = String.valueOf(getFloat(valueLatitude, 0)); + String Longitude = String.valueOf(getFloat(valueLongitude, 0)); + stringBufferLatitude.append(Latitude).append(k == 5 ? "" : ","); + stringBufferLongitude.append(Longitude).append(k == 5 ? "" : ","); + } + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.KDataID,String.valueOf(id)); + hashMap.put(DeviceKey.Latitude, stringBufferLatitude.toString()); + hashMap.put(DeviceKey.Longitude, stringBufferLongitude.toString()); + list.add(hashMap); + } + + return maps; + }*/ + +/* public static Map getActivityGpsData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.DeviceSendToApp); + maps.put(DeviceKey.End,true); + Map hashMap = new HashMap<>(); + maps.put(DeviceKey.Data, hashMap); + String date = ByteToHexString(value[1]) + "-" + + ByteToHexString(value[2]) + "-" + ByteToHexString(value[3]) + " " + + ByteToHexString(value[4]) + ":" + ByteToHexString(value[5]) + ":" + ByteToHexString(value[6]); + byte[] valueLatitude = new byte[4]; + byte[] valueLongitude = new byte[4]; + for (int j = 0; j < 4; j++) { + valueLatitude[3 - j] = value[9+j ]; + valueLongitude[3 - j] = value[14+j]; + } + String Latitude = String.valueOf(getFloat(valueLatitude, 0)); + String Longitude = String.valueOf(getFloat(valueLongitude, 0)); + int count=getValue(value[18],0); + + hashMap.put(DeviceKey.KActivityLocationTime, date); + hashMap.put(DeviceKey.KActivityLocationLatitude, Latitude); + hashMap.put(DeviceKey.KActivityLocationLongitude, Longitude); + hashMap.put(DeviceKey.KActivityLocationCount, String.valueOf(count)); + + return maps; + }*/ +public static Map getTempDataer(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetAxillaryTemperatureDataWithMode); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + + int count = 11; + int length = value.length; + int size = length / count; + if (size == 0||value[length - 1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + NumberFormat numberFormat=getNumberFormat(1); + for (int i = 0; i < size; i++) { + Map hashMap = new HashMap<>(); + String date = "20"+bcd2String(value[3 + i * count]) + "." + + bcd2String(value[4 + i * count]) + "." + bcd2String(value[5 + i * count]) + " " + + bcd2String(value[6 + i * count]) + ":" + bcd2String(value[7 + i * count]) + ":" + bcd2String(value[8 + i * count]); + int tempValue = getValue(value[9 + i * count], 0)+getValue(value[10 + i * count], 1); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.axillaryTemperature, numberFormat.format(tempValue*0.1f)); + list.add(hashMap); + } + + return maps; +} + + public static Map getTempData(byte[] value) { + Map maps=new HashMap<>(); + List> list = new ArrayList<>(); + maps.put(DeviceKey.DataType, BleConst.Temperature_history); + maps.put(DeviceKey.End,false); + maps.put(DeviceKey.Data, list); + int count = 11; + int length = value.length; + int size = length / count; + if (size == 0||value[length - 1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + NumberFormat numberFormat=getNumberFormat(1); + for (int i = 0; i < size; i++) { + if (value[length-1] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date = "20"+bcd2String(value[3 + i * count]) + "." + + bcd2String(value[4 + i * count]) + "." + bcd2String(value[5 + i * count]) + " " + + bcd2String(value[6 + i * count]) + ":" + bcd2String(value[7 + i * count]) + ":" + bcd2String(value[8 + i * count]); + int tempValue = getValue(value[9 + i * count], 0)+getValue(value[10 + i * count], 1); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.temperature, numberFormat.format(tempValue*0.1f)); + list.add(hashMap); + } + return maps; + } + + //私有属性 + private Databack databack = null; + + public interface Databack { + void Endback(Map map); + } + + //setter方法 + public void setDataback(Databack databack1) { + this.databack = databack1; + } + + protected static List ecgdata=new ArrayList<>();; + protected static int size=0; + protected static int count=0; + protected static Map maps=new HashMap<>(); + protected static List> list = new ArrayList<>(); +/* public static void Getecgdata(byte[] value,Databack databack) { + if (value[value.length - 1] == (byte) 0x71) { + maps.put(DeviceKey.DataType, BleConst.DeleteECGdata); + maps.put(DeviceKey.End,true); + if(null!=databack){databack.Endback(maps);} + }else if(3==value.length&&value[value.length - 1] == (byte) 0xff){ + if(read){ + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.ECGValue, ecgdata.toString()+""); + list.add(hashMap); + maps.put(DeviceKey.End,true); + if(null!=databack){databack.Endback(maps);} + }else{ + maps.put(DeviceKey.DataType, BleConst. ECGdata); + maps.put(DeviceKey.End,true); + if(null!=databack){databack.Endback(maps);} + + + } + }else{ + + int index =getValue(value[1 ], 0)+getValue(value[2], 1) ; + if(0==index){ + ecgdata=new ArrayList<>();; + maps=new HashMap<>(); + list = new ArrayList<>(); + maps.put(DeviceKey.DataType, BleConst. ECGdata); + maps.put(DeviceKey.Data, list); + count=0; + size =getValue(value[9 ], 0)+getValue(value[10], 1) ; + String date = "20"+bcd2String(value[3]) + "." + + bcd2String(value[4 ]) + "." + bcd2String(value[5]) + " " + + bcd2String(value[6 ]) + ":" + bcd2String(value[7 ]) + ":" + bcd2String(value[8 ]); + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.HRV, getValue(value[11], 0)+""); + hashMap.put(DeviceKey.HeartRate, getValue(value[12], 0)+""); + hashMap.put(DeviceKey.ECGMoodValue, getValue(value[12], 0)+""); + byte[] bs = new byte[value.length-14]; + System.arraycopy(value, 14, bs, 0, bs.length); + for (int i=0;i hashMap = new HashMap<>(); + hashMap.put(DeviceKey.ECGValue, ecgdata.toString()+""); + list.add(hashMap); + maps.put(DeviceKey.End,true); + if(null!=databack){databack.Endback(maps);} + }*//* + + } + } + + }*/ + + + + + public static Map getEcgHistoryData(byte[] value) { + Map maps=new HashMap<>(); + Map list = new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.ECGdata); + maps.put(DeviceKey.End,false); + maps.put(DeviceKey.Data, list); + + int length = value.length; + if (length== 3||(value[length - 3] == (byte) 0x71 && value[length - 2] == (byte) 0xff && value[length - 1] == (byte) 0xff)) { + maps.put(DeviceKey.End,true); + return maps; + } + int id = getValue(value[1], 0) + getValue(value[2], 1); + int offset = 3; + Map hashMap = new HashMap<>(); + if (id == 0) {//第一条 + String date = "20"+bcd2String(value[3]) + "-" + + bcd2String(value[4]) + "-" + bcd2String(value[5]) + " " + + bcd2String(value[6]) + ":" + bcd2String(value[7]) + ":" + bcd2String(value[8]); + String hrv = String.valueOf(getValue(value[11], 0)); + String heart = String.valueOf(getValue(value[12], 0)); + String moodValue = String.valueOf(getValue(value[13], 0)); + list.put(DeviceKey.Date, date); + list.put(DeviceKey.HRV,hrv); + list.put(DeviceKey.HeartRate,heart); + list.put(DeviceKey.ECGMoodValue, moodValue); + /* list.add(hashMap);*/ + offset = 27; + + } + byte[] tempValue = new byte[length - offset]; + System.arraycopy(value, offset, tempValue, 0, tempValue.length); + String ecgData = getEcgDataString(tempValue); + list.put(DeviceKey.ECGValue, ecgData); + /*list.add(hashMap);*/ + return maps; + } + + + protected static String getEcgDataString(byte[] value) { + StringBuffer stringBuffer = new StringBuffer(); + int length = value.length / 2 - 1; + for (int i = 0; i < length; i++) { + int ecgValue = getValue(value[i * 2 + 1], 1) + ResolveUtil.getValue(value[i * 2 + 2], 0); + if (ecgValue >= 32768) ecgValue = ecgValue - 65536; + stringBuffer.append(ecgValue).append(","); + } + return stringBuffer.toString(); + } + protected static String getPPGData(byte[] value) { + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < value.length; i++) { + int ecgValue = getValue(value[i], 0); + stringBuffer.append(ecgValue).append(","); + } + return stringBuffer.toString(); + } + + protected static String getDoublePPGData(byte[] value) { + StringBuffer stringBuffer = new StringBuffer(); + int length = value.length / 2 ; + for (int i = 0; i < length; i++) { + int ecgValue = ResolveUtil.getValue(value[2*i], 1) + ResolveUtil.getValue(value[2*i+1], 0); + /* if (ecgValue >= 32768) ecgValue = ecgValue - 65536;*/ + stringBuffer.append(ecgValue).append(","); + } + return stringBuffer.toString(); + } + + public static Map getExerciseData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.GetActivityModeData); + maps.put(DeviceKey.End,false); + List> list = new ArrayList<>(); + maps.put(DeviceKey.Data, list); + int count = 25; + int length = value.length; + int size = length / count; + if (size == 0) { + maps.put(DeviceKey.End,true); + return maps; + } + NumberFormat numberFormatCal =getNumberFormat(1); + NumberFormat numberFormat =getNumberFormat(2); + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + if (flag < length && i==size-1&&value[flag] == (byte) 0xff) { + maps.put(DeviceKey.End,true); + } + Map hashMap = new HashMap<>(); + String date ="20"+ByteToHexString(value[3 + i * count]) + "." + + ByteToHexString(value[4 + i * count]) + "." + ByteToHexString(value[5 + i * count]) + " " + + ByteToHexString(value[6 + i * count]) + ":" + ByteToHexString(value[7 + i * count]) + ":" + ByteToHexString(value[8 + i * count]); + String mode = String.valueOf(getValue(value[9 + i * count], 0)); + String heartRate = String.valueOf(getValue(value[10 + i * count], 0)); + int periodTime = getData(2, 11 + i * count, value); + int steps = getData(2, 13 + i * count, value); + int speedMin = getValue(value[15 + i * count],0); + int speedS = getValue(value[16 + i * count],0); + byte[] valueCal = new byte[4]; + for (int j = 0; j < 4; j++) { + valueCal[3 - j] = value[17 +j+ i * count]; + } + byte[] valueDistance = new byte[4]; + for (int j = 0; j < 4; j++) { + valueDistance[3 - j] = value[21 +j+ i * count]; + } + float cal = getFloat(valueCal,0); + float distance = getFloat(valueDistance,0); + + hashMap.put(DeviceKey.Date, date); + hashMap.put(DeviceKey.ActivityMode, mode); + hashMap.put(DeviceKey.HeartRate, heartRate); + hashMap.put(DeviceKey.ActiveMinutes, String.valueOf(periodTime)); + hashMap.put(DeviceKey.Step, String.valueOf(steps)); + hashMap.put(DeviceKey.Pace, String.format("%02d",speedMin)+"'"+String.format("%02d",speedS)+"\""); + hashMap.put(DeviceKey.Distance, numberFormat.format(distance)); + hashMap.put(DeviceKey.Calories, numberFormatCal.format(cal)); + list.add(hashMap); + } + + return maps; + } + + public static Map getActivityExerciseData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.SportData); + maps.put(DeviceKey.End,true); + + Map map = new HashMap<>(); + maps.put(DeviceKey.Data, map); + int heartRate = getValue(value[1], 0); + int steps = 0; + float kcal = 0; + for (int i = 0; i < 4; i++) { + steps += getValue(value[i + 2], i); + } + + byte[] valueCal = new byte[4]; + for (int i = 0; i < 4; i++) { + valueCal[3 - i] = value[i + 6]; + // kcal+=getFloat(value[i+6],i); + } + long time = 0; + for (int i = 0; i < 4; i++) { + time += getValue(value[i + 10], i); + } + kcal = getFloat(valueCal, 0); + map.put(DeviceKey.HeartRate, String.valueOf(heartRate)); + map.put(DeviceKey.Step, String.valueOf(steps)); + map.put(DeviceKey.Calories, String.valueOf(kcal)); + map.put(DeviceKey.ActiveMinutes, String.valueOf(time)); + return maps; + } + public static Map setTimeSuccessful(byte[] value) {//设置时间成功后返回手机一个数据包的最大长度 + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType,BleConst.SetDeviceTime); + maps.put(DeviceKey.End,true); + Map map = new HashMap<>(); + maps.put(DeviceKey.Data, map); + + map.put(DeviceKey.KPhoneDataLength, String.valueOf(getValue(value[1],0))); + return maps; + } + + + public static Map setMacSuccessful() {//设置时间成功后返回手机一个数据包的最大长度 + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType,BleConst.CMD_Set_Mac); + maps.put(DeviceKey.End,true); + Map map = new HashMap<>(); + maps.put(DeviceKey.Data, map); + return maps; + } + + + + + public static Map ECGData(byte[] value) { + Map maps=new HashMap<>(); + Map mapData = new HashMap<>(); + maps.put(DeviceKey.End,true); + maps.put(DeviceKey.DataType, BleConst.EcgppG); + maps.put(DeviceKey.Data, mapData); + mapData.put(DeviceKey.ECGValue,value); + return maps; + } + public static Map ecgData(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.End,true); + maps.put(DeviceKey.DataType, BleConst.EcgppGstatus); + Map map = new HashMap<>(); + int index = ResolveUtil.getValue(value[1], 0); + map.put(DeviceKey.EcgStatus, index+""); + maps.put(DeviceKey.Data, map); + return maps; + } + + public static Map GetEcgPpgStatus(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.End,true); + maps.put(DeviceKey.DataType, BleConst.GetEcgPpgStatus); + int index = ResolveUtil.getValue(value[1], 0); + Map map = new HashMap<>(); + map.put(DeviceKey.EcgStatus, index); + maps.put(DeviceKey.Data, map); + if(3==index){//有数据 + int HR = ResolveUtil.getValue(value[2], 0); + int VascularAging = ResolveUtil.getValue(value[3], 0); + int HeartRate = ResolveUtil.getValue(value[4], 0); + int Fatiguedegree= ResolveUtil.getValue(value[5], 0); + int HighPressure = ResolveUtil.getValue(value[6], 0); + int LowPressure = ResolveUtil.getValue(value[7], 0); + int ECGMoodValue = ResolveUtil.getValue(value[8], 0); + int ECGBreathValue = ResolveUtil.getValue(value[9], 0); + map.put(DeviceKey.HeartRate, HeartRate); + map.put(DeviceKey.VascularAging, VascularAging); + map.put(DeviceKey.HRV, HR); + map.put(DeviceKey.Fatiguedegree, Fatiguedegree); + map.put(DeviceKey.HighPressure, HighPressure); + map.put(DeviceKey.LowPressure, LowPressure); + map.put(DeviceKey.ECGMoodValue, ECGMoodValue); + map.put(DeviceKey.ECGBreathValue, ECGBreathValue); + String date ="20"+ByteToHexString(value[10]) + "."+ + ByteToHexString(value[11]) + "." + ByteToHexString(value[12]) + " "+ + ByteToHexString(value[13]) + ":" + ByteToHexString(value[14]) + ":" + ByteToHexString(value[15]); + maps.put(DeviceKey.Date,date); + } + return maps; + } + public static Map ECGResult(byte[] value) { + Map maps=new HashMap<>(); + Map mapData = new HashMap<>(); + maps.put(DeviceKey.End,true); + maps.put(DeviceKey.DataType, BleConst.ECGResult); + maps.put(DeviceKey.Data, mapData); + int resultValue= getValue(value[1],0); + String date ="20"+ByteToHexString(value[10]) + "."+ + ByteToHexString(value[11]) + "." + ByteToHexString(value[12]) + " "+ + ByteToHexString(value[13]) + ":" + ByteToHexString(value[14]) + ":" + ByteToHexString(value[15]); + int hrv = ResolveUtil.getValue(value[2], 0); + int avBlock = ResolveUtil.getValue(value[3], 0); + int hr = ResolveUtil.getValue(value[4], 0); + int strees = ResolveUtil.getValue(value[5], 0); + int highBp = ResolveUtil.getValue(value[6], 0); + int lowBp = ResolveUtil.getValue(value[7], 0); + int moodValue = ResolveUtil.getValue(value[8], 0); + int breathValue = ResolveUtil.getValue(value[9], 0); + mapData.put(DeviceKey.ECGResultValue,String.valueOf(resultValue)); + mapData.put(DeviceKey.Date,date); + mapData.put(DeviceKey.ECGHrvValue,String.valueOf(hrv)); + mapData.put(DeviceKey.ECGAvBlockValue,String.valueOf(avBlock)); + mapData.put(DeviceKey.ECGHrValue,String.valueOf(hr)); + mapData.put(DeviceKey.ECGStreesValue,String.valueOf(strees)); + mapData.put(DeviceKey.ECGhighBpValue,String.valueOf(highBp)); + mapData.put(DeviceKey.ECGLowBpValue,String.valueOf(lowBp)); + mapData.put(DeviceKey.ECGMoodValue,String.valueOf(moodValue)); + mapData.put(DeviceKey.ECGBreathValue,String.valueOf(breathValue)); + return maps; + } + public static Map enterEcg(byte[] value) { + Map maps=new HashMap<>(); + Map mapData = new HashMap<>(); + maps.put(DeviceKey.End,true); + maps.put(DeviceKey.DataType, BleConst.ENTERECG); + maps.put(DeviceKey.Data, mapData); + + return maps; + } + public static Map updateClockSuccessful(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.SetAlarmClockWithAllClock); + maps.put(DeviceKey.End,true); + Map map = new HashMap<>(); + maps.put(DeviceKey.Data, map); + map.put(DeviceKey.KClockLast, String.valueOf(getValue(value[value.length-1],0))); + return maps; + } + + public static int getData(int length, int start, byte[] value) { + int data = 0; + for (int j = 0; j < length; j++) { + data += getValue(value[j + start], j); + } + return data; + } + + public static int getValue(byte b, int count) { + return (int) ((b & 0xff) * Math.pow(256, count)); + } + + public static String ByteToHexString(byte a) { + String s = ""; + s = Integer.toHexString(new Byte(a).intValue()); + if (s.length() == 1) { + s = "0" + s; + } + return s; + } + + public static float getFloat(byte[] arr, int index) {//字节转浮点 + return Float.intBitsToFloat(getInt(arr, index)); + } + + public static int getInt(byte[] arr, int index) { + return (0xff000000 & (arr[index + 0] << 24)) | + (0x00ff0000 & (arr[index + 1] << 16)) | + (0x0000ff00 & (arr[index + 2] << 8)) | + (0x000000ff & arr[index + 3]); + } + public static NumberFormat getNumberFormat(int max){ + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH); + numberFormat.setMaximumFractionDigits(max); + numberFormat.setGroupingUsed(false); + return numberFormat; + } + public static String byte2Hex(byte data) { + return String.format("%02X ", data); + } + public static String getCurrentTimeZone() { + TimeZone tz = TimeZone.getDefault(); + String strTz = tz.getDisplayName(false, TimeZone.SHORT); + Log.i(TAG, "getCurrentTimeZone: "+strTz); + int _t = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / (3600 * 1000); + strTz = String.valueOf(_t); + strTz = "GMT" + strTz; + Log.i(TAG, "getCurrentTimeZone: "+strTz); + return strTz; + + } + public static Map setMethodSuccessful(String dataType) {//设置时间成功后返回手机一个数据包的最大长度 + Map maps = new HashMap<>(); + maps.put(DeviceKey.DataType, dataType); + maps.put(DeviceKey.End, true); + maps.put(DeviceKey.Data, new HashMap<>()); + return maps; + } + + public static Map GetTemperatureCorrectionValue(byte[] value) { + Map maps=new HashMap<>(); + maps.put(DeviceKey.DataType, BleConst.CMD_Set_TemperatureCorrection); + maps.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + maps.put(DeviceKey.Data, mapData); + byte[]tempValue=new byte[2]; + tempValue[0]=value[3]; + tempValue[1]=value[2]; + int TemperatureCorrectionValue = BleSDK.byteArrayToInt(tempValue); + + mapData.put(DeviceKey.TemperatureCorrectionValue, String.valueOf(TemperatureCorrectionValue)); + return maps; + } + + + public static String[] getWorkOutReminder(byte[] value) { + String[] activityAlarm = new String[6]; + String startHour = bcd2String(value[1]); + String startMin = bcd2String(value[2]); + String days= getValue(value[3], 0)+""; + String week = getByteString(value[4]); + int enable=getValue(value[5], 0); + int time = getValue(value[6], 0)+getValue(value[7],1); + + activityAlarm[0] = startHour; + activityAlarm[1] = startMin; + activityAlarm[2] = days; + activityAlarm[3] = week; + activityAlarm[4] = String.valueOf(enable); + activityAlarm[5] = String.valueOf(time); + + return activityAlarm; + } + + /** + * + * + */ + public static Map GetWomenHealth(byte[] value) { + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.DataType, BleConst.GetWomenHealth); + hashMap.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + mapData.put(DeviceKey.Month, bcd2String(value[1])); + mapData.put(DeviceKey.Day, bcd2String(value[2])); + mapData.put(DeviceKey.MenstrualPeriod_Lenth, bcd2String(value[3])); + mapData.put(DeviceKey.MenstrualPeriod_Period, bcd2String(value[4])); + hashMap.put(DeviceKey.Data, mapData); + return hashMap; + } + + public static Map Getpeisu(int nungb) { + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.DataType, BleConst.Getpeisu); + hashMap.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + mapData.put(DeviceKey.Day, nungb+""); + hashMap.put(DeviceKey.Data, mapData); + return hashMap; + } + + public static Map GetpeisuER() { + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.DataType, BleConst.GetpeisuER); + hashMap.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + hashMap.put(DeviceKey.Data, mapData); + return hashMap; + } + /** + * + * + */ + public static Map GetPregnancyCycle(byte[] value) { + Map hashMap = new HashMap<>(); + hashMap.put(DeviceKey.DataType, BleConst.GetPregnancyCycle); + hashMap.put(DeviceKey.End,true); + MapmapData=new HashMap<>(); + mapData.put(DeviceKey.Year, bcd2String(value[3])); + mapData.put(DeviceKey.Month, bcd2String(value[4])); + mapData.put(DeviceKey.Day, bcd2String(value[5])); + hashMap.put(DeviceKey.Data, mapData); + return hashMap; + } + + + + public static Map getHistoryGpsData(byte[] value) { + + List> list = new ArrayList<>(); + Map mmp=new HashMap<>(); + mmp.put(DeviceKey.DataType, BleConst.Gps); + mmp.put(DeviceKey.End, false); + int count = 59; + int length = value.length; + int size = length / count; + if (size == 0) { + return mmp; + } + int index=size*50; + if ((value[value.length - 1] == (byte) 0xff && value[value.length - 2] == (byte) 0x5a)){ + mmp.put(DeviceKey.End, true); + } + for (int i = 0; i < size; i++) { + int flag = 1 + (i + 1) * count; + Map hashMap = new HashMap<>(); + int id = getValue(value[1 + i * count], 0) + getValue(value[2 + i * count], 1)%index; + String date ="20"+bcd2String(value[3 + i * count]) + "." + + bcd2String(value[4 + i * count]) + "." + bcd2String(value[5 + i * count]) + " " + + bcd2String(value[6 + i * count]) + ":" + bcd2String(value[7 + i * count]) + ":" + bcd2String(value[8 + i * count]); + byte[] valueLatitude = new byte[4]; + byte[] valueLongitude = new byte[4]; + StringBuffer stringBufferLatitude = new StringBuffer(); + StringBuffer stringBufferLongitude = new StringBuffer(); + for (int k = 0; k < 6; k++) { + for (int j = 0; j < 4; j++) { + valueLatitude[3 - j] = value[9 + j + i * count + k * 8]; + valueLongitude[3 - j] = value[13 + j + i * count + k * 8]; + } + String Latitude = String.valueOf(getFloat(valueLatitude, 0)); + String Longitude = String.valueOf(getFloat(valueLongitude, 0)); + stringBufferLatitude.append(Latitude).append(k == 5 ? "" : ","); + stringBufferLongitude.append(Longitude).append(k == 5 ? "" : ","); + } + hashMap.put(DeviceKey.Date, date.length() == 17 ? date : "2019.01.01 00:00:00"); + hashMap.put(DeviceKey.Latitude, stringBufferLatitude.toString()); + hashMap.put(DeviceKey.Longitude, stringBufferLongitude.toString()); + list.add(hashMap); + } + mmp.put(DeviceKey.Data, list.toString()); + + return mmp; + } + + + static double[] B_HR = new double[]{ + 0.012493658738073, + 0, + -0.024987317476146, + 0, + 0.012493658738073 + }; + static double[] A_HR = new double[]{ + 1, + -3.658469528008591, + 5.026987876570873, + -3.078346646055655, + 0.709828779797188 + }; + static double[] inPut = new double[]{0, 0, 0, 0, 0}; + static double[] outPut = new double[]{0, 0, 0, 0, 0}; + + public static double filterEcgData(double data) { + inPut[4] = data * 18.3 / 128 + 0.06; + outPut[4] = B_HR[0] * inPut[4] + + B_HR[1] * inPut[3] + + B_HR[2] * inPut[2] + + B_HR[3] * inPut[1] + + B_HR[4] * inPut[0] - + A_HR[1] * outPut[3] - + A_HR[2] * outPut[2] - + A_HR[3] * outPut[1] - + A_HR[4] * outPut[0]; + for (int i = 0; i < 4; i++) { + inPut[i] = inPut[i + 1]; + outPut[i] = outPut[i + 1]; + } + return outPut[4]; + } +} diff --git a/android/blesdk_2301/src/test/java/com/jstyle/blesdk2301/ExampleUnitTest.java b/android/blesdk_2301/src/test/java/com/jstyle/blesdk2301/ExampleUnitTest.java new file mode 100644 index 00000000..bf42dda1 --- /dev/null +++ b/android/blesdk_2301/src/test/java/com/jstyle/blesdk2301/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.jstyle.blesdk2301; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/android/settings.gradle b/android/settings.gradle index 5a2f14fb..e1e9493a 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,4 @@ -include ':app' +include ':app', ':blesdk_2301' def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() diff --git a/lib/pages/medical/my_trackers/ble_device_type_screens/smart_ring_connect_screen.dart b/lib/pages/medical/my_trackers/ble_device_type_screens/smart_ring_connect_screen.dart index eb999175..02c26dc2 100644 --- a/lib/pages/medical/my_trackers/ble_device_type_screens/smart_ring_connect_screen.dart +++ b/lib/pages/medical/my_trackers/ble_device_type_screens/smart_ring_connect_screen.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:diplomaticquarterapp/pages/medical/my_trackers/ble_device_type_screens/checkme_all_in_one_info_screen.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/ble_models/ble_devices_model.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/my_trackers_view_model/my_trackers_view_model.dart'; @@ -30,6 +32,8 @@ class _SmartRingAllInOneConnectScreenState extends State