Browse Source

1、12导心电

guanxinyi 1 year ago
parent
commit
98686ee6d0

+ 18 - 0
app/src/main/java/vinno/sportinspect/bean/TwelveHeartEntity.java

@@ -0,0 +1,18 @@
+package vinno.sportinspect.bean;
+
+import androidx.annotation.Keep;
+
+import java.util.ArrayList;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+@Keep
+public class TwelveHeartEntity {
+    public TwelveHeartEntity(){
+        POINT = new ConcurrentLinkedQueue<Short>();
+        ANALYSIS = new ArrayList<>();
+    }
+    public int HR;
+    public ConcurrentLinkedQueue<Short> POINT;
+
+    public ArrayList<String> ANALYSIS;
+}

+ 7 - 0
app/src/main/java/vinno/sportinspect/config/StatusConstant.java

@@ -115,4 +115,11 @@ public class StatusConstant {
      */
     public static int BLE_ICREADER_FAIL = 1800;//	IC读卡失败
     public static int BLE_ICREADER_SUCCESS = 1801;//	IC读卡成功
+
+    /**
+     * 十二导心电
+     */
+    public static int BT_MEASURE_HEART_TWELVE_VALUE = 1900;//	心电测量值
+    public static int BT_MEASURE_HEART_TWELVE_RESULT = 1901;//	心电测量结果
+    public static int BT_MEASURE_TWELVE_NOISE = 1902;//	心电测量有噪声
 }

+ 37 - 2
app/src/main/java/vinno/sportinspect/devices/HeartByECGWS12.java

@@ -17,15 +17,18 @@ import org.json.JSONObject;
 
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
 import java.util.Vector;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import serial.jni.BluConnectionStateListener;
 import serial.jni.DataUtils;
 import serial.jni.NativeCallBack;
+import vinno.sportinspect.bean.HeartEntity;
+import vinno.sportinspect.bean.TwelveHeartEntity;
 import vinno.sportinspect.config.StatusConstant;
 import vinno.sportinspect.minterface.OnBleConnectSuccessListener;
-import vinno.sportinspect.utils.LogUtil;
+import vinno.sportinspect.utils.log.LogUtil;
 
 
 public class HeartByECGWS12 extends BaseDevices{
@@ -57,6 +60,8 @@ public class HeartByECGWS12 extends BaseDevices{
     //2020-05-13 采样转换 1000-->256
     private int srcDataIndex = 0;
     private int selectDataIndex = 0;
+    final TwelveHeartEntity entity = new TwelveHeartEntity();
+
     private EcgPoint []srcDataBuffer = new EcgPoint[srcDataBufferSize];
 
     class nativeMsg extends NativeCallBack {
@@ -64,6 +69,11 @@ public class HeartByECGWS12 extends BaseDevices{
         @Override
         public void callHRMsg(short hr) {// 心率
             mHandler.obtainMessage(MESSAGE_UPDATE_HR, hr).sendToTarget();
+            entity.HR =  hr;
+//            LogUtil.d("gxy+" + hr);
+//            callBack(StatusConstant.BT_MEASURE_HEART_TWELVE_RESULT, entity);
+            //            System.out.println(Arrays.toString(wave));
+//            callBack(StatusConstant.BT_MEASURE_HEART_TWELVE_RESULT, Arrays.toString(wave).substring(0, 10));
         }
 
         @Override
@@ -122,7 +132,12 @@ public class HeartByECGWS12 extends BaseDevices{
                         mEcgQueue.offer(points.get(i).ecg[j]);
                     }
                 }
+                entity.POINT = mEcgQueue;
+                if(mEcgQueue.size() %(1250*12) ==0) {
+                    callBack(StatusConstant.BT_MEASURE_HEART_TWELVE_RESULT, entity);
+                }
             }
+
         }
         @Override
         public void callEcg18WaveDataMsg(short[] wave) {
@@ -213,14 +228,17 @@ public class HeartByECGWS12 extends BaseDevices{
                 case MESSAGE_CONNECT_SUCCESS:
 //                    连接成功
                     callBack(StatusConstant.BLE_CONNECT_SUCCESS);
+                    mEcgQueue = new ConcurrentLinkedQueue<Short>();
                     break;
                 case MESSAGE_CONNECT_INTERRUPTED:
 //                    连接中断
                     callBack(StatusConstant.BLE_DISCONNECT);
+                    mEcgQueue =null;
                     break;
                 case MESSAGE_CONNECT_FAILED:
 //                    连接失败
                     callBack(StatusConstant.BLE_CONNECT_FAIL);
+                    mEcgQueue =null;
                     break;
                 case MESSAGE_USB_CONNECT_REMOVE_DEVICE:
 //                    Log.e("BL", "MESSAGE_USB_CONNECT_REMOVE_DEVICE");
@@ -278,27 +296,44 @@ public class HeartByECGWS12 extends BaseDevices{
                     @Override
                     public void OnBluConnectionInterrupted() {
                         LogUtil.d("vinno==>设备连接中断");
+                        mHandler.obtainMessage(MESSAGE_CONNECT_INTERRUPTED,
+                                -1, -1).sendToTarget();
                     }
                     @Override
                     public void OnBluConnectSuccess() {
                         LogUtil.d("vinno==>设备连接成功");
+                        mHandler.obtainMessage(MESSAGE_CONNECT_SUCCESS)
+                                .sendToTarget();
                     }
                     @Override
                     public void OnBluConnectStart() {
                         LogUtil.d("vinno==>开始连接BT");
+                        mHandler.obtainMessage(MESSAGE_CONNECT_START)
+                                .sendToTarget();
                     }
                     @Override
                     public void OnBluConnectFaild() {
                         LogUtil.d("vinno==>设备连接失败");
+                        mHandler.obtainMessage(MESSAGE_CONNECT_FAILED, -1,
+                                -1).sendToTarget();
                     }
                 });
-        /// 开始采集
+
         data.gatherStart(new nativeMsg());
 
+
     }
 
     @Override
     public void parseData(byte[] data) {
 
     }
+    @Override
+    public void disConnectDevice() {
+        /// 结束采集
+        data.gatherEnd();
+        LogUtil.d("结束采集");
+        /// 完全结束时释放采集资源
+        data.gatherRelease();
+    }
 }

