mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor(service): Add destination node number to remote admin commands (#4276)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
9b150bad42
commit
7f7d189958
7 changed files with 83 additions and 75 deletions
|
|
@ -203,9 +203,9 @@ constructor(
|
|||
commandSender.sendAdmin(myNodeNum, requestId) { removeByNodenum = nodeNum }
|
||||
}
|
||||
|
||||
fun handleSetRemoteOwner(id: Int, payload: ByteArray, myNodeNum: Int) {
|
||||
fun handleSetRemoteOwner(id: Int, destNum: Int, payload: ByteArray) {
|
||||
val u = MeshProtos.User.parseFrom(payload)
|
||||
commandSender.sendAdmin(myNodeNum, id) { setOwner = u }
|
||||
commandSender.sendAdmin(destNum, id) { setOwner = u }
|
||||
}
|
||||
|
||||
fun handleGetRemoteOwner(id: Int, destNum: Int) {
|
||||
|
|
@ -217,9 +217,9 @@ constructor(
|
|||
commandSender.sendAdmin(myNodeNum) { setConfig = c }
|
||||
}
|
||||
|
||||
fun handleSetRemoteConfig(id: Int, num: Int, payload: ByteArray) {
|
||||
fun handleSetRemoteConfig(id: Int, destNum: Int, payload: ByteArray) {
|
||||
val c = ConfigProtos.Config.parseFrom(payload)
|
||||
commandSender.sendAdmin(num, id) { setConfig = c }
|
||||
commandSender.sendAdmin(destNum, id) { setConfig = c }
|
||||
}
|
||||
|
||||
fun handleGetRemoteConfig(id: Int, destNum: Int, config: Int) {
|
||||
|
|
@ -232,9 +232,9 @@ constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun handleSetModuleConfig(id: Int, num: Int, payload: ByteArray) {
|
||||
fun handleSetModuleConfig(id: Int, destNum: Int, payload: ByteArray) {
|
||||
val c = ModuleConfigProtos.ModuleConfig.parseFrom(payload)
|
||||
commandSender.sendAdmin(num, id) { setModuleConfig = c }
|
||||
commandSender.sendAdmin(destNum, id) { setModuleConfig = c }
|
||||
}
|
||||
|
||||
fun handleGetModuleConfig(id: Int, destNum: Int, config: Int) {
|
||||
|
|
@ -264,10 +264,10 @@ constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun handleSetRemoteChannel(id: Int, num: Int, payload: ByteArray?) {
|
||||
fun handleSetRemoteChannel(id: Int, destNum: Int, payload: ByteArray?) {
|
||||
if (payload != null) {
|
||||
val c = ChannelProtos.Channel.parseFrom(payload)
|
||||
commandSender.sendAdmin(num, id) { setChannel = c }
|
||||
commandSender.sendAdmin(destNum, id) { setChannel = c }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,16 +279,16 @@ constructor(
|
|||
commandSender.requestNeighborInfo(requestId, destNum)
|
||||
}
|
||||
|
||||
fun handleBeginEditSettings(myNodeNum: Int) {
|
||||
commandSender.sendAdmin(myNodeNum) { beginEditSettings = true }
|
||||
fun handleBeginEditSettings(destNum: Int) {
|
||||
commandSender.sendAdmin(destNum) { beginEditSettings = true }
|
||||
}
|
||||
|
||||
fun handleCommitEditSettings(myNodeNum: Int) {
|
||||
commandSender.sendAdmin(myNodeNum) { commitEditSettings = true }
|
||||
fun handleCommitEditSettings(destNum: Int) {
|
||||
commandSender.sendAdmin(destNum) { commitEditSettings = true }
|
||||
}
|
||||
|
||||
fun handleRebootToDfu(myNodeNum: Int) {
|
||||
commandSender.sendAdmin(myNodeNum) { enterDfuModeRequest = true }
|
||||
fun handleRebootToDfu(destNum: Int) {
|
||||
commandSender.sendAdmin(destNum) { enterDfuModeRequest = true }
|
||||
}
|
||||
|
||||
fun handleRequestTelemetry(requestId: Int, destNum: Int, type: Int) {
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ class MeshService : Service() {
|
|||
router.actionHandler.handleSetOwner(u, myNodeNum)
|
||||
}
|
||||
|
||||
override fun setRemoteOwner(id: Int, payload: ByteArray) = toRemoteExceptions {
|
||||
router.actionHandler.handleSetRemoteOwner(id, payload, myNodeNum)
|
||||
override fun setRemoteOwner(id: Int, destNum: Int, payload: ByteArray) = toRemoteExceptions {
|
||||
router.actionHandler.handleSetRemoteOwner(id, destNum, payload)
|
||||
}
|
||||
|
||||
override fun getRemoteOwner(id: Int, destNum: Int) = toRemoteExceptions {
|
||||
|
|
@ -275,12 +275,12 @@ class MeshService : Service() {
|
|||
router.actionHandler.handleGetRemoteChannel(id, destNum, index)
|
||||
}
|
||||
|
||||
override fun beginEditSettings() = toRemoteExceptions {
|
||||
router.actionHandler.handleBeginEditSettings(myNodeNum)
|
||||
override fun beginEditSettings(destNum: Int) = toRemoteExceptions {
|
||||
router.actionHandler.handleBeginEditSettings(destNum)
|
||||
}
|
||||
|
||||
override fun commitEditSettings() = toRemoteExceptions {
|
||||
router.actionHandler.handleCommitEditSettings(myNodeNum)
|
||||
override fun commitEditSettings(destNum: Int) = toRemoteExceptions {
|
||||
router.actionHandler.handleCommitEditSettings(destNum)
|
||||
}
|
||||
|
||||
override fun getChannelSet(): ByteArray = toRemoteExceptions {
|
||||
|
|
@ -333,7 +333,9 @@ class MeshService : Service() {
|
|||
router.actionHandler.handleRequestReboot(requestId, destNum)
|
||||
}
|
||||
|
||||
override fun rebootToDfu() = toRemoteExceptions { router.actionHandler.handleRebootToDfu(myNodeNum) }
|
||||
override fun rebootToDfu(destNum: Int) = toRemoteExceptions {
|
||||
router.actionHandler.handleRebootToDfu(destNum)
|
||||
}
|
||||
|
||||
override fun requestFactoryReset(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
router.actionHandler.handleRequestFactoryReset(requestId, destNum)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ interface IMeshService {
|
|||
*/
|
||||
void setOwner(in MeshUser user);
|
||||
|
||||
void setRemoteOwner(in int requestId, in byte []payload);
|
||||
void setRemoteOwner(in int requestId, in int destNum, in byte []payload);
|
||||
void getRemoteOwner(in int requestId, in int destNum);
|
||||
|
||||
/// Return my unique user ID string
|
||||
|
|
@ -109,10 +109,10 @@ interface IMeshService {
|
|||
void getRemoteChannel(in int requestId, in int destNum, in int channelIndex);
|
||||
|
||||
/// Send beginEditSettings admin packet to nodeNum
|
||||
void beginEditSettings();
|
||||
void beginEditSettings(in int destNum);
|
||||
|
||||
/// Send commitEditSettings admin packet to nodeNum
|
||||
void commitEditSettings();
|
||||
void commitEditSettings(in int destNum);
|
||||
|
||||
/// delete a specific nodeNum from nodeDB
|
||||
void removeByNodenum(in int requestID, in int nodeNum);
|
||||
|
|
@ -139,7 +139,7 @@ interface IMeshService {
|
|||
void requestFactoryReset(in int requestId, in int destNum);
|
||||
|
||||
/// Send reboot to DFU admin packet
|
||||
void rebootToDfu();
|
||||
void rebootToDfu(in int destNum);
|
||||
|
||||
/// Send NodedbReset admin packet to nodeNum
|
||||
void requestNodedbReset(in int requestId, in int destNum, in boolean preserveFavorites);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ open class FakeIMeshService : IMeshService.Stub() {
|
|||
|
||||
override fun setOwner(user: MeshUser?) {}
|
||||
|
||||
override fun setRemoteOwner(requestId: Int, payload: ByteArray?) {}
|
||||
override fun setRemoteOwner(requestId: Int, destNum: Int, payload: ByteArray?) {}
|
||||
|
||||
override fun getRemoteOwner(requestId: Int, destNum: Int) {}
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ open class FakeIMeshService : IMeshService.Stub() {
|
|||
|
||||
override fun getRemoteChannel(requestId: Int, destNum: Int, channelIndex: Int) {}
|
||||
|
||||
override fun beginEditSettings() {}
|
||||
override fun beginEditSettings(destNum: Int) {}
|
||||
|
||||
override fun commitEditSettings() {}
|
||||
override fun commitEditSettings(destNum: Int) {}
|
||||
|
||||
override fun removeByNodenum(requestID: Int, nodeNum: Int) {}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ open class FakeIMeshService : IMeshService.Stub() {
|
|||
|
||||
override fun requestFactoryReset(requestId: Int, destNum: Int) {}
|
||||
|
||||
override fun rebootToDfu() {}
|
||||
override fun rebootToDfu(destNum: Int) {}
|
||||
|
||||
override fun requestNodedbReset(requestId: Int, destNum: Int, preserveFavorites: Boolean) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ open class FakeIMeshService : IMeshService.Stub() {
|
|||
|
||||
override fun setOwner(user: MeshUser?) {}
|
||||
|
||||
override fun setRemoteOwner(requestId: Int, payload: ByteArray?) {}
|
||||
override fun setRemoteOwner(requestId: Int, destNum: Int, payload: ByteArray?) {}
|
||||
|
||||
override fun getRemoteOwner(requestId: Int, destNum: Int) {}
|
||||
|
||||
|
|
@ -70,9 +70,9 @@ open class FakeIMeshService : IMeshService.Stub() {
|
|||
|
||||
override fun getRemoteChannel(requestId: Int, destNum: Int, channelIndex: Int) {}
|
||||
|
||||
override fun beginEditSettings() {}
|
||||
override fun beginEditSettings(destNum: Int) {}
|
||||
|
||||
override fun commitEditSettings() {}
|
||||
override fun commitEditSettings(destNum: Int) {}
|
||||
|
||||
override fun removeByNodenum(requestID: Int, nodeNum: Int) {}
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ open class FakeIMeshService : IMeshService.Stub() {
|
|||
|
||||
override fun requestFactoryReset(requestId: Int, destNum: Int) {}
|
||||
|
||||
override fun rebootToDfu() {}
|
||||
override fun rebootToDfu(destNum: Int) {}
|
||||
|
||||
override fun requestNodedbReset(requestId: Int, destNum: Int, preserveFavorites: Boolean) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ constructor(
|
|||
|
||||
if (firmwareUri != null) {
|
||||
updateState(FirmwareUpdateState.Processing(ProgressState(rebootingMsg)))
|
||||
serviceRepository.meshService?.rebootToDfu()
|
||||
val myNodeNum = serviceRepository.meshService?.getMyNodeInfo()?.myNodeNum ?: 0
|
||||
serviceRepository.meshService?.rebootToDfu(myNodeNum)
|
||||
delay(REBOOT_DELAY)
|
||||
|
||||
updateState(FirmwareUpdateState.AwaitingFileSave(null, "firmware.uf2", firmwareUri))
|
||||
|
|
@ -84,7 +85,8 @@ constructor(
|
|||
null
|
||||
} else {
|
||||
updateState(FirmwareUpdateState.Processing(ProgressState(rebootingMsg)))
|
||||
serviceRepository.meshService?.rebootToDfu()
|
||||
val myNodeNum = serviceRepository.meshService?.getMyNodeInfo()?.myNodeNum ?: 0
|
||||
serviceRepository.meshService?.rebootToDfu(myNodeNum)
|
||||
delay(REBOOT_DELAY)
|
||||
|
||||
updateState(FirmwareUpdateState.AwaitingFileSave(firmwareFile, firmwareFile.name))
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ constructor(
|
|||
destNum,
|
||||
{ service, packetId, _ ->
|
||||
_radioConfigState.update { it.copy(userConfig = user) }
|
||||
service.setRemoteOwner(packetId, user.toByteArray())
|
||||
service.setRemoteOwner(packetId, destNum, user.toByteArray())
|
||||
},
|
||||
"Request setOwner error",
|
||||
)
|
||||
|
|
@ -509,50 +509,54 @@ constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun installProfile(protobuf: DeviceProfile) = with(protobuf) {
|
||||
meshService?.beginEditSettings()
|
||||
if (hasLongName() || hasShortName()) {
|
||||
destNode.value?.user?.let {
|
||||
val user =
|
||||
MeshProtos.User.newBuilder()
|
||||
.setId(it.id)
|
||||
.setLongName(if (hasLongName()) longName else it.longName)
|
||||
.setShortName(if (hasShortName()) shortName else it.shortName)
|
||||
.setIsLicensed(it.isLicensed)
|
||||
.build()
|
||||
setOwner(user)
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
fun installProfile(protobuf: DeviceProfile) {
|
||||
val destNum = destNode.value?.num ?: return
|
||||
with(protobuf) {
|
||||
meshService?.beginEditSettings(destNum)
|
||||
if (hasLongName() || hasShortName()) {
|
||||
destNode.value?.user?.let {
|
||||
val user =
|
||||
MeshProtos.User.newBuilder()
|
||||
.setId(it.id)
|
||||
.setLongName(if (hasLongName()) longName else it.longName)
|
||||
.setShortName(if (hasShortName()) shortName else it.shortName)
|
||||
.setIsLicensed(it.isLicensed)
|
||||
.build()
|
||||
setOwner(user)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasChannelUrl()) {
|
||||
try {
|
||||
setChannels(channelUrl)
|
||||
} catch (ex: Exception) {
|
||||
Logger.e(ex) { "DeviceProfile channel import error" }
|
||||
sendError(ex.customMessage)
|
||||
if (hasChannelUrl()) {
|
||||
try {
|
||||
setChannels(channelUrl)
|
||||
} catch (ex: Exception) {
|
||||
Logger.e(ex) { "DeviceProfile channel import error" }
|
||||
sendError(ex.customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasConfig()) {
|
||||
val descriptor = ConfigProtos.Config.getDescriptor()
|
||||
config.allFields.forEach { (field, value) ->
|
||||
val newConfig =
|
||||
ConfigProtos.Config.newBuilder().setField(descriptor.findFieldByName(field.name), value).build()
|
||||
setConfig(newConfig)
|
||||
if (hasConfig()) {
|
||||
val descriptor = ConfigProtos.Config.getDescriptor()
|
||||
config.allFields.forEach { (field, value) ->
|
||||
val newConfig =
|
||||
ConfigProtos.Config.newBuilder().setField(descriptor.findFieldByName(field.name), value).build()
|
||||
setConfig(newConfig)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasFixedPosition()) {
|
||||
setFixedPosition(Position(fixedPosition))
|
||||
}
|
||||
if (hasModuleConfig()) {
|
||||
val descriptor = ModuleConfigProtos.ModuleConfig.getDescriptor()
|
||||
moduleConfig.allFields.forEach { (field, value) ->
|
||||
val newConfig =
|
||||
ModuleConfigProtos.ModuleConfig.newBuilder()
|
||||
.setField(descriptor.findFieldByName(field.name), value)
|
||||
.build()
|
||||
setModuleConfig(newConfig)
|
||||
if (hasFixedPosition()) {
|
||||
setFixedPosition(Position(fixedPosition))
|
||||
}
|
||||
if (hasModuleConfig()) {
|
||||
val descriptor = ModuleConfigProtos.ModuleConfig.getDescriptor()
|
||||
moduleConfig.allFields.forEach { (field, value) ->
|
||||
val newConfig =
|
||||
ModuleConfigProtos.ModuleConfig.newBuilder()
|
||||
.setField(descriptor.findFieldByName(field.name), value)
|
||||
.build()
|
||||
setModuleConfig(newConfig)
|
||||
}
|
||||
}
|
||||
meshService?.commitEditSettings(destNum)
|
||||
}
|
||||
meshService?.commitEditSettings()
|
||||
}
|
||||
|
||||
fun clearPacketResponse() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue