kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
except for dynamic device probing USB serial works pretty good now #38
rodzic
1cd0e1692d
commit
005ab16283
|
@ -1118,55 +1118,55 @@ class MeshService : Service(), Logging {
|
||||||
|
|
||||||
// Important to never throw exceptions out of onReceive
|
// Important to never throw exceptions out of onReceive
|
||||||
override fun onReceive(context: Context, intent: Intent) = exceptionReporter {
|
override fun onReceive(context: Context, intent: Intent) = exceptionReporter {
|
||||||
serviceScope.handledLaunch {
|
// NOTE: Do not call handledLaunch here, because it can cause out of order message processing - because each routine is scheduled independently
|
||||||
debug("Received broadcast ${intent.action}")
|
// serviceScope.handledLaunch {
|
||||||
when (intent.action) {
|
debug("Received broadcast ${intent.action}")
|
||||||
RadioInterfaceService.RADIO_CONNECTED_ACTION -> {
|
when (intent.action) {
|
||||||
try {
|
RadioInterfaceService.RADIO_CONNECTED_ACTION -> {
|
||||||
val connected = intent.getBooleanExtra(EXTRA_CONNECTED, false)
|
try {
|
||||||
val permanent = intent.getBooleanExtra(EXTRA_PERMANENT, false)
|
val connected = intent.getBooleanExtra(EXTRA_CONNECTED, false)
|
||||||
onConnectionChanged(
|
val permanent = intent.getBooleanExtra(EXTRA_PERMANENT, false)
|
||||||
when {
|
onConnectionChanged(
|
||||||
connected -> ConnectionState.CONNECTED
|
when {
|
||||||
permanent -> ConnectionState.DISCONNECTED
|
connected -> ConnectionState.CONNECTED
|
||||||
else -> ConnectionState.DEVICE_SLEEP
|
permanent -> ConnectionState.DISCONNECTED
|
||||||
}
|
else -> ConnectionState.DEVICE_SLEEP
|
||||||
)
|
}
|
||||||
} catch (ex: RemoteException) {
|
)
|
||||||
// This can happen sometimes (especially if the device is slowly dying due to killing power, don't report to crashlytics
|
} catch (ex: RemoteException) {
|
||||||
warn("Abandoning reconnect attempt, due to errors during init: ${ex.message}")
|
// This can happen sometimes (especially if the device is slowly dying due to killing power, don't report to crashlytics
|
||||||
}
|
warn("Abandoning reconnect attempt, due to errors during init: ${ex.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
RadioInterfaceService.RECEIVE_FROMRADIO_ACTION -> {
|
|
||||||
val proto =
|
|
||||||
MeshProtos.FromRadio.parseFrom(
|
|
||||||
intent.getByteArrayExtra(
|
|
||||||
EXTRA_PAYLOAD
|
|
||||||
)!!
|
|
||||||
)
|
|
||||||
info("Received from radio service: ${proto.toOneLineString()}")
|
|
||||||
when (proto.variantCase.number) {
|
|
||||||
MeshProtos.FromRadio.PACKET_FIELD_NUMBER -> handleReceivedMeshPacket(
|
|
||||||
proto.packet
|
|
||||||
)
|
|
||||||
|
|
||||||
MeshProtos.FromRadio.CONFIG_COMPLETE_ID_FIELD_NUMBER -> handleConfigComplete(
|
|
||||||
proto.configCompleteId
|
|
||||||
)
|
|
||||||
|
|
||||||
MeshProtos.FromRadio.MY_INFO_FIELD_NUMBER -> handleMyInfo(proto.myInfo)
|
|
||||||
|
|
||||||
MeshProtos.FromRadio.NODE_INFO_FIELD_NUMBER -> handleNodeInfo(proto.nodeInfo)
|
|
||||||
|
|
||||||
MeshProtos.FromRadio.RADIO_FIELD_NUMBER -> handleRadioConfig(proto.radio)
|
|
||||||
|
|
||||||
else -> errormsg("Unexpected FromRadio variant")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> errormsg("Unexpected radio interface broadcast")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RadioInterfaceService.RECEIVE_FROMRADIO_ACTION -> {
|
||||||
|
val proto =
|
||||||
|
MeshProtos.FromRadio.parseFrom(
|
||||||
|
intent.getByteArrayExtra(
|
||||||
|
EXTRA_PAYLOAD
|
||||||
|
)!!
|
||||||
|
)
|
||||||
|
info("Received from radio service: ${proto.toOneLineString()}")
|
||||||
|
when (proto.variantCase.number) {
|
||||||
|
MeshProtos.FromRadio.PACKET_FIELD_NUMBER -> handleReceivedMeshPacket(
|
||||||
|
proto.packet
|
||||||
|
)
|
||||||
|
|
||||||
|
MeshProtos.FromRadio.CONFIG_COMPLETE_ID_FIELD_NUMBER -> handleConfigComplete(
|
||||||
|
proto.configCompleteId
|
||||||
|
)
|
||||||
|
|
||||||
|
MeshProtos.FromRadio.MY_INFO_FIELD_NUMBER -> handleMyInfo(proto.myInfo)
|
||||||
|
|
||||||
|
MeshProtos.FromRadio.NODE_INFO_FIELD_NUMBER -> handleNodeInfo(proto.nodeInfo)
|
||||||
|
|
||||||
|
MeshProtos.FromRadio.RADIO_FIELD_NUMBER -> handleRadioConfig(proto.radio)
|
||||||
|
|
||||||
|
else -> errormsg("Unexpected FromRadio variant")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> errormsg("Unexpected radio interface broadcast")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1295,6 +1295,7 @@ class MeshService : Service(), Logging {
|
||||||
configNonce += 1
|
configNonce += 1
|
||||||
newNodes.clear()
|
newNodes.clear()
|
||||||
newMyNodeInfo = null
|
newMyNodeInfo = null
|
||||||
|
debug("Starting config nonce=$configNonce")
|
||||||
|
|
||||||
sendToRadio(ToRadio.newBuilder().apply {
|
sendToRadio(ToRadio.newBuilder().apply {
|
||||||
this.wantConfigId = configNonce
|
this.wantConfigId = configNonce
|
||||||
|
|
|
@ -154,6 +154,8 @@ class RadioInterfaceService : Service(), Logging {
|
||||||
receivedPacketsLog.flush()
|
receivedPacketsLog.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ignoreException { debug("FromRadio: ${MeshProtos.FromRadio.parseFrom(p)}") }
|
||||||
|
|
||||||
broadcastReceivedFromRadio(
|
broadcastReceivedFromRadio(
|
||||||
this,
|
this,
|
||||||
p
|
p
|
||||||
|
|
|
@ -88,14 +88,15 @@ class SerialInterface(private val service: RadioInterfaceService, val address: S
|
||||||
|
|
||||||
override fun handleSendToRadio(p: ByteArray) {
|
override fun handleSendToRadio(p: ByteArray) {
|
||||||
// This method is called from a continuation and it might show up late, so check for uart being null
|
// This method is called from a continuation and it might show up late, so check for uart being null
|
||||||
uart?.apply {
|
|
||||||
val header = ByteArray(4)
|
val header = ByteArray(4)
|
||||||
header[0] = START1
|
header[0] = START1
|
||||||
header[1] = START2
|
header[1] = START2
|
||||||
header[2] = (p.size shr 8).toByte()
|
header[2] = (p.size shr 8).toByte()
|
||||||
header[3] = (p.size and 0xff).toByte()
|
header[3] = (p.size and 0xff).toByte()
|
||||||
write(header, 0) // FIXME - combine these into one write (for fewer USB transactions)
|
ioManager?.apply {
|
||||||
write(p, 0)
|
writeAsync(header)
|
||||||
|
writeAsync(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue