kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
used deferred execution to prevent dropping packets at startup
rodzic
d03bfb556c
commit
db0936ff88
|
@ -98,6 +98,24 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
composeView(meshServiceState)
|
composeView(meshServiceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun sendTestPackets() {
|
||||||
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun composeView(meshServiceState: MeshServiceState) {
|
fun composeView(meshServiceState: MeshServiceState) {
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
|
@ -122,25 +140,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
})
|
})
|
||||||
|
|
||||||
Button(text = "send packets",
|
Button(text = "send packets",
|
||||||
onClick = {
|
onClick = { sendTestPackets() })
|
||||||
// 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
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,6 +178,11 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
val m = IMeshService.Stub.asInterface(service)
|
val m = IMeshService.Stub.asInterface(service)
|
||||||
meshService = m
|
meshService = m
|
||||||
|
|
||||||
|
// FIXME: this still can't work this early because the send to +6508675310
|
||||||
|
// requires a DB lookup which isn't yet populated (until the sim test packets
|
||||||
|
// from the radio arrive)
|
||||||
|
// sendTestPackets() // send some traffic ASAP
|
||||||
|
|
||||||
// FIXME this doesn't work because the model has already been copied into compose land?
|
// FIXME this doesn't work because the model has already been copied into compose land?
|
||||||
// runOnUiThread { // FIXME - this can be removed?
|
// runOnUiThread { // FIXME - this can be removed?
|
||||||
meshServiceState.connected = m.isConnected
|
meshServiceState.connected = m.isConnected
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Service
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import com.geeksville.android.Logging
|
import com.geeksville.android.Logging
|
||||||
|
import com.geeksville.concurrent.DeferredExecution
|
||||||
import com.geeksville.mesh.MeshProtos.MeshPacket
|
import com.geeksville.mesh.MeshProtos.MeshPacket
|
||||||
import com.geeksville.mesh.MeshProtos.ToRadio
|
import com.geeksville.mesh.MeshProtos.ToRadio
|
||||||
import com.geeksville.util.toOneLineString
|
import com.geeksville.util.toOneLineString
|
||||||
|
@ -73,13 +74,18 @@ class MeshService : Service(), Logging {
|
||||||
explicitBroadcast(intent)
|
explicitBroadcast(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a command/packet to our radio
|
private val toRadioDeferred = DeferredExecution()
|
||||||
|
|
||||||
|
/// Send a command/packet to our radio. But cope with the possiblity that we might start up
|
||||||
|
/// before we are fully bound to the RadioInterfaceService
|
||||||
private fun sendToRadio(p: ToRadio.Builder) {
|
private fun sendToRadio(p: ToRadio.Builder) {
|
||||||
|
val b = p.build().toByteArray()
|
||||||
|
|
||||||
val s = radioService
|
val s = radioService
|
||||||
if (s != null)
|
if (s != null)
|
||||||
s.sendToRadio(p.build().toByteArray())
|
s.sendToRadio(b)
|
||||||
else
|
else
|
||||||
error("FIXME! dropped sent packet because radio interface not yet fully connected")
|
toRadioDeferred.add { radioService!!.sendToRadio(b) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? {
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
|
@ -103,6 +109,9 @@ class MeshService : Service(), Logging {
|
||||||
sendToRadio(ToRadio.newBuilder().apply {
|
sendToRadio(ToRadio.newBuilder().apply {
|
||||||
wantNodes = ToRadio.WantNodes.newBuilder().build()
|
wantNodes = ToRadio.WantNodes.newBuilder().build()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Now send any packets which had previously been queued for clients
|
||||||
|
toRadioDeferred.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
override fun onServiceDisconnected(name: ComponentName?) {
|
||||||
|
|
Ładowanie…
Reference in New Issue