Add power2mW and mW2power to netrigctl.c

pull/691/head
Mike Black W9MDB 2021-04-28 17:39:08 -05:00
rodzic 0b203c7e8f
commit 5473249e9a
2 zmienionych plików z 146 dodań i 1 usunięć

Wyświetl plik

@ -512,6 +512,7 @@ static int netrigctl_open(RIG *rig)
rig->caps->has_get_level = rs->has_get_level = strtoll(buf, NULL, 0);
#if 0 // don't think we need this anymore
if (rs->has_get_level & RIG_LEVEL_RAWSTR)
{
/* include STRENGTH because the remote rig may be able to
@ -520,6 +521,7 @@ static int netrigctl_open(RIG *rig)
rs->has_get_level |= RIG_LEVEL_STRENGTH;
rig->caps->has_get_level |= RIG_LEVEL_STRENGTH;
}
#endif
ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1);
@ -645,6 +647,44 @@ static int netrigctl_open(RIG *rig)
if (!has) { rig->caps->get_freq = NULL; }
}
else if (strcmp(setting, "has_set_conf") == 0)
{
int has = strtol(value, NULL, 0);
if (!has) { rig->caps->set_conf = NULL; }
}
else if (strcmp(setting, "has_get_conf") == 0)
{
int has = strtol(value, NULL, 0);
if (!has) { rig->caps->get_conf = NULL; }
}
#if 0 // for the future
else if (strcmp(setting, "has_set_trn") == 0)
{
int has = strtol(value, NULL, 0);
if (!has) { rig->caps->set_trn = NULL; }
}
else if (strcmp(setting, "has_get_trn") == 0)
{
int has = strtol(value, NULL, 0);
if (!has) { rig->caps->get_trn = NULL; }
}
#endif
else if (strcmp(setting, "has_power2mW") == 0)
{
int has = strtol(value, NULL, 0);
if (!has) { rig->caps->power2mW = NULL; }
}
else if (strcmp(setting, "has_mw2power") == 0)
{
int has = strtol(value, NULL, 0);
if (!has) { rig->caps->mW2power = NULL; }
}
else if (strcmp(setting, "timeout") == 0)
{
// use the rig's timeout value pluse 200ms for potential network delays
@ -2319,6 +2359,99 @@ static int netrigctl_set_vfo_opt(RIG *rig, int status)
return RIG_OK;
}
#if 0 // for the futurem -- would have to poll to get the pushed data
static int netrigctl_set_trn(RIG *rig, int trn)
{
char cmdbuf[32];
char buf[BUF_MAX];
int ret;
sprintf(cmdbuf, "\\set_trn %s\n", trn ? "ON" : "OFF");
ret = netrigctl_transaction(rig, cmdbuf, strlen(cmdbuf), buf);
if (ret < 0)
{
return -RIG_EPROTO;
}
return RIG_OK;
}
static int netrigctl_get_trn(RIG *rig, int *trn)
{
char cmdbuf[32];
char buf[BUF_MAX];
int ret;
ENTERFUNC;
sprintf(cmdbuf, "\\get_trn\n");
ret = netrigctl_transaction(rig, cmdbuf, strlen(cmdbuf), buf);
if (ret <= 0)
{
return -RIG_EPROTO;
}
if (strstr(buf,"OFF")) *trn = RIG_TRN_OFF;
else if (strstr(buf,"RIG")) *trn = RIG_TRN_RIG;
else if (strstr(buf,"POLL")) *trn = RIG_TRN_POLL;
else {
rig_debug(RIG_DEBUG_ERR, "%s: Expected OFF, RIG, or POLL, got '%s'\n", __func__, buf);
ret = -RIG_EINVAL;
}
RETURNFUNC(ret);
}
#endif
static int netrigctl_mW2power(RIG *rig, float *power, unsigned int mwpower,
freq_t freq, rmode_t mode)
{
char cmdbuf[32];
char buf[BUF_MAX];
int ret;
ENTERFUNC;
sprintf(cmdbuf, "\\mW2power %u %.0f %s\n", mwpower, freq, rig_strrmode(mode));
ret = netrigctl_transaction(rig, cmdbuf, strlen(cmdbuf), buf);
if (ret <= 0)
{
return -RIG_EPROTO;
}
*power = atof(buf);
RETURNFUNC(RIG_OK);
}
static int netrigctl_power2mW(RIG *rig, unsigned int *mwpower, float power,
freq_t freq, rmode_t mode)
{
char cmdbuf[32];
char buf[BUF_MAX];
int ret;
ENTERFUNC;
sprintf(cmdbuf, "\\power2mW %f %.0f %s\n", power, freq, rig_strrmode(mode));
ret = netrigctl_transaction(rig, cmdbuf, strlen(cmdbuf), buf);
if (ret <= 0)
{
return -RIG_EPROTO;
}
*mwpower = atof(buf);
RETURNFUNC(RIG_OK);
}
/*
* Netrigctl rig capabilities.
*/
@ -2328,7 +2461,7 @@ struct rig_caps netrigctl_caps =
RIG_MODEL(RIG_MODEL_NETRIGCTL),
.model_name = "NET rigctl",
.mfg_name = "Hamlib",
.version = "20210409.0",
.version = "20210428.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_OTHER,
@ -2427,4 +2560,9 @@ struct rig_caps netrigctl_caps =
.set_channel = netrigctl_set_channel,
.get_channel = netrigctl_get_channel,
.set_vfo_opt = netrigctl_set_vfo_opt,
//.set_trn = netrigctl_set_trn,
//.get_trn = netrigctl_get_trn,
.power2mW = netrigctl_power2mW,
.mW2power = netrigctl_mW2power,
};

Wyświetl plik

@ -4342,6 +4342,13 @@ declare_proto_rig(dump_state)
fprintf(fout, "has_get_vfo=%d\n", rig->caps->get_vfo != NULL);
fprintf(fout, "has_set_freq=%d\n", rig->caps->set_freq != NULL);
fprintf(fout, "has_get_freq=%d\n", rig->caps->get_freq != NULL);
fprintf(fout, "has_set_conf=%d\n", rig->caps->set_conf != NULL);
fprintf(fout, "has_get_conf=%d\n", rig->caps->get_conf != NULL);
// for the future
// fprintf(fout, "has_set_trn=%d\n", rig->caps->set_trn != NULL);
// fprintf(fout, "has_get_trn=%d\n", rig->caps->get_trn != NULL);
fprintf(fout, "has_power2mW=%d\n", rig->caps->power2mW != NULL);
fprintf(fout, "has_mW2power=%d\n", rig->caps->mW2power != NULL);
fprintf(fout, "timeout=%d\n", rig->caps->timeout);
fprintf(fout, "done\n");
}