kopia lustrzana https://github.com/Hamlib/Hamlib
Fix FLRig get_bwA/B for rigs that do not have get_bwA/b
https://github.com/Hamlib/Hamlib/issues/1427pull/1432/head
rodzic
e19bdc3d56
commit
b1b567d64a
|
@ -118,6 +118,9 @@ struct flrig_priv_data
|
||||||
value_t parms[RIG_SETTING_MAX];
|
value_t parms[RIG_SETTING_MAX];
|
||||||
struct ext_list *ext_parms;
|
struct ext_list *ext_parms;
|
||||||
int get_SWR;
|
int get_SWR;
|
||||||
|
int has_get_modeB; /* True if this function is available */
|
||||||
|
int has_get_bwB; /* True if this function is available */
|
||||||
|
int has_set_bwB; /* True if this function is available */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* level's and parm's tokens */
|
/* level's and parm's tokens */
|
||||||
|
@ -140,7 +143,7 @@ const struct rig_caps flrig_caps =
|
||||||
RIG_MODEL(RIG_MODEL_FLRIG),
|
RIG_MODEL(RIG_MODEL_FLRIG),
|
||||||
.model_name = "FLRig",
|
.model_name = "FLRig",
|
||||||
.mfg_name = "FLRig",
|
.mfg_name = "FLRig",
|
||||||
.version = "20231110.0",
|
.version = "20231113.0",
|
||||||
.copyright = "LGPL",
|
.copyright = "LGPL",
|
||||||
.status = RIG_STATUS_STABLE,
|
.status = RIG_STATUS_STABLE,
|
||||||
.rig_type = RIG_TYPE_TRANSCEIVER,
|
.rig_type = RIG_TYPE_TRANSCEIVER,
|
||||||
|
@ -863,6 +866,21 @@ static int flrig_open(RIG *rig)
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: getmodeA is available\n", __func__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: getmodeA is available\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* see if get_modeB is available */
|
||||||
|
retval = flrig_transaction(rig, "rig.get_modeB", NULL, value, sizeof(value));
|
||||||
|
|
||||||
|
if (retval == RIG_ENAVAIL) // must not have it
|
||||||
|
{
|
||||||
|
priv->has_get_modeB = 0;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: getmodeB is not available=%s\n", __func__,
|
||||||
|
value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
priv->has_get_modeB = 1;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: getmodeB is available\n", __func__);
|
||||||
|
}
|
||||||
|
|
||||||
freq_t freq;
|
freq_t freq;
|
||||||
retval = flrig_get_freq(rig, RIG_VFO_CURR, &freq);
|
retval = flrig_get_freq(rig, RIG_VFO_CURR, &freq);
|
||||||
|
|
||||||
|
@ -902,6 +920,36 @@ static int flrig_open(RIG *rig)
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: set_bwA is available=%s\n", __func__, value);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: set_bwA is available=%s\n", __func__, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* see if get_bwB is available */
|
||||||
|
retval = flrig_transaction(rig, "rig.get_bwB", NULL, value, sizeof(value));
|
||||||
|
|
||||||
|
if (retval == RIG_ENAVAIL) // must not have it
|
||||||
|
{
|
||||||
|
priv->has_get_bwB = 0;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: get_bwB is not available=%s\n", __func__,
|
||||||
|
value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
priv->has_get_bwB = 1;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: get_bwB is available=%s\n", __func__, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* see if set_bwA is available */
|
||||||
|
retval = flrig_transaction(rig, "rig.set_bwB", NULL, value, sizeof(value));
|
||||||
|
|
||||||
|
if (retval == RIG_ENAVAIL) // must not have it
|
||||||
|
{
|
||||||
|
priv->has_set_bwB = 0;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: set_bwB is not available=%s\n", __func__,
|
||||||
|
value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
priv->has_set_bwB = 1;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: set_bwB is available=%s\n", __func__, value);
|
||||||
|
}
|
||||||
|
|
||||||
retval = flrig_transaction(rig, "rig.get_AB", NULL, value, sizeof(value));
|
retval = flrig_transaction(rig, "rig.get_AB", NULL, value, sizeof(value));
|
||||||
|
|
||||||
if (retval != RIG_OK) { RETURNFUNC(retval); }
|
if (retval != RIG_OK) { RETURNFUNC(retval); }
|
||||||
|
@ -1599,6 +1647,8 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__,
|
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__,
|
||||||
rig_strvfo(vfo));
|
rig_strvfo(vfo));
|
||||||
|
|
||||||
|
*width = 0;
|
||||||
|
|
||||||
if (check_vfo(vfo) == FALSE)
|
if (check_vfo(vfo) == FALSE)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
|
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
|
||||||
|
@ -1655,7 +1705,7 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
/* so we may not be 100% accurate if op is twiddling knobs */
|
/* so we may not be 100% accurate if op is twiddling knobs */
|
||||||
cmdp = "rig.get_modeA";
|
cmdp = "rig.get_modeA";
|
||||||
|
|
||||||
if (vfo == RIG_VFO_B) { cmdp = "rig.get_modeB"; }
|
if (priv->has_get_modeB && vfo == RIG_VFO_B) { cmdp = "rig.get_modeB"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value));
|
retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value));
|
||||||
|
@ -1692,10 +1742,6 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
/* vfo B may not be getting polled though in FLRig */
|
/* vfo B may not be getting polled though in FLRig */
|
||||||
/* so we may not be 100% accurate if op is twiddling knobs */
|
/* so we may not be 100% accurate if op is twiddling knobs */
|
||||||
cmdp = "rig.get_bwA";
|
cmdp = "rig.get_bwA";
|
||||||
|
|
||||||
if (vfo == RIG_VFO_B) { cmdp = "rig.get_bwB"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value));
|
retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value));
|
||||||
|
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -1703,6 +1749,20 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
RETURNFUNC(retval);
|
RETURNFUNC(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (priv->has_get_bwB && vfo == RIG_VFO_B)
|
||||||
|
{
|
||||||
|
cmdp = "rig.get_bwB";
|
||||||
|
retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value));
|
||||||
|
|
||||||
|
if (retval != RIG_OK)
|
||||||
|
{
|
||||||
|
RETURNFUNC(retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_TRACE, "%s: mode=%s width='%s'\n", __func__,
|
rig_debug(RIG_DEBUG_TRACE, "%s: mode=%s width='%s'\n", __func__,
|
||||||
rig_strrmode(*mode), value);
|
rig_strrmode(*mode), value);
|
||||||
|
|
||||||
|
@ -2114,12 +2174,14 @@ static int flrig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
||||||
RETURNFUNC(RIG_OK);
|
RETURNFUNC(RIG_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
float mtr;
|
float mtr;
|
||||||
float swr;
|
float swr;
|
||||||
} swrpair;
|
} swrpair;
|
||||||
|
|
||||||
static swrpair swrtbl[] = {
|
static swrpair swrtbl[] =
|
||||||
|
{
|
||||||
{0.0, 1.0},
|
{0.0, 1.0},
|
||||||
{10.5, 1.5},
|
{10.5, 1.5},
|
||||||
{23.0, 2.0},
|
{23.0, 2.0},
|
||||||
|
@ -2129,21 +2191,29 @@ static swrpair swrtbl[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to interpolate SWR from MTR
|
// Function to interpolate SWR from MTR
|
||||||
float interpolateSWR(float mtr) {
|
float interpolateSWR(float mtr)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < sizeof(swrtbl)/sizeof(swrpair) - 1; i++) {
|
|
||||||
if (mtr == swrtbl[i].mtr) {
|
for (i = 0; i < sizeof(swrtbl) / sizeof(swrpair) - 1; i++)
|
||||||
|
{
|
||||||
|
if (mtr == swrtbl[i].mtr)
|
||||||
|
{
|
||||||
// Exact match
|
// Exact match
|
||||||
return swrtbl[i].swr;
|
return swrtbl[i].swr;
|
||||||
}
|
}
|
||||||
if (mtr < swrtbl[i + 1].mtr) {
|
|
||||||
|
if (mtr < swrtbl[i + 1].mtr)
|
||||||
|
{
|
||||||
// Perform linear interpolation
|
// Perform linear interpolation
|
||||||
float slope = (swrtbl[i + 1].swr - swrtbl[i].swr) / (swrtbl[i + 1].mtr - swrtbl[i].mtr);
|
float slope = (swrtbl[i + 1].swr - swrtbl[i].swr) / (swrtbl[i + 1].mtr -
|
||||||
|
swrtbl[i].mtr);
|
||||||
float swr = round((swrtbl[i].swr + slope * (mtr - swrtbl[i].mtr)) * 10) / 10.0;
|
float swr = round((swrtbl[i].swr + slope * (mtr - swrtbl[i].mtr)) * 10) / 10.0;
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: swr=%f\n", __func__, swr);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: swr=%f\n", __func__, swr);
|
||||||
return swr;
|
return swr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If mtr is not within the range of values in the table, you could choose to return an error or extrapolate
|
// If mtr is not within the range of values in the table, you could choose to return an error or extrapolate
|
||||||
return 10; // Example er
|
return 10; // Example er
|
||||||
}
|
}
|
||||||
|
@ -2175,8 +2245,10 @@ static int flrig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
||||||
|
|
||||||
case RIG_LEVEL_SWR:
|
case RIG_LEVEL_SWR:
|
||||||
cmd = "rig.get_swrmeter";
|
cmd = "rig.get_swrmeter";
|
||||||
|
|
||||||
// we'll try get_SWR at least once to see if it works
|
// we'll try get_SWR at least once to see if it works
|
||||||
if (priv->get_SWR) cmd = "rig.get_SWR";
|
if (priv->get_SWR) { cmd = "rig.get_SWR"; }
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RIG_LEVEL_RFPOWER: cmd = "rig.get_power"; break;
|
case RIG_LEVEL_RFPOWER: cmd = "rig.get_power"; break;
|
||||||
|
@ -2211,11 +2283,17 @@ static int flrig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
||||||
case RIG_LEVEL_SWR:
|
case RIG_LEVEL_SWR:
|
||||||
{
|
{
|
||||||
if (priv->get_SWR)
|
if (priv->get_SWR)
|
||||||
|
{
|
||||||
val->f = atof(value);
|
val->f = atof(value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
val->f = interpolateSWR(atoi(value));
|
val->f = interpolateSWR(atoi(value));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RIG_LEVEL_STRENGTH:
|
case RIG_LEVEL_STRENGTH:
|
||||||
val->i = atoi(value) - 54;
|
val->i = atoi(value) - 54;
|
||||||
//if (val->i > 0) val->i /= 10;
|
//if (val->i > 0) val->i /= 10;
|
||||||
|
|
Ładowanie…
Reference in New Issue