diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index 9b057ee..9ef00b5 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -114,7 +114,7 @@ void DeviceConfig::load(DataNode *node) { busy_lock.unlock(); } -AppConfig::AppConfig() { +AppConfig::AppConfig() : configName("") { winX.store(0); winY.store(0); winW.store(0); @@ -195,6 +195,27 @@ long long AppConfig::getSnap() { return snap.load(); } +void AppConfig::setConfigName(std::string configName) { + this->configName = configName; +} + +std::string AppConfig::getConfigFileName() { + std::string cfgFileDir = getConfigDir(); + + wxFileName cfgFile; + if (configName.length()) { + std::string tempFn("config-"); + tempFn.append(configName); + tempFn.append(".xml"); + cfgFile = wxFileName(cfgFileDir, tempFn); + } else { + cfgFile = wxFileName(cfgFileDir, "config.xml"); + } + + std::string cfgFileName = cfgFile.GetFullPath(wxPATH_NATIVE).ToStdString(); + + return cfgFileName; +} bool AppConfig::save() { DataTree cfg; @@ -221,13 +242,9 @@ bool AppConfig::save() { DataNode *device_node = devices_node->newChild("device"); device_config_i->second->save(device_node); } - - std::string cfgFileDir = getConfigDir(); - - wxFileName cfgFile = wxFileName(cfgFileDir, "config.xml"); - std::string cfgFileName = cfgFile.GetFullPath(wxPATH_NATIVE).ToStdString(); - + std::string cfgFileName = getConfigFileName(); + if (!cfg.SaveToFileXML(cfgFileName)) { std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl; return false; @@ -240,8 +257,8 @@ bool AppConfig::load() { DataTree cfg; std::string cfgFileDir = getConfigDir(); - wxFileName cfgFile = wxFileName(cfgFileDir, "config.xml"); - std::string cfgFileName = cfgFile.GetFullPath(wxPATH_NATIVE).ToStdString(); + std::string cfgFileName = getConfigFileName(); + wxFileName cfgFile = wxFileName(cfgFileName); if (!cfgFile.Exists()) { return true; diff --git a/src/AppConfig.h b/src/AppConfig.h index 9d13f49..2b12f31 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -59,11 +59,14 @@ public: void setSnap(long long snapVal); long long getSnap(); + void setConfigName(std::string configName); + std::string getConfigFileName(); bool save(); bool load(); bool reset(); private: + std::string configName; std::map deviceConfig; std::atomic_int winX,winY,winW,winH; std::atomic_bool winMax; diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 1fa1e54..1b88058 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -40,8 +40,6 @@ bool CubicSDR::OnInit() { wxApp::SetAppName("CubicSDR"); - config.load(); - frequency = DEFAULT_FREQ; offset = 0; ppm = 0; @@ -171,6 +169,24 @@ PrimaryGLContext& CubicSDR::GetContext(wxGLCanvas *canvas) { return *glContext; } +void CubicSDR::OnInitCmdLine(wxCmdLineParser& parser) { + parser.SetDesc (commandLineInfo); + parser.SetSwitchChars (wxT("-")); +} + +bool CubicSDR::OnCmdLineParsed(wxCmdLineParser& parser) { + wxString *confName = new wxString; + if (parser.Found("c",confName)) { + if (confName) { + config.setConfigName(confName->ToStdString()); + } + } + + config.load(); + + return true; +} + void CubicSDR::setFrequency(long long freq) { if (freq < sampleRate / 2) { freq = sampleRate / 2; diff --git a/src/CubicSDR.h b/src/CubicSDR.h index fb9027b..909c65b 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -17,6 +17,8 @@ #include "AppConfig.h" #include "AppFrame.h" +#include + #define NUM_DEMODULATORS 1 class CubicSDR: public wxApp { @@ -31,6 +33,9 @@ public: virtual bool OnInit(); virtual int OnExit(); + virtual void OnInitCmdLine(wxCmdLineParser& parser); + virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + void setFrequency(long long freq); long long getFrequency(); @@ -94,4 +99,11 @@ private: std::thread *t_PostSDR; }; +static const wxCmdLineEntryDesc commandLineInfo [] = +{ + { wxCMD_LINE_SWITCH, "h", "help", "Command line parameter help", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_OPTION, "c", "config", "Specify a named configuration to use, i.e. '-c ham'" }, + { wxCMD_LINE_NONE } +}; + DECLARE_APP(CubicSDR)