|
|
@@ -22,6 +22,8 @@ import com.grkj.iscs.util.Executor
|
|
|
import com.grkj.iscs.util.NetApi
|
|
|
import com.grkj.iscs.util.ToastUtils
|
|
|
import com.grkj.iscs.util.log.LogUtil
|
|
|
+import com.sik.sikcore.thread.ThreadUtils
|
|
|
+import kotlinx.coroutines.delay
|
|
|
import java.util.concurrent.atomic.AtomicInteger
|
|
|
import java.util.stream.Collectors
|
|
|
import kotlin.coroutines.resume
|
|
|
@@ -217,21 +219,25 @@ object ModBusController {
|
|
|
// 更新rfid
|
|
|
updateKeyRfid(dockBean.addr, isLeft, rfid)
|
|
|
// 蓝牙准备操作
|
|
|
- NetApi.getKeyInfo(rfid) {
|
|
|
- LogUtil.i("getKeyInfo : $rfid - ${it?.macAddress}")
|
|
|
- updateKeyNewHardware(dockBean.addr, isLeft, it == null)
|
|
|
- if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
+ NetApi.getKeyInfo(rfid) { keyInfo ->
|
|
|
+ LogUtil.i("getKeyInfo : $rfid - ${keyInfo?.macAddress}")
|
|
|
+ updateKeyNewHardware(dockBean.addr, isLeft, keyInfo == null)
|
|
|
+ if (keyInfo != null && !keyInfo.macAddress.isNullOrEmpty()) {
|
|
|
// 更新mac
|
|
|
- updateKeyMac(dockBean.addr, key.isLeft, it.macAddress)
|
|
|
- BusinessManager.registerConnectListener(
|
|
|
- it.macAddress
|
|
|
- ) { isDone, bleBean ->
|
|
|
- if (isDone && bleBean?.bleDevice != null) {
|
|
|
- Executor.delayOnMain(500) {
|
|
|
- BusinessManager.getCurrentStatus(
|
|
|
- 3, bleBean.bleDevice
|
|
|
- )
|
|
|
- BusinessManager.getBatteryPower(bleBean.bleDevice)
|
|
|
+ updateKeyMac(dockBean.addr, key.isLeft, keyInfo.macAddress)
|
|
|
+ controlKeyCharge(true, keyInfo.macAddress) {
|
|
|
+ ThreadUtils.runOnIODelayed(500) {
|
|
|
+ BusinessManager.registerConnectListener(
|
|
|
+ keyInfo.macAddress
|
|
|
+ ) { isDone, bleBean ->
|
|
|
+ if (isDone && bleBean?.bleDevice != null) {
|
|
|
+ Executor.delayOnMain(500) {
|
|
|
+ BusinessManager.getCurrentStatus(
|
|
|
+ 3, bleBean.bleDevice
|
|
|
+ )
|
|
|
+ BusinessManager.getBatteryPower(bleBean.bleDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -717,7 +723,9 @@ object ModBusController {
|
|
|
) {
|
|
|
slaveAddress?.let {
|
|
|
ModBusCMDHelper.generateKeyBuckleChargeCmd(isOpen, if (isLeft) 0 else 1)?.let { cmd ->
|
|
|
+ LogUtil.i("钥匙充电:${isOpen},${isLeft},${slaveAddress},${cmd.data.toHexStrings()}")
|
|
|
modBusManager?.sendTo(it, cmd) { res ->
|
|
|
+ LogUtil.i("钥匙充电接收:${isOpen},${isLeft},${slaveAddress},${res.toHexStrings()}")
|
|
|
done?.invoke(res)
|
|
|
}
|
|
|
}
|
|
|
@@ -994,8 +1002,13 @@ object ModBusController {
|
|
|
for (kb in keyList) {
|
|
|
val mac = kb.mac ?: continue
|
|
|
val found = suspendCoroutine<DockBean.KeyBean?> { cont ->
|
|
|
- BusinessManager.registerConnectListener(mac) { isDone, _ ->
|
|
|
- if (isDone) cont.resume(kb)
|
|
|
+ controlKeyCharge(true, mac) {
|
|
|
+ ///开启充电后等待500ms尝试连接
|
|
|
+ ThreadUtils.runOnIODelayed(500) {
|
|
|
+ BusinessManager.registerConnectListener(mac) { isDone, _ ->
|
|
|
+ if (isDone) cont.resume(kb)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (found != null) {
|