Identify link loss signal

This commit is contained in:
Sylwester Zielinski
2023-03-23 15:37:52 +01:00
parent 496c815713
commit fb1fdbf477
2 changed files with 5 additions and 8 deletions

View File

@@ -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
}

View File

@@ -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()
}