mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-12 07:06:11 -05:00
PPM correction now editable + saved and loaded/applied per-device by serial and name
This commit is contained in:
parent
68d4627e99
commit
55fd0c986f
@ -19,15 +19,15 @@ std::string AppConfig::getConfigDir() {
|
||||
return dataDir;
|
||||
}
|
||||
|
||||
void AppConfig::setPPM(std::string device_serial, int ppm) {
|
||||
device_ppm[device_serial] = ppm;
|
||||
void AppConfig::setPPM(std::string deviceId, int ppm) {
|
||||
device_ppm[deviceId] = ppm;
|
||||
}
|
||||
|
||||
int AppConfig::getPPM(std::string device_serial) {
|
||||
if (device_ppm.find(device_serial) == device_ppm.end()) {
|
||||
int AppConfig::getPPM(std::string deviceId) {
|
||||
if (device_ppm.find(deviceId) == device_ppm.end()) {
|
||||
return 0;
|
||||
}
|
||||
return device_ppm[device_serial];
|
||||
return device_ppm[deviceId];
|
||||
}
|
||||
|
||||
bool AppConfig::save() {
|
||||
|
@ -11,8 +11,8 @@ public:
|
||||
|
||||
std::string getConfigDir();
|
||||
|
||||
void setPPM(std::string device_serial, int ppm);
|
||||
int getPPM(std::string device_serial);
|
||||
void setPPM(std::string deviceId, int ppm);
|
||||
int getPPM(std::string deviceId);
|
||||
bool save();
|
||||
bool load();
|
||||
bool reset();
|
||||
|
@ -132,6 +132,7 @@ AppFrame::AppFrame() :
|
||||
wxMenu *menu = new wxMenu;
|
||||
// menu->Append(wxID_NEW);
|
||||
menu->Append(wxID_SET_FREQ_OFFSET, "Set Frequency Offset");
|
||||
menu->Append(wxID_SET_PPM, "Set Device PPM");
|
||||
menu->Append(wxID_OPEN, "&Open Session");
|
||||
menu->Append(wxID_SAVE, "&Save Session");
|
||||
menu->Append(wxID_SAVEAS, "Save Session &As..");
|
||||
@ -318,6 +319,10 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
||||
if (ofs != -1) {
|
||||
wxGetApp().setOffset(ofs);
|
||||
}
|
||||
} else if (event.GetId() == wxID_SET_PPM) {
|
||||
long ofs = wxGetNumberFromUser("Frequency correction for device in PPM.\ni.e. -51 for -51 PPM", "Parts per million (PPM)",
|
||||
"Frequency Correction", wxGetApp().getPPM(), -1000, 1000, this);
|
||||
wxGetApp().setPPM(ofs);
|
||||
} else if (event.GetId() == wxID_SAVE) {
|
||||
if (!currentSessionFile.empty()) {
|
||||
saveSession(currentSessionFile);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define wxID_RT_AUDIO_DEVICE 1000
|
||||
#define wxID_SET_FREQ_OFFSET 2001
|
||||
#define wxID_RESET 2002
|
||||
#define wxID_SET_PPM 2003
|
||||
|
||||
#define wxID_THEME_DEFAULT 2100
|
||||
#define wxID_THEME_SHARP 2101
|
||||
|
@ -40,17 +40,11 @@ bool CubicSDR::OnInit() {
|
||||
|
||||
wxApp: SetAppName("cubicsdr");
|
||||
|
||||
config.setPPM("RTLBlah :: 00000001",11);
|
||||
config.setPPM("RTLBlah :: 00000002",12);
|
||||
config.save();
|
||||
config.load();
|
||||
|
||||
std::cout << "test1: " << config.getPPM("RTLBlah :: 00000001") << std::endl;
|
||||
std::cout << "test2: " << config.getPPM("RTLBlah :: 00000002") << std::endl;
|
||||
std::cout << "test3: " << config.getPPM("foo") << std::endl;
|
||||
|
||||
frequency = DEFAULT_FREQ;
|
||||
offset = 0;
|
||||
ppm = 0;
|
||||
|
||||
audioVisualQueue = new DemodulatorThreadOutputQueue();
|
||||
audioVisualQueue->set_max_num_items(1);
|
||||
@ -228,13 +222,48 @@ void CubicSDR::setDevice(int deviceId) {
|
||||
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DEVICE);
|
||||
command.llong_value = deviceId;
|
||||
threadCmdQueueSDR->push(command);
|
||||
|
||||
SDRDeviceInfo *dev = (*getDevices())[deviceId];
|
||||
|
||||
SDRThreadCommand command_ppm(SDRThreadCommand::SDR_THREAD_CMD_SET_PPM);
|
||||
ppm = config.getPPM(dev->getDeviceId());
|
||||
command_ppm.llong_value = ppm;
|
||||
threadCmdQueueSDR->push(command_ppm);
|
||||
}
|
||||
|
||||
int CubicSDR::getDevice() {
|
||||
return sdrThread->getDeviceId();
|
||||
}
|
||||
|
||||
|
||||
AppConfig *CubicSDR::getConfig() {
|
||||
return &config;
|
||||
}
|
||||
|
||||
void CubicSDR::setPPM(int ppm_in) {
|
||||
if (sdrThread->getDeviceId() < 0) {
|
||||
return;
|
||||
}
|
||||
ppm = ppm_in;
|
||||
|
||||
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_PPM);
|
||||
command.llong_value = ppm;
|
||||
threadCmdQueueSDR->push(command);
|
||||
|
||||
SDRDeviceInfo *dev = (*getDevices())[getDevice()];
|
||||
|
||||
config.setPPM(dev->getDeviceId(), ppm_in);
|
||||
config.save();
|
||||
}
|
||||
|
||||
int CubicSDR::getPPM() {
|
||||
if (sdrThread->getDeviceId() < 0) {
|
||||
return 0;
|
||||
}
|
||||
SDRDeviceInfo *dev = (*getDevices())[getDevice()];
|
||||
|
||||
SDRThreadCommand command_ppm(SDRThreadCommand::SDR_THREAD_CMD_SET_PPM);
|
||||
ppm = config.getPPM(dev->getDeviceId());
|
||||
|
||||
return ppm;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,9 @@ public:
|
||||
|
||||
AppConfig *getConfig();
|
||||
|
||||
void setPPM(int ppm_in);
|
||||
int getPPM();
|
||||
|
||||
private:
|
||||
AppConfig config;
|
||||
PrimaryGLContext *m_glContext;
|
||||
@ -61,6 +64,7 @@ private:
|
||||
|
||||
long long frequency;
|
||||
long long offset;
|
||||
int ppm;
|
||||
long long sampleRate;
|
||||
|
||||
SDRThread *sdrThread;
|
||||
|
@ -122,8 +122,9 @@ void SDRThread::threadMain() {
|
||||
std::cout << "SDR thread initializing.." << std::endl;
|
||||
|
||||
int devCount = rtlsdr_get_device_count();
|
||||
std::vector<SDRDeviceInfo *> devs;
|
||||
if (deviceId == -1) {
|
||||
deviceId = enumerate_rtl(NULL);
|
||||
deviceId = enumerate_rtl(&devs);
|
||||
}
|
||||
|
||||
if (deviceId == -1) {
|
||||
@ -136,10 +137,12 @@ void SDRThread::threadMain() {
|
||||
signed char buf[BUF_SIZE];
|
||||
|
||||
long long frequency = DEFAULT_FREQ;
|
||||
int ppm = wxGetApp().getConfig()->getPPM(devs[deviceId]->getDeviceId());
|
||||
|
||||
rtlsdr_open(&dev, deviceId);
|
||||
rtlsdr_set_sample_rate(dev, sampleRate);
|
||||
rtlsdr_set_center_freq(dev, frequency - offset);
|
||||
rtlsdr_set_freq_correction(dev, ppm);
|
||||
rtlsdr_set_agc_mode(dev, 1);
|
||||
rtlsdr_set_offset_tuning(dev, 0);
|
||||
rtlsdr_reset_buffer(dev);
|
||||
@ -164,10 +167,12 @@ void SDRThread::threadMain() {
|
||||
bool offset_changed = false;
|
||||
bool rate_changed = false;
|
||||
bool device_changed = false;
|
||||
long long new_freq;
|
||||
long long new_offset;
|
||||
long long new_rate;
|
||||
int new_device;
|
||||
bool ppm_changed = false;
|
||||
long long new_freq = frequency;
|
||||
long long new_offset = offset;
|
||||
long long new_rate = sampleRate;
|
||||
int new_device = deviceId;
|
||||
int new_ppm = ppm;
|
||||
|
||||
while (!cmdQueue->empty()) {
|
||||
SDRThreadCommand command;
|
||||
@ -197,6 +202,11 @@ void SDRThread::threadMain() {
|
||||
new_device = (int) command.llong_value;
|
||||
std::cout << "Set device: " << new_device << std::endl;
|
||||
break;
|
||||
case SDRThreadCommand::SDR_THREAD_CMD_SET_PPM:
|
||||
ppm_changed = true;
|
||||
new_ppm = (int) command.llong_value;
|
||||
std::cout << "Set PPM: " << new_ppm << std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -207,6 +217,7 @@ void SDRThread::threadMain() {
|
||||
rtlsdr_open(&dev, new_device);
|
||||
rtlsdr_set_sample_rate(dev, sampleRate);
|
||||
rtlsdr_set_center_freq(dev, frequency - offset);
|
||||
rtlsdr_set_freq_correction(dev, ppm);
|
||||
rtlsdr_set_agc_mode(dev, 1);
|
||||
rtlsdr_set_offset_tuning(dev, 0);
|
||||
rtlsdr_reset_buffer(dev);
|
||||
@ -224,6 +235,10 @@ void SDRThread::threadMain() {
|
||||
frequency = new_freq;
|
||||
rtlsdr_set_center_freq(dev, frequency - offset);
|
||||
}
|
||||
if (ppm_changed) {
|
||||
ppm = new_ppm;
|
||||
rtlsdr_set_freq_correction(dev, ppm);
|
||||
}
|
||||
}
|
||||
|
||||
rtlsdr_read_sync(dev, buf, BUF_SIZE, &n_read);
|
||||
|
@ -11,6 +11,16 @@ class SDRDeviceInfo {
|
||||
public:
|
||||
SDRDeviceInfo() : name(""), serial(""), available(false) { }
|
||||
|
||||
std::string getDeviceId() {
|
||||
std::string deviceId;
|
||||
|
||||
deviceId.append(getName());
|
||||
deviceId.append(" :: ");
|
||||
deviceId.append(getSerial());
|
||||
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
bool isAvailable() const {
|
||||
return available;
|
||||
}
|
||||
@ -71,7 +81,7 @@ private:
|
||||
class SDRThreadCommand {
|
||||
public:
|
||||
enum SDRThreadCommandEnum {
|
||||
SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET, SDR_THREAD_CMD_SET_SAMPLERATE, SDR_THREAD_CMD_SET_DEVICE
|
||||
SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET, SDR_THREAD_CMD_SET_SAMPLERATE, SDR_THREAD_CMD_SET_PPM, SDR_THREAD_CMD_SET_DEVICE
|
||||
};
|
||||
|
||||
SDRThreadCommand() :
|
||||
|
Loading…
Reference in New Issue
Block a user