Add configuration name at command line via -c or --config
sets up framework for more command line options as well.
This commit is contained in:
parent
d3dee2b184
commit
13139c7dbf
|
@ -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;
|
||||
|
|
|
@ -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<std::string, DeviceConfig *> deviceConfig;
|
||||
std::atomic_int winX,winY,winW,winH;
|
||||
std::atomic_bool winMax;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "AppConfig.h"
|
||||
#include "AppFrame.h"
|
||||
|
||||
#include <wx/cmdline.h>
|
||||
|
||||
#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)
|
||||
|
|
Loading…
Reference in New Issue