Manual/Remote SoapySDR device specification

This commit is contained in:
Charles J. Cliffe
2016-01-20 00:43:31 -05:00
parent b7d4687b8e
commit b1ac17729e
14 changed files with 1110 additions and 51 deletions
+17 -1
View File
@@ -160,7 +160,7 @@ std::vector<std::string> SDRDeviceChannel::getStreamArgNames() {
}
SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false) {
SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false) {
}
@@ -262,6 +262,22 @@ void SDRDeviceInfo::setRemote(bool remote) {
this->remote = remote;
}
bool SDRDeviceInfo::isManual() const {
return manual;
}
void SDRDeviceInfo::setManual(bool manual) {
this->manual = manual;
}
void SDRDeviceInfo::setManualParams(std::string manualParams) {
this->manual_params = manualParams;
}
std::string SDRDeviceInfo::getManualParams() {
return manual_params;
}
void SDRDeviceInfo::setDeviceArgs(SoapySDR::Kwargs deviceArgs) {
this->deviceArgs = deviceArgs;
}
+8 -2
View File
@@ -139,7 +139,13 @@ public:
bool isRemote() const;
void setRemote(bool remote);
bool isManual() const;
void setManual(bool manual);
void setManualParams(std::string manualParams);
std::string getManualParams();
void addChannel(SDRDeviceChannel *chan);
std::vector<SDRDeviceChannel *> &getChannels();
SDRDeviceChannel * getRxChannel();
@@ -159,8 +165,8 @@ public:
private:
int index;
std::string name, serial, product, manufacturer, tuner;
std::string driver, hardware;
bool timestamps, available, remote;
std::string driver, hardware, manual_params;
bool timestamps, available, remote, manual;
SoapySDR::Kwargs deviceArgs, streamArgs;
SoapySDR::ArgInfoList settingInfo;
+95 -10
View File
@@ -11,6 +11,7 @@ std::vector<std::string> SDREnumerator::remotes;
std::map< std::string, std::vector<SDRDeviceInfo *> > SDREnumerator::devs;
bool SDREnumerator::soapy_initialized = false;
bool SDREnumerator::has_remote = false;
std::vector<SDRManualDef> SDREnumerator::manuals;
SDREnumerator::SDREnumerator() : IOThread() {
@@ -20,6 +21,48 @@ SDREnumerator::~SDREnumerator() {
}
// Some utility from SoapySDR :)
static std::string trim(const std::string &s)
{
std::string out = s;
while (not out.empty() and std::isspace(out[0])) out = out.substr(1);
while (not out.empty() and std::isspace(out[out.size()-1])) out = out.substr(0, out.size()-1);
return out;
}
SoapySDR::Kwargs SDREnumerator::argsStrToKwargs(const std::string &args)
{
SoapySDR::Kwargs kwargs;
bool inKey = true;
std::string key, val;
for (size_t i = 0; i < args.size(); i++)
{
const char ch = args[i];
if (inKey)
{
if (ch == '=') inKey = false;
else if (ch == ',') inKey = true;
else key += ch;
}
else
{
if (ch == ',') inKey = true;
else val += ch;
}
if ((inKey and not val.empty()) or ((i+1) == args.size()))
{
key = trim(key);
val = trim(val);
if (not key.empty()) kwargs[key] = val;
key = "";
val = "";
}
}
return kwargs;
}
std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remoteAddr, bool noInit) {
@@ -77,14 +120,7 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
#endif
}
// modules = SoapySDR::listModules();
// for (size_t i = 0; i < modules.size(); i++) {
// std::cout << "\tModule found: " << modules[i] << std::endl;
// }
// if (modules.empty()) {
// std::cout << "No modules found!" << std::endl;
// }
if (SDREnumerator::factories.size()) {
SDREnumerator::factories.erase(SDREnumerator::factories.begin(), SDREnumerator::factories.end());
}
@@ -113,6 +149,8 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
soapy_initialized = true;
}
modules = SoapySDR::listModules();
std::vector<SoapySDR::Kwargs> results;
SoapySDR::Kwargs enumArgs;
bool isRemote = false;
@@ -128,6 +166,36 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
results = SoapySDR::Device::enumerate();
}
int manualsIdx = results.size();
std::vector<std::string> manualParams;
std::vector<bool> manualResult;
if (manuals.size()) {
for (std::vector<SDRManualDef>::const_iterator m_i = manuals.begin(); m_i != manuals.end(); m_i++) {
std::vector<SoapySDR::Kwargs> manual_result;
std::string strDevArgs = "driver="+m_i->factory+","+m_i->params;
manualParams.push_back(strDevArgs);
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, std::string("Enumerating manual device '") + strDevArgs + "'..");
manual_result = SoapySDR::Device::enumerate(strDevArgs);
if (manual_result.size()) {
for (std::vector<SoapySDR::Kwargs>::const_iterator i = manual_result.begin(); i != manual_result.end(); i++) {
results.push_back(*i);
manualResult.push_back(true);
}
} else {
SoapySDR::Kwargs failedEnum;
failedEnum = argsStrToKwargs(strDevArgs+",label=Not Found ("+m_i->factory+")");
results.push_back(failedEnum);
manualResult.push_back(false);
}
}
}
if (isRemote) {
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, std::string("Opening remote server ") + remoteAddr + "..");
}
@@ -145,7 +213,6 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
}
}
DeviceConfig *cfg = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
if (deviceArgs.count("remote")) {
isRemote = true;
@@ -154,9 +221,14 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
}
dev->setRemote(isRemote);
dev->setManual(i>=manualsIdx);
if (i>=manualsIdx) {
dev->setManualParams(manualParams[i-manualsIdx]);
}
std::cout << "Make device " << i << std::endl;
try {
if (i<manualsIdx || manualResult[i-manualsIdx]) try {
DeviceConfig *cfg = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
SoapySDR::Device *device = SoapySDR::Device::make(deviceArgs);
SoapySDR::Kwargs info = device->getHardwareInfo();
for (SoapySDR::Kwargs::const_iterator it = info.begin(); it != info.end(); ++it) {
@@ -253,6 +325,8 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
std::cerr << "Error making device: " << ex.what() << std::endl;
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, std::string("Error querying device #") + std::to_string(i));
dev->setAvailable(false);
} else {
dev->setAvailable(false);
}
std::cout << std::endl;
@@ -323,6 +397,13 @@ std::vector<std::string> &SDREnumerator::getRemotes() {
return remotes;
}
void SDREnumerator::addManual(std::string factory, std::string params) {
SDRManualDef def;
def.factory = factory;
def.params = params;
manuals.push_back(def);
}
bool SDREnumerator::hasRemoteModule() {
return SDREnumerator::has_remote;
}
@@ -333,3 +414,7 @@ void SDREnumerator::reset() {
modules.erase(modules.begin(), modules.end());
devs.erase(devs.begin(), devs.end());
}
std::vector<std::string> &SDREnumerator::getFactories() {
return SDREnumerator::factories;
}
+10
View File
@@ -12,6 +12,11 @@
#include <SoapySDR/Registry.hpp>
#include <SoapySDR/Device.hpp>
typedef struct _SDRManualDef {
std::string factory;
std::string params;
} SDRManualDef;
class SDREnumerator: public IOThread {
private:
@@ -25,11 +30,15 @@ public:
void run();
static SoapySDR::Kwargs argsStrToKwargs(const std::string &args);
static void addRemote(std::string remoteAddr);
static void removeRemote(std::string remoteAddr);
static std::vector<std::string> &getRemotes();
static bool hasRemoteModule();
static void addManual(std::string factory, std::string params);
// static void removeManual(std::string factory, std::string params);
static void reset();
static std::vector<std::string> &getFactories();
protected:
static bool soapy_initialized, has_remote;
@@ -37,4 +46,5 @@ protected:
static std::vector<std::string> modules;
static std::vector<std::string> remotes;
static std::map< std::string, std::vector<SDRDeviceInfo *> > devs;
static std::vector<SDRManualDef> manuals;
};