소스 검색

补充部分便携式底座状态更新

Frankensteinly 1 년 전
부모
커밋
3152194c22
2개의 변경된 파일58개의 추가작업 그리고 1개의 파일을 삭제
  1. 17 0
      app/src/main/java/com/grkj/iscs/activity/ModbusActivity.kt
  2. 41 1
      app/src/main/java/com/grkj/iscs/modbus/DockBean.kt

+ 17 - 0
app/src/main/java/com/grkj/iscs/activity/ModbusActivity.kt

@@ -6,6 +6,8 @@ import com.grkj.iscs.extentions.removeLeadingZeros
 import com.grkj.iscs.extentions.toHexStrings
 import com.grkj.iscs.iview.IModbusView
 import com.grkj.iscs.modbus.ModBusController
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_LOCK
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_ELEC_LOCK_BOARD
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
@@ -58,6 +60,21 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
                     }
                     DOCK_TYPE_PORTABLE -> {
                         // TODO 便携式待完善
+                        dockBean.deviceList.forEach { deviceBean ->
+                            if (deviceBean.isExist) {
+                                when (deviceBean.type) {
+                                    DEVICE_TYPE_KEY -> {
+
+                                    }
+                                    DEVICE_TYPE_LOCK -> {
+                                        ModBusController.readLockRfid(dockBean.addr.toInt() - 1, deviceBean.idx) { res ->
+                                            val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
+                                            ModBusController.updateLockRfid(dockBean.addr.toInt(), deviceBean.idx, rfid)
+                                        }
+                                    }
+                                }
+                            }
+                        }
                     }
                 }
             }

+ 41 - 1
app/src/main/java/com/grkj/iscs/modbus/DockBean.kt

@@ -105,7 +105,47 @@ class DockBean(
                 }
                 DOCK_TYPE_PORTABLE -> {
                     // TODO 便携式底座更新
-                    return null
+                    val tempList = mutableListOf<Boolean>()
+                    for (i in 0..2) {
+                        tempList.add((byteArray[4].toInt() shr i) and 0x1 == 1)
+                    }
+                    if (getLockList().isEmpty()) {
+                        for (i in 0 until tempList.size) {
+                            deviceList.add(LockBean(i, tempList[i], null))
+                        }
+                    }
+
+                    val isKeyExist = (byteArray[3].toInt() shr 0) and 0x1 == 1
+                    val isKeyCharging = (byteArray[3].toInt() shr 1) and 0x1 == 1
+
+                    if (getKeyList().isEmpty()) {
+                        deviceList.add(KeyBean(0, isKeyExist, true, isKeyCharging, null, null))
+                    }
+
+                    val isDockCharging = (byteArray[3].toInt() shr 6) and 0x1 == 1
+                    val isDockFullCharged = (byteArray[3].toInt() shr 7) and 0x1 == 1
+
+                    val changeList = mutableListOf<DeviceBean>()
+                    for (i in 0 until getLockList().size) {
+                        if (getLockList()[i].isExist != tempList[i]) {
+                            getLockList()[i].isExist = tempList[i]
+                            changeList.add(getLockList()[i])
+                            // 拿走锁具,移除锁具信息
+                            if (!tempList[i]) {
+                                getLockList()[i].rfid = null
+                            }
+                        }
+                    }
+                    if (getKeyList()[0].isExist != isKeyExist) {
+                        getKeyList()[0].isExist = isKeyExist
+                        changeList.add(getKeyList()[0])
+                        // 拿走钥匙,移除钥匙信息
+                        if (!isKeyExist) {
+                            getKeyList()[0].rfid = null
+                            getKeyList()[0].mac = null
+                        }
+                    }
+                    return DockBean(addr, type, changeList)
                 }
                 else -> return null
             }