From 3f5ffc7aaad6d3fb7995e5058493c120b93b8b49 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 15 Feb 2016 13:04:18 -0500 Subject: [PATCH] Better handling of hamlib disconnect / errors --- src/AppFrame.cpp | 8 ++++++++ src/rig/RigThread.cpp | 39 ++++++++++++++++++++++++++------------- src/rig/RigThread.h | 4 +++- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index ee8cf3e..97239a4 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -1299,6 +1299,14 @@ void AppFrame::OnIdle(wxIdleEvent& event) { peakHoldButton->clearModeChanged(); } +#if USE_HAMLIB + if (rigEnableMenuItem->IsChecked()) { + if (!wxGetApp().rigIsActive()) { + rigEnableMenuItem->Check(false); + } + } +#endif + if (!this->IsActive()) { std::this_thread::sleep_for(std::chrono::milliseconds(25)); } else { diff --git a/src/rig/RigThread.cpp b/src/rig/RigThread.cpp index 2b0c595..bc21ac1 100644 --- a/src/rig/RigThread.cpp +++ b/src/rig/RigThread.cpp @@ -7,6 +7,7 @@ RigThread::RigThread() { freq = wxGetApp().getFrequency(); newFreq = freq; freqChanged.store(true); + termStatus = 0; } RigThread::~RigThread() { @@ -40,6 +41,8 @@ void RigThread::initRig(rig_model_t rig_model, std::string rig_file, int serial_ void RigThread::run() { int retcode, status; + termStatus = 0; + std::cout << "Rig thread starting." << std::endl; rig = rig_init(rigModel); @@ -65,24 +68,34 @@ void RigThread::run() { std::this_thread::sleep_for(std::chrono::milliseconds(150)); if (freqChanged.load()) { status = rig_get_freq(rig, RIG_VFO_CURR, &freq); - if (freq != newFreq) { - freq = newFreq; - rig_set_freq(rig, RIG_VFO_CURR, freq); -// std::cout << "Set Rig Freq: %f" << newFreq << std::endl; + if (status == 0) { + if (freq != newFreq) { + freq = newFreq; + rig_set_freq(rig, RIG_VFO_CURR, freq); + // std::cout << "Set Rig Freq: %f" << newFreq << std::endl; + } + + freqChanged.store(false); + } else { + termStatus = 0; + terminate(); } - - freqChanged.store(false); } else { freq_t checkFreq; status = rig_get_freq(rig, RIG_VFO_CURR, &checkFreq); - if (checkFreq != freq) { - freq = checkFreq; - wxGetApp().setFrequency((long long)checkFreq); - } else if (wxGetApp().getFrequency() != freq) { - freq = wxGetApp().getFrequency(); - rig_set_freq(rig, RIG_VFO_CURR, freq); + if (status == 0) { + if (checkFreq != freq) { + freq = checkFreq; + wxGetApp().setFrequency((long long)checkFreq); + } else if (wxGetApp().getFrequency() != freq) { + freq = wxGetApp().getFrequency(); + rig_set_freq(rig, RIG_VFO_CURR, freq); + } + } else { + termStatus = 0; + terminate(); } } @@ -92,7 +105,7 @@ void RigThread::run() { rig_close(rig); rig_cleanup(rig); - std::cout << "Rig thread exiting." << std::endl; + std::cout << "Rig thread exiting status " << termStatus << "." << std::endl; }; freq_t RigThread::getFrequency() { diff --git a/src/rig/RigThread.h b/src/rig/RigThread.h index 9d6d80d..d161640 100644 --- a/src/rig/RigThread.h +++ b/src/rig/RigThread.h @@ -24,6 +24,8 @@ public: void initRig(rig_model_t rig_model, std::string rig_file, int serial_rate); void run(); + int terminationStatus(); + freq_t getFrequency(); void setFrequency(freq_t new_freq); @@ -35,7 +37,7 @@ private: rig_model_t rigModel; std::string rigFile; int serialRate; - + int termStatus; freq_t freq; freq_t newFreq; std::atomic_bool freqChanged;