feat: Add Status Message module support (#4163)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich
2026-01-25 08:15:47 -06:00
committed by GitHub
parent df592d4d86
commit 355d2260e8
15 changed files with 1195 additions and 9 deletions

View File

@@ -59,6 +59,7 @@ import org.meshtastic.feature.settings.radio.component.RangeTestConfigScreen
import org.meshtastic.feature.settings.radio.component.RemoteHardwareConfigScreen
import org.meshtastic.feature.settings.radio.component.SecurityConfigScreen
import org.meshtastic.feature.settings.radio.component.SerialConfigScreen
import org.meshtastic.feature.settings.radio.component.StatusMessageConfigScreen
import org.meshtastic.feature.settings.radio.component.StoreForwardConfigScreen
import org.meshtastic.feature.settings.radio.component.TelemetryConfigScreen
import org.meshtastic.feature.settings.radio.component.UserConfigScreen
@@ -163,6 +164,9 @@ fun NavGraphBuilder.settingsGraph(navController: NavHostController) {
DetectionSensorConfigScreen(viewModel, onBack = navController::popBackStack)
ModuleRoute.PAXCOUNTER -> PaxcounterConfigScreen(viewModel, onBack = navController::popBackStack)
ModuleRoute.STATUS_MESSAGE ->
StatusMessageConfigScreen(viewModel, onBack = navController::popBackStack)
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Meshtastic LLC
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.geeksville.mesh.repository.radio
import co.touchlab.kermit.Logger
@@ -32,12 +31,14 @@ import org.meshtastic.proto.ChannelProtos
import org.meshtastic.proto.ConfigKt
import org.meshtastic.proto.ConfigProtos
import org.meshtastic.proto.MeshProtos
import org.meshtastic.proto.ModuleConfigProtos
import org.meshtastic.proto.Portnums
import org.meshtastic.proto.TelemetryProtos
import org.meshtastic.proto.channel
import org.meshtastic.proto.config
import org.meshtastic.proto.deviceMetadata
import org.meshtastic.proto.fromRadio
import org.meshtastic.proto.moduleConfig
import org.meshtastic.proto.queueStatus
import kotlin.random.Random
@@ -108,6 +109,16 @@ constructor(
}
}
d.getModuleConfigRequest == AdminProtos.AdminMessage.ModuleConfigType.STATUSMESSAGE_CONFIG ->
sendAdmin(pr.packet.to, pr.packet.from, pr.packet.id) {
getModuleConfigResponse = moduleConfig {
statusmessage =
ModuleConfigProtos.ModuleConfig.StatusMessageConfig.newBuilder()
.setNodeStatus("Going to the farm.. to grow wheat.")
.build()
}
}
else -> Logger.i { "Ignoring admin sent to mock interface $d" }
}
}
@@ -240,6 +251,30 @@ constructor(
.build()
}
private fun makeNodeStatus(numIn: Int) = MeshProtos.FromRadio.newBuilder().apply {
packet =
MeshProtos.MeshPacket.newBuilder()
.apply {
id = packetIdSequence.next()
from = numIn
to = 0xffffffff.toInt() // broadcast
rxTime = (System.currentTimeMillis() / 1000).toInt()
rxSnr = 1.5f
decoded =
MeshProtos.Data.newBuilder()
.apply {
portnum = Portnums.PortNum.NODE_STATUS_APP
payload =
MeshProtos.StatusMessage.newBuilder()
.setStatus("Going to the farm.. to grow wheat.")
.build()
.toByteString()
}
.build()
}
.build()
}
private fun makeDataPacket(fromIn: Int, toIn: Int, data: MeshProtos.Data.Builder) =
MeshProtos.FromRadio.newBuilder().apply {
packet =
@@ -356,6 +391,7 @@ constructor(
makeNeighborInfo(MY_NODE + 1),
makePosition(MY_NODE + 1),
makeTelemetry(MY_NODE + 1),
makeNodeStatus(MY_NODE + 1),
)
packets.forEach { p -> service.handleFromRadio(p.build().toByteArray()) }

View File

@@ -95,6 +95,7 @@ constructor(
Portnums.PortNum.TEXT_MESSAGE_APP_VALUE,
Portnums.PortNum.ALERT_APP_VALUE,
Portnums.PortNum.WAYPOINT_APP_VALUE,
Portnums.PortNum.NODE_STATUS_APP_VALUE,
)
fun handleReceivedData(packet: MeshPacket, myNodeNum: Int, logUuid: String? = null, logInsertJob: Job? = null) {
@@ -121,6 +122,7 @@ constructor(
var shouldBroadcast = !fromUs
when (packet.decoded.portnumValue) {
Portnums.PortNum.TEXT_MESSAGE_APP_VALUE -> handleTextMessage(packet, dataPacket, myNodeNum)
Portnums.PortNum.NODE_STATUS_APP_VALUE -> handleNodeStatus(packet, dataPacket, myNodeNum)
Portnums.PortNum.ALERT_APP_VALUE -> rememberDataPacket(dataPacket, myNodeNum)
Portnums.PortNum.WAYPOINT_APP_VALUE -> handleWaypoint(packet, dataPacket, myNodeNum)
Portnums.PortNum.POSITION_APP_VALUE -> handlePosition(packet, dataPacket, myNodeNum)
@@ -331,6 +333,12 @@ constructor(
nodeManager.handleReceivedUser(packet.from, u, packet.channel)
}
private fun handleNodeStatus(packet: MeshPacket, dataPacket: DataPacket, myNodeNum: Int) {
val s = MeshProtos.StatusMessage.parseFrom(packet.decoded.payload)
nodeManager.handleReceivedNodeStatus(packet.from, s)
rememberDataPacket(dataPacket, myNodeNum)
}
private fun handleTelemetry(packet: MeshPacket, dataPacket: DataPacket, myNodeNum: Int) {
val t =
TelemetryProtos.Telemetry.parseFrom(packet.decoded.payload).copy {

View File

@@ -209,6 +209,10 @@ constructor(
updateNodeInfo(fromNum) { it.paxcounter = p }
}
fun handleReceivedNodeStatus(fromNum: Int, s: MeshProtos.StatusMessage) {
updateNodeInfo(fromNum) { it.nodeStatus = s.status }
}
fun installNodeInfo(info: MeshProtos.NodeInfo, withBroadcast: Boolean = true) {
updateNodeInfo(info.num, withBroadcast = withBroadcast) { entity ->
if (info.hasUser()) {

View File

File diff suppressed because it is too large Load Diff

View File

@@ -91,8 +91,9 @@ import org.meshtastic.core.database.entity.TracerouteNodePositionEntity
AutoMigration(from = 30, to = 31),
AutoMigration(from = 31, to = 32),
AutoMigration(from = 32, to = 33),
AutoMigration(from = 33, to = 34),
],
version = 33,
version = 34,
exportSchema = true,
)
@TypeConverters(Converters::class)

View File

@@ -62,6 +62,7 @@ data class NodeWithRelations(
paxcounter = paxcounter,
notes = notes,
manuallyVerified = manuallyVerified,
nodeStatus = nodeStatus,
)
}
@@ -85,6 +86,7 @@ data class NodeWithRelations(
paxcounter = paxcounter,
notes = notes,
manuallyVerified = manuallyVerified,
nodeStatus = nodeStatus,
)
}
}
@@ -139,6 +141,7 @@ data class NodeEntity(
@ColumnInfo(name = "notes", defaultValue = "") var notes: String = "",
@ColumnInfo(name = "manually_verified", defaultValue = "0")
var manuallyVerified: Boolean = false, // ONLY set true when scanned/imported manually
@ColumnInfo(name = "node_status") var nodeStatus: String? = null,
) {
val deviceMetrics: TelemetryProtos.DeviceMetrics
get() = deviceTelemetry.deviceMetrics
@@ -194,6 +197,7 @@ data class NodeEntity(
paxcounter = paxcounter,
publicKey = publicKey ?: user.publicKey,
notes = notes,
nodeStatus = nodeStatus,
)
fun toNodeInfo() = NodeInfo(

View File

@@ -55,6 +55,7 @@ data class Node(
val publicKey: ByteString? = null,
val notes: String = "",
val manuallyVerified: Boolean = false,
val nodeStatus: String? = null,
) {
val capabilities: Capabilities by lazy { Capabilities(metadata?.firmwareVersion) }

View File

@@ -90,10 +90,11 @@ data class DataPacket(
/** If this is a text message, return the string, otherwise null */
val text: String?
get() =
if (dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE) {
bytes?.decodeToString()
} else {
null
when (dataType) {
Portnums.PortNum.TEXT_MESSAGE_APP_VALUE -> bytes?.decodeToString()
// Portnums.PortNum.NODE_STATUS_APP_VALUE ->
// MeshProtos.StatusMessage.parseFrom(bytes).status
else -> null
}
val alert: String?

View File

@@ -141,6 +141,8 @@ object SettingsRoutes {
@Serializable data object Paxcounter : Route
@Serializable data object StatusMessage : Route
// endregion
// region advanced config routes

View File

@@ -659,6 +659,9 @@
<string name="subnet">Subnet</string>
<string name="paxcounter_config">Paxcounter Config</string>
<string name="paxcounter_enabled">Paxcounter enabled</string>
<string name="status_message">Status Message</string>
<string name="status_message_config">Status Message Config</string>
<string name="node_status_summary">The actual status string</string>
<string name="wifi_rssi_threshold_defaults_to_80">WiFi RSSI threshold (defaults to -80)</string>
<string name="ble_rssi_threshold_defaults_to_80">BLE RSSI threshold (defaults to -80)</string>
<string name="position_config">Position</string>

View File

@@ -40,6 +40,7 @@ import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.SignalCellularAlt
import androidx.compose.material.icons.filled.Verified
import androidx.compose.material.icons.filled.Work
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
@@ -128,6 +129,7 @@ private fun MismatchKeyWarning(modifier: Modifier = Modifier) {
}
}
@Suppress("LongMethod")
@Composable
private fun MainNodeDetails(node: Node) {
Column {
@@ -149,6 +151,19 @@ private fun MainNodeDetails(node: Node) {
SectionDivider()
PublicKeyItem(publicKey.toByteArray())
}
if (!node.nodeStatus.isNullOrEmpty()) {
HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f))
Row(modifier = Modifier.fillMaxWidth()) {
InfoItem(
label = "Status",
value = node.nodeStatus!!,
icon = Icons.Default.CheckCircle,
modifier = Modifier.weight(1f),
)
}
}
}
}

View File

@@ -199,6 +199,17 @@ fun NodeItem(
}
}
}
if (!thatNode.nodeStatus.isNullOrEmpty()) {
Spacer(modifier = Modifier.height(2.dp))
Text(
text = thatNode.nodeStatus!!,
style = MaterialTheme.typography.bodySmall,
color = contentColor,
maxLines = 2,
)
}
Spacer(modifier = Modifier.height(2.dp))
Row(
modifier = Modifier.fillMaxWidth(),

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Meshtastic LLC
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.feature.settings.navigation
import androidx.compose.material.icons.Icons
@@ -47,6 +46,7 @@ import org.meshtastic.core.strings.paxcounter
import org.meshtastic.core.strings.range_test
import org.meshtastic.core.strings.remote_hardware
import org.meshtastic.core.strings.serial
import org.meshtastic.core.strings.status_message
import org.meshtastic.core.strings.store_forward
import org.meshtastic.core.strings.telemetry
import org.meshtastic.proto.AdminProtos
@@ -131,6 +131,12 @@ enum class ModuleRoute(val title: StringResource, val route: Route, val icon: Im
Icons.Default.PermScanWifi,
AdminProtos.AdminMessage.ModuleConfigType.PAXCOUNTER_CONFIG_VALUE,
),
STATUS_MESSAGE(
Res.string.status_message,
SettingsRoutes.StatusMessage,
Icons.AutoMirrored.Default.Message,
AdminProtos.AdminMessage.ModuleConfigType.STATUSMESSAGE_CONFIG_VALUE,
),
;
val bitfield: Int

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.feature.settings.radio.component
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.jetbrains.compose.resources.stringResource
import org.meshtastic.core.strings.Res
import org.meshtastic.core.strings.node_status_summary
import org.meshtastic.core.strings.status_message
import org.meshtastic.core.strings.status_message_config
import org.meshtastic.core.ui.component.EditTextPreference
import org.meshtastic.core.ui.component.TitledCard
import org.meshtastic.feature.settings.radio.RadioConfigViewModel
import org.meshtastic.proto.copy
import org.meshtastic.proto.moduleConfig
@Composable
fun StatusMessageConfigScreen(viewModel: RadioConfigViewModel = hiltViewModel(), onBack: () -> Unit) {
val state by viewModel.radioConfigState.collectAsStateWithLifecycle()
val statusMessageConfig = state.moduleConfig.statusmessage
val formState = rememberConfigState(initialValue = statusMessageConfig)
val focusManager = LocalFocusManager.current
RadioConfigScreenList(
title = stringResource(Res.string.status_message),
onBack = onBack,
configState = formState,
enabled = state.connected,
responseState = state.responseState,
onDismissPacketResponse = viewModel::clearPacketResponse,
onSave = {
val config = moduleConfig { statusmessage = it }
viewModel.setModuleConfig(config)
},
) {
item {
TitledCard(title = stringResource(Res.string.status_message_config)) {
EditTextPreference(
title = stringResource(Res.string.node_status_summary),
value = formState.value.nodeStatus,
maxSize = 80, // status_message max_size:80
enabled = state.connected,
isError = false,
keyboardOptions =
KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { formState.value = formState.value.copy { nodeStatus = it } },
)
}
}
}
}