diff --git a/TODO.md b/TODO.md index ae44edc42..c471038ad 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ * test reg reading/writing directly via bt to device * fix bluetooth update -* add broadcasters for use by signal +* add broadcasters for use by signal (node changes and packet received) * make test implementation of server (doesn't use bluetooth) * add real messaging code/protobufs * use https://codelabs.developers.google.com/codelabs/jetpack-compose-basics/#4 to show service state diff --git a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl index fb5640d96..b7025bd72 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl @@ -17,7 +17,7 @@ interface IMeshService { /** Get the IDs of everyone on the mesh. You should also subscribe for NODE_CHANGE broadcasts. */ - void getOnline(out String[] ids); + String[] getOnline(); /** Is the packet radio currently connected to the phone? diff --git a/app/src/main/java/com/geeksville/mesh/MeshService.kt b/app/src/main/java/com/geeksville/mesh/MeshService.kt index 69b75827a..a2155a456 100644 --- a/app/src/main/java/com/geeksville/mesh/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/MeshService.kt @@ -3,8 +3,37 @@ package com.geeksville.mesh import android.app.Service import android.content.Intent import android.os.IBinder +import com.geeksville.android.Logging -class MeshService : Service() { +class MeshService : Service(), Logging { + + val prefix = "com.geeksville.mesh" + + /* + see com.geeksville.com.geeeksville.mesh broadcast intents + // RECEIVED_OPAQUE for data received from other nodes + // NODE_CHANGE for new IDs appearing or disappearing + // CONNECTION_CHANGED for losing/gaining connection to the packet radio + */ + fun broadcastReceivedOpaque(senderId: String, payload: ByteArray) { + val intent = Intent("$prefix.RECEIVED_OPAQUE") + intent.putExtra("$prefix.Sender", senderId) + intent.putExtra("$prefix.Payload", payload) + sendBroadcast(intent) + } + + fun broadcastNodeChange(nodeId: String, isOnline: Boolean) { + val intent = Intent("$prefix.NODE_CHANGE") + intent.putExtra("$prefix.Id", nodeId) + intent.putExtra("$prefix.Online", isOnline) + sendBroadcast(intent) + } + + fun broadcastConnectionChanged(isConnected: Boolean) { + val intent = Intent("$prefix.CONNECTION_CHANGED") + intent.putExtra("$prefix.Connected", isConnected) + sendBroadcast(intent) + } override fun onBind(intent: Intent): IBinder { // Return the interface @@ -12,20 +41,22 @@ class MeshService : Service() { } private val binder = object : IMeshService.Stub() { - override fun setOwner(myId: String?, longName: String?, shortName: String?) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + override fun setOwner(myId: String, longName: String, shortName: String) { + error("TODO setOwner $myId : $longName : $shortName") } - override fun sendOpaque(destId: String?, payload: ByteArray?) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + override fun sendOpaque(destId: String, payload: ByteArray) { + error("TODO sendOpaque $destId <- ${payload.size}") } - override fun getOnline(ids: Array?) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + override fun getOnline(): Array { + error("TODO getOnline") + return arrayOf("+16508675309") } override fun isConnected(): Boolean { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + error("TODO isConnected") + return true } } } \ No newline at end of file