From: drowe67 Date: Sun, 9 Jul 2017 22:38:36 +0000 (+0000) Subject: reporting hamlib errors to dialog box X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=72410d0f3cff20636f295d0bb4c9ebf7c4993c0d;p=freetel-svn-tracking.git reporting hamlib errors to dialog box git-svn-id: https://svn.code.sf.net/p/freetel/code@3287 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freedv-dev/src/dlg_ptt.cpp b/freedv-dev/src/dlg_ptt.cpp index 7edc1453..d50a1e8b 100644 --- a/freedv-dev/src/dlg_ptt.cpp +++ b/freedv-dev/src/dlg_ptt.cpp @@ -287,8 +287,7 @@ void ComPortsDlg::populatePortList() /* populate Hamlib serial rate combo box */ - wxString serialRates[] = {"auto", "300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"}; - fprintf(stderr, "populating serial rates...\n"); + wxString serialRates[] = {"default", "300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"}; for(int i=0; iAppend(serialRates[i]); } @@ -460,13 +459,13 @@ void ComPortsDlg::ExchangeData(int inout) wxGetApp().m_strHamlibSerialPort = m_cbSerialPort->GetValue(); wxString s = m_cbSerialRate->GetValue(); - if (s == "auto") { + if (s == "default") { wxGetApp().m_intHamlibSerialRate = 0; } else { m_cbSerialRate->GetValue().ToLong(&tmp); wxGetApp().m_intHamlibSerialRate = tmp; } - fprintf(stderr, "serial rate: %ld\n", tmp); + 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); diff --git a/freedv-dev/src/fdmdv2_main.cpp b/freedv-dev/src/fdmdv2_main.cpp index e4f6f3eb..77e1dc26 100644 --- a/freedv-dev/src/fdmdv2_main.cpp +++ b/freedv-dev/src/fdmdv2_main.cpp @@ -1630,8 +1630,11 @@ void MainFrame::togglePTT(void) { if (wxGetApp().m_boolHamlibUseForPTT) { Hamlib *hamlib = wxGetApp().m_hamlib; + wxString hamlibError; if (wxGetApp().m_boolHamlibUseForPTT && hamlib != NULL) { - hamlib->ptt(g_tx); + if (hamlib->ptt(g_tx, hamlibError) == false) { + wxMessageBox(wxString("Hamlib PTT Error: ") + hamlibError, wxT("Error"), wxOK | wxICON_ERROR, this); + } } } @@ -2435,7 +2438,7 @@ bool MainFrame::OpenHamlibRig() { int serial_rate = wxGetApp().m_intHamlibSerialRate; bool status = wxGetApp().m_hamlib->connect(rig, port.mb_str(wxConvUTF8), serial_rate); if (status == false) - wxMessageBox("Couldn't connect to Radio with hamlib", wxT("About"), wxOK | wxICON_ERROR, this); + wxMessageBox("Couldn't connect to Radio with hamlib", wxT("Error"), wxOK | wxICON_ERROR, this); return status; } @@ -2630,8 +2633,11 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) if (wxGetApp().m_boolHamlibUseForPTT) { Hamlib *hamlib = wxGetApp().m_hamlib; + wxString hamlibError; if (wxGetApp().m_boolHamlibUseForPTT && hamlib != NULL) { - hamlib->ptt(false); + if (hamlib->ptt(false, hamlibError) == false) { + wxMessageBox(wxString("Hamlib PTT Error: ") + hamlibError, wxT("Error"), wxOK | wxICON_ERROR, this); + } hamlib->close(); } } @@ -4073,8 +4079,7 @@ void MainFrame::CloseSerialPort(void) // always end with PTT in rx state SerialPTTRx(); - - closeComPort(); + closeComPort(); } } diff --git a/freedv-dev/src/hamlib.cpp b/freedv-dev/src/hamlib.cpp index 17c9176a..4a625606 100644 --- a/freedv-dev/src/hamlib.cpp +++ b/freedv-dev/src/hamlib.cpp @@ -106,8 +106,8 @@ bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int strncpy(m_rig->state.rigport.pathname, serial_port, FILPATHLEN - 1); if (serial_rate) { m_rig->state.rigport.parm.serial.rate = serial_rate; - fprintf(stderr, "hamlib: setting serial rate: %d\n", serial_rate); } + fprintf(stderr, "hamlib: setting serial rate: %d\n", m_rig->state.rigport.parm.serial.rate); /* token_t token = rig_token_lookup(m_rig, "rig_pathname"); @@ -123,17 +123,27 @@ bool Hamlib::connect(unsigned int rig_index, const char *serial_port, const int return false; } -bool Hamlib::ptt(bool press) { +bool Hamlib::ptt(bool press, wxString &hamlibError) { fprintf(stderr,"Hamlib::ptt: %d\n", press); + hamlibError = ""; if(!m_rig) return false; + /* TODO(Joel): make ON_DATA and ON configurable. */ + ptt_t on = press ? RIG_PTT_ON : RIG_PTT_OFF; + /* TODO(Joel): what should the VFO option be? */ - int status = rig_set_ptt(m_rig, RIG_VFO_CURR, on) == RIG_OK; - fprintf(stderr,"Hamlib::ptt: rig_set_ptt returned: %d\n", status); - return status; + + int retcode = rig_set_ptt(m_rig, RIG_VFO_CURR, on); + fprintf(stderr,"Hamlib::ptt: rig_set_ptt returned: %d\n", retcode); + if (retcode != RIG_OK ) { + fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(retcode)); + hamlibError = rigerror(retcode); + } + + return retcode == RIG_OK; } void Hamlib::close(void) { diff --git a/freedv-dev/src/hamlib.h b/freedv-dev/src/hamlib.h index cf5f34f7..3ce7e8b5 100644 --- a/freedv-dev/src/hamlib.h +++ b/freedv-dev/src/hamlib.h @@ -14,7 +14,7 @@ class Hamlib { ~Hamlib(); void populateComboBox(wxComboBox *cb); bool connect(unsigned int rig_index, const char *serial_port, const int serial_rate); - bool ptt(bool press); + bool ptt(bool press, wxString &hamlibError); void close(void); typedef std::vector riglist_t;