From 34492271bc21c307a5ffbbeff0fbf016fdf8db83 Mon Sep 17 00:00:00 2001 From: Wouter van Gulik Date: Wed, 8 Sep 2021 21:33:02 +0200 Subject: [PATCH 1/5] ft817.c: Only get dig mode when needed. This improves getting frequency and mode because we can skip reading EEPROM if not needed. --- rigs/yaesu/ft817.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index eda357479..90ca60cfd 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -773,14 +773,25 @@ static int ft817_get_status(RIG *rig, int status) { case FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS: { - unsigned char dig_mode; - if ((n = ft817_read_eeprom(rig, 0x0065, &dig_mode)) < 0) + /* Only in digimode we need fetch to extra bits from EEPROM. + * This save communication cycle for all other modes. + * Because mode and frequency are shared this saves also when + * getting the frequency. */ + switch (p->fm_status[4] & 0x7f) { - return n; - } + unsigned char dig_mode; + case 0x0a: + if ((n = ft817_read_eeprom(rig, 0x0065, &dig_mode)) < 0) + { + return n; + } - /* Top 3 bit define the digi mode */ - p->dig_mode = dig_mode >> 5; + /* Top 3 bit define the digi mode */ + p->dig_mode = dig_mode >> 5; + + default: + break; + } } break; From 90f27ac7aa7a24eeda2c6ca19297f8ad9544c5fd Mon Sep 17 00:00:00 2001 From: Wouter van Gulik Date: Wed, 8 Sep 2021 21:36:24 +0200 Subject: [PATCH 2/5] ft817.c: Use ft817_get_ptt instead of open coding it. --- rigs/yaesu/ft817.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index 90ca60cfd..f53eb2995 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -951,22 +951,26 @@ static int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) static int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) { struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; + ptt_t ptt; int n; rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__); - if (check_cache_timeout(&p->tx_status_tv)) - if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_STATUS)) < 0) - { - return n; - } + n = ft817_get_ptt(rig, 0, &ptt); + if (n != RIG_OK) + { + return n; + } - if (p->tx_status & 0x80) + /* Check if rig is in TX mode */ + if (ptt == RIG_PTT_OFF) { // TX status not valid when in RX unsigned char c; - if ((n = ft817_read_eeprom(rig, 0x007a, &c)) < 0) /* get split status */ + /* Get split status from EEPROM */ + n = ft817_read_eeprom(rig, 0x7a, &c); + if (n != RIG_OK) { return n; } From 759cbbed3beda49b4ee2f9591b8240ba724c86cc Mon Sep 17 00:00:00 2001 From: Wouter van Gulik Date: Wed, 8 Sep 2021 22:14:34 +0200 Subject: [PATCH 3/5] ft817.c: Improve get_ptt by fetching TX_STATUS explicitly, instead of doing a manual cache timeout. Also be consistent: if we allow set_ptt to be rejected then also allow get_tx_status en get_ptt to be rejected without failing. Stop settings ptt_response to -1; it is only set when we got a reply so it is a sane value or the default, no need set it again. --- rigs/yaesu/ft817.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index f53eb2995..e45f4d9e1 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -1514,22 +1514,33 @@ static int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { int n; n = ft817_send_cmd(rig, index); - - rig_force_cache_timeout( - &((struct ft817_priv_data *)rig->state.priv)->tx_status_tv); - if (n < 0 && n != -RIG_ERJCTED) { + rig_debug(RIG_DEBUG_ERR, "%s: send ptt cmd failed\n", __func__); return n; } - if (ft817_get_ptt(rig, vfo, &ptt_response) != RIG_OK) + /* Read TX status it contains the PTT flag. + * Use TX_STATUS instead of ft817_get_ptt to skip the cache. */ + n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_STATUS); + if (n < 0 && n != -RIG_ERJCTED) { - ptt_response = -1; + rig_debug(RIG_DEBUG_ERR, "%s: get ptt cmd failed\n", __func__); + return n; + } + + /* Should be in cache now! But if above command was rejected + * we will still try again here. */ + n = ft817_get_ptt(rig, vfo, &ptt_response); + if (n < 0 && n != -RIG_ERJCTED) + { + rig_debug(RIG_DEBUG_ERR, "%s: get ptt cmd failed\n", __func__); + return n; } if (ptt_response != ptt) { + rig_debug(RIG_DEBUG_TRACE, "%s: ptt not requested level, retry\n", __func__); hl_usleep(1000l * FT817_RETRY_DELAY); // Wait before next try. Helps with slower rigs cloning FT817 protocol (e.g. MCHF) } From 7d605c86bdd9d0bf454ced8ae12cc242add6fa4b Mon Sep 17 00:00:00 2001 From: Wouter van Gulik Date: Sun, 12 Sep 2021 22:16:28 +0200 Subject: [PATCH 4/5] Split on/off is used so drop comment saying it is not yet --- rigs/yaesu/ft817.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index e45f4d9e1..21b059fe4 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -39,9 +39,6 @@ * - received ctcss/dcs matched (yes/no flag) TBC * * - TX status command returns info that is not used: - * - split on/off flag; actually this could have been used - * for get_split_vfo, but the flag is valid only when - * PTT is ON. * - high swr flag * * Todo / tocheck list (oz9aec): From 345729421d2b7a19c8f83ffe1a43f5d79855e671 Mon Sep 17 00:00:00 2001 From: Wouter van Gulik Date: Mon, 6 Sep 2021 21:49:09 +0200 Subject: [PATCH 5/5] ft817: Only set the VFO after a successful read. --- rigs/yaesu/ft817.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index 21b059fe4..03070e487 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -1370,7 +1370,6 @@ static int ft817_send_icmd(RIG *rig, int index, unsigned char *data) static int ft817_get_vfo(RIG *rig, vfo_t *vfo) { unsigned char c; - *vfo = RIG_VFO_B; rig_debug(RIG_DEBUG_VERBOSE, "%s: called \n", __func__); @@ -1379,7 +1378,14 @@ static int ft817_get_vfo(RIG *rig, vfo_t *vfo) return -RIG_EPROTO; } - if ((c & 0x1) == 0) { *vfo = RIG_VFO_A; } + if ((c & 0x1) == 0) + { + *vfo = RIG_VFO_A; + } + else + { + *vfo = RIG_VFO_B; + } return RIG_OK; }