Fix device init and switching

This commit is contained in:
Charles J. Cliffe 2015-09-20 21:48:37 -04:00
parent d551d5f2c4
commit 6eb2636499
3 changed files with 31 additions and 24 deletions

View File

@ -153,11 +153,11 @@ void SDRDeviceInfo::setTimestamps(bool timestamps) {
this->timestamps = timestamps;
}
void SDRDeviceInfo::setDeviceArgs(std::string deviceArgs) {
void SDRDeviceInfo::setDeviceArgs(SoapySDR::Kwargs deviceArgs) {
this->deviceArgs = deviceArgs;
}
std::string SDRDeviceInfo::getDeviceArgs() {
SoapySDR::Kwargs SDRDeviceInfo::getDeviceArgs() {
return deviceArgs;
// return "driver=" + driver + "," + getDriver() + "=" + std::to_string(getIndex());
}

View File

@ -3,6 +3,8 @@
#include <string>
#include <vector>
#include <SoapySDR/Types.hpp>
/*
----------------------------------------------------
-- Device identification
@ -111,14 +113,14 @@ public:
const std::vector<SDRDeviceChannel>& getChannels() const;
void setDeviceArgs(std::string deviceArgs);
std::string getDeviceArgs();
void setDeviceArgs(SoapySDR::Kwargs deviceArgs);
SoapySDR::Kwargs getDeviceArgs();
private:
int index;
std::string name, serial, product, manufacturer, tuner;
std::string driver, hardware;
bool timestamps, available;
std::string deviceArgs;
SoapySDR::Kwargs deviceArgs;
std::vector<SDRDeviceChannel> channels;
};

View File

@ -74,7 +74,6 @@ std::vector<SDRDeviceInfo *> *SDRThread::enumerate_devices() {
for (size_t i = 0; i < results.size(); i++) {
std::cout << "Found device " << i << std::endl;
SDRDeviceInfo *dev = new SDRDeviceInfo();
std::string devArgs("");
for (SoapySDR::Kwargs::const_iterator it = results[i].begin(); it != results[i].end(); ++it) {
std::cout << " " << it->first << " = " << it->second << std::endl;
if (it->first == "driver") {
@ -82,19 +81,13 @@ std::vector<SDRDeviceInfo *> *SDRThread::enumerate_devices() {
} else if (it->first == "label") {
dev->setName(it->second);
}
if (devArgs.size()) {
devArgs.append(",");
}
devArgs.append(it->first);
devArgs.append("=");
devArgs.append(it->second);
}
dev->setDeviceArgs(devArgs);
dev->setDeviceArgs(results[i]);
dev->setIndex(deviceIndexes[dev->getDriver()]);
deviceIndexes[dev->getDriver()]++;
std::cout << "Make device " << dev->getDeviceArgs() << std::endl;
std::cout << "Make device " << i << std::endl;
try {
SoapySDR::Device *device = SoapySDR::Device::make(dev->getDeviceArgs());
SoapySDR::Kwargs info = device->getHardwareInfo();
@ -123,12 +116,12 @@ std::vector<SDRDeviceInfo *> *SDRThread::enumerate_devices() {
}
void SDRThread::run() {
//#ifdef __APPLE__
// pthread_t tID = pthread_self(); // ID of this thread
// int priority = sched_get_priority_max( SCHED_FIFO) - 1;
// sched_param prio = { priority }; // scheduling priority of thread
// pthread_setschedparam(tID, SCHED_FIFO, &prio);
//#endif
#ifdef __APPLE__
pthread_t tID = pthread_self(); // ID of this thread
int priority = sched_get_priority_max( SCHED_FIFO) - 1;
sched_param prio = { priority }; // scheduling priority of thread
pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif
std::cout << "SDR thread initializing.." << std::endl;
@ -153,8 +146,11 @@ void SDRThread::run() {
SDRDeviceInfo *dev = devs[deviceId];
SoapySDR::Device *device = SoapySDR::Device::make(dev->getDeviceArgs()+",direct_samp="+std::to_string(devConfig->getDirectSampling())+",buffers=6,buflen=16384");
SoapySDR::Kwargs args = dev->getDeviceArgs();
args["direct_samp"] = std::to_string(devConfig->getDirectSampling());
args["buffers"] = "8";
args["buflen"] = "16384";
SoapySDR::Device *device = SoapySDR::Device::make(args);
device->setSampleRate(SOAPY_SDR_RX,0,sampleRate.load());
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load());
@ -236,7 +232,16 @@ void SDRThread::run() {
device->closeStream(stream);
SoapySDR::Device::unmake(device);
device = SoapySDR::Device::make(dev->getDeviceArgs()+",direct_samp="+std::to_string(devConfig->getDirectSampling())+",buffers=6,buflen=16384");
deviceId = new_device;
dev = devs[deviceId];
device_changed = false;
SoapySDR::Kwargs args = dev->getDeviceArgs();
args["direct_samp"] = std::to_string(devConfig->getDirectSampling());
args["buffers"] = "8";
args["buflen"] = "16384";
device = SoapySDR::Device::make(args);
device->setSampleRate(SOAPY_SDR_RX,0,sampleRate.load());
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load());