Преглед изворни кода

异常断开重连补充获取当前状态,触发工作模式和作业票检查;分配钥匙时随机分配

Frankensteinly пре 1 година
родитељ
комит
052433625d

+ 9 - 1
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -726,7 +726,13 @@ object BusinessManager {
                         }
                         // 断开和重连之间最好间隔一段时间,否则可能会出现长时间连接不上的情况
                         Executor.delayOnMain(300) {
-                            registerConnectListener(bleDevice.mac)
+                            registerConnectListener(bleDevice.mac) { isDone, bleBean ->
+                                if (isDone && bleBean != null) {
+                                    Executor.delayOnMain(300) {
+                                        getCurrentStatus(6, bleBean.bleDevice)
+                                    }
+                                }
+                            }
                         }
                     } else {
                         ModBusController.updateKeyReadyStatus(bleDevice.mac, false, 3)
@@ -1102,8 +1108,10 @@ object BusinessManager {
     fun getCurrentStatus(from: Int, bleDevice: BleDevice, retryCount: Int = 3) {
         LogUtil.i("getCurrentStatus - ${bleDevice.mac} - from : $from")
         var isTimeout = true
+        // 加1秒防止早于onWriteFailure开始处理导致多次处理
         Executor.delayOnMain((BleUtil.OPERATE_TIMEOUT + 1).toLong()) {
             if (isTimeout) {
+                LogUtil.e("getCurrentStatus timeout : mac = ${bleDevice.mac}, retryCount = $retryCount")
                 if (retryCount > 0) {
                     Executor.delayOnMain(1000) {
                         getCurrentStatus(from, bleDevice, retryCount - 1)

+ 3 - 2
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -542,7 +542,7 @@ object ModBusController {
     }
 
     /**
-     * 获取一个钥匙(存在的、有RFID、有Mac、连接的、是待机模式的)
+     * 随机获取一个钥匙(存在的、有RFID、有Mac、连接的、是待机模式的)
      *
      * @return 底座地址,钥匙
      */
@@ -560,8 +560,9 @@ object ModBusController {
                     "${BusinessManager.getBleDeviceByMac(it.mac)?.bleDevice != null} - " +
                     "${BleManager.getInstance().isConnected(BusinessManager.getBleDeviceByMac(it.mac)?.bleDevice)}")
         }
-        val key = keyList.find { it.isExist && it.rfid != null && it.mac != null && it.isReady &&
+        val key = keyList.filter { it.isExist && it.rfid != null && it.mac != null && it.isReady &&
                 BleManager.getInstance().isConnected(BusinessManager.getBleDeviceByMac(it.mac)?.bleDevice) }
+            .shuffled().firstOrNull()
         if (key == null) {
             LogUtil.e("getOneKey : no key match")
             return null