Save rig names instead of rig IDs.

pull/256/head
Mooneer Salem 2022-07-08 23:06:17 -07:00
parent a612cdc79a
commit 24d03a6a3f
5 changed files with 53 additions and 3 deletions

View File

@ -463,6 +463,10 @@ void ComPortsDlg::ExchangeData(int inout)
wxGetApp().m_boolHamlibUseForPTT = m_ckUseHamlibPTT->GetValue();
wxGetApp().m_intHamlibRig = m_cbRigName->GetSelection();
Hamlib *hamlib = wxGetApp().m_hamlib;
wxGetApp().m_strHamlibRigName = hamlib->rigIndexToName(wxGetApp().m_intHamlibRig);
wxGetApp().m_strHamlibSerialPort = m_cbSerialPort->GetValue();
wxString s = m_tcIcomCIVHex->GetValue();
@ -481,7 +485,7 @@ void ComPortsDlg::ExchangeData(int inout)
if (g_verbose) fprintf(stderr, "serial rate: %d\n", wxGetApp().m_intHamlibSerialRate);
pConfig->Write(wxT("/Hamlib/UseForPTT"), wxGetApp().m_boolHamlibUseForPTT);
pConfig->Write(wxT("/Hamlib/RigName"), wxGetApp().m_intHamlibRig);
pConfig->Write(wxT("/Hamlib/RigNameStr"), wxGetApp().m_strHamlibRigName);
pConfig->Write(wxT("/Hamlib/SerialPort"), wxGetApp().m_strHamlibSerialPort);
pConfig->Write(wxT("/Hamlib/SerialRate"), wxGetApp().m_intHamlibSerialRate);

View File

@ -84,6 +84,32 @@ static bool rig_cmp(const struct rig_caps *rig1, const struct rig_caps *rig2) {
return rig1->rig_model < rig2->rig_model;
}
unsigned int Hamlib::rigNameToIndex(std::string rigName)
{
unsigned int index = 0;
for (auto& entry : m_rigList)
{
char name[128];
snprintf(name, 128, "%s %s", entry->mfg_name, entry->model_name);
if (rigName == std::string(name))
{
return index;
}
index++;
}
return -1;
}
std::string Hamlib::rigIndexToName(unsigned int rigIndex)
{
char name[128];
snprintf(name, 128, "%s %s", m_rigList[rigIndex]->mfg_name, m_rigList[rigIndex]->model_name);
return name;
}
freq_t Hamlib::get_frequency(void) const
{
return m_currFreq;

View File

@ -13,6 +13,11 @@ class Hamlib {
public:
Hamlib();
~Hamlib();
// Name to index lookup and vice versa.
unsigned int rigNameToIndex(std::string rigName);
std::string rigIndexToName(unsigned int rigIndex);
void populateComboBox(wxComboBox *cb);
bool connect(unsigned int rig_index, const char *serial_port, const int serial_rate, const int civ_hex = 0);
bool ptt(bool press, wxString &hamlibError);

View File

@ -325,7 +325,21 @@ void MainFrame::loadConfiguration_()
wxGetApp().m_boolHamlibUseForPTT = pConfig->ReadBool("/Hamlib/UseForPTT", false);
wxGetApp().m_intHamlibIcomCIVHex = pConfig->ReadLong("/Hamlib/IcomCIVHex", 0);
wxGetApp().m_intHamlibRig = pConfig->ReadLong("/Hamlib/RigName", 0);
// Note: we're no longer using RigName but we need to bring over the old data
// for backwards compatibility.
wxGetApp().m_strHamlibRigName = pConfig->Read(wxT("/Hamlib/RigNameStr"), wxT(""));
if (wxGetApp().m_strHamlibRigName == wxT(""))
{
wxGetApp().m_intHamlibRig = pConfig->ReadLong("/Hamlib/RigName", 0);
wxGetApp().m_strHamlibRigName = wxGetApp().m_hamlib->rigIndexToName(wxGetApp().m_intHamlibRig);
}
else
{
wxGetApp().m_intHamlibRig = wxGetApp().m_hamlib->rigNameToIndex(std::string(wxGetApp().m_strHamlibRigName.ToUTF8()));
}
wxGetApp().m_strHamlibSerialPort = pConfig->Read("/Hamlib/SerialPort", "");
wxGetApp().m_intHamlibSerialRate = pConfig->ReadLong("/Hamlib/SerialRate", 0);
@ -718,7 +732,7 @@ MainFrame::~MainFrame()
pConfig->Write(wxT("/Rig/SingleRxThread"), wxGetApp().m_boolSingleRxThread);
pConfig->Write(wxT("/Rig/leftChannelVoxTone"), wxGetApp().m_leftChannelVoxTone);
pConfig->Write("/Hamlib/UseForPTT", wxGetApp().m_boolHamlibUseForPTT);
pConfig->Write("/Hamlib/RigName", wxGetApp().m_intHamlibRig);
pConfig->Write("/Hamlib/RigNameStr", wxGetApp().m_strHamlibRigName);
pConfig->Write("/Hamlib/SerialPort", wxGetApp().m_strHamlibSerialPort);
pConfig->Write("/Hamlib/SerialRate", wxGetApp().m_intHamlibSerialRate);
pConfig->Write("/Hamlib/IcomCIVHex", wxGetApp().m_intHamlibIcomCIVHex);

View File

@ -198,6 +198,7 @@ class MainApp : public wxApp
bool m_boolHamlibUseForPTT;
unsigned int m_intHamlibRig;
wxString m_strHamlibRigName;
wxString m_strHamlibSerialPort;
unsigned int m_intHamlibSerialRate;
unsigned int m_intHamlibIcomCIVHex;