From 936a6403286dff5a0f420e03b91a96e7e682647d Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 9 Jan 2016 00:09:46 -0500 Subject: [PATCH] Per-Rig-Per-SDR IF frequency lock control and save/load --- src/AppConfig.cpp | 31 +++++++++++++++++++++ src/AppConfig.h | 4 +++ src/AppFrame.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++---- src/AppFrame.h | 3 ++ 4 files changed, 104 insertions(+), 5 deletions(-) diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index 7502071..264d6ed 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -55,6 +55,12 @@ void DeviceConfig::save(DataNode *node) { for (ConfigSettings::const_iterator set_i = settings.begin(); set_i != settings.end(); set_i++) { *settingsNode->newChild(set_i->first.c_str()) = set_i->second; } + DataNode *rigIFs = node->newChild("rig_ifs"); + for (std::map::const_iterator rigIF_i = rigIF.begin(); rigIF_i != rigIF.end(); rigIF_i++) { + DataNode *ifNode = rigIFs->newChild("rig_if"); + *ifNode->newChild("model") = rigIF_i->first; + *ifNode->newChild("sdr_if") = rigIF_i->second; + } busy_lock.unlock(); } @@ -98,6 +104,21 @@ void DeviceConfig::load(DataNode *node) { } } } + if (node->hasAnother("rig_ifs")) { + DataNode *rigIFNodes = node->getNext("rig_ifs"); + while (rigIFNodes->hasAnother("rig_if")) { + DataNode *rigIFNode = rigIFNodes->getNext("rig_if"); + if (rigIFNode->hasAnother("model") && rigIFNode->hasAnother("sdr_if")) { + int load_model; + long long load_freq; + + rigIFNode->getNext("model")->element()->get(load_model); + rigIFNode->getNext("sdr_if")->element()->get(load_freq); + + rigIF[load_model] = load_freq; + } + } + } busy_lock.unlock(); } @@ -140,6 +161,16 @@ ConfigSettings DeviceConfig::getSettings() { return settings; } +void DeviceConfig::setRigIF(int rigType, long long freq) { + rigIF[rigType] = freq; +} + +long long DeviceConfig::getRigIF(int rigType) { + if (rigIF.find(rigType) != rigIF.end()) { + return rigIF[rigType]; + } + return 0; +} AppConfig::AppConfig() : configName("") { winX.store(0); diff --git a/src/AppConfig.h b/src/AppConfig.h index 0306dea..b7e7f7c 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -35,6 +35,9 @@ public: void setSetting(std::string key, std::string value); std::string getSetting(std::string key, std::string defaultValue); + void setRigIF(int rigType, long long freq); + long long getRigIF(int rigType); + void save(DataNode *node); void load(DataNode *node); @@ -46,6 +49,7 @@ private: std::atomic_llong offset; ConfigSettings streamOpts; std::map settings; + std::map rigIF; }; class AppConfig { diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 9e5f69e..e2e78ae 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -417,11 +417,13 @@ AppFrame::AppFrame() : rigModel = wxGetApp().getConfig()->getRigModel(); rigSerialRate = wxGetApp().getConfig()->getRigRate(); rigPort = wxGetApp().getConfig()->getRigPort(); - + rigMenu = new wxMenu; rigEnableMenuItem = rigMenu->AppendCheckItem(wxID_RIG_TOGGLE, wxT("Enable Rig")); + rigMenu->Append(wxID_RIG_SDR_IF, wxT("SDR-IF")); + wxMenu *rigModelMenu = new wxMenu; RigList &rl = RigThread::enumerate(); numRigs = rl.size(); @@ -435,7 +437,7 @@ AppFrame::AppFrame() : rigModelMenuItems[(*ri)->rig_model] = rigModelMenu->AppendRadioItem(modelMenuId, modelString, wxT("Description?")); if (rigModel == (*ri)->rig_model) { - rigModelMenuItems[(*ri)->rig_model]->Check(); + rigModelMenuItems[(*ri)->rig_model]->Check(true); } modelMenuId++; @@ -465,7 +467,7 @@ AppFrame::AppFrame() : rigSerialMenuItems[(*rate_i)] = rigSerialMenu->AppendRadioItem(rateMenuId, rateString, wxT("Description?")); if (rigSerialRate == (*rate_i)) { - rigSerialMenuItems[(*rate_i)]->Check(); + rigSerialMenuItems[(*rate_i)]->Check(true); } rateMenuId++; @@ -590,7 +592,7 @@ void AppFrame::updateDeviceParams() { } wxMenuItem *item = subMenu->AppendRadioItem(wxID_SETTINGS_BASE+i, displayName); if (currentVal == (*str_i)) { - item->Check(); + item->Check(true); } j++; i++; @@ -648,6 +650,21 @@ void AppFrame::updateDeviceParams() { agcMenuItem->Check(wxGetApp().getAGCMode()); + +#if USE_HAMLIB + std::string deviceId = devInfo->getDeviceId(); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId); + + if (wxGetApp().rigIsActive()) { + rigSDRIF = devConfig->getRigIF(rigModel); + if (rigSDRIF) { + wxGetApp().lockFrequency(rigSDRIF); + } else { + wxGetApp().unlockFrequency(); + } + } +#endif + deviceChanged.store(false); } @@ -681,7 +698,7 @@ void AppFrame::OnMenu(wxCommandEvent& event) { // iqSwapMenuItem->Check(swap_state); } else if (event.GetId() == wxID_AGC_CONTROL) { if (wxGetApp().getDevice() == NULL) { - agcMenuItem->Check(); + agcMenuItem->Check(true); return; } if (!wxGetApp().getAGCMode()) { @@ -891,11 +908,24 @@ void AppFrame::OnMenu(wxCommandEvent& event) { } #ifdef USE_HAMLIB + bool resetRig = false; if (event.GetId() >= wxID_RIG_MODEL_BASE && event.GetId() < wxID_RIG_MODEL_BASE+numRigs) { int rigIdx = event.GetId()-wxID_RIG_MODEL_BASE; RigList &rl = RigThread::enumerate(); rigModel = rl[rigIdx]->rig_model; + if (devInfo != nullptr) { + std::string deviceId = devInfo->getDeviceId(); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId); + rigSDRIF = devConfig->getRigIF(rigModel); + if (rigSDRIF) { + wxGetApp().lockFrequency(rigSDRIF); + } else { + wxGetApp().unlockFrequency(); + } + } else { + wxGetApp().unlockFrequency(); + } resetRig = true; } @@ -919,8 +949,39 @@ void AppFrame::OnMenu(wxCommandEvent& event) { if (!wxGetApp().rigIsActive()) { wxGetApp().stopRig(); wxGetApp().initRig(rigModel, rigPort, rigSerialRate); + + if (devInfo != nullptr) { + std::string deviceId = devInfo->getDeviceId(); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId); + rigSDRIF = devConfig->getRigIF(rigModel); + if (rigSDRIF) { + wxGetApp().lockFrequency(rigSDRIF); + } else { + wxGetApp().unlockFrequency(); + } + } else { + wxGetApp().unlockFrequency(); + } } else { wxGetApp().stopRig(); + wxGetApp().unlockFrequency(); + } + } + + if (event.GetId() == wxID_RIG_SDR_IF) { + if (devInfo != nullptr) { + std::string deviceId = devInfo->getDeviceId(); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId); + long long freqRigIF = wxGetNumberFromUser("Rig SDR-IF Frequency", "Frequency (Hz)", "Frequency", devConfig->getRigIF(rigModel), 0, 2000000000); + if (freqRigIF != -1) { + rigSDRIF = freqRigIF; + devConfig->setRigIF(rigModel, rigSDRIF); + } + if (rigSDRIF && wxGetApp().rigIsActive()) { + wxGetApp().lockFrequency(rigSDRIF); + } else { + wxGetApp().unlockFrequency(); + } } } diff --git a/src/AppFrame.h b/src/AppFrame.h index 6076c1e..3ebe09a 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -56,6 +56,7 @@ #ifdef USE_HAMLIB #define wxID_RIG_TOGGLE 11900 #define wxID_RIG_PORT 11901 +#define wxID_RIG_SDR_IF 11902 #define wxID_RIG_SERIAL_BASE 11950 #define wxID_RIG_MODEL_BASE 12000 #endif @@ -140,10 +141,12 @@ private: wxMenu *rigMenu; wxMenuItem *rigEnableMenuItem; wxMenuItem *rigPortMenuItem; + wxMenuItem *sdrIFMenuItem; std::map rigSerialMenuItems; std::map rigModelMenuItems; int rigModel; int rigSerialRate; + long long rigSDRIF; std::vector rigSerialRates; std::string rigPort; int numRigs;