Per-Rig-Per-SDR IF frequency lock control and save/load

This commit is contained in:
Charles J. Cliffe 2016-01-09 00:09:46 -05:00
parent 1699c50676
commit 936a640328
4 changed files with 104 additions and 5 deletions

View File

@ -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<int, long long>::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);

View File

@ -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<std::string, std::string> settings;
std::map<int, long long> rigIF;
};
class AppConfig {

View File

@ -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();
}
}
}

View File

@ -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<int, wxMenuItem *> rigSerialMenuItems;
std::map<int, wxMenuItem *> rigModelMenuItems;
int rigModel;
int rigSerialRate;
long long rigSDRIF;
std::vector<int> rigSerialRates;
std::string rigPort;
int numRigs;