|
@@ -128,7 +128,58 @@ public class APIModuleGis extends UZModule {
|
|
|
try {
|
|
|
res.put("code",code);
|
|
|
res.put("msg",msg);
|
|
|
- res.put("version","1.0.7");
|
|
|
+ res.put("version","1.1.0");
|
|
|
+
|
|
|
+ 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位置访问权限,以便应用可检测外围设备");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 连接相关判断
|
|
|
+ String rtkName = context.optString("rtkName");
|
|
|
+// if(rtkName==null||"".equals(rtkName)){
|
|
|
+// res.put("code","4");
|
|
|
+// res.put("msg","配对设备参数不存在");
|
|
|
+// return new ModuleResult(res);
|
|
|
+// }
|
|
|
+ //打开蓝牙
|
|
|
+ if (!BlueUtils.isOpen()) {
|
|
|
+ //Util.showOnUiThreadToast(this, "请打开蓝牙进行手机蓝牙配对!");
|
|
|
+// errorPromote(this, "温馨提示", "请在设置页面打开手机蓝牙配对连接!");
|
|
|
+ res.put("code","5");
|
|
|
+ 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","6");
|
|
|
+ res.put("msg","没有已配对连接的RTK蓝牙设备!");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+ if(!arrBle.contains(rtkName)){
|
|
|
+ res.put("code","7");
|
|
|
+ res.put("msg","您选择的设备"+rtkName+"未配对,请重新选择或在手机蓝牙设置页重新配对");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
|
|
|
code = "0";
|
|
|
res.put("code", code);
|
|
@@ -161,7 +212,7 @@ public class APIModuleGis extends UZModule {
|
|
|
res.put("data", gisObj);
|
|
|
|
|
|
//TODO 大逻辑 是否重连判断
|
|
|
- String rtkName = context.optString("rtkName");
|
|
|
+// String rtkName = context.optString("rtkName");
|
|
|
//TODO cors相关判断 , 全传就登录, 有一个没传就不登
|
|
|
String ip = context.optString("ip");
|
|
|
Integer port = Integer.valueOf(context.optString("port"));
|
|
@@ -169,6 +220,27 @@ public class APIModuleGis extends UZModule {
|
|
|
String userName = context.optString("userName");
|
|
|
String passWord = context.optString("passWord");
|
|
|
|
|
|
+ //TODO 熔断
|
|
|
+ if(!"0".equals(bindCode)){
|
|
|
+ initGnss();
|
|
|
+ if (!EventBus.getDefault().isRegistered(this)) {
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ }
|
|
|
+ onBindClick();
|
|
|
+ res.put("code","8");
|
|
|
+ res.put("msg","服务已断开,正在重启,请稍后");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+ if(!"0".equals(connectCode)) {
|
|
|
+ ReceiverConnectProxy.getInstance().connByBluetooth(rtkName);
|
|
|
+ res.put("code","9");
|
|
|
+ res.put("msg","连接已断开,正在重启,请稍后");
|
|
|
+ return new ModuleResult(res);
|
|
|
+ }
|
|
|
+ if(!"0".equals(logCorsCod)) {
|
|
|
+ DiffConnectManager.loginCors(this.context(), ip, port, mountName, userName, passWord);
|
|
|
+ }
|
|
|
+
|
|
|
//TODO rtk连接比cors连接优先级要高
|
|
|
if(rtkName!=null&&rtkName.length()>0){
|
|
|
if(!rtkName.equals(ramRtkName)){
|
|
@@ -177,7 +249,7 @@ public class APIModuleGis extends UZModule {
|
|
|
DiffConnectManager.loginOutCors(this.context());
|
|
|
connectCode = "1";
|
|
|
logCorsCod = "1";
|
|
|
- startSendMessage(res,context);
|
|
|
+ res = startSendMessage(context);
|
|
|
}
|
|
|
}else{
|
|
|
//TODO 说明RTK 没传, 就断开连接
|
|
@@ -185,6 +257,8 @@ public class APIModuleGis extends UZModule {
|
|
|
DiffConnectManager.loginOutCors(this.context());
|
|
|
connectCode = "1";
|
|
|
logCorsCod = "1";
|
|
|
+ res.put("code","4");
|
|
|
+ res.put("msg","配对设备参数不存在");
|
|
|
}
|
|
|
//TODO cors更换
|
|
|
if((ip!=null&&!ip.equals(ramIp))||(port!=null&&!port.equals(ramPort))
|
|
@@ -548,7 +622,7 @@ public class APIModuleGis extends UZModule {
|
|
|
//TODO 启动服务相关判断
|
|
|
res.put("code",code);
|
|
|
res.put("msg",msg);
|
|
|
- startSendMessage(res,moduleContext);
|
|
|
+ res = startSendMessage(moduleContext);
|
|
|
return new ModuleResult(res);
|
|
|
}catch(Exception ex){
|
|
|
code = "1";
|
|
@@ -560,11 +634,13 @@ public class APIModuleGis extends UZModule {
|
|
|
}
|
|
|
|
|
|
//TODO 统一启动服务和发送连接命令
|
|
|
- private void startSendMessage(JSONObject res,UZModuleContext moduleContext) throws JSONException {
|
|
|
+ private JSONObject startSendMessage(UZModuleContext moduleContext) throws JSONException {
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
if (adapter == null) {
|
|
|
res.put("code","2");
|
|
|
res.put("msg","本机没有找到蓝牙硬件或驱动!");
|
|
|
+ return res;
|
|
|
} else {
|
|
|
if (!adapter.isEnabled()) {
|
|
|
//直接开启蓝牙
|
|
@@ -574,6 +650,7 @@ public class APIModuleGis extends UZModule {
|
|
|
if (ContextCompat.checkSelfPermission(this.context(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
res.put("code","3");
|
|
|
res.put("msg","定位授权:请授予APP位置访问权限,以便应用可检测外围设备");
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
//TODO 连接相关判断
|
|
@@ -581,6 +658,7 @@ public class APIModuleGis extends UZModule {
|
|
|
if(rtkName==null||"".equals(rtkName)){
|
|
|
res.put("code","4");
|
|
|
res.put("msg","配对设备参数不存在");
|
|
|
+ return res;
|
|
|
}
|
|
|
//打开蓝牙
|
|
|
if (!BlueUtils.isOpen()) {
|
|
@@ -588,6 +666,7 @@ public class APIModuleGis extends UZModule {
|
|
|
// errorPromote(this, "温馨提示", "请在设置页面打开手机蓝牙配对连接!");
|
|
|
res.put("code","5");
|
|
|
res.put("msg","请在设置页面打开手机蓝牙配对连接!");
|
|
|
+ return res;
|
|
|
}
|
|
|
List<String> arrBle = BlueUtils.getBluetoothDevice(BleStatusDefine.CONNECTED);
|
|
|
if (arrBle != null && arrBle.size() > 0) {
|
|
@@ -600,10 +679,12 @@ public class APIModuleGis extends UZModule {
|
|
|
// errorPromote(this, "温馨提示", "没有已配对连接的RTK蓝牙设备!");
|
|
|
res.put("code","6");
|
|
|
res.put("msg","没有已配对连接的RTK蓝牙设备!");
|
|
|
+ return res;
|
|
|
}
|
|
|
if(!arrBle.contains(rtkName)){
|
|
|
res.put("code","7");
|
|
|
res.put("msg","您选择的设备"+rtkName+"未配对,请重新选择或在手机蓝牙设置页重新配对");
|
|
|
+ return res;
|
|
|
}
|
|
|
//TODO cors相关判断 , 全传就登录, 有一个没传就不登
|
|
|
String ip = moduleContext.optString("ip");
|
|
@@ -708,9 +789,11 @@ public class APIModuleGis extends UZModule {
|
|
|
|
|
|
res.put("code","0");
|
|
|
res.put("msg","success");
|
|
|
+ return res;
|
|
|
}else {
|
|
|
ActivityCompat.requestPermissions(this.activity(), PERMISSIONS, REQUEST_PERMISSION);
|
|
|
}
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
//TODO Lx 销毁服务绑定
|