|
|
@@ -20,8 +20,13 @@ import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.artc.gbapi.ArtcCallBack.ArtcInterface; |
|
|
|
import com.artc.gbapi.invoke.ArtcObuManger; |
|
|
|
import com.genvict.ble.sdk.callback.OnConnectCallback; |
|
|
|
import com.genvict.ble.sdk.manager.entity.GvApiResult; |
|
|
|
import com.genvict.ble.sdk.manager.impl.ObuInterface; |
|
|
|
import com.hjq.base.BaseDialog; |
|
|
|
import com.huntersun.vky.obublelib.box.BoxManagers; |
|
|
|
import com.huntersun.vky.obublelib.util.UtilTool; |
|
|
@@ -40,6 +45,11 @@ import com.kcht.obublesdk.bleChannelLib.doneBleLib.exception.BleException; |
|
|
|
import com.kcht.obublesdk.region.guizhou.EnableState; |
|
|
|
import com.kcht.obublesdk.region.guizhou.KcBleSDK; |
|
|
|
import com.kcht.obublesdk.region.guizhou.ScanDeviceResultCallBack; |
|
|
|
import com.wanji.lw.etc.bean.DataResult; |
|
|
|
import com.wanji.lw.etc.bean.callBack; |
|
|
|
import com.wanji.lw.etc.bean.listenStatus; |
|
|
|
import com.wanji.lw.etc.bean.success; |
|
|
|
import com.wanji.lw.etc.service.WJBleAPI; |
|
|
|
import com.wuxian.wxsdk.BleManager; |
|
|
|
import com.wuxian.wxsdk.bean.Result; |
|
|
|
import com.wuxian.wxsdk.callback.ConnectionCallBack; |
|
|
@@ -64,8 +74,7 @@ import jl.obu.com.obu.area.biyadi.ResultStatus; |
|
|
|
*/ |
|
|
|
public class BluetoothDialog { |
|
|
|
|
|
|
|
public static final class Builder |
|
|
|
extends CommonDialog.Builder<Builder> implements ToastAction { |
|
|
|
public static final class Builder extends CommonDialog.Builder<Builder> implements ToastAction { |
|
|
|
private final Activity Context; |
|
|
|
private final LinearLayout loadingLay;//加载布局 |
|
|
|
private final RecyclerView rv;//蓝牙设备展示列表 |
|
|
@@ -78,6 +87,8 @@ public class BluetoothDialog { |
|
|
|
private static ArtcObuManger artcObuManger; |
|
|
|
private static BleManager wxBleManager; |
|
|
|
private static KcBleSDK kcBleSDK; |
|
|
|
private static WJBleAPI wJBleAPI; |
|
|
|
private static ObuInterface obuInterface; |
|
|
|
private BluetoothReceiver bluetoothReceiver; |
|
|
|
private static int isPlk; |
|
|
|
public static int HS_JL = 0;//恒生聚力 |
|
|
@@ -85,6 +96,8 @@ public class BluetoothDialog { |
|
|
|
public static int JL = 2;//聚力 |
|
|
|
public static int WX = 3;//无线感测 |
|
|
|
public static int KC = 4;//科场 |
|
|
|
public static int WJ = 5;//万集 |
|
|
|
public static int JY = 6;//金溢 |
|
|
|
// private HandlerThread thread; |
|
|
|
// private Handler mBackgroundHandler; |
|
|
|
private final TextView mHintTextView; |
|
|
@@ -116,6 +129,8 @@ public class BluetoothDialog { |
|
|
|
artcObuManger = ArtcObuManger.getInstance(context); |
|
|
|
wxBleManager = BleManager.getInstance(context); |
|
|
|
kcBleSDK = new KcBleSDK(context); |
|
|
|
wJBleAPI = WJBleAPI.getInstance(context); |
|
|
|
obuInterface = ObuInterface.getInstance(context); |
|
|
|
// artcBleAPI = ArtcBleAPI.getInstance(context); |
|
|
|
//加载动画 |
|
|
|
loadingLay = findViewById(R.id.loading_lay); |
|
|
@@ -129,10 +144,7 @@ public class BluetoothDialog { |
|
|
|
// thread.start(); |
|
|
|
// mBackgroundHandler = new Handler(thread.getLooper()); |
|
|
|
rv = findViewById(R.id.rv); |
|
|
|
mDialog = new WaitDialog.Builder(context) |
|
|
|
.setCancelable(false) |
|
|
|
.setMessage("蓝牙设备连接中...") |
|
|
|
.create(); |
|
|
|
mDialog = new WaitDialog.Builder(context).setCancelable(false).setMessage("蓝牙设备连接中...").create(); |
|
|
|
//隐藏确认关闭框 |
|
|
|
mShuView.setVisibility(View.GONE); |
|
|
|
mSelect.setVisibility(View.GONE); |
|
|
@@ -227,17 +239,17 @@ public class BluetoothDialog { |
|
|
|
mDialog.dismiss(); |
|
|
|
} |
|
|
|
|
|
|
|
public void showDialog(){ |
|
|
|
if (null!=mDialog&&!mDialog.isShowing()){ |
|
|
|
public void showDialog() { |
|
|
|
if (null != mDialog && !mDialog.isShowing()) { |
|
|
|
mDialog.show(); |
|
|
|
new Handler().postDelayed(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
if (null!=mDialog&&mDialog.isShowing()){ |
|
|
|
if (null != mDialog && mDialog.isShowing()) { |
|
|
|
mDialog.dismiss(); |
|
|
|
} |
|
|
|
} |
|
|
|
},30000); |
|
|
|
}, 30000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -288,8 +300,7 @@ public class BluetoothDialog { |
|
|
|
if ("0".equals(s2 + "")) { |
|
|
|
String strStatus = MethodManager.ReadCard();//获取卡信息 |
|
|
|
|
|
|
|
Log.e("okhttp", "卡对象信息:" + BoxManagers.mCardInfoBean.getCard_No() + |
|
|
|
"OBU号:" + status + "车辆信息:" + BoxManagers.mDecryptVehicleBean); |
|
|
|
Log.e("okhttp", "卡对象信息:" + BoxManagers.mCardInfoBean.getCard_No() + "OBU号:" + status + "车辆信息:" + BoxManagers.mDecryptVehicleBean); |
|
|
|
mResult.BluetoothLinkIsSuccessful(BoxManagers.gerBoxManager()); //回调成功 |
|
|
|
autoDismiss(); |
|
|
|
} |
|
|
@@ -345,7 +356,7 @@ public class BluetoothDialog { |
|
|
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); |
|
|
|
if (!list.contains(device)) {//防止重复添加 |
|
|
|
if (device.getName() != null) {//过滤掉设备名称为null的设备 |
|
|
|
Log.e("设备名称",device.getName()); |
|
|
|
Log.e("设备名称", device.getName()); |
|
|
|
for (String item : deviceWith) { //过滤掉不是指定名称的设备 |
|
|
|
if (device.getName().startsWith(item)) { |
|
|
|
list.add(device); |
|
|
@@ -368,7 +379,7 @@ public class BluetoothDialog { |
|
|
|
// @Override |
|
|
|
// public void run() { |
|
|
|
if (list.size() > 0) { |
|
|
|
if (list.get(position).getName().startsWith("ETC")) { |
|
|
|
if (list.get(position).getName().startsWith("ETC") || list.get(position).getName().startsWith("JY")) { |
|
|
|
new ConnectDeviceThread(list.get(position)).start(); |
|
|
|
} else { |
|
|
|
connectDevice(plkCallBack, list.get(position)); |
|
|
@@ -448,57 +459,97 @@ public class BluetoothDialog { |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(0, isPlk); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else if (d.getName().contains("WX")){ |
|
|
|
} else if (d.getName().contains("WX")) { |
|
|
|
autoDismiss(); |
|
|
|
Log.e("WX开始链接","~~~~~~"+d.getAddress()+"~~~~~~~"); |
|
|
|
Log.e("WX开始链接", "~~~~~~" + d.getAddress() + "~~~~~~~"); |
|
|
|
wxBleManager.connectWXDevice(d, new ConnectionCallBack() { |
|
|
|
@Override |
|
|
|
public void call(Result result) { |
|
|
|
Log.e("WX链接结果","~~~~~~"+JSON.toJSONString(result)+"~~~~~~~"); |
|
|
|
Log.e("WX链接结果", "~~~~~~" + JSON.toJSONString(result) + "~~~~~~~"); |
|
|
|
isPlk = WX; |
|
|
|
mDialog.dismiss(); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(result.getCode(),isPlk); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(result.getCode(), isPlk); |
|
|
|
} |
|
|
|
}); |
|
|
|
// artcObuManger.connectBleDev(d, new ArtcInterface.BleConnectCallBack() { |
|
|
|
// @Override |
|
|
|
// public void onFail(String s) { |
|
|
|
// |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onSuccess() { |
|
|
|
// isPlk = WX; |
|
|
|
// mDialog.dismiss(); |
|
|
|
// mResult.BluetoothLinkIsSuccessful9901(0, isPlk); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
}else if (d.getName().contains("KC")){ |
|
|
|
} else if (d.getName().contains("KC")) { |
|
|
|
autoDismiss(); |
|
|
|
Log.e("KC链接","~~~~~~开始连接~~~~~~~"); |
|
|
|
Log.e("KC链接", "~~~~~~开始连接~~~~~~~"); |
|
|
|
kcBleSDK.connectDevice(d, new com.kcht.obublesdk.region.guizhou.Callback() { |
|
|
|
@Override |
|
|
|
public void onResult(com.kcht.obublesdk.region.guizhou.ResultStatus resultStatus) { |
|
|
|
if (resultStatus.getCode() == 0){ |
|
|
|
if (resultStatus.getCode() == 0) { |
|
|
|
isPlk = KC; |
|
|
|
mDialog.dismiss(); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(0,isPlk); |
|
|
|
Log.e("KC链接", "连接成功"); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(0, isPlk); |
|
|
|
} |
|
|
|
} |
|
|
|
}, new com.kcht.obublesdk.region.guizhou.Callback() { |
|
|
|
@Override |
|
|
|
public void onResult(com.kcht.obublesdk.region.guizhou.ResultStatus resultStatus) { |
|
|
|
if (resultStatus.getCode() == 0){ |
|
|
|
if (resultStatus.getCode() == 0) { |
|
|
|
isPlk = KC; |
|
|
|
mDialog.dismiss(); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(0,isPlk); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(0, isPlk); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (d.getName().contains("WJ")) { |
|
|
|
autoDismiss(); |
|
|
|
Log.e("WJ链接", "~~~~~~开始连接~~~~~~~"); |
|
|
|
wJBleAPI.connectDevice(d, new success() { |
|
|
|
@Override |
|
|
|
public void onSuccess(com.wanji.lw.etc.bean.Result result) { |
|
|
|
if (result.getCode() == 0) { |
|
|
|
isPlk = WJ; |
|
|
|
mDialog.dismiss(); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(result.getCode(), isPlk); |
|
|
|
} |
|
|
|
} |
|
|
|
}, new listenStatus() { |
|
|
|
@Override |
|
|
|
public void onListenStatus(com.wanji.lw.etc.bean.Result result) { |
|
|
|
if (result.getCode() == 0) { |
|
|
|
isPlk = WJ; |
|
|
|
mDialog.dismiss(); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(result.getCode(), isPlk); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (d.getName().contains("JY")) { |
|
|
|
autoDismiss(); |
|
|
|
obuInterface.connectDevice(d + "", mOnConnectCallback); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 蓝牙连接状态回调 replace |
|
|
|
*/ |
|
|
|
private final OnConnectCallback mOnConnectCallback = new OnConnectCallback() { |
|
|
|
@Override |
|
|
|
public void onConnected() { |
|
|
|
// baseDialog.show(); |
|
|
|
// activationProcess(); |
|
|
|
Log.e("金溢", "连接成功"); |
|
|
|
isPlk = JY; |
|
|
|
mDialog.dismiss(); |
|
|
|
mResult.BluetoothLinkIsSuccessful9901(0, isPlk); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onDisconnect() { |
|
|
|
Log.e("金溢", "断开连接"); |
|
|
|
mDialog.dismiss(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onConnectFail(GvApiResult result) { |
|
|
|
Log.e("金溢", "连接失败:" + result.getCode() + " " + result.getMsg()); |
|
|
|
mDialog.dismiss(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* 广播接收器(蓝牙模块) |
|
|
|
* https://blog.csdn.net/wq892373445/article/details/119748130 |
|
|
@@ -639,14 +690,15 @@ public class BluetoothDialog { |
|
|
|
/** |
|
|
|
* 获取随机数 |
|
|
|
*/ |
|
|
|
public static void getObuRandom(PerformCmdCallBack callBack){ |
|
|
|
transCmd(sendCos4,"20",callBack); |
|
|
|
public static void getObuRandom(PerformCmdCallBack callBack) { |
|
|
|
transCmd(sendCos4, "20", callBack); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 指令执行 |
|
|
|
*/ |
|
|
|
public static void transCmd(String[] cmdArray, String cmdType, PerformCmdCallBack callBack) { |
|
|
|
Log.e("运行指令",JSONObject.toJSONString(cmdArray)); |
|
|
|
if (isPlk == ATS) { |
|
|
|
artcObuManger.transCommand(cmdType.equals("10") ? 0 : 1, cmdArray, new ArtcInterface.SendDataCallBack() { |
|
|
|
@Override |
|
|
@@ -656,7 +708,7 @@ public class BluetoothDialog { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSuccess(String[] data) { |
|
|
|
Log.e("艾特斯执行指令",JSON.toJSONString(cmdArray)+"~~执行结果~~"+JSON.toJSONString(data)); |
|
|
|
Log.e("艾特斯执行指令", JSON.toJSONString(cmdArray) + "~~执行结果~~" + JSON.toJSONString(data)); |
|
|
|
callBack.performOnSuccess(data); |
|
|
|
} |
|
|
|
}); |
|
|
@@ -665,25 +717,56 @@ public class BluetoothDialog { |
|
|
|
@Override |
|
|
|
public void onResult(ResultStatus resultStatus) { |
|
|
|
Log.e("聚力读OBU", "读取合同序列号成功:" + JSON.toJSONString(resultStatus.getData())); |
|
|
|
Log.e("聚力执行指令",JSON.toJSONString(cmdArray)+"~~执行结果~~"+JSON.toJSONString(resultStatus.getData())); |
|
|
|
Log.e("聚力执行指令", JSON.toJSONString(cmdArray) + "~~执行结果~~" + JSON.toJSONString(resultStatus.getData())); |
|
|
|
callBack.performOnSuccess(resultStatus.getData()); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else if (isPlk == WX){ |
|
|
|
Result result = wxBleManager.sendApdu(TextUtils.join(",",cmdArray),"10".equals(cmdType) ? 1 : 2); |
|
|
|
Log.e("无线感测执行结果",JSON.toJSONString(result)); |
|
|
|
if (result.getCode() == 0){ |
|
|
|
callBack.performOnSuccess(result.getData().split(",")); |
|
|
|
} |
|
|
|
}else if (isPlk == KC){ |
|
|
|
} else if (isPlk == WX) { |
|
|
|
Log.e("无线感测执行", "指令~" + TextUtils.join(",", cmdArray)); |
|
|
|
Log.e("无线感测执行", "单条指令~" +cmdArray[0] + "~~~"+("10".equals(cmdType) ? 1 : 2)); |
|
|
|
Result result = wxBleManager.sendApdu(cmdArray[0], "10".equals(cmdType) ? 1 : 2); |
|
|
|
Log.e("无线感测执行结果", JSON.toJSONString(result)); |
|
|
|
if (true)return; |
|
|
|
if (result.getCode() == 0) { |
|
|
|
callBack.performOnSuccess(result.getData().split(",")); |
|
|
|
} |
|
|
|
} else if (isPlk == KC) { |
|
|
|
kcBleSDK.transCmd(cmdArray, cmdType, new com.kcht.obublesdk.region.guizhou.Callback() { |
|
|
|
@Override |
|
|
|
public void onResult(com.kcht.obublesdk.region.guizhou.ResultStatus resultStatus) { |
|
|
|
if (resultStatus.getCode() == 0){ |
|
|
|
if (resultStatus.getCode() == 0) { |
|
|
|
Log.e("指令执行成功", "指令~~" + JSONObject.toJSONString(cmdArray) + "执行结果" + JSONObject.toJSONString(resultStatus.getData())); |
|
|
|
callBack.performOnSuccess(resultStatus.getData()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (isPlk == WJ) { |
|
|
|
wJBleAPI.transCmd(cmdArray, cmdType, new callBack() { |
|
|
|
@Override |
|
|
|
public void onCallBack(DataResult dataResult) { |
|
|
|
if (dataResult.code == 0) { |
|
|
|
Log.e("指令执行成功", "指令~~" + JSONObject.toJSONString(cmdArray) + "执行结果" + JSONObject.toJSONString(dataResult)); |
|
|
|
callBack.performOnSuccess(dataResult.data); |
|
|
|
} else { |
|
|
|
Log.e("指令执行失败", "指令~~" + JSONObject.toJSONString(cmdArray) + "执行结果" + JSONObject.toJSONString(dataResult)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (isPlk == JY) { |
|
|
|
String[] cmds = cmdArray.clone(); |
|
|
|
if (cmdType.equals("10")) { |
|
|
|
com.genvict.ble.sdk.manager.entity.ServiceStatus s = obuInterface.cardCommand(cmds); |
|
|
|
if (s.getCode() == 0) { |
|
|
|
Log.e("执行结果", "指令" + JSONObject.toJSONString(cmdArray) + "结果::::" + JSONObject.toJSONString(s.getData())); |
|
|
|
callBack.performOnSuccess(JSONObject.parseArray(JSONObject.toJSONString(s.getData())).toArray(new String[0])); |
|
|
|
} |
|
|
|
} else { |
|
|
|
com.genvict.ble.sdk.manager.entity.ServiceStatus s = obuInterface.esamCommand(cmds); |
|
|
|
if (s.getCode() == 0) { |
|
|
|
Log.e("执行结果", "指令" + JSONObject.toJSONString(cmdArray) + "结果::::" + JSONObject.toJSONString(s.getData())); |
|
|
|
callBack.performOnSuccess(JSONObject.parseArray(JSONObject.toJSONString(s.getData())).toArray(new String[0])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -742,8 +825,7 @@ public class BluetoothDialog { |
|
|
|
obuReadInfoBean.startTime = data[1].substring(36, 44); |
|
|
|
obuReadInfoBean.endTime = data[1].substring(44, 52); |
|
|
|
obuReadInfoBean.version = Integer.parseInt(data[1].substring(18, 19)) >= 4 ? "4x" : "2x"; |
|
|
|
obuReadInfoBean.isJH = "1".equals(data[1].substring(53, 54)) ? "是" : "0".equals(data[1].substring(53, 54)) ? |
|
|
|
"否" : "其他:" + data[1].substring(53, 54); |
|
|
|
obuReadInfoBean.isJH = "1".equals(data[1].substring(53, 54)) ? "是" : "0".equals(data[1].substring(53, 54)) ? "否" : "其他:" + data[1].substring(53, 54); |
|
|
|
obuReadInfoBean.rand = Integer.parseInt(data[1].substring(18, 20)) > 50 ? "40" : "00"; |
|
|
|
} |
|
|
|
return obuReadInfoBean; |