2021-02-10 21:35:56 +01:00
|
|
|
#include <imgui.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <module.h>
|
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <signal_path/signal_path.h>
|
|
|
|
#include <core.h>
|
|
|
|
#include <gui/style.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <options.h>
|
2021-02-11 15:29:51 +01:00
|
|
|
#include <sdrplay_api.h>
|
2022-01-21 20:22:13 +01:00
|
|
|
#include <gui/smgui.h>
|
2021-02-10 21:35:56 +01:00
|
|
|
|
|
|
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
|
|
|
|
2021-12-19 22:11:44 +01:00
|
|
|
SDRPP_MOD_INFO{
|
2021-02-10 21:35:56 +01:00
|
|
|
/* Name: */ "sdrplay_source",
|
2021-03-12 22:22:14 +01:00
|
|
|
/* Description: */ "SDRplay source module for SDR++",
|
2021-02-10 21:35:56 +01:00
|
|
|
/* Author: */ "Ryzerth",
|
|
|
|
/* Version: */ 0, 1, 0,
|
|
|
|
/* Max instances */ 1
|
|
|
|
};
|
|
|
|
|
|
|
|
ConfigManager config;
|
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
unsigned int sampleRates[] = {
|
|
|
|
2000000,
|
|
|
|
3000000,
|
|
|
|
4000000,
|
|
|
|
5000000,
|
|
|
|
6000000,
|
|
|
|
7000000,
|
|
|
|
8000000,
|
|
|
|
9000000,
|
|
|
|
10000000
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* sampleRatesTxt =
|
|
|
|
"2MHz\0"
|
|
|
|
"3MHz\0"
|
|
|
|
"4MHz\0"
|
|
|
|
"5MHz\0"
|
|
|
|
"6MHz\0"
|
|
|
|
"7MHz\0"
|
|
|
|
"8MHz\0"
|
|
|
|
"9MHz\0"
|
|
|
|
"10MHz\0";
|
|
|
|
|
|
|
|
sdrplay_api_Bw_MHzT bandwidths[] = {
|
|
|
|
sdrplay_api_BW_0_200,
|
|
|
|
sdrplay_api_BW_0_300,
|
|
|
|
sdrplay_api_BW_0_600,
|
|
|
|
sdrplay_api_BW_1_536,
|
|
|
|
sdrplay_api_BW_5_000,
|
|
|
|
sdrplay_api_BW_6_000,
|
|
|
|
sdrplay_api_BW_7_000,
|
|
|
|
sdrplay_api_BW_8_000,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* bandwidthsTxt =
|
|
|
|
"200KHz\0"
|
|
|
|
"300KHz\0"
|
|
|
|
"600KHz\0"
|
|
|
|
"1.536MHz\0"
|
|
|
|
"5MHz\0"
|
|
|
|
"6MHz\0"
|
|
|
|
"7MHz\0"
|
|
|
|
"8MHz\0"
|
|
|
|
"Auto\0";
|
|
|
|
|
|
|
|
sdrplay_api_Bw_MHzT preferedBandwidth[] = {
|
|
|
|
sdrplay_api_BW_5_000,
|
|
|
|
sdrplay_api_BW_5_000,
|
|
|
|
sdrplay_api_BW_5_000,
|
|
|
|
sdrplay_api_BW_5_000,
|
|
|
|
sdrplay_api_BW_6_000,
|
|
|
|
sdrplay_api_BW_7_000,
|
|
|
|
sdrplay_api_BW_8_000,
|
|
|
|
sdrplay_api_BW_8_000,
|
|
|
|
sdrplay_api_BW_8_000
|
|
|
|
};
|
|
|
|
|
2021-03-06 22:56:35 +01:00
|
|
|
const sdrplay_api_Rsp2_AntennaSelectT rsp2_antennaPorts[] = {
|
|
|
|
sdrplay_api_Rsp2_ANTENNA_A,
|
|
|
|
sdrplay_api_Rsp2_ANTENNA_B,
|
2021-03-07 00:22:35 +01:00
|
|
|
sdrplay_api_Rsp2_ANTENNA_B,
|
2021-03-06 22:56:35 +01:00
|
|
|
};
|
|
|
|
|
2021-03-07 00:22:35 +01:00
|
|
|
const char* rsp2_antennaPortsTxt = "Port A\0Port B\0Hi-Z\0";
|
2021-03-06 22:56:35 +01:00
|
|
|
|
|
|
|
const sdrplay_api_RspDx_AntennaSelectT rspdx_antennaPorts[] = {
|
|
|
|
sdrplay_api_RspDx_ANTENNA_A,
|
|
|
|
sdrplay_api_RspDx_ANTENNA_B,
|
|
|
|
sdrplay_api_RspDx_ANTENNA_C
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* rspdx_antennaPortsTxt = "Port A\0Port B\0Port C\0";
|
|
|
|
|
2021-08-30 00:28:51 +03:00
|
|
|
struct ifMode_t {
|
|
|
|
sdrplay_api_If_kHzT ifValue;
|
|
|
|
sdrplay_api_Bw_MHzT bw;
|
|
|
|
unsigned int deviceSamplerate;
|
|
|
|
unsigned int effectiveSamplerate;
|
|
|
|
};
|
|
|
|
|
|
|
|
ifMode_t ifModes[] = {
|
2021-12-19 22:11:44 +01:00
|
|
|
{ sdrplay_api_IF_Zero, sdrplay_api_BW_1_536, 2000000, 2000000 },
|
|
|
|
{ sdrplay_api_IF_2_048, sdrplay_api_BW_1_536, 8000000, 2000000 },
|
|
|
|
{ sdrplay_api_IF_2_048, sdrplay_api_BW_5_000, 8000000, 2000000 },
|
|
|
|
{ sdrplay_api_IF_1_620, sdrplay_api_BW_1_536, 6000000, 2000000 },
|
|
|
|
{ sdrplay_api_IF_0_450, sdrplay_api_BW_0_600, 2000000, 1000000 },
|
|
|
|
{ sdrplay_api_IF_0_450, sdrplay_api_BW_0_300, 2000000, 500000 },
|
|
|
|
{ sdrplay_api_IF_0_450, sdrplay_api_BW_0_200, 2000000, 500000 },
|
2021-08-30 00:28:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const char* ifModeTxt =
|
|
|
|
"ZeroIF\0"
|
2021-09-02 03:25:09 +03:00
|
|
|
"LowIF 2048KHz, IFBW 1536KHz\0"
|
|
|
|
"LowIF 2048KHz, IFBW 5000KHz\0"
|
|
|
|
"LowIF 1620KHz, IFBW 1536KHz\0"
|
|
|
|
"LowIF 450KHz, IFBW 600KHz\0"
|
|
|
|
"LowIF 450KHz, IFBW 300KHz\0"
|
|
|
|
"LowIF 450KHz, IFBW 200KHz\0";
|
2021-08-30 00:28:51 +03:00
|
|
|
|
2021-04-12 23:02:45 +02:00
|
|
|
const char* rspduo_antennaPortsTxt = "Tuner 1 (50Ohm)\0Tuner 1 (Hi-Z)\0Tuner 2 (50Ohm)\0";
|
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
class SDRPlaySourceModule : public ModuleManager::Instance {
|
|
|
|
public:
|
|
|
|
SDRPlaySourceModule(std::string name) {
|
|
|
|
this->name = name;
|
|
|
|
|
2021-02-11 22:53:00 +01:00
|
|
|
// Init callbacks
|
2021-02-12 22:44:29 +01:00
|
|
|
cbFuncs.EventCbFn = eventCB;
|
|
|
|
cbFuncs.StreamACbFn = streamCB;
|
|
|
|
cbFuncs.StreamBCbFn = streamCB;
|
2021-02-11 22:53:00 +01:00
|
|
|
|
2021-07-27 16:32:25 +02:00
|
|
|
sdrplay_api_ErrT err = sdrplay_api_Open();
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
spdlog::error("Could not intiatialized the SDRplay API. Make sure that the service is running.");
|
|
|
|
return;
|
|
|
|
}
|
2021-02-11 15:29:51 +01:00
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
sampleRate = 2000000.0;
|
|
|
|
srId = 0;
|
|
|
|
|
|
|
|
bandwidth = sdrplay_api_BW_5_000;
|
|
|
|
bandwidthId = 8;
|
2021-02-10 21:35:56 +01:00
|
|
|
|
|
|
|
handler.ctx = this;
|
|
|
|
handler.selectHandler = menuSelected;
|
2021-12-19 22:11:44 +01:00
|
|
|
handler.deselectHandler = menuDeselected;
|
2021-02-10 21:35:56 +01:00
|
|
|
handler.menuHandler = menuHandler;
|
|
|
|
handler.startHandler = start;
|
|
|
|
handler.stopHandler = stop;
|
|
|
|
handler.tuneHandler = tune;
|
|
|
|
handler.stream = &stream;
|
|
|
|
|
|
|
|
refresh();
|
2021-03-09 02:21:30 +01:00
|
|
|
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
std::string confSelectDev = config.conf["device"];
|
|
|
|
config.release();
|
|
|
|
selectByName(confSelectDev);
|
2021-02-11 22:53:00 +01:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
sigpath::sourceManager.registerSource("SDRplay", &handler);
|
2021-07-29 20:22:16 +02:00
|
|
|
|
|
|
|
initOk = true;
|
2021-02-10 21:35:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~SDRPlaySourceModule() {
|
2021-07-26 03:11:51 +02:00
|
|
|
stop(this);
|
2021-07-29 20:22:16 +02:00
|
|
|
if (initOk) { sdrplay_api_Close(); }
|
2021-07-26 03:11:51 +02:00
|
|
|
sigpath::sourceManager.unregisterSource("SDRplay");
|
2021-02-10 21:35:56 +01:00
|
|
|
}
|
|
|
|
|
2021-07-26 03:11:51 +02:00
|
|
|
void postInit() {}
|
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
void enable() {
|
|
|
|
enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void disable() {
|
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void refresh() {
|
|
|
|
devList.clear();
|
2021-03-09 02:21:30 +01:00
|
|
|
devNameList.clear();
|
2021-02-10 21:35:56 +01:00
|
|
|
devListTxt = "";
|
|
|
|
|
2021-02-11 15:29:51 +01:00
|
|
|
sdrplay_api_DeviceT devArr[128];
|
|
|
|
unsigned int numDev = 0;
|
|
|
|
sdrplay_api_GetDevices(devArr, &numDev, 128);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < numDev; i++) {
|
2021-02-11 22:53:00 +01:00
|
|
|
devList.push_back(devArr[i]);
|
2021-03-09 02:21:30 +01:00
|
|
|
std::string name = "";
|
2021-02-12 22:44:29 +01:00
|
|
|
switch (devArr[i].hwVer) {
|
2021-12-19 22:11:44 +01:00
|
|
|
case SDRPLAY_RSP1_ID:
|
|
|
|
name = "RSP1 (";
|
|
|
|
name += devArr[i].SerNo;
|
|
|
|
name += ')';
|
|
|
|
break;
|
|
|
|
case SDRPLAY_RSP1A_ID:
|
|
|
|
name = "RSP1A (";
|
|
|
|
name += devArr[i].SerNo;
|
|
|
|
name += ')';
|
|
|
|
break;
|
|
|
|
case SDRPLAY_RSP2_ID:
|
|
|
|
name = "RSP2 (";
|
|
|
|
name += devArr[i].SerNo;
|
|
|
|
name += ')';
|
|
|
|
break;
|
|
|
|
case SDRPLAY_RSPduo_ID:
|
|
|
|
name = "RSPduo (";
|
|
|
|
name += devArr[i].SerNo;
|
|
|
|
name += ')';
|
|
|
|
break;
|
|
|
|
case SDRPLAY_RSPdx_ID:
|
|
|
|
name = "RSPdx (";
|
|
|
|
name += devArr[i].SerNo;
|
|
|
|
name += ')';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
name = "Unknown (";
|
|
|
|
name += devArr[i].SerNo;
|
|
|
|
name += ')';
|
|
|
|
break;
|
2021-02-12 22:44:29 +01:00
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
devNameList.push_back(name);
|
|
|
|
devListTxt += name;
|
2021-02-11 15:29:51 +01:00
|
|
|
devListTxt += '\0';
|
|
|
|
}
|
2021-02-10 21:35:56 +01:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:53:00 +01:00
|
|
|
void selectFirst() {
|
2021-04-28 15:34:24 +02:00
|
|
|
if (devList.size() == 0) {
|
|
|
|
selectedName = "";
|
|
|
|
return;
|
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
selectDev(devList[0], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void selectByName(std::string name) {
|
|
|
|
for (int i = 0; i < devNameList.size(); i++) {
|
|
|
|
if (devNameList[i] == name) {
|
|
|
|
selectDev(devList[i], i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectFirst();
|
2021-02-11 22:53:00 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
void selectById(int id) {
|
2021-03-09 02:21:30 +01:00
|
|
|
selectDev(devList[id], id);
|
2021-02-26 16:52:54 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 02:21:30 +01:00
|
|
|
void selectDev(sdrplay_api_DeviceT dev, int id) {
|
2021-02-11 22:53:00 +01:00
|
|
|
openDev = dev;
|
|
|
|
sdrplay_api_ErrT err;
|
|
|
|
|
2021-04-20 22:53:23 +02:00
|
|
|
openDev.tuner = sdrplay_api_Tuner_A;
|
2021-04-12 23:02:45 +02:00
|
|
|
openDev.rspDuoMode = sdrplay_api_RspDuoMode_Single_Tuner;
|
2021-02-11 22:53:00 +01:00
|
|
|
err = sdrplay_api_SelectDevice(&openDev);
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
const char* errStr = sdrplay_api_GetErrorString(err);
|
|
|
|
spdlog::error("Could not select RSP device: {0}", errStr);
|
2021-03-09 02:21:30 +01:00
|
|
|
selectedName = "";
|
2021-02-11 22:53:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-20 22:53:23 +02:00
|
|
|
sdrplay_api_UnlockDeviceApi();
|
|
|
|
sdrplay_api_DebugEnable(openDev.dev, sdrplay_api_DbgLvl_Message);
|
|
|
|
|
2021-02-11 22:53:00 +01:00
|
|
|
err = sdrplay_api_GetDeviceParams(openDev.dev, &openDevParams);
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
const char* errStr = sdrplay_api_GetErrorString(err);
|
|
|
|
spdlog::error("Could not get device params for RSP device: {0}", errStr);
|
2021-03-09 02:21:30 +01:00
|
|
|
selectedName = "";
|
2021-02-11 22:53:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:44:29 +01:00
|
|
|
err = sdrplay_api_Init(openDev.dev, &cbFuncs, this);
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
const char* errStr = sdrplay_api_GetErrorString(err);
|
|
|
|
spdlog::error("Could not init RSP device: {0}", errStr);
|
2021-03-09 02:21:30 +01:00
|
|
|
selectedName = "";
|
2021-02-12 22:44:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-02-11 22:53:00 +01:00
|
|
|
|
2021-04-20 22:53:23 +02:00
|
|
|
channelParams = openDevParams->rxChannelA;
|
|
|
|
|
2021-03-09 02:21:30 +01:00
|
|
|
selectedName = devNameList[id];
|
|
|
|
|
2021-03-07 00:57:08 +01:00
|
|
|
if (openDev.hwVer == SDRPLAY_RSP1_ID) {
|
|
|
|
lnaSteps = 4;
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSP1A_ID) {
|
|
|
|
lnaSteps = 10;
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSP2_ID) {
|
|
|
|
lnaSteps = 9;
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSPduo_ID) {
|
|
|
|
lnaSteps = 10;
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSPdx_ID) {
|
|
|
|
lnaSteps = 28;
|
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
|
|
|
|
bool created = false;
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
if (!config.conf["devices"].contains(selectedName)) {
|
|
|
|
created = true;
|
|
|
|
config.conf["devices"][selectedName]["sampleRate"] = sampleRates[0];
|
|
|
|
config.conf["devices"][selectedName]["bwMode"] = 8; // Auto
|
|
|
|
config.conf["devices"][selectedName]["lnaGain"] = lnaSteps - 1;
|
|
|
|
config.conf["devices"][selectedName]["ifGain"] = 59;
|
2021-11-23 17:05:40 +01:00
|
|
|
config.conf["devices"][selectedName]["agc"] = false;
|
|
|
|
|
|
|
|
config.conf["devices"][selectedName]["agcAttack"] = 500;
|
|
|
|
config.conf["devices"][selectedName]["agcDecay"] = 500;
|
|
|
|
config.conf["devices"][selectedName]["agcDecayDelay"] = 200;
|
|
|
|
config.conf["devices"][selectedName]["agcDecayThreshold"] = 5;
|
|
|
|
config.conf["devices"][selectedName]["agcSetPoint"] = -30;
|
2021-03-09 02:21:30 +01:00
|
|
|
|
2021-08-30 00:28:51 +03:00
|
|
|
config.conf["devices"][selectedName]["ifModeId"] = 0;
|
|
|
|
|
2021-03-09 02:21:30 +01:00
|
|
|
if (openDev.hwVer == SDRPLAY_RSP1_ID) {
|
|
|
|
// No config to load
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSP1A_ID) {
|
|
|
|
config.conf["devices"][selectedName]["fmNotch"] = false;
|
|
|
|
config.conf["devices"][selectedName]["dabNotch"] = false;
|
|
|
|
config.conf["devices"][selectedName]["biast"] = false;
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSP2_ID) {
|
|
|
|
config.conf["devices"][selectedName]["antenna"] = 0;
|
|
|
|
config.conf["devices"][selectedName]["notch"] = false;
|
|
|
|
config.conf["devices"][selectedName]["biast"] = false;
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSPduo_ID) {
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["antenna"] = 0;
|
2021-04-10 03:06:51 +02:00
|
|
|
config.conf["devices"][selectedName]["fmNotch"] = false;
|
|
|
|
config.conf["devices"][selectedName]["dabNotch"] = false;
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["amNotch"] = false;
|
2021-04-10 03:06:51 +02:00
|
|
|
config.conf["devices"][selectedName]["biast"] = false;
|
2021-03-09 02:21:30 +01:00
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSPdx_ID) {
|
|
|
|
config.conf["devices"][selectedName]["antenna"] = 0;
|
|
|
|
config.conf["devices"][selectedName]["fmNotch"] = false;
|
|
|
|
config.conf["devices"][selectedName]["dabNotch"] = false;
|
|
|
|
config.conf["devices"][selectedName]["biast"] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// General options
|
|
|
|
if (config.conf["devices"][selectedName].contains("sampleRate")) {
|
|
|
|
sampleRate = config.conf["devices"][selectedName]["sampleRate"];
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
if (sampleRates[i] == sampleRate) {
|
|
|
|
srId = i;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
sampleRate = sampleRates[0];
|
|
|
|
srId = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-08-30 00:28:51 +03:00
|
|
|
|
2021-12-19 22:11:44 +01:00
|
|
|
if (config.conf["devices"][selectedName].contains("ifModeId")) {
|
|
|
|
ifModeId = config.conf["devices"][selectedName]["ifModeId"];
|
|
|
|
if (ifModeId != 0) {
|
2021-08-30 00:28:51 +03:00
|
|
|
sampleRate = ifModes[ifModeId].effectiveSamplerate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 02:21:30 +01:00
|
|
|
if (config.conf["devices"][selectedName].contains("bwMode")) {
|
|
|
|
bandwidthId = config.conf["devices"][selectedName]["bwMode"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("lnaGain")) {
|
|
|
|
lnaGain = config.conf["devices"][selectedName]["lnaGain"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("ifGain")) {
|
|
|
|
gain = config.conf["devices"][selectedName]["ifGain"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("agc")) {
|
2021-11-23 17:05:40 +01:00
|
|
|
if (!config.conf["devices"][selectedName]["agc"].is_boolean()) {
|
|
|
|
int oldMode = config.conf["devices"][selectedName]["agc"];
|
|
|
|
config.conf["devices"][selectedName]["agc"] = (bool)(oldMode != 0);
|
|
|
|
created = true;
|
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
agc = config.conf["devices"][selectedName]["agc"];
|
|
|
|
}
|
2021-11-23 17:05:40 +01:00
|
|
|
if (config.conf["devices"][selectedName].contains("agcAttack")) {
|
|
|
|
agcAttack = config.conf["devices"][selectedName]["agcAttack"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("agcDecay")) {
|
|
|
|
agcDecay = config.conf["devices"][selectedName]["agcDecay"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("agcDecayDelay")) {
|
|
|
|
agcDecayDelay = config.conf["devices"][selectedName]["agcDecayDelay"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("agcDecayThreshold")) {
|
|
|
|
agcDecayThreshold = config.conf["devices"][selectedName]["agcDecayThreshold"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("agcSetPoint")) {
|
|
|
|
agcSetPoint = config.conf["devices"][selectedName]["agcSetPoint"];
|
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
|
2021-04-28 15:34:24 +02:00
|
|
|
core::setInputSampleRate(sampleRate);
|
|
|
|
|
2021-03-09 02:21:30 +01:00
|
|
|
// Per device options
|
|
|
|
if (openDev.hwVer == SDRPLAY_RSP1_ID) {
|
|
|
|
// No config to load
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSP1A_ID) {
|
|
|
|
if (config.conf["devices"][selectedName].contains("fmNotch")) {
|
|
|
|
rsp1a_fmNotch = config.conf["devices"][selectedName]["fmNotch"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("dabNotch")) {
|
|
|
|
rsp1a_dabNotch = config.conf["devices"][selectedName]["dabNotch"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("biast")) {
|
|
|
|
rsp1a_biasT = config.conf["devices"][selectedName]["biast"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSP2_ID) {
|
|
|
|
if (config.conf["devices"][selectedName].contains("antenna")) {
|
|
|
|
rsp2_antennaPort = config.conf["devices"][selectedName]["antenna"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("notch")) {
|
|
|
|
rsp2_notch = config.conf["devices"][selectedName]["notch"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("biast")) {
|
|
|
|
rsp2_biasT = config.conf["devices"][selectedName]["biast"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSPduo_ID) {
|
2021-04-12 23:02:45 +02:00
|
|
|
if (config.conf["devices"][selectedName].contains("antenna")) {
|
|
|
|
rspduo_antennaPort = config.conf["devices"][selectedName]["antenna"];
|
|
|
|
}
|
2021-04-10 03:06:51 +02:00
|
|
|
if (config.conf["devices"][selectedName].contains("fmNotch")) {
|
|
|
|
rspduo_fmNotch = config.conf["devices"][selectedName]["fmNotch"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("dabNotch")) {
|
|
|
|
rspduo_dabNotch = config.conf["devices"][selectedName]["dabNotch"];
|
|
|
|
}
|
2021-04-12 23:02:45 +02:00
|
|
|
if (config.conf["devices"][selectedName].contains("amNotch")) {
|
|
|
|
rspduo_amNotch = config.conf["devices"][selectedName]["amNotch"];
|
|
|
|
}
|
2021-04-10 03:06:51 +02:00
|
|
|
if (config.conf["devices"][selectedName].contains("biast")) {
|
|
|
|
rspduo_biasT = config.conf["devices"][selectedName]["biast"];
|
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
}
|
|
|
|
else if (openDev.hwVer == SDRPLAY_RSPdx_ID) {
|
|
|
|
if (config.conf["devices"][selectedName].contains("antenna")) {
|
|
|
|
rspdx_antennaPort = config.conf["devices"][selectedName]["antenna"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("fmNotch")) {
|
|
|
|
rspdx_fmNotch = config.conf["devices"][selectedName]["fmNotch"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("dabNotch")) {
|
|
|
|
rspdx_dabNotch = config.conf["devices"][selectedName]["dabNotch"];
|
|
|
|
}
|
|
|
|
if (config.conf["devices"][selectedName].contains("biast")) {
|
|
|
|
rspdx_biasT = config.conf["devices"][selectedName]["biast"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config.release(created);
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-03-07 00:57:08 +01:00
|
|
|
if (lnaGain >= lnaSteps) { lnaGain = lnaSteps - 1; }
|
|
|
|
|
2021-04-28 15:34:24 +02:00
|
|
|
// Release device after selecting
|
|
|
|
sdrplay_api_Uninit(openDev.dev);
|
|
|
|
sdrplay_api_ReleaseDevice(&openDev);
|
2021-02-11 22:53:00 +01:00
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-04-12 23:02:45 +02:00
|
|
|
void rspDuoSelectTuner(sdrplay_api_TunerSelectT tuner, sdrplay_api_RspDuo_AmPortSelectT amPort) {
|
2021-04-20 22:53:23 +02:00
|
|
|
if (openDev.tuner != tuner) {
|
|
|
|
spdlog::info("Swapping tuners");
|
|
|
|
auto ret = sdrplay_api_SwapRspDuoActiveTuner(openDev.dev, &openDev.tuner, amPort);
|
|
|
|
if (ret != 0) {
|
|
|
|
spdlog::error("Error while swapping tuners: {0}", (int)ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the channel params
|
|
|
|
channelParams = (tuner == sdrplay_api_Tuner_A) ? openDevParams->rxChannelA : openDevParams->rxChannelB;
|
2021-04-21 03:03:40 +02:00
|
|
|
channelParams->rspDuoTunerParams.tuner1AmPortSel = amPort;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_AmPortSelect, sdrplay_api_Update_Ext1_None);
|
2021-04-21 14:53:09 +02:00
|
|
|
|
|
|
|
// Refresh gains (for some reason they're lost)
|
|
|
|
channelParams->tunerParams.gain.LNAstate = lnaGain;
|
|
|
|
channelParams->tunerParams.gain.gRdB = gain;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None);
|
2021-04-12 23:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void rspDuoSelectAntennaPort(int port) {
|
2021-04-20 22:53:23 +02:00
|
|
|
if (port == 0) { rspDuoSelectTuner(sdrplay_api_Tuner_A, sdrplay_api_RspDuo_AMPORT_2); }
|
|
|
|
if (port == 1) { rspDuoSelectTuner(sdrplay_api_Tuner_A, sdrplay_api_RspDuo_AMPORT_1); }
|
|
|
|
if (port == 2) { rspDuoSelectTuner(sdrplay_api_Tuner_B, sdrplay_api_RspDuo_AMPORT_1); }
|
2021-03-07 20:10:10 +01:00
|
|
|
}
|
2021-02-11 22:53:00 +01:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
private:
|
|
|
|
std::string getBandwdithScaled(double bw) {
|
|
|
|
char buf[1024];
|
|
|
|
if (bw >= 1000000.0) {
|
|
|
|
sprintf(buf, "%.1lfMHz", bw / 1000000.0);
|
|
|
|
}
|
|
|
|
else if (bw >= 1000.0) {
|
|
|
|
sprintf(buf, "%.1lfKHz", bw / 1000.0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(buf, "%.1lfHz", bw);
|
|
|
|
}
|
|
|
|
return std::string(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menuSelected(void* ctx) {
|
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx;
|
|
|
|
core::setInputSampleRate(_this->sampleRate);
|
|
|
|
spdlog::info("SDRPlaySourceModule '{0}': Menu Select!", _this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menuDeselected(void* ctx) {
|
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx;
|
|
|
|
spdlog::info("SDRPlaySourceModule '{0}': Menu Deselect!", _this->name);
|
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
static void start(void* ctx) {
|
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx;
|
2021-07-26 04:16:00 +02:00
|
|
|
if (_this->running) { return; }
|
2021-04-28 15:34:24 +02:00
|
|
|
|
2021-07-09 14:24:07 -04:00
|
|
|
// First, acquire device
|
2021-02-12 22:44:29 +01:00
|
|
|
sdrplay_api_ErrT err;
|
|
|
|
|
2021-04-28 15:34:24 +02:00
|
|
|
_this->openDev.tuner = sdrplay_api_Tuner_A;
|
|
|
|
_this->openDev.rspDuoMode = sdrplay_api_RspDuoMode_Single_Tuner;
|
|
|
|
err = sdrplay_api_SelectDevice(&_this->openDev);
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
const char* errStr = sdrplay_api_GetErrorString(err);
|
|
|
|
spdlog::error("Could not select RSP device: {0}", errStr);
|
|
|
|
_this->selectedName = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdrplay_api_UnlockDeviceApi();
|
|
|
|
sdrplay_api_DebugEnable(_this->openDev.dev, sdrplay_api_DbgLvl_Message);
|
|
|
|
|
|
|
|
err = sdrplay_api_GetDeviceParams(_this->openDev.dev, &_this->openDevParams);
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
const char* errStr = sdrplay_api_GetErrorString(err);
|
|
|
|
spdlog::error("Could not get device params for RSP device: {0}", errStr);
|
|
|
|
_this->selectedName = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = sdrplay_api_Init(_this->openDev.dev, &_this->cbFuncs, _this);
|
|
|
|
if (err != sdrplay_api_Success) {
|
|
|
|
const char* errStr = sdrplay_api_GetErrorString(err);
|
|
|
|
spdlog::error("Could not init RSP device: {0}", errStr);
|
|
|
|
_this->selectedName = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_this->channelParams = _this->openDevParams->rxChannelA;
|
|
|
|
|
|
|
|
// Configure device
|
2021-02-20 15:27:43 +01:00
|
|
|
_this->bufferIndex = 0;
|
2021-04-21 03:03:40 +02:00
|
|
|
_this->bufferSize = (float)_this->sampleRate / 200.0f;
|
2021-02-20 15:27:43 +01:00
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
// RSP1A Options
|
2021-03-06 22:56:35 +01:00
|
|
|
if (_this->openDev.hwVer == SDRPLAY_RSP1A_ID) {
|
|
|
|
_this->openDevParams->devParams->rsp1aParams.rfNotchEnable = _this->rsp1a_fmNotch;
|
2021-10-10 18:26:17 +02:00
|
|
|
_this->openDevParams->devParams->rsp1aParams.rfDabNotchEnable = _this->rsp1a_dabNotch;
|
2021-04-20 22:53:23 +02:00
|
|
|
_this->channelParams->rsp1aTunerParams.biasTEnable = _this->rsp1a_biasT;
|
2021-03-06 22:56:35 +01:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp1a_RfNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp1a_RfDabNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp1a_BiasTControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
|
|
|
else if (_this->openDev.hwVer == SDRPLAY_RSP2_ID) {
|
2021-04-20 22:53:23 +02:00
|
|
|
_this->channelParams->rsp2TunerParams.rfNotchEnable = _this->rsp2_notch;
|
|
|
|
_this->channelParams->rsp2TunerParams.biasTEnable = _this->rsp2_biasT;
|
|
|
|
_this->channelParams->rsp2TunerParams.antennaSel = rsp2_antennaPorts[_this->rsp2_antennaPort];
|
|
|
|
_this->channelParams->rsp2TunerParams.amPortSel = (_this->rsp2_antennaPort == 2) ? sdrplay_api_Rsp2_AMPORT_1 : sdrplay_api_Rsp2_AMPORT_2;
|
2021-03-06 22:56:35 +01:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_RfNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_BiasTControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_AntennaControl, sdrplay_api_Update_Ext1_None);
|
2021-03-07 00:22:35 +01:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_AmPortSelect, sdrplay_api_Update_Ext1_None);
|
2021-04-10 03:06:51 +02:00
|
|
|
}
|
|
|
|
else if (_this->openDev.hwVer == SDRPLAY_RSPduo_ID) {
|
2021-04-12 23:02:45 +02:00
|
|
|
// NOTE: mmight require setting it on both RXA and RXB
|
|
|
|
_this->rspDuoSelectAntennaPort(_this->rspduo_antennaPort);
|
2021-04-20 22:53:23 +02:00
|
|
|
_this->channelParams->rspDuoTunerParams.biasTEnable = _this->rspduo_biasT;
|
|
|
|
_this->channelParams->rspDuoTunerParams.rfNotchEnable = _this->rspduo_fmNotch;
|
|
|
|
_this->channelParams->rspDuoTunerParams.rfDabNotchEnable = _this->rspduo_dabNotch;
|
|
|
|
_this->channelParams->rspDuoTunerParams.tuner1AmNotchEnable = _this->rspduo_amNotch;
|
2021-04-12 23:02:45 +02:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_BiasTControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_RfNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_RfDabNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_Tuner1AmNotchControl, sdrplay_api_Update_Ext1_None);
|
2021-03-06 22:56:35 +01:00
|
|
|
}
|
|
|
|
else if (_this->openDev.hwVer == SDRPLAY_RSPdx_ID) {
|
|
|
|
_this->openDevParams->devParams->rspDxParams.rfNotchEnable = _this->rspdx_fmNotch;
|
2021-03-07 00:47:12 +01:00
|
|
|
_this->openDevParams->devParams->rspDxParams.rfDabNotchEnable = _this->rspdx_dabNotch;
|
2021-03-06 22:56:35 +01:00
|
|
|
_this->openDevParams->devParams->rspDxParams.biasTEnable = _this->rspdx_biasT;
|
|
|
|
_this->openDevParams->devParams->rspDxParams.antennaSel = rspdx_antennaPorts[_this->rspdx_antennaPort];
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_RfNotchControl);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_RfDabNotchControl);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_BiasTControl);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_AntennaControl);
|
|
|
|
}
|
2021-02-26 16:52:54 +01:00
|
|
|
|
2021-04-12 23:02:45 +02:00
|
|
|
// General options
|
2021-12-19 22:11:44 +01:00
|
|
|
if (_this->ifModeId == 0) {
|
2021-08-30 00:28:51 +03:00
|
|
|
_this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId];
|
|
|
|
_this->openDevParams->devParams->fsFreq.fsHz = _this->sampleRate;
|
|
|
|
_this->channelParams->tunerParams.bwType = _this->bandwidth;
|
2021-12-19 22:11:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-08-30 00:28:51 +03:00
|
|
|
_this->openDevParams->devParams->fsFreq.fsHz = ifModes[_this->ifModeId].deviceSamplerate;
|
|
|
|
_this->channelParams->tunerParams.bwType = ifModes[_this->ifModeId].bw;
|
|
|
|
}
|
2021-04-20 22:53:23 +02:00
|
|
|
_this->channelParams->tunerParams.rfFreq.rfHz = _this->freq;
|
|
|
|
_this->channelParams->tunerParams.gain.gRdB = _this->gain;
|
|
|
|
_this->channelParams->tunerParams.gain.LNAstate = _this->lnaGain;
|
|
|
|
_this->channelParams->ctrlParams.decimation.enable = false;
|
|
|
|
_this->channelParams->ctrlParams.dcOffset.DCenable = true;
|
|
|
|
_this->channelParams->ctrlParams.dcOffset.IQenable = true;
|
2021-08-30 00:28:51 +03:00
|
|
|
_this->channelParams->tunerParams.ifType = ifModes[_this->ifModeId].ifValue;
|
2021-04-20 22:53:23 +02:00
|
|
|
_this->channelParams->tunerParams.loMode = sdrplay_api_LO_Auto;
|
2021-04-20 01:38:32 +02:00
|
|
|
|
|
|
|
// Hard coded AGC parameters
|
2021-11-23 17:05:40 +01:00
|
|
|
_this->channelParams->ctrlParams.agc.attack_ms = _this->agcAttack;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_ms = _this->agcDecay;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_delay_ms = _this->agcDecayDelay;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_threshold_dB = _this->agcDecayThreshold;
|
|
|
|
_this->channelParams->ctrlParams.agc.setPoint_dBfs = _this->agcSetPoint;
|
|
|
|
_this->channelParams->ctrlParams.agc.enable = _this->agc ? sdrplay_api_AGC_CTRL_EN : sdrplay_api_AGC_DISABLE;
|
2021-04-20 01:38:32 +02:00
|
|
|
|
2021-04-12 23:02:45 +02:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Dev_Fs, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_BwType, sdrplay_api_Update_Ext1_None);
|
2021-04-20 22:53:23 +02:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_IfType, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_LoMode, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Decimation, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_DCoffsetIQimbalance, sdrplay_api_Update_Ext1_None);
|
2021-04-12 23:02:45 +02:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Frf, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None);
|
2021-04-21 03:03:40 +02:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None);
|
2021-04-12 23:02:45 +02:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
_this->running = true;
|
|
|
|
spdlog::info("SDRPlaySourceModule '{0}': Start!", _this->name);
|
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
static void stop(void* ctx) {
|
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx;
|
2021-07-26 04:16:00 +02:00
|
|
|
if (!_this->running) { return; }
|
2021-02-10 21:35:56 +01:00
|
|
|
_this->running = false;
|
|
|
|
_this->stream.stopWriter();
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-04-28 15:34:24 +02:00
|
|
|
// Release device after stopping
|
|
|
|
sdrplay_api_Uninit(_this->openDev.dev);
|
|
|
|
sdrplay_api_ReleaseDevice(&_this->openDev);
|
2021-02-10 21:35:56 +01:00
|
|
|
|
|
|
|
_this->stream.clearWriteStop();
|
|
|
|
spdlog::info("SDRPlaySourceModule '{0}': Stop!", _this->name);
|
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
static void tune(double freq, void* ctx) {
|
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx;
|
|
|
|
if (_this->running) {
|
2021-04-20 22:53:23 +02:00
|
|
|
_this->channelParams->tunerParams.rfFreq.rfHz = freq;
|
2021-02-12 22:44:29 +01:00
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Frf, sdrplay_api_Update_Ext1_None);
|
2021-02-10 21:35:56 +01:00
|
|
|
}
|
|
|
|
_this->freq = freq;
|
|
|
|
spdlog::info("SDRPlaySourceModule '{0}': Tune: {1}!", _this->name, freq);
|
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
static void menuHandler(void* ctx) {
|
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx;
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
if (_this->running) { SmGui::BeginDisabled(); }
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::FillWidth();
|
|
|
|
SmGui::ForceSync();
|
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_dev", _this->name), &_this->devId, _this->devListTxt.c_str())) {
|
2021-02-26 16:52:54 +01:00
|
|
|
_this->selectById(_this->devId);
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["device"] = _this->devNameList[_this->devId];
|
|
|
|
config.release(true);
|
2021-02-26 16:52:54 +01:00
|
|
|
}
|
2021-02-14 22:23:30 +01:00
|
|
|
|
2021-08-30 00:28:51 +03:00
|
|
|
if (_this->ifModeId == 0) {
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_sr", _this->name), &_this->srId, sampleRatesTxt)) {
|
2021-08-30 00:28:51 +03:00
|
|
|
_this->sampleRate = sampleRates[_this->srId];
|
|
|
|
if (_this->bandwidthId == 8) {
|
|
|
|
_this->bandwidth = preferedBandwidth[_this->srId];
|
|
|
|
}
|
|
|
|
core::setInputSampleRate(_this->sampleRate);
|
|
|
|
config.acquire();
|
|
|
|
config.conf["devices"][_this->selectedName]["sampleRate"] = _this->sampleRate;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2021-04-28 15:34:24 +02:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::SameLine();
|
|
|
|
SmGui::FillWidth();
|
|
|
|
SmGui::ForceSync();
|
|
|
|
if (SmGui::Button(CONCAT("Refresh##sdrplay_refresh", _this->name))) {
|
2021-08-30 00:28:51 +03:00
|
|
|
_this->refresh();
|
|
|
|
_this->selectByName(_this->selectedName);
|
|
|
|
}
|
2021-02-15 14:55:48 +01:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::FillWidth();
|
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_bw", _this->name), &_this->bandwidthId, bandwidthsTxt)) {
|
2021-08-30 00:28:51 +03:00
|
|
|
_this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId];
|
|
|
|
if (_this->running) {
|
|
|
|
_this->channelParams->tunerParams.bwType = _this->bandwidth;
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_BwType, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
|
|
|
config.acquire();
|
|
|
|
config.conf["devices"][_this->selectedName]["bwMode"] = _this->bandwidthId;
|
|
|
|
config.release(true);
|
2021-02-26 16:52:54 +01:00
|
|
|
}
|
|
|
|
}
|
2021-08-30 16:37:29 +02:00
|
|
|
else {
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::FillWidth();
|
|
|
|
SmGui::ForceSync();
|
|
|
|
if (SmGui::Button(CONCAT("Refresh##sdrplay_refresh", _this->name))) {
|
2021-08-30 16:37:29 +02:00
|
|
|
_this->refresh();
|
|
|
|
_this->selectByName(_this->selectedName);
|
|
|
|
}
|
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::LeftLabel("IF Mode");
|
|
|
|
SmGui::FillWidth();
|
|
|
|
SmGui::ForceSync();
|
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_ifmode", _this->name), &_this->ifModeId, ifModeTxt)) {
|
2021-12-19 22:11:44 +01:00
|
|
|
if (_this->ifModeId != 0) {
|
2021-08-30 15:53:41 +02:00
|
|
|
_this->bandwidth = ifModes[_this->ifModeId].bw;
|
|
|
|
_this->sampleRate = ifModes[_this->ifModeId].effectiveSamplerate;
|
2021-12-19 22:11:44 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-08-30 15:53:41 +02:00
|
|
|
config.acquire();
|
|
|
|
_this->sampleRate = config.conf["devices"][_this->selectedName]["sampleRate"];
|
|
|
|
_this->bandwidthId = config.conf["devices"][_this->selectedName]["bwMode"];
|
|
|
|
config.release(false);
|
|
|
|
_this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId];
|
2021-12-19 22:11:44 +01:00
|
|
|
}
|
2021-08-30 15:53:41 +02:00
|
|
|
core::setInputSampleRate(_this->sampleRate);
|
|
|
|
config.acquire();
|
|
|
|
config.conf["devices"][_this->selectedName]["ifModeId"] = _this->ifModeId;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2021-02-26 16:52:54 +01:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
if (_this->running) { SmGui::EndDisabled(); }
|
2021-08-30 00:28:51 +03:00
|
|
|
|
2021-04-28 15:34:24 +02:00
|
|
|
if (_this->selectedName != "") {
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::LeftLabel("LNA Gain");
|
|
|
|
SmGui::FillWidth();
|
|
|
|
if (SmGui::SliderInt(CONCAT("##sdrplay_lna_gain", _this->name), &_this->lnaGain, _this->lnaSteps - 1, 0, SmGui::FMT_STR_NONE)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (_this->running) {
|
|
|
|
_this->channelParams->tunerParams.gain.LNAstate = _this->lnaGain;
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][_this->selectedName]["lnaGain"] = _this->lnaGain;
|
|
|
|
config.release(true);
|
2021-03-06 19:23:03 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
if (_this->agc > 0) { SmGui::BeginDisabled(); }
|
|
|
|
SmGui::LeftLabel("IF Gain");
|
|
|
|
SmGui::FillWidth();
|
|
|
|
if (SmGui::SliderInt(CONCAT("##sdrplay_gain", _this->name), &_this->gain, 59, 20, SmGui::FMT_STR_NONE)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (_this->running) {
|
|
|
|
_this->channelParams->tunerParams.gain.gRdB = _this->gain;
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][_this->selectedName]["ifGain"] = _this->gain;
|
|
|
|
config.release(true);
|
2021-03-06 19:23:03 +01:00
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (_this->agc > 0) { SmGui::EndDisabled(); }
|
2021-03-09 02:21:30 +01:00
|
|
|
|
2021-11-23 17:05:40 +01:00
|
|
|
|
|
|
|
if (_this->agcParamEdit) {
|
|
|
|
bool valid = false;
|
|
|
|
_this->agcParamEdit = _this->agcParamMenu(valid);
|
|
|
|
|
|
|
|
// If the menu was closed and (TODO) valid, update options
|
|
|
|
if (!_this->agcParamEdit && valid) {
|
|
|
|
_this->agcAttack = _this->_agcAttack;
|
|
|
|
_this->agcDecay = _this->_agcDecay;
|
|
|
|
_this->agcDecayDelay = _this->_agcDecayDelay;
|
|
|
|
_this->agcDecayThreshold = _this->_agcDecayThreshold;
|
|
|
|
_this->agcSetPoint = _this->_agcSetPoint;
|
|
|
|
if (_this->running && _this->agc) {
|
|
|
|
_this->channelParams->ctrlParams.agc.attack_ms = _this->agcAttack;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_ms = _this->agcDecay;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_delay_ms = _this->agcDecayDelay;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_threshold_dB = _this->agcDecayThreshold;
|
|
|
|
_this->channelParams->ctrlParams.agc.setPoint_dBfs = _this->agcSetPoint;
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
|
|
|
config.acquire();
|
|
|
|
config.conf["devices"][_this->selectedName]["agcAttack"] = _this->agcAttack;
|
|
|
|
config.conf["devices"][_this->selectedName]["agcDecay"] = _this->agcDecay;
|
|
|
|
config.conf["devices"][_this->selectedName]["agcDecayDelay"] = _this->agcDecayDelay;
|
|
|
|
config.conf["devices"][_this->selectedName]["agcDecayThreshold"] = _this->agcDecayThreshold;
|
|
|
|
config.conf["devices"][_this->selectedName]["agcSetPoint"] = _this->agcSetPoint;
|
|
|
|
config.release(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::ForceSync();
|
|
|
|
if (SmGui::Checkbox(CONCAT("IF AGC##sdrplay_agc", _this->name), &_this->agc)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (_this->running) {
|
2021-11-23 17:05:40 +01:00
|
|
|
_this->channelParams->ctrlParams.agc.enable = _this->agc ? sdrplay_api_AGC_CTRL_EN : sdrplay_api_AGC_DISABLE;
|
|
|
|
if (_this->agc) {
|
|
|
|
_this->channelParams->ctrlParams.agc.attack_ms = _this->agcAttack;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_ms = _this->agcDecay;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_delay_ms = _this->agcDecayDelay;
|
|
|
|
_this->channelParams->ctrlParams.agc.decay_threshold_dB = _this->agcDecayThreshold;
|
|
|
|
_this->channelParams->ctrlParams.agc.setPoint_dBfs = _this->agcSetPoint;
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None);
|
2021-04-30 15:16:07 +02:00
|
|
|
_this->channelParams->tunerParams.gain.gRdB = _this->gain;
|
|
|
|
sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-03-09 02:21:30 +01:00
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][_this->selectedName]["agc"] = _this->agc;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::SameLine();
|
|
|
|
SmGui::FillWidth();
|
|
|
|
SmGui::ForceSync();
|
|
|
|
if (SmGui::Button(CONCAT("Parameters##sdrplay_agc_edit_btn", _this->name))) {
|
2021-11-23 17:05:40 +01:00
|
|
|
_this->agcParamEdit = true;
|
|
|
|
_this->_agcAttack = _this->agcAttack;
|
|
|
|
_this->_agcDecay = _this->agcDecay;
|
|
|
|
_this->_agcDecayDelay = _this->agcDecayDelay;
|
|
|
|
_this->_agcDecayThreshold = _this->agcDecayThreshold;
|
|
|
|
_this->_agcSetPoint = _this->agcSetPoint;
|
|
|
|
}
|
2021-03-06 19:23:03 +01:00
|
|
|
|
2021-02-14 22:23:30 +01:00
|
|
|
switch (_this->openDev.hwVer) {
|
2021-12-19 22:11:44 +01:00
|
|
|
case SDRPLAY_RSP1_ID:
|
2022-01-21 20:22:13 +01:00
|
|
|
_this->RSP1Menu();
|
2021-12-19 22:11:44 +01:00
|
|
|
break;
|
|
|
|
case SDRPLAY_RSP1A_ID:
|
2022-01-21 20:22:13 +01:00
|
|
|
_this->RSP1AMenu();
|
2021-12-19 22:11:44 +01:00
|
|
|
break;
|
|
|
|
case SDRPLAY_RSP2_ID:
|
2022-01-21 20:22:13 +01:00
|
|
|
_this->RSP2Menu();
|
2021-12-19 22:11:44 +01:00
|
|
|
break;
|
|
|
|
case SDRPLAY_RSPduo_ID:
|
2022-01-21 20:22:13 +01:00
|
|
|
_this->RSPduoMenu();
|
2021-12-19 22:11:44 +01:00
|
|
|
break;
|
|
|
|
case SDRPLAY_RSPdx_ID:
|
2022-01-21 20:22:13 +01:00
|
|
|
_this->RSPdxMenu();
|
2021-12-19 22:11:44 +01:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-21 20:22:13 +01:00
|
|
|
_this->RSPUnsupportedMenu();
|
2021-12-19 22:11:44 +01:00
|
|
|
break;
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "No device available");
|
2021-12-19 22:11:44 +01:00
|
|
|
}
|
2021-02-10 21:35:56 +01:00
|
|
|
}
|
2021-11-23 17:05:40 +01:00
|
|
|
|
|
|
|
bool agcParamMenu(bool& valid) {
|
|
|
|
bool open = true;
|
|
|
|
gui::mainWindow.lockWaterfallControls = true;
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::OpenPopup("Edit##sdrplay_source_edit_agc_params_");
|
|
|
|
if (SmGui::BeginPopup("Edit##sdrplay_source_edit_agc_params_", ImGuiWindowFlags_NoResize)) {
|
|
|
|
if (SmGui::BeginTable(("sdrplay_source_agc_param_tbl" + name).c_str(), 2)) {
|
|
|
|
SmGui::TableNextRow();
|
|
|
|
SmGui::TableSetColumnIndex(0);
|
|
|
|
SmGui::LeftLabel("Attack");
|
|
|
|
SmGui::TableSetColumnIndex(1);
|
|
|
|
SmGui::SetNextItemWidth(100);
|
|
|
|
SmGui::InputInt("ms##sdrplay_source_agc_attack", &_agcAttack);
|
|
|
|
_agcAttack = std::clamp<int>(_agcAttack, 0, 65535);
|
|
|
|
|
|
|
|
SmGui::TableNextRow();
|
|
|
|
SmGui::TableSetColumnIndex(0);
|
|
|
|
SmGui::LeftLabel("Decay");
|
|
|
|
SmGui::TableSetColumnIndex(1);
|
|
|
|
SmGui::SetNextItemWidth(100);
|
|
|
|
SmGui::InputInt("ms##sdrplay_source_agc_decay", &_agcDecay);
|
|
|
|
_agcDecay = std::clamp<int>(_agcDecay, 0, 65535);
|
|
|
|
|
|
|
|
SmGui::TableNextRow();
|
|
|
|
SmGui::TableSetColumnIndex(0);
|
|
|
|
SmGui::LeftLabel("Decay Delay");
|
|
|
|
SmGui::TableSetColumnIndex(1);
|
|
|
|
SmGui::SetNextItemWidth(100);
|
|
|
|
SmGui::InputInt("ms##sdrplay_source_agc_decay_delay", &_agcDecayDelay);
|
|
|
|
_agcDecayDelay = std::clamp<int>(_agcDecayDelay, 0, 65535);
|
|
|
|
|
|
|
|
SmGui::TableNextRow();
|
|
|
|
SmGui::TableSetColumnIndex(0);
|
|
|
|
SmGui::LeftLabel("Decay Threshold");
|
|
|
|
SmGui::TableSetColumnIndex(1);
|
|
|
|
SmGui::SetNextItemWidth(100);
|
|
|
|
SmGui::InputInt("dB##sdrplay_source_agc_decay_thresh", &_agcDecayThreshold);
|
|
|
|
_agcDecayThreshold = std::clamp<int>(_agcDecayThreshold, 0, 100);
|
|
|
|
|
|
|
|
SmGui::TableNextRow();
|
|
|
|
SmGui::TableSetColumnIndex(0);
|
|
|
|
SmGui::LeftLabel("Setpoint");
|
|
|
|
SmGui::TableSetColumnIndex(1);
|
|
|
|
SmGui::SetNextItemWidth(100);
|
|
|
|
SmGui::InputInt("dBFS##sdrplay_source_agc_setpoint", &_agcSetPoint);
|
|
|
|
_agcSetPoint = std::clamp<int>(_agcSetPoint, -60, -20);
|
|
|
|
|
|
|
|
SmGui::EndTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
SmGui::ForceSync();
|
2022-01-29 16:20:45 +01:00
|
|
|
if (SmGui::Button("Apply", ImVec2(100, 0))) {
|
2021-11-23 17:05:40 +01:00
|
|
|
open = false;
|
|
|
|
valid = true;
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::SameLine();
|
|
|
|
SmGui::ForceSync();
|
2022-01-29 16:20:45 +01:00
|
|
|
if (SmGui::Button("Cancel", ImVec2(100, 0))) {
|
2021-11-23 17:05:40 +01:00
|
|
|
open = false;
|
|
|
|
valid = false;
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
SmGui::EndPopup();
|
2021-11-23 17:05:40 +01:00
|
|
|
}
|
|
|
|
return open;
|
|
|
|
}
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
void RSP1Menu() {
|
2021-03-07 20:10:10 +01:00
|
|
|
// No options?
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
void RSP1AMenu() {
|
|
|
|
if (SmGui::Checkbox(CONCAT("FM Notch##sdrplay_rsp1a_fmnotch", name), &rsp1a_fmNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
openDevParams->devParams->rsp1aParams.rfNotchEnable = rsp1a_fmNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp1a_RfNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["fmNotch"] = rsp1a_fmNotch;
|
|
|
|
config.release(true);
|
2021-02-26 16:52:54 +01:00
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("DAB Notch##sdrplay_rsp1a_dabnotch", name), &rsp1a_dabNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
openDevParams->devParams->rsp1aParams.rfNotchEnable = rsp1a_dabNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp1a_RfDabNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["dabNotch"] = rsp1a_dabNotch;
|
|
|
|
config.release(true);
|
2021-02-26 16:52:54 +01:00
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("Bias-T##sdrplay_rsp1a_biast", name), &rsp1a_biasT)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rsp1aTunerParams.biasTEnable = rsp1a_biasT;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp1a_BiasTControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["biast"] = rsp1a_biasT;
|
|
|
|
config.release(true);
|
2021-02-26 21:33:48 +01:00
|
|
|
}
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
void RSP2Menu() {
|
|
|
|
SmGui::LeftLabel("Antenna");
|
|
|
|
SmGui::FillWidth();
|
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_rsp2_ant", name), &rsp2_antennaPort, rsp2_antennaPortsTxt)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rsp2TunerParams.antennaSel = rsp2_antennaPorts[rsp2_antennaPort];
|
|
|
|
channelParams->rsp2TunerParams.amPortSel = (rsp2_antennaPort == 2) ? sdrplay_api_Rsp2_AMPORT_1 : sdrplay_api_Rsp2_AMPORT_2;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_AntennaControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_AmPortSelect, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["antenna"] = rsp2_antennaPort;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("MW/FM Notch##sdrplay_rsp2_notch", name), &rsp2_notch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rsp2TunerParams.rfNotchEnable = rsp2_notch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_RfNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["notch"] = rsp2_notch;
|
|
|
|
config.release(true);
|
2021-03-06 22:56:35 +01:00
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("Bias-T##sdrplay_rsp2_biast", name), &rsp2_biasT)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rsp2TunerParams.biasTEnable = rsp2_biasT;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_BiasTControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["biast"] = rsp2_biasT;
|
|
|
|
config.release(true);
|
2021-03-06 22:56:35 +01:00
|
|
|
}
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
void RSPduoMenu() {
|
|
|
|
SmGui::LeftLabel("Antenna");
|
|
|
|
SmGui::FillWidth();
|
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_rspduo_ant", name), &rspduo_antennaPort, rspduo_antennaPortsTxt)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
rspDuoSelectAntennaPort(rspduo_antennaPort);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["antenna"] = rspduo_antennaPort;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("FM Notch##sdrplay_rspduo_notch", name), &rspduo_fmNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rspDuoTunerParams.rfNotchEnable = rspduo_fmNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_RfNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["fmNotch"] = rspduo_fmNotch;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("DAB Notch##sdrplay_rspduo_dabnotch", name), &rspduo_dabNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rspDuoTunerParams.rfDabNotchEnable = rspduo_dabNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_RfDabNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["dabNotch"] = rspduo_dabNotch;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("AM Notch##sdrplay_rspduo_dabnotch", name), &rspduo_amNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rspDuoTunerParams.tuner1AmNotchEnable = rspduo_amNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_Tuner1AmNotchControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["amNotch"] = rspduo_amNotch;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("Bias-T##sdrplay_rspduo_biast", name), &rspduo_biasT)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
channelParams->rspDuoTunerParams.biasTEnable = rspduo_biasT;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_BiasTControl, sdrplay_api_Update_Ext1_None);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-04-12 23:02:45 +02:00
|
|
|
config.conf["devices"][selectedName]["biast"] = rspduo_biasT;
|
|
|
|
config.release(true);
|
|
|
|
}
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
void RSPdxMenu() {
|
|
|
|
SmGui::LeftLabel("Antenna");
|
|
|
|
SmGui::FillWidth();
|
|
|
|
if (SmGui::Combo(CONCAT("##sdrplay_rspdx_ant", name), &rspdx_antennaPort, rspdx_antennaPortsTxt)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
openDevParams->devParams->rspDxParams.antennaSel = rspdx_antennaPorts[rspdx_antennaPort];
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_AntennaControl);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["antenna"] = rspdx_antennaPort;
|
|
|
|
config.release(true);
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("FM Notch##sdrplay_rspdx_fmnotch", name), &rspdx_fmNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
openDevParams->devParams->rspDxParams.rfNotchEnable = rspdx_fmNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_RfNotchControl);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["fmNotch"] = rspdx_fmNotch;
|
|
|
|
config.release(true);
|
2021-03-06 22:56:35 +01:00
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("DAB Notch##sdrplay_rspdx_dabnotch", name), &rspdx_dabNotch)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
openDevParams->devParams->rspDxParams.rfDabNotchEnable = rspdx_dabNotch;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_RfDabNotchControl);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["dabNotch"] = rspdx_dabNotch;
|
|
|
|
config.release(true);
|
2021-03-06 22:56:35 +01:00
|
|
|
}
|
2022-01-21 20:22:13 +01:00
|
|
|
if (SmGui::Checkbox(CONCAT("Bias-T##sdrplay_rspdx_biast", name), &rspdx_biasT)) {
|
2021-04-30 15:16:07 +02:00
|
|
|
if (running) {
|
|
|
|
openDevParams->devParams->rspDxParams.biasTEnable = rspdx_biasT;
|
|
|
|
sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_None, sdrplay_api_Update_RspDx_BiasTControl);
|
|
|
|
}
|
2021-07-09 14:24:07 -04:00
|
|
|
config.acquire();
|
2021-03-09 02:21:30 +01:00
|
|
|
config.conf["devices"][selectedName]["biast"] = rspdx_biasT;
|
|
|
|
config.release(true);
|
2021-03-06 22:56:35 +01:00
|
|
|
}
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:22:13 +01:00
|
|
|
void RSPUnsupportedMenu() {
|
|
|
|
SmGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Device currently unsupported");
|
2021-02-14 22:23:30 +01:00
|
|
|
}
|
2021-02-10 21:35:56 +01:00
|
|
|
|
2021-12-19 22:11:44 +01:00
|
|
|
static void streamCB(short* xi, short* xq, sdrplay_api_StreamCbParamsT* params,
|
|
|
|
unsigned int numSamples, unsigned int reset, void* cbContext) {
|
2021-02-12 22:44:29 +01:00
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)cbContext;
|
2021-06-30 02:48:36 +02:00
|
|
|
// TODO: Optimise using volk and math
|
2021-02-12 22:44:29 +01:00
|
|
|
if (!_this->running) { return; }
|
|
|
|
for (int i = 0; i < numSamples; i++) {
|
2021-02-20 15:27:43 +01:00
|
|
|
int id = _this->bufferIndex++;
|
2021-03-29 21:53:43 +02:00
|
|
|
_this->stream.writeBuf[id].re = (float)xi[i] / 32768.0f;
|
|
|
|
_this->stream.writeBuf[id].im = (float)xq[i] / 32768.0f;
|
2021-02-20 15:27:43 +01:00
|
|
|
|
|
|
|
if (_this->bufferIndex >= _this->bufferSize) {
|
|
|
|
_this->stream.swap(_this->bufferSize);
|
|
|
|
_this->bufferIndex = 0;
|
|
|
|
}
|
2021-02-12 22:44:29 +01:00
|
|
|
}
|
2021-02-11 22:53:00 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:44:29 +01:00
|
|
|
static void eventCB(sdrplay_api_EventT eventId, sdrplay_api_TunerSelectT tuner,
|
2021-12-19 22:11:44 +01:00
|
|
|
sdrplay_api_EventParamsT* params, void* cbContext) {
|
2021-02-12 22:44:29 +01:00
|
|
|
SDRPlaySourceModule* _this = (SDRPlaySourceModule*)cbContext;
|
2021-02-11 22:53:00 +01:00
|
|
|
}
|
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
std::string name;
|
|
|
|
bool enabled = true;
|
|
|
|
dsp::stream<dsp::complex_t> stream;
|
|
|
|
double sampleRate;
|
|
|
|
SourceManager::SourceHandler handler;
|
|
|
|
bool running = false;
|
|
|
|
double freq;
|
2021-07-29 20:22:16 +02:00
|
|
|
bool initOk = false;
|
2021-02-10 21:35:56 +01:00
|
|
|
|
2021-02-12 22:44:29 +01:00
|
|
|
sdrplay_api_CallbackFnsT cbFuncs;
|
2021-02-11 22:53:00 +01:00
|
|
|
|
2021-02-11 15:29:51 +01:00
|
|
|
sdrplay_api_DeviceT openDev;
|
2021-12-19 22:11:44 +01:00
|
|
|
sdrplay_api_DeviceParamsT* openDevParams;
|
2021-04-20 22:53:23 +02:00
|
|
|
sdrplay_api_RxChannelParamsT* channelParams;
|
2021-02-11 15:29:51 +01:00
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
sdrplay_api_Bw_MHzT bandwidth;
|
|
|
|
int bandwidthId = 0;
|
|
|
|
|
2021-02-10 21:35:56 +01:00
|
|
|
int devId = 0;
|
|
|
|
int srId = 0;
|
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
int lnaGain = 9;
|
|
|
|
int gain = 59;
|
2021-03-07 00:57:08 +01:00
|
|
|
int lnaSteps = 9;
|
2021-12-19 22:11:44 +01:00
|
|
|
|
2021-11-23 17:05:40 +01:00
|
|
|
bool agc = false;
|
|
|
|
bool agcParamEdit = false;
|
|
|
|
int agcAttack = 500;
|
|
|
|
int agcDecay = 500;
|
|
|
|
int agcDecayDelay = 200;
|
|
|
|
int agcDecayThreshold = 5;
|
|
|
|
int agcSetPoint = -30;
|
|
|
|
|
|
|
|
// Temporary values for the edit window
|
|
|
|
int _agcAttack = 500;
|
|
|
|
int _agcDecay = 500;
|
|
|
|
int _agcDecayDelay = 200;
|
|
|
|
int _agcDecayThreshold = 5;
|
|
|
|
int _agcSetPoint = -30;
|
2021-02-20 15:27:43 +01:00
|
|
|
|
|
|
|
int bufferSize = 0;
|
|
|
|
int bufferIndex = 0;
|
2021-02-15 14:55:48 +01:00
|
|
|
|
2021-08-30 00:28:51 +03:00
|
|
|
int ifModeId = 0;
|
|
|
|
|
2021-02-26 16:52:54 +01:00
|
|
|
// RSP1A Options
|
2021-03-06 22:56:35 +01:00
|
|
|
bool rsp1a_fmNotch = false;
|
|
|
|
bool rsp1a_dabNotch = false;
|
|
|
|
bool rsp1a_biasT = false;
|
|
|
|
|
|
|
|
// RSP2 Options
|
|
|
|
bool rsp2_notch = false;
|
|
|
|
bool rsp2_biasT = false;
|
|
|
|
int rsp2_antennaPort = 0;
|
|
|
|
|
2021-03-07 20:10:10 +01:00
|
|
|
// RSP Duo Options
|
2021-04-10 03:06:51 +02:00
|
|
|
bool rspduo_fmNotch = false;
|
|
|
|
bool rspduo_dabNotch = false;
|
|
|
|
bool rspduo_biasT = false;
|
2021-04-12 23:02:45 +02:00
|
|
|
bool rspduo_amNotch = false;
|
|
|
|
int rspduo_antennaPort = 0;
|
2021-03-07 20:10:10 +01:00
|
|
|
|
2021-03-06 22:56:35 +01:00
|
|
|
// RSPdx Options
|
|
|
|
bool rspdx_fmNotch = false;
|
|
|
|
bool rspdx_dabNotch = false;
|
|
|
|
bool rspdx_biasT = false;
|
|
|
|
int rspdx_antennaPort = 0;
|
2021-02-26 16:52:54 +01:00
|
|
|
|
2021-02-11 22:53:00 +01:00
|
|
|
std::vector<sdrplay_api_DeviceT> devList;
|
2021-02-10 21:35:56 +01:00
|
|
|
std::string devListTxt;
|
2021-03-09 02:21:30 +01:00
|
|
|
std::vector<std::string> devNameList;
|
|
|
|
std::string selectedName;
|
2021-02-10 21:35:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
MOD_EXPORT void _INIT_() {
|
|
|
|
json def = json({});
|
|
|
|
def["devices"] = json({});
|
|
|
|
def["device"] = "";
|
|
|
|
config.setPath(options::opts.root + "/sdrplay_config.json");
|
|
|
|
config.load(def);
|
|
|
|
config.enableAutoSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {
|
|
|
|
return new SDRPlaySourceModule(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* instance) {
|
|
|
|
delete (SDRPlaySourceModule*)instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_EXPORT void _END_() {
|
|
|
|
config.disableAutoSave();
|
|
|
|
config.save();
|
2021-08-30 15:50:47 +02:00
|
|
|
}
|