|
|
@@ -37,10 +37,12 @@ import com.grkj.iscs.model.bo.DeviceTakeUpdateBO
|
|
|
import com.grkj.iscs.model.bo.WorkTicketGetBO
|
|
|
import com.grkj.iscs.model.bo.WorkTicketSendBO
|
|
|
import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
|
|
|
+import com.grkj.iscs.model.eventmsg.CurrentModeMsg
|
|
|
import com.grkj.iscs.model.eventmsg.DeviceTakeUpdateMsg
|
|
|
import com.grkj.iscs.model.eventmsg.GetTicketStatusMsg
|
|
|
import com.grkj.iscs.model.eventmsg.LoadingMsg
|
|
|
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_GET_TICKET_STATUS
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
|
|
|
@@ -103,16 +105,23 @@ object BusinessManager {
|
|
|
*/
|
|
|
fun initMsgEventBus() {
|
|
|
mEventBus.observeForever {
|
|
|
+ LogUtil.i("msgEvent : $it")
|
|
|
when (it.code) {
|
|
|
+ // loading消息
|
|
|
MSG_EVENT_LOADING -> {
|
|
|
Executor.runOnMain {
|
|
|
val loadingMsg = it.data as LoadingMsg
|
|
|
(ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(loadingMsg.isShow, loadingMsg.loadingText)
|
|
|
}
|
|
|
}
|
|
|
+ // 设备取出
|
|
|
MSG_EVENT_DEVICE_TAKE_UPDATE -> {
|
|
|
handleDeviceTake(it.data as DeviceTakeUpdateMsg)
|
|
|
}
|
|
|
+ // 钥匙当前模式
|
|
|
+ MSG_EVENT_CURRENT_MODE -> {
|
|
|
+ handleCurrentMode(it.data as CurrentModeMsg)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -244,7 +253,7 @@ object BusinessManager {
|
|
|
NetApi.getKeyInfo(rfid) {
|
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
ModBusController.updateKeyMac(dockBean.addr, isLeft, it.macAddress)
|
|
|
- showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr)
|
|
|
+// showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr)
|
|
|
} else {
|
|
|
ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
}
|
|
|
@@ -304,13 +313,13 @@ object BusinessManager {
|
|
|
* 钥匙归还提示确认弹框
|
|
|
*/
|
|
|
private fun showKeyReturnDialog(mac: String, isLeft: Boolean, slaveAddress: Byte) {
|
|
|
- val dlg = TipDialog(MyApplication.instance!!.applicationContext)
|
|
|
- dlg.setTip(MyApplication.instance!!.getString(R.string.key_return_tip))
|
|
|
- dlg.setType(TipDialog.TYPE_CONFIRM)
|
|
|
- dlg.setConfirmListener {
|
|
|
- ModBusController.controlKeyBuckle(false, isLeft, slaveAddress)
|
|
|
- getTicketStatusBusiness(mac, true)
|
|
|
- }
|
|
|
+// val dlg = TipDialog(MyApplication.instance!!.applicationContext)
|
|
|
+// dlg.setTip(MyApplication.instance!!.getString(R.string.key_return_tip))
|
|
|
+// dlg.setType(TipDialog.TYPE_CONFIRM)
|
|
|
+// dlg.setConfirmListener {
|
|
|
+// ModBusController.controlKeyBuckle(false, isLeft, slaveAddress)
|
|
|
+// getTicketStatusBusiness(mac, true)
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
fun readLockBuckleStatus() {
|
|
|
@@ -422,7 +431,9 @@ object BusinessManager {
|
|
|
if (deviceList.none { it.bleDevice.mac == mac }) {
|
|
|
connectListeners.add(ConnectListener(mac, callBack))
|
|
|
if (connectListeners.size == 1) {
|
|
|
- connectKey()
|
|
|
+ Executor.runOnMain {
|
|
|
+ connectKey()
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
callBack?.invoke(true, deviceList.find { it.bleDevice.mac == mac })
|
|
|
@@ -864,6 +875,10 @@ object BusinessManager {
|
|
|
byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> handleSwitchModeResult(byteArray, isNeedLoading)
|
|
|
// 工作票下发
|
|
|
byteArray.startsWith(BleConst.RSP_SEND_WORK_TICKET) -> handleWorkTicketResult(bleBean, byteArray, isNeedLoading)
|
|
|
+ // 获取设备当前状态
|
|
|
+ byteArray.startsWith(BleConst.RSP_CURRENT_STATUS) -> BleCmdManager.handleCurrentStatus(byteArray) {
|
|
|
+ mEventBus.postValue(MsgEvent(MSG_EVENT_CURRENT_MODE, CurrentModeMsg(bleBean, it)))
|
|
|
+ }
|
|
|
// 获取设备工作票完成情况
|
|
|
byteArray.startsWith(BleConst.RSP_WORK_TICKET_RESULT) && byteArray[3] == 0x02.toByte() ->
|
|
|
handleTicketStatus(bleBean.bleDevice, byteArray, isNeedLoading)
|
|
|
@@ -909,6 +924,21 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun getCurrentStatus(bleDevice: BleDevice) {
|
|
|
+ BleCmdManager.getCurrentStatus(bleDevice, object : CustomBleWriteCallback() {
|
|
|
+ override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
+ LogUtil.i("getCurrentStatus success")
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onWriteFailure(exception: BleException?) {
|
|
|
+ LogUtil.i("getCurrentStatus fail")
|
|
|
+ Executor.delayOnMain(500) {
|
|
|
+ getCurrentStatus(bleDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
private fun switchWorkMode(bleDevice: BleDevice, isNeedLoading: Boolean = false) {
|
|
|
LogUtil.i("switchWorkMode - ${bleDevice.mac}")
|
|
|
BleCmdManager.switchMode(STATUS_WORK, bleDevice, object : CustomBleWriteCallback() {
|
|
|
@@ -1046,4 +1076,19 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private fun handleCurrentMode(currentModeMsg: CurrentModeMsg) {
|
|
|
+ when (currentModeMsg.mode) {
|
|
|
+ 0x01.toByte() -> {
|
|
|
+ // TODO 读工作票
|
|
|
+ getTicketStatusBusiness(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
+ }
|
|
|
+ 0x02.toByte() -> {
|
|
|
+ // 暂无
|
|
|
+ }
|
|
|
+ 0x03.toByte() -> {
|
|
|
+ // TODO 上报?
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|