|
|
@@ -116,7 +116,7 @@ object ModBusController {
|
|
|
LogUtil.i("initDevicesStatus 设备(${bytes[0].toInt()})类型:$type")
|
|
|
}
|
|
|
}
|
|
|
- Executor.delayOnIO({
|
|
|
+ Executor.delayOnMain({
|
|
|
// TODO 待完善
|
|
|
initLock() // TODO 打开所有无锁的卡扣、读取所有锁的RFID
|
|
|
initKey() // TODO 打开所有无钥匙的卡扣、关闭所有钥匙灯光、读取所有钥匙的RFID
|
|
|
@@ -131,15 +131,14 @@ object ModBusController {
|
|
|
private fun initLock() {
|
|
|
LogUtil.i("initLock : $deviceList")
|
|
|
deviceList.filter { it.type == 0x01.toByte() }.forEach { deviceBean ->
|
|
|
- deviceBean.lockList.forEach { lockBean ->
|
|
|
- if (lockBean.hasLock) {
|
|
|
- LogUtil.i("initLock rfid: ${deviceBean.idx!!.toInt() - 1} : ${lockBean.idx}")
|
|
|
- readLockRfid(deviceBean.idx!!.toInt() - 1, lockBean.idx)
|
|
|
- } else {
|
|
|
- LogUtil.i("initLock buckle : ${deviceBean.idx!!.toInt() - 1} : ${lockBean.idx}")
|
|
|
- controlLockBuckle(false, deviceBean.idx!!.toInt() - 1, lockBean.idx)
|
|
|
- }
|
|
|
+ val hasLockIdxList = deviceBean.lockList.filter { it.hasLock }.map { it.idx }
|
|
|
+ val noLockIdxList = deviceBean.lockList.filter { !it.hasLock }.map { it.idx } as MutableList<Int>
|
|
|
+
|
|
|
+ hasLockIdxList.forEach { idx ->
|
|
|
+ readLockRfid(deviceBean.addr!!.toInt() - 1, idx)
|
|
|
}
|
|
|
+
|
|
|
+ controlLockBuckle(true, deviceBean.addr!!.toInt() - 1, noLockIdxList)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -149,11 +148,11 @@ object ModBusController {
|
|
|
private fun initKey() {
|
|
|
LogUtil.i("initKey : $deviceList")
|
|
|
deviceList.filter { it.type == 0x00.toByte() }.forEach { deviceBean ->
|
|
|
- controlKeyLight(deviceBean.idx!!.toInt() - 1, 2, 2)
|
|
|
+ controlKeyLight(deviceBean.addr!!.toInt() - 1, 2, 2)
|
|
|
deviceBean.keyList.forEach { key ->
|
|
|
if (key.hasKey) {
|
|
|
- LogUtil.i("initKey : ${deviceBean.idx!!.toInt() - 1} : ${key.isLeft}")
|
|
|
- readKeyRfid(deviceBean.idx!!.toInt() - 1, key.isLeft)
|
|
|
+ LogUtil.i("initKey : ${deviceBean.addr!!.toInt() - 1} : ${key.isLeft}")
|
|
|
+ readKeyRfid(deviceBean.addr!!.toInt() - 1, key.isLeft)
|
|
|
} else {
|
|
|
// TODO 关闭钥匙卡扣
|
|
|
}
|
|
|
@@ -168,7 +167,7 @@ object ModBusController {
|
|
|
if (byteArray.isEmpty()) {
|
|
|
return null
|
|
|
}
|
|
|
- val deviceBean = deviceList.find { it.idx == byteArray[0] }
|
|
|
+ val deviceBean = deviceList.find { it.addr == byteArray[0] }
|
|
|
return deviceBean?.parseStatus(byteArray) ?: let {
|
|
|
val temp = DeviceBean(byteArray[0], null, mutableListOf(), mutableListOf())
|
|
|
deviceList.add(temp)
|
|
|
@@ -189,7 +188,7 @@ object ModBusController {
|
|
|
* 更新设备类型
|
|
|
*/
|
|
|
fun updateDeviceType(idx: Byte?, type: Byte?) {
|
|
|
- deviceList.find { it.idx == idx }?.type = type
|
|
|
+ deviceList.find { it.addr == idx }?.type = type
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -225,6 +224,18 @@ object ModBusController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun controlLockBuckle(isOpen: Boolean, slaveIdx: Int?, lockIdxList: MutableList<Int>, done: ((res: ByteArray) -> Unit)? = null) {
|
|
|
+ slaveIdx?.let {
|
|
|
+ modBusManager?.generateLockBuckleCmd(isOpen, lockIdxList)?.let { cmdList ->
|
|
|
+ cmdList.forEach { cmd ->
|
|
|
+ modBusManager?.sendTo(it, cmd) { res ->
|
|
|
+ done?.invoke(res)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 读取钥匙RFID
|
|
|
*/
|
|
|
@@ -255,7 +266,7 @@ object ModBusController {
|
|
|
* 更新钥匙RFID
|
|
|
*/
|
|
|
fun updateKeyRfid(slaveIdx: Int, isLeft: Boolean, rfid: String) {
|
|
|
- deviceList.find { it.idx?.toInt() == slaveIdx }?.keyList?.find { it.isLeft == isLeft }?.rfid = rfid
|
|
|
+ deviceList.find { it.addr?.toInt() == slaveIdx }?.keyList?.find { it.isLeft == isLeft }?.rfid = rfid
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -269,7 +280,7 @@ object ModBusController {
|
|
|
* 更新锁具RFID
|
|
|
*/
|
|
|
fun updateLockRfid(slaveIdx: Int, lockIdx: Int, rfid: String) {
|
|
|
- deviceList.find { it.idx?.toInt() == slaveIdx }?.lockList?.find { it.idx == lockIdx }?.rfid = rfid
|
|
|
+ deviceList.find { it.addr?.toInt() == slaveIdx }?.lockList?.find { it.idx == lockIdx }?.rfid = rfid
|
|
|
}
|
|
|
|
|
|
/**
|