sforkowany z mirror/meshtastic-android
feat: implement `PacketResponseState.Success` (#634)
rodzic
b9be26e344
commit
c3ab3c5ae9
|
@ -127,16 +127,16 @@ interface IMeshService {
|
|||
void requestTraceroute(in int requestId, in int destNum);
|
||||
|
||||
/// Send Shutdown admin packet to nodeNum
|
||||
void requestShutdown(in int destNum);
|
||||
void requestShutdown(in int requestId, in int destNum);
|
||||
|
||||
/// Send Reboot admin packet to nodeNum
|
||||
void requestReboot(in int destNum);
|
||||
void requestReboot(in int requestId, in int destNum);
|
||||
|
||||
/// Send FactoryReset admin packet to nodeNum
|
||||
void requestFactoryReset(in int destNum);
|
||||
void requestFactoryReset(in int requestId, in int destNum);
|
||||
|
||||
/// Send NodedbReset admin packet to nodeNum
|
||||
void requestNodedbReset(in int destNum);
|
||||
void requestNodedbReset(in int requestId, in int destNum);
|
||||
|
||||
/// Returns a ChannelSet protobuf
|
||||
byte []getChannelSet();
|
||||
|
|
|
@ -299,6 +299,30 @@ class UIViewModel @Inject constructor(
|
|||
"Request traceroute error"
|
||||
)
|
||||
|
||||
fun requestShutdown(destNum: Int) = request(
|
||||
destNum,
|
||||
{ service, packetId, dest -> service.requestShutdown(packetId, dest) },
|
||||
"Request shutdown error"
|
||||
)
|
||||
|
||||
fun requestReboot(destNum: Int) = request(
|
||||
destNum,
|
||||
{ service, packetId, dest -> service.requestReboot(packetId, dest) },
|
||||
"Request reboot error"
|
||||
)
|
||||
|
||||
fun requestFactoryReset(destNum: Int) = request(
|
||||
destNum,
|
||||
{ service, packetId, dest -> service.requestFactoryReset(packetId, dest) },
|
||||
"Request factory reset error"
|
||||
)
|
||||
|
||||
fun requestNodedbReset(destNum: Int) = request(
|
||||
destNum,
|
||||
{ service, packetId, dest -> service.requestNodedbReset(packetId, dest) },
|
||||
"Request NodeDB reset error"
|
||||
)
|
||||
|
||||
fun requestPosition(destNum: Int, position: Position = Position(0.0, 0.0, 0)) {
|
||||
try {
|
||||
meshService?.requestPosition(destNum, position)
|
||||
|
@ -515,38 +539,6 @@ class UIViewModel @Inject constructor(
|
|||
val adminChannelIndex: Int
|
||||
get() = channelSet.settingsList.map { it.name.lowercase() }.indexOf("admin")
|
||||
|
||||
fun requestShutdown(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestShutdown(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun requestReboot(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestReboot(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun requestFactoryReset(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestFactoryReset(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun requestNodedbReset(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestNodedbReset(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the persisted packet data out to a CSV file in the specified location.
|
||||
*/
|
||||
|
|
|
@ -1788,26 +1788,26 @@ class MeshService : Service(), Logging {
|
|||
})
|
||||
}
|
||||
|
||||
override fun requestShutdown(idNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
override fun requestShutdown(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket(id = requestId) {
|
||||
shutdownSeconds = 5
|
||||
})
|
||||
}
|
||||
|
||||
override fun requestReboot(idNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
override fun requestReboot(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket(id = requestId) {
|
||||
rebootSeconds = 5
|
||||
})
|
||||
}
|
||||
|
||||
override fun requestFactoryReset(idNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
override fun requestFactoryReset(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket(id = requestId) {
|
||||
factoryReset = 1
|
||||
})
|
||||
}
|
||||
|
||||
override fun requestNodedbReset(idNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
override fun requestNodedbReset(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket(id = requestId) {
|
||||
nodedbReset = 1
|
||||
})
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
val configResponse by viewModel.packetResponse.collectAsStateWithLifecycle()
|
||||
val deviceProfile by viewModel.deviceProfile.collectAsStateWithLifecycle()
|
||||
var packetResponseState by remember { mutableStateOf<PacketResponseState>(PacketResponseState.Empty) }
|
||||
val isWaiting = packetResponseState is PacketResponseState.Loading
|
||||
val isWaiting = packetResponseState !is PacketResponseState.Empty
|
||||
var showEditDeviceProfileDialog by remember { mutableStateOf(false) }
|
||||
|
||||
val importConfigLauncher = rememberLauncherForActivityResult(
|
||||
|
@ -237,7 +237,7 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
}
|
||||
)
|
||||
|
||||
if (isWaiting || packetResponseState is PacketResponseState.Error) PacketResponseStateDialog(
|
||||
if (isWaiting) PacketResponseStateDialog(
|
||||
packetResponseState,
|
||||
onDismiss = {
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
|
@ -249,8 +249,11 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
val data = configResponse?.meshPacket?.decoded
|
||||
if (data?.portnumValue == Portnums.PortNum.ROUTING_APP_VALUE) {
|
||||
val parsed = MeshProtos.Routing.parseFrom(data.payload)
|
||||
if (parsed.errorReason != MeshProtos.Routing.Error.NONE)
|
||||
packetResponseState = PacketResponseState.Error(parsed.errorReason.toString())
|
||||
packetResponseState = if (parsed.errorReason == MeshProtos.Routing.Error.NONE) {
|
||||
PacketResponseState.Success(emptyList())
|
||||
} else {
|
||||
PacketResponseState.Error(parsed.errorReason.toString())
|
||||
}
|
||||
}
|
||||
if (data?.portnumValue == Portnums.PortNum.ADMIN_APP_VALUE) {
|
||||
viewModel.clearPacketResponse()
|
||||
|
@ -267,24 +270,24 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
viewModel.getChannel(destNum, response.index + 1)
|
||||
} else {
|
||||
// Received the last channel, start channel editor
|
||||
packetResponseState = PacketResponseState.Success(emptyList())
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
navController.navigate("channels")
|
||||
}
|
||||
} else {
|
||||
// Received max channels, start channel editor
|
||||
packetResponseState = PacketResponseState.Success(emptyList())
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
navController.navigate("channels")
|
||||
}
|
||||
}
|
||||
|
||||
AdminProtos.AdminMessage.PayloadVariantCase.GET_OWNER_RESPONSE -> {
|
||||
packetResponseState = PacketResponseState.Success(emptyList())
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
userConfig = parsed.getOwnerResponse
|
||||
navController.navigate("user")
|
||||
}
|
||||
|
||||
AdminProtos.AdminMessage.PayloadVariantCase.GET_CONFIG_RESPONSE -> {
|
||||
packetResponseState = PacketResponseState.Success(emptyList())
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
val response = parsed.getConfigResponse
|
||||
radioConfig = response
|
||||
enumValues<ConfigDest>().find { it.name == "${response.payloadVariantCase}" }
|
||||
|
@ -292,7 +295,7 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
}
|
||||
|
||||
AdminProtos.AdminMessage.PayloadVariantCase.GET_MODULE_CONFIG_RESPONSE -> {
|
||||
packetResponseState = PacketResponseState.Success(emptyList())
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
val response = parsed.getModuleConfigResponse
|
||||
moduleConfig = response
|
||||
enumValues<ModuleDest>().find { it.name == "${response.payloadVariantCase}" }
|
||||
|
@ -350,22 +353,18 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
|
|||
}
|
||||
|
||||
"REBOOT" -> {
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
viewModel.requestReboot(destNum)
|
||||
}
|
||||
|
||||
"SHUTDOWN" -> {
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
viewModel.requestShutdown(destNum)
|
||||
}
|
||||
|
||||
"FACTORY_RESET" -> {
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
viewModel.requestFactoryReset(destNum)
|
||||
}
|
||||
|
||||
"NODEDB_RESET" -> {
|
||||
packetResponseState = PacketResponseState.Empty
|
||||
viewModel.requestNodedbReset(destNum)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ fun PacketResponseStateDialog(
|
|||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { },
|
||||
text = {
|
||||
title = {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
@ -42,6 +42,9 @@ fun PacketResponseStateDialog(
|
|||
color = MaterialTheme.colors.onSurface,
|
||||
)
|
||||
}
|
||||
if (state is PacketResponseState.Success) {
|
||||
Text("Success!")
|
||||
}
|
||||
if (state is PacketResponseState.Error) {
|
||||
Text("Error: ${state.error}")
|
||||
}
|
||||
|
@ -54,7 +57,7 @@ fun PacketResponseStateDialog(
|
|||
) {
|
||||
Button(
|
||||
onClick = onDismiss,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
modifier = Modifier.padding(top = 16.dp)
|
||||
) {
|
||||
if (state is PacketResponseState.Loading) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
|
|
Ładowanie…
Reference in New Issue