|
|
@@ -4,6 +4,7 @@ import com.google.gson.Gson
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
import com.grkj.iscs_mars.BusinessManager
|
|
|
import com.grkj.iscs_mars.MyApplication
|
|
|
+import com.grkj.iscs_mars.extentions.toHexStrings
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
@@ -243,7 +244,7 @@ class DockBean(
|
|
|
|
|
|
DOCK_TYPE_COLLECT -> {
|
|
|
val working = (byteArray[4].toInt() shr 0) and 0x1 == 1
|
|
|
- LogUtil.d("开关量采集板是否工作 : $working")
|
|
|
+ if (!working) LogUtil.d("开关量 采集板工作异常")
|
|
|
return DockBean(
|
|
|
addr,
|
|
|
dockConfig.find { it.address == addr }?.row?.toInt() ?: 0,
|
|
|
@@ -386,69 +387,49 @@ class DockBean(
|
|
|
* 转换开关状态
|
|
|
*/
|
|
|
fun parseSwitchStatus(byteArray: ByteArray, done: () -> Unit): DockBean? {
|
|
|
- if (byteArray.isEmpty()) {
|
|
|
- return null
|
|
|
- }
|
|
|
- type?.let {
|
|
|
- // 因为都是一个寄存器返回的,所以一定能得到2个钥匙的状态或者10把锁具的状态
|
|
|
- when (it) {
|
|
|
- DOCK_TYPE_COLLECT -> {
|
|
|
- val remainTimes = AtomicInteger(0)
|
|
|
- for (i in 0 until byteArray[4].toInt()) {
|
|
|
- val switchBoardAddr = byteArrayOf(0x00, (0x20 + i).toByte())
|
|
|
- ModBusController.readSwitchStatus(addr, switchBoardAddr) { res ->
|
|
|
- val switchStatus: MutableList<Boolean> = mutableListOf()
|
|
|
- for (switchIdx in 0..7) {
|
|
|
- switchStatus.add((res[4].toInt() shr switchIdx) and 0x1 == 1)
|
|
|
- }
|
|
|
- for (switchIdx in 0..7) {
|
|
|
- switchStatus.add((res[3].toInt() shr switchIdx) and 0x1 == 1)
|
|
|
- }
|
|
|
- for (idx in 0 until switchStatus.size) {
|
|
|
- deviceList.filterIsInstance<SwitchBean>()
|
|
|
- .find { it.switchBoardAddr == switchBoardAddr[1] && it.idx == idx }
|
|
|
- ?.let {
|
|
|
- if (it.enabled != switchStatus[idx]) {
|
|
|
- it.enabled =
|
|
|
- switchStatus[idx]
|
|
|
- it.changed = true
|
|
|
- }
|
|
|
- } ?: run {
|
|
|
- deviceList.add(
|
|
|
- SwitchBean(
|
|
|
- idx,
|
|
|
- switchBoardAddr[1],
|
|
|
- switchStatus[idx],
|
|
|
- changed = true
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- remainTimes.addAndGet(1)
|
|
|
- if (remainTimes.get() == byteArray[4].toInt()) {
|
|
|
- BusinessManager.sendEventMsg(
|
|
|
- MsgEvent(
|
|
|
- MSG_EVENT_SWITCH_COLLECTION_UPDATE,
|
|
|
- null
|
|
|
- )
|
|
|
- )
|
|
|
- done()
|
|
|
- }
|
|
|
+ if (byteArray.isEmpty() || type == null) return null
|
|
|
+ if (type != DOCK_TYPE_COLLECT) return null
|
|
|
+ // 处理开关量采集操作
|
|
|
+ val remainTimes = AtomicInteger(0)
|
|
|
+ val swModuleCount = byteArray[4].toInt()
|
|
|
+ LogUtil.d("开关量 模块总数 -> $swModuleCount")
|
|
|
+ for (i in 0 until swModuleCount) {
|
|
|
+ // 开关模块索引地址
|
|
|
+ val swModuleIdx = byteArrayOf(0x00, (0x20 + i).toByte())
|
|
|
+ ModBusController.readSwitchStatus(addr, swModuleIdx) { res ->
|
|
|
+ LogUtil.d("开关量 读${byteArrayOf(swModuleIdx[1]).toHexStrings(false)}数据 -> ${res.toHexStrings()}")
|
|
|
+ val switchStatus: MutableList<Boolean> = mutableListOf()
|
|
|
+ for (switchIdx in 0..7) {
|
|
|
+ switchStatus.add((res[4].toInt() shr switchIdx) and 0x1 == 1)
|
|
|
+ }
|
|
|
+ for (switchIdx in 0..7) {
|
|
|
+ switchStatus.add((res[3].toInt() shr switchIdx) and 0x1 == 1)
|
|
|
+ }
|
|
|
+ for (idx in 0 until switchStatus.size) {
|
|
|
+ deviceList.filterIsInstance<SwitchBean>().find { it.switchBoardAddr == swModuleIdx[1] && it.idx == idx }?.let {
|
|
|
+ if (it.enabled != switchStatus[idx]) {
|
|
|
+ it.enabled = switchStatus[idx]
|
|
|
+ it.changed = true
|
|
|
}
|
|
|
+ } ?: run {
|
|
|
+ deviceList.add(SwitchBean(idx, swModuleIdx[1], switchStatus[idx], changed = true))
|
|
|
}
|
|
|
- return DockBean(
|
|
|
- addr,
|
|
|
- dockConfig.find { it.address == addr }?.row?.toInt() ?: 0,
|
|
|
- dockConfig.find { it.address == addr }?.column?.toInt() ?: 0,
|
|
|
- type,
|
|
|
- isWorking,
|
|
|
- deviceList
|
|
|
- )
|
|
|
}
|
|
|
-
|
|
|
- else -> return null
|
|
|
+ remainTimes.addAndGet(1)
|
|
|
+ if (remainTimes.get() == byteArray[4].toInt()) {
|
|
|
+ BusinessManager.sendEventMsg(MsgEvent(MSG_EVENT_SWITCH_COLLECTION_UPDATE, null))
|
|
|
+ done()
|
|
|
+ }
|
|
|
}
|
|
|
- } ?: return null
|
|
|
+ }
|
|
|
+ return DockBean(
|
|
|
+ addr,
|
|
|
+ dockConfig.find { it.address == addr }?.row?.toInt() ?: 0,
|
|
|
+ dockConfig.find { it.address == addr }?.column?.toInt() ?: 0,
|
|
|
+ type,
|
|
|
+ isWorking,
|
|
|
+ deviceList
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -558,7 +539,7 @@ class DockBean(
|
|
|
/**
|
|
|
* 钥匙
|
|
|
*/
|
|
|
- // TODO isLeft待移除,使用idx替代
|
|
|
+// TODO isLeft待移除,使用idx替代
|
|
|
class KeyBean(
|
|
|
idx: Int,
|
|
|
isExist: Boolean,
|