reporting hamlib errors to dialog box
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 9 Jul 2017 22:38:36 +0000 (22:38 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 9 Jul 2017 22:38:36 +0000 (22:38 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3287 01035d8c-6547-0410-b346-abe4f91aad63

freedv-dev/src/dlg_ptt.cpp
freedv-dev/src/fdmdv2_main.cpp
freedv-dev/src/hamlib.cpp
freedv-dev/src/hamlib.h

index 7edc14530d0d9fd9bc559c11f857903c737fc974..d50a1e8b2651eeed2781325c3cad31cd49a0dbef 100644 (file)
@@ -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; i<WXSIZEOF(serialRates); i++) {
         m_cbSerialRate->Append(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);
index e4f6f3ebc6a2657d5e630d4525945b721f0544cb..77e1dc26d40c7582dfea6f85cca72bf26fec9e85 100644 (file)
@@ -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();
     }
 }
 
index 17c9176aec12e619492d14614ade619e6ddf3c0d..4a625606c88fed00056c320d143864ffe73cea93 100644 (file)
@@ -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) {
index cf5f34f777d127d8f5d212b58c8f4fb201edc91d..3ce7e8b56cb7996e42d8012438649dab76f70dfd 100644 (file)
@@ -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<const struct rig_caps *> riglist_t;