From 16cf1990155faaf547b2bb6a8349d0349557f965 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Mon, 13 Dec 2021 23:12:29 -0600 Subject: [PATCH] JST-145 is now working with WSJT-X --- rigs/jrc/jst145.c | 138 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 15 deletions(-) diff --git a/rigs/jrc/jst145.c b/rigs/jrc/jst145.c index 10459156f..5cf8dfc3d 100644 --- a/rigs/jrc/jst145.c +++ b/rigs/jrc/jst145.c @@ -32,6 +32,7 @@ #include "jrc.h" +static int jst145_init(RIG *rig); static int jst145_open(RIG *rig); static int jst145_close(RIG *rig); static int jst145_set_vfo(RIG *rig, vfo_t vfo); @@ -45,6 +46,8 @@ static int jst145_set_func(RIG *rig, vfo_t vfo, setting_t func, int status); static int jst145_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); static int jst145_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); static int jst145_set_mem(RIG *rig, vfo_t vfo, int ch); +static int jst145_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt); +static int jst145_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt); #define JST145_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_RTTY|RIG_MODE_FAX) @@ -59,6 +62,14 @@ static int jst145_set_mem(RIG *rig, vfo_t vfo, int ch); .levels = RIG_LEVEL_AGC, \ } +struct jst145_priv_data +{ + ptt_t ptt; + freq_t freqA, freqB; + mode_t mode; +}; + + /* * JST-145 rig capabilities. * @@ -70,9 +81,9 @@ const struct rig_caps jst145_caps = .mfg_name = "JRC", .version = BACKEND_VER ".1", .copyright = "LGPL", - .status = RIG_STATUS_ALPHA, - .rig_type = RIG_TYPE_RECEIVER, - .ptt_type = RIG_PTT_NONE, + .status = RIG_STATUS_STABLE, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_RIG, .dcd_type = RIG_DCD_NONE, .port_type = RIG_PORT_SERIAL, .serial_rate_min = 4800, @@ -82,9 +93,9 @@ const struct rig_caps jst145_caps = .serial_parity = RIG_PARITY_NONE, .serial_handshake = RIG_HANDSHAKE_NONE, .write_delay = 0, - .post_write_delay = 20, + .post_write_delay = 0, .timeout = 1000, - .retry = 0, + .retry = 1, .has_get_func = RIG_FUNC_NONE, .has_set_func = RIG_FUNC_NONE, @@ -154,7 +165,9 @@ const struct rig_caps jst145_caps = .set_func = jst145_set_func, .set_level = jst145_set_level, .set_mem = jst145_set_mem, - .vfo_op = jst145_vfo_op + .vfo_op = jst145_vfo_op, + .set_ptt = jst145_set_ptt, + .get_ptt = jst145_get_ptt }; /* @@ -168,9 +181,9 @@ const struct rig_caps jst245_caps = .mfg_name = "JRC", .version = BACKEND_VER ".1", .copyright = "LGPL", - .status = RIG_STATUS_ALPHA, - .rig_type = RIG_TYPE_RECEIVER, - .ptt_type = RIG_PTT_NONE, + .status = RIG_STATUS_STABLE, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_RIG, .dcd_type = RIG_DCD_NONE, .port_type = RIG_PORT_SERIAL, .serial_rate_min = 4800, @@ -241,6 +254,7 @@ const struct rig_caps jst245_caps = RIG_FLT_END, }, + .rig_init = jst145_init, .rig_open = jst145_open, .rig_close = jst145_close, .set_vfo = jst145_set_vfo, @@ -252,16 +266,53 @@ const struct rig_caps jst245_caps = .set_func = jst145_set_func, .set_level = jst145_set_level, .set_mem = jst145_set_mem, - .vfo_op = jst145_vfo_op + .vfo_op = jst145_vfo_op, + .set_ptt = jst145_set_ptt, + .get_ptt = jst145_get_ptt }; /* * Function definitions below */ + +static int jst145_init(RIG *rig) +{ + struct jst145_priv_data *priv; + priv = (struct jst145_priv_data *)malloc(sizeof(struct jst145_priv_data)); + + if (!priv) + { + return -RIG_ENOMEM; + } + + rig->state.priv = (void *)priv; + return RIG_OK; +} + static int jst145_open(RIG *rig) { - return write_block(&rig->state.rigport, "H1\r", 3); + int retval; + freq_t freq; + rmode_t mode; + pbwidth_t width; + struct jst145_priv_data *priv = rig->state.priv; + + retval = write_block(&rig->state.rigport, "H1\r", 3); + + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: H1 failed: %s\n", __func__, rigerror(retval)); + return retval; + } + + jst145_get_freq(rig, RIG_VFO_A, &freq); + priv->freqA = freq; + jst145_get_freq(rig, RIG_VFO_B, &freq); + priv->freqB = freq; + jst145_get_mode(rig, RIG_VFO_A, &mode, &width); + priv->mode = mode; + return retval; } static int jst145_close(RIG *rig) @@ -303,12 +354,24 @@ static int jst145_get_vfo(RIG *rig, vfo_t *vfo) static int jst145_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { char freqbuf[24]; + struct jst145_priv_data *priv = rig->state.priv; - snprintf(freqbuf, sizeof(freqbuf), "F%08u%c\r", (unsigned)(freq / 10), + snprintf(freqbuf, sizeof(freqbuf), "F%08u%c\r", (unsigned)(freq), vfo == RIG_VFO_A ? 'A' : 'B'); + if (vfo == RIG_VFO_B) + { + priv->freqB = freq; + } + else + { + priv->freqA = freq; + } + return write_block(&rig->state.rigport, freqbuf, strlen(freqbuf)); } + + static int jst145_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { char freqbuf[24]; @@ -318,7 +381,15 @@ static int jst145_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int n; char vfoc; - rig_set_vfo(rig, vfo); + struct jst145_priv_data *priv = rig->state.priv; + + if (priv->ptt) // can't get freq while transmitting + { + *freq = vfo == RIG_VFO_B ? priv->freqB : priv->freqA; + return RIG_OK; + } + + jst145_set_vfo(rig, vfo); snprintf(cmd, sizeof(cmd), "L\r"); retval = jrc_transaction(rig, cmd, strlen(cmd), freqbuf, &freqbuf_size); @@ -329,11 +400,11 @@ static int jst145_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return retval; } - n = sscanf(freqbuf, "L%c%lf", &vfoc, freq); + n = sscanf(freqbuf, "L%c%*c%*c%*c%8lf", &vfoc, freq); if (n != 2) { retval = -RIG_EPROTO; } - if (vfoc == 'B') { rig_set_vfo(rig, RIG_VFO_A); } + if (vfoc == 'B') { jst145_set_vfo(rig, RIG_VFO_A); } return retval; } @@ -342,6 +413,7 @@ static int jst145_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { int retval; char *modestr; + struct jst145_priv_data *priv = rig->state.priv; switch (mode) { @@ -368,6 +440,8 @@ static int jst145_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) return retval; } + priv->mode = mode; + if (RIG_PASSBAND_NOCHANGE == width) { return retval; } @@ -456,3 +530,37 @@ static int jst145_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) return -RIG_EINVAL; } +static int jst145_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) +{ + char cmd[24]; + struct jst145_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: entered\n", __func__); + snprintf(cmd, sizeof(cmd), "X%c\r", ptt ? '1' : '0'); + priv->ptt = ptt; + return write_block(&rig->state.rigport, cmd, strlen(cmd)); +} + +static int jst145_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) +{ + char cmd[24]; + char pttstatus[24]; + int pttstatus_size = sizeof(pttstatus); + int retval; + + rig_debug(RIG_DEBUG_TRACE, "%s: entered\n", __func__); + + snprintf(cmd, sizeof(cmd), "X\r"); + retval = jrc_transaction(rig, cmd, strlen(cmd), pttstatus, &pttstatus_size); + + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: jrc_transaction error: %s\n", __func__, + rigerror(retval)); + return retval; + } + + if (pttstatus[1] == '1') { *ptt = RIG_PTT_ON; } + else { *ptt = RIG_PTT_OFF; } + + return RIG_OK; +}