|
|
@@ -25,12 +25,9 @@ import com.grkj.iscs.extentions.startsWith
|
|
|
import com.grkj.iscs.extentions.toHexStrings
|
|
|
import com.grkj.iscs.modbus.DockBean
|
|
|
import com.grkj.iscs.modbus.ModBusController
|
|
|
-import com.grkj.iscs.modbus.ModBusController.controlKeyBuckle
|
|
|
-import com.grkj.iscs.modbus.ModBusController.controlLockBuckle
|
|
|
import com.grkj.iscs.modbus.ModBusController.dockList
|
|
|
import com.grkj.iscs.model.Constants.PERMISSION_REQUEST_CODE
|
|
|
import com.grkj.iscs.model.Constants.USER_TYPE_LOCKER
|
|
|
-import com.grkj.iscs.model.DeviceConst
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
@@ -150,10 +147,10 @@ object BusinessManager {
|
|
|
mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
|
|
|
ToastUtils.tip(R.string.key_not_exists)
|
|
|
} else {
|
|
|
- sendLoadingEventMsg(MyApplication.instance?.applicationContext?.getString(R.string.take_out_key_tip))
|
|
|
+ sendLoadingEventMsg(CommonUtils.getStr(R.string.take_out_key_tip))
|
|
|
val dock = ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
|
|
|
ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
|
|
|
- ModBusController.updateKeyReadyStatus(it.data.bleBean.bleDevice.mac, false)
|
|
|
+ ModBusController.updateKeyReadyStatus(it.data.bleBean.bleDevice.mac, false, 1)
|
|
|
ToastUtils.tip(R.string.take_out_key)
|
|
|
}
|
|
|
} else {
|
|
|
@@ -166,7 +163,7 @@ object BusinessManager {
|
|
|
// 待机模式
|
|
|
2 -> {
|
|
|
if (it.data.res == 1) {
|
|
|
- ModBusController.updateKeyReadyStatus(it.data.bleBean.bleDevice.mac, true)
|
|
|
+ ModBusController.updateKeyReadyStatus(it.data.bleBean.bleDevice.mac, true, 2)
|
|
|
// 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
|
Executor.delayOnMain(500) {
|
|
|
getCurrentStatus(1, it.data.bleBean.bleDevice)
|
|
|
@@ -222,7 +219,7 @@ object BusinessManager {
|
|
|
ModBusController.registerStatusListener(this) { res ->
|
|
|
LogUtil.i("设备状态:${(res as List<ByteArray>).map { it.toHexStrings() }}")
|
|
|
if (res.isEmpty() || res.any { it.isEmpty() }) {
|
|
|
- var tipStr = MyApplication.instance?.applicationContext?.getString(R.string.no_response_board_exists) + " : "
|
|
|
+ var tipStr = CommonUtils.getStr(R.string.no_response_board_exists) + " : "
|
|
|
val addressList = mutableListOf<String>()
|
|
|
|
|
|
ModBusController.modBusManager?.mSlaveAddressList?.forEach { itDock ->
|
|
|
@@ -243,7 +240,7 @@ object BusinessManager {
|
|
|
DOCK_TYPE_KEY -> {
|
|
|
dockBean.getKeyList().forEach { keyBean ->
|
|
|
if (keyBean.isExist) {
|
|
|
- sendLoadingEventMsg(MyApplication.instance?.applicationContext?.getString(R.string.data_is_uploading))
|
|
|
+ sendLoadingEventMsg(CommonUtils.getStr(R.string.data_is_uploading))
|
|
|
// 放回钥匙,读取rfid
|
|
|
ModBusController.readKeyRfid(dockBean.addr, if (keyBean.isLeft) 0 else 1) { isLeft, res ->
|
|
|
if (res.size < 11) {
|
|
|
@@ -255,6 +252,7 @@ object BusinessManager {
|
|
|
NetApi.getKeyInfo(rfid) {
|
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
ModBusController.updateKeyMac(dockBean.addr, keyBean.isLeft, it.macAddress)
|
|
|
+ ModBusController.updateKeyReadyStatus(it.macAddress, false, 5)
|
|
|
// TODO 移动到HomePresenter里,根据业务进行处理
|
|
|
// showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr.toInt())
|
|
|
// registerConnectListener(it.macAddress)
|
|
|
@@ -715,7 +713,6 @@ object BusinessManager {
|
|
|
bleDevice.mac?.let { itMac ->
|
|
|
unregisterConnectListener(itMac)
|
|
|
}
|
|
|
- ModBusController.updateKeyReadyStatus(bleDevice.mac, false)
|
|
|
if (!isActiveDisConnected) {
|
|
|
// 测试模式下不重连
|
|
|
if (isTestMode) {
|
|
|
@@ -725,6 +722,8 @@ object BusinessManager {
|
|
|
Executor.delayOnMain(300) {
|
|
|
registerConnectListener(bleDevice.mac)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ ModBusController.updateKeyReadyStatus(bleDevice.mac, false, 3)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -844,6 +843,7 @@ object BusinessManager {
|
|
|
return@registerConnectListener
|
|
|
}
|
|
|
// 单bleBean json赋值
|
|
|
+ bleBean.retryCount = 0
|
|
|
bleBean.ticketSend = generateTicketSendJson(isLock, ticketDetail, lockList)
|
|
|
bleBean.ticketSend?.let { itJson ->
|
|
|
sendTicketWithRetry(itJson, bleBean.bleDevice, isNeedLoading)
|
|
|
@@ -922,16 +922,16 @@ object BusinessManager {
|
|
|
}
|
|
|
|
|
|
private fun sendTicket(jsonStr: String, bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
|
|
|
- if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始下发工作票...", null)))
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, CommonUtils.getStr(R.string.start_to_send_ticket), null)))
|
|
|
BleCmdManager.sendWorkTicket(jsonStr, bleDevice = bleDevice, callback = object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
LogUtil.i("sendTicket success")
|
|
|
- if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "工作票下发中...", null)))
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, CommonUtils.getStr(R.string.sending_ticket), null)))
|
|
|
}
|
|
|
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.e("sendTicket fail : ${bleDevice.mac}")
|
|
|
- if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票下发失败", null)))
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, CommonUtils.getStr(R.string.send_ticket_fail), null)))
|
|
|
processCallback?.invoke(false)
|
|
|
}
|
|
|
})
|
|
|
@@ -1066,6 +1066,21 @@ object BusinessManager {
|
|
|
Executor.delayOnIO(800) {
|
|
|
switchWorkMode(bleBean.bleDevice, isNeedLoading)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ sendLoadingEventMsg(null, false)
|
|
|
+ if (bleBean.retryCount < 3) {
|
|
|
+ Executor.delayOnMain(500) {
|
|
|
+ bleBean.retryCount++
|
|
|
+ sendLoadingEventMsg(MyApplication.instance!!.getString(R.string.start_to_send_ticket))
|
|
|
+ sendTicketWithRetry(bleBean.ticketSend!!, bleBean.bleDevice, isNeedLoading)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ToastUtils.tip(R.string.send_ticket_fail)
|
|
|
+ LogUtil.e("Send ticket fail")
|
|
|
+ ModBusController.getKeyByMac(bleBean.bleDevice.mac)?.let { itKey ->
|
|
|
+ mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_KEY && it.nfc == itKey.rfid }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1239,7 +1254,7 @@ object BusinessManager {
|
|
|
mEventBus.postValue(MsgEvent(MSG_EVENT_UPDATE_TICKET_PROGRESS, UpdateTicketProgressMsg(info.ticketId)))
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ } ?: sendLoadingEventMsg(null, false)
|
|
|
}
|
|
|
// 挂锁
|
|
|
1 -> {
|
|
|
@@ -1323,7 +1338,8 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
} ?: let {
|
|
|
- ModBusController.updateKeyReadyStatus(currentModeMsg.bleBean.bleDevice.mac, true)
|
|
|
+ ModBusController.updateKeyReadyStatus(currentModeMsg.bleBean.bleDevice.mac, true, 4)
|
|
|
+ ModBusController.controlKeyBuckle(false, currentModeMsg.bleBean.bleDevice.mac)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
}
|
|
|
}
|
|
|
@@ -1332,7 +1348,7 @@ object BusinessManager {
|
|
|
0x03.toByte() -> {
|
|
|
// TODO 上报?
|
|
|
ToastUtils.tip("${currentModeMsg.bleBean.bleDevice.mac} : " +
|
|
|
- "${MyApplication.instance?.applicationContext?.getString(R.string.key_is_in_failure_mode)}"
|
|
|
+ "${CommonUtils.getStr(R.string.key_is_in_failure_mode)}"
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
@@ -1385,12 +1401,12 @@ object BusinessManager {
|
|
|
// 关所有有设备的卡扣
|
|
|
dockList.filter { it.type == DOCK_TYPE_LOCK || it.type == DOCK_TYPE_PORTABLE }.forEach { dockBean ->
|
|
|
val hasLockIdxList = dockBean.getLockList().filter { it.isExist }.map { it.idx } as MutableList<Int>
|
|
|
- controlLockBuckle(false, dockBean.addr, hasLockIdxList)
|
|
|
+ ModBusController.controlLockBuckle(false, dockBean.addr, hasLockIdxList)
|
|
|
}
|
|
|
dockList.filter { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }.forEach { dockBean ->
|
|
|
dockBean.getKeyList().forEach { key ->
|
|
|
if (key.isExist) {
|
|
|
- controlKeyBuckle(false, key.isLeft, dockBean.addr)
|
|
|
+ ModBusController.controlKeyBuckle(false, key.isLeft, dockBean.addr)
|
|
|
}
|
|
|
}
|
|
|
}
|