[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. 5ae848c48f1810fa81deb
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: Michael B. <mdb...@us...> - 2020-10-03 05:25:54
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via 5ae848c48f1810fa81deb8365cb89e552740c8b7 (commit) via 86949c4ef711d5e4baa86241d7e7579bdffef1e3 (commit) via ba943ae4b9209dfb7f4ed2cdb3efff679c71b900 (commit) via 293a844c41945db98dc6d8fa3036fec598de56a0 (commit) from 0576a01ec2b73cafec6f1ea5506d014fa82d75ff (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5ae848c48f1810fa81deb8365cb89e552740c8b7 Author: Michael Black W9MDB <mdb...@ya...> Date: Sat Oct 3 00:16:02 2020 -0500 Implemented dynamic detection of RFPOWER levels for Kenwoods Need to remove RFPOWER customizations from other Kenwood backends now Need to do this same thing for MICGAIN https://github.com/Hamlib/Hamlib/issues/389 diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 374b9cff..4dc3ca1c 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -2179,6 +2179,63 @@ int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return RIG_OK; } +/* kenwood_get_power_minmax + * Kenwood rigs have different power levels by mode and by rig + * This routine relies on the idea that setting the power + * to 0 and 255 will result in the minimum and maximum values being set + * If a rig doesn't behave this way then customize inside that rig's backend +*/ +static int kenwood_get_power_minmax(RIG *rig, int *power_now, int *power_min, + int *power_max, + int restore) +{ + int retval; + char levelbuf[19]; + // read power_now, set 0, read power_min, set 255, read_power_max; set 0 + // we set back to 0 for safety and if restore is true we restore power_min + // otherwise we expect calling routine to be setting new power level + // we batch these commands together for speed + char *cmd = "PC;PC000;PC;PC255;PC;PC000;"; + int n; + struct rig_state *rs = &rig->state; + + rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); + retval = write_block(&rs->rigport, cmd, strlen(cmd)); + + if (retval != RIG_OK) { return retval; } + + retval = read_string(&rs->rigport, levelbuf, sizeof(levelbuf), NULL, 0); + + rig_debug(RIG_DEBUG_TRACE, "%s: retval=%d\n", __func__, retval); + + if (retval != 18) + { + rig_debug(RIG_DEBUG_ERR, "%s: expected 19, got %d in '%s'\n", __func__, retval, + levelbuf); + return -RIG_EPROTO; + } + + n = sscanf(levelbuf, "PC%d;PC%d;PC%d", power_now, power_min, power_max); + + if (n != 3) + { + rig_debug(RIG_DEBUG_ERR, "%s: count not parse 3 values from '%s'\n", __func__, + levelbuf); + return -RIG_EPROTO; + } + + if (restore) + { + snprintf(levelbuf, sizeof(levelbuf), "PC%03d;", *power_now); + retval = kenwood_transaction(rig, levelbuf, NULL, 0); + return retval; + } + + rig_debug(RIG_DEBUG_TRACE, "%s: returning now=%d, min=%d, max=%d\n", __func__, + *power_now, *power_min, *power_max); + return RIG_OK; +} + int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { char levelbuf[16]; @@ -2198,12 +2255,16 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) switch (level) { + int power_now, power_min, power_max; + int retval; + case RIG_LEVEL_RFPOWER: + // Power min/max can vary so we query to find them out every time + retval = kenwood_get_power_minmax(rig, &power_now, &power_min, &power_max, 0); - /* - * Best estimate: 1.0 corresponds to 100W - */ - kenwood_val = val.f * 100; + if (retval != RIG_OK) { return retval; } + + kenwood_val = val.f * (power_max - power_min) + power_min; snprintf(levelbuf, sizeof(levelbuf), "PC%03d", kenwood_val); break; @@ -2425,6 +2486,8 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { + int power_now, power_min, power_max; + case RIG_LEVEL_RAWSTR: if (RIG_IS_TS590S || RIG_IS_TS590SG) { @@ -2562,12 +2625,13 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) break; case RIG_LEVEL_RFPOWER: - /* - * an answer "PC100" means 100 Watt - */ - ret = get_kenwood_level(rig, "PC", NULL, &val->i); - val->f = val->i / 100.0; - return ret; + // Power min/max can vary so we query to find them out every time + retval = kenwood_get_power_minmax(rig, &power_now, &power_min, &power_max, 1); + + if (retval != RIG_OK) { return retval; } + + val->f = (power_now - power_min) / (float)(power_max - power_min); + return RIG_OK; case RIG_LEVEL_AF: diff --git a/rigs/kenwood/kenwood.h b/rigs/kenwood/kenwood.h index ce8ec5b2..ecc284ff 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -27,7 +27,7 @@ #include <string.h> #include "token.h" -#define BACKEND_VER "20200930" +#define BACKEND_VER "20201002" #define EOM_KEN ';' #define EOM_TH '\r' diff --git a/rigs/kenwood/ts480.c b/rigs/kenwood/ts480.c index be13fc6d..0f6a97ac 100644 --- a/rigs/kenwood/ts480.c +++ b/rigs/kenwood/ts480.c @@ -111,9 +111,7 @@ kenwood_ts480_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) switch (level) { case RIG_LEVEL_RFPOWER: - kenwood_val = val.f * 100; /* level for TS480SAT is from 0.. 100W in SSB */ - sprintf(levelbuf, "PC%03d", kenwood_val); - break; + return kenwood_set_level(rig, vfo, level, val); case RIG_LEVEL_AF: return kenwood_set_level(rig, vfo, level, val); @@ -246,29 +244,6 @@ kenwood_ts480_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { - case RIG_LEVEL_RFPOWER: - retval = kenwood_transaction(rig, "PC", ackbuf, sizeof(ackbuf)); - - if (RIG_OK != retval) - { - return retval; - } - - ack_len = strlen(ackbuf); - - if (5 != ack_len) - { - return -RIG_EPROTO; - } - - if (1 != sscanf(&ackbuf[2], "%d", &levelint)) - { - return -RIG_EPROTO; - } - - val->f = (float) levelint / 100.; - return RIG_OK; - case RIG_LEVEL_AF: if (rig->caps->rig_model == RIG_MODEL_TS890S) { @@ -424,6 +399,9 @@ kenwood_ts480_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return RIG_OK; + case RIG_LEVEL_RFPOWER: + return kenwood_get_level(rig, vfo, level, val); + case RIG_LEVEL_MICGAIN: case RIG_LEVEL_PREAMP: case RIG_LEVEL_IF: commit 86949c4ef711d5e4baa86241d7e7579bdffef1e3 Author: Michael Black W9MDB <mdb...@ya...> Date: Fri Oct 2 23:00:53 2020 -0500 Remove debug diff --git a/src/iofunc.c b/src/iofunc.c index 6fc16ae1..c3677a7f 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -753,7 +753,6 @@ int HAMLIB_API read_string(hamlib_port_t *p, */ rd_count = port_read(p, &rxbuffer[total_count], 1); - rig_debug(RIG_DEBUG_TRACE, "%s: YYY rd_count=%d, total_count=%d\n", __func__, rd_count, total_count); /* if we get 0 bytes or an error something is wrong */ if (rd_count <= 0) { commit ba943ae4b9209dfb7f4ed2cdb3efff679c71b900 Author: Michael Black W9MDB <mdb...@ya...> Date: Fri Oct 2 15:46:06 2020 -0700 Fix kenwood RFPOWER...more to come to make it know the max power possible https://github.com/Hamlib/Hamlib/issues/389 diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 02dac60a..374b9cff 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -2566,7 +2566,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) * an answer "PC100" means 100 Watt */ ret = get_kenwood_level(rig, "PC", NULL, &val->i); - val->f = val->f / 100.0; + val->f = val->i / 100.0; return ret; case RIG_LEVEL_AF: commit 293a844c41945db98dc6d8fa3036fec598de56a0 Author: Michael Black W9MDB <mdb...@ya...> Date: Fri Oct 2 17:23:48 2020 -0500 Fix W command speed by using bytes requested correctly read_string now recognizes binary strings to read 5X more bytes Fixed Reply: prompt double output and space after : https://github.com/Hamlib/Hamlib/issues/387 diff --git a/src/iofunc.c b/src/iofunc.c index d7380bce..6fc16ae1 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -753,6 +753,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, */ rd_count = port_read(p, &rxbuffer[total_count], 1); + rig_debug(RIG_DEBUG_TRACE, "%s: YYY rd_count=%d, total_count=%d\n", __func__, rd_count, total_count); /* if we get 0 bytes or an error something is wrong */ if (rd_count <= 0) { @@ -765,6 +766,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, return -RIG_EIO; } + // check to see if our string startis with \...if so we need more chars + if (total_count == 0 && rxbuffer[total_count] == '\\') rxmax = (rxmax-1)*5; ++total_count; if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len)) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index ce37d0a5..3d1e8da3 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -989,11 +989,13 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, { rig_debug(RIG_DEBUG_TRACE, "%s: debug7\n", __func__); +#if 0 // was printing Reply: twice if (prompt) { rig_debug(RIG_DEBUG_TRACE, "%s: debug8\n", __func__); fprintf_flush(fout, "%s: ", cmd_entry->arg2); } +#endif if (scanfc(fin, "%s", arg2) < 1) { @@ -4285,11 +4287,11 @@ declare_proto_rig(get_powerstat) return status; } -static int hasbinary(char *s) +static int hasbinary(char *s, int len) { int i; - for (i = 0; s[i] != 0; ++i) + for (i = 0; i < len; ++i) { if (!isascii(s[i])) { return 1; } } @@ -4309,7 +4311,7 @@ declare_proto_rig(send_cmd) struct rig_state *rs; int backend_num, cmd_len; #define BUFSZ 128 - char bufcmd[BUFSZ]; + char bufcmd[BUFSZ*5]; // allow for 5 chars for binary unsigned char buf[BUFSZ]; char eom_buf[4] = { 0xa, 0xd, 0, 0 }; int binary = 0; @@ -4414,7 +4416,7 @@ declare_proto_rig(send_cmd) rig_flush(&rs->rigport); rig_debug(RIG_DEBUG_TRACE, "%s: rigport=%d, bufcmd=%s, cmd_len=%d\n", __func__, - rs->rigport.fd, hasbinary(bufcmd) ? "BINARY" : bufcmd, cmd_len); + rs->rigport.fd, hasbinary(bufcmd, cmd_len) ? "BINARY" : bufcmd, cmd_len); retval = write_block(&rs->rigport, (char *)bufcmd, cmd_len); if (retval != RIG_OK) @@ -4426,7 +4428,7 @@ declare_proto_rig(send_cmd) { rig_debug(RIG_DEBUG_TRACE, "%s: debug Cmd\n", __func__); fwrite(cmd->arg2, 1, strlen(cmd->arg2), fout); /* i.e. "Frequency" */ - fwrite(":", 1, 1, fout); /* i.e. "Frequency" */ + fwrite(": ", 1, 2, fout); /* i.e. "Frequency" */ } do @@ -4436,9 +4438,6 @@ declare_proto_rig(send_cmd) if (rxbytes > 0) { ++rxbytes; // need length + 1 for end of string - - if (cmd->cmd == 'W') { rxbytes *= 5; } - eom_buf[0] = 0; } @@ -4463,10 +4462,10 @@ declare_proto_rig(send_cmd) buf[BUFSZ - 1] = '\0'; } - if (rig->caps->rig_model != RIG_MODEL_NETRIGCTL) + //if (rig->caps->rig_model != RIG_MODEL_NETRIGCTL) { // see if we have binary being returned - binary = hasbinary((char *)buf); + binary = hasbinary((char *)buf, retval); } if (binary) // convert our buf to a hex representation ----------------------------------------------------------------------- Summary of changes: rigs/kenwood/kenwood.c | 84 ++++++++++++++++++++++++++++++++++++++++++++------ rigs/kenwood/kenwood.h | 2 +- rigs/kenwood/ts480.c | 30 +++--------------- src/iofunc.c | 2 ++ tests/rigctl_parse.c | 19 ++++++------ 5 files changed, 90 insertions(+), 47 deletions(-) hooks/post-receive -- Hamlib -- Ham radio control libraries |