Skip to content

Commit

Permalink
feat: warn user when duty cycle limit reached
Browse files Browse the repository at this point in the history
closes #540
  • Loading branch information
andrekir committed Oct 13, 2023
1 parent e82eb94 commit 8d22a23
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/geeksville/mesh/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class MainActivity : AppCompatActivity(), Logging {
// val messageStr = getText(messageText)

val builder = MaterialAlertDialogBuilder(this)
.setCancelable(false)
.setTitle(titleText)
.setMessage(messageText)
.setPositiveButton(R.string.okay) { _, _ ->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/geeksville/mesh/model/UIState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -143,6 +144,11 @@ class UIViewModel @Inject constructor(
private val requestIds = MutableStateFlow<HashMap<Int, Boolean>>(hashMapOf())

init {
radioInterfaceService.errorMessage.filterNotNull().onEach {
_snackbarText.value = it
radioInterfaceService.clearErrorMessage()
}.launchIn(viewModelScope)

radioConfigRepository.nodeInfoFlow().onEach(nodeDB::setNodes)
.launchIn(viewModelScope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class RadioInterfaceService @Inject constructor(
private val _receivedData = MutableSharedFlow<ByteArray>()
val receivedData: SharedFlow<ByteArray> = _receivedData

private val _errorMessage = MutableStateFlow<String?>(null)
val errorMessage: SharedFlow<String?> = _errorMessage

fun setErrorMessage(text: String) {
errormsg(text)
_errorMessage.value = text
}

fun clearErrorMessage() {
_errorMessage.value = null
}

private val logSends = false
private val logReceives = false
private lateinit var sentPacketsLog: BinaryLogFile // inited in onCreate
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/geeksville/mesh/service/MeshService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,16 @@ class MeshService : Service(), Logging {
handleReceivedTelemetry(packet.from, u, dataPacket.time)
}

// Handle new style routing info
Portnums.PortNum.ROUTING_APP_VALUE -> {
shouldBroadcast =
true // We always send acks to other apps, because they might care about the messages they sent
// We always send ACKs to other apps, because they might care about the messages they sent
shouldBroadcast = true
val u = MeshProtos.Routing.parseFrom(data.payload)
val isAck = u.errorReasonValue == MeshProtos.Routing.Error.NONE_VALUE

if (u.errorReason == MeshProtos.Routing.Error.DUTY_CYCLE_LIMIT) {
radioInterfaceService.setErrorMessage(getString(R.string.error_duty_cycle))
}

handleAckNak(isAck, fromId, data.requestId)
queueResponse.remove(data.requestId)?.complete(true)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@
<string name="waypoint_delete">Delete waypoint?</string>
<string name="waypoint_new">New waypoint</string>
<string name="waypoint_received">Received waypoint: %s</string>
<string name="error_duty_cycle">Duty Cycle limit reached. Cannot send messages right now, please try again later.</string>
</resources>

0 comments on commit 8d22a23

Please sign in to comment.