Skip to content

Commit

Permalink
fix: incrementCompleted() placement
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Oct 1, 2023
1 parent d4659ec commit 50e794e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/com/geeksville/mesh/model/UIState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,8 @@ class UIViewModel @Inject constructor(
}

private fun processPacketResponse(log: MeshLog?) {
val destNum = destNode.value?.num ?: return
val packet = log?.meshPacket ?: return
val data = packet.decoded
val destStr = destNum.toUInt()
val fromStr = packet.from.toUInt()
requestId.value = null

Expand All @@ -875,11 +873,14 @@ class UIViewModel @Inject constructor(
append(nodeName(packet.from))
}
}
val destNum = destNode.value?.num ?: return
val destStr = destNum.toUInt()

if (data?.portnumValue == Portnums.PortNum.ROUTING_APP_VALUE) {
val parsed = MeshProtos.Routing.parseFrom(data.payload)
debug("packet for destNum $destStr received ${parsed.errorReason} from $fromStr")
if (parsed.errorReason != MeshProtos.Routing.Error.NONE) {
setResponseStateError(parsed.errorReason.toString())
setResponseStateError(parsed.errorReason.name)
} else if (packet.from == destNum) {
_radioConfigState.update { it.copy(responseState = ResponseState.Success(true)) }
}
Expand All @@ -896,7 +897,6 @@ class UIViewModel @Inject constructor(
when (parsed.payloadVariantCase) {
AdminProtos.AdminMessage.PayloadVariantCase.GET_CHANNEL_RESPONSE -> {
val response = parsed.getChannelResponse
incrementCompleted()
// Stop once we get to the first disabled entry
if (response.role != ChannelProtos.Channel.Role.DISABLED) {
_radioConfigState.update { state ->
Expand All @@ -905,6 +905,7 @@ class UIViewModel @Inject constructor(
}
state.copy(channelList = updatedList)
}
incrementCompleted()
if (response.index + 1 < maxChannels && goChannels) {
// Not done yet, request next channel
getChannel(destNum, response.index + 1)
Expand All @@ -914,7 +915,7 @@ class UIViewModel @Inject constructor(
}
} else {
// Received last channel, get lora config (for default channel names)
setResponseStateTotal(radioConfigState.value.channelList.size + 1)
setResponseStateTotal(response.index + 1)
getConfig(destNum, AdminProtos.AdminMessage.ConfigType.LORA_CONFIG_VALUE)
}
}
Expand Down

0 comments on commit 50e794e

Please sign in to comment.