1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-04 07:51:14 -05:00

Add support for lnaGain API setting, to allow gain to be set more easily.

This commit is contained in:
Jon Beniston 2023-09-15 09:32:41 +01:00
parent a278cf0373
commit 1b1530f10d
7 changed files with 87 additions and 12 deletions

View File

@ -171,6 +171,7 @@ bool SDRPlayV3Gui::handleMessage(const Message& message)
if (SDRPlayV3Input::MsgConfigureSDRPlayV3::match(message))
{
const SDRPlayV3Input::MsgConfigureSDRPlayV3& cfg = (SDRPlayV3Input::MsgConfigureSDRPlayV3&) message;
qDebug() << "SDRPlayV3Gui::handleMessage: MsgConfigureSDRPlayV3: " << cfg.getSettings().getDebugString(cfg.getSettingsKeys(), cfg.getForce());
if (cfg.getForce()) {
m_settings = cfg.getSettings();
@ -313,6 +314,7 @@ void SDRPlayV3Gui::updateLNAValues()
const int *attenuations = SDRPlayV3LNA::getAttenuations(m_sdrPlayV3Input->getDeviceId(), m_settings.m_centerFrequency);
int len = attenuations[0];
ui->gainLNA->blockSignals(true);
ui->gainLNA->clear();
for (int i = 1; i <= len; i++)
{
@ -328,6 +330,7 @@ void SDRPlayV3Gui::updateLNAValues()
found = true;
}
}
ui->gainLNA->blockSignals(false);
}
void SDRPlayV3Gui::sendSettings()

View File

@ -778,14 +778,24 @@ int SDRPlayV3Input::webapiSettingsPutPatch(
{
(void) errorMessage;
SDRPlayV3Settings settings = m_settings;
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
QStringList deviceSettingsKeysModifiable = deviceSettingsKeys;
MsgConfigureSDRPlayV3 *msg = MsgConfigureSDRPlayV3::create(settings, deviceSettingsKeys, force);
webapiUpdateDeviceSettings(settings, deviceSettingsKeysModifiable, response);
// Convert lnaGain to lnaIndex
if (deviceSettingsKeysModifiable.contains("lnaGain"))
{
int lnaGain = response.getSdrPlayV3Settings()->getLnaGain();
settings.m_lnaIndex = mapLNAGainDBToLNAIndex(lnaGain, settings.m_centerFrequency);
deviceSettingsKeysModifiable.append("lnaIndex");
}
MsgConfigureSDRPlayV3 *msg = MsgConfigureSDRPlayV3::create(settings, deviceSettingsKeysModifiable, force);
m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureSDRPlayV3 *msgToGUI = MsgConfigureSDRPlayV3::create(settings, deviceSettingsKeys, force);
MsgConfigureSDRPlayV3 *msgToGUI = MsgConfigureSDRPlayV3::create(settings, deviceSettingsKeysModifiable, force);
m_guiMessageQueue->push(msgToGUI);
}
@ -893,6 +903,7 @@ void SDRPlayV3Input::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings&
response.getSdrPlayV3Settings()->setDcBlock(settings.m_dcBlock ? 1 : 0);
response.getSdrPlayV3Settings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
response.getSdrPlayV3Settings()->setLnaIndex(settings.m_lnaIndex);
response.getSdrPlayV3Settings()->setLnaGain(0); // Write only setting
response.getSdrPlayV3Settings()->setIfAgc(settings.m_ifAGC ? 1 : 0);
response.getSdrPlayV3Settings()->setIfGain(settings.m_ifGain);
response.getSdrPlayV3Settings()->setAmNotch(settings.m_amNotch);
@ -1011,6 +1022,9 @@ void SDRPlayV3Input::webapiReverseSendSettings(const QList<QString>& deviceSetti
if (deviceSettingsKeys.contains("lnaIndex") || force) {
swgSDRPlayV3Settings->setLnaIndex(settings.m_lnaIndex);
}
if (deviceSettingsKeys.contains("lnaGain") || force) {
swgSDRPlayV3Settings->setLnaGain(0); // Write only setting
}
if (deviceSettingsKeys.contains("ifAGC") || force) {
swgSDRPlayV3Settings->setIfAgc(settings.m_ifAGC ? 1 : 0);
}
@ -1118,7 +1132,7 @@ void SDRPlayV3Input::networkManagerFinished(QNetworkReply *reply)
reply->deleteLater();
}
int SDRPlayV3Input::getDeviceId()
int SDRPlayV3Input::getDeviceId() const
{
if (m_dev != nullptr)
return m_dev->hwVer; // E.g. SDRPLAY_RSPduo_ID
@ -1126,6 +1140,33 @@ int SDRPlayV3Input::getDeviceId()
return -1;
}
// Convert gain in dB to closest index
int SDRPlayV3Input::mapLNAGainDBToLNAIndex(int gainDB, qint64 frequency) const
{
const int *attenuations = SDRPlayV3LNA::getAttenuations(getDeviceId(), frequency);
int len = attenuations[0];
for (int i = 1; i <= len; i++)
{
if (gainDB >= -attenuations[i]) {
return i - 1;
}
}
return len - 1;
}
// Convert index to gain in dB
int SDRPlayV3Input::mapLNAIndexToLNAGainDB(int lnaIndex, qint64 frequency) const
{
const int *attenuations = SDRPlayV3LNA::getAttenuations(getDeviceId(), frequency);
int len = attenuations[0];
if (lnaIndex < len) {
return attenuations[lnaIndex+1];
} else {
return -1000;
}
}
// ====================================================================
sdrplay_api_Bw_MHzT SDRPlayV3Bandwidths::m_bwEnums[m_nb_bw] = {

View File

@ -134,7 +134,7 @@ public:
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response);
int getDeviceId();
int getDeviceId() const;
private:
DeviceAPI *m_deviceAPI;
@ -157,6 +157,8 @@ private:
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const SDRPlayV3Settings& settings, bool force);
void webapiReverseSendStartStop(bool start);
int mapLNAGainDBToLNAIndex(int gainDB, qint64 frequency) const;
int mapLNAIndexToLNAGainDB(int lnaIndex, qint64 frequency) const;
private slots:
void networkManagerFinished(QNetworkReply *reply);

