diff --git a/plugins/feature/limerfe/limerfe.cpp b/plugins/feature/limerfe/limerfe.cpp index 4a9c9127a..a8d21dc7e 100644 --- a/plugins/feature/limerfe/limerfe.cpp +++ b/plugins/feature/limerfe/limerfe.cpp @@ -257,6 +257,27 @@ int LimeRFE::getState() qInfo("LimeRFE::getState: %s", getError(rc).c_str()); } + if (m_rfeBoardState.mode == RFE_MODE_RX) + { + m_rxOn = true; + m_txOn = false; + } + else if (m_rfeBoardState.mode == RFE_MODE_TX) + { + m_rxOn = false; + m_txOn = true; + } + else if (m_rfeBoardState.mode == RFE_MODE_NONE) + { + m_rxOn = false; + m_txOn = false; + } + else if (m_rfeBoardState.mode == RFE_MODE_TXRX) + { + m_rxOn = true; + m_txOn = true; + } + return rc; } @@ -271,7 +292,7 @@ std::string LimeRFE::getError(int errorCode) } } -int LimeRFE::setRx(LimeRFESettings& settings, bool rxOn) +int LimeRFE::setRx(bool rxOn) { if (!m_rfeDevice) { return -1; @@ -281,7 +302,7 @@ int LimeRFE::setRx(LimeRFESettings& settings, bool rxOn) if (rxOn) { - if (settings.m_txOn) { + if (m_txOn) { mode = RFE_MODE_TXRX; } else { mode = RFE_MODE_RX; @@ -289,7 +310,7 @@ int LimeRFE::setRx(LimeRFESettings& settings, bool rxOn) } else { - if (settings.m_txOn) { + if (m_txOn) { mode = RFE_MODE_TX; } } @@ -298,7 +319,7 @@ int LimeRFE::setRx(LimeRFESettings& settings, bool rxOn) int rc = RFE_Mode(m_rfeDevice, mode); if (rc == 0) { - settings.m_rxOn = rxOn; + m_rxOn = rxOn; } else { qInfo("LimeRFE::setRx: %s", getError(rc).c_str()); } @@ -306,7 +327,7 @@ int LimeRFE::setRx(LimeRFESettings& settings, bool rxOn) return rc; } -int LimeRFE::setTx(LimeRFESettings& settings, bool txOn) +int LimeRFE::setTx(bool txOn) { if (!m_rfeDevice) { return -1; @@ -316,7 +337,7 @@ int LimeRFE::setTx(LimeRFESettings& settings, bool txOn) if (txOn) { - if (settings.m_rxOn) { + if (m_rxOn) { mode = RFE_MODE_TXRX; } else { mode = RFE_MODE_TX; @@ -324,7 +345,7 @@ int LimeRFE::setTx(LimeRFESettings& settings, bool txOn) } else { - if (settings.m_rxOn) { + if (m_rxOn) { mode = RFE_MODE_RX; } } @@ -333,7 +354,7 @@ int LimeRFE::setTx(LimeRFESettings& settings, bool txOn) int rc = RFE_Mode(m_rfeDevice, mode); if (rc == 0) { - settings.m_txOn = txOn; + m_txOn = txOn; } else { qInfo("LimeRFE::setTx: %s", getError(rc).c_str()); } @@ -433,14 +454,6 @@ void LimeRFE::settingsToState(const LimeRFESettings& settings) } else { - m_rfeBoardState.mode = settings.m_rxOn && settings.m_txOn ? - RFE_MODE_TXRX : - settings.m_rxOn ? - RFE_MODE_RX : - settings.m_txOn ? - RFE_MODE_TX : - RFE_MODE_NONE; - if (settings.m_rxChannels == LimeRFESettings::ChannelGroups::ChannelsWideband) { if (settings.m_rxWidebandChannel == LimeRFESettings::WidebandChannel::WidebandLow) { @@ -716,28 +729,6 @@ void LimeRFE::stateToSettings(LimeRFESettings& settings) settings.m_attenuationFactor = m_rfeBoardState.attValue; settings.m_amfmNotch = m_rfeBoardState.notchOnOff == RFE_NOTCH_ON; - - if (m_rfeBoardState.mode == RFE_MODE_RX) - { - settings.m_rxOn = true; - settings.m_txOn = false; - } - else if (m_rfeBoardState.mode == RFE_MODE_TX) - { - settings.m_rxOn = false; - settings.m_txOn = true; - } - else if (m_rfeBoardState.mode == RFE_MODE_NONE) - { - settings.m_rxOn = false; - settings.m_txOn = false; - } - else if (m_rfeBoardState.mode == RFE_MODE_TXRX) - { - settings.m_rxOn = true; - settings.m_txOn = true; - } - settings.m_swrEnable = m_rfeBoardState.enableSWR == RFE_SWR_ENABLE; settings.m_swrSource = m_rfeBoardState.sourceSWR == RFE_SWR_SRC_CELL ? LimeRFESettings::SWRSource::SWRCellular : @@ -847,6 +838,18 @@ int LimeRFE::webapiActionsPost( } } + if (featureActionsKeys.contains("getState") && (swgLimeRFEActions->getGetState() != 0)) + { + int rc = getState(); + unknownAction = false; + + if (rc != 0) + { + errorMessage = QString("Get state %1: %2").arg(m_settings.m_devicePath).arg(getError(rc).c_str()); + return 500; + } + } + if (featureActionsKeys.contains("fromToSettings") && (swgLimeRFEActions->getFromToSettings() != 0)) { settingsToState(m_settings); @@ -858,7 +861,7 @@ int LimeRFE::webapiActionsPost( if (channel == 0) { bool on = swgLimeRFEActions->getSwitchChannel() != 0; - int rc = setRx(m_settings, on); + int rc = setRx(on); if (rc != 0) { @@ -868,14 +871,14 @@ int LimeRFE::webapiActionsPost( if (getMessageQueueToGUI()) { - MsgConfigureLimeRFE *msg = MsgConfigureLimeRFE::create(m_settings, false); + MsgReportSetRx *msg = MsgReportSetRx::create(on); getMessageQueueToGUI()->push(msg); } } else { bool on = swgLimeRFEActions->getSwitchChannel() != 0; - int rc = setTx(m_settings, swgLimeRFEActions->getSwitchChannel() != 0); + int rc = setTx(on); if (rc != 0) { @@ -885,7 +888,7 @@ int LimeRFE::webapiActionsPost( if (getMessageQueueToGUI()) { - MsgConfigureLimeRFE *msg = MsgConfigureLimeRFE::create(m_settings, false); + MsgReportSetTx *msg = MsgReportSetTx::create(on); getMessageQueueToGUI()->push(msg); } } @@ -949,7 +952,6 @@ void LimeRFE::webapiFormatFeatureSettings( response.getLimeRfeSettings()->setRxHamChannel((int) settings.m_rxHAMChannel); response.getLimeRfeSettings()->setRxCellularChannel((int) settings.m_rxCellularChannel); response.getLimeRfeSettings()->setRxPort((int) settings.m_rxPort); - response.getLimeRfeSettings()->setRxOn(settings.m_rxOn ? 1 : 0); response.getLimeRfeSettings()->setAmfmNotch(settings.m_amfmNotch ? 1 : 0); response.getLimeRfeSettings()->setAttenuationFactor(settings.m_attenuationFactor); response.getLimeRfeSettings()->setTxChannels((int) settings.m_txChannels); @@ -957,7 +959,6 @@ void LimeRFE::webapiFormatFeatureSettings( response.getLimeRfeSettings()->setTxHamChannel((int) settings.m_txHAMChannel); response.getLimeRfeSettings()->setTxCellularChannel((int) settings.m_txCellularChannel); response.getLimeRfeSettings()->setTxPort((int) settings.m_txPort); - response.getLimeRfeSettings()->setTxOn(settings.m_txOn ? 1 : 0); response.getLimeRfeSettings()->setSwrEnable(settings.m_swrEnable ? 1 : 0); response.getLimeRfeSettings()->setSwrSource((int) settings.m_swrSource); response.getLimeRfeSettings()->setTxRxDriven(settings.m_txRxDriven ? 1 : 0); @@ -1018,9 +1019,6 @@ void LimeRFE::webapiUpdateFeatureSettings( if (featureSettingsKeys.contains("rxPort")) { settings.m_rxPort = (LimeRFESettings::RxPort) response.getLimeRfeSettings()->getRxPort(); } - if (featureSettingsKeys.contains("rxOn")) { - settings.m_rxOn = response.getLimeRfeSettings()->getRxOn() != 0; - } if (featureSettingsKeys.contains("amfmNotch")) { settings.m_amfmNotch = response.getLimeRfeSettings()->getAmfmNotch() != 0; } @@ -1042,9 +1040,6 @@ void LimeRFE::webapiUpdateFeatureSettings( if (featureSettingsKeys.contains("txPort")) { settings.m_txPort = (LimeRFESettings::TxPort) response.getLimeRfeSettings()->getTxPort(); } - if (featureSettingsKeys.contains("txOn")) { - settings.m_txOn = response.getLimeRfeSettings()->getTxOn() != 0; - } if (featureSettingsKeys.contains("swrEnable")) { settings.m_swrEnable = response.getLimeRfeSettings()->getSwrEnable() != 0; } @@ -1076,6 +1071,9 @@ void LimeRFE::webapiUpdateFeatureSettings( int LimeRFE::webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response, QString& errorMessage) { + response.getLimeRfeReport()->setRxOn(m_rxOn ? 1 : 0); + response.getLimeRfeReport()->setTxOn(m_txOn ? 1 : 0); + int fwdPower; int rc = getFwdPower(fwdPower); diff --git a/plugins/feature/limerfe/limerfe.h b/plugins/feature/limerfe/limerfe.h index e224fd87a..9f24490bc 100644 --- a/plugins/feature/limerfe/limerfe.h +++ b/plugins/feature/limerfe/limerfe.h @@ -146,8 +146,10 @@ public: int configure(); int getState(); static std::string getError(int errorCode); - int setRx(LimeRFESettings& settings, bool rxOn); - int setTx(LimeRFESettings& settings, bool txOn); + int setRx(bool rxOn); + int setTx(bool txOn); + bool getRx() const { return m_rxOn; }; + bool getTx() const { return m_txOn; }; bool turnDevice(int deviceSetIndex, bool on); int getFwdPower(int& powerDB); int getRefPower(int& powerDB); @@ -161,6 +163,8 @@ public: private: LimeRFESettings m_settings; LimeRFEUSBCalib m_calib; + bool m_rxOn; + bool m_txOn; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; diff --git a/plugins/feature/limerfe/limerfegui.cpp b/plugins/feature/limerfe/limerfegui.cpp index 05c5fabe5..32c136820 100644 --- a/plugins/feature/limerfe/limerfegui.cpp +++ b/plugins/feature/limerfe/limerfegui.cpp @@ -128,6 +128,8 @@ LimeRFEGUI::LimeRFEGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature ui(new Ui::LimeRFEGUI), m_pluginAPI(pluginAPI), m_featureUISet(featureUISet), + m_rxOn(false), + m_txOn(false), m_doApplySettings(true), m_rxTxToggle(false), m_currentPowerCorrection(0.0), @@ -200,9 +202,9 @@ void LimeRFEGUI::displayMode() { QString s; - if (m_settings.m_rxOn) + if (m_rxOn) { - if (m_settings.m_txOn) { + if (m_txOn) { s = "Rx/Tx"; } else { s = "Rx"; @@ -210,7 +212,7 @@ void LimeRFEGUI::displayMode() } else { - if (m_settings.m_txOn) { + if (m_txOn) { s = "Tx"; } else { s = "None"; @@ -222,20 +224,20 @@ void LimeRFEGUI::displayMode() ui->modeRx->blockSignals(true); ui->modeTx->blockSignals(true); - if (m_settings.m_rxOn) { + if (m_rxOn) { ui->modeRx->setStyleSheet("QToolButton { background-color : green; }"); } else { ui->modeRx->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); } - if (m_settings.m_txOn) { + if (m_txOn) { ui->modeTx->setStyleSheet("QToolButton { background-color : red; }"); } else { ui->modeTx->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); } - ui->modeRx->setChecked(m_settings.m_rxOn); - ui->modeTx->setChecked(m_settings.m_txOn); + ui->modeRx->setChecked(m_rxOn); + ui->modeTx->setChecked(m_txOn); ui->modeRx->blockSignals(false); ui->modeTx->blockSignals(false); @@ -674,6 +676,8 @@ void LimeRFEGUI::on_deviceToGUI_clicked() } m_limeRFE->stateToSettings(m_settings); + m_rxOn = m_limeRFE->getRx(); + m_txOn = m_limeRFE->getTx(); displaySettings(); highlightApplyButton(false); } @@ -830,14 +834,14 @@ void LimeRFEGUI::on_deviceSetSync_clicked() void LimeRFEGUI::syncRxTx() { - if (!m_settings.m_txOn) { - stopStartTx(m_settings.m_txOn); + if (!m_txOn) { + stopStartTx(m_txOn); } - stopStartRx(m_settings.m_rxOn); + stopStartRx(m_rxOn); - if (m_settings.m_txOn) { - stopStartTx(m_settings.m_txOn); + if (m_txOn) { + stopStartTx(m_txOn); } } @@ -865,30 +869,30 @@ void LimeRFEGUI::on_modeRx_toggled(bool checked) { int rc; ui->statusText->clear(); - m_settings.m_rxOn = checked; + m_rxOn = checked; if (m_rxTxToggle) { - m_settings.m_txOn = !checked; + m_txOn = !checked; if (checked) // Rx on { - rc = m_limeRFE->setTx(m_settings, false); // stop Tx first + rc = m_limeRFE->setTx(false); // stop Tx first ui->statusText->append(QString("Stop TX: %1").arg(m_limeRFE->getError(rc).c_str())); } - rc = m_limeRFE->setRx(m_settings, m_settings.m_rxOn); // Rx on or off + rc = m_limeRFE->setRx(m_rxOn); // Rx on or off ui->statusText->append(QString("RX: %1").arg(m_limeRFE->getError(rc).c_str())); if (!checked) // Rx off { - rc = m_limeRFE->setTx(m_settings, true); // start Tx next + rc = m_limeRFE->setTx(true); // start Tx next ui->statusText->append(QString("Start TX: %1").arg(m_limeRFE->getError(rc).c_str())); } } else { - rc = m_limeRFE->setRx(m_settings, m_settings.m_rxOn); + rc = m_limeRFE->setRx(m_rxOn); ui->statusText->setText(m_limeRFE->getError(rc).c_str()); } @@ -903,30 +907,30 @@ void LimeRFEGUI::on_modeTx_toggled(bool checked) { int rc; ui->statusText->clear(); - m_settings.m_txOn = checked; + m_txOn = checked; if (m_rxTxToggle) { - m_settings.m_rxOn = !checked; + m_rxOn = !checked; if (checked) // Tx on { - rc = m_limeRFE->setRx(m_settings, false); // stop Rx first + rc = m_limeRFE->setRx(false); // stop Rx first ui->statusText->append(QString("Stop RX: %1").arg(m_limeRFE->getError(rc).c_str())); } - rc = m_limeRFE->setTx(m_settings, m_settings.m_txOn); // Tx on or off + rc = m_limeRFE->setTx(m_txOn); // Tx on or off ui->statusText->append(QString("TX: %1").arg(m_limeRFE->getError(rc).c_str())); if (!checked) // Tx off { - rc = m_limeRFE->setRx(m_settings, true); // start Rx next + rc = m_limeRFE->setRx(true); // start Rx next ui->statusText->append(QString("Start RX: %1").arg(m_limeRFE->getError(rc).c_str())); } } else { - rc = m_limeRFE->setTx(m_settings, m_settings.m_txOn); + rc = m_limeRFE->setTx(m_txOn); ui->statusText->setText(m_limeRFE->getError(rc).c_str()); } @@ -941,10 +945,10 @@ void LimeRFEGUI::on_rxTxToggle_clicked() { m_rxTxToggle = ui->rxTxToggle->isChecked(); - if (m_rxTxToggle && m_settings.m_rxOn && m_settings.m_txOn) + if (m_rxTxToggle && m_rxOn && m_txOn) { - m_settings.m_txOn = false; - int rc = m_limeRFE->setTx(m_settings, m_settings.m_txOn); + m_txOn = false; + int rc = m_limeRFE->setTx(m_txOn); ui->statusText->setText(m_limeRFE->getError(rc).c_str()); displayMode(); @@ -991,6 +995,22 @@ bool LimeRFEGUI::handleMessage(const Message& message) highlightApplyButton(cfg.getForce()); return true; } + else if (LimeRFE::MsgReportSetRx::match(message)) + { + bool on = ((LimeRFE::MsgReportSetRx&) message).isOn(); + qDebug("LimeRFEGUI::handleMessage: LimeRFE::MsgReportSetRx: %s", on ? "on" : "off"); + m_rxOn = on; + displaySettings(); + return true; + } + else if (LimeRFE::MsgReportSetTx::match(message)) + { + bool on = ((LimeRFE::MsgReportSetTx&) message).isOn(); + qDebug("LimeRFEGUI::handleMessage: LimeRFE::MsgReportSetTx: %s", on ? "on" : "off"); + m_txOn = on; + displaySettings(); + return true; + } return false; } diff --git a/plugins/feature/limerfe/limerfegui.h b/plugins/feature/limerfe/limerfegui.h index 1d6688aea..f3563b8ea 100644 --- a/plugins/feature/limerfe/limerfegui.h +++ b/plugins/feature/limerfe/limerfegui.h @@ -65,6 +65,8 @@ private: LimeRFESettings m_settings; LimeRFEUSBCalib* m_limeRFEUSBCalib; RollupState m_rollupState; + bool m_rxOn; + bool m_txOn; bool m_doApplySettings; bool m_rxTxToggle; QTimer m_timer; diff --git a/plugins/feature/limerfe/limerfesettings.cpp b/plugins/feature/limerfe/limerfesettings.cpp index e164cc96d..12a87b6fa 100644 --- a/plugins/feature/limerfe/limerfesettings.cpp +++ b/plugins/feature/limerfe/limerfesettings.cpp @@ -48,8 +48,6 @@ void LimeRFESettings::resetToDefaults() m_swrEnable = false; m_swrSource = SWRExternal; m_txRxDriven = false; - m_rxOn = false; - m_txOn = false; m_useReverseAPI = false; m_reverseAPIAddress = "127.0.0.1"; m_reverseAPIPort = 8888; @@ -79,8 +77,6 @@ QByteArray LimeRFESettings::serialize() const s.writeS32(16, (int) m_swrSource); s.writeBool(20, m_txRxDriven); - s.writeBool(21, m_rxOn); - s.writeBool(22, m_txOn); s.writeString(30, m_title); s.writeU32(31, m_rgbColor); @@ -145,8 +141,6 @@ bool LimeRFESettings::deserialize(const QByteArray& data) m_swrSource = (SWRSource) tmp; d.readBool(20, &m_txRxDriven, false); - d.readBool(21, &m_rxOn, false); - d.readBool(22, &m_txOn, false); d.readString(30, &m_title, "Lime RFE"); d.readU32(31, &m_rgbColor, QColor(50, 205, 50).rgb()); diff --git a/plugins/feature/limerfe/limerfesettings.h b/plugins/feature/limerfe/limerfesettings.h index 9e3a98180..2e29381b5 100644 --- a/plugins/feature/limerfe/limerfesettings.h +++ b/plugins/feature/limerfe/limerfesettings.h @@ -97,8 +97,6 @@ struct LimeRFESettings SWRSource m_swrSource; // Rx/Tx bool m_txRxDriven; //!< Tx settings set according to Rx settings - bool m_rxOn; - bool m_txOn; // Common QString m_devicePath; QString m_title; diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html index 7e220ddf6..423a2de1f 100644 --- a/sdrbase/resources/webapi/doc/html2/index.html +++ b/sdrbase/resources/webapi/doc/html2/index.html @@ -7092,6 +7092,10 @@ margin-bottom: 20px; "type" : "integer", "description" : "Switch on or off\n * 0 - Off\n * 1 - On\n" }, + "getState" : { + "type" : "integer", + "description" : "Set to non zero value to get the board state" + }, "fromToSettings" : { "type" : "integer", "description" : "Move from/to settings to/from device\n * 0 - From device to settings. The toGUI button in GUI mode\n * 1 - From settings to device. The Apply button in GUI mode\n" @@ -7144,6 +7148,14 @@ margin-bottom: 20px; }; defs.LimeRFEReport = { "properties" : { + "rxOn" : { + "type" : "integer", + "description" : "Boolean 1 if Rx is active else 0" + }, + "txOn" : { + "type" : "integer", + "description" : "Boolean 1 if Tx is active else 0" + }, "forwardPower" : { "type" : "integer", "description" : "relative forward power in centi-Bels" @@ -7226,14 +7238,6 @@ margin-bottom: 20px; "type" : "integer", "description" : "Boolean 1 if Tx is copy of Rx else 0" }, - "rxOn" : { - "type" : "integer", - "description" : "Boolean 1 if Rx is active else 0" - }, - "txOn" : { - "type" : "integer", - "description" : "Boolean 1 if Tx is active else 0" - }, "useReverseAPI" : { "type" : "integer", "description" : "Synchronize with reverse API (1 for yes, 0 for no)" @@ -59773,7 +59777,7 @@ except ApiException as e: