|
|
@@ -1,6 +1,7 @@
|
|
|
package com.iscs.comm
|
|
|
|
|
|
import android.os.Bundle
|
|
|
+import android.util.Log
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.activity.compose.setContent
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
|
@@ -17,7 +18,10 @@ import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import com.iscs.comm.entity.device.Device
|
|
|
+import com.iscs.comm.entity.device.DeviceKeySlot
|
|
|
import com.iscs.comm.entity.device.DeviceLockSlot
|
|
|
+import com.iscs.comm.entity.device.status.DeviceStatusKeySlot
|
|
|
+import com.iscs.comm.entity.device.status.DeviceStatusLockSlot
|
|
|
import com.iscs.comm.intf.IDeviceListener
|
|
|
import com.iscs.comm.ui.theme.CommunicationDemoTheme
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
@@ -33,40 +37,99 @@ class MainActivity : ComponentActivity() {
|
|
|
setContent {
|
|
|
CommunicationDemoTheme {
|
|
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
|
|
- Column {
|
|
|
- Text("测试", modifier = Modifier.padding(innerPadding))
|
|
|
+ Column(modifier = Modifier.padding(10.dp)) {
|
|
|
+ Text("测试锁底座", modifier = Modifier.padding(innerPadding))
|
|
|
Row {
|
|
|
- Button({ ctrlLockSlotLock(0, false) }) { Text("开锁0") }
|
|
|
+ Button({ ctrlLockSlotLock(0, false) }) { Text("0-开") }
|
|
|
Spacer(modifier = Modifier.width(10.dp))
|
|
|
- Button({ ctrlLockSlotLock(0, true) }) { Text("关锁0") }
|
|
|
+ Button({ ctrlLockSlotLock(0, true) }) { Text("0-关") }
|
|
|
Spacer(modifier = Modifier.width(10.dp))
|
|
|
- Button({ ctrlLockSlotLock(1, false) }) { Text("开锁1") }
|
|
|
+ Button({ ctrlLockSlotLock(1, false) }) { Text("1-开") }
|
|
|
Spacer(modifier = Modifier.width(10.dp))
|
|
|
- Button({ ctrlLockSlotLock(1, true) }) { Text("关锁1") }
|
|
|
+ Button({ ctrlLockSlotLock(1, true) }) { Text("1-关") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlLockSlotLock(2, false) }) { Text("2-开") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlLockSlotLock(2, true) }) { Text("2-关") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlLockSlotLock(3, false) }) { Text("3-开") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlLockSlotLock(3, true) }) { Text("3-关") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlLockSlotLock(4, false) }) { Text("4-开") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlLockSlotLock(4, true) }) { Text("4-关") }
|
|
|
+ }
|
|
|
+ Text("测试钥匙底座", modifier = Modifier.padding(innerPadding))
|
|
|
+ Row {
|
|
|
+ Button({ ctrlKeySlotLock(0, false) }) { Text("0-开锁") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotLock(0, true) }) { Text("0-关锁") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotCharge(0, true) }) { Text("0-开充电") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotCharge(0, false) }) { Text("0-关充电") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotLock(1, false) }) { Text("1-开锁") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotLock(1, true) }) { Text("1-关锁") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotCharge(1, true) }) { Text("1-开充电") }
|
|
|
+ Spacer(modifier = Modifier.width(10.dp))
|
|
|
+ Button({ ctrlKeySlotCharge(1, false) }) { Text("1-关充电") }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 做SDK初始化操作处理
|
|
|
+ initISCSSDK()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun ctrlLockSlotLock(ch: Int, isLock: Boolean) {
|
|
|
+ val device = list.find { it.frame.cmd == 0x0602 }
|
|
|
+ if (device is DeviceLockSlot) {
|
|
|
+ CommManager.write(device.ctrlSlotLock(ch, isLock))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun ctrlKeySlotLock(ch: Int, isLock: Boolean) {
|
|
|
+ val device = list.find { it.frame.cmd == 0x0601 }
|
|
|
+ if (device is DeviceKeySlot) {
|
|
|
+ CommManager.write(device.ctrlSlotLock(ch, isLock))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun ctrlKeySlotCharge(ch: Int, isCharge: Boolean) {
|
|
|
+ val device = list.find { it.frame.cmd == 0x0601 }
|
|
|
+ if (device is DeviceKeySlot) {
|
|
|
+ CommManager.write(device.ctrlSlotCharge(ch, isCharge))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化ISCS SDK 操作
|
|
|
+ */
|
|
|
+ fun initISCSSDK() {
|
|
|
lifecycleScope.launch(Dispatchers.IO) {
|
|
|
CommManager.init()
|
|
|
CommManager.setOnDeviceListener(object : IDeviceListener {
|
|
|
+
|
|
|
override fun onDeviceList(devices: List<Device>) {
|
|
|
list.addAll(devices)
|
|
|
}
|
|
|
|
|
|
override fun onDeviceChanged(device: Device) {
|
|
|
-
|
|
|
+ val msg = when (device.deviceStatus) {
|
|
|
+ is DeviceStatusKeySlot -> (device.deviceStatus as DeviceStatusKeySlot).slotList.toString()
|
|
|
+ is DeviceStatusLockSlot -> (device.deviceStatus as DeviceStatusLockSlot).slotList.toString()
|
|
|
+ else -> "未知状态变化"
|
|
|
+ }
|
|
|
+ Log.d("xiaoming", "设备状态发生变化了 $msg")
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- fun ctrlLockSlotLock(ch: Int, isLock: Boolean) {
|
|
|
- val device = list.find { it.frame.cmd == 0x0602 }
|
|
|
- if (device is DeviceLockSlot) {
|
|
|
- CommManager.write(device.ctrlSlotLock(ch, isLock))
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|