|
@@ -1,6 +1,7 @@
|
|
|
package com.iscs.comm.entity.device
|
|
package com.iscs.comm.entity.device
|
|
|
|
|
|
|
|
import com.iscs.comm.CommManager.writeWithResponse
|
|
import com.iscs.comm.CommManager.writeWithResponse
|
|
|
|
|
+import com.iscs.comm.entity.CtrlResponse
|
|
|
import com.iscs.comm.entity.Frame
|
|
import com.iscs.comm.entity.Frame
|
|
|
import com.iscs.comm.entity.device.status.DeviceStatus
|
|
import com.iscs.comm.entity.device.status.DeviceStatus
|
|
|
import com.iscs.comm.entity.device.status.DeviceStatusKeySlot
|
|
import com.iscs.comm.entity.device.status.DeviceStatusKeySlot
|
|
@@ -89,16 +90,19 @@ class DeviceKeySlot(frame: Frame) : Device(frame) {
|
|
|
* @param ch 控制槽位 默认-1控制所有
|
|
* @param ch 控制槽位 默认-1控制所有
|
|
|
* @param isLock 是否锁定
|
|
* @param isLock 是否锁定
|
|
|
*/
|
|
*/
|
|
|
- fun ctrlSlotLock(ch: Int, isLock: Boolean, done: (rsp: Frame) -> Unit = {}) {
|
|
|
|
|
|
|
+ fun ctrlSlotLock(ch: Int, isLock: Boolean, done: (CtrlResponse) -> Unit = {}) {
|
|
|
if (ch !in 0..1) {
|
|
if (ch !in 0..1) {
|
|
|
- done(Frame(-1, byteArrayOf()))
|
|
|
|
|
|
|
+ done(CtrlResponse())
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
// 不控制的一项从本地缓存状态中获取写入
|
|
// 不控制的一项从本地缓存状态中获取写入
|
|
|
val status = (deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == ch }
|
|
val status = (deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == ch }
|
|
|
(frame.newFrame().apply { cmd = frame.cmd }
|
|
(frame.newFrame().apply { cmd = frame.cmd }
|
|
|
- .buildCtrlKeySlotLockAndCharge(ch, isLock, status?.isCharging ?: false))
|
|
|
|
|
- .writeWithResponse(done)
|
|
|
|
|
|
|
+ .buildCtrlKeySlotLockAndCharge(ch, isLock, isLock))
|
|
|
|
|
+ .writeWithResponse {
|
|
|
|
|
+ val slot = (deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == ch }
|
|
|
|
|
+ done(CtrlResponse(code = if (slot?.isSlotLock == isLock) 200 else 500, msg = if (slot?.isSlotLock == isLock) "success" else "fail"))
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -107,14 +111,23 @@ class DeviceKeySlot(frame: Frame) : Device(frame) {
|
|
|
* @param ch 控制槽位
|
|
* @param ch 控制槽位
|
|
|
* @param isCharge 是否充电
|
|
* @param isCharge 是否充电
|
|
|
*/
|
|
*/
|
|
|
- fun ctrlSlotCharge(ch: Int, isCharge: Boolean, done: (rsp: Frame) -> Unit = {}) {
|
|
|
|
|
|
|
+ fun ctrlSlotCharge(ch: Int, isCharge: Boolean, done: (CtrlResponse) -> Unit = {}) {
|
|
|
if (ch !in 0..1) {
|
|
if (ch !in 0..1) {
|
|
|
- done(Frame(-1, byteArrayOf()))
|
|
|
|
|
|
|
+ done(CtrlResponse())
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
// 不控制的一项从本地缓存状态中获取写入
|
|
// 不控制的一项从本地缓存状态中获取写入
|
|
|
val status = (deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == ch }
|
|
val status = (deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == ch }
|
|
|
- (frame.newFrame().apply { cmd = frame.cmd }.buildCtrlKeySlotLockAndCharge(ch, status?.isSlotLock ?: false, isCharge)).writeWithResponse(done)
|
|
|
|
|
|
|
+ (frame.newFrame().apply { cmd = frame.cmd }.buildCtrlKeySlotLockAndCharge(ch, status?.isSlotLock ?: false, isCharge))
|
|
|
|
|
+ .writeWithResponse {
|
|
|
|
|
+ val slot = (deviceStatus as DeviceStatusKeySlot).slotList.find { it.ch == ch }
|
|
|
|
|
+ done(
|
|
|
|
|
+ CtrlResponse(
|
|
|
|
|
+ code = if (slot?.isCharging == isCharge) 200 else 500,
|
|
|
|
|
+ msg = if (slot?.isCharging == isCharge) "success" else "fail"
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -124,8 +137,23 @@ class DeviceKeySlot(frame: Frame) : Device(frame) {
|
|
|
* @param isLock 是否锁住
|
|
* @param isLock 是否锁住
|
|
|
* @param isCharge 是否充电
|
|
* @param isCharge 是否充电
|
|
|
*/
|
|
*/
|
|
|
- fun ctrlSlotLockAndCharge(ch: Int, isLock: Boolean, isCharge: Boolean, done: (rsp: Frame) -> Unit = {}) {
|
|
|
|
|
- (frame.newFrame().apply { cmd = frame.cmd }.buildCtrlKeySlotLockAndCharge(ch, isLock, isCharge)).writeWithResponse(done)
|
|
|
|
|
|
|
+ fun ctrlSlotLockAndCharge(ch: Int, isLock: Boolean, isCharge: Boolean, done: (CtrlResponse) -> Unit = {}) {
|
|
|
|
|
+ (frame.newFrame().apply { cmd = frame.cmd }
|
|
|
|
|
+ .buildCtrlKeySlotLockAndCharge(ch, isLock, isCharge))
|
|
|
|
|
+ .writeWithResponse {
|
|
|
|
|
+ if (ch < 0) {
|
|
|
|
|
+ val status = (deviceStatus as DeviceStatusKeySlot).slotList
|
|
|
|
|
+ // 全部控制
|
|
|
|
|
+ val isOk = status.filter { it.isSlotLock == isLock && it.isCharging == isCharge }.size == status.size
|
|
|
|
|
+ done(CtrlResponse(code = if (isOk) 200 else 500, msg = if (isOk) "success" else "fail"))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 单个控制
|
|
|
|
|
+ val isOk = (deviceStatus as DeviceStatusKeySlot).slotList.find {
|
|
|
|
|
+ it.ch == ch && it.isCharging == isCharge && it.isSlotLock == isLock
|
|
|
|
|
+ } != null
|
|
|
|
|
+ done(CtrlResponse(code = if (isOk) 200 else 500, msg = if (isOk) "success" else "fail"))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|