From 5128ea0e69e4764342720b9df90cdd0bea0ee4f8 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 27 Jan 2023 01:41:35 +0000 Subject: [PATCH] Lots of fixes for PBT and command handling - experimental --- udpbase.h | 1 + wfmain.cpp | 310 ++++++++++++++++++++++++++++++----------------------- wfmain.h | 2 + wfmain.ui | 136 +++++++++++++---------- 4 files changed, 257 insertions(+), 192 deletions(-) diff --git a/udpbase.h b/udpbase.h index e5c67cf..24ce4be 100644 --- a/udpbase.h +++ b/udpbase.h @@ -35,6 +35,7 @@ struct udpPreferences { QString password; QString clientName; quint8 waterfallFormat; + bool halfDuplex; }; struct networkAudioLevels { diff --git a/wfmain.cpp b/wfmain.cpp index fe04ed2..ae94410 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -2040,6 +2040,8 @@ void wfmain::loadSettings() udpPrefs.clientName = settings->value("ClientName", udpDefPrefs.clientName).toString(); + udpPrefs.halfDuplex = settings->value("HalfDuplex", udpDefPrefs.halfDuplex).toBool(); + settings->endGroup(); settings->beginGroup("Server"); @@ -2700,6 +2702,7 @@ void wfmain::saveSettings() settings->setValue("ResampleQuality", rxSetup.resampleQuality); settings->setValue("ClientName", udpPrefs.clientName); settings->setValue("WaterfallFormat", prefs.waterfallFormat); + settings->setValue("HalfDuplex", udpPrefs.halfDuplex); settings->endGroup(); @@ -4055,9 +4058,15 @@ void wfmain::issueDelayedCommandUnique(cmds cmd) cmddata.cmd = cmd; cmddata.data = NULL; + delayedCmdQue.push_front(cmddata); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + // The following is both expensive and not that great, - // since it does not check if the arguments are the same. - bool found = false; + // since it does not check if the arguments are the same. +/* bool found = false; + + + for(unsigned int i=0; i < delayedCmdQue.size(); i++) { if(delayedCmdQue.at(i).cmd == cmd) @@ -4076,7 +4085,9 @@ void wfmain::issueDelayedCommandUnique(cmds cmd) // { // delayedCmdQue.push_front(cmddata); // } +*/ +// delayedCmdQue.push_front(cmddata); } void wfmain::issueCmd(cmds cmd, mode_info m) @@ -4175,7 +4186,9 @@ void wfmain::issueCmdUniquePriority(cmds cmd, bool b) cmddata.cmd = cmd; cmddata.data = std::shared_ptr(new bool(b)); delayedCmdQue.push_front(cmddata); - removeSimilarCommand(cmd); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + + //removeSimilarCommand(cmd); } void wfmain::issueCmdUniquePriority(cmds cmd, unsigned char c) @@ -4184,7 +4197,9 @@ void wfmain::issueCmdUniquePriority(cmds cmd, unsigned char c) cmddata.cmd = cmd; cmddata.data = std::shared_ptr(new unsigned char(c)); delayedCmdQue.push_front(cmddata); - removeSimilarCommand(cmd); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + + //removeSimilarCommand(cmd); } void wfmain::issueCmdUniquePriority(cmds cmd, char c) @@ -4193,7 +4208,8 @@ void wfmain::issueCmdUniquePriority(cmds cmd, char c) cmddata.cmd = cmd; cmddata.data = std::shared_ptr(new char(c)); delayedCmdQue.push_front(cmddata); - removeSimilarCommand(cmd); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + //removeSimilarCommand(cmd); } void wfmain::issueCmdUniquePriority(cmds cmd, freqt f) @@ -4202,7 +4218,8 @@ void wfmain::issueCmdUniquePriority(cmds cmd, freqt f) cmddata.cmd = cmd; cmddata.data = std::shared_ptr(new freqt(f)); delayedCmdQue.push_front(cmddata); - removeSimilarCommand(cmd); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + //removeSimilarCommand(cmd); } void wfmain::issueCmdUniquePriority(cmds cmd, quint16 c) @@ -4211,7 +4228,8 @@ void wfmain::issueCmdUniquePriority(cmds cmd, quint16 c) cmddata.cmd = cmd; cmddata.data = std::shared_ptr(new quint16(c)); delayedCmdQue.push_front(cmddata); - removeSimilarCommand(cmd); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + //removeSimilarCommand(cmd); } void wfmain::issueCmdUniquePriority(cmds cmd, qint16 c) @@ -4220,7 +4238,8 @@ void wfmain::issueCmdUniquePriority(cmds cmd, qint16 c) cmddata.cmd = cmd; cmddata.data = std::shared_ptr(new qint16(c)); delayedCmdQue.push_front(cmddata); - removeSimilarCommand(cmd); + delayedCmdQue.erase(std::remove_if(delayedCmdQue.begin() + 1, delayedCmdQue.end(), [cmd](const commandtype& c) { return (c.cmd == cmd); }), delayedCmdQue.end()); + //removeSimilarCommand(cmd); } void wfmain::removeSimilarCommand(cmds cmd) @@ -4507,9 +4526,13 @@ void wfmain::initPeriodicCommands() rapidPollCmdQueue.clear(); if (rigCaps.hasSpectrum) { // Get passband - insertPeriodicRapidCmd(cmdGetPassband); - insertPeriodicRapidCmd(cmdGetTPBFInner); - insertPeriodicRapidCmd(cmdGetTPBFOuter); + //insertPeriodicRapidCmd(cmdGetPassband); + //insertPeriodicRapidCmd(cmdGetTPBFInner); + //insertPeriodicRapidCmd(cmdGetTPBFOuter); + insertSlowPeriodicCommand(cmdGetPassband, 128); + insertSlowPeriodicCommand(cmdGetTPBFInner, 128); + insertSlowPeriodicCommand(cmdGetTPBFOuter, 128); + } rapidPollCmdQueueEnabled = true; } @@ -5110,31 +5133,36 @@ void wfmain::handlePlotMouseMove(QMouseEvent* me) } else if (passbandAction == passbandResizing) { - // We are currently resizing the passband. - double pb = 0.0; - double origin = 0.0; - switch (currentModeInfo.mk) - { - case modeCW: - case modeCW_R: - origin = 0.0; - break; - case modeLSB: - origin = -passbandCenterFrequency; - break; - default: - origin = passbandCenterFrequency; - break; - } + static double lastFreq = movedFrequency; + if (lastFreq - movedFrequency > 0.000049 || movedFrequency - lastFreq > 0.000049) { - if (plot->xAxis->pixelToCoord(cursor) >= freq.MHzDouble + origin) { - pb = plot->xAxis->pixelToCoord(cursor) - passbandIndicator->topLeft->coords().x(); - } - else { - pb = passbandIndicator->bottomRight->coords().x() - plot->xAxis->pixelToCoord(cursor); - } + // We are currently resizing the passband. + double pb = 0.0; + double origin = 0.0; + switch (currentModeInfo.mk) + { + case modeCW: + case modeCW_R: + origin = 0.0; + break; + case modeLSB: + origin = -passbandCenterFrequency; + break; + default: + origin = passbandCenterFrequency; + break; + } - issueCmdUniquePriority(cmdSetPassband, (quint16)(pb * 1000000)); + if (plot->xAxis->pixelToCoord(cursor) >= freq.MHzDouble + origin) { + pb = plot->xAxis->pixelToCoord(cursor) - passbandIndicator->topLeft->coords().x(); + } + else { + pb = passbandIndicator->bottomRight->coords().x() - plot->xAxis->pixelToCoord(cursor); + } + issueCmdUniquePriority(cmdSetPassband, (quint16)(pb * 1000000)); + issueDelayedCommandUnique(cmdGetPassband); + lastFreq = movedFrequency; + } } else if (passbandAction == pbtMoving) { @@ -5154,25 +5182,36 @@ void wfmain::handlePlotMouseMove(QMouseEvent* me) qDebug() << QString("Moving passband by %1 Hz (Inner %2) (Outer %3) Mode:%4").arg((qint16)(movedFrequency * 1000000)) .arg(newInFreq).arg(newOutFreq).arg(currentModeInfo.mk); - issueCmd(cmdSetTPBFInner, (unsigned char)newInFreq); - issueCmd(cmdSetTPBFOuter, (unsigned char)newOutFreq); - + issueCmdUniquePriority(cmdSetTPBFInner, (unsigned char)newInFreq); + issueCmdUniquePriority(cmdSetTPBFOuter, (unsigned char)newOutFreq); + issueDelayedCommandUnique(cmdGetTPBFInner); + issueDelayedCommandUnique(cmdGetTPBFOuter); } lastFreq = movedFrequency; } } else if (passbandAction == pbtInnerMove) { - double pbFreq = ((double)(TPBFInner + movedFrequency) / passbandWidth) * 127.0; - qint16 newFreq = pbFreq + 128; - if (newFreq >= 0 && newFreq <= 255) { - issueCmdUniquePriority(cmdSetTPBFInner, (unsigned char)newFreq); + static double lastFreq = movedFrequency; + if (lastFreq - movedFrequency > 0.000049 || movedFrequency - lastFreq > 0.000049) { + double pbFreq = ((double)(TPBFInner + movedFrequency) / passbandWidth) * 127.0; + qint16 newFreq = pbFreq + 128; + if (newFreq >= 0 && newFreq <= 255) { + issueCmdUniquePriority(cmdSetTPBFInner, (unsigned char)newFreq); + issueDelayedCommandUnique(cmdGetTPBFInner); + } + lastFreq = movedFrequency; } } else if (passbandAction == pbtOuterMove) { - double pbFreq = ((double)(TPBFOuter + movedFrequency) / passbandWidth) * 127.0; - qint16 newFreq = pbFreq + 128; - if (newFreq >= 0 && newFreq <= 255) { - issueCmdUniquePriority(cmdSetTPBFOuter, (unsigned char)newFreq); + static double lastFreq = movedFrequency; + if (lastFreq - movedFrequency > 0.000049 || movedFrequency - lastFreq > 0.000049) { + double pbFreq = ((double)(TPBFOuter + movedFrequency) / passbandWidth) * 127.0; + qint16 newFreq = pbFreq + 128; + if (newFreq >= 0 && newFreq <= 255) { + issueCmdUniquePriority(cmdSetTPBFOuter, (unsigned char)newFreq); + issueDelayedCommandUnique(cmdGetTPBFOuter); + } + lastFreq = movedFrequency; } } else if (passbandAction == passbandStatic && me->buttons() == Qt::LeftButton && textItem == nullptr && prefs.clickDragTuningEnable) @@ -5266,106 +5305,101 @@ void wfmain::receiveMode(unsigned char mode, unsigned char filter) if(mode < 0x23) { - for(int i=0; i < ui->modeSelectCombo->count(); i++) + // Update mode information if mode/filter has changed + if (currentModeInfo.mk != (mode_kind)mode || currentModeInfo.filter != filter) { - if(ui->modeSelectCombo->itemData(i).toInt() == mode) - { - ui->modeSelectCombo->blockSignals(true); - ui->modeSelectCombo->setCurrentIndex(i); - ui->modeSelectCombo->blockSignals(false); - found = true; + + removePeriodicRapidCmd(cmdGetCwPitch); + quint16 maxPassbandHz = 0; + switch ((mode_kind)mode) { + case modeFM: + if (filter == 1) + passbandWidth = 0.015; + else if (filter == 2) + passbandWidth = 0.010; + else + passbandWidth = 0.007; + passbandCenterFrequency = 0.0; + maxPassbandHz = 10E3; + break; + case modeCW: + case modeCW_R: + insertPeriodicRapidCmdUnique(cmdGetCwPitch); + maxPassbandHz = 3600; + break; + case modeAM: + passbandCenterFrequency = 0.0; + maxPassbandHz = 10E3; + break; + case modeLSB: + case modeUSB: + passbandCenterFrequency = 0.0015; + maxPassbandHz = 3600; + break; + default: + passbandCenterFrequency = 0.0; + maxPassbandHz = 3600; + break; } - } - currentModeIndex = mode; - currentModeInfo.mk = (mode_kind)mode; - cw->handleCurrentModeUpdate((mode_kind)mode); - currentModeInfo.filter = filter; - switch (currentModeInfo.mk) { - case modeFM: - if (currentModeInfo.filter == 1) - passbandWidth = 0.015; - else if (currentModeInfo.filter == 2) - passbandWidth = 0.010; - else - passbandWidth = 0.007; - passbandCenterFrequency = 0.0; - break; - case modeLSB: - case modeUSB: - removePeriodicCommand(cmdGetCwPitch); - removePeriodicCommand(cmdGetPskTone); - removePeriodicCommand(cmdGetRttyMark); - passbandCenterFrequency = 0.0015; - break; - case modeCW: - case modeCW_R: - insertPeriodicCommandUnique(cmdGetCwPitch); - removePeriodicCommand(cmdGetPskTone); - removePeriodicCommand(cmdGetRttyMark); - break; - default: - removePeriodicCommand(cmdGetCwPitch); - removePeriodicCommand(cmdGetPskTone); - removePeriodicCommand(cmdGetRttyMark); - passbandCenterFrequency = 0.0; - break; - } + for (int i = 0; i < ui->modeSelectCombo->count(); i++) + { + if (ui->modeSelectCombo->itemData(i).toInt() == mode) + { + ui->modeSelectCombo->blockSignals(true); + ui->modeSelectCombo->setCurrentIndex(i); + ui->modeSelectCombo->blockSignals(false); + found = true; + } + } - } else { - qCritical(logSystem()) << __func__ << "Invalid mode " << mode << " received. "; - } + if ((filter) && (filter < 4)) { + ui->modeFilterCombo->blockSignals(true); + ui->modeFilterCombo->setCurrentIndex(filter - 1); + ui->modeFilterCombo->blockSignals(false); + } - if(!found) - { - qWarning(logSystem()) << __func__ << "Received mode " << mode << " but could not match to any index within the modeSelectCombo. "; - return; - } + currentModeIndex = mode; + currentModeInfo.mk = (mode_kind)mode; + currentMode = (mode_kind)mode; + currentModeInfo.filter = filter; + currentModeInfo.reg = mode; + rpt->handleUpdateCurrentMainMode(currentModeInfo); +<<<<<<< Updated upstream currentModeIndex = mode; currentModeInfo.mk = (mode_kind)mode; currentMode = (mode_kind)mode; currentModeInfo.filter = filter; +======= + if (!found) + { + qWarning(logSystem()) << __func__ << "Received mode " << mode << " but could not match to any index within the modeSelectCombo. "; + return; + } +>>>>>>> Stashed changes - if( (filter) && (filter < 4)){ - ui->modeFilterCombo->blockSignals(true); - ui->modeFilterCombo->setCurrentIndex(filter-1); - ui->modeFilterCombo->blockSignals(false); - } + if (maxPassbandHz != 0) + { + trxadj->setMaxPassband(maxPassbandHz); + } - quint16 maxPassbandHz = 0; - switch(currentMode) - { - case modeUSB: - case modeLSB: - case modeCW: - case modeCW_R: - case modePSK: - case modePSK_R: - maxPassbandHz = 3600; - break; - case modeRTTY: - case modeRTTY_R: - maxPassbandHz = 2700; - break; - case modeAM: - maxPassbandHz = 10E3; - break; - case modeFM: - maxPassbandHz = 10E3; - break; - default: - break; - } - if(maxPassbandHz != 0) - { - trxadj->setMaxPassband(maxPassbandHz); - } - // Note: we need to know if the DATA mode is active to reach mode-D - // some kind of queued query: - if (rigCaps.hasDataModes && rigCaps.hasTransmit) - { - issueDelayedCommand(cmdGetDataMode); + issueDelayedCommandUnique(cmdGetPassband); + issueDelayedCommandUnique(cmdGetCwPitch); + issueDelayedCommandUnique(cmdGetTPBFInner); + issueDelayedCommandUnique(cmdGetTPBFOuter); + + // Note: we need to know if the DATA mode is active to reach mode-D + // some kind of queued query: + if (rigCaps.hasDataModes && rigCaps.hasTransmit) + { + issueDelayedCommand(cmdGetDataMode); + } + + } + + } else { + qCritical(logSystem()) << __func__ << "Invalid mode " << mode << " received. "; } } @@ -5649,7 +5683,9 @@ void wfmain::on_modeSelectCombo_activated(int index) } issueCmd(cmdSetMode, mode); - currentModeInfo = mode; + issueDelayedCommand(cmdGetMode); + + //currentModeInfo = mode; } } @@ -6191,6 +6227,11 @@ void wfmain::on_passwordTxt_textChanged(QString text) udpPrefs.password = text; } +void wfmain::on_audioDuplexCombo_currentIndexChanged(int value) +{ + udpPrefs.halfDuplex = (bool)value; +} + void wfmain::on_audioOutputCombo_currentIndexChanged(int value) { @@ -6344,6 +6385,7 @@ void wfmain::on_modeFilterCombo_activated(int index) m.mk = (mode_kind)newMode; m.reg = newMode; issueCmd(cmdSetMode, m); + //emit setMode(newMode, (unsigned char)filterSelection); } } diff --git a/wfmain.h b/wfmain.h index 00c1063..d5c27c7 100644 --- a/wfmain.h +++ b/wfmain.h @@ -451,6 +451,8 @@ private slots: void on_passwordTxt_textChanged(QString text); + void on_audioDuplexCombo_currentIndexChanged(int value); + void on_audioOutputCombo_currentIndexChanged(int value); void on_audioInputCombo_currentIndexChanged(int value); diff --git a/wfmain.ui b/wfmain.ui index cb896a4..21ff7aa 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -6,7 +6,7 @@ 0 0 - 1082 + 1063 660 @@ -18,7 +18,7 @@ - 0 + 3 @@ -1808,7 +1808,6 @@ DejaVu Sans Mono 14 - 75 true @@ -2233,7 +2232,7 @@ - 1 + 0 @@ -2775,61 +2774,26 @@ - + - Audio Output + Duplex - - - - 120 - 16777215 - - - - Audio Output Selector - + + + + Full Duplex + + + + + Half Duplex + + - - - - Audio Input - - - - - - - - 120 - 16777215 - - - - Audio Input Selector - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 15 - 20 - - - - @@ -2871,6 +2835,63 @@ + + + + + + Audio Output + + + + + + + + 200 + 16777215 + + + + Audio Output Selector + + + + + + + Audio Input + + + + + + + + 200 + 16777215 + + + + Audio Input Selector + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -3409,8 +3430,8 @@ 0 0 - 858 - 287 + 579 + 224 @@ -5359,7 +5380,6 @@ - 50 false @@ -5378,8 +5398,8 @@ 0 0 - 1082 - 21 + 1063 + 22 @@ -5407,7 +5427,7 @@ - +