+ 9 - 4
app/src/main/java/vinno/sportinspect/sdk/VinnnoVnoteSdk.java

@@ -9,7 +9,6 @@ import org.json.JSONObject;
 import vinno.sportinspect.config.RequestConstant;
 import vinno.sportinspect.config.StatusConstant;
 import vinno.sportinspect.minterface.OnGlobalResultListener;
-import vinno.sportinspect.utils.LogUtil;
 import vinno.sportinspect.utils.SearchResultUtils;
 
 /**
@@ -80,9 +79,15 @@ public class VinnnoVnoteSdk extends BaseSdk{
 //                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
 //                    return;
 //                }
-                startSearch(type, SCAN_TIMEOUT, jsonObject -> {
-                    onGlobalResultListener.onResult(jsonObject);
-                });
+                if(type == "twelveheart") {
+                    startSearchBT(type, SCAN_TIMEOUT, jsonObject -> {
+                        onGlobalResultListener.onResult(jsonObject);
+                    });
+                }else {
+                    startSearch(type, SCAN_TIMEOUT, jsonObject -> {
+                        onGlobalResultListener.onResult(jsonObject);
+                    });
+                }
                 //停止搜索
             }else if( action.equals( RequestConstant.SEARCH_STOP ) ){
                 //type 可以为空搜索全部支持的设备

+ 10 - 11
demo/src/main/java/com/vinno/sdk/demo/SplashScreenActivity.java

@@ -134,12 +134,7 @@ public class SplashScreenActivity extends AppCompatActivity {
                 params.put("ACTION", "SEARCH_START");
                 params.put("TYPE", typeName); //不传就是搜索全部设备
                 params.put("SCAN_TIMEOUT", 10000);//50秒
-                /// 十二导心电
-                if(typeName == "twelveheart") {
-                    VinnnoVnoteSdk.getInstance().requestBT(params);
-                }else {
-                    VinnnoVnoteSdk.getInstance().request(params);
-                }
+                VinnnoVnoteSdk.getInstance().request(params);
             } catch (JSONException e) {
                 throw new RuntimeException(e);
             }
@@ -358,11 +353,15 @@ public class SplashScreenActivity extends AppCompatActivity {
 
 
     public void notifyText(String value) {
-        if (tv_result.getText().toString().length() > 1000) {
-            tv_result.setText(value);
-            return;
-        }
-        tv_result.setText(value + "\n" + tv_result.getText().toString());
+        runOnUiThread(new Runnable() {
+            public void run() {
+                if (tv_result.getText().toString().length() > 1000) {
+                    tv_result.setText(value);
+                } else {
+                    tv_result.setText(value + "\n" + tv_result.getText().toString());
+                }
+            }
+        });
     }
 
     @Override