|
|
@@ -74,7 +74,7 @@ class CanReadyPlugin : CommPlugin {
|
|
|
}
|
|
|
|
|
|
/** 单协程,逐节点轮询 */
|
|
|
- fun startPollingSingleLoop() {
|
|
|
+ fun startPollingSingleLoop(needCharge: Boolean = true) {
|
|
|
pollJob?.cancel()
|
|
|
pollJob = scope.launch {
|
|
|
NodeIdHelper.scanRangeLinear({ nodeId ->
|
|
|
@@ -112,7 +112,7 @@ class CanReadyPlugin : CommPlugin {
|
|
|
}
|
|
|
HardwareMode.getCurrentHardwareMode().controlAllKeyBuckleClose()
|
|
|
initLock() // 打开所有无锁的卡扣、关闭所有有锁的卡扣、读取所有锁的RFID
|
|
|
- initKey() // 打开所有无钥匙的卡扣、关闭所有有钥匙的卡扣、读取所有钥匙的RFID
|
|
|
+ initKey(needCharge) // 打开所有无钥匙的卡扣、关闭所有有钥匙的卡扣、读取所有钥匙的RFID
|
|
|
while (isActive) {
|
|
|
for (nodeId in activeNodes) {
|
|
|
try {
|
|
|
@@ -191,7 +191,7 @@ class CanReadyPlugin : CommPlugin {
|
|
|
/**
|
|
|
* 初始化钥匙
|
|
|
*/
|
|
|
- private fun initKey() {
|
|
|
+ private fun initKey(needCharge: Boolean = true) {
|
|
|
LogUtil.i("initKey : ${HardwareMode.getCurrentHardwareMode().getKeyDockData()}")
|
|
|
HardwareMode.getCurrentHardwareMode().getKeyDockData().forEach { dockBean ->
|
|
|
if (dockBean.addr != 3) {
|
|
|
@@ -203,48 +203,48 @@ class CanReadyPlugin : CommPlugin {
|
|
|
if (key.isExist) {
|
|
|
LogUtil.i("initKey : ${dockBean.addr} : ${key.idx == 0}")
|
|
|
HardwareMode.getCurrentHardwareMode().readKeyRfidStr(dockBean.addr, key.idx) { _, rfid ->
|
|
|
- LogUtil.i("初始化钥匙 RFID : $rfid")
|
|
|
- // 更新rfid
|
|
|
- HardwareMode.getCurrentHardwareMode().updateKeyRfid(dockBean.addr, key.idx, rfid)
|
|
|
- // 蓝牙准备操作
|
|
|
- NetApi.getKeyInfo(rfid) { keyInfo ->
|
|
|
- LogUtil.i("getKeyInfo : $rfid - ${keyInfo?.macAddress}")
|
|
|
- HardwareMode.getCurrentHardwareMode().updateKeyNewHardware(
|
|
|
- dockBean.addr,
|
|
|
- key.idx,
|
|
|
- keyInfo == null || keyInfo.keyNfc?.isEmpty() == true || keyInfo.macAddress?.isEmpty() == true
|
|
|
- )
|
|
|
- LogUtil.i("钥匙是否为新设备:${keyInfo == null || keyInfo.keyNfc?.isEmpty() == true || keyInfo.macAddress?.isEmpty() == true}")
|
|
|
- if (keyInfo != null && !keyInfo.macAddress.isNullOrEmpty()) {
|
|
|
- // 更新底座蓝牙Mac信息
|
|
|
- HardwareMode.getCurrentHardwareMode().updateKeyMac(dockBean.addr, key.idx, keyInfo.macAddress)
|
|
|
- HardwareMode.getCurrentHardwareMode().controlKeyBuckle(false, key.idx, dockBean.addr)
|
|
|
- ThreadUtils.runOnIO {
|
|
|
- delay(1000)
|
|
|
- // 已经初始化完成才会去连接
|
|
|
- HardwareMode.getCurrentHardwareMode().controlKeyCharge(true, key.idx, dockBean.addr)
|
|
|
- }
|
|
|
- } else {
|
|
|
- ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
- HardwareMode.getCurrentHardwareMode().controlKeyLockAndCharge(true, key.idx, dockBean.addr)
|
|
|
- }
|
|
|
- val isKeyReady = HardwareMode.getCurrentHardwareMode().getKeyDockData().all {
|
|
|
- it.keyData.filter { it.type == DeviceConst.DEVICE_TYPE_KEY }
|
|
|
- .filterIsInstance<DockBean.KeyBean>()
|
|
|
- .filter { it.isExist }
|
|
|
- .all {
|
|
|
- LogUtil.i("钥匙信息:${it.rfid}")
|
|
|
- it.rfid?.isNotEmpty() == true
|
|
|
- }
|
|
|
- }
|
|
|
- LogUtil.i("钥匙是否准备完毕:${isKeyReady}")
|
|
|
- if (isKeyReady) {
|
|
|
- ISCSDomainData.canInitDevice = true
|
|
|
- LogUtil.i("发送初始化完成事件")
|
|
|
- BusinessManager.sendEventMsg(MsgEvent(MsgEventConstants.MSG_EVENT_INIT_KEY_COMPLETE, null))
|
|
|
+ LogUtil.i("初始化钥匙 RFID : $rfid")
|
|
|
+ // 更新rfid
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyRfid(dockBean.addr, key.idx, rfid)
|
|
|
+ // 蓝牙准备操作
|
|
|
+ NetApi.getKeyInfo(rfid) { keyInfo ->
|
|
|
+ LogUtil.i("getKeyInfo : $rfid - ${keyInfo?.macAddress}")
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyNewHardware(
|
|
|
+ dockBean.addr,
|
|
|
+ key.idx,
|
|
|
+ keyInfo == null || keyInfo.keyNfc?.isEmpty() == true || keyInfo.macAddress?.isEmpty() == true
|
|
|
+ )
|
|
|
+ LogUtil.i("钥匙是否为新设备:${keyInfo == null || keyInfo.keyNfc?.isEmpty() == true || keyInfo.macAddress?.isEmpty() == true}")
|
|
|
+ if (keyInfo != null && !keyInfo.macAddress.isNullOrEmpty()) {
|
|
|
+ // 更新底座蓝牙Mac信息
|
|
|
+ HardwareMode.getCurrentHardwareMode().updateKeyMac(dockBean.addr, key.idx, keyInfo.macAddress)
|
|
|
+ HardwareMode.getCurrentHardwareMode().controlKeyBuckle(false, key.idx, dockBean.addr)
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ delay(1000)
|
|
|
+ // 已经初始化完成才会去连接
|
|
|
+ if (needCharge) HardwareMode.getCurrentHardwareMode().controlKeyCharge(true, key.idx, dockBean.addr)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
+ HardwareMode.getCurrentHardwareMode().controlKeyLockAndCharge(true, key.idx, dockBean.addr)
|
|
|
+ }
|
|
|
+ val isKeyReady = HardwareMode.getCurrentHardwareMode().getKeyDockData().all {
|
|
|
+ it.keyData.filter { it.type == DeviceConst.DEVICE_TYPE_KEY }
|
|
|
+ .filterIsInstance<DockBean.KeyBean>()
|
|
|
+ .filter { it.isExist }
|
|
|
+ .all {
|
|
|
+ LogUtil.i("钥匙信息:${it.rfid}")
|
|
|
+ it.rfid?.isNotEmpty() == true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LogUtil.i("钥匙是否准备完毕:${isKeyReady}")
|
|
|
+ if (isKeyReady) {
|
|
|
+ ISCSDomainData.canInitDevice = true
|
|
|
+ LogUtil.i("发送初始化完成事件")
|
|
|
+ BusinessManager.sendEventMsg(MsgEvent(MsgEventConstants.MSG_EVENT_INIT_KEY_COMPLETE, null))
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
} else {
|
|
|
HardwareMode.getCurrentHardwareMode()
|
|
|
.controlKeyBuckle(true, key.idx, dockBean.addr)
|