Skip to content

Commit

Permalink
Enable level_gran[] checking for all calls to kenwood_set_level.
Browse files Browse the repository at this point in the history
Part of issue Hamlib#1144
  • Loading branch information
GeoBaltz committed Jul 10, 2023
1 parent 649f094 commit b2ea9da
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions rigs/kenwood/kenwood.c
Expand Up @@ -3151,13 +3151,16 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
int i, kenwood_val, len, result;
struct kenwood_priv_data *priv = rig->state.priv;
struct kenwood_priv_caps *caps = kenwood_caps(rig);
gran_t *level_info;

ENTERFUNC;

/* Check input parameter against level_gran limits */
result = check_level_param(rig, level, val, &level_info);
if (result != RIG_OK) { RETURNFUNC(result); }

if (RIG_LEVEL_IS_FLOAT(level))
{
if (val.f > 1.0) { RETURNFUNC(-RIG_EINVAL); }

kenwood_val = val.f * 255;
}
else
Expand Down Expand Up @@ -3240,8 +3243,6 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
if (retval != RIG_OK) { RETURNFUNC(retval); }
}

if (val.f > 1.0 || val.f < 0) { RETURNFUNC(-RIG_EINVAL); }

// is micgain_min ever > 0 ??
kenwood_val = val.f * (priv->micgain_max - priv->micgain_min) +
priv->micgain_min;
Expand Down Expand Up @@ -3381,15 +3382,6 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)

case RIG_LEVEL_CWPITCH:
{
gran_t *level_info;

retval = check_level_param(rig, level, val, &level_info);

if (retval != RIG_OK)
{
RETURNFUNC(retval);
}

/* Newer rigs have an extra digit of pitch factor */
int len = (RIG_IS_TS890S || RIG_IS_TS990S) ? 3 : 2;

Expand All @@ -3401,23 +3393,11 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
}

case RIG_LEVEL_KEYSPD:
if (val.i > 60 || val.i < 5)
{
RETURNFUNC(-RIG_EINVAL);
}

SNPRINTF(levelbuf, sizeof(levelbuf), "KS%03d", val.i);
break;

case RIG_LEVEL_COMP:
if (RIG_IS_TS990S)
{
kenwood_val = val.f * 255.0f;
}
else
{
kenwood_val = val.f * 100.0f;
}
kenwood_val = (int)((val.f / level_info->step.f) + 0.5f);

SNPRINTF(levelbuf, sizeof(levelbuf), "PL%03d%03d", kenwood_val, kenwood_val);
break;
Expand Down

0 comments on commit b2ea9da

Please sign in to comment.