bjb 2 месяцев назад
Родитель
Сommit
e8bd99c6f3

+ 47 - 30
app/src/main/java/com/iscs/comm/CtrlActivity.kt

@@ -81,13 +81,16 @@ class CtrlActivity : ComponentActivity() {
         val cmd = intent.getIntExtra("cmd_id", -1)
         val device = CommManager.deviceList.find { it.frame.cmd == cmd }
         if (device == null) return
-        Box(modifier = Modifier.padding(10.dp, pv.calculateTopPadding())) {
+        Box(modifier = Modifier.padding(10.dp, pv.calculateTopPadding()).fillMaxSize()) {
             when (device.deviceType) {
                 DeviceType.SLOT_KEY -> CtrlKeySlot(device as DeviceKeySlot)
                 DeviceType.SLOT_LOCK -> CtrlLock5Slot(device as DeviceLockSlot)
                 // 未知设备
                 else -> Text("未知设备,无法控制")
             }
+            Button({ finish() }, modifier = Modifier.align(Alignment.BottomEnd)) {
+                Text("返回")
+            }
         }
     }
 
@@ -115,7 +118,7 @@ class CtrlActivity : ComponentActivity() {
                 }) { Text("全关") }
             }
             LazyVerticalGrid(
-                columns = GridCells.Adaptive(minSize = 180.dp),
+                columns = GridCells.Adaptive(minSize = 160.dp),
                 contentPadding = PaddingValues(10.dp, 10.dp),
                 horizontalArrangement = Arrangement.spacedBy(8.dp),
                 verticalArrangement = Arrangement.spacedBy(8.dp),
@@ -129,18 +132,19 @@ class CtrlActivity : ComponentActivity() {
                         override fun onDeviceChanged(device: Device) {
                             super.onDeviceChanged(device)
                             if (dev.frame.cmd == device.frame.cmd) {
-                                (device.deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == state.ch && it.isChanged() }?.let {
-                                    isLock.value = it.isSlotLock
-                                    isUsed.value = it.isUsed
-                                    rfid.value = it.rfid
-                                    if (it.isChanged() && rfid.value.isNotEmpty() && rfid.value != lastRFID) {
-                                        lastRFID = rfid.value
-                                        // 硬件逻辑已经存在
-                                        dev.ctrlSlotLockAndCharge(state.ch, true, true)
-                                    } else if (rfid.value.isEmpty()) {
-                                        lastRFID = ""
+                                (device.deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == state.ch && it.isChanged() }
+                                    ?.let {
+                                        isLock.value = it.isSlotLock
+                                        isUsed.value = it.isUsed
+                                        rfid.value = it.rfid
+                                        if (it.isChanged() && rfid.value.isNotEmpty() && rfid.value != lastRFID) {
+                                            lastRFID = rfid.value
+                                            // 硬件逻辑已经存在
+                                            dev.ctrlSlotLockAndCharge(state.ch, true, true)
+                                        } else if (rfid.value.isEmpty()) {
+                                            lastRFID = ""
+                                        }
                                     }
-                                }
                             }
                         }
                     }
@@ -172,23 +176,35 @@ class CtrlActivity : ComponentActivity() {
                             Row {
                                 Button(
                                     { dev.ctrlSlotLockAndCharge(state.ch, false, false) },
-                                    contentPadding = PaddingValues(horizontal = 6.dp, vertical = 0.dp)
+                                    contentPadding = PaddingValues(
+                                        horizontal = 6.dp,
+                                        vertical = 0.dp
+                                    )
                                 ) { Text("打开锁") }
                                 Spacer(modifier = Modifier.weight(1f))
                                 Button(
                                     { dev.ctrlSlotLockAndCharge(state.ch, true, true) },
-                                    contentPadding = PaddingValues(horizontal = 6.dp, vertical = 0.dp)
+                                    contentPadding = PaddingValues(
+                                        horizontal = 6.dp,
+                                        vertical = 0.dp
+                                    )
                                 ) { Text("关闭锁") }
                             }
                             Row {
                                 Button(
                                     { dev.ctrlSlotCharge(state.ch, true) },
-                                    contentPadding = PaddingValues(horizontal = 6.dp, vertical = 0.dp)
+                                    contentPadding = PaddingValues(
+                                        horizontal = 6.dp,
+                                        vertical = 0.dp
+                                    )
                                 ) { Text("开充电") }
                                 Spacer(modifier = Modifier.weight(1f))
                                 Button(
                                     { dev.ctrlSlotCharge(state.ch, false) },
-                                    contentPadding = PaddingValues(horizontal = 6.dp, vertical = 0.dp)
+                                    contentPadding = PaddingValues(
+                                        horizontal = 6.dp,
+                                        vertical = 0.dp
+                                    )
                                 ) { Text("关充电") }
                             }
                         }
@@ -226,20 +242,21 @@ class CtrlActivity : ComponentActivity() {
                         override fun onDeviceChanged(device: Device) {
                             super.onDeviceChanged(device)
                             if (dev.frame.cmd == device.frame.cmd) {
-                                (device.deviceStatus as DeviceStatusLockSlot).slotList.find { it.ch == state.ch && it.isChanged() }?.let {
-                                    isLock.value = it.isSlotLock
-                                    isUsed.value = it.isUsed
-                                    rfid.value = it.rfid
-                                    // Log.d("xiaoming", "${state.ch} ${it.isChanged} ${rfid.value} ${lastRFID}")
-                                    // 这里可以做一些其他逻辑,比如如果当前有锁存在,但是没上锁,这里可执行上锁操作
-                                    if (it.isChanged() && rfid.value.isNotEmpty() && rfid.value != lastRFID) {
-                                        lastRFID = rfid.value
-                                        // 硬件逻辑已存在
-                                        // dev.ctrlSlotLock(state.ch, true).writeByFrame()
-                                    } else if (rfid.value.isEmpty()) {
-                                        lastRFID = ""
+                                (device.deviceStatus as DeviceStatusLockSlot).slotList.find { it.ch == state.ch && it.isChanged() }
+                                    ?.let {
+                                        isLock.value = it.isSlotLock
+                                        isUsed.value = it.isUsed
+                                        rfid.value = it.rfid
+                                        // Log.d("xiaoming", "${state.ch} ${it.isChanged} ${rfid.value} ${lastRFID}")
+                                        // 这里可以做一些其他逻辑,比如如果当前有锁存在,但是没上锁,这里可执行上锁操作
+                                        if (it.isChanged() && rfid.value.isNotEmpty() && rfid.value != lastRFID) {
+                                            lastRFID = rfid.value
+                                            // 硬件逻辑已存在
+                                            // dev.ctrlSlotLock(state.ch, true).writeByFrame()
+                                        } else if (rfid.value.isEmpty()) {
+                                            lastRFID = ""
+                                        }
                                     }
-                                }
                             }
                         }
                     }

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -1,3 +1,3 @@
 <resources>
-    <string name="app_name">ISCS_SDK</string>
+    <string name="app_name">SDK</string>
 </resources>

+ 16 - 12
transport/src/main/java/com/iscs/comm/CommManager.kt

@@ -126,14 +126,13 @@ object CommManager {
             val frame = writeWithResponse(it)
             // 通过数据帧转换设备类型
             if (frame.cmd > 0) deviceList.add(frame.factoryDevice())
-            delay(20)
         }
         // 遍历一遍设备状态
         checkDeviceStatus(true)?.join()
         // 将设备列表回调给外部
         deviceChangeListeners.forEach { it.onDeviceList(ArrayList(deviceList)) }
         // 延时一点时间,开始执行查询设备状态操作
-        delay(20)
+        delay(500)
         // 开启轮询设备状态
         startDeviceStatusLoop()
     }
@@ -154,22 +153,27 @@ object CommManager {
     private fun checkDeviceStatus(isInit: Boolean) = manager?.scope?.launch(Dispatchers.IO) {
         deviceList.forEach {
             // 根据已有的设备,遍历设备状态
-            // 读取设备信息
-            val iFrame = writeWithResponse(it.ctrlCheckDeviceInfo())
-            // 通过响应的数据帧更新设备模型的状态
-            it.updateDeviceInfo(iFrame)
-            // 读取设备属性状态
-            val sFrame = writeWithResponse(it.ctrlCheckDeviceStatus())
-            it.updateDeviceStatus(sFrame)
-            // 查询底座带读取RFID功能的设备读取REID
+            // 读取卡槽是否使用
+            val iFrame = writeWithResponse(it.ctrlCheckSlotUseStatus())
+            // 更新当前卡槽使用状态
+            it.updateSlotUseStatus(iFrame)
+            // 间隔30ms读取卡扣状态比较准确
+            if (!isInit) delay(30)
+            // 读取卡槽的卡扣和充电状态
+            val sFrame = writeWithResponse(it.ctrlCheckSlotLockStatus())
+            // 更新卡槽的卡扣状态
+            it.updateSlotLockStatus(sFrame)
+            // 查询底座带读取RFID功能的设备读取REID,这里只读取
             it.ctrlReadSlotRFID().forEach { frame ->
                 val rFrame = writeWithResponse(frame)
                 it.updateSlotRFID(rFrame)
             }
             // 设备状态发生变化通知外部
-            if (it.isDeviceStatusChanged() && !isInit) deviceChangeListeners.forEach { lis -> lis.onDeviceChanged(it) }
+            if (!isInit) deviceChangeListeners.forEach { lis ->
+                lis.onDeviceChanged(it)
+            }
             // 限制轮询的速度
-            delay(20)
+            delay(30)
         }
     }
 

+ 6 - 8
transport/src/main/java/com/iscs/comm/entity/device/Device.kt

@@ -4,7 +4,7 @@ import com.iscs.comm.entity.Frame
 import com.iscs.comm.entity.device.status.DeviceStatus
 import com.iscs.comm.entity.device.status.DeviceStatusNone
 import com.iscs.comm.enums.DeviceType
-import com.iscs.comm.extension.buildCtrlReadDeviceStatus
+import com.iscs.comm.extension.buildCtrlReadSlotUseStatus
 
 /**
  * 用于封装设备类型对外输出
@@ -34,17 +34,15 @@ abstract class Device(val frame: Frame) {
 
     /**
      * 构建获取当前底座状态的数据帧
-     *
-     * 问题:如果是钥匙仓位的话,开启充电时仓位是否有设备就不上报了
      */
-    open fun ctrlCheckDeviceInfo(): Frame {
-        return frame.newFrame().apply { cmd = frame.cmd }.buildCtrlReadDeviceStatus()
+    open fun ctrlCheckSlotUseStatus(): Frame {
+        return frame.newFrame().apply { cmd = frame.cmd }.buildCtrlReadSlotUseStatus()
     }
 
     /**
      * 构建获取当前底座卡扣状态的数据帧
      */
-    abstract fun ctrlCheckDeviceStatus(): Frame
+    abstract fun ctrlCheckSlotLockStatus(): Frame
 
     /**
      * 构建读取当前底座上设备RFID
@@ -56,14 +54,14 @@ abstract class Device(val frame: Frame) {
      *
      * @param frame 查询设备信息返回的数据帧,由设备模型自己处理
      */
-    abstract fun updateDeviceInfo(frame: Frame)
+    abstract fun updateSlotUseStatus(frame: Frame)
 
     /**
      * 更新设备状态
      *
      * @param frame 设备属性状态
      */
-    abstract fun updateDeviceStatus(frame: Frame)
+    abstract fun updateSlotLockStatus(frame: Frame)
 
     /**
      * 更新底座读取到的RFID

+ 3 - 3
transport/src/main/java/com/iscs/comm/entity/device/DeviceKeySlot.kt

@@ -30,7 +30,7 @@ class DeviceKeySlot(frame: Frame) : Device(frame) {
     /**
      * 构建获取钥匙锁定状态的数据帧
      */
-    override fun ctrlCheckDeviceStatus(): Frame {
+    override fun ctrlCheckSlotLockStatus(): Frame {
         return frame.newFrame().apply { cmd = frame.cmd }.buildCheckDeviceCtrlStatus()
     }
 
@@ -55,14 +55,14 @@ class DeviceKeySlot(frame: Frame) : Device(frame) {
      *
      * @param frame 查询到的设备信息
      */
-    override fun updateDeviceInfo(frame: Frame) {
+    override fun updateSlotUseStatus(frame: Frame) {
         deviceStatus.updateInfo(frame)
     }
 
     /**
      * 更新设备状态操作
      */
-    override fun updateDeviceStatus(frame: Frame) {
+    override fun updateSlotLockStatus(frame: Frame) {
         deviceStatus.updateStatus(frame)
     }
 

+ 3 - 3
transport/src/main/java/com/iscs/comm/entity/device/DeviceLockSlot.kt

@@ -28,7 +28,7 @@ class DeviceLockSlot(frame: Frame) : Device(frame) {
      */
     override var deviceStatus: DeviceStatus = DeviceStatusLockSlot()
 
-    override fun ctrlCheckDeviceStatus(): Frame {
+    override fun ctrlCheckSlotLockStatus(): Frame {
         return frame.newFrame().apply { cmd = frame.cmd }.buildCheckDeviceCtrlStatus()
     }
 
@@ -47,11 +47,11 @@ class DeviceLockSlot(frame: Frame) : Device(frame) {
     /**
      * 更新锁底座设备状态
      */
-    override fun updateDeviceInfo(frame: Frame) {
+    override fun updateSlotUseStatus(frame: Frame) {
         deviceStatus.updateInfo(frame)
     }
 
-    override fun updateDeviceStatus(frame: Frame) {
+    override fun updateSlotLockStatus(frame: Frame) {
         deviceStatus.updateStatus(frame)
     }
 

+ 3 - 3
transport/src/main/java/com/iscs/comm/entity/device/DeviceNone.kt

@@ -8,11 +8,11 @@ import com.iscs.comm.extension.buildCheckDeviceCtrlStatus
  */
 class DeviceNone(frame: Frame) : Device(frame) {
 
-    override fun updateDeviceInfo(frame: Frame) {
+    override fun updateSlotUseStatus(frame: Frame) {
 
     }
 
-    override fun updateDeviceStatus(frame: Frame) {
+    override fun updateSlotLockStatus(frame: Frame) {
 
     }
 
@@ -20,7 +20,7 @@ class DeviceNone(frame: Frame) : Device(frame) {
         return false
     }
 
-    override fun ctrlCheckDeviceStatus(): Frame {
+    override fun ctrlCheckSlotLockStatus(): Frame {
         return frame.newFrame().apply { cmd = frame.cmd }.buildCheckDeviceCtrlStatus()
     }
 

+ 3 - 3
transport/src/main/java/com/iscs/comm/entity/device/DeviceSupplyCabinet.kt

@@ -12,7 +12,7 @@ class DeviceSupplyCabinet(frame: Frame) : Device(frame) {
     override val deviceType: DeviceType = DeviceType.SUPPLY_CABINET
 
 
-    override fun ctrlCheckDeviceStatus(): Frame {
+    override fun ctrlCheckSlotLockStatus(): Frame {
         return frame.newFrame().apply { cmd = frame.cmd }.buildCheckDeviceCtrlStatus()
     }
 
@@ -20,11 +20,11 @@ class DeviceSupplyCabinet(frame: Frame) : Device(frame) {
         return emptyList()
     }
 
-    override fun updateDeviceInfo(frame: Frame) {
+    override fun updateSlotUseStatus(frame: Frame) {
         // ISCSLog.i("xiaoming", "更新设备信息:${frame.data.toHexString()}")
     }
 
-    override fun updateDeviceStatus(frame: Frame) {
+    override fun updateSlotLockStatus(frame: Frame) {
         // ISCSLog.i("xiaoming", "更新设备状态:${frame.data.toHexString()}")
     }
 

+ 1 - 1
transport/src/main/java/com/iscs/comm/extension/FrameExt.kt

@@ -78,7 +78,7 @@ fun Frame.buildCtrlKeySlotLockAndCharge(ch: Int, isLock: Boolean, isCharge: Bool
 /**
  * 构建查询设备信息状态的命令
  */
-fun Frame.buildCtrlReadDeviceStatus(): Frame {
+fun Frame.buildCtrlReadSlotUseStatus(): Frame {
     val id = this.cmd
     return this.newFrame().apply {
         cmd = id