--- hamlib-3.0/kenwood/ts950.c.orig 2016-04-03 12:50:12.655492000 -0700 +++ hamlib-3.0/kenwood/ts950.c 2015-11-18 00:07:39.753390000 -0800 @@ -160,6 +160,7 @@ .priv = (void *)&ts950_priv_caps, .rig_init = kenwood_init, +.rig_open = kenwood_open, .rig_cleanup = kenwood_cleanup, .set_freq = kenwood_set_freq, .get_freq = kenwood_get_freq, --- hamlib-3.0/kenwood/ts850.c.orig 2016-04-03 12:49:54.095655000 -0700 +++ hamlib-3.0/kenwood/ts850.c 2015-11-18 00:07:54.234091000 -0800 @@ -208,6 +208,7 @@ .priv = (void *)&ts850_priv_caps, .rig_init = kenwood_init, + .rig_open = kenwood_open, .rig_cleanup = kenwood_cleanup, .set_freq = kenwood_set_freq, .get_freq = kenwood_get_freq, --- hamlib-3.0/kenwood/kenwood.c.orig 2015-11-17 23:56:42.765796000 -0800 +++ hamlib-3.0/kenwood/kenwood.c 2015-11-18 00:54:24.257529000 -0800 @@ -76,6 +76,7 @@ { RIG_MODEL_TS850, 9 }, { RIG_MODEL_TS450S, 10 }, { RIG_MODEL_TS690S, 11 }, + { RIG_MODEL_TS950SDX, 12 }, /* Actual value from TS-950SDX */ { RIG_MODEL_TS870S, 15 }, { RIG_MODEL_TRC80, 16 }, { RIG_MODEL_TS570D, 17 }, /* Elecraft K2|K3 also returns 17 */ @@ -100,6 +101,7 @@ { RIG_MODEL_TS850, "009" }, { RIG_MODEL_TS450S, "010" }, { RIG_MODEL_TS690S, "011" }, + { RIG_MODEL_TS950SDX, "012" }, /* Actual value from TS-950SDX */ { RIG_MODEL_TS870S, "015" }, { RIG_MODEL_TS570D, "017" }, /* Elecraft K2|K3 also returns 17 */ { RIG_MODEL_TS570S, "018" }, @@ -174,6 +176,48 @@ { RIG_CONF_END, NULL, } }; +/* + * Synchronize with the radio. It's easy to fall out of sync when + * issuing an invalid command, or if the radio was left in an + * inconsistent state by a previous session. + */ + +void kenwood_sync(RIG *rig) +{ + char buf[256]; + struct rig_state *rs; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called", __func__); + + if (rig->caps->rig_model != RIG_MODEL_TS950SDX && + rig->caps->rig_model != RIG_MODEL_TS850) + goto skip; + + rs = &rig->state; + + while (1) { + write_block(&rs->rigport, "ID;", 3); + bzero (buf, sizeof(buf)); + read_string (&rs->rigport, buf, 255, ";\r", 2); + if (strlen(buf) == 6 && strncmp (buf, "ID", 2) == 0) { + break; + } + } + + while (1) { + int r; + bzero (buf, sizeof(buf)); + read_string (&rs->rigport, buf, 255, ";\r", 1); + if (strncmp (buf, "ID", 2) != 0) + break; + } + +skip: + + rig_debug(RIG_DEBUG_VERBOSE, "%s done", __func__); + return; +} + /** * kenwood_transaction @@ -271,6 +315,7 @@ len = min (datasize ? datasize + 1 : strlen (verify) + 7, KENWOOD_MAX_BUF_LEN); retval = read_string(&rs->rigport, buffer, len, cmdtrm, strlen(cmdtrm)); if (retval < 0) { + kenwood_sync (rig); if (retry_read++ < rig->caps->retry) goto transaction_write; goto transaction_quit; @@ -278,6 +323,7 @@ /* Check that command termination is correct */ if (strchr(cmdtrm, buffer[strlen(buffer)-1])==NULL) { + kenwood_sync (rig); rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n", __func__, buffer); if (retry_read++ < rig->caps->retry) goto transaction_write; @@ -311,6 +357,7 @@ { rig_debug(RIG_DEBUG_VERBOSE, "%s: Communication error for '%s'\n", __func__, cmdstr); } + kenwood_sync (rig); if (retry_read++ < rig->caps->retry) goto transaction_write; retval = -RIG_EIO; @@ -321,6 +368,7 @@ { rig_debug(RIG_DEBUG_ERR, "%s: Unknown command or rig busy '%s'\n", __func__, cmdstr); } + kenwood_sync (rig); if (retry_read++ < rig->caps->retry) { rig_debug(RIG_DEBUG_ERR, "%s: Retrying shortly\n", __func__); @@ -350,6 +398,7 @@ rig_debug(RIG_DEBUG_ERR, "%s: wrong reply %c%c for command %c%c\n", __func__, buffer[0], buffer[1], cmdstr[0], cmdstr[1]); + kenwood_sync (rig); if (retry_read++ < rig->caps->retry) goto transaction_write; @@ -557,6 +606,8 @@ rig_debug (RIG_DEBUG_TRACE, "%s: found f/w version %s\n", __func__, priv->fw_rev); } + kenwood_sync (rig); + /* get id in buffer, will be null terminated */ err = kenwood_get_id(rig, id); if (err != RIG_OK) { @@ -1273,13 +1324,13 @@ if (width <= Hz(250)) cmd = "FL010009"; else if(width <= Hz(500)) - cmd = "FL009009"; + cmd = "FL002009"; else if(width <= kHz(2.7)) cmd = "FL007007"; else if(width <= kHz(6)) cmd = "FL005005"; else - cmd = "FL002002"; + cmd = "FL002010"; return kenwood_transaction(rig, cmd, NULL, 0); }