|
@@ -93,17 +93,32 @@ object CanCommands {
|
|
|
object Common {
|
|
object Common {
|
|
|
/** 版本 (R) → 0x6003/0x00, 4B: HW主,HW子,SW主,SW子 */
|
|
/** 版本 (R) → 0x6003/0x00, 4B: HW主,HW子,SW主,SW子 */
|
|
|
fun getDeviceVersion(nodeId: Int): SdoRequest.Read =
|
|
fun getDeviceVersion(nodeId: Int): SdoRequest.Read =
|
|
|
- SdoRequest.Read(nodeId, Command.VERSION, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.VERSION,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
/** 大多数设备复用的状态寄存器 (R) → 0x6010/0x00, 2B */
|
|
/** 大多数设备复用的状态寄存器 (R) → 0x6010/0x00, 2B */
|
|
|
fun getStatus(nodeId: Int): SdoRequest.Read =
|
|
fun getStatus(nodeId: Int): SdoRequest.Read =
|
|
|
- SdoRequest.Read(nodeId, Command.STATUS, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.STATUS,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取设备类型
|
|
* 获取设备类型
|
|
|
*/
|
|
*/
|
|
|
fun getDeviceType(nodeId: Int): SdoRequest.Read =
|
|
fun getDeviceType(nodeId: Int): SdoRequest.Read =
|
|
|
- SdoRequest.Read(nodeId, Command.DEVICE_TYPE, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.DEVICE_TYPE,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -118,14 +133,26 @@ object CanCommands {
|
|
|
|
|
|
|
|
/** 控制/状态 (R/W) 0x6011/0x00, 2B:写仅置相关位,其余写0;读回含工作位 */
|
|
/** 控制/状态 (R/W) 0x6011/0x00, 2B:写仅置相关位,其余写0;读回含工作位 */
|
|
|
fun readControlReg(): SdoRequest.Read =
|
|
fun readControlReg(): SdoRequest.Read =
|
|
|
- SdoRequest.Read(nodeId, Command.CONTROL_REG, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.CONTROL_REG,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
/** 设置左右卡扣(bit0=左卡扣,bit4=右卡扣) */
|
|
/** 设置左右卡扣(bit0=左卡扣,bit4=右卡扣) */
|
|
|
fun setLatch(left: Boolean? = null, right: Boolean? = null): SdoRequest.Write {
|
|
fun setLatch(left: Boolean? = null, right: Boolean? = null): SdoRequest.Write {
|
|
|
var v = 0
|
|
var v = 0
|
|
|
if (left != null) v = v or ((if (left) 1 else 0) shl 0)
|
|
if (left != null) v = v or ((if (left) 1 else 0) shl 0)
|
|
|
if (right != null) v = v or ((if (right) 1 else 0) shl 4)
|
|
if (right != null) v = v or ((if (right) 1 else 0) shl 4)
|
|
|
- return SdoRequest.Write(nodeId, Command.CONTROL_REG, 0x00, shortLE(v, 0b0001_0001), 2, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ return SdoRequest.Write(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.CONTROL_REG,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ shortLE(v, 0b0001_0001),
|
|
|
|
|
+ 2,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 设置左右充电(bit1=左充电,bit5=右充电) */
|
|
/** 设置左右充电(bit1=左充电,bit5=右充电) */
|
|
@@ -133,7 +160,14 @@ object CanCommands {
|
|
|
var v = 0
|
|
var v = 0
|
|
|
if (leftOn != null) v = v or ((if (leftOn) 1 else 0) shl 1)
|
|
if (leftOn != null) v = v or ((if (leftOn) 1 else 0) shl 1)
|
|
|
if (rightOn != null) v = v or ((if (rightOn) 1 else 0) shl 5)
|
|
if (rightOn != null) v = v or ((if (rightOn) 1 else 0) shl 5)
|
|
|
- return SdoRequest.Write(nodeId, Command.CONTROL_REG, 0x00, shortLE(v, 0b0010_0010), 2, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ return SdoRequest.Write(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.CONTROL_REG,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ shortLE(v, 0b0010_0010),
|
|
|
|
|
+ 2,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 单侧卡扣语法糖:keySlotId: 0左/1右;status: 0解锁/1锁住 */
|
|
/** 单侧卡扣语法糖:keySlotId: 0左/1右;status: 0解锁/1锁住 */
|
|
@@ -151,15 +185,33 @@ object CanCommands {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 左/右 RFID (R) 4B 小端(常见地址) */
|
|
/** 左/右 RFID (R) 4B 小端(常见地址) */
|
|
|
- fun getLeftRfid(): SdoRequest.Read = SdoRequest.Read(nodeId, Command.RFID, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
- fun getRightRfid(): SdoRequest.Read = SdoRequest.Read(nodeId, Command.RIGHT_KEY_RFID, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ fun getLeftRfid(): SdoRequest.Read = SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.RFID,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ fun getRightRfid(): SdoRequest.Read = SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.RIGHT_KEY_RFID,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
// ---- FiveLock / KeyCabinet(常见 1..5 位同构写法,寄存器通常与 0x6011 兼容) ----
|
|
// ---- FiveLock / KeyCabinet(常见 1..5 位同构写法,寄存器通常与 0x6011 兼容) ----
|
|
|
|
|
|
|
|
/** 一次写入 5 位控制(低5位有效),适配 5路/柜体同构 */
|
|
/** 一次写入 5 位控制(低5位有效),适配 5路/柜体同构 */
|
|
|
fun setLatchBits_1to5(bits01to05: Int): SdoRequest.Write {
|
|
fun setLatchBits_1to5(bits01to05: Int): SdoRequest.Write {
|
|
|
val v = bits01to05 and 0b1_1111
|
|
val v = bits01to05 and 0b1_1111
|
|
|
- return SdoRequest.Write(nodeId, Command.CONTROL_REG, 0x00, shortLE(v, 0b1_1111), 2, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ return SdoRequest.Write(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.CONTROL_REG,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ shortLE(v, 0b1_1111),
|
|
|
|
|
+ 2,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -167,7 +219,14 @@ object CanCommands {
|
|
|
*/
|
|
*/
|
|
|
fun setLatchBits_1to5(target: Int, isOpen: Boolean): SdoRequest.Write {
|
|
fun setLatchBits_1to5(target: Int, isOpen: Boolean): SdoRequest.Write {
|
|
|
val v = if (isOpen) 0b0_0000 else 0b1_1111
|
|
val v = if (isOpen) 0b0_0000 else 0b1_1111
|
|
|
- return SdoRequest.Write(nodeId, Command.CONTROL_REG, 0x00, shortLE(v, target), 2, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ return SdoRequest.Write(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.CONTROL_REG,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ shortLE(v, target),
|
|
|
|
|
+ 2,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 单位控制(1..5) */
|
|
/** 单位控制(1..5) */
|
|
@@ -183,18 +242,43 @@ object CanCommands {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 开门控制 */
|
|
|
|
|
+ fun controlDoorOpen(left: Boolean?, right: Boolean?): SdoRequest.Write {
|
|
|
|
|
+ var v = 0
|
|
|
|
|
+ if (left != null) v = v or (1 shl 0)
|
|
|
|
|
+ if (right != null) v = v or (1 shl 4)
|
|
|
|
|
+ return SdoRequest.Write(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.CONTROL_REG,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ shortLE(v, v),
|
|
|
|
|
+ 2
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/** 1..5 位 RFID 常见映射:0x6020..0x6024 */
|
|
/** 1..5 位 RFID 常见映射:0x6020..0x6024 */
|
|
|
fun getSlotRfid_1to5(slotIndex1to5: Int): SdoRequest.Read {
|
|
fun getSlotRfid_1to5(slotIndex1to5: Int): SdoRequest.Read {
|
|
|
require(slotIndex1to5 in 1..5) { "slotIndex must be 1..5" }
|
|
require(slotIndex1to5 in 1..5) { "slotIndex must be 1..5" }
|
|
|
- return SdoRequest.Read(nodeId, Command.RFID, 0x00 + (slotIndex1to5 - 1), timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ return SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.RFID,
|
|
|
|
|
+ 0x00 + (slotIndex1to5 - 1),
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ---- MaterialCabinet(RGB/温湿度扩展) ----
|
|
// ---- MaterialCabinet(RGB/温湿度扩展) ----
|
|
|
|
|
|
|
|
/** RGB 状态灯 (R/W) 0x6016/0x00, 4B: B[0..7],G[8..15],R[16..23], 模式[24..26], 时间[27..29], 单位[30], 锁定[31] */
|
|
/** RGB 状态灯 (R/W) 0x6016/0x00, 4B: B[0..7],G[8..15],R[16..23], 模式[24..26], 时间[27..29], 单位[30], 锁定[31] */
|
|
|
- fun getRgb(): SdoRequest.Read = SdoRequest.Read(nodeId, Command.LED_STRIP_CONTROL, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ fun getRgb(): SdoRequest.Read = SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.LED_STRIP_CONTROL,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
fun setRgb(
|
|
fun setRgb(
|
|
|
|
|
+ leftLed: Boolean,
|
|
|
r: Int, g: Int, b: Int, // 0..255
|
|
r: Int, g: Int, b: Int, // 0..255
|
|
|
mode: Int, // 0关/1常亮/2闪烁/3呼吸/4流水
|
|
mode: Int, // 0关/1常亮/2闪烁/3呼吸/4流水
|
|
|
timeStep: Int, // 0..7(实际=+1)
|
|
timeStep: Int, // 0..7(实际=+1)
|
|
@@ -214,12 +298,30 @@ object CanCommands {
|
|
|
v = v or ((tt and 0x07) shl 27)
|
|
v = v or ((tt and 0x07) shl 27)
|
|
|
v = v or ((if (secondsUnit) 1 else 0) shl 30)
|
|
v = v or ((if (secondsUnit) 1 else 0) shl 30)
|
|
|
v = v or ((if (lockControl) 1 else 0) shl 31)
|
|
v = v or ((if (lockControl) 1 else 0) shl 31)
|
|
|
- return SdoRequest.Write(nodeId, Command.LED_STRIP_CONTROL, 0x00, intLE(v), 4, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ return SdoRequest.Write(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.LED_STRIP_CONTROL,
|
|
|
|
|
+ if (leftLed) 0x00 else 0x01,
|
|
|
|
|
+ intLE(v),
|
|
|
|
|
+ 4,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 温湿度(常见扩展) */
|
|
/** 温湿度(常见扩展) */
|
|
|
- fun getTemperature(): SdoRequest.Read = SdoRequest.Read(nodeId, Command.TEMPERATURE, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
- fun getHumidity(): SdoRequest.Read = SdoRequest.Read(nodeId, Command.HUMIDITY, 0x00, timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong())
|
|
|
|
|
|
|
+ fun getTemperature(): SdoRequest.Read = SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.TEMPERATURE,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ fun getHumidity(): SdoRequest.Read = SdoRequest.Read(
|
|
|
|
|
+ nodeId,
|
|
|
|
|
+ Command.HUMIDITY,
|
|
|
|
|
+ 0x00,
|
|
|
|
|
+ timeoutMs = CustomCanConfig.instance.readTimeoutMs.toLong()
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
// ---- 通用状态 ----
|
|
// ---- 通用状态 ----
|
|
|
fun getStatus(): SdoRequest.Read = Common.getStatus(nodeId)
|
|
fun getStatus(): SdoRequest.Read = Common.getStatus(nodeId)
|