2015-07-29 22:19:00 -04:00
|
|
|
#include "SDRDeviceInfo.h"
|
2015-10-20 23:57:54 -04:00
|
|
|
#include <cstdlib>
|
2015-07-29 22:19:00 -04:00
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false), soapyDevice(nullptr) {
|
2015-10-23 02:53:51 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
SDRDeviceInfo::~SDRDeviceInfo() {
|
|
|
|
if (soapyDevice != nullptr) {
|
|
|
|
SoapySDR::Device::unmake(soapyDevice);
|
2015-10-23 02:53:51 -04:00
|
|
|
}
|
2015-07-29 22:19:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SDRDeviceInfo::getDeviceId() {
|
|
|
|
std::string deviceId;
|
|
|
|
|
|
|
|
deviceId.append(getName());
|
2015-09-13 22:18:29 -04:00
|
|
|
// deviceId.append(" :: ");
|
|
|
|
// deviceId.append(getSerial());
|
2015-07-29 22:19:00 -04:00
|
|
|
|
|
|
|
return deviceId;
|
|
|
|
}
|
|
|
|
|
2016-01-27 11:39:17 +11:00
|
|
|
int SDRDeviceInfo::getIndex() const {
|
2015-09-13 22:18:29 -04:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setIndex(const int index) {
|
|
|
|
this->index = index;
|
|
|
|
}
|
|
|
|
|
2015-07-29 22:19:00 -04:00
|
|
|
bool SDRDeviceInfo::isAvailable() const {
|
|
|
|
return available;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setAvailable(bool available) {
|
|
|
|
this->available = available;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& SDRDeviceInfo::getName() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setName(const std::string& name) {
|
|
|
|
this->name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& SDRDeviceInfo::getSerial() const {
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setSerial(const std::string& serial) {
|
|
|
|
this->serial = serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& SDRDeviceInfo::getTuner() const {
|
|
|
|
return tuner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setTuner(const std::string& tuner) {
|
|
|
|
this->tuner = tuner;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& SDRDeviceInfo::getManufacturer() const {
|
|
|
|
return manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setManufacturer(const std::string& manufacturer) {
|
|
|
|
this->manufacturer = manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& SDRDeviceInfo::getProduct() const {
|
|
|
|
return product;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setProduct(const std::string& product) {
|
|
|
|
this->product = product;
|
|
|
|
}
|
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
const std::string& SDRDeviceInfo::getDriver() const {
|
|
|
|
return driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setDriver(const std::string& driver) {
|
|
|
|
this->driver = driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& SDRDeviceInfo::getHardware() const {
|
|
|
|
return hardware;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setHardware(const std::string& hardware) {
|
|
|
|
this->hardware = hardware;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SDRDeviceInfo::hasTimestamps() const {
|
|
|
|
return timestamps;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setTimestamps(bool timestamps) {
|
|
|
|
this->timestamps = timestamps;
|
|
|
|
}
|
|
|
|
|
2015-11-11 00:16:26 -05:00
|
|
|
bool SDRDeviceInfo::isRemote() const {
|
|
|
|
return remote;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setRemote(bool remote) {
|
|
|
|
this->remote = remote;
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:43:31 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-20 21:48:37 -04:00
|
|
|
void SDRDeviceInfo::setDeviceArgs(SoapySDR::Kwargs deviceArgs) {
|
2015-09-14 20:31:39 -04:00
|
|
|
this->deviceArgs = deviceArgs;
|
|
|
|
}
|
|
|
|
|
2015-09-20 21:48:37 -04:00
|
|
|
SoapySDR::Kwargs SDRDeviceInfo::getDeviceArgs() {
|
2015-09-14 20:31:39 -04:00
|
|
|
return deviceArgs;
|
2015-09-30 23:45:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDeviceInfo::setStreamArgs(SoapySDR::Kwargs streamArgs) {
|
|
|
|
this->streamArgs = streamArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
SoapySDR::Kwargs SDRDeviceInfo::getStreamArgs() {
|
|
|
|
return streamArgs;
|
2015-09-13 22:18:29 -04:00
|
|
|
}
|
2015-10-04 19:55:52 -04:00
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
void SDRDeviceInfo::setSoapyDevice(SoapySDR::Device *dev) {
|
|
|
|
if (soapyDevice) {
|
|
|
|
SoapySDR::Device::unmake(soapyDevice);
|
|
|
|
}
|
|
|
|
soapyDevice = dev;
|
2015-10-23 02:53:51 -04:00
|
|
|
}
|
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
SoapySDR::Device *SDRDeviceInfo::getSoapyDevice() {
|
|
|
|
if (soapyDevice == nullptr) {
|
|
|
|
soapyDevice = SoapySDR::Device::make(deviceArgs);
|
2015-10-23 02:53:51 -04:00
|
|
|
}
|
2016-01-31 15:11:54 -05:00
|
|
|
return soapyDevice;
|
2015-10-23 02:53:51 -04:00
|
|
|
}
|
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
bool SDRDeviceInfo::hasCORR(int direction, size_t channel) {
|
|
|
|
SoapySDR::Device *dev = getSoapyDevice();
|
|
|
|
|
|
|
|
std::vector<std::string> freqs = dev->listFrequencies(direction, channel);
|
|
|
|
if (std::find(freqs.begin(), freqs.end(), "CORR") != freqs.end()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-04 19:55:52 -04:00
|
|
|
}
|
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
std::vector<long> SDRDeviceInfo::getSampleRates(int direction, size_t channel) {
|
|
|
|
SoapySDR::Device *dev = getSoapyDevice();
|
|
|
|
|
|
|
|
std::vector<long> result;
|
|
|
|
std::vector<double> sampleRates = dev->listSampleRates(direction, channel);
|
|
|
|
for (std::vector<double>::iterator si = sampleRates.begin(); si != sampleRates.end(); si++) {
|
|
|
|
result.push_back((long)(*si));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2015-10-04 19:55:52 -04:00
|
|
|
}
|
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
long SDRDeviceInfo::getSampleRateNear(int direction, size_t channel, long sampleRate_in) {
|
|
|
|
std::vector<long> sampleRates = getSampleRates(direction, channel);
|
|
|
|
long returnRate = sampleRates[0];
|
|
|
|
long sDelta = (long)sampleRate_in-sampleRates[0];
|
|
|
|
long minDelta = std::abs(sDelta);
|
|
|
|
for (std::vector<long>::iterator i = sampleRates.begin(); i != sampleRates.end(); i++) {
|
|
|
|
long thisDelta = std::abs(sampleRate_in - (*i));
|
|
|
|
if (thisDelta < minDelta) {
|
|
|
|
minDelta = thisDelta;
|
|
|
|
returnRate = (*i);
|
2015-10-04 19:55:52 -04:00
|
|
|
}
|
|
|
|
}
|
2016-01-31 15:11:54 -05:00
|
|
|
return returnRate;
|
2015-10-04 19:55:52 -04:00
|
|
|
}
|
|
|
|
|
2016-01-31 15:11:54 -05:00
|
|
|
SDRRangeMap SDRDeviceInfo::getGains(int direction, size_t channel) {
|
|
|
|
SoapySDR::Device *dev = getSoapyDevice();
|
|
|
|
std::vector<std::string> gainNames = dev->listGains(direction, channel);
|
|
|
|
std::map<std::string, SoapySDR::Range> gainMap;
|
|
|
|
|
|
|
|
for (std::vector<std::string>::iterator gname = gainNames.begin(); gname!= gainNames.end(); gname++) {
|
|
|
|
gainMap[(*gname)] = dev->getGainRange(direction, channel, (*gname));
|
2015-10-04 19:55:52 -04:00
|
|
|
}
|
2016-01-31 15:11:54 -05:00
|
|
|
|
|
|
|
return gainMap;
|
2015-10-04 19:55:52 -04:00
|
|
|
}
|