Browse Source

补充便携式底座卡片和指纹更新

Frankensteinly 1 year ago
parent
commit
1d9731f75b

+ 11 - 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_CARD
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
 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
@@ -72,6 +74,15 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
                                             ModBusController.updateLockRfid(dockBean.addr.toInt(), deviceBean.idx, rfid)
                                         }
                                     }
+                                    DEVICE_TYPE_CARD -> {
+                                        ModBusController.readPortalCaseCardRfid(dockBean.addr.toInt() - 1) { res ->
+                                            val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
+                                            println("卡片RFID : $rfid")
+                                        }
+                                    }
+                                    DEVICE_TYPE_FINGERPRINT -> {
+
+                                    }
                                 }
                             }
                         }

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

@@ -1,5 +1,7 @@
 package com.grkj.iscs.modbus
 
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
 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
@@ -122,10 +124,23 @@ class DockBean(
                         deviceList.add(KeyBean(0, isKeyExist, true, isKeyCharging, null, null))
                     }
 
+                    val isCardExist = (byteArray[3].toInt() shr 4) and 0x1 == 1
+                    val isFingerPrintExist = (byteArray[3].toInt() shr 5) and 0x1 == 1
                     val isDockCharging = (byteArray[3].toInt() shr 6) and 0x1 == 1
                     val isDockFullCharged = (byteArray[3].toInt() shr 7) and 0x1 == 1
+                    println("便携式底座状态 : $isCardExist - $isFingerPrintExist - $isDockCharging - $isDockFullCharged")
+
+                    // TODO 便携柜 list
+                    if (getCardList().isEmpty()) {
+                        deviceList.add(CardBean(0, isCardExist))
+                    }
+
+                    if (getFingerPrintList().isEmpty()) {
+                        deviceList.add(FingerPrintBean(0, isFingerPrintExist))
+                    }
 
                     val changeList = mutableListOf<DeviceBean>()
+                    // 锁具变化
                     for (i in 0 until getLockList().size) {
                         if (getLockList()[i].isExist != tempList[i]) {
                             getLockList()[i].isExist = tempList[i]
@@ -136,6 +151,7 @@ class DockBean(
                             }
                         }
                     }
+                    // 蓝牙钥匙变化
                     if (getKeyList()[0].isExist != isKeyExist) {
                         getKeyList()[0].isExist = isKeyExist
                         changeList.add(getKeyList()[0])
@@ -145,6 +161,17 @@ class DockBean(
                             getKeyList()[0].mac = null
                         }
                     }
+                    // 卡片变化
+                    if (getCardList()[0].isExist != isCardExist) {
+                        getCardList()[0].isExist = isCardExist
+                        changeList.add(getCardList()[0])
+                    }
+                    // 指纹变化
+                    if (getFingerPrintList()[0].isExist != isFingerPrintExist) {
+                        getFingerPrintList()[0].isExist = isFingerPrintExist
+                        changeList.add(getFingerPrintList()[0])
+                    }
+                    LogUtil.i("便携式刷新状态 : $changeList")
                     return DockBean(addr, type, changeList)
                 }
                 else -> return null
@@ -160,6 +187,14 @@ class DockBean(
         return deviceList.filter { it.type == 1 } as MutableList<LockBean>
     }
 
+    fun getCardList(): MutableList<CardBean> {
+        return deviceList.filter { it.type == 2 } as MutableList<CardBean>
+    }
+
+    fun getFingerPrintList(): MutableList<FingerPrintBean> {
+        return deviceList.filter { it.type == 3 } as MutableList<FingerPrintBean>
+    }
+
     fun getBit(by: Byte): String {
         val sb = StringBuffer()
         sb.append((by.toInt() shr 7) and 0x1)
@@ -181,7 +216,7 @@ class DockBean(
      * @param idx 锁具底座时:锁具序号 0-9  钥匙底座时:0-左 1-右    便携式底座:锁具0-2 钥匙0
      * @param isExist true:有设备 false:无设备
      */
-    open class DeviceBean(
+    sealed class DeviceBean(
         var type: Int,
         var idx: Int,
         var isExist: Boolean
@@ -210,4 +245,20 @@ class DockBean(
         isExist: Boolean,
         var rfid: String?
     ) : DeviceBean(DEVICE_TYPE_LOCK, idx, isExist)
+
+    /**
+     * 卡
+     */
+    class CardBean(
+        idx: Int,
+        isExist: Boolean
+    ) : DeviceBean(DEVICE_TYPE_CARD, idx, isExist)
+
+    /**
+     * 指纹
+     */
+    class FingerPrintBean(
+        idx: Int,
+        isExist: Boolean
+    ) : DeviceBean(DEVICE_TYPE_FINGERPRINT, idx, isExist)
 }

+ 13 - 0
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -277,6 +277,19 @@ object ModBusController {
         }
     }
 
+    /**
+     * 读便携式底座卡RFID
+     */
+    fun readPortalCaseCardRfid(slaveIdx: Int?, done: ((res: ByteArray) -> Unit)? = null) {
+        slaveIdx?.let {
+            modBusManager?.generateRfidCmd(8)?.let { cmd ->
+                modBusManager?.sendTo(it, cmd) { res ->
+                    done?.invoke(res)
+                }
+            }
+        }
+    }
+
     /**
      * 更新钥匙RFID
      */

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

@@ -340,7 +340,7 @@ class ModBusManager(
     /**
      * 生成RFID 读指令
      *
-     * @param idx 锁具底座锁具:0-9  钥匙底座钥匙:0(left)-1(right)  便携式底座锁具:0-2  便携式底座钥匙:3
+     * @param idx 锁具底座锁具:0-9  钥匙底座钥匙:0(left)-1(right)  便携式底座锁具:0-2  便携式底座钥匙:4   便携式底座卡:8
      */
     fun generateRfidCmd(idx: Int): MBFrame {
         return MBFrame(

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

@@ -123,7 +123,7 @@ class PortManager private constructor(
         @WorkerThread
         fun openCtrlBord(ctx: Context) : PortManager? {
             // TODO 端口号待定:大屏调试设备-1,小屏调试设备-0
-            val port = 1
+            val port = 0
             val bps = 115200
             val usb = false
             LogUtil.i("主控板 port = ${port}, bps = ${bps}, usb = $usb")

+ 5 - 2
app/src/main/java/com/grkj/iscs/model/DeviceConst.kt

@@ -12,6 +12,9 @@ object DeviceConst {
     const val DOCK_TYPE_PORTABLE = 0x03.toByte()
 
     /***********************  底座设备类型  ***********************/
-    const val DEVICE_TYPE_KEY = 0
-    const val DEVICE_TYPE_LOCK = 1
+    const val DEVICE_TYPE_KEY = 0           // 蓝牙钥匙
+    const val DEVICE_TYPE_LOCK = 1          // 锁具
+    const val DEVICE_TYPE_CARD = 2          // 卡
+    const val DEVICE_TYPE_FINGERPRINT = 3   // 指纹
+    const val DEVICE_TYPE_PORTAL_CASE = 4   // 便携柜
 }