From 7d4a49aecbcb65b9ab8dd5b3cbd12d0db761c8a0 Mon Sep 17 00:00:00 2001 From: wb2osz Date: Wed, 21 Oct 2020 22:07:19 -0400 Subject: [PATCH] Issue 290 - Add capability to set serial port speed for hamlib. --- src/audio.h | 2 ++ src/config.c | 17 +++++++++++++++-- src/ptt.c | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/audio.h b/src/audio.h index 53768f2..61dec9d 100644 --- a/src/audio.h +++ b/src/audio.h @@ -278,6 +278,8 @@ struct audio_s { #ifdef USE_HAMLIB int ptt_model; /* HAMLIB model. -1 for AUTO. 2 for rigctld. Others are radio model. */ + int ptt_rate; /* Serial port speed when using hamlib CAT control for PTT. */ + /* If zero, hamlib will come up with a default for pariticular rig. */ #endif } octrl[NUM_OCTYPES]; diff --git a/src/config.c b/src/config.c index d7d71af..8588a8c 100644 --- a/src/config.c +++ b/src/config.c @@ -1682,8 +1682,8 @@ void config_init (char *fname, struct audio_s *p_audio_config, * xxx serial-port [-]rts-or-dtr [ [-]rts-or-dtr ] * xxx GPIO [-]gpio-num * xxx LPT [-]bit-num - * PTT RIG model port - * PTT RIG AUTO port + * PTT RIG model port [ rate ] + * PTT RIG AUTO port [ rate ] * PTT CM108 [ [-]bit-num ] [ hid-device ] * * When model is 2, port would host:port like 127.0.0.1:4532 @@ -1808,6 +1808,19 @@ void config_init (char *fname, struct audio_s *p_audio_config, } strlcpy (p_audio_config->achan[channel].octrl[ot].ptt_device, t, sizeof(p_audio_config->achan[channel].octrl[ot].ptt_device)); + // Optional serial port rate for CAT controll PTT. + + t = split(NULL,0); + if (t != NULL) { + if ( ! alldigits(t)) { + text_color_set(DW_COLOR_ERROR); + dw_printf ("Config file line %d: An optional number is required here for CAT serial port speed: %s\n", line, t); + continue; + } + int n = atoi(t); + p_audio_config->achan[channel].octrl[ot].ptt_rate = n; + } + t = split(NULL,0); if (t != NULL) { text_color_set(DW_COLOR_ERROR); diff --git a/src/ptt.c b/src/ptt.c index cf49bba..2a94300 100644 --- a/src/ptt.c +++ b/src/ptt.c @@ -984,10 +984,20 @@ void ptt_init (struct audio_s *audio_config_p) /* For "AUTO" model, try to guess what is out there. */ if (audio_config_p->achan[ch].octrl[ot].ptt_model == -1) { - hamlib_port_t hport; + hamlib_port_t hport; // http://hamlib.sourceforge.net/manuals/1.2.15/structhamlib__port__t.html memset (&hport, 0, sizeof(hport)); strlcpy (hport.pathname, audio_config_p->achan[ch].octrl[ot].ptt_device, sizeof(hport.pathname)); + + if (audio_config_p->achan[ch].octrl[ot].ptt_rate > 0) { + // Override the default serial port data rate. + hport.parm.serial.rate = audio_config_p->achan[ch].octrl[ot].ptt_rate; + hport.parm.serial.data_bits = 8; + hport.parm.serial.stop_bits = 1; + hport.parm.serial.parity = RIG_PARITY_NONE; + hport.parm.serial.handshake = RIG_HANDSHAKE_NONE; + } + rig_load_all_backends(); audio_config_p->achan[ch].octrl[ot].ptt_model = rig_probe(&hport); @@ -1011,6 +1021,29 @@ void ptt_init (struct audio_s *audio_config_p) } strlcpy (rig[ch][ot]->state.rigport.pathname, audio_config_p->achan[ch].octrl[ot].ptt_device, sizeof(rig[ch][ot]->state.rigport.pathname)); + + // Issue 290. + // We had a case where hamlib defaulted to 9600 baud for a particular + // radio model but 38400 was needed. Add an option for the configuration + // file to override the hamlib default speed. + + text_color_set(DW_COLOR_INFO); + if (audio_config_p->achan[ch].octrl[ot].ptt_model != 2) { // 2 is network, not serial port. + dw_printf ("Hamlib determined CAT control serial port rate of %d.\n", rig[ch][ot]->state.rigport.parm.serial.rate); + } + + // Config file can optionally override the rate that hamlib came up with. + + if (audio_config_p->achan[ch].octrl[ot].ptt_rate > 0) { + dw_printf ("User configuration overriding hamlib CAT control speed to %d.\n", audio_config_p->achan[ch].octrl[ot].ptt_rate); + rig[ch][ot]->state.rigport.parm.serial.rate = audio_config_p->achan[ch].octrl[ot].ptt_rate; + + // Do we want to explicitly set all of these or let it default? + rig[ch][ot]->state.rigport.parm.serial.data_bits = 8; + rig[ch][ot]->state.rigport.parm.serial.stop_bits = 1; + rig[ch][ot]->state.rigport.parm.serial.parity = RIG_PARITY_NONE; + rig[ch][ot]->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE; + } int err = rig_open(rig[ch][ot]); if (err != RIG_OK) { text_color_set(DW_COLOR_ERROR);