|
|
@@ -1,9 +1,8 @@
|
|
|
package com.grkj.iscs_mars
|
|
|
-//todo 所有蓝牙包替换com.clj. -> com.clj.
|
|
|
+
|
|
|
import android.bluetooth.BluetoothGattCharacteristic
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
-import android.util.Log
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import com.google.gson.Gson
|
|
|
@@ -19,7 +18,6 @@ import com.grkj.iscs_mars.ble.BleUtil
|
|
|
import com.grkj.iscs_mars.ble.CustomBleWriteCallback
|
|
|
import com.grkj.iscs_mars.can.CanCommands
|
|
|
import com.grkj.iscs_mars.can.CanDeviceConst
|
|
|
-import com.grkj.iscs_mars.can.CanHardwareHelper
|
|
|
import com.grkj.iscs_mars.can.CanHelper
|
|
|
import com.grkj.iscs_mars.can.DeviceModel
|
|
|
import com.grkj.iscs_mars.can.HandlerGate
|
|
|
@@ -30,15 +28,9 @@ import com.grkj.iscs_mars.extentions.toHexFromLe
|
|
|
import com.grkj.iscs_mars.extentions.toHexStrings
|
|
|
import com.grkj.iscs_mars.modbus.DockBean
|
|
|
import com.grkj.iscs_mars.modbus.ModBusController
|
|
|
-import com.grkj.iscs_mars.modbus.ModBusController.dockList
|
|
|
-import com.grkj.iscs_mars.modbus.ModBusController.getOneKey
|
|
|
import com.grkj.iscs_mars.model.Constants.USER_TYPE_LOCKER
|
|
|
-import com.grkj.iscs_mars.model.DeviceConst
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_LOCK
|
|
|
-import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
-import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_LOCK
|
|
|
-import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
import com.grkj.iscs_mars.model.DictAndSystemConstants
|
|
|
import com.grkj.iscs_mars.model.ISCSDomainData
|
|
|
import com.grkj.iscs_mars.model.bo.DeviceTakeUpdateBO
|
|
|
@@ -84,6 +76,7 @@ import com.huyuhui.fastble.exception.BleException
|
|
|
import com.sik.sikandroid.activity.ActivityTracker
|
|
|
import com.sik.sikcore.SIKCore
|
|
|
import com.sik.sikcore.date.TimeUtils
|
|
|
+import com.sik.sikcore.extension.isNullOrEmpty
|
|
|
import com.sik.sikcore.extension.toJson
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
@@ -131,12 +124,8 @@ object BusinessManager {
|
|
|
// 有问题的钥匙的列表 - rfid
|
|
|
var mExceptionKeyList = mutableListOf<String>()
|
|
|
|
|
|
- /**
|
|
|
- * 检查钥匙任务
|
|
|
- */
|
|
|
-// var checkKeyInfoTask: CheckKeyInfoTask = CheckKeyInfoTask()
|
|
|
-
|
|
|
- var canManager: CanHardwareHelper? = null
|
|
|
+ // Can是否初始化
|
|
|
+ var isCanInit = false
|
|
|
|
|
|
/**
|
|
|
* 初始化消息总线
|
|
|
@@ -173,31 +162,20 @@ object BusinessManager {
|
|
|
// 工作模式
|
|
|
1 -> {
|
|
|
if (it.data.res == 1) {
|
|
|
+ val opt = HardwareMode.getCurrentHardwareMode()
|
|
|
// 只能在这里断开,不能全部断开
|
|
|
BleCmdManager.shutdownOrRebootReq(mac = it.data.bleBean.bleDevice.mac)
|
|
|
BleSendDispatcher.scheduleDisconnect(it.data.bleBean.bleDevice.mac)
|
|
|
// 打开钥匙卡扣
|
|
|
- val keyBean =
|
|
|
- ModBusController.getKeyByMac(it.data.bleBean.bleDevice.mac)
|
|
|
+ val keyBean = opt.getKeyBeanByMac(it.data.bleBean.bleDevice.mac)
|
|
|
if (keyBean == null) {
|
|
|
- sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "未找到钥匙信息", false)
|
|
|
- )
|
|
|
- )
|
|
|
+ sendEventMsg(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
|
|
|
ToastUtils.tip(R.string.key_not_exists)
|
|
|
} else {
|
|
|
sendLoadingEventMsg(CommonUtils.getStr(R.string.take_out_key_tip))
|
|
|
- val dock =
|
|
|
- ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
|
|
|
keyBean.isReady = false
|
|
|
- ModBusController.controlKeyBuckle(
|
|
|
- true, keyBean.isLeft, dock?.addr
|
|
|
- )
|
|
|
- ModBusController.updateKeyReadyStatus(
|
|
|
- it.data.bleBean.bleDevice.mac, false, 1
|
|
|
- )
|
|
|
+ opt.controlKeyBuckle(true, it.data.bleBean.bleDevice.mac)
|
|
|
+ opt.updateKeyReadyStatus(it.data.bleBean.bleDevice.mac, false, 1)
|
|
|
ToastUtils.tip(R.string.take_out_key)
|
|
|
ThreadUtils.runOnIO {
|
|
|
checkMyTodoForHandleKey(it.data.bleBean.bleDevice.mac)
|
|
|
@@ -213,9 +191,7 @@ object BusinessManager {
|
|
|
// 待机模式
|
|
|
2 -> {
|
|
|
if (it.data.res == 1) {
|
|
|
- ModBusController.updateKeyReadyStatus(
|
|
|
- it.data.bleBean.bleDevice.mac, true, 2
|
|
|
- )
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyReadyStatus(it.data.bleBean.bleDevice.mac, true, 2)
|
|
|
BleReturnDispatcher.scheduleDisconnect(it.data.bleBean.bleDevice.mac)
|
|
|
// 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
|
//切换回待机之后不再次查询状态,没有意义,单机操作没有并发需求
|
|
|
@@ -288,24 +264,22 @@ object BusinessManager {
|
|
|
*/
|
|
|
fun connectDock(isNeedInit: Boolean = false) {
|
|
|
val dockData = SPUtils.getDockConfig(SIKCore.getApplication())
|
|
|
- LogUtil.i("基座数据:${dockData}")
|
|
|
+ LogUtil.i("connectDock $isNeedInit 基座数据:${dockData}")
|
|
|
if (dockData?.isEmpty() == true || dockData == "[]") return
|
|
|
- if (canManager == null) {
|
|
|
- canManager = CanHardwareHelper()
|
|
|
- // CAN总线连接和监听
|
|
|
- canManager?.interruptReadTrashBinStatus(true)
|
|
|
- canManager?.connectAndAddListener()
|
|
|
- CanHelper.addDeviceChangeListener(this) { canDeviceStatusHandle(it) }
|
|
|
+ if (!isCanInit) {
|
|
|
+ isCanInit = true
|
|
|
+ HardwareMode.getCurrentHardwareMode().interruptReadTrashBinStatus(true)
|
|
|
+ HardwareMode.getCurrentHardwareMode().connectAndAddListener()
|
|
|
+ registerMainListener()
|
|
|
}
|
|
|
- // 是否需要初始化Dock数据
|
|
|
- // if (isNeedInit) initDevicesStatus()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 断开底座链接
|
|
|
*/
|
|
|
fun disconnectDock() {
|
|
|
- canManager?.disconnect()
|
|
|
+ // 取消所有监听
|
|
|
+ listeners.clear()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -386,9 +360,6 @@ object BusinessManager {
|
|
|
// TODO 物资柜主控板
|
|
|
}
|
|
|
}
|
|
|
- Executor.delayOnMain(200) {
|
|
|
- listeners.forEach { it.callBack(res) }
|
|
|
- }
|
|
|
Executor.delayOnMain(200) {
|
|
|
if (ISCSDomainData.isDeviceRegistration) {
|
|
|
initListener?.invoke()
|
|
|
@@ -403,10 +374,9 @@ object BusinessManager {
|
|
|
*/
|
|
|
private fun canDeviceKeyHandler(keyBean: DeviceModel.DeviceKey) {
|
|
|
if (!keyBean.deviceChange) return
|
|
|
- Log.i("Manager", "钥匙状态变化canDeviceKeyHandler:$keyBean")
|
|
|
+ LogUtil.i("canDeviceKeyHandler $keyBean")
|
|
|
if (keyBean.isExist) {
|
|
|
- val req = CanCommands.forDevice(keyBean.nodeId)
|
|
|
- .let { if (keyBean.id == 0) it.getLeftRfid() else it.getRightRfid() }
|
|
|
+ val req = CanCommands.forDevice(keyBean.nodeId).let { if (keyBean.id == 0) it.getLeftRfid() else it.getRightRfid() }
|
|
|
CanHelper.readFrom(req) { res ->
|
|
|
val rfidData = res?.payload ?: byteArrayOf()
|
|
|
if (!ISCSDomainData.isDeviceRegistration) {
|
|
|
@@ -416,14 +386,14 @@ object BusinessManager {
|
|
|
) {}
|
|
|
}
|
|
|
if (rfidData.size < 4) {
|
|
|
- Log.e("Manager", "Key rfid error")
|
|
|
+ LogUtil.e("Key rfid error")
|
|
|
keyBean.deviceChange = false
|
|
|
return@readFrom
|
|
|
}
|
|
|
val rfid = rfidData.toHexFromLe()
|
|
|
- Log.i("Manager", "读取到的rfid:$rfid")
|
|
|
+ LogUtil.i("读取到的rfid:$rfid")
|
|
|
keyBean.rfid = rfid
|
|
|
- Log.i("Manager", "更新rfid完成:$keyBean")
|
|
|
+ LogUtil.i("更新rfid完成:$keyBean")
|
|
|
|
|
|
ThreadUtils.runOnIO {
|
|
|
val slotStatus = async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
|
|
|
@@ -443,27 +413,22 @@ object BusinessManager {
|
|
|
// 锁钥匙未异常正常请求锁数据,关锁
|
|
|
if (rfid in (keyData?.records?.filter { it.exStatus == keyStatus.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
?.map { it.keyNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
- ToastUtils.tip(
|
|
|
- MyApplication.instance?.applicationContext!!.getString(
|
|
|
- R.string.key_exception_tag
|
|
|
- )
|
|
|
- )
|
|
|
+ ToastUtils.tip(MyApplication.instance?.applicationContext!!.getString(R.string.key_exception_tag))
|
|
|
} else if (slotsPage?.records?.filter {
|
|
|
it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
}
|
|
|
?.find { it.row?.toInt() == keyBean.nodeId && it.col?.toInt() == (keyBean.nodeId + (keyBean.id) * 2 + 1) } != null) {
|
|
|
- ToastUtils.tip(
|
|
|
- MyApplication.instance?.applicationContext!!.getString(
|
|
|
- R.string.slot_exception_tag
|
|
|
- )
|
|
|
- )
|
|
|
+ ToastUtils.tip(MyApplication.instance?.applicationContext!!.getString(R.string.slot_exception_tag))
|
|
|
} else {
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyRfid(keyBean.nodeId, keyBean.id, rfid)
|
|
|
val ctrl = CanCommands.forDevice(keyBean.nodeId).controlLatch(keyBean.id, 1)
|
|
|
CanHelper.writeTo(ctrl) { _ ->
|
|
|
NetApi.getKeyInfo(rfid) {
|
|
|
- // TODO QUEST ModBusController.updateKeyNewHardware(dockBean.addr, true, it == null)
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyNewHardware(keyBean.nodeId, keyBean.id, it == null)
|
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
- keyBean.mac = it.macAddress
|
|
|
+ keyBean.mac = it.macAddress ?: ""
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyMac(keyBean.nodeId, keyBean.id, it.macAddress!!)
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyReadyStatus(it.macAddress, false, 5)
|
|
|
} else {
|
|
|
LogUtil.e("Get key info fail : $rfid")
|
|
|
if (!ISCSDomainData.isDeviceRegistration) {
|
|
|
@@ -472,14 +437,29 @@ object BusinessManager {
|
|
|
val unlock = CanCommands.forDevice(keyBean.nodeId).controlLatch(keyBean.id, 0)
|
|
|
CanHelper.writeTo(unlock) {}
|
|
|
}
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ try {
|
|
|
+ listeners.forEach { it.callBack(listOf(keyBean)) }
|
|
|
+ } finally {
|
|
|
+ keyBean.deviceChange = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if (!keyBean.isCharging) {
|
|
|
- unregisterConnectListener(keyBean.mac)
|
|
|
+ if (keyBean.mac.isNullOrEmpty()) unregisterConnectListener(keyBean.mac)
|
|
|
+ keyBean.deviceChange = false
|
|
|
sendEventMsg(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)))
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ try {
|
|
|
+ listeners.forEach { it.callBack(listOf(keyBean)) }
|
|
|
+ } catch (_: Exception) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -489,6 +469,7 @@ object BusinessManager {
|
|
|
*/
|
|
|
private fun canDeviceLockHandler(lockBean: DeviceModel.CommonDevice) {
|
|
|
if (!lockBean.deviceChange) return
|
|
|
+ LogUtil.i("canDeviceLockHandler $lockBean")
|
|
|
if (lockBean.isExist) {
|
|
|
val req = CanCommands.forDevice(lockBean.nodeId).getSlotRfid_1to5(lockBean.id)
|
|
|
CanHelper.readFrom(req) { res ->
|
|
|
@@ -513,9 +494,8 @@ object BusinessManager {
|
|
|
val slotStatusList = slotStatus.await()
|
|
|
val slotTypeList = slotType.await()
|
|
|
|
|
|
-
|
|
|
NetApi.getIsLockPage { lockData ->
|
|
|
- //锁rfid未异常正常请求锁数据,关锁
|
|
|
+ // 锁rfid未异常正常请求锁数据,关锁
|
|
|
if (rfid in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
?.map { it.lockNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
ToastUtils.tip(
|
|
|
@@ -538,8 +518,8 @@ object BusinessManager {
|
|
|
NetApi.getLockStateByNfc(rfid) {
|
|
|
if (it != 1) {
|
|
|
val ctrl = CanCommands.forDevice(lockBean.nodeId).controlOne_1to5(lockBean.id, true)
|
|
|
+ // 上报锁具信息
|
|
|
CanHelper.writeTo(ctrl) {
|
|
|
- // 上报锁具信息
|
|
|
NetApi.updateLockReturn(rfid, MyApplication.instance!!.serialNo()) {}
|
|
|
}
|
|
|
} else {
|
|
|
@@ -547,6 +527,13 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ try {
|
|
|
+ listeners.forEach { it.callBack(listOf(lockBean)) }
|
|
|
+ } finally {
|
|
|
+ lockBean.deviceChange = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -555,7 +542,14 @@ object BusinessManager {
|
|
|
} else {
|
|
|
LogUtil.i("挂锁取出-:${lockBean.rfid}")
|
|
|
sendEventMsg(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_LOCK, lockBean.rfid)))
|
|
|
- lockBean.deviceChange = false // 取出分支可在同步处理后立即归零
|
|
|
+ lockBean.deviceChange = false
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ try {
|
|
|
+ listeners.forEach { it.callBack(listOf(lockBean)) }
|
|
|
+ } catch (_: Exception) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -723,7 +717,7 @@ object BusinessManager {
|
|
|
LogUtil.i("锁柜id:${SPUtils.getHardwareId()}")
|
|
|
// —— 在 Default 线程做计算密集操作 ——
|
|
|
val lockMap = withContext(Dispatchers.Default) {
|
|
|
- ModBusController.getLocks(
|
|
|
+ CanHelper.getLocks(
|
|
|
needLockCount,
|
|
|
locksPage?.records?.filter { it.hardwareId != null && it.hardwareId == SPUtils.getHardwareId() }
|
|
|
?.mapNotNull { it.lockNfc } ?: mutableListOf(),
|
|
|
@@ -740,7 +734,7 @@ object BusinessManager {
|
|
|
if (isNeedKey) {
|
|
|
val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
|
|
|
keyPair = withContext(Dispatchers.Default) {
|
|
|
- getOneKey(
|
|
|
+ CanHelper.getOneKey(
|
|
|
slotsPage?.records?.filter {
|
|
|
it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
}?.toMutableList() ?: mutableListOf(),
|
|
|
@@ -768,11 +762,7 @@ object BusinessManager {
|
|
|
/**
|
|
|
* 注册连接监听
|
|
|
*/
|
|
|
- fun registerConnectListener(
|
|
|
- mac: String, connectNow: Boolean = false, isSend: Boolean = true, callBack: ((
|
|
|
- Boolean, BleBean?
|
|
|
- ) -> Unit)? = null
|
|
|
- ) {
|
|
|
+ fun registerConnectListener(mac: String, connectNow: Boolean = false, isSend: Boolean = true, callBack: ((Boolean, BleBean?) -> Unit)? = null) {
|
|
|
BleConnectionManager.registerConnectListener(mac, connectNow, isSend, callBack)
|
|
|
}
|
|
|
|
|
|
@@ -866,10 +856,7 @@ object BusinessManager {
|
|
|
getBleDeviceByMac(mac)?.bleDevice?.let {
|
|
|
LogUtil.i("开始读取作业票")
|
|
|
BleReturnDispatcher.busy(mac)
|
|
|
- getTicketStatusWithRetry(
|
|
|
- it,
|
|
|
- isNeedLoading
|
|
|
- )
|
|
|
+ getTicketStatusWithRetry(it, isNeedLoading)
|
|
|
}
|
|
|
} else {
|
|
|
//如果连接在待发列表则断开连接,重新使用归还队列连接之后检查
|
|
|
@@ -879,11 +866,7 @@ object BusinessManager {
|
|
|
getTicketStatusBusiness(mac, isNeedLoading)
|
|
|
}
|
|
|
}
|
|
|
- if (isNeedLoading) sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_LOADING, LoadingMsg(false, null, false)
|
|
|
- )
|
|
|
- )
|
|
|
+ if (isNeedLoading) sendEventMsg(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1016,7 +999,7 @@ object BusinessManager {
|
|
|
// TODO 挂锁数组
|
|
|
if (!lockList.isNullOrEmpty()) {
|
|
|
bo.lockList = mutableListOf()
|
|
|
- lockList.forEachIndexed { index, s ->
|
|
|
+ lockList?.forEachIndexed { index, s ->
|
|
|
if (s.isNullOrEmpty()) {
|
|
|
LogUtil.w("Lock nfc is null or empty")
|
|
|
return@forEachIndexed
|
|
|
@@ -1055,40 +1038,19 @@ object BusinessManager {
|
|
|
return jsonStr
|
|
|
}
|
|
|
|
|
|
- fun handleRsp(
|
|
|
- bleBean: BleBean,
|
|
|
- byteArray: ByteArray,
|
|
|
- isNeedLoading: Boolean = false,
|
|
|
- prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?
|
|
|
- ) {
|
|
|
- // TODO Token校验
|
|
|
-// val len = byteArray[2].toInt()
|
|
|
-// val token = byteArray.copyOfRange(len + 7, len + 11)
|
|
|
-// if (token.contentEquals(bleBean.token)) {
|
|
|
-// LogUtil.i("Token is right")
|
|
|
-// } else {
|
|
|
-// LogUtil.e("Token is wrong")
|
|
|
-// }
|
|
|
+ fun handleRsp(bleBean: BleBean, byteArray: ByteArray, isNeedLoading: Boolean = false, prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?) {
|
|
|
when {
|
|
|
// 获取令牌
|
|
|
- byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(
|
|
|
- bleBean.bleDevice, byteArray
|
|
|
- ) { isSuccess ->
|
|
|
+ byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(bleBean.bleDevice, byteArray) { isSuccess ->
|
|
|
if (isSuccess) {
|
|
|
- //尝试使用命令作为心跳 ,获取token完成之后就要建立心跳了
|
|
|
- BleCmdManager.getPower(
|
|
|
- bleBean.bleDevice.mac, null
|
|
|
- )
|
|
|
+ // 尝试使用命令作为心跳 ,获取token完成之后就要建立心跳了
|
|
|
+ BleCmdManager.getPower(bleBean.bleDevice.mac, null)
|
|
|
}
|
|
|
}
|
|
|
// 工作模式切换
|
|
|
byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> {
|
|
|
handleSwitchModeResult(byteArray, isNeedLoading) { res, job ->
|
|
|
- sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_SWITCH_MODE, SwitchModeMsg(job.toInt(), res.toInt(), bleBean)
|
|
|
- )
|
|
|
- )
|
|
|
+ sendEventMsg(MsgEvent(MSG_EVENT_SWITCH_MODE, SwitchModeMsg(job.toInt(), res.toInt(), bleBean)))
|
|
|
}
|
|
|
}
|
|
|
// 工作票下发
|
|
|
@@ -1096,23 +1058,24 @@ object BusinessManager {
|
|
|
bleBean, byteArray, isNeedLoading
|
|
|
)
|
|
|
// 获取设备当前状态
|
|
|
- byteArray.startsWith(BleConst.RSP_CURRENT_STATUS) -> BleCmdManager.handleCurrentStatus(
|
|
|
- byteArray
|
|
|
- ) {
|
|
|
+ byteArray.startsWith(BleConst.RSP_CURRENT_STATUS) -> BleCmdManager.handleCurrentStatus(byteArray) {
|
|
|
sendEventMsg(MsgEvent(MSG_EVENT_CURRENT_MODE, CurrentModeMsg(bleBean, it)))
|
|
|
}
|
|
|
// 获取设备工作票完成情况
|
|
|
byteArray.startsWith(BleConst.RSP_WORK_TICKET_RESULT) && byteArray[3] == 0x02.toByte() -> handleTicketStatus(
|
|
|
- bleBean.bleDevice, byteArray, isNeedLoading
|
|
|
+ bleBean.bleDevice,
|
|
|
+ byteArray,
|
|
|
+ isNeedLoading
|
|
|
)
|
|
|
-
|
|
|
+ // 查询电池电量
|
|
|
byteArray.startsWith(BleConst.RSP_POWER_STATUS) -> {
|
|
|
val power = byteArray[4].toInt()
|
|
|
- ModBusController.updateKeyPower(power, bleBean.bleDevice.mac)
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyPower(power, bleBean.bleDevice.mac)
|
|
|
LogUtil.i("电量(${bleBean.bleDevice.mac}):${power}")
|
|
|
prepareDoneCallBack?.invoke(true, bleBean)
|
|
|
- if (power < 50) {//如果电量小于50就打开仓位充电
|
|
|
- ModBusController.controlKeyCharge(true, bleBean.bleDevice.mac) {
|
|
|
+ if (power < 50) {
|
|
|
+ // 如果电量小于50就打开仓位充电
|
|
|
+ HardwareMode.getCurrentHardwareMode().controlKeyCharge(true, bleBean.bleDevice.mac) {
|
|
|
LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 开始充电")
|
|
|
}
|
|
|
}
|
|
|
@@ -1134,24 +1097,14 @@ object BusinessManager {
|
|
|
if (res == 0x01.toByte() && job == 0x01.toByte()) {
|
|
|
LogUtil.i("切换工作模式成功")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_LOADING, LoadingMsg(false, "切换工作模式成功", null)
|
|
|
- )
|
|
|
+ MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "切换工作模式成功", null))
|
|
|
)
|
|
|
} else if (res == 0x01.toByte() && job == 0x02.toByte()) {
|
|
|
LogUtil.i("切换待机模式成功")
|
|
|
- if (isNeedLoading) sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_LOADING, LoadingMsg(false, "切换待机模式成功", null)
|
|
|
- )
|
|
|
- )
|
|
|
+ if (isNeedLoading) sendEventMsg(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "切换待机模式成功", null)))
|
|
|
} else {
|
|
|
LogUtil.e("切换模式失败 : ${job.toInt()} - ${res.toInt()}")
|
|
|
- if (isNeedLoading) sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
- )
|
|
|
- )
|
|
|
+ if (isNeedLoading) sendEventMsg(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
}
|
|
|
callBack?.invoke(res, job)
|
|
|
}
|
|
|
@@ -1166,9 +1119,7 @@ object BusinessManager {
|
|
|
) {
|
|
|
BleCmdManager.handleWorkTicketResult(bleBean, byteArray) { isSuccess, rst ->
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
- )
|
|
|
+ MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null))
|
|
|
)
|
|
|
if (isSuccess) {
|
|
|
// 下发完毕,切换工作模式
|
|
|
@@ -1193,7 +1144,7 @@ object BusinessManager {
|
|
|
} else {
|
|
|
ToastUtils.tip(R.string.send_ticket_fail)
|
|
|
LogUtil.e("Send ticket fail")
|
|
|
- ModBusController.getKeyByMac(bleBean.bleDevice.mac)?.let { itKey ->
|
|
|
+ HardwareMode.getCurrentHardwareMode().getKeyBeanByMac(bleBean.bleDevice.mac)?.let { itKey ->
|
|
|
mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_KEY && it.nfc == itKey.rfid }
|
|
|
}
|
|
|
}
|
|
|
@@ -1213,7 +1164,7 @@ object BusinessManager {
|
|
|
LogUtil.i("getCurrentStatus - ${bleDevice.mac} - from : $from")
|
|
|
var isTimeout = true
|
|
|
// 加1秒防止早于onWriteFailure开始处理导致多次处理
|
|
|
- Executor.delayOnMain((BleUtil.OPERATE_TIMEOUT + 1).toLong()) {
|
|
|
+ Executor.delayOnMain((BleUtil.OPERATE_TIMEOUT + 1)) {
|
|
|
if (isTimeout) {
|
|
|
LogUtil.e("getCurrentStatus timeout : mac = ${bleDevice.mac}, retryCount = $retryCount")
|
|
|
if (retryCount > 0) {
|
|
|
@@ -1224,23 +1175,20 @@ object BusinessManager {
|
|
|
BleSendDispatcher.scheduleDisconnect(bleDevice.mac)
|
|
|
}
|
|
|
BleSendDispatcher.submit(bleDevice.mac) {
|
|
|
- getCurrentStatus(
|
|
|
- from, bleDevice, retryCount - 1, timeoutCallBack
|
|
|
- )
|
|
|
+ getCurrentStatus(from, bleDevice, retryCount - 1, timeoutCallBack)
|
|
|
}
|
|
|
} else {
|
|
|
BleReturnDispatcher.clearNoBusyConnectedDevice()
|
|
|
BleReturnDispatcher.scheduleDisconnect(bleDevice.mac)
|
|
|
BleReturnDispatcher.submit(bleDevice.mac) {
|
|
|
- getCurrentStatus(
|
|
|
- from, bleDevice, retryCount - 1, timeoutCallBack
|
|
|
- )
|
|
|
+ getCurrentStatus(from, bleDevice, retryCount - 1, timeoutCallBack)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
BleSendDispatcher.scheduleDisconnect(bleDevice.mac)
|
|
|
BleReturnDispatcher.scheduleDisconnect(bleDevice.mac)
|
|
|
- ModBusController.getKeyByMac(bleDevice.mac)?.rfid?.let {
|
|
|
+ val keyBean = HardwareMode.getCurrentHardwareMode().getKeyBeanByMac(bleDevice.mac)
|
|
|
+ keyBean?.rfid?.let {
|
|
|
addExceptionKey(it)
|
|
|
timeoutCallBack?.invoke(true)
|
|
|
}
|
|
|
@@ -1274,10 +1222,7 @@ object BusinessManager {
|
|
|
LogUtil.i("getCurrentStatus fail : ${bleDevice.mac}")
|
|
|
isTimeout = false
|
|
|
Executor.delayOnMain(1000) {
|
|
|
- getCurrentStatus(
|
|
|
- from, bleDevice,
|
|
|
- retryCount - 1, timeoutCallBack = timeoutCallBack
|
|
|
- )
|
|
|
+ getCurrentStatus(from, bleDevice, retryCount - 1, timeoutCallBack = timeoutCallBack)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -1393,18 +1338,13 @@ object BusinessManager {
|
|
|
if (finishedStatus.first) {
|
|
|
Executor.delayOnMain(500) {
|
|
|
handleKeyReturn(bleDevice, workTicketGetBO, finishedStatus.second)
|
|
|
- //检查钥匙是否代取,如果是的话给钥匙
|
|
|
- val keyBean = ModBusController.getKeyByMac(bleDevice.mac)
|
|
|
- mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == keyBean?.rfid }
|
|
|
- ?.let { itKey ->
|
|
|
- LogUtil.i("检查到存在待取钥匙:${itKey}")
|
|
|
- sendLoadingEventMsg(
|
|
|
- MyApplication.instance?.applicationContext!!.getString(
|
|
|
- R.string.ble_connecting
|
|
|
- )
|
|
|
- )
|
|
|
- handleGiveKey(itKey)
|
|
|
- }
|
|
|
+ // 检查钥匙是否代取,如果是的话给钥匙
|
|
|
+ val keyBean = HardwareMode.getCurrentHardwareMode().getKeyBeanByMac(bleDevice.mac)
|
|
|
+ mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == keyBean?.rfid }?.let { itKey ->
|
|
|
+ LogUtil.i("检查到存在待取钥匙:${itKey}")
|
|
|
+ sendLoadingEventMsg(MyApplication.instance?.applicationContext!!.getString(R.string.ble_connecting))
|
|
|
+ handleGiveKey(itKey)
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
// 当前策略:作业票未完成禁止归还钥匙
|
|
|
@@ -1412,14 +1352,10 @@ object BusinessManager {
|
|
|
showKeyReturnUploadDataForceDialog({
|
|
|
handleKeyReturn(bleDevice, workTicketGetBO, finishedStatus.second)
|
|
|
//检查钥匙是否代取,如果是的话给钥匙
|
|
|
- val keyBean = ModBusController.getKeyByMac(bleDevice.mac)
|
|
|
+ val keyBean = HardwareMode.getCurrentHardwareMode().getKeyBeanByMac(bleDevice.mac)
|
|
|
mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == keyBean?.rfid }
|
|
|
?.let { itKey ->
|
|
|
- sendLoadingEventMsg(
|
|
|
- MyApplication.instance?.applicationContext!!.getString(
|
|
|
- R.string.ble_connecting
|
|
|
- )
|
|
|
- )
|
|
|
+ sendLoadingEventMsg(MyApplication.instance?.applicationContext!!.getString(R.string.ble_connecting))
|
|
|
handleGiveKey(itKey)
|
|
|
}
|
|
|
}) {
|
|
|
@@ -1443,20 +1379,17 @@ object BusinessManager {
|
|
|
/**
|
|
|
* ticketFinished主要是后端的作业票是否已经结束,结束了,就直接修改状态就好了
|
|
|
*/
|
|
|
- private fun handleKeyReturn(
|
|
|
- bleDevice: BleDevice, workTicketGetBO: WorkTicketGetBO?, ticketFinished: Boolean
|
|
|
- ) {
|
|
|
- val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
- val keyBean = dock?.getKeyList()?.find { it.mac == bleDevice.mac }
|
|
|
- keyBean?.let {
|
|
|
- ModBusController.controlKeyBuckle(false, keyBean.isLeft, dock.addr)
|
|
|
- }
|
|
|
+ private fun handleKeyReturn(bleDevice: BleDevice, workTicketGetBO: WorkTicketGetBO?, ticketFinished: Boolean) {
|
|
|
+ val dockBean = HardwareMode.getCurrentHardwareMode().getKeyDockData().find { dock -> dock.keyData.find { it.mac == bleDevice.mac } != null }
|
|
|
+ val keyBean = dockBean?.keyData?.find { it.mac == bleDevice.mac }
|
|
|
+ val opt = HardwareMode.getCurrentHardwareMode()
|
|
|
+ opt.controlKeyBuckle(false, bleDevice.mac)
|
|
|
if (ticketFinished) {
|
|
|
mDeviceTakeList.removeIf { it.nfc == keyBean?.rfid }
|
|
|
switchReadyMode(bleDevice)
|
|
|
} else {
|
|
|
// 上报隔离点状态
|
|
|
- val keyNfc = ModBusController.getKeyByMac(bleDevice.mac)?.rfid ?: "key rfid lost"
|
|
|
+ val keyNfc = opt.getKeyBeanByMac(bleDevice.mac)?.rfid ?: "key rfid lost"
|
|
|
workTicketGetBO?.data?.forEach { data ->
|
|
|
val updateList = mutableListOf<LockPointUpdateReqVO>()
|
|
|
data.dataList?.filter { it.closed == 1 && it.status == it.target }
|
|
|
@@ -1514,13 +1447,11 @@ object BusinessManager {
|
|
|
)
|
|
|
}
|
|
|
} else {
|
|
|
- val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
- val keyBean =
|
|
|
- dock?.getKeyList()?.find { it.mac == bleDevice.mac }
|
|
|
+ val dockBean = HardwareMode.getCurrentHardwareMode().getKeyDockData()
|
|
|
+ .find { dock -> dock.keyData.find { it.mac == bleDevice.mac } != null }
|
|
|
+ val keyBean = dockBean?.keyData?.find { it.mac == bleDevice.mac }
|
|
|
keyBean?.let {
|
|
|
- ModBusController.controlKeyBuckle(
|
|
|
- true, keyBean.isLeft, dock.addr
|
|
|
- )
|
|
|
+ opt.controlKeyBuckle(true, keyBean.idx, keyBean.addr)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1546,21 +1477,10 @@ object BusinessManager {
|
|
|
* 钥匙归还
|
|
|
*/
|
|
|
private fun keyReturn(ticketId: Long, keyNfc: String) {
|
|
|
- NetApi.updateKeyReturn(
|
|
|
- ticketId,
|
|
|
- keyNfc,
|
|
|
- MyApplication.instance!!.serialNo()
|
|
|
- ) { isSuccess, msg, code ->
|
|
|
+ NetApi.updateKeyReturn(ticketId, keyNfc, MyApplication.instance!!.serialNo()) { isSuccess, msg, code ->
|
|
|
if (!isSuccess) {
|
|
|
- if (msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
- R.string.ticket_lost
|
|
|
- )
|
|
|
- ) {
|
|
|
- sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
|
|
|
- )
|
|
|
- )
|
|
|
+ if (msg == MyApplication.instance?.applicationContext!!.getString(R.string.ticket_lost)) {
|
|
|
+ sendEventMsg(MsgEvent(MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null))
|
|
|
}
|
|
|
SPUtils.clearUpdateKeyReturn(MyApplication.instance!!)
|
|
|
ToastUtils.tip(R.string.key_return_success)
|
|
|
@@ -1713,31 +1633,23 @@ object BusinessManager {
|
|
|
"$nodeId-$deviceType-$id"
|
|
|
|
|
|
private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg, rfid: String? = null) {
|
|
|
- LogUtil.i("$deviceTakeUpdateBO")
|
|
|
+ LogUtil.i("handleDeviceTake $deviceTakeUpdateBO")
|
|
|
when (deviceTakeUpdateBO.deviceType) {
|
|
|
// 钥匙
|
|
|
DEVICE_TYPE_KEY -> {
|
|
|
mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == deviceTakeUpdateBO.nfc }
|
|
|
?.let { info ->
|
|
|
- if (mDeviceTakeList.any { it.deviceType == DeviceConst.DEVICE_TYPE_LOCK && it.ticketId == info.ticketId }) {
|
|
|
+ if (mDeviceTakeList.any { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == info.ticketId }) {
|
|
|
LogUtil.i("存在未取出的挂锁,不继续操作")
|
|
|
return
|
|
|
}
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
- NetApi.updateKeyTake(
|
|
|
- info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!
|
|
|
- ) { isSuccess ->
|
|
|
+ NetApi.updateKeyTake(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!) { isSuccess ->
|
|
|
if (isSuccess) {
|
|
|
mDeviceTakeList.removeIf {
|
|
|
- it.deviceType == DEVICE_TYPE_KEY && it.nfc == info.nfc && it.ticketId ==
|
|
|
- info.ticketId
|
|
|
+ it.deviceType == DEVICE_TYPE_KEY && it.nfc == info.nfc && it.ticketId == info.ticketId
|
|
|
}
|
|
|
- sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_UPDATE_TICKET_PROGRESS,
|
|
|
- UpdateTicketProgressMsg(info.ticketId)
|
|
|
- )
|
|
|
- )
|
|
|
+ sendEventMsg(MsgEvent(MSG_EVENT_UPDATE_TICKET_PROGRESS, UpdateTicketProgressMsg(info.ticketId)))
|
|
|
// 钥匙取出之后重新再连一把钥匙待机
|
|
|
HardwareMode.getCurrentHardwareMode().getKeyMacByRfid(info.nfc)?.let {
|
|
|
HardwareMode.getCurrentHardwareMode().getKeyBeanByMac(it)?.let { keyBean ->
|
|
|
@@ -1747,9 +1659,6 @@ object BusinessManager {
|
|
|
}
|
|
|
// 待机数不够就再连一把,但不能是原来那把
|
|
|
HardwareMode.getCurrentHardwareMode().getKeyMacByRfid(info.nfc)?.let {
|
|
|
- HardwareMode.getCurrentHardwareMode().getKeyBeanByMac(it)?.let { keyBean ->
|
|
|
- HandlerGate.leave(devKey(keyBean.addr, keyBean.type, keyBean.idx))
|
|
|
- }
|
|
|
ThreadUtils.runOnIO { checkMyTodoForHandleKey(it) }
|
|
|
}
|
|
|
}
|
|
|
@@ -1760,7 +1669,15 @@ object BusinessManager {
|
|
|
DEVICE_TYPE_LOCK -> {
|
|
|
mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_LOCK && it.nfc == deviceTakeUpdateBO.nfc }
|
|
|
?.let { info ->
|
|
|
- NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
|
|
|
+ NetApi.updateLockTake(
|
|
|
+ mutableListOf(
|
|
|
+ LockTakeUpdateReqVO(
|
|
|
+ info.ticketId,
|
|
|
+ info.nfc,
|
|
|
+ MyApplication.instance?.serialNo()!!
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ) { isSuccess ->
|
|
|
Executor.runOnMain {
|
|
|
if (isSuccess == false) {
|
|
|
LogUtil.e("Lock take report fail")
|
|
|
@@ -1792,13 +1709,10 @@ object BusinessManager {
|
|
|
return@runOnMain
|
|
|
}
|
|
|
// 检查有无当前工作票的钥匙
|
|
|
- mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == info.ticketId }
|
|
|
- ?.let { itKey ->
|
|
|
- sendLoadingEventMsg(MyApplication.instance?.applicationContext!!.getString(
|
|
|
- R.string.ble_connecting
|
|
|
- ))
|
|
|
- handleGiveKey(itKey)
|
|
|
- }
|
|
|
+ mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == info.ticketId }?.let { itKey ->
|
|
|
+ sendLoadingEventMsg(MyApplication.instance?.applicationContext!!.getString(R.string.ble_connecting))
|
|
|
+ handleGiveKey(itKey)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1810,61 +1724,40 @@ object BusinessManager {
|
|
|
* 分配钥匙
|
|
|
*/
|
|
|
private fun handleGiveKey(deviceTakeUpdateBO: DeviceTakeUpdateBO) {
|
|
|
- getBleDeviceByMac(ModBusController.getKeyByRfid(deviceTakeUpdateBO.nfc)?.mac)?.let {
|
|
|
- getCurrentStatus(
|
|
|
- 2,
|
|
|
- getBleDeviceByMac(ModBusController.getKeyByRfid(deviceTakeUpdateBO.nfc)?.mac)!!.bleDevice
|
|
|
- ) {
|
|
|
- if (!it) {
|
|
|
- return@getCurrentStatus
|
|
|
- }
|
|
|
+ LogUtil.i("handleGiveKey $deviceTakeUpdateBO")
|
|
|
+ val optDevice = HardwareMode.getCurrentHardwareMode()
|
|
|
+ val keyMac = optDevice.getKeyMacByRfid(deviceTakeUpdateBO.nfc)
|
|
|
+ getBleDeviceByMac(keyMac)?.let {
|
|
|
+ getCurrentStatus(2, getBleDeviceByMac(keyMac)!!.bleDevice) {
|
|
|
+ if (!it) return@getCurrentStatus
|
|
|
LogUtil.w("handleGiveKey timeout")
|
|
|
removeDeviceTake(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)
|
|
|
- checkEquipCount(0, true) { keyPair, lockMap ->
|
|
|
+ checkEquipCount(0, true) { keyPair, _ ->
|
|
|
if (keyPair == null) {
|
|
|
ThreadUtils.runOnMain {
|
|
|
val tipDialog = TipDialog(SIKCore.getApplication())
|
|
|
- tipDialog.setTip(
|
|
|
- SIKCore.getApplication().getString(R.string.key_take_error_tip)
|
|
|
- )
|
|
|
+ tipDialog.setTip(SIKCore.getApplication().getString(R.string.key_take_error_tip))
|
|
|
tipDialog.setConfirmListener {
|
|
|
tipDialog.dismiss()
|
|
|
- sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_DEVICE_EXCEPTION,
|
|
|
- DeviceExceptionMsg(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)
|
|
|
- )
|
|
|
- )
|
|
|
+ sendEventMsg(MsgEvent(MSG_EVENT_DEVICE_EXCEPTION, DeviceExceptionMsg(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)))
|
|
|
}
|
|
|
tipDialog.show()
|
|
|
}
|
|
|
} else {
|
|
|
- addDeviceTake(
|
|
|
- DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!
|
|
|
- )
|
|
|
- handleGiveKey(
|
|
|
- DeviceTakeUpdateBO(
|
|
|
- DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!
|
|
|
- )
|
|
|
- )
|
|
|
+ addDeviceTake(DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!)
|
|
|
+ handleGiveKey(DeviceTakeUpdateBO(DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} ?: run {
|
|
|
ThreadUtils.runOnMain {
|
|
|
ActivityTracker.getCurrentActivity()?.let {
|
|
|
+ // 钥匙分配失败
|
|
|
val tipDialog = TipDialog(it)
|
|
|
- tipDialog.setTip(
|
|
|
- SIKCore.getApplication().getString(R.string.key_take_error_tip)
|
|
|
- )
|
|
|
+ tipDialog.setTip(SIKCore.getApplication().getString(R.string.key_take_error_tip))
|
|
|
tipDialog.setConfirmListener {
|
|
|
tipDialog.dismiss()
|
|
|
- sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_DEVICE_EXCEPTION,
|
|
|
- DeviceExceptionMsg(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)
|
|
|
- )
|
|
|
- )
|
|
|
+ sendEventMsg(MsgEvent(MSG_EVENT_DEVICE_EXCEPTION, DeviceExceptionMsg(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)))
|
|
|
}
|
|
|
tipDialog.show()
|
|
|
}
|
|
|
@@ -1876,6 +1769,7 @@ object BusinessManager {
|
|
|
* 根据当前模式进行处理
|
|
|
*/
|
|
|
private fun handleCurrentMode(currentModeMsg: CurrentModeMsg) {
|
|
|
+ LogUtil.i("handleCurrentMode ${currentModeMsg.mode}")
|
|
|
when (currentModeMsg.mode) {
|
|
|
// 工作模式
|
|
|
0x01.toByte() -> {
|
|
|
@@ -1885,12 +1779,12 @@ object BusinessManager {
|
|
|
// 待机模式
|
|
|
0x02.toByte() -> {
|
|
|
// 根据情况看是否需要下发工作票
|
|
|
- ModBusController.getKeyByMac(currentModeMsg.bleBean.bleDevice.mac)?.let { key ->
|
|
|
+ val opt = HardwareMode.getCurrentHardwareMode()
|
|
|
+ opt.getKeyBeanByMac(currentModeMsg.bleBean.bleDevice.mac)?.let { key ->
|
|
|
// 判断是否有待取的钥匙
|
|
|
- val updateBo =
|
|
|
- mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && key.rfid == it.nfc }
|
|
|
+ val updateBo = mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && key.rfid == it.nfc }
|
|
|
if (mDeviceTakeList.any { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == updateBo?.ticketId }) {
|
|
|
- //todo 如果有钥匙待取但是对应的作业票的锁还有的,就不发
|
|
|
+ LogUtil.i("没有代取的钥匙,不做继续处理")
|
|
|
return
|
|
|
}
|
|
|
updateBo?.let { itBO ->
|
|
|
@@ -1908,26 +1802,21 @@ object BusinessManager {
|
|
|
checkAndSendTicket(currentModeMsg, itBO)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} ?: let {
|
|
|
- ModBusController.updateKeyReadyStatus(
|
|
|
- currentModeMsg.bleBean.bleDevice.mac, true, 4
|
|
|
- )
|
|
|
+ opt.updateKeyReadyStatus(currentModeMsg.bleBean.bleDevice.mac, true, 4)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
BleCmdManager.shutdownOrRebootReq(mac = currentModeMsg.bleBean.bleDevice.mac)
|
|
|
BleReturnDispatcher.scheduleDisconnect(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
- //连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
+ // 连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
ThreadUtils.runOnIO {
|
|
|
checkMyTodoForHandleKey(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
}
|
|
|
}
|
|
|
} ?: let {
|
|
|
- ModBusController.updateKeyReadyStatus(
|
|
|
- currentModeMsg.bleBean.bleDevice.mac, true, 4
|
|
|
- )
|
|
|
+ opt.updateKeyReadyStatus(currentModeMsg.bleBean.bleDevice.mac, true, 4)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
BleReturnDispatcher.scheduleDisconnect(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
- //连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
+ // 连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
ThreadUtils.runOnIO {
|
|
|
checkMyTodoForHandleKey(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
}
|
|
|
@@ -1935,10 +1824,7 @@ object BusinessManager {
|
|
|
}
|
|
|
// 故障模式
|
|
|
0x03.toByte() -> {
|
|
|
- // TODO 上报?
|
|
|
- ToastUtils.tip(
|
|
|
- "${currentModeMsg.bleBean.bleDevice.mac} : " + "${CommonUtils.getStr(R.string.key_is_in_failure_mode)}"
|
|
|
- )
|
|
|
+ ToastUtils.tip("${currentModeMsg.bleBean.bleDevice.mac} : " + "${CommonUtils.getStr(R.string.key_is_in_failure_mode)}")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2087,38 +1973,7 @@ object BusinessManager {
|
|
|
reConnectKey()
|
|
|
NetApi.logout()
|
|
|
// 关所有有设备的卡扣
|
|
|
- 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>
|
|
|
- val noLockIdxList =
|
|
|
- dockBean.getLockList().filter { !it.isExist }.map { it.idx } as MutableList<Int>
|
|
|
- ModBusController.controlLockBuckle(false, dockBean.addr, hasLockIdxList)
|
|
|
- ModBusController.controlLockBuckle(true, dockBean.addr, noLockIdxList)
|
|
|
- }
|
|
|
- dockList.filter { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }
|
|
|
- .forEach { dockBean ->
|
|
|
- dockBean.getKeyList().forEach { key ->
|
|
|
- if (key.isExist) {
|
|
|
- NetApi.getKeyInfo(key.rfid.toString()) {
|
|
|
- if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
- ModBusController.updateKeyMac(
|
|
|
- dockBean.addr, key.isLeft, it.macAddress
|
|
|
- )
|
|
|
- ModBusController.controlKeyBuckle(
|
|
|
- false, key.isLeft, dockBean.addr
|
|
|
- )
|
|
|
- } else {
|
|
|
- ModBusController.controlKeyBuckle(
|
|
|
- true, key.isLeft, dockBean.addr
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- ModBusController.controlKeyBuckle(true, key.isLeft, dockBean.addr)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ HardwareMode.getCurrentHardwareMode().allSlotOff()
|
|
|
BleSendDispatcher.disconnectAll(60_0000L)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
context.startActivity(Intent(context, LoginActivity::class.java).apply {
|
|
|
@@ -2136,8 +1991,8 @@ object BusinessManager {
|
|
|
mDeviceTakeList.clear()
|
|
|
// 连接后直接切换待机模式,让钥匙作业票失效并且重新准备完毕
|
|
|
keyList.forEach {
|
|
|
- val mac = ModBusController.getKeyByRfid(it.nfc)?.mac
|
|
|
- if (mac == null) {
|
|
|
+ val mac = HardwareMode.getCurrentHardwareMode().getKeyMacByRfid(it.nfc)
|
|
|
+ if (mac.isNullOrEmpty()) {
|
|
|
NetApi.getKeyInfo(it.nfc) { keyInfo ->
|
|
|
keyInfo?.macAddress?.let { itMac ->
|
|
|
registerConnectListener(itMac, isSend = true) { isDone, bleBean ->
|
|
|
@@ -2148,7 +2003,7 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- registerConnectListener(mac, isSend = true) { isDone, bleBean ->
|
|
|
+ registerConnectListener(mac!!, isSend = true) { isDone, bleBean ->
|
|
|
if (isDone && bleBean != null) {
|
|
|
switchReadyMode(bleBean.bleDevice)
|
|
|
}
|