diff --git a/TODO.md b/TODO.md
index 761b77060..c6cd45c6d 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,17 +1,16 @@
-* test reg reading/writing directly via bt to device
-* fix bluetooth update
-* refactor sw update code to share with my other bluetooth service
-* get signal running under debugger
+
* handle failures in onCharWrite, instead of logAssert - because they can happen if device goes away
+* 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)
-* make test implementation of server (doesn't use bluetooth)
* make compose based access show mesh state
-* make a test client of the android service
+* use android service from Signal
* add real messaging code/protobufs
* use https://codelabs.developers.google.com/codelabs/jetpack-compose-basics/#4 to show service state
* connect to bluetooth device automatically using minimum power
* have signal declare receivers: https://developer.android.com/guide/components/broadcasts#manifest-declared-receivers
+* fix BT device scanning
protobuf notes
protoc -I=. --java_out /tmp mesh.proto
@@ -40,9 +39,14 @@ Don't leave device discoverable. Don't let unpaired users do thing with device
# Done
+* DONE fix bluetooth update
+* DONE refactor sw update code to share with my other bluetooth service
+* DONE don't let sw update got to sleep during the update
* assert() is apparently a noop - change to use my version of assert
* DONE add crash reporting
* DONE add analytics (make them optional)
* make frontend using https://developer.android.com/jetpack/compose/tutorial
* change bluetooth mtu length to 512 (default is only 20)
+* DONE get signal running under debugger
+* Find good Signal hooks
diff --git a/app/src/main/java/com/geeksville/mesh/SoftwareUpdateService.kt b/app/src/main/java/com/geeksville/mesh/SoftwareUpdateService.kt
index 338224c14..9fb6580f0 100644
--- a/app/src/main/java/com/geeksville/mesh/SoftwareUpdateService.kt
+++ b/app/src/main/java/com/geeksville/mesh/SoftwareUpdateService.kt
@@ -72,7 +72,8 @@ class SoftwareUpdateService : JobIntentService(), Logging {
// Our write completed, queue up a readback
val totalSizeReadback = sync.readCharacteristic(totalSizeDesc)
.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 0)
- logAssert(totalSizeReadback != 0) // FIXME - handle this case
+ if(totalSizeReadback == 0) // FIXME - handle this case
+ throw Exception("Device rejected file size")
// Send all the blocks
while (firmwareNumSent < firmwareSize) {
@@ -103,7 +104,8 @@ class SoftwareUpdateService : JobIntentService(), Logging {
val updateResult =
sync.readCharacteristic(updateResultDesc)
.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)
- logAssert(updateResult == 0) // FIXME - handle this case
+ if(updateResult != 0) // FIXME - handle this case
+ throw Exception("Device update failed, reason=$updateResult")
// FIXME perhaps ask device to reboot
}
@@ -209,10 +211,7 @@ class SoftwareUpdateService : JobIntentService(), Logging {
val startUpdateIntent = Intent("com.geeksville.com.geeeksville.mesh.START_UPDATE")
private const val SCAN_PERIOD: Long = 10000
-
- //const val ACTION_GATT_CONNECTED = "com.example.bluetooth.le.ACTION_GATT_CONNECTED"
- //const val ACTION_GATT_DISCONNECTED = "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED"
-
+
private val TAG =
MainActivity::class.java.simpleName // FIXME - use my logging class instead
diff --git a/app/src/main/java/com/geeksville/mesh/SyncBluetoothDevice.kt b/app/src/main/java/com/geeksville/mesh/SyncBluetoothDevice.kt
index 68012181e..725199a25 100644
--- a/app/src/main/java/com/geeksville/mesh/SyncBluetoothDevice.kt
+++ b/app/src/main/java/com/geeksville/mesh/SyncBluetoothDevice.kt
@@ -21,19 +21,21 @@ class SyncBluetoothDevice(private val context: Context, private val device: Blue
Logging {
private var pendingServiceDesc: SyncContinuation? = null
- private var pendingMtu: SyncContinuation? = null
+ private var pendingMtu: SyncContinuation? = null
private var pendingWriteC: SyncContinuation? = null
private var pendingReadC: SyncContinuation? = null
private var pendingConnect: SyncContinuation? = null
- private val gattCallback = object : BluetoothGattCallback() {
+ var state = BluetoothProfile.STATE_DISCONNECTED
+ private val gattCallback = object : BluetoothGattCallback() {
override fun onConnectionStateChange(
gatt: BluetoothGatt,
status: Int,
newState: Int
) {
info("new bluetooth connection state $newState")
+ state = newState
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
if (pendingConnect != null) { // If someone was waiting to connect unblock them
@@ -42,7 +44,12 @@ class SyncBluetoothDevice(private val context: Context, private val device: Blue
}
}
BluetoothProfile.STATE_DISCONNECTED -> {
- TODO("handle loss of connection")
+ // cancel any ops
+
+ val pendings = listOf(pendingMtu, pendingServiceDesc, pendingWriteC, pendingReadC, pendingConnect)
+ pendings.filterNotNull().forEach {
+ it.resumeWithException(IOException("Lost connection"))
+ }
}
}
}
@@ -103,7 +110,7 @@ class SyncBluetoothDevice(private val context: Context, private val device: Blue
}
/// Returns the actual MTU size used
- fun requestMtu(len: Int) = suspend { cont ->
+ fun requestMtu(len: Int) = suspend { cont ->
pendingMtu = cont
logAssert(gatt.requestMtu(len))
}