mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-07-28 21:14:15 -04:00
Meshtastic: fixed Tx and strengthen Rx header processing
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include "maincore.h"
|
||||
#include "channel/channelwebapiutils.h"
|
||||
|
||||
#include "meshtasticpacket.h"
|
||||
#include "meshtasticmodbaseband.h"
|
||||
#include "meshtasticmod.h"
|
||||
|
||||
@@ -204,8 +205,102 @@ void MeshtasticMod::setCenterFrequency(qint64 frequency)
|
||||
}
|
||||
}
|
||||
|
||||
void MeshtasticMod::applySettings(const MeshtasticModSettings& settings, bool force)
|
||||
int MeshtasticMod::findBandwidthIndex(int bandwidthHz) const
|
||||
{
|
||||
int bestIndex = -1;
|
||||
int bestDelta = 1 << 30;
|
||||
|
||||
for (int i = 0; i < MeshtasticModSettings::nbBandwidths; i++)
|
||||
{
|
||||
const int delta = std::abs(MeshtasticModSettings::bandwidths[i] - bandwidthHz);
|
||||
|
||||
if (delta < bestDelta)
|
||||
{
|
||||
bestDelta = delta;
|
||||
bestIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return bestIndex;
|
||||
}
|
||||
|
||||
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;
|
||||
const int bwIndex = findBandwidthIndex(meshRadio.bandwidthHz);
|
||||
|
||||
if ((bwIndex >= 0) && (bwIndex != settings.m_bandwidthIndex)) {
|
||||
settings.m_bandwidthIndex = bwIndex;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
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<quint64> 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<qint64>(centerFrequencies.at(selectedIndex));
|
||||
const qint64 wantedOffset = meshRadio.centerFrequencyHz - deviceCenterFrequency;
|
||||
|
||||
if (wantedOffset != settings.m_inputFrequencyOffset)
|
||||
{
|
||||
settings.m_inputFrequencyOffset = static_cast<int>(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
|
||||
<< " m_rfBandwidth: " << settings.m_bandwidthIndex
|
||||
@@ -226,6 +321,7 @@ void MeshtasticMod::applySettings(const MeshtasticModSettings& settings, bool fo
|
||||
<< " m_udpEnabled: " << settings.m_udpEnabled
|
||||
<< " m_udpAddress: " << settings.m_udpAddress
|
||||
<< " m_udpPort: " << settings.m_udpPort
|
||||
<< " m_syncWord: " << settings.m_syncWord
|
||||
<< " m_invertRamps: " << settings.m_invertRamps
|
||||
<< " m_useReverseAPI: " << settings.m_useReverseAPI
|
||||
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
|
||||
@@ -289,6 +385,9 @@ void MeshtasticMod::applySettings(const MeshtasticModSettings& settings, bool fo
|
||||
if ((settings.m_invertRamps != m_settings.m_invertRamps) || force) {
|
||||
reverseAPIKeys.append("invertRamps");
|
||||
}
|
||||
if ((settings.m_syncWord != m_settings.m_syncWord) || force) {
|
||||
reverseAPIKeys.append("syncWord");
|
||||
}
|
||||
|
||||
MeshtasticModBaseband::MsgConfigureMeshtasticModPayload *payloadMsg = nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user