View File

@ -502,10 +502,9 @@ bool ChannelWebAPIUtils::getGain(unsigned int deviceIndex, int stage, int &gain)
}
else if ((devId == "SDRplayV3"))
{
QStringList sdrplayStages = {"lnaIndex", "ifGain"};
QStringList sdrplayStages = {"lnaGain", "ifGain"};
if (stage < sdrplayStages.size())
{
// FIXME: How to map to lnaIndex - gain can vary by SDR
error = ChannelWebAPIUtils::getDeviceSetting(deviceIndex, sdrplayStages[stage], gain);
gain *= 10;
}
@ -561,10 +560,8 @@ bool ChannelWebAPIUtils::setGain(unsigned int deviceIndex, int stage, int gain)
}
else if (devId == "SDRplayV3")
{
QStringList sdrplayStages = {"lnaIndex", "ifGain"};
if (stage < sdrplayStages.size())
{
// FIXME: How to map to lnaIndex - gain can vary by SDR
QStringList sdrplayStages = {"lnaGain", "ifGain"};
if (stage < sdrplayStages.size()) {
return ChannelWebAPIUtils::patchDeviceSetting(deviceIndex, sdrplayStages[stage], gain / 10);
}
}
@ -1120,7 +1117,7 @@ bool ChannelWebAPIUtils::patchDeviceSetting(unsigned int deviceIndex, const QStr
if (getDeviceSettings(deviceIndex, deviceSettingsResponse, deviceSet))
{
// Patch centerFrequency
// Patch setting
QJsonObject *jsonObj = deviceSettingsResponse.asJsonObject();
int oldValue;
if (WebAPIUtils::getSubObjectInt(*jsonObj, setting, oldValue))

View File

@ -22,6 +22,9 @@ SDRPlayV3Settings:
type: integer
lnaIndex:
type: integer
lnaGain:
description: Gain in dB, as an alternative to lnaIndex setting
type: integer
ifAGC:
type: integer
ifGain:

View File

@ -48,6 +48,8 @@ SWGSDRPlayV3Settings::SWGSDRPlayV3Settings() {
m_iq_correction_isSet = false;
lna_index = 0;
m_lna_index_isSet = false;
lna_gain = 0;
m_lna_gain_isSet = false;
if_agc = 0;
m_if_agc_isSet = false;
if_gain = 0;
@ -108,6 +110,8 @@ SWGSDRPlayV3Settings::init() {
m_iq_correction_isSet = false;
lna_index = 0;
m_lna_index_isSet = false;
lna_gain = 0;
m_lna_gain_isSet = false;
if_agc = 0;
m_if_agc_isSet = false;
if_gain = 0;
@ -165,6 +169,7 @@ SWGSDRPlayV3Settings::cleanup() {
if(reverse_api_address != nullptr) {
@ -205,6 +210,8 @@ SWGSDRPlayV3Settings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&lna_index, pJson["lnaIndex"], "qint32", "");
::SWGSDRangel::setValue(&lna_gain, pJson["lnaGain"], "qint32", "");
::SWGSDRangel::setValue(&if_agc, pJson["ifAGC"], "qint32", "");
::SWGSDRangel::setValue(&if_gain, pJson["ifGain"], "qint32", "");
@ -283,6 +290,9 @@ SWGSDRPlayV3Settings::asJsonObject() {
if(m_lna_index_isSet){
obj->insert("lnaIndex", QJsonValue(lna_index));
}
if(m_lna_gain_isSet){
obj->insert("lnaGain", QJsonValue(lna_gain));
}
if(m_if_agc_isSet){
obj->insert("ifAGC", QJsonValue(if_agc));
}
@ -435,6 +445,16 @@ SWGSDRPlayV3Settings::setLnaIndex(qint32 lna_index) {
this->m_lna_index_isSet = true;
}
qint32
SWGSDRPlayV3Settings::getLnaGain() {
return lna_gain;
}
void
SWGSDRPlayV3Settings::setLnaGain(qint32 lna_gain) {
this->lna_gain = lna_gain;
this->m_lna_gain_isSet = true;
}
qint32
SWGSDRPlayV3Settings::getIfAgc() {
return if_agc;
@ -630,6 +650,9 @@ SWGSDRPlayV3Settings::isSet(){
if(m_lna_index_isSet){
isObjectUpdated = true; break;
}
if(m_lna_gain_isSet){
isObjectUpdated = true; break;
}
if(m_if_agc_isSet){
isObjectUpdated = true; break;
}

View File

@ -72,6 +72,9 @@ public:
qint32 getLnaIndex();
void setLnaIndex(qint32 lna_index);
qint32 getLnaGain();
void setLnaGain(qint32 lna_gain);
qint32 getIfAgc();
void setIfAgc(qint32 if_agc);
@ -154,6 +157,9 @@ private:
qint32 lna_index;
bool m_lna_index_isSet;
qint32 lna_gain;
bool m_lna_gain_isSet;
qint32 if_agc;
bool m_if_agc_isSet;