Re-do get_rit for has_rit2 rigs

If this works should be able to change get_rit in TS480 to the generic kenwood get_rit
https://github.com/Hamlib/Hamlib/issues/677
pull/691/head
Mike Black W9MDB 2021-04-25 23:19:11 -05:00
rodzic 25eb70d90d
commit 7ea0a49dcd
2 zmienionych plików z 124 dodań i 35 usunięć

Wyświetl plik

@ -781,6 +781,18 @@ int kenwood_open(RIG *rig)
"%s: no response to get_id from rig...continuing anyways.\n", __func__);
}
if (RIG_IS_TS2000
|| RIG_IS_TS480
|| RIG_IS_TS590S
|| RIG_IS_TS590SG
|| RIG_IS_TS890S
|| RIG_IS_TS990S)
{
// rig has Set 2 RIT/XIT function
rig_debug(RIG_DEBUG_TRACE, "%s: rig has_rit2\n", __func__);
priv->has_rit2 = 1;
}
if (RIG_IS_TS590S)
{
/* we need the firmware version for these rigs to deal with f/w defects */
@ -1717,41 +1729,77 @@ int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit)
*/
int kenwood_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit)
{
char buf[4];
char buf[32];
int retval, i;
shortfreq_t curr_rit;
int diff;
int rit_enabled;
int xit_enabled;
struct kenwood_priv_data *priv = rig->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: vfo=%s, rit=%ld\n",
__func__,
rig_strvfo(vfo), rit);
retval = kenwood_get_rit(rig, vfo, &curr_rit);
// RC clear command cannot be executed if RIT/XIT is not enabled
retval = kenwood_get_func(rig, vfo, RIG_FUNC_RIT, &rit_enabled);
if (retval != RIG_OK)
{
RETURNFUNC(retval);
}
// we'll set the rigs that have a rit step setting to 10Hz steps
retval = kenwood_transaction(rig, "RC;RU00010", NULL, 0);
if (!rit_enabled)
{
retval = kenwood_get_func(rig, vfo, RIG_FUNC_XIT, &xit_enabled);
if (retval != RIG_OK)
{
RETURNFUNC(retval);
}
}
if (!rit_enabled && !xit_enabled)
{
retval = kenwood_set_func(rig, vfo, RIG_FUNC_RIT, 1);
if (retval != RIG_OK)
{
RETURNFUNC(retval);
}
}
// zero out rit
// we might be able to read rit and just do the difference
// see if anybody ever wants that or complain about this being slow
retval = kenwood_transaction(rig, "RC", NULL, 0);
if (retval != RIG_OK)
{
RETURNFUNC(retval);
}
if (rit == 0) { RETURNFUNC(RIG_OK); } // we're done here
snprintf(buf, sizeof(buf), "R%c", (rit > 0) ? 'U' : 'D');
diff = labs((rit + rit >= 0 ? 5 : -5) / 10); // round to nearest
rig_debug(RIG_DEBUG_TRACE, "%s: rit change loop=%d\n", __func__, diff);
for (i = 0; i < diff; i++)
if (rit == 0)
{
RETURNFUNC(RIG_OK);
}
if (priv->has_rit2)
{
snprintf(buf, sizeof(buf), "R%c%05d", (rit > 0) ? 'U' : 'D', abs((int) rit));
retval = kenwood_transaction(rig, buf, NULL, 0);
}
else
{
snprintf(buf, sizeof(buf), "R%c", (rit > 0) ? 'U' : 'D');
diff = labs((rit + rit >= 0 ? 5 : -5) / 10); // round to nearest
rig_debug(RIG_DEBUG_TRACE, "%s: rit change loop=%d\n", __func__, diff);
for (i = 0; i < diff; i++)
{
retval = kenwood_transaction(rig, buf, NULL, 0);
}
}
RETURNFUNC(retval);
}
@ -1849,6 +1897,7 @@ static int kenwood_set_filter_width(RIG *rig, rmode_t mode, pbwidth_t width)
if (caps->filter_width[i].modes & mode)
{
selected_filter_width = &caps->filter_width[i];
if (caps->filter_width[i].width_hz >= width)
{
break;
@ -2014,10 +2063,12 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
else if (RIG_IS_TS480)
{
err = kenwood_set_filter_width(rig, mode, width);
if (err != RIG_OK)
{
// Ignore errors as non-fatal
rig_debug(RIG_DEBUG_ERR, "%s: error setting filter width, error: %d\n", __func__, err);
rig_debug(RIG_DEBUG_ERR, "%s: error setting filter width, error: %d\n",
__func__, err);
}
}
@ -2100,6 +2151,7 @@ static int kenwood_get_filter_width(RIG *rig, rmode_t mode, pbwidth_t *width)
}
retval = kenwood_safe_transaction(rig, "FW", ackbuf, sizeof(ackbuf), 6);
if (retval != RIG_OK)
{
RETURNFUNC(retval);
@ -2238,10 +2290,12 @@ int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
if (RIG_IS_TS480)
{
retval = kenwood_get_filter_width(rig, *mode, width);
if (retval != RIG_OK)
{
// Ignore errors as non-fatal
rig_debug(RIG_DEBUG_ERR, "%s: error getting filter width, error: %d\n", __func__, retval);
rig_debug(RIG_DEBUG_ERR, "%s: error getting filter width, error: %d\n",
__func__, retval);
*width = rig_passband_normal(rig, *mode);
}
}
@ -2474,7 +2528,8 @@ static int kenwood_get_power_minmax(RIG *rig, int *power_now, int *power_min,
RETURNFUNC(RIG_OK);
}
static int kenwood_find_slope_filter_for_frequency(RIG *rig, vfo_t vfo, struct kenwood_slope_filter *filter, int frequency_hz, int *value)
static int kenwood_find_slope_filter_for_frequency(RIG *rig, vfo_t vfo,
struct kenwood_slope_filter *filter, int frequency_hz, int *value)
{
int retval;
int i;
@ -2492,13 +2547,17 @@ static int kenwood_find_slope_filter_for_frequency(RIG *rig, vfo_t vfo, struct k
return -RIG_ENAVAIL;
}
retval = rig_get_cache(rig, vfo, &freq, &cache_ms_freq, &mode, &cache_ms_mode, &width, &cache_ms_width);
retval = rig_get_cache(rig, vfo, &freq, &cache_ms_freq, &mode, &cache_ms_mode,
&width, &cache_ms_width);
if (retval != RIG_OK)
{
return -RIG_EINVAL;
}
retval = rig_get_ext_func(rig, vfo, TOK_FUNC_FILTER_WIDTH_DATA, &data_mode_filter_active);
retval = rig_get_ext_func(rig, vfo, TOK_FUNC_FILTER_WIDTH_DATA,
&data_mode_filter_active);
if (retval != RIG_OK)
{
// Ignore errors, e.g. if the command is not supported
@ -2507,13 +2566,15 @@ static int kenwood_find_slope_filter_for_frequency(RIG *rig, vfo_t vfo, struct k
for (i = 0; filter[i].value >= 0; i++)
{
if (filter[i].modes & mode && filter[i].data_mode_filter == data_mode_filter_active)
if (filter[i].modes & mode
&& filter[i].data_mode_filter == data_mode_filter_active)
{
if (filter[i].frequency_hz >= frequency_hz)
{
*value = filter[i].value;
return RIG_OK;
}
last_filter = &filter[i];
}
}
@ -2527,7 +2588,8 @@ static int kenwood_find_slope_filter_for_frequency(RIG *rig, vfo_t vfo, struct k
return -RIG_EINVAL;
}
static int kenwood_find_slope_filter_for_value(RIG *rig, vfo_t vfo, struct kenwood_slope_filter *filter, int value, int *frequency_hz)
static int kenwood_find_slope_filter_for_value(RIG *rig, vfo_t vfo,
struct kenwood_slope_filter *filter, int value, int *frequency_hz)
{
int retval;
int i;
@ -2544,13 +2606,17 @@ static int kenwood_find_slope_filter_for_value(RIG *rig, vfo_t vfo, struct kenwo
return -RIG_ENAVAIL;
}
retval = rig_get_cache(rig, vfo, &freq, &cache_ms_freq, &mode, &cache_ms_mode, &width, &cache_ms_width);
retval = rig_get_cache(rig, vfo, &freq, &cache_ms_freq, &mode, &cache_ms_mode,
&width, &cache_ms_width);
if (retval != RIG_OK)
{
return -RIG_EINVAL;
}
retval = rig_get_ext_func(rig, vfo, TOK_FUNC_FILTER_WIDTH_DATA, &data_mode_filter_active);
retval = rig_get_ext_func(rig, vfo, TOK_FUNC_FILTER_WIDTH_DATA,
&data_mode_filter_active);
if (retval != RIG_OK)
{
// Ignore errors, e.g. if the command is not supported
@ -2559,7 +2625,8 @@ static int kenwood_find_slope_filter_for_value(RIG *rig, vfo_t vfo, struct kenwo
for (i = 0; filter[i].value >= 0; i++)
{
if (filter[i].modes & mode && filter[i].data_mode_filter == data_mode_filter_active)
if (filter[i].modes & mode
&& filter[i].data_mode_filter == data_mode_filter_active)
{
if (filter[i].value == value)
{
@ -2750,7 +2817,9 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
break;
case RIG_LEVEL_SLOPE_HIGH:
retval = kenwood_find_slope_filter_for_frequency(rig, vfo, caps->slope_filter_high, val.i, &kenwood_val);
retval = kenwood_find_slope_filter_for_frequency(rig, vfo,
caps->slope_filter_high, val.i, &kenwood_val);
if (retval != RIG_OK)
{
// Fall back to using raw values
@ -2758,6 +2827,7 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
{
RETURNFUNC(-RIG_EINVAL);
}
kenwood_val = val.i;
}
@ -2765,7 +2835,9 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
break;
case RIG_LEVEL_SLOPE_LOW:
retval = kenwood_find_slope_filter_for_frequency(rig, vfo, caps->slope_filter_low, val.i, &kenwood_val);
retval = kenwood_find_slope_filter_for_frequency(rig, vfo,
caps->slope_filter_low, val.i, &kenwood_val);
if (retval != RIG_OK)
{
// Fall back to using raw values
@ -2773,6 +2845,7 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
{
RETURNFUNC(-RIG_EINVAL);
}
kenwood_val = val.i;
}
@ -2806,6 +2879,7 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
{
kenwood_val = val.f * 100.0f;
}
snprintf(levelbuf, sizeof(levelbuf), "PL%03d%03d", kenwood_val, kenwood_val);
break;
@ -3181,7 +3255,9 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
value = atoi(&lvlbuf[2]);
retval = kenwood_find_slope_filter_for_value(rig, vfo, caps->slope_filter_low, value, &val->i);
retval = kenwood_find_slope_filter_for_value(rig, vfo, caps->slope_filter_low,
value, &val->i);
if (retval != RIG_OK)
{
if (retval == -RIG_ENAVAIL)
@ -3194,6 +3270,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
RETURNFUNC(retval);
}
}
break;
case RIG_LEVEL_SLOPE_HIGH:
@ -3206,7 +3283,9 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
value = atoi(&lvlbuf[2]);
retval = kenwood_find_slope_filter_for_value(rig, vfo, caps->slope_filter_high, value, &val->i);
retval = kenwood_find_slope_filter_for_value(rig, vfo, caps->slope_filter_high,
value, &val->i);
if (retval != RIG_OK)
{
if (retval == -RIG_ENAVAIL)
@ -3219,6 +3298,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
RETURNFUNC(retval);
}
}
break;
case RIG_LEVEL_CWPITCH:
@ -3244,7 +3324,8 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
sscanf(lvlbuf + 2, "%d", &val->i);
break;
case RIG_LEVEL_COMP: {
case RIG_LEVEL_COMP:
{
int raw_value;
retval = kenwood_safe_transaction(rig, "PL", lvlbuf, 50, 8);
@ -3263,10 +3344,12 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
val->f = (float) raw_value / 100.0f;
}
break;
}
case RIG_LEVEL_VOXDELAY: {
case RIG_LEVEL_VOXDELAY:
{
int raw_value;
retval = kenwood_safe_transaction(rig, "VD", lvlbuf, 50, 6);
@ -3282,7 +3365,8 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
break;
}
case RIG_LEVEL_VOXGAIN: {
case RIG_LEVEL_VOXGAIN:
{
int raw_value;
retval = kenwood_safe_transaction(rig, "VG", lvlbuf, 50, 5);
@ -3297,7 +3381,8 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
break;
}
case RIG_LEVEL_BKIN_DLYMS: {
case RIG_LEVEL_BKIN_DLYMS:
{
int raw_value;
retval = kenwood_safe_transaction(rig, "SD", lvlbuf, 50, 6);
@ -3600,7 +3685,8 @@ int kenwood_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
*status = respbuf[3] != '0' ? 1 : 0;
RETURNFUNC(RIG_OK);
case RIG_FUNC_FBKIN: {
case RIG_FUNC_FBKIN:
{
int raw_value;
retval = kenwood_safe_transaction(rig, "SD", respbuf, 20, 6);
@ -4172,7 +4258,8 @@ int kenwood_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
RETURNFUNC(-RIG_EINVAL);
}
if (RIG_IS_TS480 || RIG_IS_TS590S || RIG_IS_TS590SG || RIG_IS_TS990S || RIG_IS_TS2000)
if (RIG_IS_TS480 || RIG_IS_TS590S || RIG_IS_TS590SG || RIG_IS_TS990S
|| RIG_IS_TS2000)
{
expected = 4;
}
@ -4188,7 +4275,8 @@ int kenwood_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
RETURNFUNC(retval);
}
if ((RIG_IS_TS990S && RIG_VFO_SUB == vfo) || (RIG_IS_TS2000 && RIG_VFO_SUB == vfo))
if ((RIG_IS_TS990S && RIG_VFO_SUB == vfo) || (RIG_IS_TS2000
&& RIG_VFO_SUB == vfo))
{
offs = 3;
}

Wyświetl plik

@ -28,7 +28,7 @@
#include "token.h"
#include "misc.h"
#define BACKEND_VER "20210423"
#define BACKEND_VER "20210425"
#define EOM_KEN ';'
#define EOM_TH '\r'
@ -154,6 +154,7 @@ struct kenwood_priv_data
char last_if_response[KENWOOD_MAX_BUF_LEN];
int poweron; /* to avoid powering on more than once */
int ag_format; /* which AG command is being used...see LEVEL_AF in kenwood.c*/
int has_rit2; /* rig has set 2 rit command -- can set rit 0-99999 directly */
int micgain_min, micgain_max; /* varies by rig so we figure it out automagically */
int is_k2;
int is_k3;