Frankensteinly 1 жил өмнө
parent
commit
4d823fb73c

+ 8 - 2
app/src/main/java/com/grkj/iscs/activity/ModbusActivity.kt

@@ -72,7 +72,7 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
                 return@setOnClickListener
             }
             ModBusController.openLockBuckle(mBinding?.slaveIdx?.text.toString().toInt(), mBinding?.lockIdx?.text.toString().toInt()) { res ->
-                LogUtil.i("开锁卡扣成功 : ${res.toHexStrings()}")
+                LogUtil.i("开锁卡扣 : ${res.toHexStrings()}")
             }
         }
 
@@ -86,7 +86,13 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
             return@setOnClickListener
         }
             ModBusController.closeLockBuckle(mBinding?.slaveIdx?.text.toString().toInt(), mBinding?.lockIdx?.text.toString().toInt()) { res ->
-                LogUtil.i("关锁卡扣成功 : ${res.toHexStrings()}")
+                LogUtil.i("关锁卡扣 : ${res.toHexStrings()}")
+            }
+        }
+
+        mBinding?.lockRfid?.setOnClickListener {
+            ModBusController.readLockRfid(mBinding?.slaveIdx?.text.toString().toInt(), mBinding?.lockIdx?.text.toString().toInt()) { res ->
+                LogUtil.i("查询锁具RFID : ${res.toHexStrings()}")
             }
         }
 

+ 5 - 5
app/src/main/java/com/grkj/iscs/modbus/DeviceBean.kt

@@ -19,11 +19,11 @@ class DeviceBean(var idx: Byte?, var type: Byte?, var status: ByteArray?) {
         type?.let {
             when (it) {
                 0x00.toByte() -> {
-                    // TODO 判断有问题
-                    val leftHasKey = byteArray[3] and 0x01.toByte() == 0x01.toByte()
-                    val isLeftCharging = byteArray[3] and 0x02.toByte() == 0x01.toByte()
-                    val rightHasKey = byteArray[4] and 0x01.toByte() == 0x01.toByte()
-                    val isRightCharging = byteArray[4] and 0x02.toByte() == 0x01.toByte()
+                    // TODO 未验证
+                    val leftHasKey = (byteArray[3].toInt() shr 0) and 0x1 == 1
+                    val isLeftCharging = (byteArray[3].toInt() shr 1) and 0x1 == 1
+                    val rightHasKey = (byteArray[4].toInt() shr 0) and 0x1 == 1
+                    val isRightCharging = (byteArray[4].toInt() shr 1) and 0x1 == 1
                     LogUtil.i("钥匙刷新状态 : $leftHasKey - $isLeftCharging - $rightHasKey - $isRightCharging")
                     if (status == null) {
                         return false

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

@@ -231,4 +231,14 @@ object ModBusController {
             }
         }
     }
+
+    fun readLockRfid(slaveIdx: Int?, lockIdx: Int, done: ((res: ByteArray) -> Unit)? = null) {
+        slaveIdx?.let {
+            modBusManager?.generateLockRfidCmd(lockIdx)?.let { cmd ->
+                modBusManager?.sendTo(it, cmd) { res ->
+                    done?.invoke(res)
+                }
+            }
+        }
+    }
 }

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

@@ -273,6 +273,21 @@ class ModBusManager(
                 str.toInt(2).toByte(),
                 if (isOpen) 0x00 else 0xFF.toByte()))
     }
+
+//    fun generateKeyRfidCmd(): MBFrame {
+//
+//    }
+
+    /**
+     * 生成锁具 RFID 读指令
+     */
+    fun generateLockRfidCmd(lockIdx: Int): MBFrame {
+        return MBFrame(
+            FRAME_TYPE_READ,
+//            byteArrayOf(0x00, (32 + (lockIdx - 1) * 4).toByte(), 0x00, 0x04)
+            byteArrayOf(0x00, 0x39, 0x00, 0x04)
+        )
+    }
 }
 
 

+ 10 - 0
app/src/main/res/layout/activity_modbus.xml

@@ -91,5 +91,15 @@
             android:text="Close Lock Buckle"
             android:textSize="8sp"
             android:layout_margin="5dp"/>
+
+        <Button
+            android:id="@+id/lockRfid"
+            android:layout_width="100dp"
+            android:layout_height="40dp"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:text="Lock Rfid"
+            android:textSize="8sp"
+            android:layout_margin="5dp"/>
     </LinearLayout>
 </LinearLayout>