mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2025-12-24 00:07:48 -05:00
refactor(connections): Improve RSSI reading robustness (#3804)
This commit is contained in:
@@ -228,7 +228,7 @@ class MeshService : Service() {
|
||||
private const val DEFAULT_CONFIG_ONLY_NONCE = 69420
|
||||
private const val DEFAULT_NODE_INFO_NONCE = 69421
|
||||
|
||||
private const val WANT_CONFIG_DELAY = 50L
|
||||
private const val WANT_CONFIG_DELAY = 100L
|
||||
private const val HISTORY_TAG = "HistoryReplay"
|
||||
private const val DEFAULT_HISTORY_RETURN_WINDOW_MINUTES = 60 * 24
|
||||
private const val DEFAULT_HISTORY_RETURN_MAX_MESSAGES = 100
|
||||
|
||||
@@ -42,6 +42,9 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.geeksville.mesh.model.DeviceListEntry
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import no.nordicsemi.kotlin.ble.client.exception.OperationFailedException
|
||||
import no.nordicsemi.kotlin.ble.client.exception.PeripheralNotConnectedException
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.meshtastic.core.database.model.Node
|
||||
import org.meshtastic.core.strings.Res
|
||||
@@ -58,7 +61,9 @@ import org.meshtastic.proto.TelemetryProtos
|
||||
import timber.log.Timber
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
private const val RSSI_DELAY = 10
|
||||
private const val RSSI_TIMEOUT = 5
|
||||
|
||||
@Composable
|
||||
fun CurrentlyConnectedInfo(
|
||||
node: Node,
|
||||
@@ -72,10 +77,17 @@ fun CurrentlyConnectedInfo(
|
||||
if (bleDevice != null) {
|
||||
while (bleDevice.peripheral.isConnected) {
|
||||
try {
|
||||
rssi = bleDevice.peripheral.readRssi()
|
||||
delay(10.seconds)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to read RSSI")
|
||||
rssi = withTimeout(RSSI_TIMEOUT.seconds) { bleDevice.peripheral.readRssi() }
|
||||
delay(RSSI_DELAY.seconds)
|
||||
} catch (e: PeripheralNotConnectedException) {
|
||||
Timber.e(e, "Failed to read RSSI ${e.message}")
|
||||
break
|
||||
} catch (e: OperationFailedException) {
|
||||
Timber.e(e, "Failed to read RSSI ${e.message}")
|
||||
break
|
||||
} catch (e: SecurityException) {
|
||||
Timber.e(e, "Failed to read RSSI ${e.message}")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user