add a api for tempearture test in error state.
authorTrillGates <williamtrillgates@gmail.com>
Thu, 23 Sep 2021 08:31:51 +0000 (16:31 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Thu, 23 Sep 2021 08:31:51 +0000 (16:31 +0800)
app/src/main/aidl/com/ic/work/ITempSensorCallback.aidl
app/src/main/java/com/ic/work/SensorDataService.java
app/src/main/java/com/ic/work/hardware/TemperatureHelper.java
app/src/main/java/com/ic/work/utils/AlgorithmUtils.java
app/src/main/java/com/ic/work/utils/TemperatureUtil.java
app/src/main/res/values/strings.xml

index ebe9aaa..827e216 100644 (file)
@@ -4,7 +4,7 @@ package com.ic.work;
 import com.ic.work.domain.Temperature;
 
 interface ITempSensorCallback {
-
+   oneway void onTemperatureTestError(in String message,in int code);
    oneway void onTemperatureGet(in Temperature temperature);
    oneway void onTemperatureUpdating(in Temperature temperature);
    oneway void onGettingData();
index f5f5a44..abf9b06 100644 (file)
@@ -832,6 +832,30 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
         checkContinue();
     }
 
+    @Override
+    public void onTemperatureError(String message, int code) {
+        //通知监听的地方,测试出错
+        ICLogger.d("message==> " + message + " code==> " + code);
+        dispatchTemperatureTestError(message, code);
+    }
+
+    private void dispatchTemperatureTestError(String message, int code) {
+        synchronized (mLock) {
+            int i = temperatureCallbacks.beginBroadcast();
+            ICLogger.d("dispatchTemperatureTestError==> " + message);
+            try {
+                while (i > 0) {
+                    i--;
+                    temperatureCallbacks.getBroadcastItem(i).onTemperatureTestError(message, code);
+                }
+            } catch (RemoteException e) {
+                e.printStackTrace();
+            } finally {
+                temperatureCallbacks.finishBroadcast();
+            }
+        }
+    }
+
     @Override
     public void onHeartRateUpdate(int high, int low, int heart, int oxygen) {
         ICLogger.d("onHeartRateUpdate == > "
index 4030122..4a28cf3 100644 (file)
@@ -4,6 +4,7 @@ import android.os.SystemClock;
 
 import com.ic.jni.ICJniUtils;
 import com.ic.work.domain.TemperatureItem;
+import com.ic.work.utils.AlgorithmUtils;
 import com.ic.work.utils.HardwareUtils;
 import com.ic.work.utils.ICLogger;
 import com.ic.work.utils.IcLog;
@@ -66,7 +67,17 @@ public class TemperatureHelper {
                     if (typeOrder == ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_IC68.ordinal()) {
                         //IC68走这个
                         IcLog.d(TAG, "type is == > IC68");
-                        temperatureItem = TemperatureUtil.doTempTest();
+                        try {
+                            temperatureItem = TemperatureUtil.doTempTest();
+                        } catch (AlgorithmUtils.TempValueException e) {
+                            //输出信息
+                            if (mListener != null) {
+                                mListener.onTemperatureError(e.getMessage(), e.getCode());
+                            }
+                            //停止测试,跳出循环以后,就会指定到Listener的onTemperatureResult结束
+                            delayTimesInSeconds = 0;
+                            continue;
+                        }
                         if (temperatureItem != null) {
                             lastBodyTemp = Double.parseDouble(temperatureItem.getBodyTemp());
                             lastTempOut = Double.parseDouble(temperatureItem.getEvnTemp());
@@ -128,5 +139,7 @@ public class TemperatureHelper {
         void onTemperatureUpdate(double wristTemp, double bodyTemp, double envTemp);
 
         void onTemperatureResult(double wristTemp, double bodyTemp, double envTemp);
+
+        void onTemperatureError(String message, int code);
     }
 }
index f500020..517405f 100644 (file)
@@ -1,7 +1,10 @@
 package com.ic.work.utils;
 
+import android.content.Context;
 import android.text.TextUtils;
 
+import com.ic.work.R;
+
 public class AlgorithmUtils {
 
     private static final String TAG = "AlgorithmUtils";
@@ -15,7 +18,7 @@ public class AlgorithmUtils {
             //36.18~38.64:result = 0.0472*sourceTemp-0.1094
             if (innerTemp >= 39.21f && innerTemp < 43.12f) {
                 //dx = (0.0472f * innerTemp - 0.1094f);
-                dx = (0.749f * innerTemp)-26.592f;
+                dx = (0.749f * innerTemp) - 26.592f;
             } else
                 //38.64~43.46:result = 0.0178*result+1.3565
                 if (innerTemp >= 43.12f && innerTemp < 43.61) {
@@ -102,7 +105,6 @@ public class AlgorithmUtils {
     }
 
 
-
     public static double l56A(double bodyTemp, double innerTemp) {
         double dx;
         if (innerTemp <= 40.5f) {
@@ -115,5 +117,68 @@ public class AlgorithmUtils {
         return bodyTemp - dx;
     }
 
+    private final Context mContext;
+
+    private AlgorithmUtils(Context context) {
+        this.mContext = context;
+    }
+
+
+    private static AlgorithmUtils sInstance = null;
+
+
+    public static AlgorithmUtils getInstance(Context context) {
+        if (sInstance == null) {
+            sInstance = new AlgorithmUtils(context);
+        }
+        return sInstance;
+    }
+
+    public double MW13C(double bodyTemp, double boardTemp) throws TempValueException {
+        //对体温值进行检查
+        if (bodyTemp <= 28.0f) {
+            throw new TempValueException(
+                    mContext.getString(R.string.body_sensor_value_too_low_text) + ":" + bodyTemp,
+                    ERROR_SENSOR_TOO_LOW);
+        } else if (bodyTemp > 39.0f) {
+            throw new TempValueException(
+                    mContext.getString(R.string.body_sensor_value_too_high_text) + ":" + bodyTemp,
+                    ERROR_SENSOR_TOO_HIGH);
+        }
+        //对主板温度值进行检查
+        if (boardTemp > 53.4) {
+            throw new TempValueException(
+                    mContext.getString(R.string.board_temperature_high_text) + ":" + boardTemp,
+                    ERROR_HARD_WEAR_TOO_HIGH);
+        }
+
+        //当主板温度比较低的时候,可以认为主板对传感器温度不影响
+        double dx = 0.5326 * boardTemp - 22.51114f;
+        if (boardTemp < 40.3) {
+            //对此温度没有影响,直接返回传感器的温度即可
+            return bodyTemp;
+        }
+        //可以计算
+        return bodyTemp - dx;
+    }
+
+    public static final int ERROR_HARD_WEAR_TOO_HIGH = 1;
+    public static final int ERROR_SENSOR_TOO_HIGH = 3;
+    public static final int ERROR_SENSOR_TOO_LOW = 4;
+
+    public static class TempValueException extends Exception {
+        private final int mCode;
+
+        public int getCode() {
+            return mCode;
+        }
+
+
+        public TempValueException(String description, int code) {
+            super(description);
+            this.mCode = code;
+        }
+    }
+
 
 }
index 91026cc..d2ddf1e 100644 (file)
@@ -3,6 +3,7 @@ package com.ic.work.utils;
 import android.util.Log;
 
 import com.ic.jni.ICJniUtils;
+import com.ic.work.WorkServiceApp;
 import com.ic.work.domain.TemperatureItem;
 
 public class TemperatureUtil {
@@ -49,9 +50,8 @@ public class TemperatureUtil {
     /**
      * 这里获取到CPU温度,主板温度,体温,外温的数据,然后写到log里,后面转成数据表,再转成函数表达式。
      */
-    public static TemperatureItem doTempTest() {
+    public static TemperatureItem doTempTest() throws AlgorithmUtils.TempValueException {
         if (ICJniUtils.isTemperatureDevAvailable() > ICJniUtils.TempSensorType.TEMPSENSOR_TYPE_NONE.ordinal()) {
-
             double bodyTemp/*体温*/ = 0.0f;
             double cpuTemp/*cpu温度*/ = 0.0f;
             double evnTemp/*环境温度*/ = 0.0f;
@@ -135,6 +135,8 @@ public class TemperatureUtil {
                     ICLogger.d("final body temp == > " + lastBodyTemp);
                     ICLogger.d("final wrist temp == > " + bodyTempResult);
                 }
+            } else if ("MW13C".equals(property)) {
+                AlgorithmUtils.getInstance(WorkServiceApp.sContext).MW13C(bodyTemp, boardTemp);
             } else {
                 //   double bodyTempResult = AlgorithmUtils.l004Pt(bodyTemp, evnTemp);
                 ICLogger.d("wrist TempResult == > " + bodyTemp);
@@ -143,9 +145,7 @@ public class TemperatureUtil {
                     lastBodyTemp = getBodyTemp(bodyTemp, 26.1f);
                     ICLogger.d("final body temp == > " + lastBodyTemp);
                 }
-
             }
-
             if (lastBodyTemp <= 0) {
                 return null;
             }
index 00b1727..3f41099 100644 (file)
@@ -1,5 +1,8 @@
 <resources>
     <string name="app_name">IcWorkService</string>
-
     <string name="program_abnormal">很抱歉,程序出现异常,即将退出</string>
+    <string name="body_sensor_value_too_low_text">体温传感器温度过低</string>
+    <string name="body_sensor_value_too_high_text">体温传感器温度过高</string>
+    <string name="board_temperature_low_text">主板温度低影响测试结果</string>
+    <string name="board_temperature_high_text">主板温度过高</string>
 </resources>