diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index fa5073e59..1acbdec38 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -308,6 +308,33 @@ static int newcat_get_vfo_mode(RIG *rig, vfo_t *vfo_mode); static int newcat_vfomem_toggle(RIG *rig); static ncboolean newcat_valid_command(RIG *rig, char const *const command); +/* + * The BS command needs to know what band we're on so we can restore band info + * So this converts freq to band index + */ +static int newcat_band_index(freq_t freq) +{ + // FTDX101D has band=12=MW...what is that? + int band = 11; // general + + if (freq >= 1.8) { band = 0; } + else if (freq >= 3.5) { band = 1; } + else if (freq >= 5) { band = 2; } + else if (freq >= 7) { band = 3; } + else if (freq >= 10) { band = 4; } + else if (freq >= 14) { band = 5; } + else if (freq >= 18) { band = 6; } + else if (freq >= 21) { band = 7; } + else if (freq >= 24.5) { band = 8; } + else if (freq >= 28) { band = 9; } + else if (freq >= 50) { band = 10; } + // what about 11-16? + else if (freq >= 70) { band = 17; } + + rig_debug(RIG_DEBUG_TRACE, "%s: band=%d\n", __func__, band); + return band; +} + /* * ************************************ * @@ -348,6 +375,7 @@ int newcat_init(RIG *rig) priv->rig_id = NC_RIGID_NONE; priv->current_mem = NC_MEM_CHANNEL_NONE; priv->fast_set_commands = FALSE; + priv->has_bs_cmd = 1; // assume true until proven otherwise..in set_freq return RIG_OK; } @@ -665,6 +693,26 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) return err; } + rig_debug(RIG_DEBUG_TRACE, "%s: band changing? old=%d, new=%d\n", __func__, + newcat_band_index(freq), newcat_band_index(rig->state.current_freq)); + + // Restore band memory if we can + if (priv->has_bs_cmd + && newcat_band_index(freq) != newcat_band_index(rig->state.current_freq)) + { + snprintf(priv->cmd_str, sizeof(priv->cmd_str), "BS%c", cat_term); + + if (RIG_OK != (err = newcat_set_cmd(rig))) + { + priv->has_bs_cmd = 0; // guess we can't do this so don't try again + rig_debug(RIG_DEBUG_TRACE, "%s: rig does not have BS command\n", __func__); + } + else + { + rig_debug(RIG_DEBUG_TRACE, "%s: need to restore band settings\n", __func__); + } + } + if (RIG_MODEL_FT450 == caps->rig_model && priv->ret_data[2] != target_vfo) { /* revert current VFO */ @@ -4903,7 +4951,7 @@ int newcat_get_channel(RIG *rig, channel_t *chan, int read_only) const char *newcat_get_info(RIG *rig) { struct newcat_priv_data *priv = (struct newcat_priv_data *)rig->state.priv; - static char idbuf[129]; /* extra large static string array */ + static char idbuf[513]; /* extra large static string array */ rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/rigs/yaesu/newcat.h b/rigs/yaesu/newcat.h index ce7ff95b1..e93713907 100644 --- a/rigs/yaesu/newcat.h +++ b/rigs/yaesu/newcat.h @@ -52,8 +52,8 @@ typedef char ncboolean; /* shared function version */ #define NEWCAT_VER "20201016" -/* Hopefully large enough for future use, 128 chars plus '\0' */ -#define NEWCAT_DATA_LEN 129 +/* Hopefully large enough for future use, 512 chars plus '\0' */ +#define NEWCAT_DATA_LEN 513 /* arbitrary value for now. 11 bits (8N2+1) == 2.2917 mS @ 4800 bps */ #define NEWCAT_DEFAULT_READ_TIMEOUT (NEWCAT_DATA_LEN * 5) @@ -96,6 +96,7 @@ struct newcat_priv_data struct timespec cache_start; char last_if_response[NEWCAT_DATA_LEN]; int poweron; /* to prevent powering on more than once */ + int has_bs_cmd; // used to restore band memory */ };