Skip to content

Commit

Permalink
Hamlib: allow frequency/mode changes during TX.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jul 1, 2023
1 parent 95b0eec commit 6497fe8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 17 deletions.
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

0 comments on commit 6497fe8

Please sign in to comment.