|
|
@@ -693,7 +693,7 @@ object BusinessManager {
|
|
|
override fun onCharacteristicChanged(data: ByteArray?) {
|
|
|
LogUtil.i("onCharacteristicChanged : ${data?.toHexStrings()}")
|
|
|
data?.let { itData ->
|
|
|
- handleRsp(it, itData, isNeedLoading)
|
|
|
+ handleRsp(it, itData, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -714,7 +714,6 @@ object BusinessManager {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "token获取成功", null)))
|
|
|
LogUtil.i("getToken success : ${bleBean.bleDevice.mac}")
|
|
|
- prepareDoneCallBack?.invoke(true, bleBean)
|
|
|
}
|
|
|
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
@@ -908,7 +907,7 @@ object BusinessManager {
|
|
|
return jsonStr
|
|
|
}
|
|
|
|
|
|
- fun handleRsp(bleBean: BleBean, byteArray: ByteArray, isNeedLoading: Boolean = false) {
|
|
|
+ fun handleRsp(bleBean: BleBean, byteArray: ByteArray, isNeedLoading: Boolean = false, prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?) {
|
|
|
// TODO Token校验
|
|
|
// val len = byteArray[2].toInt()
|
|
|
// val token = byteArray.copyOfRange(len + 7, len + 11)
|
|
|
@@ -919,7 +918,11 @@ object BusinessManager {
|
|
|
// }
|
|
|
when {
|
|
|
// 获取令牌
|
|
|
- byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(bleBean.bleDevice, byteArray)
|
|
|
+ byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(bleBean.bleDevice, byteArray) { isSuccess ->
|
|
|
+ if (isSuccess) {
|
|
|
+ prepareDoneCallBack?.invoke(true, bleBean)
|
|
|
+ }
|
|
|
+ }
|
|
|
// 工作模式切换
|
|
|
byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> {
|
|
|
handleSwitchModeResult(byteArray, isNeedLoading) { res, job ->
|
|
|
@@ -987,7 +990,7 @@ object BusinessManager {
|
|
|
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.i("getCurrentStatus fail : ${bleDevice.mac}")
|
|
|
- Executor.delayOnMain(500) {
|
|
|
+ Executor.delayOnMain(1000) {
|
|
|
getCurrentStatus(from, bleDevice)
|
|
|
}
|
|
|
}
|