|
|
@@ -36,6 +36,7 @@ import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
import com.grkj.iscs.model.bo.WorkTicketGetBO
|
|
|
import com.grkj.iscs.model.bo.WorkTicketSendBO
|
|
|
import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
|
|
|
+import com.grkj.iscs.model.eventmsg.LoadingMsg
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEvent
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
|
|
|
import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
|
|
|
@@ -95,7 +96,10 @@ object BusinessManager {
|
|
|
mEventBus.observeForever {
|
|
|
when (it.code) {
|
|
|
MSG_EVENT_LOADING -> {
|
|
|
-
|
|
|
+ Executor.runOnMain {
|
|
|
+ val loadingMsg = it.data as LoadingMsg
|
|
|
+ (ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(loadingMsg.isShow, loadingMsg.loadingText)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -289,9 +293,7 @@ object BusinessManager {
|
|
|
dlg.setType(TipDialog.TYPE_CONFIRM)
|
|
|
dlg.setConfirmListener {
|
|
|
ModBusController.controlKeyBuckle(false, isLeft, slaveAddress)
|
|
|
- getTicketStatusBusiness(mac, ActivityUtils.currentActivity() as BaseActivity<*>) { b, s, rst ->
|
|
|
- (ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(b, s)
|
|
|
- }
|
|
|
+ getTicketStatusBusiness(mac, true)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -437,7 +439,7 @@ object BusinessManager {
|
|
|
}
|
|
|
isPreparing = true
|
|
|
val listener = connectListeners[0]
|
|
|
- prepareBle(listener.mac, ActivityUtils.currentActivity() as BaseActivity<*>, null) { isDone, bleBean ->
|
|
|
+ prepareBle(listener.mac, ActivityUtils.currentActivity() as BaseActivity<*>, false) { isDone, bleBean ->
|
|
|
Executor.runOnMain {
|
|
|
isPreparing = false
|
|
|
if (!isDone) {
|
|
|
@@ -466,31 +468,31 @@ object BusinessManager {
|
|
|
private fun prepareBle(
|
|
|
mac: String,
|
|
|
activity: AppCompatActivity,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?
|
|
|
) {
|
|
|
Executor.runOnMain {
|
|
|
CommonUtils.checkBlePermission(activity) {
|
|
|
- doScanBle(mac, loadingCallBack, prepareDoneCallBack)
|
|
|
+ doScanBle(mac, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@AfterPermissionGranted(PERMISSION_REQUEST_CODE)
|
|
|
- private fun doScanBle(mac: String, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?, prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?) {
|
|
|
+ private fun doScanBle(mac: String, isNeedLoading: Boolean = false, prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?) {
|
|
|
LogUtil.i("doScanBle:$mac")
|
|
|
- loadingCallBack?.invoke(true, "正在扫描设备...", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "正在扫描设备...", null)))
|
|
|
BleUtil.instance?.scan(object : CustomBleScanCallback() {
|
|
|
override fun onPrompt(promptStr: String?) {
|
|
|
// 蓝牙未启动重试
|
|
|
BleManager.getInstance().enableBluetooth()
|
|
|
- doScanBle(mac, loadingCallBack, prepareDoneCallBack)
|
|
|
+ doScanBle(mac, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
|
|
|
override fun onScanStarted(success: Boolean) {
|
|
|
LogUtil.i("onScanStarted:${success}")
|
|
|
if (!success) {
|
|
|
- loadingCallBack?.invoke(false, null, null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
prepareDoneCallBack?.invoke(false, null)
|
|
|
}
|
|
|
}
|
|
|
@@ -499,14 +501,14 @@ object BusinessManager {
|
|
|
LogUtil.i("onScanning:${bleDevice?.mac}")
|
|
|
bleDevice?.let {
|
|
|
if (connectListeners.any { itData -> itData.mac == bleDevice.mac }) {
|
|
|
- doConnect(it, loadingCallBack, prepareDoneCallBack)
|
|
|
+ doConnect(it, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onScanFinished(scanResultList: MutableList<BleDevice>?) {
|
|
|
LogUtil.i("onScanFinished: $mac")
|
|
|
- loadingCallBack?.invoke(false, null, null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
if (connectListeners.any { it.mac == mac }) {
|
|
|
LogUtil.w("$mac is not scanned")
|
|
|
prepareDoneCallBack?.invoke(false, null)
|
|
|
@@ -520,27 +522,27 @@ object BusinessManager {
|
|
|
*/
|
|
|
private fun doConnect(
|
|
|
bleDevice: BleDevice,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?
|
|
|
) {
|
|
|
- loadingCallBack?.invoke(true, CommonUtils.getStr(R.string.ble_connecting), null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, CommonUtils.getStr(R.string.ble_connecting), null)))
|
|
|
BleManager.getInstance().disconnect(bleDevice)
|
|
|
BleUtil.instance?.connectBySelect(bleDevice,
|
|
|
object : CustomBleGattCallback() {
|
|
|
override fun onPrompt(promptStr: String?) {
|
|
|
- loadingCallBack?.invoke(false, promptStr, false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, promptStr, null)))
|
|
|
}
|
|
|
|
|
|
override fun onStartConnect() {}
|
|
|
|
|
|
override fun onConnectFail(bleDevice: BleDevice?, exception: BleException?) {
|
|
|
- loadingCallBack?.invoke(false, CommonUtils.getStr(R.string.ble_connect_fail), false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, CommonUtils.getStr(R.string.ble_connect_fail), false)))
|
|
|
LogUtil.e("onConnectFail : $bleDevice - ${exception?.description}")
|
|
|
prepareDoneCallBack?.invoke(false, null)
|
|
|
}
|
|
|
|
|
|
override fun onConnectSuccess(bleDevice: BleDevice?, gatt: BluetoothGatt?, status: Int) {
|
|
|
- loadingCallBack?.invoke(false, null, null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
LogUtil.i("onConnectSuccess : ${bleDevice?.mac}")
|
|
|
bleDevice?.let {
|
|
|
val bleBean = BleBean(it)
|
|
|
@@ -551,13 +553,13 @@ object BusinessManager {
|
|
|
}
|
|
|
// 监听
|
|
|
Executor.delayOnMain(500) {
|
|
|
- indicate(bleBean, loadingCallBack, prepareDoneCallBack)
|
|
|
+ indicate(bleBean, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onDisConnected(isActiveDisConnected: Boolean, device: BleDevice?, gatt: BluetoothGatt?, status: Int) {
|
|
|
- loadingCallBack?.invoke(false, null, false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
|
|
|
LogUtil.i("onDisConnected : ${device?.mac} - $isActiveDisConnected")
|
|
|
getBleDeviceByMac(device?.mac)?.let {
|
|
|
deviceList.remove(it)
|
|
|
@@ -580,10 +582,10 @@ object BusinessManager {
|
|
|
*/
|
|
|
private fun indicate(
|
|
|
bleBean: BleBean?,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?
|
|
|
) {
|
|
|
- loadingCallBack?.invoke(true, "开始监听...", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始监听...", null)))
|
|
|
bleBean?.let {
|
|
|
BleUtil.instance?.indicate(it.bleDevice, indicateCallback = object : CustomBleIndicateCallback() {
|
|
|
override fun onPrompt(promptStr: String?) {
|
|
|
@@ -602,11 +604,11 @@ object BusinessManager {
|
|
|
LogUtil.i("onIndicateSuccess")
|
|
|
// val testStr = "{\"cardNo\":\"80A8C0F4EA\",\"password\":\"12345678\",\"effectiveTime\":24,\"data\":[{\"taskCode\":\"202401020001\",\"taskId\":\"71b49baa49b343bc84d7e6b829ac1bdc\",\"codeId\":1,\"dataList\":[{\"dataId\":1,\"equipRfidNo\":\"049648B2E31690\",\"infoRfidNo\":\"04E3BCCA201290\",\"target\":1},{\"dataId\":2,\"equipRfidNo\":\"0405982414C563\",\"target\":0,\"prevId\":1}]},{\"taskCode\":\"202401020002\",\"taskId\":\"145b5a4cc38c41e19943f4c8b48d12b0\",\"codeId\":2,\"dataList\":[{\"dataId\":1,\"equipRfidNo\":\"045460F7F4F438\",\"infoRfidNo\":\"04BC6584C65009\",\"target\":1},{\"dataId\":2,\"equipRfidNo\":\"042B99E449E795\",\"target\":0,\"prevId\":1},{\"dataId\":3,\"equipRfidNo\":\"04A312EE848B62\",\"infoRfidNo\":\"04220E86831289\",\"target\":1,\"prevId\":2}]}],\"lockList\":[{\"lockId\":\"1\",\"rfid\":\"040E21443010E9\"},{\"lockId\":\"2\",\"rfid\":\"0457505E5861C2\"}]}"
|
|
|
// sendTicket(testStr, it.bleDevice, loadingCallBack)
|
|
|
- getToken(bleBean, loadingCallBack, prepareDoneCallBack)
|
|
|
+ getToken(bleBean, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
|
|
|
override fun onIndicateFailure(exception: BleException?) {
|
|
|
- loadingCallBack?.invoke(false, null, false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
|
|
|
LogUtil.e("onIndicateFailure : ${bleBean.bleDevice.mac} - ${exception?.description}")
|
|
|
prepareDoneCallBack?.invoke(false, null)
|
|
|
}
|
|
|
@@ -614,7 +616,7 @@ object BusinessManager {
|
|
|
override fun onCharacteristicChanged(data: ByteArray?) {
|
|
|
LogUtil.i("onCharacteristicChanged : ${data?.toHexStrings()}")
|
|
|
data?.let { itData ->
|
|
|
- handleRsp(it, itData, loadingCallBack)
|
|
|
+ handleRsp(it, itData, isNeedLoading)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -626,20 +628,20 @@ object BusinessManager {
|
|
|
*/
|
|
|
private fun getToken(
|
|
|
bleBean: BleBean?,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
prepareDoneCallBack: ((Boolean, BleBean?) -> Unit)?
|
|
|
) {
|
|
|
- loadingCallBack?.invoke(true, "开始获取token...", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始获取token...", null)))
|
|
|
bleBean?.let {
|
|
|
BleCmdManager.getToken(it.bleDevice.mac, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
- loadingCallBack?.invoke(false, "token获取成功", null)
|
|
|
+ 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?) {
|
|
|
- loadingCallBack?.invoke(false, "token获取失败", false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "token获取失败", false)))
|
|
|
LogUtil.e("getToken fail : ${bleBean.bleDevice.mac}")
|
|
|
prepareDoneCallBack?.invoke(false, null)
|
|
|
}
|
|
|
@@ -661,11 +663,11 @@ object BusinessManager {
|
|
|
ticketDetail: TicketDetailRespVO,
|
|
|
lockList: MutableList<String?>?,
|
|
|
activity: AppCompatActivity,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
) {
|
|
|
registerConnectListener(mac) { isDone, bleBean ->
|
|
|
if (!isDone) {
|
|
|
- sendTicketBusiness(mac, ticketDetail, lockList, activity, loadingCallBack)
|
|
|
+ sendTicketBusiness(mac, ticketDetail, lockList, activity, isNeedLoading)
|
|
|
return@registerConnectListener
|
|
|
}
|
|
|
if (bleBean == null) {
|
|
|
@@ -676,7 +678,7 @@ object BusinessManager {
|
|
|
// 单bleBean json赋值
|
|
|
bleBean.ticketSend = generateTicketSendJson(ticketDetail, lockList)
|
|
|
bleBean.ticketSend?.let { itJson ->
|
|
|
- sendTicketWithRetry(itJson, bleBean.bleDevice, loadingCallBack)
|
|
|
+ sendTicketWithRetry(itJson, bleBean.bleDevice, isNeedLoading)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -687,14 +689,14 @@ object BusinessManager {
|
|
|
private fun sendTicketWithRetry(
|
|
|
json: String,
|
|
|
bleDevice: BleDevice,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
maxRetries: Int = 3,
|
|
|
delayMillis: Long = 500
|
|
|
) {
|
|
|
var retryCount = 0
|
|
|
|
|
|
fun attemptSend() {
|
|
|
- sendTicket(json, bleDevice, loadingCallBack) { sendRst ->
|
|
|
+ sendTicket(json, bleDevice, isNeedLoading) { sendRst ->
|
|
|
if (!sendRst && retryCount < maxRetries) {
|
|
|
retryCount++
|
|
|
// 等待一段时间后再次尝试
|
|
|
@@ -714,31 +716,30 @@ object BusinessManager {
|
|
|
*/
|
|
|
fun getTicketStatusBusiness(
|
|
|
mac: String,
|
|
|
- activity: AppCompatActivity,
|
|
|
- loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?
|
|
|
+ isNeedLoading: Boolean = false
|
|
|
) {
|
|
|
registerConnectListener(mac) { isDone, bleBean ->
|
|
|
if (isDone) {
|
|
|
Executor.delayOnMain(500) {
|
|
|
- getTicketStatus(bleBean!!.bleDevice, loadingCallBack)
|
|
|
+ getTicketStatus(bleBean!!.bleDevice, isNeedLoading)
|
|
|
}
|
|
|
} else {
|
|
|
- loadingCallBack?.invoke(false, null, false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun sendTicket(jsonStr: String, bleDevice: BleDevice, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?, processCallback: ((Boolean) -> Unit)? = null) {
|
|
|
- loadingCallBack?.invoke(true, "开始下发工作票...", null)
|
|
|
+ private fun sendTicket(jsonStr: String, bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始下发工作票...", null)))
|
|
|
BleCmdManager.sendWorkTicket(jsonStr, bleDevice = bleDevice, callback = object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
println("sendTicket success")
|
|
|
- loadingCallBack?.invoke(true, "工作票下发中...", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "工作票下发中...", null)))
|
|
|
}
|
|
|
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.e("sendTicket fail : ${bleDevice.mac}")
|
|
|
- loadingCallBack?.invoke(false, "工作票下发失败", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票下发失败", null)))
|
|
|
processCallback?.invoke(false)
|
|
|
}
|
|
|
})
|
|
|
@@ -802,7 +803,7 @@ object BusinessManager {
|
|
|
return jsonStr
|
|
|
}
|
|
|
|
|
|
- fun handleRsp(bleBean: BleBean, byteArray: ByteArray, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?) {
|
|
|
+ fun handleRsp(bleBean: BleBean, byteArray: ByteArray, isNeedLoading: Boolean = false) {
|
|
|
// TODO Token校验
|
|
|
// val len = byteArray[2].toInt()
|
|
|
// val token = byteArray.copyOfRange(len + 7, len + 11)
|
|
|
@@ -815,12 +816,12 @@ object BusinessManager {
|
|
|
// 获取令牌
|
|
|
byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(bleBean.bleDevice, byteArray)
|
|
|
// 工作模式切换
|
|
|
- byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> handleSwitchModeResult(byteArray, loadingCallBack)
|
|
|
+ byteArray.startsWith(BleConst.RSP_SWITCH_MODE) -> handleSwitchModeResult(byteArray, isNeedLoading)
|
|
|
// 工作票下发
|
|
|
- byteArray.startsWith(BleConst.RSP_SEND_WORK_TICKET) -> handleWorkTicketResult(bleBean, byteArray, loadingCallBack)
|
|
|
+ byteArray.startsWith(BleConst.RSP_SEND_WORK_TICKET) -> handleWorkTicketResult(bleBean, byteArray, isNeedLoading)
|
|
|
// 获取设备工作票完成情况
|
|
|
byteArray.startsWith(BleConst.RSP_WORK_TICKET_RESULT) && byteArray[3] == 0x02.toByte() ->
|
|
|
- handleTicketStatus(bleBean.bleDevice, byteArray, loadingCallBack)
|
|
|
+ handleTicketStatus(bleBean.bleDevice, byteArray, isNeedLoading)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -829,17 +830,17 @@ object BusinessManager {
|
|
|
* job : 0x01:工作模式 0x02:待机模式
|
|
|
* res : 0x01:成功 0x02:失败
|
|
|
*/
|
|
|
- private fun handleSwitchModeResult(byteArray: ByteArray, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?) {
|
|
|
+ private fun handleSwitchModeResult(byteArray: ByteArray, isNeedLoading: Boolean = false) {
|
|
|
BleCmdManager.handleSwitchModeResult(byteArray) { job, res ->
|
|
|
if (res == 0x01.toByte() && job == 0x01.toByte()) {
|
|
|
LogUtil.i("切换工作模式成功")
|
|
|
- loadingCallBack?.invoke(false, "切换工作模式成功", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "切换工作模式成功", null)))
|
|
|
} else if (res == 0x01.toByte() && job == 0x02.toByte()) {
|
|
|
LogUtil.i("切换待机模式成功")
|
|
|
- loadingCallBack?.invoke(false, "切换待机模式成功", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "切换待机模式成功", null)))
|
|
|
} else {
|
|
|
LogUtil.e("切换模式失败 : ${job.toInt()} - ${res.toInt()}")
|
|
|
- loadingCallBack?.invoke(false, null, null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -848,22 +849,22 @@ object BusinessManager {
|
|
|
* 工作票下发结果
|
|
|
* res:0x00:成功 0x01:失败 0x02:传输超时 0x0D:当前IDX超出范围 0x0E:当前数据CRC校验失败 0x14:JSON结构错误 0x63:未知错误
|
|
|
*/
|
|
|
- private fun handleWorkTicketResult(bleBean: BleBean, byteArray: ByteArray, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?) {
|
|
|
+ private fun handleWorkTicketResult(bleBean: BleBean, byteArray: ByteArray, isNeedLoading: Boolean = false) {
|
|
|
BleCmdManager.handleWorkTicketResult(bleBean, byteArray) { isSuccess, rst ->
|
|
|
- loadingCallBack?.invoke(false, null, null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, null)))
|
|
|
if (isSuccess) {
|
|
|
// 下发完毕,切换工作模式
|
|
|
LogUtil.i("工作票下发完毕")
|
|
|
- loadingCallBack?.invoke(true, "切换钥匙为工作模式", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "切换钥匙为工作模式", null)))
|
|
|
|
|
|
Executor.delayOnIO(800) {
|
|
|
- switchWorkMode(bleBean.bleDevice, loadingCallBack)
|
|
|
+ switchWorkMode(bleBean.bleDevice, isNeedLoading)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun switchWorkMode(bleDevice: BleDevice, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?) {
|
|
|
+ private fun switchWorkMode(bleDevice: BleDevice, isNeedLoading: Boolean = false) {
|
|
|
LogUtil.i("switchWorkMode - ${bleDevice.mac}")
|
|
|
BleCmdManager.switchMode(STATUS_WORK, bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
@@ -874,10 +875,10 @@ object BusinessManager {
|
|
|
// 打开钥匙卡扣
|
|
|
val keyBean = ModBusController.getKeyByMac(bleDevice.mac)
|
|
|
if (keyBean == null) {
|
|
|
- loadingCallBack?.invoke(false, "未找到钥匙信息", false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
|
|
|
ToastUtils.tip(R.string.key_not_exists)
|
|
|
} else {
|
|
|
- loadingCallBack?.invoke(false, null, true)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
|
|
|
val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
|
|
|
}
|
|
|
@@ -885,7 +886,7 @@ object BusinessManager {
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.e("switch mode work fail : ${exception?.code} - ${exception?.description}")
|
|
|
Executor.delayOnMain(500) {
|
|
|
- switchWorkMode(bleDevice, loadingCallBack)
|
|
|
+ switchWorkMode(bleDevice, isNeedLoading)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -894,15 +895,15 @@ object BusinessManager {
|
|
|
/**
|
|
|
* 处理工作票完成情况
|
|
|
*/
|
|
|
- private fun handleTicketStatus(bleDevice: BleDevice, byteArray: ByteArray, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?) {
|
|
|
+ private fun handleTicketStatus(bleDevice: BleDevice, byteArray: ByteArray, isNeedLoading: Boolean = false) {
|
|
|
BleCmdManager.handleTicketStatus(bleDevice, byteArray) { ticketJson ->
|
|
|
if (ticketJson.isNullOrEmpty()) {
|
|
|
return@handleTicketStatus
|
|
|
}
|
|
|
- loadingCallBack?.invoke(false, "工作票完成状态读取完成", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票完成状态读取完成", null)))
|
|
|
LogUtil.i("Get ticket status complete")
|
|
|
// TD:Ticket Done
|
|
|
- loadingCallBack?.invoke(false, "TD$ticketJson}", true)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "TD$ticketJson}", true)))
|
|
|
// TODO 根据工作票完成情况,切换为待机模式
|
|
|
BleCmdManager.switchMode(STATUS_READY, bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
@@ -951,14 +952,14 @@ object BusinessManager {
|
|
|
/**
|
|
|
* 获取工作票完成情况
|
|
|
*/
|
|
|
- private fun getTicketStatus(bleDevice: BleDevice, loadingCallBack: ((Boolean, String?, Boolean?) -> Unit)?) {
|
|
|
- loadingCallBack?.invoke(true, "开始获取工作票", null)
|
|
|
+ private fun getTicketStatus(bleDevice: BleDevice, isNeedLoading: Boolean = false) {
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始获取工作票", null)))
|
|
|
BleCmdManager.getTicketStatus(bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
- loadingCallBack?.invoke(false, "工作票获取成功", null)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取成功", null)))
|
|
|
println("getTicketStatus success")}
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
- loadingCallBack?.invoke(false, "工作票获取失败", false)
|
|
|
+ if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取失败", false)))
|
|
|
println("getTicketStatus fail")}
|
|
|
})
|
|
|
}
|