mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-10 02:04:26 +01:00
Identify link loss signal
This commit is contained in:
@@ -14,9 +14,5 @@ data class PRXServiceData(
|
||||
val deviceName: String? = null
|
||||
) {
|
||||
|
||||
val isLinkLossDisconnected = connectionState?.let { connectionState ->
|
||||
connectionStatus?.let { connectionStatus ->
|
||||
connectionStatus != BleGattConnectionStatus.SUCCESS && connectionStatus != BleGattConnectionStatus.TERMINATE_PEER_USER
|
||||
} ?: false
|
||||
} ?: false
|
||||
val isLinkLossDisconnected = connectionStatus?.isLinkLoss ?: false
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import no.nordicsemi.android.kotlin.ble.core.client.BleWriteType
|
||||
import no.nordicsemi.android.kotlin.ble.core.client.callback.BleGattClient
|
||||
import no.nordicsemi.android.kotlin.ble.core.client.service.BleGattCharacteristic
|
||||
import no.nordicsemi.android.kotlin.ble.core.client.service.BleGattServices
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleGattConnectionStatus
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleGattPermission
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty
|
||||
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
|
||||
@@ -161,7 +162,7 @@ internal class PRXService : NotificationService() {
|
||||
.filterNotNull()
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.filterNotNull()
|
||||
.onEach { stopIfDisconnected(it.first) }
|
||||
.onEach { stopIfDisconnected(it.first, it.second) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
client.services
|
||||
@@ -193,8 +194,8 @@ internal class PRXService : NotificationService() {
|
||||
repository.onRemoteAlarmLevelSet(alarmLevel)
|
||||
}
|
||||
|
||||
private suspend fun stopIfDisconnected(connectionState: GattConnectionState) {
|
||||
if (connectionState == GattConnectionState.STATE_DISCONNECTED) {
|
||||
private fun stopIfDisconnected(connectionState: GattConnectionState, connectionStatus: BleGattConnectionStatus) {
|
||||
if (connectionState == GattConnectionState.STATE_DISCONNECTED && !connectionStatus.isLinkLoss) {
|
||||
server.stopServer()
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user