kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
finished most of the firmware update code
rodzic
bf26f7293a
commit
2245c753e3
|
@ -10,9 +10,9 @@
|
|||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$/../../geeksville-androidlib" />
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/../geeksville-androidlib" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
|
|
16
TODO.md
16
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
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue