فهرست منبع

refactor(更新) :
- 充电更新

周文健 5 ماه پیش
والد
کامیت
23c8bd2cbe

+ 4 - 0
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -1158,6 +1158,10 @@ object BusinessManager {
                     ModBusController.controlKeyCharge(true, bleBean.bleDevice.mac) {
                         LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 开始充电")
                     }
+                } else {
+                    ModBusController.controlKeyCharge(false, bleBean.bleDevice.mac) {
+                        LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 关闭充电")
+                    }
                 }
             }
         }

+ 4 - 4
app/src/main/java/com/grkj/iscs/modbus/ModBusCMDHelper.kt

@@ -112,8 +112,8 @@ object ModBusCMDHelper {
             byteArrayOf(
                 0x00,
                 0x11,
-                if (index == 1) 0b00010000.toByte() else 0b0000001.toByte(),
-                if (isOpen) 0x00 else 0xFF.toByte()
+                (if (index == 1) 0b00010000 else 0b0000001).toByte(),
+                (if (isOpen) 0x00 else 0xFF).toByte()
             )
         )
     }
@@ -130,8 +130,8 @@ object ModBusCMDHelper {
             byteArrayOf(
                 0x00,
                 0x11,
-                if (index == 1) 0b00100000.toByte() else 0b0000010.toByte(),
-                if (isOpen) 0xFF.toByte() else 0x00.toByte()
+                (if (index == 1) 0b00100000 else 0b00000010).toByte(),
+                (if (isOpen) 0xFF else 0x00).toByte()
             )
         )
     }

+ 29 - 16
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -22,6 +22,8 @@ import com.grkj.iscs.util.Executor
 import com.grkj.iscs.util.NetApi
 import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.log.LogUtil
+import com.sik.sikcore.thread.ThreadUtils
+import kotlinx.coroutines.delay
 import java.util.concurrent.atomic.AtomicInteger
 import java.util.stream.Collectors
 import kotlin.coroutines.resume
