diff --git a/plugins/channeltx/modmeshtastic/meshtasticmod.cpp b/plugins/channeltx/modmeshtastic/meshtasticmod.cpp index 72bc3005e..2670982e8 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmod.cpp +++ b/plugins/channeltx/modmeshtastic/meshtasticmod.cpp @@ -205,76 +205,9 @@ void MeshtasticMod::setCenterFrequency(qint64 frequency) } } -bool MeshtasticMod::applyMeshtasticRadioSettingsIfPresent(MeshtasticModSettings& settings) const -{ - if (settings.m_codingScheme != MeshtasticModSettings::CodingLoRa) { - return false; - } - - if (!modemmeshtastic::Packet::isCommand(settings.m_textMessage)) { - return false; - } - - modemmeshtastic::TxRadioSettings meshRadio; - QString error; - if (!modemmeshtastic::Packet::deriveTxRadioSettings(settings.m_textMessage, meshRadio, error)) - { - qWarning() << "MeshtasticMod::applyMeshtasticRadioSettingsIfPresent:" << error; - return false; - } - - bool changed = false; - - if ((meshRadio.spreadFactor > 0) && (meshRadio.spreadFactor != settings.m_spreadFactor)) { - settings.m_spreadFactor = meshRadio.spreadFactor; - changed = true; - } - - if ((meshRadio.parityBits > 0) && (meshRadio.parityBits != settings.m_nbParityBits)) { - settings.m_nbParityBits = meshRadio.parityBits; - changed = true; - } - - if (meshRadio.deBits != settings.m_deBits) { - settings.m_deBits = meshRadio.deBits; - changed = true; - } - - if (meshRadio.syncWord != settings.m_syncWord) { - settings.m_syncWord = meshRadio.syncWord; - changed = true; - } - - if (meshRadio.hasCenterFrequency && (m_deviceAPI != nullptr)) - { - const QList centerFrequencies = m_deviceAPI->getCenterFrequency(); - const int streamIndex = std::max(0, settings.m_streamIndex); - const int selectedIndex = (streamIndex < centerFrequencies.size()) ? streamIndex : 0; - - if (!centerFrequencies.isEmpty()) - { - const qint64 deviceCenterFrequency = static_cast(centerFrequencies.at(selectedIndex)); - const qint64 wantedOffset = meshRadio.centerFrequencyHz - deviceCenterFrequency; - - if (wantedOffset != settings.m_inputFrequencyOffset) - { - settings.m_inputFrequencyOffset = static_cast(wantedOffset); - changed = true; - } - } - } - - if (changed) { - qInfo() << "MeshtasticMod::applyMeshtasticRadioSettingsIfPresent:" << meshRadio.summary; - } - - return changed; -} - void MeshtasticMod::applySettings(const MeshtasticModSettings& incomingSettings, bool force) { MeshtasticModSettings settings(incomingSettings); - applyMeshtasticRadioSettingsIfPresent(settings); qDebug() << "MeshtasticMod::applySettings:" << " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset diff --git a/plugins/channeltx/modmeshtastic/meshtasticmod.h b/plugins/channeltx/modmeshtastic/meshtasticmod.h index 3641f0f75..a6af59ed0 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmod.h +++ b/plugins/channeltx/modmeshtastic/meshtasticmod.h @@ -213,7 +213,6 @@ private: void openUDP(const MeshtasticModSettings& settings); void closeUDP(); void sendCurrentSettingsMessage(); - bool applyMeshtasticRadioSettingsIfPresent(MeshtasticModSettings& settings) const; private slots: void networkManagerFinished(QNetworkReply *reply); diff --git a/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp b/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp index ab2bc9341..2cd1249d5 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp +++ b/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp @@ -203,91 +203,6 @@ bool MeshtasticModGUI::retuneDeviceToFrequency(qint64 centerFrequencyHz) return false; } -void MeshtasticModGUI::applyMeshtasticRadioSettingsIfPresent(const QString& payloadText) -{ - if (m_settings.m_codingScheme != MeshtasticModSettings::CodingLoRa) { - return; - } - - if (!modemmeshtastic::Packet::isCommand(payloadText)) { - return; - } - - modemmeshtastic::TxRadioSettings meshRadio; - QString error; - if (!modemmeshtastic::Packet::deriveTxRadioSettings(payloadText, meshRadio, error)) - { - qWarning() << "MeshtasticModGUI::applyMeshtasticRadioSettingsIfPresent:" << error; - return; - } - - bool changed = false; - - if (meshRadio.spreadFactor > 0 && meshRadio.spreadFactor != m_settings.m_spreadFactor) { - m_settings.m_spreadFactor = meshRadio.spreadFactor; - changed = true; - } - - if (meshRadio.parityBits > 0 && meshRadio.parityBits != m_settings.m_nbParityBits) { - m_settings.m_nbParityBits = meshRadio.parityBits; - changed = true; - } - - if (meshRadio.deBits != m_settings.m_deBits) { - m_settings.m_deBits = meshRadio.deBits; - changed = true; - } - - if (meshRadio.syncWord != m_settings.m_syncWord) { - m_settings.m_syncWord = meshRadio.syncWord; - changed = true; - } - - if (meshRadio.hasCenterFrequency) - { - if (m_deviceCenterFrequency != 0) - { - const qint64 wantedOffset = meshRadio.centerFrequencyHz - m_deviceCenterFrequency; - if (wantedOffset != m_settings.m_inputFrequencyOffset) - { - m_settings.m_inputFrequencyOffset = static_cast(wantedOffset); - changed = true; - } - } - else - { - qWarning() << "MeshtasticModGUI::applyMeshtasticRadioSettingsIfPresent: device center frequency unknown, cannot auto-center"; - } - } - - if (!changed) { - return; - } - - qInfo() << "MeshtasticModGUI::applyMeshtasticRadioSettingsIfPresent:" << meshRadio.summary; - - const int thisBW = MeshtasticModSettings::bandwidths[m_settings.m_bandwidthIndex]; - m_channelMarker.blockSignals(true); - m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); - m_channelMarker.setBandwidth(thisBW); - m_channelMarker.blockSignals(false); - - blockApplySettings(true); - ui->deltaFrequency->setValue(m_settings.m_inputFrequencyOffset); - ui->bw->setValue(m_settings.m_bandwidthIndex); - ui->bwText->setText(QString("%1 Hz").arg(thisBW)); - ui->spread->setValue(m_settings.m_spreadFactor); - ui->spreadText->setText(tr("%1").arg(m_settings.m_spreadFactor)); - ui->deBits->setValue(m_settings.m_deBits); - ui->deBitsText->setText(tr("%1").arg(m_settings.m_deBits)); - ui->fecParity->setValue(m_settings.m_nbParityBits); - ui->fecParityText->setText(tr("%1").arg(m_settings.m_nbParityBits)); - ui->syncWord->setText(tr("%1").arg(m_settings.m_syncWord, 2, 16)); - blockApplySettings(false); - - updateAbsoluteCenterFrequency(); -} - void MeshtasticModGUI::applyMeshtasticProfileFromSelection() { const QString region = ui->meshRegion->currentData().toString(); @@ -600,7 +515,6 @@ void MeshtasticModGUI::on_fecParity_valueChanged(int value) void MeshtasticModGUI::on_playMessage_clicked(bool checked) { (void) checked; - applyMeshtasticRadioSettingsIfPresent(getActivePayloadText()); applySettings(); m_meshtasticMod->sendMessage(); } @@ -618,14 +532,12 @@ void MeshtasticModGUI::on_messageText_editingFinished() m_settings.m_textMessage = ui->messageText->toPlainText(); } - applyMeshtasticRadioSettingsIfPresent(getActivePayloadText()); applySettings(); } void MeshtasticModGUI::on_hexText_editingFinished() { m_settings.m_bytesMessage = QByteArray::fromHex(ui->hexText->text().toLatin1()); - applyMeshtasticRadioSettingsIfPresent(getActivePayloadText()); applySettings(); } diff --git a/plugins/channeltx/modmeshtastic/meshtasticmodgui.h b/plugins/channeltx/modmeshtastic/meshtasticmodgui.h index bbb92fb95..f0dfabc0f 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmodgui.h +++ b/plugins/channeltx/modmeshtastic/meshtasticmodgui.h @@ -93,7 +93,6 @@ private: QString getActivePayloadText() const; int findBandwidthIndex(int bandwidthHz) const; bool retuneDeviceToFrequency(qint64 centerFrequencyHz); - void applyMeshtasticRadioSettingsIfPresent(const QString& payloadText); void setupMeshtasticAutoProfileControls(); void rebuildMeshtasticChannelOptions(); void applyMeshtasticProfileFromSelection(); diff --git a/plugins/channeltx/modmeshtastic/readme.md b/plugins/channeltx/modmeshtastic/readme.md index d174e983d..8dd2b4727 100644 --- a/plugins/channeltx/modmeshtastic/readme.md +++ b/plugins/channeltx/modmeshtastic/readme.md @@ -37,22 +37,17 @@ In LoRa coding mode, if the message text starts with `MESH:` the plugin will bui Quick example (Text mode): -`MESH:from=0x11223344;to=0xffffffff;id=0x1234;channel_name=LongFast;key=default;port=TEXT;text=hello mesh;want_ack=1;hop_limit=3` +`MESH:from=0x11223344;to=0xffffffff;id=0x1234;key=default;port=TEXT;text=hello mesh;want_ack=1;hop_limit=3` Supported fields: - - Header: `to`, `from`, `id`, `hop_limit`, `hop_start`, `want_ack`, `via_mqtt`, `channel_hash` (or `channel`), `channel_name`, `next_hop`, `relay_node` - - Preset helper: `preset` / `modem_preset` (`LONG_FAST`, `LONG_SLOW`, `LONG_TURBO`, `LONG_MODERATE`, `MEDIUM_FAST`, `MEDIUM_SLOW`, `SHORT_FAST`, `SHORT_SLOW`, `SHORT_TURBO`) maps to channel naming/hash defaults - - Radio planner: `region`, `channel_num`, `frequency`/`freq`/`freq_hz`, `frequency_offset`/`frequency_offset_hz` + - Header: `to`, `from`, `id`, `hop_limit`, `hop_start`, `want_ack`, `via_mqtt`, `next_hop`, `relay_node` - Data protobuf: `port`/`portnum`, `text`, `payload_hex`, `payload_base64`/`payload_b64`, `want_response`, `dest`, `source`, `request_id`, `reply_id`, `emoji`, `bitfield` - Crypto: `key`/`psk` (`default`, `none`, `simple0..10`, `hex:<...>`, `base64:<...>`), `encrypt` (`true|false|auto`) Notes: - If `encrypt=true` then `key` must resolve to 16 or 32 bytes. - - If `channel_hash` is not provided, it is derived from `channel_name` and `key` using Meshtastic hash rules. - - In GUI mode, when the active message is a valid `MESH:` command, the plugin auto-applies LoRa settings (`BW/SF/CR/DE`, `syncword=0x2B`) from `modem_preset`. - - If `region` (+ optional `channel_num`) or explicit `frequency` is present, GUI mode also auto-centers the channel when device center frequency is known. - If a `MESH:` command is invalid it is rejected (no payload is emitted), and an error is logged.

Interface