From 0f69a791b5c1982bd7dc1d0f4e9f079fe371c4d0 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Wed, 20 Nov 2024 12:32:19 +1300 Subject: [PATCH] if channel name is empty, use the modem preset display name instead --- src/components/channels/ChannelsList.vue | 7 ++- src/components/pages/ChannelMessagesPage.vue | 7 ++- src/js/ChannelUtils.js | 55 +++++++++++++++++++- src/js/Connection.js | 7 +++ src/js/GlobalState.js | 1 + 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/components/channels/ChannelsList.vue b/src/components/channels/ChannelsList.vue index 885acf2..1893f04 100644 --- a/src/components/channels/ChannelsList.vue +++ b/src/components/channels/ChannelsList.vue @@ -4,10 +4,7 @@
-
- {{ channel.settings.name }} - (No Name) -
+
{{ getChannelName(channel.index) }}
Primary Channel Secondary Channel @@ -30,6 +27,7 @@ import { Protobuf, } from "@meshtastic/js"; import ChannelPskBadge from "./ChannelPskBadge.vue"; +import ChannelUtils from "../../js/ChannelUtils.js"; export default { name: 'ChannelsList', components: {ChannelPskBadge}, @@ -46,6 +44,7 @@ export default { }; }, methods: { + getChannelName: (channelId) => ChannelUtils.getChannelName(channelId), onChannelClick(channel) { this.$emit("channel-click", channel); }, diff --git a/src/components/pages/ChannelMessagesPage.vue b/src/components/pages/ChannelMessagesPage.vue index 964e830..dd991cb 100644 --- a/src/components/pages/ChannelMessagesPage.vue +++ b/src/components/pages/ChannelMessagesPage.vue @@ -29,6 +29,7 @@ import Page from "./Page.vue"; import ChannelPskBadge from "../channels/ChannelPskBadge.vue"; import IconButton from "../IconButton.vue"; import Database from "../../js/Database.js"; +import ChannelUtils from "../../js/ChannelUtils.js"; export default { name: 'ChannelMessagesPage', @@ -54,6 +55,7 @@ export default { }, methods: { + getChannelName: (channelId) => ChannelUtils.getChannelName(channelId), async deleteMessageHistory() { // confirm user wants to delete message history @@ -71,7 +73,10 @@ export default { return GlobalState.channelsByIndex[this.channelId]; }, subtitle() { - return this.channel?.settings?.name || '(No Name)'; + if(this.channel){ + return this.getChannelName(this.channel.index); + } + return "Unknown Channel"; }, }, } diff --git a/src/js/ChannelUtils.js b/src/js/ChannelUtils.js index 3b6a42f..ec6331d 100644 --- a/src/js/ChannelUtils.js +++ b/src/js/ChannelUtils.js @@ -1,10 +1,63 @@ import GlobalState from "./GlobalState.js"; +import {Protobuf} from "@meshtastic/js"; class ChannelUtils { + // https://github.com/meshtastic/firmware/blob/2b0113ae82f2dc5cde82e5c00921d41d10ac141d/src/mesh/Channels.cpp#L294 static getChannelName(channelId) { + + // get channel name from channel settings + const channel = GlobalState.channelsByIndex[channelId]; + var channelName = channel?.settings?.name; + + // if channel name is empty, determine what the name should be based on modem preset + if(channelName === ""){ + if(GlobalState.loraConfig?.usePreset === true){ + channelName = this.getModemPresetDisplayName(GlobalState.loraConfig.modemPreset); + } else { + channelName = "Custom"; + } + } + + return channelName; + + } + + static getModemPresetDisplayName(modemPreset) { + switch(modemPreset){ + case Protobuf.Config.Config_LoRaConfig_ModemPreset.SHORT_TURBO: return "ShortTurbo"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.SHORT_SLOW: return "ShortSlow"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.SHORT_FAST: return "ShortFast"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.MEDIUM_SLOW: return "MediumSlow"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.MEDIUM_FAST: return "MediumFast"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.LONG_SLOW: return "LongSlow"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.LONG_FAST: return "LongFast"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.LONG_MODERATE: return "LongMod"; + case Protobuf.Config.Config_LoRaConfig_ModemPreset.VERY_LONG_SLOW: return "VLongSlow"; + default: return "Invalid"; + } + } + + // https://github.com/meshtastic/firmware/blob/2b0113ae82f2dc5cde82e5c00921d41d10ac141d/src/mesh/Channels.cpp#L312 + static isDefaultChannel(channelId) { + + // find channel by id const channel = GlobalState.channelsByIndex[channelId]; - return channel?.settings?.name; + if(!channel){ + return false; + } + + // check if channel has default key + const hasDefaultPsk = channel.settings.psk.length === 1 && channel.settings.psk[0] === 1; + + // check if channel has default display name + const channelName = this.getChannelName(channelId); + const modemPresetDisplayName = this.getModemPresetDisplayName(GlobalState.loraConfig?.modemPreset); + const hasDefaultDisplayName = channelName === modemPresetDisplayName; + + // channel is a default channel if it is using the default key and default display name + return hasDefaultPsk && hasDefaultDisplayName; + } } diff --git a/src/js/Connection.js b/src/js/Connection.js index 5c10849..6720d81 100644 --- a/src/js/Connection.js +++ b/src/js/Connection.js @@ -150,6 +150,13 @@ class Connection { GlobalState.deviceStatus = deviceStatus; }); + // listen for lora config + connection.events.onConfigPacket.subscribe((configPacket) => { + if(configPacket.payloadVariant.case.toString() === "lora"){ + GlobalState.loraConfig = configPacket.payloadVariant.value; + } + }); + // listen for packets from radio // we use this for some packets that don't have their own event listener connection.events.onFromRadio.subscribe(async (data) => { diff --git a/src/js/GlobalState.js b/src/js/GlobalState.js index 7b2706e..17aa749 100644 --- a/src/js/GlobalState.js +++ b/src/js/GlobalState.js @@ -12,6 +12,7 @@ const globalState = reactive({ myNodeId: null, myNodeUser: null, + loraConfig: null, channelsByIndex: {}, nodesById: {},