@@ -217,21 +219,25 @@ object ModBusController {
                             // 更新rfid
                             updateKeyRfid(dockBean.addr, isLeft, rfid)
                             // 蓝牙准备操作
-                            NetApi.getKeyInfo(rfid) {
-                                LogUtil.i("getKeyInfo : $rfid - ${it?.macAddress}")
-                                updateKeyNewHardware(dockBean.addr, isLeft, it == null)
-                                if (it != null && !it.macAddress.isNullOrEmpty()) {
+                            NetApi.getKeyInfo(rfid) { keyInfo ->
+                                LogUtil.i("getKeyInfo : $rfid - ${keyInfo?.macAddress}")
+                                updateKeyNewHardware(dockBean.addr, isLeft, keyInfo == null)
+                                if (keyInfo != null && !keyInfo.macAddress.isNullOrEmpty()) {
                                     // 更新mac
-                                    updateKeyMac(dockBean.addr, key.isLeft, it.macAddress)
-                                    BusinessManager.registerConnectListener(
-                                        it.macAddress
-                                    ) { isDone, bleBean ->
-                                        if (isDone && bleBean?.bleDevice != null) {
-                                            Executor.delayOnMain(500) {
-                                                BusinessManager.getCurrentStatus(
-                                                    3, bleBean.bleDevice
-                                                )
-                                                BusinessManager.getBatteryPower(bleBean.bleDevice)
+                                    updateKeyMac(dockBean.addr, key.isLeft, keyInfo.macAddress)
+                                    controlKeyCharge(true, keyInfo.macAddress) {
+                                        ThreadUtils.runOnIODelayed(500) {
+                                            BusinessManager.registerConnectListener(
+                                                keyInfo.macAddress
+                                            ) { isDone, bleBean ->
+                                                if (isDone && bleBean?.bleDevice != null) {
+                                                    Executor.delayOnMain(500) {
+                                                        BusinessManager.getCurrentStatus(
+                                                            3, bleBean.bleDevice
+                                                        )
+                                                        BusinessManager.getBatteryPower(bleBean.bleDevice)
+                                                    }
+                                                }
                                             }
                                         }
                                     }
@@ -717,7 +723,9 @@ object ModBusController {
     ) {
         slaveAddress?.let {
             ModBusCMDHelper.generateKeyBuckleChargeCmd(isOpen, if (isLeft) 0 else 1)?.let { cmd ->
+                LogUtil.i("钥匙充电:${isOpen},${isLeft},${slaveAddress},${cmd.data.toHexStrings()}")
                 modBusManager?.sendTo(it, cmd) { res ->
+                    LogUtil.i("钥匙充电接收:${isOpen},${isLeft},${slaveAddress},${res.toHexStrings()}")
                     done?.invoke(res)
                 }
             }
@@ -994,8 +1002,13 @@ object ModBusController {
         for (kb in keyList) {
             val mac = kb.mac ?: continue
             val found = suspendCoroutine<DockBean.KeyBean?> { cont ->
-                BusinessManager.registerConnectListener(mac) { isDone, _ ->
-                    if (isDone) cont.resume(kb)
+                controlKeyCharge(true, mac) {
+                    ///开启充电后等待500ms尝试连接
+                    ThreadUtils.runOnIODelayed(500) {
+                        BusinessManager.registerConnectListener(mac) { isDone, _ ->
+                            if (isDone) cont.resume(kb)
+                        }
+                    }
                 }
             }
             if (found != null) {

+ 4 - 0
app/src/main/java/com/grkj/iscs/view/activity/test/ModbusActivity.kt

@@ -110,6 +110,10 @@ class ModbusActivity : BaseMvpActivity<IModbusView, ModBusPresenter, ActivityMod
                 LogUtil.i("开左钥匙卡扣 : ${it.toHexStrings()}")
                 LogUtil.i("____________________________________")
             }
+            ModBusController.controlKeyCharge(isOpen = true, true, mBinding?.slaveIdx?.text.toString().toByte()) {
+                LogUtil.i("左钥匙卡扣充电 : ${it.toHexStrings()}")
+                LogUtil.i("____________________________________")
+            }
         }
 
         mBinding?.closeLeftKeyBuckle?.setOnClickListener {

+ 28 - 16
app/src/main/java/com/grkj/iscs/view/presenter/HomePresenter.kt

@@ -4,12 +4,15 @@ import com.grkj.iscs.BusinessManager
 import com.grkj.iscs.MyApplication
 import com.grkj.iscs.R
 import com.grkj.iscs.extentions.serialNo
+import com.grkj.iscs.modbus.ModBusController
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
 import com.grkj.iscs.util.Executor
 import com.grkj.iscs.util.NetApi
 import com.grkj.iscs.util.SPUtils
+import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BasePresenter
 import com.grkj.iscs.view.iview.IHomeView
+import com.sik.sikcore.thread.ThreadUtils
 
 class HomePresenter : BasePresenter<IHomeView>() {
 
@@ -23,23 +26,32 @@ class HomePresenter : BasePresenter<IHomeView>() {
                     dockBean.getKeyList().forEach { keyBean ->
                         if (keyBean.isExist) {
                             Executor.repeatOnMain({
-                                keyBean.mac?.let {
+                                keyBean.mac?.let { mac ->
                                     BusinessManager.sendLoadingEventMsg(mContext?.getString(R.string.loading_msg_return_key_start))
-                                    BusinessManager.registerConnectListener(
-                                        it
-                                    ) { isDone, bleBean ->
-                                        if (isDone && bleBean != null) {
-                                            Executor.delayOnMain(300) {
-                                                BusinessManager.sendLoadingEventMsg(
-                                                    mContext?.getString(
-                                                        R.string.loading_msg_get_ticket_status_start
-                                                    )
-                                                )
-                                                BusinessManager.getCurrentStatus(
-                                                    4,
-                                                    bleBean.bleDevice
-                                                )
-                                                BusinessManager.getBatteryPower(bleBean.bleDevice)
+                                    ModBusController.controlKeyCharge(
+                                        true,
+                                        keyBean.isLeft,
+                                        dockBean.addr
+                                    ) {
+                                        LogUtil.i("钥匙开启充电:${mac}")
+                                        ThreadUtils.runOnMainDelayed(500) {
+                                            BusinessManager.registerConnectListener(
+                                                mac
+                                            ) { isDone, bleBean ->
+                                                if (isDone && bleBean != null) {
+                                                    Executor.delayOnMain(300) {
+                                                        BusinessManager.sendLoadingEventMsg(
+                                                            mContext?.getString(
+                                                                R.string.loading_msg_get_ticket_status_start
+                                                            )
+                                                        )
+                                                        BusinessManager.getCurrentStatus(
+                                                            4,
+                                                            bleBean.bleDevice
+                                                        )
+                                                        BusinessManager.getBatteryPower(bleBean.bleDevice)
+                                                    }
+                                                }
                                             }
                                         }
                                     }