浏览代码

1、优化12导心电

guanxinyi 1 年之前
父节点
当前提交
99421df8c0

+ 8 - 2
app/build.gradle

@@ -20,7 +20,11 @@ android {
             // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
         }
     }
-
+    repositories {
+        flatDir {
+            dirs 'libs'
+        }
+    }
     sourceSets {
         main {
             jni.srcDirs = []
@@ -70,7 +74,9 @@ android {
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
-    implementation fileTree(dir: 'libs', include: ['*.aar'])
+    implementation(name: 'ecgsdk_library-garea-release-1.8.6_202301111341', ext: 'aar')
+//    implementation fileTree(dir: 'libs', include: ['*.aar'])
+
     //noinspection GradleCompatible
     implementation 'com.android.support:gridlayout-v7:25.+'
     implementation 'androidx.appcompat:appcompat:1.4.1'

+ 2 - 0
app/src/main/java/vinno/sportinspect/config/RequestConstant.java

@@ -9,6 +9,8 @@ package vinno.sportinspect.config;
  */
 public class RequestConstant {
     public final  static  String SEARCH_START = "SEARCH_START";
+
+    public final  static  String SEARCH_START_BT = "SEARCH_START_BT";
     public final  static  String SEARCH_STOP = "SEARCH_STOP";
 
     public final  static  String BLE_CONNECT = "BLE_CONNECT";

+ 0 - 32
app/src/main/java/vinno/sportinspect/devices/BaseDevices.java

@@ -26,10 +26,6 @@ import org.json.JSONObject;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
-
-import serial.jni.BluConnectionStateListener;
-import serial.jni.DataUtils;
-import serial.jni.NativeCallBack;
 import vinno.sportinspect.bean.Device;
 import vinno.sportinspect.config.StatusConstant;
 import vinno.sportinspect.minterface.OnBleConnectSuccessListener;
@@ -203,33 +199,5 @@ abstract public class BaseDevices {
         }
     }
 
-    public void operationBT(String action, JSONObject params ){
-        JSONObject DEVICE = null;
-        Device _device = null;
-        try {
-            DEVICE = params.getJSONObject("DEVICE");
-            _device = JSONUtil.DeserializeObject(DEVICE.toString(),Device.class);
-        } catch (JSONException e) {}
-        //驱动参数错误
-        if( _device == null ){
-            callBack( PARAMS_ERROR );
-            return;
-        }
-        this.device = _device;
-        try {
-            Method method = this.getClass().getDeclaredMethod(action, JSONObject.class);
-            method.invoke(this, params);
-        } catch (IllegalAccessException e) {
-            //throw new RuntimeException(e);
-            callBack( BLE_IllegalAccessException );
-        } catch (InvocationTargetException e) {
-            //throw new RuntimeException(e);
-            callBack( BLE_InvocationTargetException );
-        } catch (NoSuchMethodException e) {
-            //throw new RuntimeException(e);
-            callBack( BLE_SUPPORT_METHOD );
-        }
-    }
-
 
 }

+ 1 - 10
app/src/main/java/vinno/sportinspect/devices/HeartByECGWS12.java

@@ -7,27 +7,18 @@ import android.content.Context;
 import android.os.Handler;
 import android.os.Message;
 import android.util.Log;
-import android.widget.Toast;
-
 import com.clj.fastble.BleManager;
-import com.clj.fastble.data.BleDevice;
-
-import org.json.JSONException;
 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.log.LogUtil;
 
 

+ 0 - 44
app/src/main/java/vinno/sportinspect/sdk/BaseSdk.java

@@ -390,50 +390,6 @@ class BaseSdk {
     }
 
 
-    /**
-     * 连接BT设备
-     *
-     * @param action                     操作
-     * @param model                      设备型号
-     * @param onBleMeasureResultListener 回调接口
-     */
-    public void operationBT(String action, String model, JSONObject params, OnBleMeasureResultListener onBleMeasureResultListener) {
-        if (!isBleEnable()) {
-            onBleMeasureResultListener.onMeasureResult(new MeasureResultUtils(StatusConstant.BLE_NO_OPEN, "", model).toJSONObject());
-            return;
-        }
-        //获取型号下的类名
-        Device device = deviceMapsByModels.get(model);
-        //不支持该设备
-        if (device == null) {
-            onBleMeasureResultListener.onMeasureResult(new MeasureResultUtils(StatusConstant.BLE_NO_SUPPORT, "", model).toJSONObject());
-            return;
-        }
-        BaseDevices instanceDevice = instanceDevices.get(model);
-        if (instanceDevice == null) {
-            Class<?> clazz = null;
-            try {
-                clazz = Class.forName("vinno.sportinspect.devices." + device.fragmentClassPath);
-                instanceDevice = (BaseDevices) clazz.newInstance();
-                instanceDevice.setOnBleMeasureResultListener(jsonObject -> onBleMeasureResultListener.onMeasureResult(jsonObject));
-                instanceDevices.put(model, instanceDevice);
-            } catch (ClassNotFoundException e) {
-                throw new RuntimeException(e);
-            } catch (IllegalAccessException e) {
-                throw new RuntimeException(e);
-            } catch (InstantiationException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        try {
-            String jsonString = JSONUtil.Serializable(device, device.getClass());
-            params.put("DEVICE", new JSONObject(jsonString));
-        } catch (JSONException e) {
-            throw new RuntimeException(e);
-        }
-        instanceDevice.operationBT(action, params);
-    }
-
     //判断是否连接
     public boolean isConnected(String model) {
         BaseDevices instanceDevice = instanceDevices.get(model);

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

@@ -79,90 +79,16 @@ public class VinnnoVnoteSdk extends BaseSdk{
 //                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
 //                    return;
 //                }
-                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 可以为空搜索全部支持的设备
-//                if( StringUtils.isEmpty( type ) ){
-//                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
-//                    return;
-//                }
-                stopSearch();
-                //断开设备
-            }else if( action.equals( RequestConstant.BLE_DISCONNECT ) ){
-                if( StringUtils.isEmpty( model )  ){
-                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
-                    return;
-                }
-                disConnectDevice( model );
-                //是否连接
-            }else if( action.equals( RequestConstant.BLE_IS_CONNECTED ) ){
-                if( StringUtils.isEmpty( model )  ){
-                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
-                    return;
-                }
-                isConnected( model );
-            }else{
-                if( StringUtils.isEmpty( model )  ){
-                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
-                    return;
-                }
-                operation( action, model, params, jsonObject -> {
+                startSearch(type, SCAN_TIMEOUT, jsonObject -> {
                     onGlobalResultListener.onResult(jsonObject);
                 });
-            }
-        } catch (JSONException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * 请求数据
-     * @param params
-     */
-    public void requestBT (JSONObject params){
-        //监听检查
-        if( onGlobalResultListener == null ){
-            onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.NO_REGISTER_INTERFACE).toJSONObject() );
-            return;
-        }
-        //权限检查
-        JSONObject checkRes = checkPermission();
-        if( checkRes != null ){
-            onGlobalResultListener.onResult( checkRes );
-            return;
-        }
-        //操作
-        try {
-            String action = params.has("ACTION") ? params.getString("ACTION") : "";
-            String model = params.has("MODEL") ? params.getString("MODEL") : "";
-            //String mac = params.has("MAC") ? params.getString("MAC") : "";
-            String type = params.has("TYPE") ? params.getString("TYPE") : "";
-            int SCAN_TIMEOUT = params.has("SCAN_TIMEOUT") ? params.getInt("SCAN_TIMEOUT") : ScanTimeOut;
-            if( StringUtils.isEmpty( action ) ){
-                onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
-                return;
-            }
-            //开始搜索
-            if( action.equals(RequestConstant.SEARCH_START ) ){
-                //type 可以为空搜索全部支持的设备
-//                if( StringUtils.isEmpty( type ) ){
-//                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
-//                    return;
-//                }
+                //停止搜索
+            }else if (action.equals(RequestConstant.SEARCH_START_BT )) {
                 startSearchBT(type, SCAN_TIMEOUT, jsonObject -> {
                     onGlobalResultListener.onResult(jsonObject);
                 });
-                //停止搜索
-            }else if( action.equals( RequestConstant.SEARCH_STOP ) ){
+            }
+            else if( action.equals( RequestConstant.SEARCH_STOP ) ){
                 //type 可以为空搜索全部支持的设备
 //                if( StringUtils.isEmpty( type ) ){
 //                    onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
@@ -170,14 +96,14 @@ public class VinnnoVnoteSdk extends BaseSdk{
 //                }
                 stopSearch();
                 //断开设备
-            }else if( action.equals( RequestConstant.BT_DISCONNECT ) ){
+            }else if( action.equals( RequestConstant.BLE_DISCONNECT ) ){
                 if( StringUtils.isEmpty( model )  ){
                     onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
                     return;
                 }
                 disConnectDevice( model );
                 //是否连接
-            }else if( action.equals( RequestConstant.BT_IS_CONNECTED ) ){
+            }else if( action.equals( RequestConstant.BLE_IS_CONNECTED ) ){
                 if( StringUtils.isEmpty( model )  ){
                     onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
                     return;
@@ -188,7 +114,7 @@ public class VinnnoVnoteSdk extends BaseSdk{
                     onGlobalResultListener.onResult( new SearchResultUtils(StatusConstant.PARAMS_ERROR).toJSONObject() );
                     return;
                 }
-                operationBT( action, model, params, jsonObject -> {
+                operation( action, model, params, jsonObject -> {
                     onGlobalResultListener.onResult(jsonObject);
                 });
             }
@@ -197,4 +123,5 @@ public class VinnnoVnoteSdk extends BaseSdk{
         }
     }
 
+
 }

+ 2 - 20
demo/src/main/java/com/vinno/sdk/demo/SplashScreenActivity.java

@@ -261,11 +261,11 @@ public class SplashScreenActivity extends AppCompatActivity {
 
         //开始十二导心电
         findViewById(R.id.bt_connect_twelvehear).setOnClickListener(v -> {
-            requestBT("BT_CONNECT");
+            request("BT_CONNECT");
         });
         //停止十二导心电
         findViewById(R.id.bt_disconnect_twelvehear).setOnClickListener(v -> {
-            requestBT("BT_DISCONNECT");
+            request("BT_DISCONNECT");
         });
 
     }
@@ -288,24 +288,6 @@ public class SplashScreenActivity extends AppCompatActivity {
         }
     }
 
-    void requestBT(String action) {
-        String[] res = getSpinnerData();
-
-        if (res == null) {
-            Toast.makeText(this, "请选择设备型号", Toast.LENGTH_SHORT).show();
-            return;
-        }
-        JSONObject params = new JSONObject();
-        try {
-            params.put("ACTION", action);
-            params.put("MODEL", res[0]);
-            params.put("MAC", res[1]);
-            VinnnoVnoteSdk.getInstance().requestBT(params);
-        } catch (JSONException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     void stopSearch() {
         JSONObject params = new JSONObject();
         try {