add aidl get/begin/commit configs

This commit is contained in:
andrekir
2022-11-29 17:47:49 -03:00
parent a1984c5136
commit 35ffcceb79
2 changed files with 39 additions and 28 deletions

View File

@@ -72,6 +72,8 @@ interface IMeshService {
List<NodeInfo> 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);

View File

@@ -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<NodeInfo> = 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
})
}
}
}