Skip to content

Commit

Permalink
Elecraft K rigs now only emulate VFO selection for rigctl compatibility
Browse files Browse the repository at this point in the history
set_mode on VFOB should work now too
  • Loading branch information
mdblack98 committed Feb 28, 2021
1 parent a5db433 commit 1f23798
Showing 1 changed file with 57 additions and 68 deletions.
125 changes: 57 additions & 68 deletions rigs/kenwood/k3.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const struct rig_caps k3_caps =
RIG_MODEL(RIG_MODEL_K3),
.model_name = "K3",
.mfg_name = "Elecraft",
.version = BACKEND_VER ".6",
.version = BACKEND_VER ".7",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TRANSCEIVER,
Expand Down Expand Up @@ -334,7 +334,7 @@ const struct rig_caps k3s_caps =
RIG_MODEL(RIG_MODEL_K3S),
.model_name = "K3S",
.mfg_name = "Elecraft",
.version = BACKEND_VER ".5",
.version = BACKEND_VER ".6",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TRANSCEIVER,
Expand Down Expand Up @@ -484,7 +484,7 @@ const struct rig_caps k4_caps =
RIG_MODEL(RIG_MODEL_K4),
.model_name = "K4",
.mfg_name = "Elecraft",
.version = BACKEND_VER ".5",
.version = BACKEND_VER ".6",
.copyright = "LGPL",
.status = RIG_STATUS_ALPHA,
.rig_type = RIG_TYPE_TRANSCEIVER,
Expand Down Expand Up @@ -633,7 +633,7 @@ const struct rig_caps kx3_caps =
RIG_MODEL(RIG_MODEL_KX3),
.model_name = "KX3",
.mfg_name = "Elecraft",
.version = BACKEND_VER ".5",
.version = BACKEND_VER ".6",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TRANSCEIVER,
Expand Down Expand Up @@ -782,7 +782,7 @@ const struct rig_caps kx2_caps =
RIG_MODEL(RIG_MODEL_KX2),
.model_name = "KX2",
.mfg_name = "Elecraft",
.version = BACKEND_VER ".5",
.version = BACKEND_VER ".6",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rig_type = RIG_TYPE_TRANSCEIVER,
Expand Down Expand Up @@ -1131,7 +1131,15 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
width = pb_wid;
}

snprintf(cmd_s, sizeof(cmd_s), "BW%04ld", width / 10);
if (vfo == RIG_VFO_B)
{
snprintf(cmd_s, sizeof(cmd_s), "BW$%04ld", width / 10);
}
else
{
snprintf(cmd_s, sizeof(cmd_s), "BW%04ld", width / 10);
}

err = kenwood_transaction(rig, cmd_s, NULL, 0);

if (err != RIG_OK)
Expand All @@ -1157,91 +1165,72 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
return RIG_OK;
}


/* The K3 changes "VFOs" by swapping the contents of
* the upper display with the lower display. This function
* accomplishes this by sending the emulation command, SWT11, KX3 is SWT24;
* to the K3 to emulate a tap of the A/B button.
*/

int k3_set_vfo(RIG *rig, vfo_t vfo)
int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
int err;
// Does SWT11 work for the K4 or do we need to emulate set/get vfo?
char *cmd = "SWT11";
struct kenwood_priv_data *priv = rig->state.priv;
char *cmd = "MD";
int offset = 2;
int retval;
char buf[KENWOOD_MAX_BUF_LEN];
int kmode;

ENTERFUNC;

// we emulate vfo selection for some elecraft
if (priv->is_kx3 || priv->is_k4)
// get our mode
if (vfo == RIG_VFO_B)
{
rig->state.current_vfo = vfo;
return (RIG_OK);
cmd = "MD$";
offset = 3;
}

// vfo is toggle so we check first to see if we need to switch
vfo_t tvfo;
err = rig_get_vfo(rig, &tvfo);

if (err != RIG_OK)
retval = kenwood_safe_transaction(rig, cmd, buf, KENWOOD_MAX_BUF_LEN, offset + 1);
if (retval != RIG_OK)
{
RETURNFUNC(err);
RETURNFUNC(retval);
}

if (tvfo == vfo) { RETURNFUNC(RIG_OK); }

#if 0 // this doesn't seem to work and IC command VFO B indicator doesn't change

if (priv->is_kx3)
if (buf[offset] <= '9')
{

cmd = "SWT24";
kmode = buf[offset] - '0';
}
else
{
kmode = buf[offset] - 'A' + 10;
}

#endif

err = kenwood_transaction(rig, cmd, NULL, 0);
struct kenwood_priv_caps *caps = kenwood_caps(rig);
*mode = kenwood2rmode(kmode, caps->mode_table);

if (err != RIG_OK)
// now we get the bandwidth
cmd = "BW";
retval = kenwood_safe_transaction(rig, cmd, buf, KENWOOD_MAX_BUF_LEN, 7);
if (retval != RIG_OK)
{
RETURNFUNC(err);
RETURNFUNC(retval);
}
int twidth = 0;
sscanf(buf,"BW%d",&twidth);
*width = twidth;

RETURNFUNC(RIG_OK);
}

int k3_get_vfo(RIG *rig, vfo_t *vfo)
{
char buf[KENWOOD_MAX_BUF_LEN];
int ret;
struct kenwood_priv_data *priv = rig->state.priv;

if (priv->is_kx3 | priv->is_k4) // we emulate VFO set/get as SW24 and IC don't seem to work
{
*vfo = rig->state.current_vfo;
RETURNFUNC(RIG_OK);
}
/* Elecraft rigs don't really know about swappings vfos.
* We just emulate them so rigctl can work correctly.
*/

ret = write_block(&rig->state.rigport, "IC;", 3);
int k3_set_vfo(RIG *rig, vfo_t vfo)
{
ENTERFUNC;

if (ret != RIG_OK)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: Cannot write K3 IC value\n", __func__);
RETURNFUNC(ret);
}
// we emulate vfo selection for Elecraft
rig->state.current_vfo = vfo;

ret = read_block(&rig->state.rigport, buf, 8);
RETURNFUNC(RIG_OK);
}

if (ret != 8)
{
rig_debug(RIG_DEBUG_ERR, "%s: expected 8 bytes from '%s', got %d bytes\n",
__func__, buf, ret);
RETURNFUNC(-RIG_EPROTO);
}
int k3_get_vfo(RIG *rig, vfo_t *vfo)
{
ENTERFUNC;

if ((buf[6] & 0x02) == 0) { *vfo = RIG_VFO_B; }
else { *vfo = RIG_VFO_A; }
*vfo = rig->state.current_vfo;

RETURNFUNC(RIG_OK);
}
Expand Down

0 comments on commit 1f23798

Please sign in to comment.