Cleanup: SDR threads, enumerator, device info
This commit is contained in:
parent
8420f5fb4b
commit
690896f65d
|
@ -6,7 +6,7 @@
|
|||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
|
||||
SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false), soapyDevice(nullptr) {
|
||||
SDRDeviceInfo::SDRDeviceInfo() : available(false), remote(false), manual(false), soapyDevice(nullptr) {
|
||||
active.store(false);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ SDRDeviceInfo::~SDRDeviceInfo() {
|
|||
}
|
||||
}
|
||||
|
||||
std::string SDRDeviceInfo::getDeviceId() {
|
||||
std::string SDRDeviceInfo::getDeviceId() const {
|
||||
std::string deviceId;
|
||||
|
||||
deviceId.append(getName());
|
||||
|
@ -30,124 +30,124 @@ int SDRDeviceInfo::getIndex() const {
|
|||
return index;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setIndex(const int index) {
|
||||
this->index = index;
|
||||
void SDRDeviceInfo::setIndex(const int index_in) {
|
||||
index = index_in;
|
||||
}
|
||||
|
||||
bool SDRDeviceInfo::isAvailable() const {
|
||||
return available;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setAvailable(bool available) {
|
||||
this->available = available;
|
||||
void SDRDeviceInfo::setAvailable(bool available_in) {
|
||||
available = available_in;
|
||||
}
|
||||
|
||||
bool SDRDeviceInfo::isActive() const {
|
||||
return active.load();
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setActive(bool active) {
|
||||
this->active.store(active);
|
||||
void SDRDeviceInfo::setActive(bool active_in) {
|
||||
active.store(active_in);
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setName(const std::string& name) {
|
||||
this->name = name;
|
||||
void SDRDeviceInfo::setName(const std::string& name_in) {
|
||||
name = name_in;
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getSerial() const {
|
||||
return serial;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setSerial(const std::string& serial) {
|
||||
this->serial = serial;
|
||||
void SDRDeviceInfo::setSerial(const std::string& serial_in) {
|
||||
serial = serial_in;
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getTuner() const {
|
||||
return tuner;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setTuner(const std::string& tuner) {
|
||||
this->tuner = tuner;
|
||||
void SDRDeviceInfo::setTuner(const std::string& tuner_in) {
|
||||
tuner = tuner_in;
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getManufacturer() const {
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setManufacturer(const std::string& manufacturer) {
|
||||
this->manufacturer = manufacturer;
|
||||
void SDRDeviceInfo::setManufacturer(const std::string& manufacturer_in) {
|
||||
manufacturer = manufacturer_in;
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getProduct() const {
|
||||
return product;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setProduct(const std::string& product) {
|
||||
this->product = product;
|
||||
void SDRDeviceInfo::setProduct(const std::string& product_in) {
|
||||
product = product_in;
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getDriver() const {
|
||||
return driver;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setDriver(const std::string& driver) {
|
||||
this->driver = driver;
|
||||
void SDRDeviceInfo::setDriver(const std::string& driver_in) {
|
||||
driver = driver_in;
|
||||
}
|
||||
|
||||
const std::string& SDRDeviceInfo::getHardware() const {
|
||||
return hardware;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setHardware(const std::string& hardware) {
|
||||
this->hardware = hardware;
|
||||
void SDRDeviceInfo::setHardware(const std::string& hardware_in) {
|
||||
hardware = hardware_in;
|
||||
}
|
||||
|
||||
bool SDRDeviceInfo::hasTimestamps() const {
|
||||
return timestamps;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setTimestamps(bool timestamps) {
|
||||
this->timestamps = timestamps;
|
||||
void SDRDeviceInfo::setTimestamps(bool timestamps_in) {
|
||||
timestamps = timestamps_in;
|
||||
}
|
||||
|
||||
bool SDRDeviceInfo::isRemote() const {
|
||||
return remote;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setRemote(bool remote) {
|
||||
this->remote = remote;
|
||||
void SDRDeviceInfo::setRemote(bool remote_in) {
|
||||
remote = remote_in;
|
||||
}
|
||||
|
||||
bool SDRDeviceInfo::isManual() const {
|
||||
return manual;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setManual(bool manual) {
|
||||
this->manual = manual;
|
||||
void SDRDeviceInfo::setManual(bool manual_in) {
|
||||
manual = manual_in;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setManualParams(std::string manualParams) {
|
||||
this->manual_params = manualParams;
|
||||
void SDRDeviceInfo::setManualParams(std::string manualParams_in) {
|
||||
manual_params = manualParams_in;
|
||||
}
|
||||
|
||||
std::string SDRDeviceInfo::getManualParams() {
|
||||
return manual_params;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setDeviceArgs(SoapySDR::Kwargs deviceArgs) {
|
||||
this->deviceArgs = deviceArgs;
|
||||
void SDRDeviceInfo::setDeviceArgs(SoapySDR::Kwargs deviceArgs_in) {
|
||||
deviceArgs = deviceArgs_in;
|
||||
}
|
||||
|
||||
SoapySDR::Kwargs SDRDeviceInfo::getDeviceArgs() {
|
||||
return deviceArgs;
|
||||
}
|
||||
|
||||
void SDRDeviceInfo::setStreamArgs(SoapySDR::Kwargs streamArgs) {
|
||||
this->streamArgs = streamArgs;
|
||||
void SDRDeviceInfo::setStreamArgs(SoapySDR::Kwargs streamArgs_in) {
|
||||
streamArgs = streamArgs_in;
|
||||
}
|
||||
|
||||
SoapySDR::Kwargs SDRDeviceInfo::getStreamArgs() {
|
||||
|
@ -268,7 +268,7 @@ SDRRangeMap SDRDeviceInfo::getGains(int direction, size_t channel) {
|
|||
|
||||
std::map<std::string, SoapySDR::Range> gainMap;
|
||||
|
||||
for (std::string gname : gainNames) {
|
||||
for (const std::string& gname : gainNames) {
|
||||
|
||||
gainMap[gname] = dev->getGainRange(direction, channel, gname);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <SoapySDR/Types.hpp>
|
||||
#include <SoapySDR/Device.hpp>
|
||||
|
||||
typedef struct _SDRManualDef {
|
||||
typedef struct SDRManualDef {
|
||||
std::string factory;
|
||||
std::string params;
|
||||
} SDRManualDef;
|
||||
|
@ -22,54 +22,54 @@ public:
|
|||
SDRDeviceInfo();
|
||||
~SDRDeviceInfo();
|
||||
|
||||
std::string getDeviceId();
|
||||
std::string getDeviceId() const;
|
||||
|
||||
int getIndex() const;
|
||||
void setIndex(const int index);
|
||||
void setIndex(int index_in);
|
||||
|
||||
bool isAvailable() const;
|
||||
void setAvailable(bool available);
|
||||
void setAvailable(bool available_in);
|
||||
|
||||
bool isActive() const;
|
||||
void setActive(bool active);
|
||||
void setActive(bool active_in);
|
||||
|
||||
const std::string& getName() const;
|
||||
void setName(const std::string& name);
|
||||
void setName(const std::string& name_in);
|
||||
|
||||
const std::string& getSerial() const;
|
||||
void setSerial(const std::string& serial);
|
||||
void setSerial(const std::string& serial_in);
|
||||
|
||||
const std::string& getTuner() const;
|
||||
void setTuner(const std::string& tuner);
|
||||
void setTuner(const std::string& tuner_in);
|
||||
|
||||
const std::string& getManufacturer() const;
|
||||
void setManufacturer(const std::string& manufacturer);
|
||||
void setManufacturer(const std::string& manufacturer_in);
|
||||
|
||||
const std::string& getProduct() const;
|
||||
void setProduct(const std::string& product);
|
||||
void setProduct(const std::string& product_in);
|
||||
|
||||
const std::string& getDriver() const;
|
||||
void setDriver(const std::string& driver);
|
||||
void setDriver(const std::string& driver_in);
|
||||
|
||||
const std::string& getHardware() const;
|
||||
void setHardware(const std::string& hardware);
|
||||
void setHardware(const std::string& hardware_in);
|
||||
|
||||
bool hasTimestamps() const;
|
||||
void setTimestamps(bool timestamps);
|
||||
void setTimestamps(bool timestamps_in);
|
||||
|
||||
bool isRemote() const;
|
||||
void setRemote(bool remote);
|
||||
void setRemote(bool remote_in);
|
||||
|
||||
bool isManual() const;
|
||||
void setManual(bool manual);
|
||||
void setManual(bool manual_in);
|
||||
|
||||
void setManualParams(std::string manualParams);
|
||||
void setManualParams(std::string manualParams_in);
|
||||
std::string getManualParams();
|
||||
|
||||
void setDeviceArgs(SoapySDR::Kwargs deviceArgs);
|
||||
void setDeviceArgs(SoapySDR::Kwargs deviceArgs_in);
|
||||
SoapySDR::Kwargs getDeviceArgs();
|
||||
|
||||
void setStreamArgs(SoapySDR::Kwargs deviceArgs);
|
||||
void setStreamArgs(SoapySDR::Kwargs streamArgs_in);
|
||||
SoapySDR::Kwargs getStreamArgs();
|
||||
|
||||
// void setSettingsInfo(SoapySDR::ArgInfoList settingsArgs);
|
||||
|
@ -100,8 +100,8 @@ private:
|
|||
int index = 0;
|
||||
std::string name, serial, product, manufacturer, tuner;
|
||||
std::string driver, hardware, manual_params;
|
||||
bool timestamps, available, remote, manual;
|
||||
std::atomic_bool active;
|
||||
bool timestamps{}, available, remote, manual;
|
||||
std::atomic_bool active{};
|
||||
|
||||
SoapySDR::Kwargs deviceArgs, streamArgs;
|
||||
SoapySDR::Device *soapyDevice;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include "SDREnumerator.h"
|
||||
#include "CubicSDRDefs.h"
|
||||
#include <vector>
|
||||
#include "CubicSDR.h"
|
||||
#include <string>
|
||||
|
@ -24,9 +23,7 @@ SDREnumerator::SDREnumerator() : IOThread() {
|
|||
|
||||
}
|
||||
|
||||
SDREnumerator::~SDREnumerator() {
|
||||
|
||||
}
|
||||
SDREnumerator::~SDREnumerator() = default;
|
||||
|
||||
// Some utility from SoapySDR :)
|
||||
static std::string trim(const std::string &s)
|
||||
|
@ -79,14 +76,14 @@ SoapySDR::Kwargs SDREnumerator::argsStrToKwargs(const std::string &args)
|
|||
}
|
||||
|
||||
|
||||
std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remoteAddr, bool noInit) {
|
||||
std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(const std::string& remoteAddr, bool noInit) {
|
||||
|
||||
if (SDREnumerator::devs[remoteAddr].size()) {
|
||||
if (!SDREnumerator::devs[remoteAddr].empty()) {
|
||||
return &SDREnumerator::devs[remoteAddr];
|
||||
}
|
||||
|
||||
if (noInit) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!soapy_initialized) {
|
||||
|
@ -99,10 +96,10 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
|||
|
||||
std::string userModPath = wxGetApp().getModulePath();
|
||||
|
||||
if (userModPath != "") {
|
||||
if (!userModPath.empty()) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Loading SoapySDR modules from " + userModPath + "..");
|
||||
std::vector<std::string> localMods = SoapySDR::listModules(userModPath);
|
||||
for (std::string mod : localMods) {
|
||||
for (const std::string& mod : localMods) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Initializing user specified SoapySDR module " + (mod) + "..");
|
||||
std::cout << "Initializing user specified SoapySDR module " << (mod) << ".." << std::endl << std::flush;
|
||||
SoapySDR::loadModule(mod);
|
||||
|
@ -150,9 +147,9 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
|||
|
||||
|
||||
std::cout << "\tAvailable factories...";
|
||||
SoapySDR::FindFunctions factories = SoapySDR::Registry::listFindFunctions();
|
||||
for (SoapySDR::FindFunctions::const_iterator it = factories.begin(); it != factories.end(); ++it) {
|
||||
if (it != factories.begin()) {
|
||||
SoapySDR::FindFunctions factoryList = SoapySDR::Registry::listFindFunctions();
|
||||
for (SoapySDR::FindFunctions::const_iterator it = factoryList.begin(); it != factoryList.end(); ++it) {
|
||||
if (it != factoryList.begin()) {
|
||||
std::cout << ", ";
|
||||
}
|
||||
std::cout << it->first;
|
||||
|
@ -162,10 +159,10 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
|||
}
|
||||
SDREnumerator::factories.push_back(it->first);
|
||||
}
|
||||
if (factories.empty()) {
|
||||
std::cout << "No factories found!" << std::endl;
|
||||
if (factoryList.empty()) {
|
||||
std::cout << "No factoryList found!" << std::endl;
|
||||
}
|
||||
if ((factories.size() == 1) && factories.find("null") != factories.end()) {
|
||||
if ((factoryList.size() == 1) && factoryList.find("null") != factoryList.end()) {
|
||||
std::cout << "Just 'null' factory found." << std::endl;
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_FAILED, std::string("No modules available."));
|
||||
}
|
||||
|
@ -194,27 +191,27 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
|||
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++) {
|
||||
if (!manuals.empty()) {
|
||||
for (const auto & manual : manuals) {
|
||||
std::vector<SoapySDR::Kwargs> manual_result;
|
||||
|
||||
std::string strDevArgs = "driver="+m_i->factory+","+m_i->params;
|
||||
std::string strDevArgs = "driver="+manual.factory+","+manual.params;
|
||||
|
||||
manualParams.push_back(m_i->params);
|
||||
manualParams.push_back(manual.params);
|
||||
|
||||
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);
|
||||
if (!manual_result.empty()) {
|
||||
for (const auto & i : manual_result) {
|
||||
results.push_back(i);
|
||||
manualResult.push_back(true);
|
||||
}
|
||||
} else {
|
||||
SoapySDR::Kwargs failedEnum;
|
||||
failedEnum = argsStrToKwargs(strDevArgs);
|
||||
failedEnum["label"] = "Not Found ("+m_i->factory+")";
|
||||
failedEnum["label"] = "Not Found ("+manual.factory+")";
|
||||
results.push_back(failedEnum);
|
||||
manualResult.push_back(false);
|
||||
}
|
||||
|
@ -225,7 +222,7 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
|||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, std::string("Opening remote server ") + remoteAddr + "..");
|
||||
}
|
||||
for (size_t i = 0; i < results.size(); i++) {
|
||||
SDRDeviceInfo *dev = new SDRDeviceInfo();
|
||||
auto *dev = new SDRDeviceInfo();
|
||||
|
||||
SoapySDR::Kwargs deviceArgs = results[i];
|
||||
|
||||
|
@ -273,14 +270,14 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
|
|||
DeviceConfig *cfg = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
|
||||
|
||||
ConfigSettings devSettings = cfg->getSettings();
|
||||
if (devSettings.size()) {
|
||||
if (!devSettings.empty()) {
|
||||
// Load the saved device settings to deviceArgs, and back to settingsInfo.
|
||||
for (ConfigSettings::const_iterator set_i = devSettings.begin(); set_i != devSettings.end(); set_i++) {
|
||||
deviceArgs[set_i->first] = set_i->second;
|
||||
}
|
||||
for (size_t j = 0; j < settingsInfo.size(); j++) {
|
||||
if (deviceArgs.find(settingsInfo[j].key) != deviceArgs.end()) {
|
||||
settingsInfo[j].value = deviceArgs[settingsInfo[j].key];
|
||||
for (auto & j : settingsInfo) {
|
||||
if (deviceArgs.find(j.key) != deviceArgs.end()) {
|
||||
j.value = deviceArgs[j.key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -317,9 +314,9 @@ void SDREnumerator::run() {
|
|||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Scanning local devices, please wait..");
|
||||
SDREnumerator::enumerate_devices("");
|
||||
|
||||
if (remotes.size()) {
|
||||
if (!remotes.empty()) {
|
||||
|
||||
for (std::string remote : remotes) {
|
||||
for (const std::string& remote : remotes) {
|
||||
wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, "Scanning devices at " + (remote) + ", please wait..");
|
||||
SDREnumerator::enumerate_devices(remote);
|
||||
}
|
||||
|
@ -333,8 +330,8 @@ void SDREnumerator::run() {
|
|||
|
||||
|
||||
|
||||
void SDREnumerator::addRemote(std::string remoteAddr) {
|
||||
std::vector<std::string>::iterator remote_i = std::find(remotes.begin(), remotes.end(), remoteAddr);
|
||||
void SDREnumerator::addRemote(const std::string& remoteAddr) {
|
||||
auto remote_i = std::find(remotes.begin(), remotes.end(), remoteAddr);
|
||||
|
||||
if (remote_i != remotes.end()) {
|
||||
return;
|
||||
|
@ -343,12 +340,12 @@ void SDREnumerator::addRemote(std::string remoteAddr) {
|
|||
}
|
||||
}
|
||||
|
||||
void SDREnumerator::removeRemote(std::string remoteAddr) {
|
||||
std::vector<std::string>::iterator remote_i = std::find(remotes.begin(), remotes.end(), remoteAddr);
|
||||
void SDREnumerator::removeRemote(const std::string& remoteAddr) {
|
||||
auto remote_i = std::find(remotes.begin(), remotes.end(), remoteAddr);
|
||||
|
||||
if (remote_i != remotes.end()) {
|
||||
if (devs.find(*remote_i) != devs.end()) {
|
||||
while (devs[*remote_i].size()) {
|
||||
while (!devs[*remote_i].empty()) {
|
||||
SDRDeviceInfo *devRemove = devs[*remote_i].back();
|
||||
devs[*remote_i].pop_back();
|
||||
delete devRemove;
|
||||
|
@ -371,11 +368,11 @@ void SDREnumerator::addManual(std::string factory, std::string params) {
|
|||
manuals.push_back(def);
|
||||
}
|
||||
|
||||
void SDREnumerator::removeManual(std::string factory, std::string params) {
|
||||
for (std::vector<SDRManualDef>::iterator i = manuals.begin(); i != manuals.end(); i++) {
|
||||
void SDREnumerator::removeManual(const std::string& factory, const std::string& params) {
|
||||
for (auto i = manuals.begin(); i != manuals.end(); i++) {
|
||||
if (i->factory == factory && i->params == params) {
|
||||
manuals.erase(i);
|
||||
for (std::vector<SDRDeviceInfo *>::iterator subdevs_i = devs[""].begin(); subdevs_i != devs[""].end(); subdevs_i++) {
|
||||
for (auto subdevs_i = devs[""].begin(); subdevs_i != devs[""].end(); subdevs_i++) {
|
||||
if ((*subdevs_i)->isManual() && (*subdevs_i)->getDriver() == factory && (*subdevs_i)->getManualParams() == params) {
|
||||
devs[""].erase(subdevs_i);
|
||||
break;
|
||||
|
@ -390,8 +387,8 @@ std::vector<SDRManualDef> &SDREnumerator::getManuals() {
|
|||
return SDREnumerator::manuals;
|
||||
}
|
||||
|
||||
void SDREnumerator::setManuals(std::vector<SDRManualDef> manuals) {
|
||||
SDREnumerator::manuals = manuals;
|
||||
void SDREnumerator::setManuals(std::vector<SDRManualDef> manuals_in) {
|
||||
SDREnumerator::manuals = manuals_in;
|
||||
}
|
||||
|
||||
bool SDREnumerator::hasRemoteModule() {
|
||||
|
@ -403,12 +400,10 @@ void SDREnumerator::reset() {
|
|||
factories.clear();
|
||||
modules.clear();
|
||||
|
||||
for (std::map< std::string, std::vector<SDRDeviceInfo *> >::iterator di = devs.begin(); di != devs.end(); di++) {
|
||||
|
||||
for (std::vector<SDRDeviceInfo *>::iterator i = di->second.begin(); i != di->second.end(); i++) {
|
||||
(*i)->setSoapyDevice(nullptr);
|
||||
for (auto & dev : devs) {
|
||||
for (auto & i : dev.second) {
|
||||
i->setSoapyDevice(nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
devs.clear();
|
||||
}
|
||||
|
|
|
@ -21,22 +21,22 @@ private:
|
|||
|
||||
public:
|
||||
SDREnumerator();
|
||||
~SDREnumerator();
|
||||
~SDREnumerator() override;
|
||||
enum SDREnumState { SDR_ENUM_DEVICES_READY, SDR_ENUM_MESSAGE, SDR_ENUM_TERMINATED, SDR_ENUM_FAILED };
|
||||
|
||||
static std::vector<SDRDeviceInfo *> *enumerate_devices(std::string remoteAddr = "", bool noInit=false);
|
||||
static std::vector<SDRDeviceInfo *> *enumerate_devices(const std::string& remoteAddr = "", bool noInit=false);
|
||||
|
||||
virtual void run();
|
||||
void run() override;
|
||||
|
||||
static SoapySDR::Kwargs argsStrToKwargs(const std::string &args);
|
||||
static void addRemote(std::string remoteAddr);
|
||||
static void removeRemote(std::string remoteAddr);
|
||||
static void addRemote(const std::string& remoteAddr);
|
||||
static void removeRemote(const 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 removeManual(const std::string& factory, const std::string& params);
|
||||
static std::vector<SDRManualDef> &getManuals();
|
||||
static void setManuals(std::vector<SDRManualDef> manuals);
|
||||
static void setManuals(std::vector<SDRManualDef> manuals_in);
|
||||
static void reset();
|
||||
static std::vector<std::string> &getFactories();
|
||||
|
||||
|
@ -47,5 +47,4 @@ protected:
|
|||
static std::vector<std::string> remotes;
|
||||
static std::map< std::string, std::vector<SDRDeviceInfo *> > devs;
|
||||
static std::vector<SDRManualDef> manuals;
|
||||
static std::mutex devs_busy;
|
||||
};
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include "SDRPostThread.h"
|
||||
#include "CubicSDRDefs.h"
|
||||
#include "CubicSDR.h"
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
|
||||
|
@ -54,7 +52,7 @@ void SDRPostThread::updateActiveDemodulators() {
|
|||
//retreive the current list of demodulators:
|
||||
auto demodulators = wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
for (auto demod : demodulators) {
|
||||
for (const auto& demod : demodulators) {
|
||||
|
||||
// not in range?
|
||||
if (demod->isDeltaLock()) {
|
||||
|
@ -70,7 +68,6 @@ void SDRPostThread::updateActiveDemodulators() {
|
|||
// deactivate if active
|
||||
|
||||
if (wxGetApp().getDemodMgr().getCurrentModem() == demod) {
|
||||
|
||||
demod->setActive(false);
|
||||
}
|
||||
else if (demod->isActive() && !demod->isFollow() && !demod->isTracking()) {
|
||||
|
@ -105,7 +102,7 @@ void SDRPostThread::resetAllDemodulators() {
|
|||
//retreive the current list of demodulators:
|
||||
auto demodulators = wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
for (auto demod : demodulators) {
|
||||
for (const auto& demod : demodulators) {
|
||||
|
||||
demod->setActive(false);
|
||||
demod->getIQInputDataPipe()->flush();
|
||||
|
@ -128,11 +125,11 @@ void SDRPostThread::updateChannels() {
|
|||
|
||||
|
||||
// Find the channelizer channel that corresponds to the given frequency
|
||||
int SDRPostThread::getChannelAt(long long frequency) {
|
||||
int SDRPostThread::getChannelAt(long long frequency_in) {
|
||||
int chan = -1;
|
||||
long long minDelta = sampleRate;
|
||||
for (int i = 0; i < numChannels+1; i++) {
|
||||
long long fdelta = abs(frequency - chanCenters[i]);
|
||||
long long fdelta = abs(frequency_in - chanCenters[i]);
|
||||
if (fdelta < minDelta) {
|
||||
minDelta = fdelta;
|
||||
chan = i;
|
||||
|
@ -176,7 +173,7 @@ void SDRPostThread::run() {
|
|||
|
||||
bool doUpdate = false;
|
||||
|
||||
if (data_in && data_in->data.size()) {
|
||||
if (data_in && !data_in->data.empty()) {
|
||||
|
||||
if(data_in->numChannels > 1) {
|
||||
if (chanMode == 1) {
|
||||
|
@ -189,8 +186,7 @@ void SDRPostThread::run() {
|
|||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < runDemods.size(); j++) {
|
||||
DemodulatorInstancePtr demod = runDemods[j];
|
||||
for (const auto& demod : runDemods) {
|
||||
if (abs(frequency - demod->getFrequency()) > (sampleRate / 2)) {
|
||||
doUpdate = true;
|
||||
}
|
||||
|
@ -234,7 +230,7 @@ DemodulatorThreadIQDataPtr SDRPostThread::getFullSampleRateIqData(SDRThreadIQDat
|
|||
}
|
||||
|
||||
// Push visual data; i.e. Main Waterfall (all frames) and Spectrum (active frame)
|
||||
void SDRPostThread::pushVisualData(DemodulatorThreadIQDataPtr iqDataOut) {
|
||||
void SDRPostThread::pushVisualData(const DemodulatorThreadIQDataPtr& iqDataOut) {
|
||||
|
||||
if (iqDataOutQueue != nullptr) {
|
||||
|
||||
|
@ -290,15 +286,15 @@ void SDRPostThread::runSingleCH(SDRThreadIQData *data_in) {
|
|||
//push the DC-corrected data as Main Spactrum + Waterfall data.
|
||||
pushVisualData(demodDataOut);
|
||||
|
||||
if (runDemods.size() > 0 && iqActiveDemodVisualQueue != nullptr) {
|
||||
if (!runDemods.empty() && iqActiveDemodVisualQueue != nullptr) {
|
||||
//non-blocking push here, we can afford to loose some samples for a ever-changing visual display.
|
||||
iqActiveDemodVisualQueue->try_push(demodDataOut);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < runDemods.size(); i++) {
|
||||
for (auto & runDemod : runDemods) {
|
||||
// try-push() : we do our best to only stimulate active demods, but some could happen to be dead, full, or indeed non-active.
|
||||
//so in short never block here no matter what.
|
||||
runDemods[i]->getIQInputDataPipe()->try_push(demodDataOut);
|
||||
runDemod->getIQInputDataPipe()->try_push(demodDataOut);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +443,7 @@ void SDRPostThread::runPFBCH(SDRThreadIQData *data_in) {
|
|||
}
|
||||
|
||||
// Find active demodulators
|
||||
if (runDemods.size() > 0) {
|
||||
if (!runDemods.empty()) {
|
||||
// Channelize data
|
||||
// firpfbch produces [numChannels] interleaved output samples for every [numChannels] samples
|
||||
for (int i = 0, iMax = data_in->data.size(); i < iMax; i+=numChannels) {
|
||||
|
@ -503,7 +499,7 @@ void SDRPostThread::runPFBCH2(SDRThreadIQData *data_in) {
|
|||
}
|
||||
|
||||
// Find active demodulators
|
||||
if (runDemods.size() > 0) {
|
||||
if (!runDemods.empty()) {
|
||||
// Channelize data
|
||||
// firpfbch2 produces [numChannels] interleaved output samples for every [numChannels/2] input samples
|
||||
for (int i = 0, iMax = data_in->data.size(); i < iMax; i += numChannels/2) {
|
||||
|
|
|
@ -14,12 +14,12 @@ enum SDRPostThreadChannelizerType {
|
|||
class SDRPostThread : public IOThread {
|
||||
public:
|
||||
SDRPostThread();
|
||||
~SDRPostThread();
|
||||
~SDRPostThread() override;
|
||||
|
||||
void notifyDemodulatorsChanged();
|
||||
|
||||
virtual void run();
|
||||
virtual void terminate();
|
||||
void run() override;
|
||||
void terminate() override;
|
||||
|
||||
void resetAllDemodulators();
|
||||
|
||||
|
@ -36,7 +36,7 @@ protected:
|
|||
private:
|
||||
// Copy the full samplerate into a new DemodulatorThreadIQDataPtr.
|
||||
DemodulatorThreadIQDataPtr getFullSampleRateIqData(SDRThreadIQData *data_in);
|
||||
void pushVisualData(DemodulatorThreadIQDataPtr iqDataOut);
|
||||
void pushVisualData(const DemodulatorThreadIQDataPtr& iqDataOut);
|
||||
|
||||
void runSingleCH(SDRThreadIQData *data_in);
|
||||
|
||||
|
@ -50,7 +50,7 @@ private:
|
|||
|
||||
void updateActiveDemodulators();
|
||||
void updateChannels();
|
||||
int getChannelAt(long long frequency);
|
||||
int getChannelAt(long long frequency_in);
|
||||
|
||||
ReBuffer<DemodulatorThreadIQData> buffers;
|
||||
std::vector<liquid_float_complex> dataOut;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "CubicSDR.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <SoapySDR/Logger.h>
|
||||
#include <chrono>
|
||||
|
||||
#define TARGET_DISPLAY_FPS (60)
|
||||
|
@ -47,9 +46,7 @@ SDRThread::SDRThread() : IOThread(), buffers("SDRThreadBuffers") {
|
|||
iq_swap.store(false);
|
||||
}
|
||||
|
||||
SDRThread::~SDRThread() {
|
||||
|
||||
}
|
||||
SDRThread::~SDRThread() = default;
|
||||
|
||||
SoapySDR::Kwargs SDRThread::combineArgs(SoapySDR::Kwargs a, SoapySDR::Kwargs b) {
|
||||
SoapySDR::Kwargs c;
|
||||
|
@ -86,12 +83,12 @@ bool SDRThread::init() {
|
|||
|
||||
SoapySDR::Kwargs currentStreamArgs = combineArgs(devInfo->getStreamArgs(),streamArgs);
|
||||
|
||||
std::string streamExceptionStr("");
|
||||
std::string streamExceptionStr;
|
||||
|
||||
//1. setup stream for CF32:
|
||||
try {
|
||||
stream = device->setupStream(SOAPY_SDR_RX,"CF32", std::vector<size_t>(), currentStreamArgs);
|
||||
} catch(exception e) {
|
||||
} catch(const exception &e) {
|
||||
streamExceptionStr = e.what();
|
||||
}
|
||||
|
||||
|
@ -195,7 +192,7 @@ void SDRThread::assureBufferMinSize(SDRThreadIQData * dataOut, size_t minSize) {
|
|||
//Called in an infinite loop, read SaopySDR device to build
|
||||
// a 'this.numElems' sized batch of samples (SDRThreadIQData) and push it into iqDataOutQueue.
|
||||
//this batch of samples is built to represent 1 frame / TARGET_DISPLAY_FPS.
|
||||
int SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
|
||||
int SDRThread::readStream(const SDRThreadIQDataQueuePtr& iqDataOutQueue) {
|
||||
|
||||
int flags(0);
|
||||
|
||||
|
@ -442,10 +439,9 @@ void SDRThread::updateGains() {
|
|||
gainChanged.clear();
|
||||
|
||||
SDRRangeMap gains = devInfo->getGains(SOAPY_SDR_RX, 0);
|
||||
for (SDRRangeMap::iterator gi = gains.begin(); gi != gains.end(); gi++) {
|
||||
|
||||
gainValues[gi->first] = device->getGain(SOAPY_SDR_RX, 0, gi->first);
|
||||
gainChanged[gi->first] = false;
|
||||
for (auto & gain : gains) {
|
||||
gainValues[gain.first] = device->getGain(SOAPY_SDR_RX, 0, gain.first);
|
||||
gainChanged[gain.first] = false;
|
||||
}
|
||||
|
||||
gain_value_changed.store(false);
|
||||
|
@ -573,8 +569,8 @@ void SDRThread::updateSettings() {
|
|||
DeviceConfig *devConfig = deviceConfig.load();
|
||||
ConfigGains gains = devConfig->getGains();
|
||||
|
||||
for (ConfigGains::iterator gain_i = gains.begin(); gain_i != gains.end(); gain_i++) {
|
||||
setGain(gain_i->first, gain_i->second);
|
||||
for (auto & gain : gains) {
|
||||
setGain(gain.first, gain.second);
|
||||
}
|
||||
}
|
||||
doUpdate = true;
|
||||
|
@ -583,10 +579,10 @@ void SDRThread::updateSettings() {
|
|||
if (gain_value_changed.load() && !agc_mode.load()) {
|
||||
std::lock_guard < std::mutex > lock(gain_busy);
|
||||
|
||||
for (std::map<std::string,bool>::iterator gci = gainChanged.begin(); gci != gainChanged.end(); gci++) {
|
||||
if (gci->second) {
|
||||
device->setGain(SOAPY_SDR_RX, 0, gci->first, gainValues[gci->first]);
|
||||
gainChanged[gci->first] = false;
|
||||
for (auto & gci : gainChanged) {
|
||||
if (gci.second) {
|
||||
device->setGain(SOAPY_SDR_RX, 0, gci.first, gainValues[gci.first]);
|
||||
gainChanged[gci.first] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -597,10 +593,10 @@ void SDRThread::updateSettings() {
|
|||
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
for (std::map<std::string, bool>::iterator sci = settingChanged.begin(); sci != settingChanged.end(); sci++) {
|
||||
if (sci->second) {
|
||||
device->writeSetting(sci->first, settings[sci->first]);
|
||||
settingChanged[sci->first] = false;
|
||||
for (auto & sci : settingChanged) {
|
||||
if (sci.second) {
|
||||
device->writeSetting(sci.first, settings[sci.first]);
|
||||
settingChanged[sci.first] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -669,21 +665,21 @@ void SDRThread::setDevice(SDRDeviceInfo *dev) {
|
|||
}
|
||||
}
|
||||
|
||||
int SDRThread::getOptimalElementCount(long long sampleRate, int fps) {
|
||||
int elemCount = (int)floor((double)sampleRate/(double)fps);
|
||||
int SDRThread::getOptimalElementCount(long long sampleRate_in, int fps) {
|
||||
int elemCount = (int)floor((double)sampleRate_in / (double)fps);
|
||||
int nch = numChannels.load();
|
||||
elemCount = int(ceil((double)elemCount/(double)nch))*nch;
|
||||
// std::cout << "Calculated optimal " << numChannels.load() << " channel element count of " << elemCount << std::endl;
|
||||
return elemCount;
|
||||
}
|
||||
|
||||
int SDRThread::getOptimalChannelCount(long long sampleRate) {
|
||||
if (sampleRate <= CHANNELIZER_RATE_MAX) {
|
||||
int SDRThread::getOptimalChannelCount(long long sampleRate_in) {
|
||||
if (sampleRate_in <= CHANNELIZER_RATE_MAX) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int optimal_rate = CHANNELIZER_RATE_MAX;
|
||||
int optimal_count = int(ceil(double(sampleRate)/double(optimal_rate)));
|
||||
int optimal_count = int(ceil(double(sampleRate_in) / double(optimal_rate)));
|
||||
|
||||
if (optimal_count % 2 == 1) {
|
||||
optimal_count--;
|
||||
|
@ -769,16 +765,16 @@ long SDRThread::getSampleRate() {
|
|||
return sampleRate.load();
|
||||
}
|
||||
|
||||
void SDRThread::setPPM(int ppm) {
|
||||
this->ppm.store(ppm);
|
||||
void SDRThread::setPPM(int ppm_in) {
|
||||
ppm.store(ppm_in);
|
||||
ppm_changed.store(true);
|
||||
|
||||
DeviceConfig *devConfig = deviceConfig.load();
|
||||
if (devConfig) {
|
||||
devConfig->setPPM(ppm);
|
||||
devConfig->setPPM(ppm_in);
|
||||
}
|
||||
|
||||
// std::cout << "Set PPM: " << this->ppm.load() << std::endl;
|
||||
// std::cout << "Set PPM: " << this->ppm_in.load() << std::endl;
|
||||
}
|
||||
|
||||
int SDRThread::getPPM() {
|
||||
|
@ -806,7 +802,7 @@ bool SDRThread::getIQSwap() {
|
|||
return iq_swap.load();
|
||||
}
|
||||
|
||||
void SDRThread::setGain(std::string name, float value) {
|
||||
void SDRThread::setGain(const std::string& name, float value) {
|
||||
std::lock_guard < std::mutex > lock(gain_busy);
|
||||
gainValues[name] = value;
|
||||
gainChanged[name] = true;
|
||||
|
@ -818,14 +814,14 @@ void SDRThread::setGain(std::string name, float value) {
|
|||
}
|
||||
}
|
||||
|
||||
float SDRThread::getGain(std::string name) {
|
||||
float SDRThread::getGain(const std::string& name) {
|
||||
std::lock_guard < std::mutex > lock(gain_busy);
|
||||
float val = gainValues[name];
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void SDRThread::writeSetting(std::string name, std::string value) {
|
||||
void SDRThread::writeSetting(const std::string& name, std::string value) {
|
||||
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
|
@ -837,7 +833,7 @@ void SDRThread::writeSetting(std::string name, std::string value) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string SDRThread::readSetting(std::string name) {
|
||||
std::string SDRThread::readSetting(const std::string& name) {
|
||||
std::string val;
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <SoapySDR/Registry.hpp>
|
||||
#include <SoapySDR/Device.hpp>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
class SDRThreadIQData {
|
||||
public:
|
||||
|
@ -35,9 +35,7 @@ public:
|
|||
|
||||
}
|
||||
|
||||
virtual ~SDRThreadIQData() {
|
||||
|
||||
}
|
||||
virtual ~SDRThreadIQData() = default;
|
||||
};
|
||||
typedef std::shared_ptr<SDRThreadIQData> SDRThreadIQDataPtr;
|
||||
typedef ThreadBlockingQueue<SDRThreadIQDataPtr> SDRThreadIQDataQueue;
|
||||
|
@ -50,23 +48,23 @@ private:
|
|||
|
||||
//returns the SoapyDevice readStream return value,
|
||||
//i.e if >= 0 the number of samples read, else if < 0 an error code.
|
||||
int readStream(SDRThreadIQDataQueuePtr iqDataOutQueue);
|
||||
int readStream(const SDRThreadIQDataQueuePtr& iqDataOutQueue);
|
||||
|
||||
void readLoop();
|
||||
|
||||
public:
|
||||
SDRThread();
|
||||
~SDRThread();
|
||||
~SDRThread() override;
|
||||
|
||||
enum SDRThreadState { SDR_THREAD_MESSAGE, SDR_THREAD_INITIALIZED, SDR_THREAD_FAILED};
|
||||
|
||||
virtual void run();
|
||||
virtual void terminate();
|
||||
void run() override;
|
||||
void terminate() override;
|
||||
|
||||
SDRDeviceInfo *getDevice();
|
||||
void setDevice(SDRDeviceInfo *dev);
|
||||
int getOptimalElementCount(long long sampleRate, int fps);
|
||||
int getOptimalChannelCount(long long sampleRate);
|
||||
int getOptimalElementCount(long long sampleRate_in, int fps);
|
||||
int getOptimalChannelCount(long long sampleRate_in);
|
||||
|
||||
void setFrequency(long long freq);
|
||||
long long getFrequency();
|
||||
|
@ -84,7 +82,7 @@ public:
|
|||
void setSampleRate(long rate);
|
||||
long getSampleRate();
|
||||
|
||||
void setPPM(int ppm);
|
||||
void setPPM(int ppm_in);
|
||||
int getPPM();
|
||||
|
||||
void setAGCMode(bool mode);
|
||||
|
@ -93,11 +91,11 @@ public:
|
|||
void setIQSwap(bool swap);
|
||||
bool getIQSwap();
|
||||
|
||||
void setGain(std::string name, float value);
|
||||
float getGain(std::string name);
|
||||
void setGain(const std::string& name, float value);
|
||||
float getGain(const std::string& name);
|
||||
|
||||
void writeSetting(std::string name, std::string value);
|
||||
std::string readSetting(std::string name);
|
||||
void writeSetting(const std::string& name, std::string value);
|
||||
std::string readSetting(const std::string& name);
|
||||
|
||||
void setStreamArgs(SoapySDR::Kwargs streamArgs);
|
||||
|
||||
|
|
Loading…
Reference in New Issue