mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-10-01 17:46:53 -04:00
Merge pull request #109 from cjcliffe/save_device_prefs
Save device prefs
This commit is contained in:
commit
1d20fd16bb
@ -1,36 +1,76 @@
|
|||||||
#include "AppConfig.h"
|
#include "AppConfig.h"
|
||||||
|
#include "CubicSDR.h"
|
||||||
|
|
||||||
DeviceConfig::DeviceConfig() : ppm(0), deviceId("") {
|
DeviceConfig::DeviceConfig() : deviceId("") {
|
||||||
|
ppm.store(0);
|
||||||
|
directSampling.store(false);
|
||||||
|
offset.store(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceConfig::DeviceConfig(std::string deviceId) : ppm(0) {
|
DeviceConfig::DeviceConfig(std::string deviceId) : DeviceConfig() {
|
||||||
this->deviceId = deviceId;
|
this->deviceId = deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConfig::setPPM(int ppm) {
|
void DeviceConfig::setPPM(int ppm) {
|
||||||
this->ppm = ppm;
|
this->ppm.store(ppm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceConfig::getPPM() {
|
int DeviceConfig::getPPM() {
|
||||||
return ppm;
|
return ppm.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceConfig::setDirectSampling(int mode) {
|
||||||
|
directSampling.store(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeviceConfig::getDirectSampling() {
|
||||||
|
return directSampling.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceConfig::setOffset(long long offset) {
|
||||||
|
this->offset.store(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
long long DeviceConfig::getOffset() {
|
||||||
|
return offset.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceConfig::setIQSwap(bool iqSwap) {
|
||||||
|
this->iqSwap.store(iqSwap);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceConfig::getIQSwap() {
|
||||||
|
return iqSwap.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConfig::setDeviceId(std::string deviceId) {
|
void DeviceConfig::setDeviceId(std::string deviceId) {
|
||||||
|
busy_lock.lock();
|
||||||
this->deviceId = deviceId;
|
this->deviceId = deviceId;
|
||||||
|
busy_lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DeviceConfig::getDeviceId() {
|
std::string DeviceConfig::getDeviceId() {
|
||||||
return deviceId;
|
std::string tmp;
|
||||||
|
|
||||||
|
busy_lock.lock();
|
||||||
|
tmp = deviceId;
|
||||||
|
busy_lock.unlock();
|
||||||
|
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConfig::save(DataNode *node) {
|
void DeviceConfig::save(DataNode *node) {
|
||||||
node->newChild("id")->element()->set(deviceId);
|
busy_lock.lock();
|
||||||
DataNode *ppm_node = node->newChild("ppm");
|
*node->newChild("id") = deviceId;
|
||||||
ppm_node->element()->set((int)ppm);
|
*node->newChild("ppm") = (int)ppm;
|
||||||
|
*node->newChild("iq_swap") = iqSwap;
|
||||||
|
*node->newChild("direct_sampling") = directSampling;
|
||||||
|
*node->newChild("offset") = offset;
|
||||||
|
busy_lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConfig::load(DataNode *node) {
|
void DeviceConfig::load(DataNode *node) {
|
||||||
|
busy_lock.lock();
|
||||||
if (node->hasAnother("ppm")) {
|
if (node->hasAnother("ppm")) {
|
||||||
DataNode *ppm_node = node->getNext("ppm");
|
DataNode *ppm_node = node->getNext("ppm");
|
||||||
int ppmValue = 0;
|
int ppmValue = 0;
|
||||||
@ -38,11 +78,48 @@ void DeviceConfig::load(DataNode *node) {
|
|||||||
setPPM(ppmValue);
|
setPPM(ppmValue);
|
||||||
std::cout << "Loaded PPM for device '" << deviceId << "' at " << ppmValue << "ppm" << std::endl;
|
std::cout << "Loaded PPM for device '" << deviceId << "' at " << ppmValue << "ppm" << std::endl;
|
||||||
}
|
}
|
||||||
|
if (node->hasAnother("iq_swap")) {
|
||||||
|
DataNode *iq_swap_node = node->getNext("iq_swap");
|
||||||
|
int iqSwapValue = 0;
|
||||||
|
iq_swap_node->element()->get(iqSwapValue);
|
||||||
|
setIQSwap(iqSwapValue?true:false);
|
||||||
|
std::cout << "Loaded I/Q Swap for device '" << deviceId << "' as " << (iqSwapValue?"swapped":"not swapped") << std::endl;
|
||||||
|
}
|
||||||
|
if (node->hasAnother("direct_sampling")) {
|
||||||
|
DataNode *direct_sampling_node = node->getNext("direct_sampling");
|
||||||
|
int directSamplingValue = 0;
|
||||||
|
direct_sampling_node->element()->get(directSamplingValue);
|
||||||
|
setDirectSampling(directSamplingValue);
|
||||||
|
std::cout << "Loaded Direct Sampling Mode for device '" << deviceId << "': ";
|
||||||
|
switch (directSamplingValue) {
|
||||||
|
case 0:
|
||||||
|
std::cout << "off" << std::endl;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
std::cout << "I-ADC" << std::endl;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
std::cout << "Q-ADC" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node->hasAnother("offset")) {
|
||||||
|
DataNode *offset_node = node->getNext("offset");
|
||||||
|
long long offsetValue = 0;
|
||||||
|
offset_node->element()->get(offsetValue);
|
||||||
|
setOffset(offsetValue);
|
||||||
|
std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "Hz" << std::endl;
|
||||||
|
}
|
||||||
|
busy_lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceConfig *AppConfig::getDevice(std::string deviceId) {
|
DeviceConfig *AppConfig::getDevice(std::string deviceId) {
|
||||||
DeviceConfig *conf = &deviceConfig[deviceId];
|
if (deviceConfig.find(deviceId) == deviceConfig.end()) {
|
||||||
|
deviceConfig[deviceId] = new DeviceConfig();
|
||||||
|
}
|
||||||
|
DeviceConfig *conf = deviceConfig[deviceId];
|
||||||
conf->setDeviceId(deviceId);
|
conf->setDeviceId(deviceId);
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
@ -71,10 +148,10 @@ bool AppConfig::save() {
|
|||||||
cfg.rootNode()->setName("cubicsdr_config");
|
cfg.rootNode()->setName("cubicsdr_config");
|
||||||
DataNode *devices_node = cfg.rootNode()->newChild("devices");
|
DataNode *devices_node = cfg.rootNode()->newChild("devices");
|
||||||
|
|
||||||
std::map<std::string, DeviceConfig>::iterator device_config_i;
|
std::map<std::string, DeviceConfig *>::iterator device_config_i;
|
||||||
for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) {
|
for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) {
|
||||||
DataNode *device_node = devices_node->newChild("device");
|
DataNode *device_node = devices_node->newChild("device");
|
||||||
device_config_i->second.save(device_node);
|
device_config_i->second->save(device_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cfgFileDir = getConfigDir();
|
std::string cfgFileDir = getConfigDir();
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "DataTree.h"
|
#include "DataTree.h"
|
||||||
|
|
||||||
|
|
||||||
class DeviceConfig {
|
class DeviceConfig {
|
||||||
public:
|
public:
|
||||||
DeviceConfig();
|
DeviceConfig();
|
||||||
@ -15,6 +16,15 @@ public:
|
|||||||
void setPPM(int ppm);
|
void setPPM(int ppm);
|
||||||
int getPPM();
|
int getPPM();
|
||||||
|
|
||||||
|
void setDirectSampling(int mode);
|
||||||
|
int getDirectSampling();
|
||||||
|
|
||||||
|
void setOffset(long long offset);
|
||||||
|
long long getOffset();
|
||||||
|
|
||||||
|
void setIQSwap(bool iqSwap);
|
||||||
|
bool getIQSwap();
|
||||||
|
|
||||||
void setDeviceId(std::string deviceId);
|
void setDeviceId(std::string deviceId);
|
||||||
std::string getDeviceId();
|
std::string getDeviceId();
|
||||||
|
|
||||||
@ -23,7 +33,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string deviceId;
|
std::string deviceId;
|
||||||
int ppm;
|
std::mutex busy_lock;
|
||||||
|
|
||||||
|
std::atomic_int ppm, directSampling;
|
||||||
|
std::atomic_bool iqSwap;
|
||||||
|
std::atomic_llong offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AppConfig {
|
class AppConfig {
|
||||||
@ -36,5 +50,5 @@ public:
|
|||||||
bool reset();
|
bool reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, DeviceConfig> deviceConfig;
|
std::map<std::string, DeviceConfig *> deviceConfig;
|
||||||
};
|
};
|
||||||
|
@ -151,9 +151,9 @@ AppFrame::AppFrame() :
|
|||||||
|
|
||||||
wxMenu *dsMenu = new wxMenu;
|
wxMenu *dsMenu = new wxMenu;
|
||||||
|
|
||||||
dsMenu->AppendRadioItem(wxID_SET_DS_OFF, "Off");
|
directSamplingMenuItems[0] = dsMenu->AppendRadioItem(wxID_SET_DS_OFF, "Off");
|
||||||
dsMenu->AppendRadioItem(wxID_SET_DS_I, "I-ADC");
|
directSamplingMenuItems[1] = dsMenu->AppendRadioItem(wxID_SET_DS_I, "I-ADC");
|
||||||
dsMenu->AppendRadioItem(wxID_SET_DS_Q, "Q-ADC");
|
directSamplingMenuItems[2] = dsMenu->AppendRadioItem(wxID_SET_DS_Q, "Q-ADC");
|
||||||
|
|
||||||
menu->AppendSubMenu(dsMenu, "Direct Sampling");
|
menu->AppendSubMenu(dsMenu, "Direct Sampling");
|
||||||
|
|
||||||
@ -328,6 +328,22 @@ AppFrame::~AppFrame() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AppFrame::initDeviceParams(std::string deviceId) {
|
||||||
|
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId);
|
||||||
|
|
||||||
|
int dsMode = devConfig->getDirectSampling();
|
||||||
|
|
||||||
|
if (dsMode > 0 && dsMode <= 2) {
|
||||||
|
directSamplingMenuItems[devConfig->getDirectSampling()]->Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (devConfig->getIQSwap()) {
|
||||||
|
iqSwapMenuItem->Check();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AppFrame::OnMenu(wxCommandEvent& event) {
|
void AppFrame::OnMenu(wxCommandEvent& event) {
|
||||||
if (event.GetId() >= wxID_RT_AUDIO_DEVICE && event.GetId() < wxID_RT_AUDIO_DEVICE + devices.size()) {
|
if (event.GetId() >= wxID_RT_AUDIO_DEVICE && event.GetId() < wxID_RT_AUDIO_DEVICE + devices.size()) {
|
||||||
if (activeDemodulator) {
|
if (activeDemodulator) {
|
||||||
@ -448,7 +464,19 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
|||||||
|
|
||||||
std::vector<SDRDeviceInfo *> *devs = wxGetApp().getDevices();
|
std::vector<SDRDeviceInfo *> *devs = wxGetApp().getDevices();
|
||||||
if (event.GetId() >= wxID_DEVICE_ID && event.GetId() <= wxID_DEVICE_ID + devs->size()) {
|
if (event.GetId() >= wxID_DEVICE_ID && event.GetId() <= wxID_DEVICE_ID + devs->size()) {
|
||||||
wxGetApp().setDevice(event.GetId() - wxID_DEVICE_ID);
|
int devId = event.GetId() - wxID_DEVICE_ID;
|
||||||
|
wxGetApp().setDevice(devId);
|
||||||
|
|
||||||
|
SDRDeviceInfo *dev = (*wxGetApp().getDevices())[devId];
|
||||||
|
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
|
||||||
|
|
||||||
|
int dsMode = devConfig->getDirectSampling();
|
||||||
|
|
||||||
|
if (dsMode >= 0 && dsMode <= 2) {
|
||||||
|
directSamplingMenuItems[devConfig->getDirectSampling()]->Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
iqSwapMenuItem->Check(devConfig->getIQSwap());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.GetId() >= wxID_AUDIO_BANDWIDTH_BASE) {
|
if (event.GetId() >= wxID_AUDIO_BANDWIDTH_BASE) {
|
||||||
@ -617,7 +645,6 @@ void AppFrame::saveSession(std::string fileName) {
|
|||||||
DataNode *header = s.rootNode()->newChild("header");
|
DataNode *header = s.rootNode()->newChild("header");
|
||||||
*header->newChild("version") = std::string(CUBICSDR_VERSION);
|
*header->newChild("version") = std::string(CUBICSDR_VERSION);
|
||||||
*header->newChild("center_freq") = wxGetApp().getFrequency();
|
*header->newChild("center_freq") = wxGetApp().getFrequency();
|
||||||
*header->newChild("offset") = wxGetApp().getOffset();
|
|
||||||
|
|
||||||
DataNode *demods = s.rootNode()->newChild("demodulators");
|
DataNode *demods = s.rootNode()->newChild("demodulators");
|
||||||
|
|
||||||
@ -656,14 +683,11 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
|
|
||||||
std::string version(*header->getNext("version"));
|
std::string version(*header->getNext("version"));
|
||||||
long long center_freq = *header->getNext("center_freq");
|
long long center_freq = *header->getNext("center_freq");
|
||||||
long long offset = *header->getNext("offset");
|
|
||||||
|
|
||||||
std::cout << "Loading " << version << " session file" << std::endl;
|
std::cout << "Loading " << version << " session file" << std::endl;
|
||||||
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
|
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
|
||||||
std::cout << "\tOffset: " << offset << std::endl;
|
|
||||||
|
|
||||||
wxGetApp().setFrequency(center_freq);
|
wxGetApp().setFrequency(center_freq);
|
||||||
wxGetApp().setOffset(offset);
|
|
||||||
|
|
||||||
DataNode *demodulators = l.rootNode()->getNext("demodulators");
|
DataNode *demodulators = l.rootNode()->getNext("demodulators");
|
||||||
|
|
||||||
@ -711,7 +735,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newDemod->run();
|
newDemod->run();
|
||||||
|
newDemod->setActive(false);
|
||||||
wxGetApp().bindDemodulator(newDemod);
|
wxGetApp().bindDemodulator(newDemod);
|
||||||
|
|
||||||
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
|
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
|
||||||
|
@ -58,6 +58,7 @@ public:
|
|||||||
~AppFrame();
|
~AppFrame();
|
||||||
void OnThread(wxCommandEvent& event);
|
void OnThread(wxCommandEvent& event);
|
||||||
void OnEventInput(wxThreadEvent& event);
|
void OnEventInput(wxThreadEvent& event);
|
||||||
|
void initDeviceParams(std::string deviceId);
|
||||||
|
|
||||||
void saveSession(std::string fileName);
|
void saveSession(std::string fileName);
|
||||||
bool loadSession(std::string fileName);
|
bool loadSession(std::string fileName);
|
||||||
@ -86,6 +87,7 @@ private:
|
|||||||
std::map<int, wxMenuItem *> outputDeviceMenuItems;
|
std::map<int, wxMenuItem *> outputDeviceMenuItems;
|
||||||
std::map<int, wxMenuItem *> sampleRateMenuItems;
|
std::map<int, wxMenuItem *> sampleRateMenuItems;
|
||||||
std::map<int, wxMenuItem *> audioSampleRateMenuItems;
|
std::map<int, wxMenuItem *> audioSampleRateMenuItems;
|
||||||
|
std::map<int, wxMenuItem *> directSamplingMenuItems;
|
||||||
wxMenuItem *iqSwapMenuItem;
|
wxMenuItem *iqSwapMenuItem;
|
||||||
|
|
||||||
std::string currentSessionFile;
|
std::string currentSessionFile;
|
||||||
|
@ -67,6 +67,7 @@ bool CubicSDR::OnInit() {
|
|||||||
std::vector<SDRDeviceInfo *>::iterator devs_i;
|
std::vector<SDRDeviceInfo *>::iterator devs_i;
|
||||||
|
|
||||||
SDRThread::enumerate_rtl(&devs);
|
SDRThread::enumerate_rtl(&devs);
|
||||||
|
SDRDeviceInfo *dev = NULL;
|
||||||
|
|
||||||
if (devs.size() > 1) {
|
if (devs.size() > 1) {
|
||||||
wxArrayString choices;
|
wxArrayString choices;
|
||||||
@ -85,15 +86,35 @@ bool CubicSDR::OnInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int devId = wxGetSingleChoiceIndex(wxT("Devices"), wxT("Choose Input Device"), choices);
|
int devId = wxGetSingleChoiceIndex(wxT("Devices"), wxT("Choose Input Device"), choices);
|
||||||
|
if (devId == -1) { // User chose to cancel
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev = devs[devId];
|
||||||
|
|
||||||
std::cout << "Chosen: " << devId << std::endl;
|
|
||||||
sdrThread->setDeviceId(devId);
|
sdrThread->setDeviceId(devId);
|
||||||
|
} else if (devs.size() == 1) {
|
||||||
|
dev = devs[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dev) {
|
||||||
|
wxMessageDialog *info;
|
||||||
|
info = new wxMessageDialog(NULL, wxT("\x28\u256F\xB0\u25A1\xB0\uFF09\u256F\uFE35\x20\u253B\u2501\u253B"), wxT("RTL-SDR device not found"), wxOK | wxICON_ERROR);
|
||||||
|
info->ShowModal();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread);
|
t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread);
|
||||||
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
|
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
|
||||||
|
|
||||||
appframe = new AppFrame();
|
appframe = new AppFrame();
|
||||||
|
if (dev != NULL) {
|
||||||
|
appframe->initDeviceParams(dev->getDeviceId());
|
||||||
|
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
|
||||||
|
ppm = devConfig->getPPM();
|
||||||
|
offset = devConfig->getOffset();
|
||||||
|
directSamplingMode = devConfig->getDirectSampling();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
int main_policy;
|
int main_policy;
|
||||||
@ -169,6 +190,10 @@ void CubicSDR::setOffset(long long ofs) {
|
|||||||
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_OFFSET);
|
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_OFFSET);
|
||||||
command.llong_value = ofs;
|
command.llong_value = ofs;
|
||||||
threadCmdQueueSDR->push(command);
|
threadCmdQueueSDR->push(command);
|
||||||
|
|
||||||
|
SDRDeviceInfo *dev = (*getDevices())[getDevice()];
|
||||||
|
config.getDevice(dev->getDeviceId())->setOffset(ofs);
|
||||||
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CubicSDR::setDirectSampling(int mode) {
|
void CubicSDR::setDirectSampling(int mode) {
|
||||||
@ -176,6 +201,10 @@ void CubicSDR::setDirectSampling(int mode) {
|
|||||||
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DIRECT_SAMPLING);
|
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DIRECT_SAMPLING);
|
||||||
command.llong_value = mode;
|
command.llong_value = mode;
|
||||||
threadCmdQueueSDR->push(command);
|
threadCmdQueueSDR->push(command);
|
||||||
|
|
||||||
|
SDRDeviceInfo *dev = (*getDevices())[getDevice()];
|
||||||
|
config.getDevice(dev->getDeviceId())->setDirectSampling(mode);
|
||||||
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CubicSDR::getDirectSampling() {
|
int CubicSDR::getDirectSampling() {
|
||||||
@ -184,6 +213,9 @@ int CubicSDR::getDirectSampling() {
|
|||||||
|
|
||||||
void CubicSDR::setSwapIQ(bool swapIQ) {
|
void CubicSDR::setSwapIQ(bool swapIQ) {
|
||||||
sdrPostThread->setSwapIQ(swapIQ);
|
sdrPostThread->setSwapIQ(swapIQ);
|
||||||
|
SDRDeviceInfo *dev = (*getDevices())[getDevice()];
|
||||||
|
config.getDevice(dev->getDeviceId())->setIQSwap(swapIQ);
|
||||||
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CubicSDR::getSwapIQ() {
|
bool CubicSDR::getSwapIQ() {
|
||||||
@ -244,11 +276,12 @@ void CubicSDR::setDevice(int deviceId) {
|
|||||||
threadCmdQueueSDR->push(command);
|
threadCmdQueueSDR->push(command);
|
||||||
|
|
||||||
SDRDeviceInfo *dev = (*getDevices())[deviceId];
|
SDRDeviceInfo *dev = (*getDevices())[deviceId];
|
||||||
|
DeviceConfig *devConfig = config.getDevice(dev->getDeviceId());
|
||||||
|
|
||||||
SDRThreadCommand command_ppm(SDRThreadCommand::SDR_THREAD_CMD_SET_PPM);
|
setPPM(devConfig->getPPM());
|
||||||
ppm = config.getDevice(dev->getDeviceId())->getPPM();
|
setDirectSampling(devConfig->getDirectSampling());
|
||||||
command_ppm.llong_value = ppm;
|
setSwapIQ(devConfig->getIQSwap());
|
||||||
threadCmdQueueSDR->push(command_ppm);
|
setOffset(devConfig->getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
int CubicSDR::getDevice() {
|
int CubicSDR::getDevice() {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) :
|
SDRThread::SDRThread(SDRThreadCommandQueue* pQueue) :
|
||||||
commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false), offset(0), deviceId(-1) {
|
commandQueue(pQueue), iqDataOutQueue(NULL), terminated(false), offset(0), deviceId(-1) {
|
||||||
dev = NULL;
|
dev = NULL;
|
||||||
sampleRate = DEFAULT_SAMPLE_RATE;
|
sampleRate.store(DEFAULT_SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDRThread::~SDRThread() {
|
SDRThread::~SDRThread() {
|
||||||
@ -122,6 +122,7 @@ void SDRThread::threadMain() {
|
|||||||
std::cout << "SDR thread initializing.." << std::endl;
|
std::cout << "SDR thread initializing.." << std::endl;
|
||||||
|
|
||||||
int devCount = rtlsdr_get_device_count();
|
int devCount = rtlsdr_get_device_count();
|
||||||
|
|
||||||
std::vector<SDRDeviceInfo *> devs;
|
std::vector<SDRDeviceInfo *> devs;
|
||||||
if (deviceId == -1) {
|
if (deviceId == -1) {
|
||||||
deviceId = enumerate_rtl(&devs);
|
deviceId = enumerate_rtl(&devs);
|
||||||
@ -136,16 +137,20 @@ void SDRThread::threadMain() {
|
|||||||
std::cout << "Using device #" << deviceId << std::endl;
|
std::cout << "Using device #" << deviceId << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(devs[deviceId]->getDeviceId());
|
||||||
|
|
||||||
signed char buf[BUF_SIZE];
|
signed char buf[BUF_SIZE];
|
||||||
|
|
||||||
long long frequency = DEFAULT_FREQ;
|
long long frequency = DEFAULT_FREQ;
|
||||||
int ppm = wxGetApp().getConfig()->getDevice(devs[deviceId]->getDeviceId())->getPPM();
|
int ppm = devConfig->getPPM();
|
||||||
int direct_sampling_mode = 0;
|
int direct_sampling_mode = devConfig->getDirectSampling();;
|
||||||
int buf_size = BUF_SIZE;
|
int buf_size = BUF_SIZE;
|
||||||
|
offset.store(devConfig->getOffset());
|
||||||
|
wxGetApp().setSwapIQ(devConfig->getIQSwap());
|
||||||
|
|
||||||
rtlsdr_open(&dev, deviceId);
|
rtlsdr_open(&dev, deviceId);
|
||||||
rtlsdr_set_sample_rate(dev, sampleRate);
|
rtlsdr_set_sample_rate(dev, sampleRate.load());
|
||||||
rtlsdr_set_center_freq(dev, frequency - offset);
|
rtlsdr_set_center_freq(dev, frequency - offset.load());
|
||||||
rtlsdr_set_freq_correction(dev, ppm);
|
rtlsdr_set_freq_correction(dev, ppm);
|
||||||
rtlsdr_set_agc_mode(dev, 1);
|
rtlsdr_set_agc_mode(dev, 1);
|
||||||
rtlsdr_set_offset_tuning(dev, 0);
|
rtlsdr_set_offset_tuning(dev, 0);
|
||||||
@ -153,7 +158,7 @@ void SDRThread::threadMain() {
|
|||||||
|
|
||||||
// sampleRate = rtlsdr_get_sample_rate(dev);
|
// sampleRate = rtlsdr_get_sample_rate(dev);
|
||||||
|
|
||||||
std::cout << "Sample Rate is: " << sampleRate << std::endl;
|
std::cout << "Sample Rate is: " << sampleRate.load() << std::endl;
|
||||||
|
|
||||||
int n_read;
|
int n_read;
|
||||||
double seconds = 0.0;
|
double seconds = 0.0;
|
||||||
@ -174,8 +179,8 @@ void SDRThread::threadMain() {
|
|||||||
bool ppm_changed = false;
|
bool ppm_changed = false;
|
||||||
bool direct_sampling_changed = false;
|
bool direct_sampling_changed = false;
|
||||||
long long new_freq = frequency;
|
long long new_freq = frequency;
|
||||||
long long new_offset = offset;
|
long long new_offset = offset.load();
|
||||||
long long new_rate = sampleRate;
|
long long new_rate = sampleRate.load();
|
||||||
int new_device = deviceId;
|
int new_device = deviceId;
|
||||||
int new_ppm = ppm;
|
int new_ppm = ppm;
|
||||||
|
|
||||||
@ -187,8 +192,8 @@ void SDRThread::threadMain() {
|
|||||||
case SDRThreadCommand::SDR_THREAD_CMD_TUNE:
|
case SDRThreadCommand::SDR_THREAD_CMD_TUNE:
|
||||||
freq_changed = true;
|
freq_changed = true;
|
||||||
new_freq = command.llong_value;
|
new_freq = command.llong_value;
|
||||||
if (new_freq < sampleRate / 2) {
|
if (new_freq < sampleRate.load() / 2) {
|
||||||
new_freq = sampleRate / 2;
|
new_freq = sampleRate.load() / 2;
|
||||||
}
|
}
|
||||||
// std::cout << "Set frequency: " << new_freq << std::endl;
|
// std::cout << "Set frequency: " << new_freq << std::endl;
|
||||||
break;
|
break;
|
||||||
@ -231,8 +236,8 @@ void SDRThread::threadMain() {
|
|||||||
if (device_changed) {
|
if (device_changed) {
|
||||||
rtlsdr_close(dev);
|
rtlsdr_close(dev);
|
||||||
rtlsdr_open(&dev, new_device);
|
rtlsdr_open(&dev, new_device);
|
||||||
rtlsdr_set_sample_rate(dev, sampleRate);
|
rtlsdr_set_sample_rate(dev, sampleRate.load());
|
||||||
rtlsdr_set_center_freq(dev, frequency - offset);
|
rtlsdr_set_center_freq(dev, frequency - offset.load());
|
||||||
rtlsdr_set_freq_correction(dev, ppm);
|
rtlsdr_set_freq_correction(dev, ppm);
|
||||||
rtlsdr_set_agc_mode(dev, 1);
|
rtlsdr_set_agc_mode(dev, 1);
|
||||||
rtlsdr_set_offset_tuning(dev, 0);
|
rtlsdr_set_offset_tuning(dev, 0);
|
||||||
@ -244,16 +249,16 @@ void SDRThread::threadMain() {
|
|||||||
new_freq = frequency;
|
new_freq = frequency;
|
||||||
freq_changed = true;
|
freq_changed = true;
|
||||||
}
|
}
|
||||||
offset = new_offset;
|
offset.store(new_offset);
|
||||||
}
|
}
|
||||||
if (rate_changed) {
|
if (rate_changed) {
|
||||||
rtlsdr_set_sample_rate(dev, new_rate);
|
rtlsdr_set_sample_rate(dev, new_rate);
|
||||||
rtlsdr_reset_buffer(dev);
|
rtlsdr_reset_buffer(dev);
|
||||||
sampleRate = rtlsdr_get_sample_rate(dev);
|
sampleRate.store(rtlsdr_get_sample_rate(dev));
|
||||||
}
|
}
|
||||||
if (freq_changed) {
|
if (freq_changed) {
|
||||||
frequency = new_freq;
|
frequency = new_freq;
|
||||||
rtlsdr_set_center_freq(dev, frequency - offset);
|
rtlsdr_set_center_freq(dev, frequency - offset.load());
|
||||||
}
|
}
|
||||||
if (ppm_changed) {
|
if (ppm_changed) {
|
||||||
ppm = new_ppm;
|
ppm = new_ppm;
|
||||||
@ -283,7 +288,7 @@ void SDRThread::threadMain() {
|
|||||||
// std::lock_guard < std::mutex > lock(dataOut->m_mutex);
|
// std::lock_guard < std::mutex > lock(dataOut->m_mutex);
|
||||||
dataOut->setRefCount(1);
|
dataOut->setRefCount(1);
|
||||||
dataOut->frequency = frequency;
|
dataOut->frequency = frequency;
|
||||||
dataOut->sampleRate = sampleRate;
|
dataOut->sampleRate = sampleRate.load();
|
||||||
|
|
||||||
if (dataOut->data.capacity() < n_read) {
|
if (dataOut->data.capacity() < n_read) {
|
||||||
dataOut->data.reserve(n_read);
|
dataOut->data.reserve(n_read);
|
||||||
@ -295,7 +300,7 @@ void SDRThread::threadMain() {
|
|||||||
|
|
||||||
memcpy(&dataOut->data[0], buf, n_read);
|
memcpy(&dataOut->data[0], buf, n_read);
|
||||||
|
|
||||||
double time_slice = (double) n_read / (double) sampleRate;
|
double time_slice = (double) n_read / (double) sampleRate.load();
|
||||||
seconds += time_slice;
|
seconds += time_slice;
|
||||||
|
|
||||||
if (iqDataOutQueue.load() != NULL) {
|
if (iqDataOutQueue.load() != NULL) {
|
||||||
|
@ -140,19 +140,19 @@ public:
|
|||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
int getDeviceId() const {
|
int getDeviceId() const {
|
||||||
return deviceId;
|
return deviceId.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDeviceId(int deviceId) {
|
void setDeviceId(int deviceId) {
|
||||||
this->deviceId = deviceId;
|
this->deviceId.store(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t sampleRate;
|
std::atomic<uint32_t> sampleRate;
|
||||||
long long offset;
|
std::atomic<long long> offset;
|
||||||
std::atomic<SDRThreadCommandQueue*> commandQueue;
|
std::atomic<SDRThreadCommandQueue*> commandQueue;
|
||||||
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
|
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
|
||||||
|
|
||||||
std::atomic<bool> terminated;
|
std::atomic<bool> terminated;
|
||||||
int deviceId;
|
std::atomic<int> deviceId;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user