|
|
@@ -127,15 +127,39 @@ object BusinessManager {
|
|
|
when ((it.data as SwitchModeMsg).job) {
|
|
|
// 工作模式
|
|
|
1 -> {
|
|
|
-
|
|
|
+ if (it.data.res == 1) {
|
|
|
+ // 只能在这里断开,不能全部断开
|
|
|
+ BleManager.getInstance().disconnect(it.data.bleBean.bleDevice)
|
|
|
+
|
|
|
+ // 打开钥匙卡扣
|
|
|
+ val keyBean = ModBusController.getKeyByMac(it.data.bleBean.bleDevice.mac)
|
|
|
+ if (keyBean == null) {
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
|
|
|
+ ToastUtils.tip(R.string.key_not_exists)
|
|
|
+ } else {
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
|
|
|
+ val dock = ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
|
|
|
+ ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
|
|
|
+ }
|
|
|
+ // 强制结束Loading防止有loading仍在显示
|
|
|
+ Executor.delayOnMain(500) {
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LogUtil.e("切换工作模式失败 : ${it.data.bleBean.bleDevice.mac}")
|
|
|
+ // TODO 切换工作模式失败
|
|
|
+ }
|
|
|
}
|
|
|
// 待机模式
|
|
|
2 -> {
|
|
|
if (it.data.res == 1) {
|
|
|
// 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
|
Executor.delayOnMain(500) {
|
|
|
- getCurrentStatus(it.data.bleBean.bleDevice)
|
|
|
+ getCurrentStatus(1, it.data.bleBean.bleDevice)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ LogUtil.e("切换待机模式失败 : ${it.data.bleBean.bleDevice.mac}")
|
|
|
+ // TODO 切换待机模式失败
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -221,7 +245,7 @@ object BusinessManager {
|
|
|
keyBean.mac?.let {
|
|
|
unregisterConnectListener(it)
|
|
|
}
|
|
|
- mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(0, keyBean.rfid)))
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -248,7 +272,7 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(1, lockBean.rfid)))
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_LOCK, lockBean.rfid)))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -954,8 +978,8 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun getCurrentStatus(bleDevice: BleDevice) {
|
|
|
- LogUtil.i("getCurrentStatus - ${bleDevice.mac}")
|
|
|
+ fun getCurrentStatus(from: Int, bleDevice: BleDevice) {
|
|
|
+ LogUtil.i("getCurrentStatus - ${bleDevice.mac} - from : $from")
|
|
|
BleCmdManager.getCurrentStatus(bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
LogUtil.i("getCurrentStatus success : ${bleDevice.mac}")
|
|
|
@@ -964,7 +988,7 @@ object BusinessManager {
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.i("getCurrentStatus fail : ${bleDevice.mac}")
|
|
|
Executor.delayOnMain(500) {
|
|
|
- getCurrentStatus(bleDevice)
|
|
|
+ getCurrentStatus(from, bleDevice)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -975,21 +999,6 @@ object BusinessManager {
|
|
|
BleCmdManager.switchMode(STATUS_WORK, bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
LogUtil.i("switch mode work success : ${bleDevice.mac}")
|
|
|
- // 只能在这里断开,不能全部断开
|
|
|
- BleManager.getInstance().disconnect(bleDevice)
|
|
|
-
|
|
|
- // 打开钥匙卡扣
|
|
|
- val keyBean = ModBusController.getKeyByMac(bleDevice.mac)
|
|
|
- if (keyBean == null) {
|
|
|
- if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
|
|
|
- ToastUtils.tip(R.string.key_not_exists)
|
|
|
- } else {
|
|
|
- if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
|
|
|
- val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
- ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
|
|
|
- }
|
|
|
- // 强制结束Loading防止有loading仍在显示
|
|
|
- mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
|
|
|
}
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.e("switch mode work fail : ${exception?.code} - ${exception?.description}")
|
|
|
@@ -1119,7 +1128,7 @@ object BusinessManager {
|
|
|
}
|
|
|
// 检查有无当前工作票的钥匙
|
|
|
mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == info.ticketId }?.let { itKey ->
|
|
|
- getCurrentStatus(getBleDeviceByMac(ModBusController.getKeyByRfid(itKey.nfc)?.mac)!!.bleDevice)
|
|
|
+ getCurrentStatus(2, getBleDeviceByMac(ModBusController.getKeyByRfid(itKey.nfc)?.mac)!!.bleDevice)
|
|
|
}
|
|
|
}
|
|
|
}
|