Skip to content

Commit

Permalink
Merge branch 'master' into ms-reporter-bg-color
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jul 4, 2023
2 parents 5640342 + 1989969 commit 797e414
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 21 deletions.
3 changes: 2 additions & 1 deletion USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,11 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
* Disable PTT and Voice Keyer buttons if only RX devices are configured. (PR #449)
* Fix Linux display bugs when switching between dark and light mode. (PR #454)
2. Enhancements:
* Add the ability to request that another FreeDV Reporter user QSY. (PR #434, #453, #458)
* Add the ability to request that another FreeDV Reporter user QSY. (PR #434, #453, #456, #458)
* Display 'Digital' on button when Analog mode is active. (PR #447)
* Set minimum size for Mode box to 250px. (PR #446)
* Notify FreeDV Reporter if only capable of RX. (PR #449)
* Hamlib: allow frequency and mode changes during TX. (PR #455)
3. Build system:
* Bump Codec2 version to v1.1.1. (PR #437)
4. Miscallenous:
Expand Down
101 changes: 84 additions & 17 deletions src/hamlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,86 @@ void Hamlib::disable_mode_detection()

void Hamlib::setMode(bool analog, uint64_t frequencyHz)
{
if (m_rig == nullptr || pttSet_ || readOnly_)
if (m_rig == nullptr || readOnly_)
{
// Ignore if not connected
return;
}

if (pttSet_)
{
// If transmitting, temporarily stop transmitting so we can change the mode.
int result = rig_set_ptt(m_rig, RIG_VFO_CURR, RIG_PTT_OFF);
if (result != RIG_OK)
{
// If we can't stop transmitting, we shouldn't try to change the mode
// as it'll fail on some radios.
if (g_verbose) fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(result));

return;
}
}


vfo_t currVfo = getCurrentVfo_();
rmode_t mode = getHamlibMode_(analog, frequencyHz);
setModeHelper_(currVfo, mode);

if (pttSet_)
{
// If transmitting, temporarily stop transmitting so we can change the mode.
int result = rig_set_ptt(m_rig, RIG_VFO_CURR, RIG_PTT_ON);
if (result != RIG_OK)
{
// If we can't stop transmitting, we shouldn't try to change the mode
// as it'll fail on some radios.
if (g_verbose) fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(result));
}
}
}

void Hamlib::setFrequencyAndMode(uint64_t frequencyHz, bool analog)
{
if (m_rig == nullptr || readOnly_)
{
// Ignore if not connected or if transmitting
return;
}

if (pttSet_)
{
// If transmitting, temporarily stop transmitting so we can change the mode.
int result = rig_set_ptt(m_rig, RIG_VFO_CURR, RIG_PTT_OFF);
if (result != RIG_OK)
{
// If we can't stop transmitting, we shouldn't try to change the mode
// as it'll fail on some radios.
if (g_verbose) fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(result));

return;
}
}

vfo_t currVfo = getCurrentVfo_();
rmode_t mode = getHamlibMode_(analog, frequencyHz);
setModeHelper_(currVfo, mode);
setFrequencyHelper_(currVfo, frequencyHz);

if (pttSet_)
{
// If transmitting, temporarily stop transmitting so we can change the mode.
int result = rig_set_ptt(m_rig, RIG_VFO_CURR, RIG_PTT_ON);
if (result != RIG_OK)
{
// If we can't stop transmitting, we shouldn't try to change the mode
// as it'll fail on some radios.
if (g_verbose) fprintf(stderr, "rig_set_ptt: error = %s \n", rigerror(result));
}
}
}

rmode_t Hamlib::getHamlibMode_(bool analog, uint64_t frequencyHz)
{
// Widest 60 meter allocation is 5.250-5.450 MHz per https://en.wikipedia.org/wiki/60-meter_band.
bool is60MeterBand = frequencyHz >= 5250000 && frequencyHz <= 5450000;

Expand All @@ -361,24 +435,10 @@ void Hamlib::setMode(bool analog, uint64_t frequencyHz)
{
assert(0);
}

vfo_t currVfo = getCurrentVfo_();
setModeHelper_(currVfo, mode);
}

void Hamlib::setFrequencyAndMode(uint64_t frequencyHz, bool analog)
{
if (m_rig == nullptr || pttSet_ || readOnly_)
{
// Ignore if not connected or if transmitting
return;
}

vfo_t currVfo = getCurrentVfo_();
setMode(analog, frequencyHz);
setFrequencyHelper_(currVfo, frequencyHz);
return mode;
}

void Hamlib::setModeHelper_(vfo_t currVfo, rmode_t mode)
{
bool setOkay = false;
Expand Down Expand Up @@ -596,6 +656,13 @@ void Hamlib::update_mode_status()

void Hamlib::close(void) {
if(m_rig) {
// Stop transmitting.
if (pttSet_)
{
wxString tmp;
ptt(false, tmp);
}

// Turn off status thread if needed.
disable_mode_detection();

Expand Down
1 change: 1 addition & 0 deletions src/hamlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Hamlib {
typedef std::vector<const struct rig_caps *> riglist_t;

private:
rmode_t getHamlibMode_(bool analog, uint64_t frequencyHz);
void update_mode_status();
void statusUpdateThreadEntryFn_();
void update_from_hamlib_();
Expand Down
13 changes: 10 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,16 +2138,23 @@ void MainFrame::performFreeDVOn_()
freedvReporter->setOnQSYRequestFn([&](std::string callsign, uint64_t freqHz, std::string message) {
double frequencyMHz = freqHz / 1000000.0;
wxString fullMessage = wxString::Format(_("%s has requested that you QSY to %.04f MHz."), callsign, frequencyMHz);
int dialogStyle = wxOK | wxICON_INFORMATION;
int dialogStyle = wxOK | wxICON_INFORMATION | wxCENTRE;

if (wxGetApp().m_hamlib != nullptr && wxGetApp().m_boolHamlibEnableFreqModeChanges)
{
fullMessage = wxString::Format(_("%s has requested that you QSY to %.04f MHz. Would you like to change to that frequency now?"), callsign, frequencyMHz);
dialogStyle = wxYES_NO | wxICON_QUESTION;
dialogStyle = wxYES_NO | wxICON_QUESTION | wxCENTRE;
}

CallAfter([&, fullMessage, dialogStyle, frequencyMHz]() {
auto answer = wxMessageBox(fullMessage, wxT("FreeDV Reporter"), dialogStyle, this);
wxMessageDialog messageDialog(this, fullMessage, wxT("FreeDV Reporter"), dialogStyle);

if (dialogStyle & wxYES_NO)
{
messageDialog.SetYesNoLabels(_("Change Frequency"), _("Cancel"));
}

auto answer = messageDialog.ShowModal();
if (answer == wxYES)
{
// This will implicitly cause Hamlib to change the frequecy and mode.
Expand Down

0 comments on commit 797e414

Please sign in to comment.