Issue 290 - Add capability to set serial port speed for hamlib.

This commit is contained in:
wb2osz 2020-10-21 22:07:19 -04:00
parent f0bd085a13
commit 7d4a49aecb
3 changed files with 51 additions and 3 deletions

View File

@ -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];

View File

@ -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);

View File

@ -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);