|
|
@@ -1,5 +1,6 @@
|
|
|
package com.grkj.iscs.activity
|
|
|
|
|
|
+import com.grkj.iscs.BusinessManager
|
|
|
import com.grkj.iscs.base.BaseMvpActivity
|
|
|
import com.grkj.iscs.databinding.ActivityModbusBinding
|
|
|
import com.grkj.iscs.extentions.removeLeadingZeros
|
|
|
@@ -25,151 +26,24 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
|
|
|
get() = ActivityModbusBinding.inflate(layoutInflater)
|
|
|
|
|
|
override fun initView() {
|
|
|
+ BusinessManager.connectDock(1)
|
|
|
|
|
|
- presenter?.initModbus()
|
|
|
-
|
|
|
-// Executor.delayOnMain({
|
|
|
-// ModBusController.initDevicesStatus()
|
|
|
-// }, 3000)
|
|
|
-
|
|
|
- ModBusController.registerStatusListener(this) { res ->
|
|
|
- LogUtil.i("设备状态:${(res as List<ByteArray>).map { it.toHexStrings() }}")
|
|
|
- res.forEach { bytes ->
|
|
|
- val dockBean = ModBusController.updateStatus(bytes) ?: return@forEach
|
|
|
- when (dockBean.type) {
|
|
|
- DOCK_TYPE_KEY -> {
|
|
|
- dockBean.getKeyList().forEach { keyBean ->
|
|
|
- if (keyBean.isExist) {
|
|
|
- // 放回钥匙,读取rfid
|
|
|
- ModBusController.readKeyRfid(dockBean.addr.toInt() - 1, keyBean.isLeft) { isLeft, res ->
|
|
|
- val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
- ModBusController.updateKeyRfid(dockBean.addr.toInt(), keyBean.isLeft, rfid)
|
|
|
- // TODO 从HTTP读取Mac
|
|
|
- // TODO 蓝牙通信
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- DOCK_TYPE_LOCK -> {
|
|
|
- dockBean.getLockList().forEach { lockBean ->
|
|
|
- if (lockBean.isExist) {
|
|
|
- ModBusController.readLockRfid(dockBean.addr.toInt() - 1, lockBean.idx) { res ->
|
|
|
- val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
- ModBusController.updateLockRfid(dockBean.addr.toInt(), lockBean.idx, rfid)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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)
|
|
|
- }
|
|
|
- }
|
|
|
- DEVICE_TYPE_CARD -> {
|
|
|
- ModBusController.readPortalCaseCardRfid(dockBean.addr.toInt() - 1) { res ->
|
|
|
- val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
- println("卡片RFID : $rfid")
|
|
|
- ToastUtils.tip("卡片RFID : $rfid")
|
|
|
- }
|
|
|
- }
|
|
|
- DEVICE_TYPE_FINGERPRINT -> {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ BusinessManager.registerStatusListener(this)
|
|
|
|
|
|
mBinding?.init?.setOnClickListener {
|
|
|
ModBusController.initDevicesStatus()
|
|
|
}
|
|
|
|
|
|
mBinding?.keyBuckleStatus?.setOnClickListener {
|
|
|
- // TODO slaveIdx暂时写死,调试用
|
|
|
- ModBusController.readBuckleStatus(false, 1) { type, res ->
|
|
|
- LogUtil.i("单slave卡扣状态 : $type - ${res.toHexStrings()}")
|
|
|
- // TODO 待验证
|
|
|
- when (type) {
|
|
|
- 0 -> {
|
|
|
- val isLeftLock = (res[4].toInt() shr 0) and 0x1 == 1
|
|
|
- val isRightLock = (res[4].toInt() shr 4) and 0x1 == 1
|
|
|
- println("钥匙底座卡扣状态 : $isLeftLock - $isRightLock")
|
|
|
- }
|
|
|
- 1 -> {
|
|
|
- val tempList = mutableListOf<Boolean>()
|
|
|
- for (i in 0..7) {
|
|
|
- tempList.add((res[4].toInt() shr i) and 0x1 == 1)
|
|
|
- }
|
|
|
- println("锁具底座卡扣1-8状态 : $tempList")
|
|
|
- }
|
|
|
- 2 -> {
|
|
|
- val lock9Status = (res[4].toInt() shr 0) and 0x1 == 1
|
|
|
- val lock10Status = (res[4].toInt() shr 1) and 0x1 == 1
|
|
|
- println("锁具底座卡扣9、10状态 : $lock9Status - $lock10Status")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ BusinessManager.readKeyBuckleStatus()
|
|
|
}
|
|
|
|
|
|
mBinding?.lockBuckleStatus?.setOnClickListener {
|
|
|
- // TODO slaveIdx暂时写死,调试用
|
|
|
- ModBusController.readBuckleStatus(true, 0) { type, res ->
|
|
|
- LogUtil.i("单slave卡扣状态 : $type - ${res.toHexStrings()}")
|
|
|
- when (type) {
|
|
|
- 0 -> {
|
|
|
- val isLeftLock = (res[4].toInt() shr 0) and 0x1 == 1
|
|
|
- val isRightLock = (res[4].toInt() shr 4) and 0x1 == 1
|
|
|
- println("锁具底座卡扣状态 : $isLeftLock - $isRightLock")
|
|
|
- }
|
|
|
- 1 -> {
|
|
|
- val tempList = mutableListOf<Boolean>()
|
|
|
- for (i in 0..7) {
|
|
|
- tempList.add((res[4].toInt() shr i) and 0x1 == 1)
|
|
|
- }
|
|
|
- println("锁具底座卡扣1-8状态 : $tempList")
|
|
|
- }
|
|
|
- 2 -> {
|
|
|
- val lock9Status = (res[4].toInt() shr 0) and 0x1 == 1
|
|
|
- val lock10Status = (res[4].toInt() shr 1) and 0x1 == 1
|
|
|
- println("锁具底座卡扣9、10状态 : $lock9Status - $lock10Status")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ BusinessManager.readLockBuckleStatus()
|
|
|
}
|
|
|
|
|
|
mBinding?.deviceType?.setOnClickListener {
|
|
|
- println("____________________________________")
|
|
|
- ModBusController.readDeviceType { res ->
|
|
|
- LogUtil.i("设备类型数量 : ${res.size}")
|
|
|
- LogUtil.i("设备类型 : ${res.map { it.toHexStrings()}}")
|
|
|
- res.forEach { bytes ->
|
|
|
- if (bytes.size < 5) return@forEach
|
|
|
- // 设备具体数据由0x0011寄存器提供
|
|
|
- ModBusController.updateDeviceType(bytes[0], bytes[4])
|
|
|
- val type = when (bytes[4]) {
|
|
|
- DOCK_TYPE_KEY -> "钥匙底座"
|
|
|
- DOCK_TYPE_LOCK -> "锁具底座"
|
|
|
- DOCK_TYPE_ELEC_LOCK_BOARD -> "电磁锁控制板"
|
|
|
- DOCK_TYPE_PORTABLE -> "便携式底座"
|
|
|
- else -> "未知"
|
|
|
- }
|
|
|
- LogUtil.i("设备(${bytes[0].toInt()})类型:$type")
|
|
|
- }
|
|
|
- println("____________________________________")
|
|
|
- }
|
|
|
-
|
|
|
+ ModBusController.updateDeviceType()
|
|
|
}
|
|
|
|
|
|
mBinding?.openLockBuckle?.setOnClickListener {
|
|
|
@@ -218,7 +92,7 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
|
|
|
|
|
|
mBinding?.keyRfid?.setOnClickListener {
|
|
|
// TODO 暂时写死,调试用
|
|
|
- ModBusController.readKeyRfid(1, true) { left, res ->
|
|
|
+ ModBusController.readKeyRfid(1, 1) { left, res ->
|
|
|
val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
println("钥匙RFID : $rfid")
|
|
|
ModBusController.updateKeyRfid(1, left, rfid)
|
|
|
@@ -245,7 +119,7 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
|
|
|
mBinding?.openKeyBuckle?.setOnClickListener {
|
|
|
println("____________________________________")
|
|
|
// TODO 暂时写死,调试用
|
|
|
- ModBusController.controlKeyBuckle(isOpen = true, false, 1) {
|
|
|
+ ModBusController.controlKeyBuckle(isOpen = true, true, 0) {
|
|
|
LogUtil.i("开锁钥匙卡扣 : ${it.toHexStrings()}")
|
|
|
println("____________________________________")
|
|
|
}
|
|
|
@@ -254,32 +128,22 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
|
|
|
mBinding?.closeKeyBuckle?.setOnClickListener {
|
|
|
println("____________________________________")
|
|
|
// TODO 暂时写死,调试用
|
|
|
- ModBusController.controlKeyBuckle(isOpen = false, false, 1) {
|
|
|
+ ModBusController.controlKeyBuckle(isOpen = false, true, 0) {
|
|
|
LogUtil.i("关锁钥匙卡扣 : ${it.toHexStrings()}")
|
|
|
println("____________________________________")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
mBinding?.closeAllLockBuckles?.setOnClickListener {
|
|
|
- ModBusController.dockList.filter { it.type == DOCK_TYPE_LOCK }.forEach { dockBean ->
|
|
|
- val list = dockBean.getLockList().stream().map { it.idx }.collect(Collectors.toList())
|
|
|
- ModBusController.controlLockBuckle(false, dockBean.addr.toInt() - 1, list) {
|
|
|
- LogUtil.i("关所有锁卡扣 : ${it.toHexStrings()}")
|
|
|
- }
|
|
|
- }
|
|
|
+ ModBusController.closeAllLockBuckles()
|
|
|
}
|
|
|
|
|
|
mBinding?.openAllLockBuckles?.setOnClickListener {
|
|
|
- ModBusController.dockList.filter { it.type == DOCK_TYPE_LOCK }.forEach { dockBean ->
|
|
|
- val list = dockBean.getLockList().stream().map { it.idx }.collect(Collectors.toList())
|
|
|
- ModBusController.controlLockBuckle(true, dockBean.addr.toInt() - 1, list) {
|
|
|
- LogUtil.i("开所有锁卡扣 : ${it.toHexStrings()}")
|
|
|
- }
|
|
|
- }
|
|
|
+ ModBusController.openAllLockBuckles()
|
|
|
}
|
|
|
|
|
|
mBinding?.deviceList?.setOnClickListener {
|
|
|
- println("当前底座列表 : ${ModBusController.dockList}")
|
|
|
+ ModBusController.printDockInfo()
|
|
|
}
|
|
|
|
|
|
mBinding?.exit?.setOnClickListener { finish() }
|
|
|
@@ -291,6 +155,7 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
super.onDestroy()
|
|
|
- ModBusController.stop()
|
|
|
+ ModBusController.unregisterListener(this)
|
|
|
+ BusinessManager.disconnectDock()
|
|
|
}
|
|
|
}
|