Better handling of hamlib disconnect / errors

This commit is contained in:
Charles J. Cliffe 2016-02-15 13:04:18 -05:00
parent 75fc82b9ae
commit 3f5ffc7aaa
3 changed files with 37 additions and 14 deletions

View File

@ -1299,6 +1299,14 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
peakHoldButton->clearModeChanged(); peakHoldButton->clearModeChanged();
} }
#if USE_HAMLIB
if (rigEnableMenuItem->IsChecked()) {
if (!wxGetApp().rigIsActive()) {
rigEnableMenuItem->Check(false);
}
}
#endif
if (!this->IsActive()) { if (!this->IsActive()) {
std::this_thread::sleep_for(std::chrono::milliseconds(25)); std::this_thread::sleep_for(std::chrono::milliseconds(25));
} else { } else {

View File

@ -7,6 +7,7 @@ RigThread::RigThread() {
freq = wxGetApp().getFrequency(); freq = wxGetApp().getFrequency();
newFreq = freq; newFreq = freq;
freqChanged.store(true); freqChanged.store(true);
termStatus = 0;
} }
RigThread::~RigThread() { RigThread::~RigThread() {
@ -40,6 +41,8 @@ void RigThread::initRig(rig_model_t rig_model, std::string rig_file, int serial_
void RigThread::run() { void RigThread::run() {
int retcode, status; int retcode, status;
termStatus = 0;
std::cout << "Rig thread starting." << std::endl; std::cout << "Rig thread starting." << std::endl;
rig = rig_init(rigModel); rig = rig_init(rigModel);
@ -65,24 +68,34 @@ void RigThread::run() {
std::this_thread::sleep_for(std::chrono::milliseconds(150)); std::this_thread::sleep_for(std::chrono::milliseconds(150));
if (freqChanged.load()) { if (freqChanged.load()) {
status = rig_get_freq(rig, RIG_VFO_CURR, &freq); status = rig_get_freq(rig, RIG_VFO_CURR, &freq);
if (freq != newFreq) { if (status == 0) {
freq = newFreq; if (freq != newFreq) {
rig_set_freq(rig, RIG_VFO_CURR, freq); freq = newFreq;
// std::cout << "Set Rig Freq: %f" << newFreq << std::endl; 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 { } else {
freq_t checkFreq; freq_t checkFreq;
status = rig_get_freq(rig, RIG_VFO_CURR, &checkFreq); status = rig_get_freq(rig, RIG_VFO_CURR, &checkFreq);
if (checkFreq != freq) { if (status == 0) {
freq = checkFreq; if (checkFreq != freq) {
wxGetApp().setFrequency((long long)checkFreq); freq = checkFreq;
} else if (wxGetApp().getFrequency() != freq) { wxGetApp().setFrequency((long long)checkFreq);
freq = wxGetApp().getFrequency(); } else if (wxGetApp().getFrequency() != freq) {
rig_set_freq(rig, RIG_VFO_CURR, 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_close(rig);
rig_cleanup(rig); rig_cleanup(rig);
std::cout << "Rig thread exiting." << std::endl; std::cout << "Rig thread exiting status " << termStatus << "." << std::endl;
}; };
freq_t RigThread::getFrequency() { freq_t RigThread::getFrequency() {

View File

@ -24,6 +24,8 @@ public:
void initRig(rig_model_t rig_model, std::string rig_file, int serial_rate); void initRig(rig_model_t rig_model, std::string rig_file, int serial_rate);
void run(); void run();
int terminationStatus();
freq_t getFrequency(); freq_t getFrequency();
void setFrequency(freq_t new_freq); void setFrequency(freq_t new_freq);
@ -35,7 +37,7 @@ private:
rig_model_t rigModel; rig_model_t rigModel;
std::string rigFile; std::string rigFile;
int serialRate; int serialRate;
int termStatus;
freq_t freq; freq_t freq;
freq_t newFreq; freq_t newFreq;
std::atomic_bool freqChanged; std::atomic_bool freqChanged;