Skip to content

Commit

Permalink
Merge pull request #1 from dl1jbe/rig_mode_disable
Browse files Browse the repository at this point in the history
Refactor and move FOLLOW_MODE condition
  • Loading branch information
darvark committed Jan 6, 2024
2 parents 8425b28 + 7cc430e commit 1f00702
Showing 1 changed file with 95 additions and 100 deletions.
195 changes: 95 additions & 100 deletions src/gettxinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ static pbwidth_t get_cw_bandwidth() {
return (cw_bandwidth > 0 ? cw_bandwidth : TLF_DEFAULT_PASSBAND);
}


void gettxinfo(void) {

freq_t rigfreq;
static void poll_rig_state() {
freq_t rigfreq;
vfo_t vfo;
pbwidth_t bwidth;
int retval;
Expand All @@ -109,6 +107,88 @@ void gettxinfo(void) {
static double last_freq_time = 0.0;
static int oldbandinx;

rigfreq = 0.0;

double now = get_current_seconds();
if (now < last_freq_time + 0.2) {
return; // last read-out was within 200 ms, skip this query
}
last_freq_time = now;

pthread_mutex_lock(&rig_lock);
retval = rig_get_vfo(my_rig, &vfo); /* initialize RIG_VFO_CURR */
pthread_mutex_unlock(&rig_lock);

if (retval == RIG_OK || retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) {
pthread_mutex_lock(&rig_lock);
retval = rig_get_freq(my_rig, RIG_VFO_CURR, &rigfreq);
pthread_mutex_unlock(&rig_lock);

if (trxmode == DIGIMODE && (digikeyer == GMFSK || digikeyer == FLDIGI)
&& retval == RIG_OK) {

pthread_mutex_lock(&rig_lock);
retvalmode = rig_get_mode(my_rig, RIG_VFO_CURR, &rigmode, &bwidth);
pthread_mutex_unlock(&rig_lock);

if (retvalmode != RIG_OK) {
rigmode = RIG_MODE_NONE;
}
}
}

if (trxmode == DIGIMODE && (digikeyer == GMFSK || digikeyer == FLDIGI)) {
rigfreq += (freq_t)fldigi_get_carrier();
if (rigmode == RIG_MODE_RTTY || rigmode == RIG_MODE_RTTYR) {
fldigi_shift_freq = fldigi_get_shift_freq();
if (fldigi_shift_freq != 0) {
pthread_mutex_lock(&rig_lock);
retval = rig_set_freq(my_rig, RIG_VFO_CURR,
((freq_t)rigfreq + (freq_t)fldigi_shift_freq));
pthread_mutex_unlock(&rig_lock);
}
}
}

if (retval != RIG_OK || rigfreq < 0.1) {
freq = 0.0;
return;
}

if (rigfreq >= bandcorner[0][0]) {
freq = rigfreq; // Hz
}

bandinx = freq2bandindex((unsigned int)freq);

bandfrequency[bandinx] = freq;

if (bandinx != oldbandinx) { // band change on trx
oldbandinx = bandinx;
handle_trx_bandswitch((int) freq);
}

/* read speed from rig */
if (cwkeyer == HAMLIB_KEYER) {
int rig_cwspeed;
retval = hamlib_keyer_get_speed(&rig_cwspeed);

if (retval == RIG_OK) {
if (GetCWSpeed() != rig_cwspeed) { // FIXME: doesn't work if rig speed is between the values from CW_SPEEDS
SetCWSpeed(rig_cwspeed);

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
}
} else {
TLF_LOG_WARN("Problem with rig link: %s", rigerror(retval));
}
}
}

void gettxinfo(void) {
int retval;

if (!trx_control)
return;

Expand Down Expand Up @@ -143,97 +223,7 @@ void gettxinfo(void) {
freq_t reqf = get_and_reset_outfreq(); // get actual request

if (reqf == 0) {

rigfreq = 0.0;

double now = get_current_seconds();
if (now < last_freq_time + 0.2) {
return; // last read-out was within 200 ms, skip this query
}
last_freq_time = now;

pthread_mutex_lock(&rig_lock);
retval = rig_get_vfo(my_rig, &vfo); /* initialize RIG_VFO_CURR */
pthread_mutex_unlock(&rig_lock);

if (retval == RIG_OK || retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) {
pthread_mutex_lock(&rig_lock);
retval = rig_get_freq(my_rig, RIG_VFO_CURR, &rigfreq);
pthread_mutex_unlock(&rig_lock);

if (trxmode == DIGIMODE && (digikeyer == GMFSK || digikeyer == FLDIGI)
&& retval == RIG_OK) {

pthread_mutex_lock(&rig_lock);
retvalmode = rig_get_mode(my_rig, RIG_VFO_CURR, &rigmode, &bwidth);
pthread_mutex_unlock(&rig_lock);

if (retvalmode != RIG_OK) {
rigmode = RIG_MODE_NONE;
}
}
}

if (trxmode == DIGIMODE && (digikeyer == GMFSK || digikeyer == FLDIGI)) {
rigfreq += (freq_t)fldigi_get_carrier();
if (rigmode == RIG_MODE_RTTY || rigmode == RIG_MODE_RTTYR) {
fldigi_shift_freq = fldigi_get_shift_freq();
if (fldigi_shift_freq != 0) {
pthread_mutex_lock(&rig_lock);
retval = rig_set_freq(my_rig, RIG_VFO_CURR,
((freq_t)rigfreq + (freq_t)fldigi_shift_freq));
pthread_mutex_unlock(&rig_lock);
}
}
}

if (retval != RIG_OK || rigfreq < 0.1) {
freq = 0.0;
return;
}


if (rigfreq >= bandcorner[0][0]) {
freq = rigfreq; // Hz
}

bandinx = freq2bandindex((unsigned int)freq);

bandfrequency[bandinx] = freq;

if (bandinx != oldbandinx) { // band change on trx
oldbandinx = bandinx;
if (follow_mode) {
handle_trx_bandswitch((int) freq);
}
}

/* read speed from rig */
if (cwkeyer == HAMLIB_KEYER) {
int rig_cwspeed;
retval = hamlib_keyer_get_speed(&rig_cwspeed);

if (retval == RIG_OK) {
if (GetCWSpeed() != rig_cwspeed) { // FIXME: doesn't work if rig speed is between the values from CW_SPEEDS
SetCWSpeed(rig_cwspeed);

attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
mvprintw(0, 14, "%2u", GetCWSpeed());
}
} else {
TLF_LOG_WARN("Problem with rig link: %s", rigerror(retval));
}
}

} else if (reqf == SETCWMODE) {

pthread_mutex_lock(&rig_lock);
retval = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, get_cw_bandwidth());
pthread_mutex_unlock(&rig_lock);

if (retval != RIG_OK) {
TLF_LOG_WARN("Problem with rig link: %s", rigerror(retval));
}
poll_rig_state();

} else if (reqf == SETSSBMODE) {

Expand Down Expand Up @@ -294,11 +284,7 @@ static double get_current_seconds() {
return tv.tv_sec + tv.tv_usec / 1e6;
}


static void handle_trx_bandswitch(const freq_t freq) {

send_bandswitch(freq);

static void set_default_rig_mode() {
rmode_t mode = RIG_MODE_NONE; // default: no change
pbwidth_t width = TLF_DEFAULT_PASSBAND; // passband width, in Hz

Expand Down Expand Up @@ -328,3 +314,12 @@ static void handle_trx_bandswitch(const freq_t freq) {

}


static void handle_trx_bandswitch(const freq_t freq) {

send_bandswitch(freq);
if (follow_mode) {
set_default_rig_mode();
}
}

0 comments on commit 1f00702

Please sign in to comment.