|
|
@@ -45,6 +45,8 @@ import com.grkj.iscs.model.eventmsg.MsgEvent
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_CURRENT_MODE
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_TAKE_UPDATE
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
|
|
|
+import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_SWITCH_MODE
|
|
|
+import com.grkj.iscs.model.eventmsg.SwitchModeMsg
|
|
|
import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
|
|
|
import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
|
|
|
import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
|
|
|
@@ -120,6 +122,24 @@ object BusinessManager {
|
|
|
MSG_EVENT_CURRENT_MODE -> {
|
|
|
handleCurrentMode(it.data as CurrentModeMsg)
|
|
|
}
|
|
|
+ // 钥匙切换模式结果
|
|
|
+ MSG_EVENT_SWITCH_MODE -> {
|
|
|
+ when ((it.data as SwitchModeMsg).job) {
|
|
|
+ // 工作模式
|
|
|
+ 1 -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ // 待机模式
|
|
|
+ 2 -> {
|
|
|
+ if (it.data.res == 1) {
|
|
|
+ // 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
|
+ Executor.delayOnMain(500) {
|
|
|
+ getCurrentStatus(it.data.bleBean.bleDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -876,7 +896,11 @@ object BusinessManager {
|
|
|
// 获取令牌
|
|
|
byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(bleBean.bleDevice, byteArray)
|
|
|
// 工作模式切换
|
|
|
- byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> handleSwitchModeResult(byteArray, isNeedLoading)
|
|
|
+ byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> {
|
|
|
+ handleSwitchModeResult(byteArray, isNeedLoading) { res, job ->
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_SWITCH_MODE, SwitchModeMsg(job.toInt(), res.toInt(), bleBean)))
|
|
|
+ }
|
|
|
+ }
|
|
|
// 工作票下发
|
|
|
byteArray.startsWith(BleConst.RSP_SEND_WORK_TICKET) -> handleWorkTicketResult(bleBean, byteArray, isNeedLoading)
|
|
|
// 获取设备当前状态
|
|
|
@@ -894,7 +918,7 @@ object BusinessManager {
|
|
|
* job : 0x01:工作模式 0x02:待机模式
|
|
|
* res : 0x01:成功 0x02:失败
|
|
|
*/
|
|
|
- private fun handleSwitchModeResult(byteArray: ByteArray, isNeedLoading: Boolean = false) {
|
|
|
+ private fun handleSwitchModeResult(byteArray: ByteArray, isNeedLoading: Boolean = false, callBack: ((Byte, Byte) -> Unit)? = null) {
|
|
|
BleCmdManager.handleSwitchModeResult(byteArray) { job, res ->
|
|
|
if (res == 0x01.toByte() && job == 0x01.toByte()) {
|
|
|
LogUtil.i("切换工作模式成功")
|
|
|
@@ -906,6 +930,7 @@ object BusinessManager {
|
|
|
LogUtil.e("切换模式失败 : ${job.toInt()} - ${res.toInt()}")
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
}
|
|
|
+ callBack?.invoke(res, job)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -986,14 +1011,7 @@ object BusinessManager {
|
|
|
// TD:Ticket Done
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "TD$ticketJson}", true)))
|
|
|
// TODO 根据工作票完成情况,切换为待机模式
|
|
|
- switchReadyMode(bleDevice) { isSuccess ->
|
|
|
- if (isSuccess) {
|
|
|
- // 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
|
- Executor.delayOnMain(500) {
|
|
|
- getCurrentStatus(bleDevice)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ switchReadyMode(bleDevice)
|
|
|
|
|
|
// TODO 和confirm dialog冲突,待定
|
|
|
val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
@@ -1032,17 +1050,16 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun switchReadyMode(bleDevice: BleDevice, processCallback: ((Boolean) -> Unit)) {
|
|
|
+ private fun switchReadyMode(bleDevice: BleDevice) {
|
|
|
BleCmdManager.switchMode(STATUS_READY, bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
LogUtil.i("switch mode ready success : ${bleDevice.mac}")
|
|
|
- processCallback.invoke(true)
|
|
|
}
|
|
|
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.e("switch mode ready fail : ${bleDevice.mac}")
|
|
|
Executor.delayOnMain(300) {
|
|
|
- switchReadyMode(bleDevice, processCallback)
|
|
|
+ switchReadyMode(bleDevice)
|
|
|
}
|
|
|
}
|
|
|
})
|