|
@@ -95,7 +95,7 @@ public class APIModuleGis extends UZModule {
|
|
|
//TODO 做连接状态字段connectCode的监听
|
|
|
long time = System.currentTimeMillis();
|
|
|
while (true) {
|
|
|
- if(System.currentTimeMillis() - time < 2 * 1000) {
|
|
|
+ if(System.currentTimeMillis() - time < 3 * 1000) {
|
|
|
if ("0".equals(connectCode)) {
|
|
|
//TODO 说明已经调用过启动连接方法,并且连接成功
|
|
|
//TODO 而且还要满足此时经纬度返回已经不是0.0了
|
|
@@ -229,6 +229,66 @@ public class APIModuleGis extends UZModule {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public ModuleResult jsmethod_huaceRtkList_sync(UZModuleContext moduleContext){
|
|
|
+ String code = "1";//0表示成功,1表示失败
|
|
|
+ String msg = "error";//状态信息
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ try{
|
|
|
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
+ if (adapter == null) {
|
|
|
+ res.put("code","2");
|
|
|
+ res.put("msg","本机没有找到蓝牙硬件或驱动!");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ } else {
|
|
|
+ if (!adapter.isEnabled()) {
|
|
|
+ //直接开启蓝牙
|
|
|
+ adapter.enable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ContextCompat.checkSelfPermission(this.context(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ res.put("code","3");
|
|
|
+ res.put("msg","定位授权:请授予APP位置访问权限,以便应用可检测外围设备");
|
|
|
+ }
|
|
|
+ if (checkPermissionEnable(PERMISSIONS)) {
|
|
|
+ //打开蓝牙
|
|
|
+ if (!BlueUtils.isOpen()) {
|
|
|
+ //Util.showOnUiThreadToast(this, "请打开蓝牙进行手机蓝牙配对!");
|
|
|
+// errorPromote(this, "温馨提示", "请在设置页面打开手机蓝牙配对连接!");
|
|
|
+ res.put("code","4");
|
|
|
+ res.put("msg","请在设置页面打开手机蓝牙配对连接!");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+ List<String> arrBle = BlueUtils.getBluetoothDevice(BleStatusDefine.CONNECTED);
|
|
|
+ if (arrBle != null && arrBle.size() > 0) {
|
|
|
+ for (int i = arrBle.size() - 1; i >= 0; i--) {
|
|
|
+ if (!arrBle.get(i).startsWith("GNSS"))
|
|
|
+ arrBle.remove(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (arrBle == null || arrBle.size() <= 0) {
|
|
|
+// errorPromote(this, "温馨提示", "没有已配对连接的RTK蓝牙设备!");
|
|
|
+ res.put("code","5");
|
|
|
+ res.put("msg","没有已配对连接的RTK蓝牙设备!");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+ res.put("code","0");
|
|
|
+ res.put("msg","success");
|
|
|
+ res.put("data",arrBle);
|
|
|
+ }else{
|
|
|
+ res.put("code","6");
|
|
|
+ res.put("msg","权限不足,请允许相关权限");
|
|
|
+ ActivityCompat.requestPermissions(this.activity(), PERMISSIONS, REQUEST_PERMISSION);
|
|
|
+ }
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }catch(Exception ex){
|
|
|
+ code = "1";
|
|
|
+ msg = "errorException";
|
|
|
+ try{res.put("code",code);res.put("msg",msg);}catch(Exception e){}
|
|
|
+ Log.e(TAG,ex.getLocalizedMessage());
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public ModuleResult jsmethod_sendConnect_sync(UZModuleContext moduleContext){
|
|
|
String code = "1";//0表示成功,1表示失败
|
|
|
String msg = "error";//状态信息
|
|
@@ -236,6 +296,13 @@ public class APIModuleGis extends UZModule {
|
|
|
try {
|
|
|
res.put("code",code);
|
|
|
res.put("msg",msg);
|
|
|
+
|
|
|
+ String rtkName = moduleContext.optString("rtkName");
|
|
|
+ if(rtkName==null||"".equals(rtkName)){
|
|
|
+ res.put("msg","配对设备参数不存在");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+
|
|
|
//打开蓝牙
|
|
|
if (!BlueUtils.isOpen()) {
|
|
|
//Util.showOnUiThreadToast(this, "请打开蓝牙进行手机蓝牙配对!");
|
|
@@ -256,10 +323,14 @@ public class APIModuleGis extends UZModule {
|
|
|
res.put("msg","没有已配对连接的RTK蓝牙设备!");
|
|
|
return new ModuleResult(res);
|
|
|
}
|
|
|
+ if(!arrBle.contains(rtkName)){
|
|
|
+ res.put("msg","您选择的设备"+rtkName+"未配对,请重新选择或在手机蓝牙设置页重新配对");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
if (!EventBus.getDefault().isRegistered(this)) {
|
|
|
EventBus.getDefault().register(this);
|
|
|
}
|
|
|
- ReceiverConnectProxy.getInstance().connByBluetooth(arrBle.get(0));
|
|
|
+ ReceiverConnectProxy.getInstance().connByBluetooth(rtkName);
|
|
|
GnssServerEnvironment.getInstance().setLog(new ILog(){
|
|
|
|
|
|
@Override
|
|
@@ -285,8 +356,8 @@ public class APIModuleGis extends UZModule {
|
|
|
//TODO 做连接状态字段connectCode的监听
|
|
|
// long time = System.currentTimeMillis();
|
|
|
// while (true){
|
|
|
-// if (System.currentTimeMillis() - time < 3 * 1000) {//设置时间不超3秒
|
|
|
- //3秒内这个变量有变动,执行返回
|
|
|
+// if (System.currentTimeMillis() - time < 10 * 1000) {//设置时间不超5秒
|
|
|
+ //5秒内这个变量有变动,执行返回
|
|
|
if(!"".equals(connectCode)) {
|
|
|
if (connectCode.equals("0")) {
|
|
|
code = "0";
|
|
@@ -297,7 +368,7 @@ public class APIModuleGis extends UZModule {
|
|
|
return new ModuleResult(res);
|
|
|
}
|
|
|
// } else {
|
|
|
- //TODO 说明超时
|
|
|
+// //TODO 说明超时
|
|
|
// msg = "连接超时";
|
|
|
// res.put("msg",msg);
|
|
|
// break;
|