Report "unk" for mode on Hamlib disconnect (#851)

* Add missed Hamlib call to disconnect event.

* Clean up duplicated freq/mode event code.

* Clean up duplicated connect/disconnect logic.

* Add PR #851 to changelog.

* Fix typo

* Fix compiler errors for real.
ms-dns-warn
Mooneer Salem 2025-03-26 16:28:34 -07:00 committed by GitHub
parent ed24f932ec
commit 9d618d4719
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 137 additions and 204 deletions

View File

@ -901,6 +901,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
* Fix issue preventing suppression of the Msg tooltip for non-truncated messages. (PR #829) * Fix issue preventing suppression of the Msg tooltip for non-truncated messages. (PR #829)
* Preserve Hamlib rig names on startup to guard against changes by Hamlib during execution. (PR #834) * Preserve Hamlib rig names on startup to guard against changes by Hamlib during execution. (PR #834)
* Fix dropouts related to virtual audio cables. (PR #840) * Fix dropouts related to virtual audio cables. (PR #840)
* Report "unk" for mode on Hamlib disconnect. (PR #851)
2. Enhancements: 2. Enhancements:
* Show green line indicating RX frequency. (PR #725) * Show green line indicating RX frequency. (PR #725)
* Update configuration of the Voice Keyer feature based on user feedback. (PR #730, #746, #793) * Update configuration of the Voice Keyer feature based on user feedback. (PR #730, #746, #793)

View File

@ -518,6 +518,10 @@ class MainFrame : public TopFrame
void updateReportingFreqList_(); void updateReportingFreqList_();
void initializeFreeDVReporter_(); void initializeFreeDVReporter_();
void onFrequencyModeChange_(IRigFrequencyController*, uint64_t freq, IRigFrequencyController::Mode mode);
void onRadioConnected_(IRigController* ptr);
void onRadioDisconnected_(IRigController* ptr);
}; };
void resample_for_plot(struct FIFO *plotFifo, short buf[], int length, int fs); void resample_for_plot(struct FIFO *plotFifo, short buf[], int length, int fs);

View File

@ -375,6 +375,124 @@ void MainFrame::OnHelpAbout(wxCommandEvent& event)
wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this); wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this);
} }
void MainFrame::onFrequencyModeChange_(IRigFrequencyController*, uint64_t freq, IRigFrequencyController::Mode mode)
{
CallAfter([&, mode, freq]() {
if (firstFreqUpdateOnConnect_)
{
firstFreqUpdateOnConnect_ = false;
return;
}
// Update string value.
switch(mode)
{
case IRigFrequencyController::USB:
m_txtModeStatus->SetLabel(wxT("USB"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGU:
m_txtModeStatus->SetLabel(wxT("USB-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::LSB:
m_txtModeStatus->SetLabel(wxT("LSB"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGL:
m_txtModeStatus->SetLabel(wxT("LSB-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::FM:
m_txtModeStatus->SetLabel(wxT("FM"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGFM:
m_txtModeStatus->SetLabel(wxT("FM-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::AM:
m_txtModeStatus->SetLabel(wxT("AM"));
m_txtModeStatus->Enable(true);
break;
default:
m_txtModeStatus->SetLabel(wxT("unk"));
m_txtModeStatus->Enable(false);
break;
}
// Widest 60 meter allocation is 5.250-5.450 MHz per https://en.wikipedia.org/wiki/60-meter_band.
bool is60MeterBand = freq >= 5250000 && freq <= 5450000;
// Update color based on the mode and current frequency.
bool isUsbFreq = freq >= 10000000 || is60MeterBand;
bool isLsbFreq = freq < 10000000 && !is60MeterBand;
bool isMatchingMode =
(isUsbFreq && (mode == IRigFrequencyController::USB || mode == IRigFrequencyController::DIGU)) ||
(isLsbFreq && (mode == IRigFrequencyController::LSB || mode == IRigFrequencyController::DIGL));
if (isMatchingMode)
{
m_txtModeStatus->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
}
else
{
m_txtModeStatus->SetForegroundColour(wxColor(*wxRED));
}
// Update frequency box
if (!suppressFreqModeUpdates_ && (
!wxGetApp().appConfiguration.reportingConfiguration.reportingEnabled ||
!wxGetApp().appConfiguration.reportingConfiguration.manualFrequencyReporting))
{
// wxString::Format() doesn't respect locale but C++ iomanip should. Use the latter instead.
std::stringstream ss;
std::locale loc("");
ss.imbue(loc);
if (wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz)
{
ss << std::fixed << std::setprecision(1) << (freq / 1000.0);
}
else
{
ss << std::fixed << std::setprecision(4) << (freq / 1000.0 / 1000.0);
}
m_cboReportFrequency->SetValue(ss.str());
}
m_txtModeStatus->Refresh();
});
}
void MainFrame::onRadioConnected_(IRigController* ptr)
{
if (wxGetApp().rigFrequencyController &&
(wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges || wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqChangesOnly) &&
wxGetApp().appConfiguration.reportingConfiguration.reportingFrequency > 0)
{
// Suppress the frequency update message that will occur immediately after
// connect; this will prevent overwriting of whatever's in the text box.
firstFreqUpdateOnConnect_ = true;
// Set frequency/mode to the one pre-selected by the user before start.
wxGetApp().rigFrequencyController->setFrequency(wxGetApp().appConfiguration.reportingConfiguration.reportingFrequency);
if (wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges)
{
wxGetApp().rigFrequencyController->setMode(getCurrentMode_());
}
}
}
void MainFrame::onRadioDisconnected_(IRigController* ptr)
{
CallAfter([&]() {
m_txtModeStatus->SetLabel(wxT("unk"));
m_txtModeStatus->Enable(false);
});
}
// Attempt to talk to rig using Hamlib // Attempt to talk to rig using Hamlib
@ -412,123 +530,17 @@ bool MainFrame::OpenHamlibRig() {
}); });
}; };
wxGetApp().rigFrequencyController->onRigConnected += [&](IRigController*) { wxGetApp().rigFrequencyController->onRigConnected += [&](IRigController* ptr) {
if (wxGetApp().rigFrequencyController && onRadioConnected_(ptr);
(wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges || wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqChangesOnly) &&
wxGetApp().appConfiguration.reportingConfiguration.reportingFrequency > 0)
{
// Suppress the frequency update message that will occur immediately after
// connect; this will prevent overwriting of whatever's in the text box.
firstFreqUpdateOnConnect_ = true;
// Set frequency/mode to the one pre-selected by the user before start.
wxGetApp().rigFrequencyController->setFrequency(wxGetApp().appConfiguration.reportingConfiguration.reportingFrequency);
if (wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges)
{
wxGetApp().rigFrequencyController->setMode(getCurrentMode_());
}
}
}; };
wxGetApp().rigFrequencyController->onRigDisconnected += [&](IRigController*) { wxGetApp().rigFrequencyController->onRigDisconnected += [&](IRigController* ptr) {
CallAfter([&]() { onRadioDisconnected_(ptr);
m_txtModeStatus->SetLabel(wxT("unk"));
m_txtModeStatus->Enable(false);
});
}; };
wxGetApp().rigFrequencyController->onFreqModeChange += [&](IRigFrequencyController*, uint64_t freq, IRigFrequencyController::Mode mode) wxGetApp().rigFrequencyController->onFreqModeChange += [&](IRigFrequencyController* ptr, uint64_t freq, IRigFrequencyController::Mode mode) {
{ onFrequencyModeChange_(ptr, freq, mode);
CallAfter([&, mode, freq]() {
if (firstFreqUpdateOnConnect_)
{
firstFreqUpdateOnConnect_ = false;
return;
}
// Update string value.
switch(mode)
{
case IRigFrequencyController::USB:
m_txtModeStatus->SetLabel(wxT("USB"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGU:
m_txtModeStatus->SetLabel(wxT("USB-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::LSB:
m_txtModeStatus->SetLabel(wxT("LSB"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGL:
m_txtModeStatus->SetLabel(wxT("LSB-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::FM:
m_txtModeStatus->SetLabel(wxT("FM"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGFM:
m_txtModeStatus->SetLabel(wxT("FM-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::AM:
m_txtModeStatus->SetLabel(wxT("AM"));
m_txtModeStatus->Enable(true);
break;
default:
m_txtModeStatus->SetLabel(wxT("unk"));
m_txtModeStatus->Enable(false);
break;
}
// Widest 60 meter allocation is 5.250-5.450 MHz per https://en.wikipedia.org/wiki/60-meter_band.
bool is60MeterBand = freq >= 5250000 && freq <= 5450000;
// Update color based on the mode and current frequency.
bool isUsbFreq = freq >= 10000000 || is60MeterBand;
bool isLsbFreq = freq < 10000000 && !is60MeterBand;
bool isMatchingMode =
(isUsbFreq && (mode == IRigFrequencyController::USB || mode == IRigFrequencyController::DIGU)) ||
(isLsbFreq && (mode == IRigFrequencyController::LSB || mode == IRigFrequencyController::DIGL));
if (isMatchingMode)
{
m_txtModeStatus->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
}
else
{
m_txtModeStatus->SetForegroundColour(wxColor(*wxRED));
}
// Update frequency box
if (!suppressFreqModeUpdates_ && (
!wxGetApp().appConfiguration.reportingConfiguration.reportingEnabled ||
!wxGetApp().appConfiguration.reportingConfiguration.manualFrequencyReporting))
{
// wxString::Format() doesn't respect locale but C++ iomanip should. Use the latter instead.
std::stringstream ss;
std::locale loc("");
ss.imbue(loc);
if (wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz)
{
ss << std::fixed << std::setprecision(1) << (freq / 1000.0);
}
else
{
ss << std::fixed << std::setprecision(4) << (freq / 1000.0 / 1000.0);
}
m_cboReportFrequency->SetValue(ss.str());
}
m_txtModeStatus->Refresh();
});
}; };
wxGetApp().rigFrequencyController->connect(); wxGetApp().rigFrequencyController->connect();
return true; return true;
} }
@ -562,102 +574,16 @@ void MainFrame::OpenOmniRig()
}); });
}; };
wxGetApp().rigFrequencyController->onRigConnected += [&](IRigController*) { wxGetApp().rigFrequencyController->onRigConnected += [&](IRigController* ptr) {
if (wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges || wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqChangesOnly) onRadioConnected_(ptr);
{
wxGetApp().rigFrequencyController->setFrequency(wxGetApp().appConfiguration.reportingConfiguration.reportingFrequency);
if (wxGetApp().appConfiguration.rigControlConfiguration.hamlibEnableFreqModeChanges)
{
wxGetApp().rigFrequencyController->setMode(getCurrentMode_());
}
}
}; };
wxGetApp().rigFrequencyController->onRigDisconnected += [&](IRigController*) { wxGetApp().rigFrequencyController->onRigDisconnected += [&](IRigController* ptr) {
CallAfter([&]() { onRadioDisconnected_(ptr);
m_txtModeStatus->SetLabel(wxT("unk"));
m_txtModeStatus->Enable(false);
});
}; };
wxGetApp().rigFrequencyController->onFreqModeChange += [&](IRigFrequencyController*, uint64_t freq, IRigFrequencyController::Mode mode) wxGetApp().rigFrequencyController->onFreqModeChange += [&](IRigFrequencyController* ptr, uint64_t freq, IRigFrequencyController::Mode mode) {
{ onFrequencyModeChange_(ptr, freq, mode);
CallAfter([&, mode, freq]() {
// Update string value.
switch(mode)
{
case IRigFrequencyController::USB:
m_txtModeStatus->SetLabel(wxT("USB"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGU:
m_txtModeStatus->SetLabel(wxT("USB-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::LSB:
m_txtModeStatus->SetLabel(wxT("LSB"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGL:
m_txtModeStatus->SetLabel(wxT("LSB-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::FM:
m_txtModeStatus->SetLabel(wxT("FM"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::DIGFM:
m_txtModeStatus->SetLabel(wxT("FM-D"));
m_txtModeStatus->Enable(true);
break;
case IRigFrequencyController::AM:
m_txtModeStatus->SetLabel(wxT("AM"));
m_txtModeStatus->Enable(true);
break;
default:
m_txtModeStatus->SetLabel(wxT("unk"));
m_txtModeStatus->Enable(false);
break;
}
// Widest 60 meter allocation is 5.250-5.450 MHz per https://en.wikipedia.org/wiki/60-meter_band.
bool is60MeterBand = freq >= 5250000 && freq <= 5450000;
// Update color based on the mode and current frequency.
bool isUsbFreq = freq >= 10000000 || is60MeterBand;
bool isLsbFreq = freq < 10000000 && !is60MeterBand;
bool isMatchingMode =
(isUsbFreq && (mode == IRigFrequencyController::USB || mode == IRigFrequencyController::DIGU)) ||
(isLsbFreq && (mode == IRigFrequencyController::LSB || mode == IRigFrequencyController::DIGL));
if (isMatchingMode)
{
m_txtModeStatus->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
}
else
{
m_txtModeStatus->SetForegroundColour(wxColor(*wxRED));
}
// Update frequency box
if (!wxGetApp().appConfiguration.reportingConfiguration.reportingEnabled ||
!wxGetApp().appConfiguration.reportingConfiguration.manualFrequencyReporting)
{
if (wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz)
{
m_cboReportFrequency->SetValue(wxString::Format("%.1f", freq / 1000.0));
}
else
{
m_cboReportFrequency->SetValue(wxString::Format("%.4f", freq / 1000.0 / 1000.0));
}
}
m_txtModeStatus->Refresh();
// Suppress updates if the Report Frequency box has focus.
suppressFreqModeUpdates_ = m_cboReportFrequency->HasFocus();
});
}; };
// Temporarily suppress frequency updates until we're fully connected. // Temporarily suppress frequency updates until we're fully connected.

View File

@ -396,6 +396,8 @@ void HamlibRigController::disconnectImpl_()
rig_close(rig_); rig_close(rig_);
rig_cleanup(rig_); rig_cleanup(rig_);
rig_ = nullptr; rig_ = nullptr;
onRigDisconnected(this);
} }
} }