diff --git a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl index f91d5184c..e6990925d 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl @@ -72,6 +72,8 @@ interface IMeshService { List getNodes(); /// This method is only intended for use in our GUI, so the user can set radio options + /// It returns a DeviceConfig protobuf. + byte []getConfig(); /// It sets a Config protobuf via admin packet void setConfig(in byte []payload); @@ -83,6 +85,12 @@ interface IMeshService { /// It sets a Channel protobuf via admin packet void setChannel(in byte []payload); + /// Send beginEditSettings admin packet to nodeNum + void beginEditSettings(); + + /// Send commitEditSettings admin packet to nodeNum + void commitEditSettings(); + /// Send position packet with wantResponse to nodeNum void requestPosition(in int idNum, in double lat, in double lon, in int alt); diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 6d7fb8719..d9a409c09 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -99,6 +99,9 @@ class MeshService : Service(), Logging { class NodeNumNotFoundException(id: Int) : NodeNotFoundException("NodeNum not found $id") class IdNotFoundException(id: String) : NodeNotFoundException("ID not found $id") + class NoDeviceConfigException(message: String = "No radio settings received (is our app too old?)") : + RadioNotConnectedException(message) + /** We treat software update as similar to loss of comms to the regular bluetooth service (so things like sendPosition for background GPS ignores the problem */ class IsUpdatingException : RadioNotConnectedException("Operation prohibited during firmware update") @@ -1367,30 +1370,6 @@ class MeshService : Service(), Logging { }) } - private fun requestShutdown(idNum: Int) { - sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { - shutdownSeconds = 5 - }) - } - - private fun requestReboot(idNum: Int) { - sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { - rebootSeconds = 5 - }) - } - - private fun requestFactoryReset(idNum: Int) { - sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { - factoryReset = 1 - }) - } - - private fun requestNodedbReset(idNum: Int) { - sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { - nodedbReset = 1 - }) - } - /** * Start the modern (REV2) API configuration flow */ @@ -1689,6 +1668,10 @@ class MeshService : Service(), Logging { } } + override fun getConfig(): ByteArray = toRemoteExceptions { + this@MeshService.localConfig.toByteArray() ?: throw NoDeviceConfigException() + } + override fun setConfig(payload: ByteArray) = toRemoteExceptions { val parsed = ConfigProtos.Config.parseFrom(payload) setConfig(parsed) @@ -1704,6 +1687,18 @@ class MeshService : Service(), Logging { setChannel(parsed) } + override fun beginEditSettings() = toRemoteExceptions { + sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket { + beginEditSettings = true + }) + } + + override fun commitEditSettings() = toRemoteExceptions { + sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket { + commitEditSettings = true + }) + } + override fun getNodes(): MutableList = toRemoteExceptions { val r = nodeDBbyID.values.toMutableList() info("in getOnline, count=${r.size}") @@ -1734,19 +1729,27 @@ class MeshService : Service(), Logging { } override fun requestShutdown(idNum: Int) = toRemoteExceptions { - this@MeshService.requestShutdown(idNum) + sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { + shutdownSeconds = 5 + }) } override fun requestReboot(idNum: Int) = toRemoteExceptions { - this@MeshService.requestReboot(idNum) + sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { + rebootSeconds = 5 + }) } override fun requestFactoryReset(idNum: Int) = toRemoteExceptions { - this@MeshService.requestFactoryReset(idNum) + sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { + factoryReset = 1 + }) } override fun requestNodedbReset(idNum: Int) = toRemoteExceptions { - this@MeshService.requestNodedbReset(idNum) + sendToRadio(newMeshPacketTo(idNum).buildAdminPacket { + nodedbReset = 1 + }) } } }