timeout slow bluetooth operations

1.2-legacy
geeksville 2020-01-26 09:48:25 -08:00
rodzic 38119a61f6
commit 140c1561c3
4 zmienionych plików z 30 dodań i 7 usunięć

Wyświetl plik

@ -0,0 +1,17 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="previewFile" value="true" />
</inspection_tool>
</profile>
</component>

Wyświetl plik

@ -13,8 +13,10 @@ Once this project is public, I'll happily let collaborators have access to the c
* To see analytics: https://console.firebase.google.com/u/0/project/meshutil/analytics/app/android:com.geeksville.mesh/overview
* To see crash logs: https://console.firebase.google.com/u/0/project/meshutil/crashlytics/app/android:com.geeksville.mesh/issues?state=open&time=last-seven-days&type=crash
for verbose logging
for verbose logging:
```aidl
adb shell setprop log.tag.FA VERBOSE
adb shell setprop log.tag.FA-SVC VERBOSE
```

Wyświetl plik

@ -2,6 +2,7 @@
* use android service from Signal
* DONE handle failures in onCharWrite, instead of logAssert - because they can happen if device goes away
* explictly broadcast towards signal https://developer.android.com/guide/components/broadcasts
* make test implementation of android service (doesn't use bluetooth)
* clean up sw update code in device side
* DONE add broadcasters for use by signal (node changes and packet received)

Wyświetl plik

@ -26,6 +26,9 @@ class SyncBluetoothDevice(private val context: Context, private val device: Blue
private var pendingReadC: SyncContinuation<BluetoothGattCharacteristic>? = null
private var pendingConnect: SyncContinuation<Unit>? = null
/// Timeout before we declare a bluetooth operation failed
private val timeoutMsec = 30 * 1000L
var state = BluetoothProfile.STATE_DISCONNECTED
private val gattCallback = object : BluetoothGattCallback() {
@ -104,31 +107,31 @@ class SyncBluetoothDevice(private val context: Context, private val device: Blue
lateinit var gatt: BluetoothGatt
fun connect() =
suspend<Unit> { cont ->
suspend<Unit>(timeoutMsec) { cont ->
pendingConnect = cont
gatt = device.connectGatt(context, false, gattCallback)!!
}
fun discoverServices() =
suspend<Unit> { cont ->
suspend<Unit>(timeoutMsec) { cont ->
pendingServiceDesc = cont
logAssert(gatt.discoverServices())
}
/// Returns the actual MTU size used
fun requestMtu(len: Int) = suspend<Int> { cont ->
fun requestMtu(len: Int) = suspend<Int>(timeoutMsec) { cont ->
pendingMtu = cont
logAssert(gatt.requestMtu(len))
}
fun writeCharacteristic(c: BluetoothGattCharacteristic) =
suspend<Unit> { cont ->
suspend<Unit>(timeoutMsec) { cont ->
pendingWriteC = cont
logAssert(gatt.writeCharacteristic(c))
}
fun readCharacteristic(c: BluetoothGattCharacteristic) =
suspend<BluetoothGattCharacteristic> { cont ->
suspend<BluetoothGattCharacteristic>(timeoutMsec) { cont ->
pendingReadC = cont
logAssert(gatt.readCharacteristic(c))
}