|
|
@@ -33,6 +33,8 @@ import com.tendyron.etc.core.guizhou.TDRimpl; |
|
|
|
import com.tendyron.etc.guizhou.TianDiBle; |
|
|
|
import com.wanji.etcble.service.WJBleAPI; |
|
|
|
import com.watchdata.obusdkguizhou.impl.ObuSdkImpl; |
|
|
|
import com.wuxian.wxsdk.BleManager; |
|
|
|
import com.wuxian.wxsdk.bean.Result; |
|
|
|
import com.zj.blueinfoReader.PlkReaderLeLib; |
|
|
|
import com.zj.transmission.GattConnectState; |
|
|
|
import com.zj.transmission.TransmissionReader; |
|
|
@@ -121,6 +123,11 @@ public class BoxManagers implements ResponseListener { |
|
|
|
*/ |
|
|
|
public TianDiBle tianDiBle = null; |
|
|
|
private static int TianDi = 11; |
|
|
|
/** |
|
|
|
* 无线感测 |
|
|
|
*/ |
|
|
|
public BleManager bleManager = null; |
|
|
|
private static int WX = 12; |
|
|
|
/** |
|
|
|
* 蓝牙链接和断开的回调 |
|
|
|
*/ |
|
|
@@ -246,157 +253,168 @@ public class BoxManagers implements ResponseListener { |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } |
|
|
|
new AsyncTask<Void, Void, BluetoothDevice>() { |
|
|
|
@Override |
|
|
|
protected BluetoothDevice doInBackground(Void... voids) { |
|
|
|
if (null != device.getName() && device.getName().startsWith("PLK_")) { |
|
|
|
//连接中交 |
|
|
|
isPlk = ZJ; |
|
|
|
mPlkLib = new ZJReaderLeLib(mContext); |
|
|
|
mPlkLib.Open(); |
|
|
|
mPlkLib.SetReaderLeCallback(plkCallBack); |
|
|
|
mPlkLib.Connect(device.toString()); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("sdlan")) { |
|
|
|
//中交新版SDK,调试时间2017.09.14 |
|
|
|
isPlk = ZJ_NEW; |
|
|
|
return device; |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("JY")) { |
|
|
|
//链接金益 |
|
|
|
isPlk = JY; |
|
|
|
new AsyncTask<Void, Void, BluetoothDevice>() { |
|
|
|
@Override |
|
|
|
protected BluetoothDevice doInBackground(Void... voids) { |
|
|
|
if (null != device.getName() && device.getName().startsWith("WX")) { |
|
|
|
//连接无线感测 |
|
|
|
isPlk = WX; |
|
|
|
bleManager = new BleManager(mContext); |
|
|
|
Result _ss = bleManager.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getSs("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("PLK_")) { |
|
|
|
//连接中交 |
|
|
|
isPlk = ZJ; |
|
|
|
mPlkLib = new ZJReaderLeLib(mContext); |
|
|
|
mPlkLib.Open(); |
|
|
|
mPlkLib.SetReaderLeCallback(plkCallBack); |
|
|
|
mPlkLib.Connect(device.toString()); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("sdlan")) { |
|
|
|
//中交新版SDK,调试时间2017.09.14 |
|
|
|
isPlk = ZJ_NEW; |
|
|
|
return device; |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("JY")) { |
|
|
|
//链接金益 |
|
|
|
isPlk = JY; |
|
|
|
/*obuInterface = ObuInterface.getInstance(); |
|
|
|
obuInterface.initialize(mContext);*/ |
|
|
|
|
|
|
|
com.genvict.obusdk.data.ServiceStatus _ss = obuInterface.connectDevice(device |
|
|
|
.getAddress()); |
|
|
|
if (null != _ss) { |
|
|
|
result = getJYss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (null != device.getName() && device.getName().startsWith("LC")) { |
|
|
|
//链接金益 |
|
|
|
isPlk = LC; |
|
|
|
obuInterface = ObuInterface.getInstance(); |
|
|
|
obuInterface.initialize(mContext); |
|
|
|
try { |
|
|
|
Thread.sleep(500); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
com.genvict.obusdk.data.ServiceStatus _ss = obuInterface.connectDevice(device |
|
|
|
.getAddress()); |
|
|
|
if (null != _ss) { |
|
|
|
result = getJYss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (null != device.getName() && device.getName().startsWith("WJ")) { |
|
|
|
isPlk = WJ; |
|
|
|
wjBleAPI = WJBleAPI.getInstance(mContext); |
|
|
|
com.wanji.etcble.bean.ServiceStatus _ss = wjBleAPI.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getWJss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (null != device.getName() && device.getName().startsWith("ZZ")) { |
|
|
|
isPlk = ZZ; |
|
|
|
wjBleAPI = WJBleAPI.getInstance(mContext); |
|
|
|
com.wanji.etcble.bean.ServiceStatus _ss = wjBleAPI.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getWJss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
com.genvict.obusdk.data.ServiceStatus _ss = obuInterface.connectDevice(device |
|
|
|
.getAddress()); |
|
|
|
if (null != _ss) { |
|
|
|
result = getJYss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (null != device.getName() && device.getName().startsWith("AT")) { |
|
|
|
isPlk = Artc; |
|
|
|
artcBleGuizhouSDK = ArtcBleGuizhouSDK.getInstance(mContext); |
|
|
|
ArtcBleGuizhouSDK.ServiceStatus _ss = artcBleGuizhouSDK.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getSs("连接设备", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("LC")) { |
|
|
|
//链接金益 |
|
|
|
isPlk = LC; |
|
|
|
obuInterface = ObuInterface.getInstance(); |
|
|
|
obuInterface.initialize(mContext); |
|
|
|
try { |
|
|
|
Thread.sleep(500); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
com.genvict.obusdk.data.ServiceStatus _ss = obuInterface.connectDevice(device |
|
|
|
.getAddress()); |
|
|
|
if (null != _ss) { |
|
|
|
result = getJYss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (null != device.getName() && device.getName().startsWith("JT")) { |
|
|
|
isPlk = JT; |
|
|
|
if (null == jtObu) { |
|
|
|
jtObu = JtObu.getInstance(mContext); |
|
|
|
} |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("WJ")) { |
|
|
|
isPlk = WJ; |
|
|
|
wjBleAPI = WJBleAPI.getInstance(mContext); |
|
|
|
com.wanji.etcble.bean.ServiceStatus _ss = wjBleAPI.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getWJss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} |
|
|
|
|
|
|
|
result = getSs("连接设备", jtObu.connectDevice(device)); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("ZZ")) { |
|
|
|
isPlk = ZZ; |
|
|
|
wjBleAPI = WJBleAPI.getInstance(mContext); |
|
|
|
com.wanji.etcble.bean.ServiceStatus _ss = wjBleAPI.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getWJss("初始化", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("WQ")) { |
|
|
|
isPlk = WQ; |
|
|
|
WoQiObu1 = ObuSdkImpl.getInstance(mContext); |
|
|
|
result = getSs("连接设备", WoQiObu1.connectDevice(device)); |
|
|
|
try { |
|
|
|
Thread.sleep(1000); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (null != device.getName() && device.getName().startsWith("AT")) { |
|
|
|
isPlk = Artc; |
|
|
|
artcBleGuizhouSDK = ArtcBleGuizhouSDK.getInstance(mContext); |
|
|
|
ArtcBleGuizhouSDK.ServiceStatus _ss = artcBleGuizhouSDK.connectDevice(device); |
|
|
|
if (null != _ss) { |
|
|
|
result = getSs("连接设备", _ss); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("CG")) { |
|
|
|
isPlk = ChengGu; |
|
|
|
ChengGuObu = BluetoothHelper.getInstance(); |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mConnectStatus.ConnectCb(getSs("连接设备", ChengGuObu.connectDevice(device))); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("TD")) { |
|
|
|
isPlk = TianDi; |
|
|
|
tianDiBle = TDRimpl.getInstance(mContext); |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mConnectStatus.ConnectCb(getSs("连接设备", tianDiBle.connectDevice(device))); |
|
|
|
|
|
|
|
} else {//连接聚力 |
|
|
|
//CZFIX 兼容7.0手机的问题,比如锤子手机会报错 Can't create handler inside thread that has not called Looper.prepare() |
|
|
|
MainHandler.getInstance().post(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
isPlk = JL; |
|
|
|
mObuMan = new deviceInit(mContext); |
|
|
|
mObuMan.setConnectStatusCallback(csCallBack); |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mObuMan.connectDevice(device); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onPostExecute(BluetoothDevice bluetoothDevice) { |
|
|
|
super.onPostExecute(bluetoothDevice); |
|
|
|
if (null != bluetoothDevice) { |
|
|
|
mTReader = new TransmissionReader(mContext); |
|
|
|
mTReader.setReaderLeCallBack(zjReaderLeCallBack); |
|
|
|
mTReader.connectDevice(bluetoothDevice); |
|
|
|
deviceName = bluetoothDevice.getName(); |
|
|
|
} else if (null == bluetoothDevice && 2 == isPlk) { |
|
|
|
//中交新版SDK,调试时间2017.09.14 |
|
|
|
Toast.makeText(mContext, "设备不支持蓝牙4.0", Toast.LENGTH_SHORT).show(); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("JT")) { |
|
|
|
isPlk = JT; |
|
|
|
if (null == jtObu) { |
|
|
|
jtObu = JtObu.getInstance(mContext); |
|
|
|
} |
|
|
|
|
|
|
|
result = getSs("连接设备", jtObu.connectDevice(device)); |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("WQ")) { |
|
|
|
isPlk = WQ; |
|
|
|
WoQiObu1 = ObuSdkImpl.getInstance(mContext); |
|
|
|
result = getSs("连接设备", WoQiObu1.connectDevice(device)); |
|
|
|
try { |
|
|
|
Thread.sleep(1000); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mConnectStatus.ConnectCb(result); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("CG")) { |
|
|
|
isPlk = ChengGu; |
|
|
|
ChengGuObu = BluetoothHelper.getInstance(); |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mConnectStatus.ConnectCb(getSs("连接设备", ChengGuObu.connectDevice(device))); |
|
|
|
} else if (null != device.getName() && device.getName().startsWith("TD")) { |
|
|
|
isPlk = TianDi; |
|
|
|
tianDiBle = TDRimpl.getInstance(mContext); |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mConnectStatus.ConnectCb(getSs("连接设备", tianDiBle.connectDevice(device))); |
|
|
|
|
|
|
|
} else {//连接聚力 |
|
|
|
//CZFIX 兼容7.0手机的问题,比如锤子手机会报错 Can't create handler inside thread that has not called Looper.prepare() |
|
|
|
MainHandler.getInstance().post(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
isPlk = JL; |
|
|
|
mObuMan = new deviceInit(mContext); |
|
|
|
mObuMan.setConnectStatusCallback(csCallBack); |
|
|
|
try { |
|
|
|
Thread.sleep(300); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
mObuMan.connectDevice(device); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}.execute(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onPostExecute(BluetoothDevice bluetoothDevice) { |
|
|
|
super.onPostExecute(bluetoothDevice); |
|
|
|
if (null != bluetoothDevice) { |
|
|
|
mTReader = new TransmissionReader(mContext); |
|
|
|
mTReader.setReaderLeCallBack(zjReaderLeCallBack); |
|
|
|
mTReader.connectDevice(bluetoothDevice); |
|
|
|
deviceName = bluetoothDevice.getName(); |
|
|
|
} else if (null == bluetoothDevice && 2 == isPlk) { |
|
|
|
//中交新版SDK,调试时间2017.09.14 |
|
|
|
Toast.makeText(mContext, "设备不支持蓝牙4.0", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
}.execute(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 断开设备 |
|
|
|
*/ |
|
|
|
public void disconnect() { |
|
|
|
if (isPlk == ZJ) { |
|
|
|
if (isPlk == WX) { |
|
|
|
bleManager.disconnect(); |
|
|
|
bleManager = null; |
|
|
|
} else if (isPlk == ZJ) { |
|
|
|
//0:中交;1:聚力 |
|
|
|
mPlkLib.Disconnect(); |
|
|
|
mPlkLib = null; |
|
|
@@ -570,7 +588,10 @@ public class BoxManagers implements ResponseListener { |
|
|
|
*/ |
|
|
|
public ServiceStatus resetICC() { |
|
|
|
result = ServiceStatusBrage.getServiceStatus(); |
|
|
|
if (isPlk == ZJ) { |
|
|
|
if (isPlk == WX) { |
|
|
|
Result _ss = bleManager.reset(1); |
|
|
|
result = getSs("ICC复位", _ss); |
|
|
|
} else if (isPlk == ZJ) { |
|
|
|
//0:中交;1:聚力 |
|
|
|
String str = mPlkLib.GetAtrStr(2000); |
|
|
|
result.setServiceCode(0); |
|
|
@@ -628,7 +649,10 @@ public class BoxManagers implements ResponseListener { |
|
|
|
*/ |
|
|
|
public void resetEsam() { |
|
|
|
ServiceStatus result = ServiceStatusBrage.getServiceStatus(); |
|
|
|
if (isPlk == 1) { |
|
|
|
if (isPlk == WX) { |
|
|
|
Result _ss = bleManager.reset(1); |
|
|
|
result = getSs("ESAM复位", _ss); |
|
|
|
} else if (isPlk == 1) { |
|
|
|
//聚力 |
|
|
|
result = mObuMan.resetEsam(5000); |
|
|
|
} else if (isPlk == 3) { |
|
|
@@ -678,6 +702,10 @@ public class BoxManagers implements ResponseListener { |
|
|
|
*/ |
|
|
|
public ServiceStatus sendApduICC(String cmd) { |
|
|
|
result = ServiceStatusBrage.getServiceStatus(); |
|
|
|
if (isPlk == WX) { |
|
|
|
Result _ss = bleManager.sendApdu(cmd, 5000); |
|
|
|
result = getSs(cmd, _ss); |
|
|
|
}else |
|
|
|
if (isPlk == ZJ) { |
|
|
|
//0:中交;1:聚力 |
|
|
|
String str = mPlkLib.ApduStr(cmd, 5000); |
|
|
@@ -752,6 +780,10 @@ public class BoxManagers implements ResponseListener { |
|
|
|
*/ |
|
|
|
public ServiceStatus sendApduEsam(String cmd) { |
|
|
|
result = ServiceStatusBrage.getServiceStatus(); |
|
|
|
if (isPlk == WX) { |
|
|
|
Result _ss = bleManager.sendApdu(cmd, 5000); |
|
|
|
result = getSs(cmd, _ss); |
|
|
|
}else |
|
|
|
if (isPlk == JL) { |
|
|
|
//聚力6217232402000311359 |
|
|
|
ServiceStatus ss = mObuMan.sendApduEsam(cmd, 5000); |
|
|
@@ -807,10 +839,10 @@ public class BoxManagers implements ResponseListener { |
|
|
|
j.put("ServiceInfo", result.getServiceInfo()); |
|
|
|
j.put("ServiceCode", result.getServiceCode()); |
|
|
|
} catch (JSONException e) { |
|
|
|
Log.e("log","打印标题:" + e.getMessage() ); |
|
|
|
Log.e("log", "打印标题:" + e.getMessage()); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
Log.e("log","返回结果:" + j.toString() ); |
|
|
|
Log.e("log", "返回结果:" + j.toString()); |
|
|
|
return j.toString(); |
|
|
|
} |
|
|
|
|