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