Skip to content

Commit ac415c9

Browse files
committed
Handle slow Hamlib init. This change adds a retry loop to the
rig_open call. If the rig_open continues to fail after 5 tries, exit.
1 parent c25629a commit ac415c9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Diff for: src/ptt.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,8 @@ void ptt_init (struct audio_s *audio_config_p)
990990
for (ot = 0; ot < NUM_OCTYPES; ot++) {
991991
if (audio_config_p->achan[ch].octrl[ot].ptt_method == PTT_METHOD_HAMLIB) {
992992
if (ot == OCTYPE_PTT) {
993+
int err = -1;
994+
int tries = 0;
993995

994996
/* For "AUTO" model, try to guess what is out there. */
995997

@@ -1054,13 +1056,24 @@ void ptt_init (struct audio_s *audio_config_p)
10541056
rig[ch][ot]->state.rigport.parm.serial.parity = RIG_PARITY_NONE;
10551057
rig[ch][ot]->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
10561058
}
1057-
int err = rig_open(rig[ch][ot]);
1059+
tries = 0;
1060+
do {
1061+
// Try up to 5 times, Hamlib can take a moment to finish init
1062+
err = rig_open(rig[ch][ot]);
1063+
if (++tries > 5) {
1064+
break;
1065+
} else if (err != RIG_OK) {
1066+
text_color_set(DW_COLOR_INFO);
1067+
dw_printf ("Retrying Hamlib Rig open...\n");
1068+
sleep (5);
1069+
}
1070+
} while (err != RIG_OK);
10581071
if (err != RIG_OK) {
10591072
text_color_set(DW_COLOR_ERROR);
10601073
dw_printf ("Hamlib Rig open error %d: %s\n", err, rigerror(err));
10611074
rig_cleanup (rig[ch][ot]);
10621075
rig[ch][ot] = NULL;
1063-
continue;
1076+
exit (1);
10641077
}
10651078

10661079
/* Successful. Later code should check for rig[ch][ot] not NULL. */

0 commit comments

Comments
 (0)