mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
finished most of the firmware update code
This commit is contained in:
parent
bf26f7293a
commit
2245c753e3
4 changed files with 27 additions and 17 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -21,19 +21,21 @@ class SyncBluetoothDevice(private val context: Context, private val device: Blue
|
|||
Logging {
|
||||
|
||||
private var pendingServiceDesc: SyncContinuation<Unit>? = null
|
||||
private var pendingMtu: SyncContinuation<kotlin.Int>? = null
|
||||
private var pendingMtu: SyncContinuation<Int>? = null
|
||||
private var pendingWriteC: SyncContinuation<Unit>? = null
|
||||
private var pendingReadC: SyncContinuation<BluetoothGattCharacteristic>? = null
|
||||
private var pendingConnect: SyncContinuation<Unit>? = 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<kotlin.Int> { cont ->
|
||||
fun requestMtu(len: Int) = suspend<Int> { cont ->
|
||||
pendingMtu = cont
|
||||
logAssert(gatt.requestMtu(len))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue