sforkowany z mirror/meshtastic-android
better
rodzic
456014dd5f
commit
d2f6156841
|
@ -120,6 +120,27 @@ class MainActivity : AppCompatActivity(), Logging {
|
|||
)
|
||||
}
|
||||
})
|
||||
|
||||
Button(text = "send packets",
|
||||
onClick = {
|
||||
// FIXME - don't do these operations until we are informed we have a connection, otherwise
|
||||
// the radio interface service might not yet be connected to the mesh service
|
||||
val m = meshService!!
|
||||
|
||||
// Do some test operations
|
||||
m.setOwner("+16508675309", "Kevin Xter", "kx")
|
||||
val testPayload = "hello world".toByteArray()
|
||||
m.sendData(
|
||||
"+16508675310",
|
||||
testPayload,
|
||||
MeshProtos.Data.Type.SIGNAL_OPAQUE_VALUE
|
||||
)
|
||||
m.sendData(
|
||||
"+16508675310",
|
||||
testPayload,
|
||||
MeshProtos.Data.Type.CLEAR_TEXT_VALUE
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,15 +178,6 @@ class MainActivity : AppCompatActivity(), Logging {
|
|||
val m = IMeshService.Stub.asInterface(service)
|
||||
meshService = m
|
||||
|
||||
// FIXME - don't do these operations until we are informed we have a connection, otherwise
|
||||
// the radio interface service might not yet be connected to the mesh service
|
||||
|
||||
// Do some test operations
|
||||
m.setOwner("+16508675309", "Kevin Xter", "kx")
|
||||
val testPayload = "hello world".toByteArray()
|
||||
m.sendData("+16508675310", testPayload, MeshProtos.Data.Type.SIGNAL_OPAQUE_VALUE)
|
||||
m.sendData("+16508675310", testPayload, MeshProtos.Data.Type.CLEAR_TEXT_VALUE)
|
||||
|
||||
// FIXME this doesn't work because the model has already been copied into compose land?
|
||||
// runOnUiThread { // FIXME - this can be removed?
|
||||
meshServiceState.connected = m.isConnected
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Service
|
|||
import android.bluetooth.BluetoothAdapter
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.bluetooth.BluetoothGattCharacteristic.PERMISSION_WRITE
|
||||
import android.bluetooth.BluetoothManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -153,6 +154,8 @@ class RadioInterfaceService : Service(), Logging {
|
|||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
info("Creating radio interface service")
|
||||
|
||||
// FIXME, let user GUI select which device we are talking to
|
||||
|
||||
// Note: this call does no comms, it just creates the device object (even if the
|
||||
|
@ -170,14 +173,21 @@ class RadioInterfaceService : Service(), Logging {
|
|||
// This callback is invoked after we are connected
|
||||
|
||||
connRes.getOrThrow() // FIXME, instead just try to reconnect?
|
||||
info("Connected to radio!")
|
||||
|
||||
// FIXME - no need to discover services, instead just hardwire the characteristics (like we do for toRadio)
|
||||
safe.asyncDiscoverServices { discRes ->
|
||||
discRes.getOrThrow() // FIXME, instead just try to reconnect?
|
||||
|
||||
fromRadio = service.getCharacteristic(BTM_FROMRADIO_CHARACTER)
|
||||
fromNum = service.getCharacteristic(BTM_FROMNUM_CHARACTER)
|
||||
// we begin by setting our MTU size as high as it can go
|
||||
safe.asyncRequestMtu(512) { mtuRes ->
|
||||
mtuRes.getOrThrow()
|
||||
|
||||
fromRadio = service.getCharacteristic(BTM_FROMRADIO_CHARACTER)
|
||||
fromNum = service.getCharacteristic(BTM_FROMNUM_CHARACTER)
|
||||
|
||||
doReadFromRadio()
|
||||
doReadFromRadio()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,6 +195,7 @@ class RadioInterfaceService : Service(), Logging {
|
|||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
info("Destroying radio interface service")
|
||||
sentPacketsLog.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
@ -199,7 +210,12 @@ class RadioInterfaceService : Service(), Logging {
|
|||
|
||||
// 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)
|
||||
val toRadio = BluetoothGattCharacteristic(
|
||||
BTM_FROMRADIO_CHARACTER,
|
||||
BluetoothGattCharacteristic.PROPERTY_WRITE,
|
||||
PERMISSION_WRITE
|
||||
)
|
||||
|
||||
toRadio.value = a
|
||||
safe.asyncWriteCharacteristic(toRadio) {
|
||||
it.getOrThrow() // FIXME, handle the error better
|
||||
|
|
|
@ -60,8 +60,8 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
|||
completeWork(status, Unit)
|
||||
}
|
||||
BluetoothProfile.STATE_DISCONNECTED -> {
|
||||
// cancel any ops
|
||||
failAllWork(IOException("Lost connection"))
|
||||
// cancel any queued ops? for now I think it is best to keep them around
|
||||
// failAllWork(IOException("Lost connection"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,11 +49,11 @@ class SoftwareUpdateService : JobIntentService(), Logging {
|
|||
|
||||
sync.connect()
|
||||
|
||||
// we begin by setting our MTU size as high as it can go
|
||||
sync.requestMtu(512)
|
||||
|
||||
sync.discoverServices() // Get our services
|
||||
|
||||
// we begin by setting our MTU size as high as it can go
|
||||
sync.requestMtu(512)
|
||||
|
||||
val service = sync.gatt.services.find { it.uuid == SW_UPDATE_UUID }!!
|
||||
|
||||
val totalSizeDesc = service.getCharacteristic(SW_UPDATE_TOTALSIZE_CHARACTER)
|
||||
|
|
Ładowanie…
Reference in New Issue