kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
transmit write packets to the radio
rodzic
6cebf063d7
commit
456014dd5f
|
@ -75,7 +75,11 @@ class MeshService : Service(), Logging {
|
||||||
|
|
||||||
/// Send a command/packet to our radio
|
/// Send a command/packet to our radio
|
||||||
private fun sendToRadio(p: ToRadio.Builder) {
|
private fun sendToRadio(p: ToRadio.Builder) {
|
||||||
radioService!!.sendToRadio(p.build().toByteArray())
|
val s = radioService
|
||||||
|
if (s != null)
|
||||||
|
s.sendToRadio(p.build().toByteArray())
|
||||||
|
else
|
||||||
|
error("FIXME! dropped sent packet because radio interface not yet fully connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? {
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
|
|
|
@ -102,8 +102,9 @@ class RadioInterfaceService : Service(), Logging {
|
||||||
private lateinit var device: BluetoothDevice
|
private lateinit var device: BluetoothDevice
|
||||||
private lateinit var safe: SafeBluetooth
|
private lateinit var safe: SafeBluetooth
|
||||||
|
|
||||||
|
val service get() = safe.gatt.services.find { it.uuid == BTM_SERVICE_UUID }!!
|
||||||
|
|
||||||
private lateinit var fromRadio: BluetoothGattCharacteristic
|
private lateinit var fromRadio: BluetoothGattCharacteristic
|
||||||
private lateinit var toRadio: BluetoothGattCharacteristic
|
|
||||||
private lateinit var fromNum: BluetoothGattCharacteristic
|
private lateinit var fromNum: BluetoothGattCharacteristic
|
||||||
|
|
||||||
lateinit var sentPacketsLog: DebugLogFile // inited in onCreate
|
lateinit var sentPacketsLog: DebugLogFile // inited in onCreate
|
||||||
|
@ -136,7 +137,16 @@ class RadioInterfaceService : Service(), Logging {
|
||||||
/// Attempt to read from the fromRadio mailbox, if data is found broadcast it to android apps
|
/// Attempt to read from the fromRadio mailbox, if data is found broadcast it to android apps
|
||||||
private fun doReadFromRadio() {
|
private fun doReadFromRadio() {
|
||||||
safe.asyncReadCharacteristic(fromRadio) {
|
safe.asyncReadCharacteristic(fromRadio) {
|
||||||
logAssert(it.isSuccess) // FIXME, handle failure
|
val b = it.getOrThrow().value
|
||||||
|
|
||||||
|
if (b.isNotEmpty()) {
|
||||||
|
debug("Received ${b.size} bytes from radio")
|
||||||
|
handleFromRadio(b)
|
||||||
|
|
||||||
|
// Queue up another read, until we run out of packets
|
||||||
|
doReadFromRadio()
|
||||||
|
} else
|
||||||
|
debug("Done reading from radio, fromradio is empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,15 +169,12 @@ class RadioInterfaceService : Service(), Logging {
|
||||||
safe.asyncConnect(true) { connRes ->
|
safe.asyncConnect(true) { connRes ->
|
||||||
// This callback is invoked after we are connected
|
// This callback is invoked after we are connected
|
||||||
|
|
||||||
logAssert(connRes.isSuccess) // FIXME, instead just try to reconnect?
|
connRes.getOrThrow() // FIXME, instead just try to reconnect?
|
||||||
|
|
||||||
safe.asyncDiscoverServices { discRes ->
|
safe.asyncDiscoverServices { discRes ->
|
||||||
logAssert(discRes.isSuccess) // IXME, instead just try to reconnect?
|
discRes.getOrThrow() // FIXME, instead just try to reconnect?
|
||||||
|
|
||||||
val service = safe.gatt.services.find { it.uuid == BTM_SERVICE_UUID }!!
|
|
||||||
|
|
||||||
fromRadio = service.getCharacteristic(BTM_FROMRADIO_CHARACTER)
|
fromRadio = service.getCharacteristic(BTM_FROMRADIO_CHARACTER)
|
||||||
toRadio = service.getCharacteristic(BTM_FROMRADIO_CHARACTER)
|
|
||||||
fromNum = service.getCharacteristic(BTM_FROMNUM_CHARACTER)
|
fromNum = service.getCharacteristic(BTM_FROMNUM_CHARACTER)
|
||||||
|
|
||||||
doReadFromRadio()
|
doReadFromRadio()
|
||||||
|
@ -188,7 +195,15 @@ class RadioInterfaceService : Service(), Logging {
|
||||||
|
|
||||||
private val binder = object : IRadioInterfaceService.Stub() {
|
private val binder = object : IRadioInterfaceService.Stub() {
|
||||||
override fun sendToRadio(a: ByteArray) {
|
override fun sendToRadio(a: ByteArray) {
|
||||||
handleFromRadio(a)
|
debug("queuing ${a.size} bytes to radio")
|
||||||
|
|
||||||
|
// Note: we generate a new characteristic each time, because we are about to
|
||||||
|
// change the data and we want the data stored in the closure
|
||||||
|
val toRadio = service.getCharacteristic(BTM_FROMRADIO_CHARACTER)
|
||||||
|
toRadio.value = a
|
||||||
|
safe.asyncWriteCharacteristic(toRadio) {
|
||||||
|
it.getOrThrow() // FIXME, handle the error better
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -48,6 +48,10 @@ class SoftwareUpdateService : JobIntentService(), Logging {
|
||||||
val firmwareSize = firmwareStream.available()
|
val firmwareSize = firmwareStream.available()
|
||||||
|
|
||||||
sync.connect()
|
sync.connect()
|
||||||
|
|
||||||
|
// we begin by setting our MTU size as high as it can go
|
||||||
|
sync.requestMtu(512)
|
||||||
|
|
||||||
sync.discoverServices() // Get our services
|
sync.discoverServices() // Get our services
|
||||||
|
|
||||||
val service = sync.gatt.services.find { it.uuid == SW_UPDATE_UUID }!!
|
val service = sync.gatt.services.find { it.uuid == SW_UPDATE_UUID }!!
|
||||||
|
@ -57,9 +61,6 @@ class SoftwareUpdateService : JobIntentService(), Logging {
|
||||||
val crc32Desc = service.getCharacteristic(SW_UPDATE_CRC32_CHARACTER)
|
val crc32Desc = service.getCharacteristic(SW_UPDATE_CRC32_CHARACTER)
|
||||||
val updateResultDesc = service.getCharacteristic(SW_UPDATE_RESULT_CHARACTER)
|
val updateResultDesc = service.getCharacteristic(SW_UPDATE_RESULT_CHARACTER)
|
||||||
|
|
||||||
// we begin by setting our MTU size as high as it can go
|
|
||||||
sync.requestMtu(512)
|
|
||||||
|
|
||||||
// Start the update by writing the # of bytes in the image
|
// Start the update by writing the # of bytes in the image
|
||||||
logAssert(
|
logAssert(
|
||||||
totalSizeDesc.setValue(
|
totalSizeDesc.setValue(
|
||||||
|
|
Ładowanie…
Reference in New Issue