You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
313 lines
10 KiB
313 lines
10 KiB
/////////////////////////////////////////////////////////////////////////////////// |
|
// Copyright (C) 2026 Dan Chokola, KD2HSG // |
|
// Based on the packet modulator plugin: // |
|
// Copyright (C) 2020-2023 Jon Beniston, M7RCE <jon@beniston.com> // |
|
// Copyright (C) 2020-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> // |
|
// // |
|
// 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 as 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 V3 for more details. // |
|
// // |
|
// You should have received a copy of the GNU General Public License // |
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. // |
|
/////////////////////////////////////////////////////////////////////////////////// |
|
|
|
#include <QColor> |
|
|
|
#include <algorithm> |
|
#include <cmath> |
|
|
|
#include "settings/serializable.h" |
|
#include "util/simpleserializer.h" |
|
|
|
#include "chirpmodemmodsettings.h" |
|
|
|
ChirpModemModSettings::ChirpModemModSettings() |
|
{ |
|
resetToDefaults(); |
|
} |
|
|
|
void ChirpModemModSettings::resetToDefaults() |
|
{ |
|
m_inputFrequencyOffset = 0; |
|
m_spreadFactor = 9; |
|
m_bandwidth = 62500; |
|
m_mode = ModeAuto; |
|
m_profile = ProfileLicensed; |
|
m_source = QString(); |
|
m_destination = QString(); |
|
m_message = QStringLiteral("test"); |
|
m_repeat = 1; |
|
m_gap = 0.5f; |
|
m_amplitude = 0.7f; |
|
m_cwId = true; |
|
m_cwWpm = m_maxWpm; |
|
m_rgbColor = QColor(255, 140, 0).rgb(); |
|
m_title = QStringLiteral("ChirpModem Modulator"); |
|
m_streamIndex = 0; |
|
m_useReverseAPI = false; |
|
m_reverseAPIAddress = QStringLiteral("127.0.0.1"); |
|
m_reverseAPIPort = 8888; |
|
m_reverseAPIDeviceIndex = 0; |
|
m_reverseAPIChannelIndex = 0; |
|
m_workspaceIndex = 0; |
|
m_geometryBytes = QByteArray(); |
|
m_hidden = false; |
|
} |
|
|
|
void ChirpModemModSettings::normalize() |
|
{ |
|
m_spreadFactor = std::clamp(m_spreadFactor, 7, 12); |
|
m_bandwidth = std::clamp(m_bandwidth, 1000, 2000000); |
|
m_mode = std::clamp(m_mode, (int) ModeAuto, (int) ModeCoherent); |
|
m_profile = m_profile == ProfileUnlicensed ? ProfileUnlicensed : ProfileLicensed; |
|
m_source = m_source.trimmed().toUpper(); |
|
m_destination = m_destination.trimmed().toUpper(); |
|
m_repeat = std::clamp(m_repeat, 1, 1000); |
|
m_gap = std::isfinite(m_gap) ? std::clamp(m_gap, 0.0f, 60.0f) : 0.5f; |
|
m_amplitude = std::isfinite(m_amplitude) ? std::clamp(m_amplitude, 0.0f, 1.0f) : 0.7f; |
|
m_cwWpm = std::clamp(m_cwWpm, 5, (int) m_maxWpm); |
|
m_streamIndex = std::max(0, m_streamIndex); |
|
|
|
if (!m_reverseAPIPort || m_reverseAPIPort > 65535) { |
|
m_reverseAPIPort = 8888; |
|
} |
|
|
|
m_reverseAPIDeviceIndex = std::min(m_reverseAPIDeviceIndex, 99u); |
|
m_reverseAPIChannelIndex = std::min(m_reverseAPIChannelIndex, 99u); |
|
} |
|
|
|
QByteArray ChirpModemModSettings::serialize() const |
|
{ |
|
SimpleSerializer s(1); |
|
|
|
s.writeS64(1, m_inputFrequencyOffset); |
|
s.writeS32(2, m_spreadFactor); |
|
s.writeS32(3, m_bandwidth); |
|
s.writeS32(4, m_mode); |
|
s.writeS32(5, m_profile); |
|
s.writeString(6, m_source); |
|
s.writeString(7, m_destination); |
|
s.writeString(8, m_message); |
|
s.writeS32(9, m_repeat); |
|
s.writeFloat(10, m_gap); |
|
s.writeFloat(11, m_amplitude); |
|
s.writeBool(12, m_cwId); |
|
s.writeS32(13, m_cwWpm); |
|
s.writeU32(15, m_rgbColor); |
|
s.writeString(16, m_title); |
|
s.writeS32(17, m_streamIndex); |
|
s.writeBool(18, m_useReverseAPI); |
|
s.writeString(19, m_reverseAPIAddress); |
|
s.writeU32(20, m_reverseAPIPort); |
|
s.writeU32(21, m_reverseAPIDeviceIndex); |
|
s.writeU32(22, m_reverseAPIChannelIndex); |
|
s.writeS32(23, m_workspaceIndex); |
|
s.writeBlob(24, m_geometryBytes); |
|
s.writeBool(25, m_hidden); |
|
|
|
if (m_channelMarker) { |
|
s.writeBlob(40, m_channelMarker->serialize()); |
|
} |
|
if (m_rollupState) { |
|
s.writeBlob(41, m_rollupState->serialize()); |
|
} |
|
if (m_spectrumGUI) { |
|
s.writeBlob(42, m_spectrumGUI->serialize()); |
|
} |
|
|
|
return s.final(); |
|
} |
|
|
|
bool ChirpModemModSettings::deserialize(const QByteArray& data) |
|
{ |
|
SimpleDeserializer d(data); |
|
|
|
resetToDefaults(); |
|
|
|
if (!d.isValid() || d.getVersion() != 1) { |
|
return false; |
|
} |
|
|
|
d.readS64(1, &m_inputFrequencyOffset, 0); |
|
d.readS32(2, &m_spreadFactor, 9); |
|
d.readS32(3, &m_bandwidth, 62500); |
|
d.readS32(4, &m_mode, ModeAuto); |
|
d.readS32(5, &m_profile, ProfileLicensed); |
|
d.readString(6, &m_source, QString()); |
|
d.readString(7, &m_destination, QString()); |
|
d.readString(8, &m_message, QStringLiteral("test")); |
|
d.readS32(9, &m_repeat, 1); |
|
d.readFloat(10, &m_gap, 0.5f); |
|
d.readFloat(11, &m_amplitude, 0.7f); |
|
d.readBool(12, &m_cwId, true); |
|
d.readS32(13, &m_cwWpm, m_maxWpm); |
|
d.readU32(15, &m_rgbColor, QColor(255, 140, 0).rgb()); |
|
d.readString(16, &m_title, QStringLiteral("ChirpModem Modulator")); |
|
d.readS32(17, &m_streamIndex, 0); |
|
d.readBool(18, &m_useReverseAPI, false); |
|
d.readString(19, &m_reverseAPIAddress, QStringLiteral("127.0.0.1")); |
|
d.readU32(20, &m_reverseAPIPort, 8888); |
|
d.readU32(21, &m_reverseAPIDeviceIndex, 0); |
|
d.readU32(22, &m_reverseAPIChannelIndex, 0); |
|
d.readS32(23, &m_workspaceIndex, 0); |
|
d.readBlob(24, &m_geometryBytes); |
|
d.readBool(25, &m_hidden, false); |
|
|
|
QByteArray blob; |
|
|
|
if (m_channelMarker && d.readBlob(40, &blob)) { |
|
m_channelMarker->deserialize(blob); |
|
} |
|
if (m_rollupState && d.readBlob(41, &blob)) { |
|
m_rollupState->deserialize(blob); |
|
} |
|
if (m_spectrumGUI && d.readBlob(42, &blob)) { |
|
m_spectrumGUI->deserialize(blob); |
|
} |
|
|
|
normalize(); |
|
return true; |
|
} |
|
|
|
void ChirpModemModSettings::applySettings(const QStringList& keys, const ChirpModemModSettings& settings) |
|
{ |
|
if (keys.contains("inputFrequencyOffset")) { |
|
m_inputFrequencyOffset = settings.m_inputFrequencyOffset; |
|
} |
|
if (keys.contains("spreadFactor")) { |
|
m_spreadFactor = settings.m_spreadFactor; |
|
} |
|
if (keys.contains("bandwidth")) { |
|
m_bandwidth = settings.m_bandwidth; |
|
} |
|
if (keys.contains("mode")) { |
|
m_mode = settings.m_mode; |
|
} |
|
if (keys.contains("profile")) { |
|
m_profile = settings.m_profile; |
|
} |
|
if (keys.contains("source")) { |
|
m_source = settings.m_source; |
|
} |
|
if (keys.contains("destination")) { |
|
m_destination = settings.m_destination; |
|
} |
|
if (keys.contains("message")) { |
|
m_message = settings.m_message; |
|
} |
|
if (keys.contains("repeat")) { |
|
m_repeat = settings.m_repeat; |
|
} |
|
if (keys.contains("gap")) { |
|
m_gap = settings.m_gap; |
|
} |
|
if (keys.contains("amplitude")) { |
|
m_amplitude = settings.m_amplitude; |
|
} |
|
if (keys.contains("cwId")) { |
|
m_cwId = settings.m_cwId; |
|
} |
|
if (keys.contains("cwWpm")) { |
|
m_cwWpm = settings.m_cwWpm; |
|
} |
|
if (keys.contains("rgbColor")) { |
|
m_rgbColor = settings.m_rgbColor; |
|
} |
|
if (keys.contains("title")) { |
|
m_title = settings.m_title; |
|
} |
|
if (keys.contains("streamIndex")) { |
|
m_streamIndex = settings.m_streamIndex; |
|
} |
|
if (keys.contains("useReverseAPI")) { |
|
m_useReverseAPI = settings.m_useReverseAPI; |
|
} |
|
if (keys.contains("reverseAPIAddress")) { |
|
m_reverseAPIAddress = settings.m_reverseAPIAddress; |
|
} |
|
if (keys.contains("reverseAPIPort")) { |
|
m_reverseAPIPort = settings.m_reverseAPIPort; |
|
} |
|
if (keys.contains("reverseAPIDeviceIndex")) { |
|
m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex; |
|
} |
|
if (keys.contains("reverseAPIChannelIndex")) { |
|
m_reverseAPIChannelIndex = settings.m_reverseAPIChannelIndex; |
|
} |
|
if (keys.contains("workspaceIndex")) { |
|
m_workspaceIndex = settings.m_workspaceIndex; |
|
} |
|
if (keys.contains("geometryBytes")) { |
|
m_geometryBytes = settings.m_geometryBytes; |
|
} |
|
if (keys.contains("hidden")) { |
|
m_hidden = settings.m_hidden; |
|
} |
|
normalize(); |
|
} |
|
|
|
QString ChirpModemModSettings::getDebugString(const QStringList& keys, bool force) const |
|
{ |
|
QStringList result; |
|
|
|
if (force || keys.contains("inputFrequencyOffset")) { |
|
result << QString("inputFrequencyOffset: %1").arg(m_inputFrequencyOffset); |
|
} |
|
if (force || keys.contains("spreadFactor")) { |
|
result << QString("spreadFactor: %1").arg(m_spreadFactor); |
|
} |
|
if (force || keys.contains("bandwidth")) { |
|
result << QString("bandwidth: %1").arg(m_bandwidth); |
|
} |
|
if (force || keys.contains("mode")) { |
|
result << QString("mode: %1").arg(m_mode); |
|
} |
|
if (force || keys.contains("profile")) { |
|
result << QString("profile: %1").arg(m_profile); |
|
} |
|
if (force || keys.contains("source")) { |
|
result << QString("source: %1").arg(m_source); |
|
} |
|
if (force || keys.contains("destination")) { |
|
result << QString("destination: %1").arg(m_destination); |
|
} |
|
if (force || keys.contains("message")) { |
|
result << QString("message: %1").arg(m_message); |
|
} |
|
if (force || keys.contains("repeat")) { |
|
result << QString("repeat: %1").arg(m_repeat); |
|
} |
|
if (force || keys.contains("gap")) { |
|
result << QString("gap: %1").arg(m_gap); |
|
} |
|
if (force || keys.contains("amplitude")) { |
|
result << QString("amplitude: %1").arg(m_amplitude); |
|
} |
|
if (force || keys.contains("cwId")) { |
|
result << QString("cwId: %1").arg(m_cwId); |
|
} |
|
if (force || keys.contains("cwWpm")) { |
|
result << QString("cwWpm: %1").arg(m_cwWpm); |
|
} |
|
if (force || keys.contains("rgbColor")) { |
|
result << QString("rgbColor: %1").arg(m_rgbColor); |
|
} |
|
if (force || keys.contains("title")) { |
|
result << QString("title: %1").arg(m_title); |
|
} |
|
if (force || keys.contains("streamIndex")) { |
|
result << QString("streamIndex: %1").arg(m_streamIndex); |
|
} |
|
if (force || keys.contains("useReverseAPI")) { |
|
result << QString("useReverseAPI: %1").arg(m_useReverseAPI); |
|
} |
|
|
|
return result.join(" "); |
|
}
|
|
|