Skip to content

Commit

Permalink
Fix display of hamlib errors during initialization (#460)
Browse files Browse the repository at this point in the history
* Fix display of hamlib errors during initialization

- display via showmsg() as full screen is not working at the time of
  initialization
- move to rigerror2(), which shows only the last error message
  rigerror() got changed at >=Hamlib-4.5 to provide a list of last errors
  each time called.
  rigerror2()  returns a single line description of the last error.
  • Loading branch information
dl1jbe authored Feb 13, 2025
1 parent f41982a commit 73afaeb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
14 changes: 7 additions & 7 deletions src/gettxinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static void poll_rig_state() {
mvprintw(0, 14, "%2u", speed);
}
} else {
TLF_LOG_WARN("Problem with rig link: %s", rigerror(retval));
TLF_LOG_WARN("Problem with rig link: %s", tlf_rigerror(retval));
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ void gettxinfo(void) {
pthread_mutex_unlock(&tlf_rig_mutex);

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

} else if (reqf == SETSSBMODE) {
Expand All @@ -257,7 +257,7 @@ void gettxinfo(void) {
pthread_mutex_unlock(&tlf_rig_mutex);

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

} else if (reqf == SETDIGIMODE) {
Expand All @@ -274,7 +274,7 @@ void gettxinfo(void) {
pthread_mutex_unlock(&tlf_rig_mutex);

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

} else if (reqf == RESETRIT) {
Expand All @@ -283,7 +283,7 @@ void gettxinfo(void) {
pthread_mutex_unlock(&tlf_rig_mutex);

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

} else {
Expand All @@ -294,7 +294,7 @@ void gettxinfo(void) {
pthread_mutex_unlock(&tlf_rig_mutex);

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

}
Expand Down Expand Up @@ -341,7 +341,7 @@ static void handle_trx_bandswitch(const freq_t freq) {
pthread_mutex_unlock(&tlf_rig_mutex);

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

40 changes: 16 additions & 24 deletions src/sendqrg.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ bool sendqrg(void) {

/**************************************************************************/

void show_rigerror(char *message, int errcode) {
char *str = g_strdup_printf("%s: %s", message, tlf_rigerror(errcode));
showmsg(str);
g_free(str);
}


int init_tlf_rig(void) {
freq_t rigfreq; /* frequency */
vfo_t vfo;
int retcode; /* generic return code from functions */

const char *ptt_file = NULL, *dcd_file = NULL;
dcd_type_t dcd_type = RIG_DCD_NONE;

const struct rig_caps *caps;
int rig_cwspeed;

Expand All @@ -111,10 +115,12 @@ int init_tlf_rig(void) {
return -1;
}

rigportname[strlen(rigportname) - 1] = '\0'; // remove '\n'
g_strchomp(rigportname); // remove trailing '\n'
strncpy(my_rig->state.rigport.pathname, rigportname,
TLFFILPATHLEN - 1);

my_rig->state.rigport.parm.serial.rate = serial_rate;

caps = my_rig->caps;

can_send_morse = caps->send_morse != NULL;
Expand All @@ -134,24 +140,14 @@ int init_tlf_rig(void) {
}
}

if (dcd_type != RIG_DCD_NONE)
my_rig->state.dcdport.type.dcd = dcd_type;
if (ptt_file)
strncpy(my_rig->state.pttport.pathname, ptt_file, TLFFILPATHLEN);
if (dcd_file)
strncpy(my_rig->state.dcdport.pathname, dcd_file, TLFFILPATHLEN);

my_rig->state.rigport.parm.serial.rate = serial_rate;

// parse RIGCONF parameters
if (parse_rigconf() < 0) {
return -1;
}

retcode = rig_open(my_rig);

if (retcode != RIG_OK) {
TLF_LOG_WARN("rig_open: %s", rigerror(retcode));
show_rigerror("rig_open", retcode);
return -1;
}

Expand All @@ -162,7 +158,7 @@ int init_tlf_rig(void) {
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &rigfreq);

if (retcode != RIG_OK) {
TLF_LOG_WARN("Problem with rig link: %s", rigerror(retcode));
show_rigerror("Problem with rig link", retcode);
if (!debugflag)
return -1;
}
Expand All @@ -177,7 +173,7 @@ int init_tlf_rig(void) {
shownr("CW speed = ", rig_cwspeed);
speed = rig_cwspeed;
} else {
TLF_LOG_WARN("Could not read CW speed from rig: %s", rigerror(retcode));
show_rigerror("Could not read CW speed from rig", retcode);
if (!debugflag)
return -1;
}
Expand Down Expand Up @@ -205,13 +201,10 @@ int init_tlf_rig(void) {
}

void close_tlf_rig(RIG *my_rig) {

pthread_mutex_lock(&tlf_rig_mutex);
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
pthread_mutex_unlock(&tlf_rig_mutex);

printf("Rig port %s closed\n", rigportname);
}

static int parse_rigconf() {
Expand Down Expand Up @@ -268,7 +261,7 @@ static void debug_tlf_rig() {
pthread_mutex_unlock(&tlf_rig_mutex);

if (retcode != RIG_OK) {
TLF_LOG_WARN("Problem with rig get freq: %s", rigerror(retcode));
show_rigerror("Problem with rig get freq", retcode);
} else {
shownr("freq =", (int) rigfreq);
}
Expand All @@ -281,7 +274,7 @@ static void debug_tlf_rig() {
pthread_mutex_unlock(&tlf_rig_mutex);

if (retcode != RIG_OK) {
TLF_LOG_WARN("Problem with rig set freq: %s", rigerror(retcode));
show_rigerror("Problem with rig set freq", retcode);
} else {
showmsg("Rig set freq ok!");
}
Expand All @@ -291,13 +284,12 @@ static void debug_tlf_rig() {
pthread_mutex_unlock(&tlf_rig_mutex);

if (retcode != RIG_OK) {
TLF_LOG_WARN("Problem with rig get freq: %s", rigerror(retcode));
show_rigerror("Problem with rig get freq", retcode);
} else {
shownr("freq =", (int) rigfreq);
if (rigfreq != testfreq) {
showmsg("Failed to set rig freq!");
}
}
sleep(10);

}
2 changes: 1 addition & 1 deletion src/speedupndown.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static int setspeed(int cwspeed) {
if (retval >= 0) {
speed = cwspeed;
} else {
TLF_LOG_WARN("Could not set CW speed: %s", rigerror(retval));
TLF_LOG_WARN("Could not set CW speed: %s", tlf_rigerror(retval));
clear_display();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stoptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int stoptx(void) {

int error = hamlib_keyer_stop();
if (error != RIG_OK) {
TLF_LOG_WARN("CW stop error: %s", rigerror(error));
TLF_LOG_WARN("CW stop error: %s", tlf_rigerror(error));

}
}
Expand Down
7 changes: 7 additions & 0 deletions src/tlf.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,12 @@ enum {
#define QSOS(n) (((struct qso_t*)g_ptr_array_index(qso_array, n))->logline)
#define NR_QSOS (qso_array->len)

/* Fix for changed rigerror() behaviour */
#if HAMLIB_VERSION > 450
#define tlf_rigerror(errcode) rigerror2(errcode)
#else
#define tlf_rigerror(errcode) rigerror(errcode)
#endif

#endif /* TLF_H */

2 changes: 1 addition & 1 deletion src/write_keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void write_keyer(void) {

int error = hamlib_keyer_send(tosend);
if (error != RIG_OK) {
TLF_LOG_WARN("CW send error: %s", rigerror(error));
TLF_LOG_WARN("CW send error: %s", tlf_rigerror(error));
}
} else if (cwkeyer == MFJ1278_KEYER || digikeyer == MFJ1278_KEYER) {
if ((bfp = fopen(controllerport, "a")) == NULL) {
Expand Down

0 comments on commit 73afaeb

Please sign in to comment.