mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-15 16:41:54 -05:00
Fix device init and switching
This commit is contained in:
parent
d551d5f2c4
commit
6eb2636499
@ -153,11 +153,11 @@ void SDRDeviceInfo::setTimestamps(bool timestamps) {
|
|||||||
this->timestamps = timestamps;
|
this->timestamps = timestamps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRDeviceInfo::setDeviceArgs(std::string deviceArgs) {
|
void SDRDeviceInfo::setDeviceArgs(SoapySDR::Kwargs deviceArgs) {
|
||||||
this->deviceArgs = deviceArgs;
|
this->deviceArgs = deviceArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SDRDeviceInfo::getDeviceArgs() {
|
SoapySDR::Kwargs SDRDeviceInfo::getDeviceArgs() {
|
||||||
return deviceArgs;
|
return deviceArgs;
|
||||||
// return "driver=" + driver + "," + getDriver() + "=" + std::to_string(getIndex());
|
// return "driver=" + driver + "," + getDriver() + "=" + std::to_string(getIndex());
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <SoapySDR/Types.hpp>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
-- Device identification
|
-- Device identification
|
||||||
@ -111,14 +113,14 @@ public:
|
|||||||
|
|
||||||
const std::vector<SDRDeviceChannel>& getChannels() const;
|
const std::vector<SDRDeviceChannel>& getChannels() const;
|
||||||
|
|
||||||
void setDeviceArgs(std::string deviceArgs);
|
void setDeviceArgs(SoapySDR::Kwargs deviceArgs);
|
||||||
std::string getDeviceArgs();
|
SoapySDR::Kwargs getDeviceArgs();
|
||||||
private:
|
private:
|
||||||
int index;
|
int index;
|
||||||
std::string name, serial, product, manufacturer, tuner;
|
std::string name, serial, product, manufacturer, tuner;
|
||||||
std::string driver, hardware;
|
std::string driver, hardware;
|
||||||
bool timestamps, available;
|
bool timestamps, available;
|
||||||
|
|
||||||
std::string deviceArgs;
|
SoapySDR::Kwargs deviceArgs;
|
||||||
std::vector<SDRDeviceChannel> channels;
|
std::vector<SDRDeviceChannel> channels;
|
||||||
};
|
};
|
||||||
|
@ -74,7 +74,6 @@ std::vector<SDRDeviceInfo *> *SDRThread::enumerate_devices() {
|
|||||||
for (size_t i = 0; i < results.size(); i++) {
|
for (size_t i = 0; i < results.size(); i++) {
|
||||||
std::cout << "Found device " << i << std::endl;
|
std::cout << "Found device " << i << std::endl;
|
||||||
SDRDeviceInfo *dev = new SDRDeviceInfo();
|
SDRDeviceInfo *dev = new SDRDeviceInfo();
|
||||||
std::string devArgs("");
|
|
||||||
for (SoapySDR::Kwargs::const_iterator it = results[i].begin(); it != results[i].end(); ++it) {
|
for (SoapySDR::Kwargs::const_iterator it = results[i].begin(); it != results[i].end(); ++it) {
|
||||||
std::cout << " " << it->first << " = " << it->second << std::endl;
|
std::cout << " " << it->first << " = " << it->second << std::endl;
|
||||||
if (it->first == "driver") {
|
if (it->first == "driver") {
|
||||||
@ -82,19 +81,13 @@ std::vector<SDRDeviceInfo *> *SDRThread::enumerate_devices() {
|
|||||||
} else if (it->first == "label") {
|
} else if (it->first == "label") {
|
||||||
dev->setName(it->second);
|
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()]);
|
dev->setIndex(deviceIndexes[dev->getDriver()]);
|
||||||
deviceIndexes[dev->getDriver()]++;
|
deviceIndexes[dev->getDriver()]++;
|
||||||
|
|
||||||
std::cout << "Make device " << dev->getDeviceArgs() << std::endl;
|
std::cout << "Make device " << i << std::endl;
|
||||||
try {
|
try {
|
||||||
SoapySDR::Device *device = SoapySDR::Device::make(dev->getDeviceArgs());
|
SoapySDR::Device *device = SoapySDR::Device::make(dev->getDeviceArgs());
|
||||||
SoapySDR::Kwargs info = device->getHardwareInfo();
|
SoapySDR::Kwargs info = device->getHardwareInfo();
|
||||||
@ -123,12 +116,12 @@ std::vector<SDRDeviceInfo *> *SDRThread::enumerate_devices() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SDRThread::run() {
|
void SDRThread::run() {
|
||||||
//#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// pthread_t tID = pthread_self(); // ID of this thread
|
pthread_t tID = pthread_self(); // ID of this thread
|
||||||
// int priority = sched_get_priority_max( SCHED_FIFO) - 1;
|
int priority = sched_get_priority_max( SCHED_FIFO) - 1;
|
||||||
// sched_param prio = { priority }; // scheduling priority of thread
|
sched_param prio = { priority }; // scheduling priority of thread
|
||||||
// pthread_setschedparam(tID, SCHED_FIFO, &prio);
|
pthread_setschedparam(tID, SCHED_FIFO, &prio);
|
||||||
//#endif
|
#endif
|
||||||
|
|
||||||
std::cout << "SDR thread initializing.." << std::endl;
|
std::cout << "SDR thread initializing.." << std::endl;
|
||||||
|
|
||||||
@ -153,13 +146,16 @@ void SDRThread::run() {
|
|||||||
|
|
||||||
|
|
||||||
SDRDeviceInfo *dev = devs[deviceId];
|
SDRDeviceInfo *dev = devs[deviceId];
|
||||||
|
SoapySDR::Kwargs args = dev->getDeviceArgs();
|
||||||
SoapySDR::Device *device = SoapySDR::Device::make(dev->getDeviceArgs()+",direct_samp="+std::to_string(devConfig->getDirectSampling())+",buffers=6,buflen=16384");
|
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->setSampleRate(SOAPY_SDR_RX,0,sampleRate.load());
|
||||||
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load());
|
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load());
|
||||||
device->setFrequency(SOAPY_SDR_RX,0,"CORR",ppm);
|
device->setFrequency(SOAPY_SDR_RX,0,"CORR",ppm);
|
||||||
device->setGainMode(SOAPY_SDR_RX,0, true);
|
device->setGainMode(SOAPY_SDR_RX,0,true);
|
||||||
|
|
||||||
SoapySDR::Stream *stream = device->setupStream(SOAPY_SDR_RX,"CF32");
|
SoapySDR::Stream *stream = device->setupStream(SOAPY_SDR_RX,"CF32");
|
||||||
device->activateStream(stream);
|
device->activateStream(stream);
|
||||||
@ -236,7 +232,16 @@ void SDRThread::run() {
|
|||||||
device->closeStream(stream);
|
device->closeStream(stream);
|
||||||
SoapySDR::Device::unmake(device);
|
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->setSampleRate(SOAPY_SDR_RX,0,sampleRate.load());
|
||||||
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load());
|
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load());
|
||||||
|
Loading…
Reference in New Issue
Block a user