From 65d201455d7c7887e2ec97177ef6729fa55d3746 Mon Sep 17 00:00:00 2001 From: Alexander Sack Date: Sat, 28 May 2011 10:22:44 -0400 Subject: [PATCH] Get firmware revision level from K3/KX3. Signed-off-by: Nate Bargmann --- kenwood/elecraft.c | 47 +++++++++++++++++++++++++++++++++++++++++++--- kenwood/kenwood.h | 1 + 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/kenwood/elecraft.c b/kenwood/elecraft.c index 640e00e56..37e4729f2 100644 --- a/kenwood/elecraft.c +++ b/kenwood/elecraft.c @@ -58,7 +58,7 @@ const struct confparams elecraft_ext_levels[] = { /* Private function declarations */ int verify_kenwood_id(RIG *rig, char *id); int elecraft_get_extension_level(RIG *rig, const char *cmd, int *ext_level); - +int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, char *fw_rev); /* Shared backend function definitions */ @@ -118,6 +118,11 @@ int elecraft_open(RIG *rig) rig_debug(RIG_DEBUG_ERR, "%s: K3 level is %d, %s\n", __func__, priv->k3_ext_lvl, elec_ext_id_str_lst[priv->k3_ext_lvl].id); + + err = elecraft_get_firmware_revision_level(rig, "RVM", priv->k3_fw_rev); + if (err != RIG_OK) + return err; + break; default: rig_debug(RIG_DEBUG_ERR, "%s: unrecognized rig model %d\n", @@ -200,11 +205,47 @@ int elecraft_get_extension_level(RIG *rig, const char *cmd, int *ext_level) if (strcmp(elec_ext_id_str_lst[i].id, bufptr) == 0) { *ext_level = elec_ext_id_str_lst[i].level; - rig_debug(RIG_DEBUG_TRACE, "%s: Extension level is %d, %s\n", - __func__, *ext_level, elec_ext_id_str_lst[i].id); + rig_debug(RIG_DEBUG_TRACE, "%s: %s extension level is %d, %s\n", + __func__, cmd, *ext_level, elec_ext_id_str_lst[i].id); } } return RIG_OK; } +/* Determine firmware revision level */ + +int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, char *fw_rev) +{ + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!rig || !fw_rev) + return -RIG_EINVAL; + + int err; + char *bufptr; + char buf[KENWOOD_MAX_BUF_LEN]; + size_t size = KENWOOD_MAX_BUF_LEN; + + err = kenwood_transaction(rig, cmd, sizeof(cmd), buf, &size); + if (err != RIG_OK) { + rig_debug(RIG_DEBUG_ERR, "%s: Cannot get firmeware revision level\n", __func__); + return err; + } + + /* Get the actual firmware revision number. */ + bufptr = &buf[0]; + + /* Skip the command string */ + bufptr += sizeof(cmd); + + /* Ignore leading zero's */ + while (bufptr && *bufptr == '0') { bufptr++; } + + /* Copy out */ + strncpy(fw_rev, bufptr, sizeof(bufptr)); + + rig_debug(RIG_DEBUG_TRACE, "%s: Elecraft firmware revision is %s\n", __func__, fw_rev); + + return RIG_OK; +} diff --git a/kenwood/kenwood.h b/kenwood/kenwood.h index f3c7ee3ea..bae46c404 100644 --- a/kenwood/kenwood.h +++ b/kenwood/kenwood.h @@ -71,6 +71,7 @@ struct kenwood_priv_data { int k2_ext_lvl; /* Initial K2 extension level */ int k3_ext_lvl; /* Initial K3 extension level */ int k2_md_rtty; /* K2 RTTY mode available flag, 1 = RTTY, 0 = N/A */ + char k3_fw_rev[KENWOOD_MAX_BUF_LEN]; /* K3 firmware revision level */ }; #define kenwood_caps(rig) ((struct kenwood_priv_caps *)(rig)->caps->priv)