diff --git a/USER_MANUAL.html b/USER_MANUAL.html index ecf1623d7..b21c289a5 100644 --- a/USER_MANUAL.html +++ b/USER_MANUAL.html @@ -621,6 +621,7 @@

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)
  • Build system:
      diff --git a/USER_MANUAL.md b/USER_MANUAL.md index 2b1dfa731..a0275f9ca 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -879,6 +879,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes * 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: diff --git a/USER_MANUAL.pdf b/USER_MANUAL.pdf index 3628919ca..3f3acddd3 100644 Binary files a/USER_MANUAL.pdf and b/USER_MANUAL.pdf differ diff --git a/src/hamlib.cpp b/src/hamlib.cpp index dbd08921b..87de8d0bb 100644 --- a/src/hamlib.cpp +++ b/src/hamlib.cpp @@ -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; @@ -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; @@ -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(); diff --git a/src/hamlib.h b/src/hamlib.h index ea78c0539..f53342b82 100644 --- a/src/hamlib.h +++ b/src/hamlib.h @@ -50,6 +50,7 @@ class Hamlib { typedef std::vector riglist_t; private: + rmode_t getHamlibMode_(bool analog, uint64_t frequencyHz); void update_mode_status(); void statusUpdateThreadEntryFn_(); void update_from_hamlib_();