|
|
@@ -172,6 +172,11 @@ object BusinessManager {
|
|
|
keyBean.isLeft,
|
|
|
dock?.addr
|
|
|
)
|
|
|
+ ModBusController.controlKeyCharge(
|
|
|
+ false,
|
|
|
+ keyBean.isLeft,
|
|
|
+ dock?.addr
|
|
|
+ )
|
|
|
ModBusController.updateKeyReadyStatus(
|
|
|
it.data.bleBean.bleDevice.mac,
|
|
|
false,
|
|
|
@@ -314,6 +319,11 @@ object BusinessManager {
|
|
|
|
|
|
/**
|
|
|
* 硬件状态
|
|
|
+ * 1、检测到有钥匙
|
|
|
+ * 2、上锁
|
|
|
+ * 3、开启充电
|
|
|
+ * 4、蓝牙连接
|
|
|
+ * 5、蓝牙数据通讯
|
|
|
*/
|
|
|
private fun deviceStatusHandle(res: Any) {
|
|
|
LogUtil.i("硬件状态:${(res as List<ByteArray>).map { it.toHexStrings() }}")
|
|
|
@@ -339,38 +349,44 @@ object BusinessManager {
|
|
|
DOCK_TYPE_KEY -> {
|
|
|
dockBean.getKeyList().forEach { keyBean ->
|
|
|
if (keyBean.isExist) {
|
|
|
-// sendLoadingEventMsg(CommonUtils.getStr(R.string.ble_connecting))
|
|
|
- // 放回钥匙,读取rfid
|
|
|
- ModBusController.readKeyRfid(
|
|
|
- dockBean.addr,
|
|
|
- if (keyBean.isLeft) 0 else 1
|
|
|
- ) { isLeft, res ->
|
|
|
- if (res.size < 11) {
|
|
|
- LogUtil.e("Key rfid error")
|
|
|
- return@readKeyRfid
|
|
|
- }
|
|
|
- val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
- .removeLeadingZeros()
|
|
|
- ModBusController.updateKeyRfid(
|
|
|
+ // 放回钥匙,上锁
|
|
|
+ ModBusController.controlKeyBuckle(
|
|
|
+ false,
|
|
|
+ keyBean.isLeft,
|
|
|
+ dockBean.addr
|
|
|
+ ) {
|
|
|
+ // 放回钥匙,读取rfid
|
|
|
+ ModBusController.readKeyRfid(
|
|
|
dockBean.addr,
|
|
|
- keyBean.isLeft,
|
|
|
- rfid
|
|
|
- )
|
|
|
- NetApi.getKeyInfo(rfid) {
|
|
|
- if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
- ModBusController.updateKeyMac(
|
|
|
- dockBean.addr,
|
|
|
- keyBean.isLeft,
|
|
|
- it.macAddress
|
|
|
- )
|
|
|
- ModBusController.updateKeyReadyStatus(
|
|
|
- it.macAddress,
|
|
|
- false,
|
|
|
- 5
|
|
|
- )
|
|
|
- } else {
|
|
|
- LogUtil.e("Get key info fail : $rfid")
|
|
|
- ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
+ if (keyBean.isLeft) 0 else 1
|
|
|
+ ) { isLeft, res ->
|
|
|
+ if (res.size < 11) {
|
|
|
+ LogUtil.e("Key rfid error")
|
|
|
+ return@readKeyRfid
|
|
|
+ }
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
+ .removeLeadingZeros()
|
|
|
+ ModBusController.updateKeyRfid(
|
|
|
+ dockBean.addr,
|
|
|
+ keyBean.isLeft,
|
|
|
+ rfid
|
|
|
+ )
|
|
|
+ NetApi.getKeyInfo(rfid) {
|
|
|
+ if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
+ ModBusController.updateKeyMac(
|
|
|
+ dockBean.addr,
|
|
|
+ keyBean.isLeft,
|
|
|
+ it.macAddress
|
|
|
+ )
|
|
|
+ ModBusController.updateKeyReadyStatus(
|
|
|
+ it.macAddress,
|
|
|
+ false,
|
|
|
+ 5
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ LogUtil.e("Get key info fail : $rfid")
|
|
|
+ ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1043,6 +1059,15 @@ object BusinessManager {
|
|
|
byteArray.startsWith(BleConst.RSP_WORK_TICKET_RESULT) && byteArray[3] == 0x02.toByte() -> handleTicketStatus(
|
|
|
bleBean.bleDevice, byteArray, isNeedLoading
|
|
|
)
|
|
|
+
|
|
|
+ byteArray.startsWith(BleConst.RSP_POWER_STATUS) -> {
|
|
|
+ val power = byteArray[4].toInt()
|
|
|
+ if (power < 50) {//如果电量小于50就打开仓位充电
|
|
|
+ ModBusController.controlKeyCharge(true, bleBean.bleDevice.mac) {
|
|
|
+ LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 开始充电")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1172,6 +1197,28 @@ object BusinessManager {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取电池电量
|
|
|
+ */
|
|
|
+ fun getBatteryPower(bleDevice: BleDevice) {
|
|
|
+ LogUtil.i("获取电池电量:${bleDevice.mac}")
|
|
|
+ BleCmdManager.getPower(bleDevice.mac, object : CustomBleWriteCallback() {
|
|
|
+ override fun onWriteSuccess(p0: Int, p1: Int, p2: ByteArray?) {
|
|
|
+ LogUtil.i("发送获取电池电量命令成功:${bleDevice.mac}")
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onWriteFailure(p0: BleException?) {
|
|
|
+ ThreadUtils.runOnIODelayed(500) {
|
|
|
+ LogUtil.i("发送获取电池电量命令失败:${bleDevice.mac}")
|
|
|
+ getBatteryPower(bleDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切换工作模式
|
|
|
+ */
|
|
|
private fun switchWorkMode(bleDevice: BleDevice, isNeedLoading: Boolean = false) {
|
|
|
LogUtil.i("switchWorkMode - ${bleDevice.mac}")
|
|
|
BleCmdManager.switchMode(STATUS_WORK, bleDevice, object : CustomBleWriteCallback() {
|