Simplify and fix defects in the FT991 back end

The FT991 only receives  on VFO A, VFO B is only used  for split Tx or
for exchanging with VFO A. There are no commands to set or query VFO B
mode. Added a set split mode function  that saves VFO A mode and VFO b
frequency then sets the required VFO B mode into VFO A and then copies
VFO  A  to  VFO  B  and  restores  the  VFO  B  frequency  and  VFO  A
mode. Bandwidth and narrow settings are not touched.

Several functins that had been  implemented specifically for the FT991
have been removed because existing newcat.c functions were suitable or
there should not have been a function as the rig doesn't support it.
astyle-formatting
Bill Somerville 2017-01-18 15:28:23 +00:00
rodzic 08adaf2079
commit 7ab76d59df
4 zmienionych plików z 81 dodań i 206 usunięć

Wyświetl plik

@ -191,13 +191,12 @@ const struct rig_caps ft991_caps = {
.set_freq = newcat_set_freq,
.get_freq = newcat_get_freq,
.set_mode = ft991_set_mode,
.set_mode = newcat_set_mode,
.get_mode = newcat_get_mode,
.get_vfo = newcat_get_vfo,
.set_ptt = newcat_set_ptt,
.get_ptt = newcat_get_ptt,
.set_split_vfo = ft991_set_split_vfo,
.get_split_vfo = ft991_get_split_vfo,
.set_split_vfo = newcat_set_split_vfo,
.get_split_vfo = newcat_get_split_vfo,
.get_split_mode = ft991_get_split_mode,
.set_split_mode = ft991_set_split_mode,
.set_rit = newcat_set_rit,
@ -233,115 +232,6 @@ const struct rig_caps ft991_caps = {
};
/*
* rig_set_split_vfo*
*
* Set split operation for a given VFO
*
* Parameter | Type | Accepted/Expected Values
* -------------------------------------------------------------------------
* RIG * | input | pointer to private data
* vfo | input | currVFO, VFOA, VFOB, MEM
* split | input | 0 = off, 1 = on
* tx_vfo | input | currVFO, VFOA, VFOB
* -------------------------------------------------------------------------
* Returns RIG_OK on success or an error code on failure
*
* Comments: Passing currVFO to vfo or tx_vfo will use the currently
* selected VFO obtained from the priv->current_vfo data structure.
* Only VFOA and VFOB are valid assignments for the tx_vfo.
* The tx_vfo is loaded first when assigning MEM to vfo to ensure
* the correct TX VFO is selected by the rig in split mode.
* An error is returned if vfo and tx_vfo are the same.
*/
int ft991_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
{
struct newcat_priv_data *priv;
struct rig_state *state;
unsigned char ci;
int err;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig)
return -RIG_EINVAL;
rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo);
rig_debug(RIG_DEBUG_TRACE, "%s: passed split = 0x%02x\n", __func__, split);
rig_debug(RIG_DEBUG_TRACE, "%s: passed tx_vfo = 0x%02x\n", __func__, tx_vfo);
priv = (struct newcat_priv_data *)rig->state.priv;
state = &rig->state;
// RX VFO and TX VFO cannot be the same, no support for MEM as TX VFO
if (vfo == tx_vfo || tx_vfo == RIG_VFO_MEM)
return -RIG_ENTARGET;
switch(split) {
case RIG_SPLIT_ON:
ci = '3';
break;
case RIG_SPLIT_OFF:
ci = '2';
break;
default:
return -RIG_EINVAL;
}
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "FT%c;", ci);
if ( RIG_OK != (err = write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str)))) {
rig_debug(RIG_DEBUG_ERR, "%s: write_block err = %d\n", __func__, err);
return err;
}
return RIG_OK;
}
/*
* rig_get_split_vfo*
*
* Get split mode status for a given VFO
*
* Parameter | Type | Accepted/Expected Values
* -------------------------------------------------------------------------
* RIG * | input | pointer to private data
* vfo | input | currVFO, Main, VFO, VFOA, VFOB, MEM
* split * | output | 0 = on, 1 = off
* tx_vfo * | output | VFOA, VFOB
* -------------------------------------------------------------------------
* Returns RIG_OK on success or an error code on failure
*
* Comments: The passed value for the vfo is ignored since can only split one way
*/
int ft991_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo)
{
struct newcat_priv_data *priv;
int err;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig)
return -RIG_EINVAL;
rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo);
priv = (struct newcat_priv_data *)rig->state.priv;
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "FT;");
if (RIG_OK != (err = newcat_get_cmd (rig)))
return err;
// Get split mode status
*split = priv->ret_data[2]=='1'; // 1=VFOB TX so is in split mode
rig_debug(RIG_DEBUG_TRACE, "%s: get split = 0x%02x\n", __func__, *split);
*tx_vfo = RIG_VFO_A;
if (*split) *tx_vfo = RIG_VFO_B;
rig_debug(RIG_DEBUG_TRACE, "%s: get tx_vfo = 0x%02x\n", __func__, *tx_vfo);
return RIG_OK;
}
/*
* rig_get_split_mode*
*
@ -371,7 +261,7 @@ int ft991_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_wi
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig)
if (!rig || !tx_mode || !tx_width)
return -RIG_EINVAL;
priv = (struct newcat_priv_data *)rig->state.priv;
@ -380,6 +270,7 @@ int ft991_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_wi
if (RIG_OK != (err = newcat_get_cmd (rig)))
return err;
*tx_mode = priv->ret_data[22];
*tx_width = RIG_PASSBAND_NORMAL;
return RIG_OK;
}
@ -398,9 +289,11 @@ int ft991_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_wi
* ------------------------------------------------------------------
* Returns RIG_OK on success or an error code on failure
*
* Comments: Passsband is not set here.
* FT991 apparentlhy cannot set VFOB mode directly
* So we'll just set A and swap A into B
* Comments: Passs band is not set here nor does it make sense as the
* FT991 cannot receive on VFO B. The FT991 cannot set
* VFO B mode directly so we'll just set A and swap A
* into B but we must preserve the VFO A mode and VFO B
* frequency.
*
*/
@ -409,6 +302,7 @@ int ft991_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_widt
struct newcat_priv_data *priv;
struct rig_state *state;
int err;
char restore_commands[NEWCAT_DATA_LEN];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
@ -420,56 +314,41 @@ int ft991_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_widt
rig_debug(RIG_DEBUG_TRACE, "%s: passed mode = %i\n", __func__, tx_mode);
rig_debug(RIG_DEBUG_TRACE, "%s: passed width = %li Hz\n", __func__, tx_width);
priv = (struct newcat_priv_data *)rig->state.priv;
priv = (struct newcat_priv_data *)state->priv;
// Change mode on VFOA and make VFOB match VFOA
if (RIG_OK != (err = newcat_set_mode(rig,RIG_VFO_A,tx_mode,tx_width))) {
return err;
}
// Copy A to B
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "AB;");
if (RIG_OK != (err = write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str))))
/* add VFO A -> B copy to command buffer */
strncpy (restore_commands, "AB;", NEWCAT_DATA_LEN - 1);
/* append VFO A mode restore command first as we want to minimize
any Rx glitches */
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "MD0;");
rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str);
if (RIG_OK != (err = newcat_get_cmd (rig)))
{
rig_debug(RIG_DEBUG_VERBOSE, "%s:%d write_block err = %d\n", __func__, __LINE__, err);
return err;
}
strncat (restore_commands, priv->ret_data, NEWCAT_DATA_LEN - 1 - strlen (restore_commands));
#if 0
/* append VFO B frequency restore command */
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "FB;");
rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str);
if (RIG_OK != (err = newcat_get_cmd (rig)))
{
return err;
#endif
return RIG_OK;
}
strncat (restore_commands, priv->ret_data, NEWCAT_DATA_LEN - 1 - strlen (restore_commands));
/* Change mode on VFOA */
if (RIG_OK != (err = newcat_set_mode (rig, RIG_VFO_A, tx_mode, RIG_PASSBAND_NOCHANGE)))
{
return err;
}
/* Send the copy VFO A to VFO B and restore commands */
snprintf(priv->cmd_str, sizeof(priv->cmd_str), restore_commands);
return newcat_set_cmd (rig);
}
int ft991_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
struct newcat_priv_data *priv;
int err;
struct rig_state *state;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig)
return -RIG_EINVAL;
state = &rig->state;
// FT991 can't set VFOB mode directly so we always set VFOA and copy to VFOB
// We will always make VFOB match VFOA mode
newcat_set_mode(rig, RIG_VFO_A, mode, width);
priv = (struct newcat_priv_data *)rig->state.priv;
// Copy A to B "AB" command has no return so we write directly
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "AB;");
if (RIG_OK != (err = write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str))))
{
rig_debug(RIG_DEBUG_VERBOSE, "%s:%d write_block err = %d\n", __func__, __LINE__, err);
return err;
}
return RIG_OK;
}
int ft991_init(RIG *rig) {
struct newcat_priv_data *priv;
rig_debug(RIG_DEBUG_VERBOSE,"%s called, version %s\n", __func__,rig->caps->version);

Wyświetl plik

@ -121,14 +121,8 @@
#define FT991_POST_WRITE_DELAY 50
/* Prototypes */
int ft991_init(RIG *rig);
static int ft991_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo);
static int ft991_init(RIG *rig);
static int ft991_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_width);
static int ft991_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width);
static int ft991_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
static int ft991_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo);
/* Reuse newcat_get_cmd */
extern int newcat_get_cmd(RIG *rig);
#endif /* _FT991_H */

Wyświetl plik

@ -243,10 +243,7 @@ static int newcat_get_faststep(RIG * rig, ncboolean * fast_step);
static int newcat_get_rigid(RIG * rig);
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 *command);
/* NewCAT Exposed Functions */
int newcat_get_cmd(RIG * rig);
int newcat_set_cmd (RIG *rig);
static ncboolean newcat_valid_command(RIG *rig, char const * const command);
/*
* ************************************
@ -914,22 +911,19 @@ int newcat_set_vfo(RIG *rig, vfo_t vfo) {
int newcat_get_vfo(RIG *rig, vfo_t *vfo) {
struct rig_state *state = &rig->state;
struct newcat_priv_data *priv = (struct newcat_priv_data *)rig->state.priv;
char c;
int err;
vfo_t vfo_mode;
char command[] = "VS";
char const * command = "VS";
if (!rig || !vfo)
return -RIG_EINVAL;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!newcat_valid_command(rig, command))
return -RIG_ENAVAIL;
/* Build the command string */
if (!newcat_valid_command(rig, command))
return -RIG_ENAVAIL;
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "%s;", command);
rig_debug(RIG_DEBUG_TRACE, "%s: cmd_str = %s\n", __func__, priv->cmd_str);
/* Get VFO */
@ -939,22 +933,20 @@ int newcat_get_vfo(RIG *rig, vfo_t *vfo) {
}
/*
* The current VFO value is a digit ('0' or '1' ('A' or 'B' respectively))
* embedded at ret_data[2] in the read string.
* The current VFO value is a digit ('0' or '1' ('A' or 'B'
* respectively)) embedded at ret_data[2] in the read string.
*/
c = priv->ret_data[2];
switch (c) {
case '0':
*vfo = RIG_VFO_A;
break;
case '1':
*vfo = RIG_VFO_B;
break;
default:
return -RIG_EPROTO; /* sorry, wrong current VFO */
}
switch (priv->ret_data[2])
{
case '0':
*vfo = RIG_VFO_A;
break;
case '1':
*vfo = RIG_VFO_B;
break;
default:
return -RIG_EPROTO; /* sorry, wrong current VFO */
}
/* Check to see if RIG is in MEM mode */
err = newcat_get_vfo_mode(rig, &vfo_mode);
@ -966,7 +958,6 @@ int newcat_get_vfo(RIG *rig, vfo_t *vfo) {
rig_debug(RIG_DEBUG_TRACE, "%s: rig->state.current_vfo = 0x%02x\n", __func__, state->current_vfo);
return RIG_OK;
}
@ -1193,9 +1184,17 @@ int newcat_set_split_vfo(RIG * rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
if (err < 0)
return err;
err = newcat_get_vfo(rig, &rx_vfo); /* sync to rig current vfo */
if (err != RIG_OK)
return err;
if (newcat_is_rig(rig, RIG_MODEL_FT991))
{
vfo = RIG_VFO_A;
tx_vfo = RIG_SPLIT_ON == split ? RIG_VFO_B : RIG_VFO_A;
}
else
{
err = newcat_get_vfo(rig, &rx_vfo); /* sync to rig current vfo */
if (err != RIG_OK)
return err;
}
switch (split) {
case RIG_SPLIT_OFF:
@ -1203,7 +1202,7 @@ int newcat_set_split_vfo(RIG * rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
if (err != RIG_OK)
return err;
if (rx_vfo != vfo) {
if (rx_vfo != vfo && newcat_valid_command (rig, "VS")) {
err = newcat_set_vfo(rig, vfo);
if (err != RIG_OK)
return err;
@ -1216,7 +1215,7 @@ int newcat_set_split_vfo(RIG * rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
if (rx_vfo != vfo) {
err = newcat_set_vfo(rig, vfo);
if (err != RIG_OK)
if (err != RIG_OK && err != -RIG_ENAVAIL)
return err;
}
break;
@ -3360,7 +3359,7 @@ const char *newcat_get_info(RIG * rig)
* commands (for a rig).
*/
ncboolean newcat_valid_command(RIG *rig, char *command) {
ncboolean newcat_valid_command(RIG *rig, char const * const command) {
const struct rig_caps *caps;
ncboolean is_ft450;
ncboolean is_ft950;
@ -3504,10 +3503,11 @@ int newcat_set_tx_vfo(RIG * rig, vfo_t tx_vfo) {
definitively set the TX VFO (VS; doesn't seem to help
either) */
if (newcat_is_rig(rig, RIG_MODEL_FT950) ||
newcat_is_rig(rig, RIG_MODEL_FT2000) ||
newcat_is_rig(rig, RIG_MODEL_FTDX5000) ||
newcat_is_rig(rig, RIG_MODEL_FT1200))
p1 = p1 + 2; /* use non-Toggle commands */
newcat_is_rig(rig, RIG_MODEL_FT2000) ||
newcat_is_rig(rig, RIG_MODEL_FTDX5000) ||
newcat_is_rig(rig, RIG_MODEL_FT1200) ||
newcat_is_rig(rig, RIG_MODEL_FT991))
p1 = p1 + 2; /* use non-Toggle commands */
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "%s%c%c", "FT", p1, cat_term);
@ -3526,14 +3526,13 @@ int newcat_get_tx_vfo(RIG * rig, vfo_t * tx_vfo) {
int err;
char c;
vfo_t vfo_mode;
char const * command = "FT";
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!newcat_valid_command(rig, "FT"))
return -RIG_ENAVAIL;
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "%s%c", "FT", cat_term);
if (!newcat_valid_command(rig, command))
return -RIG_ENAVAIL;
snprintf(priv->cmd_str, sizeof(priv->cmd_str), "%s%c", command, cat_term);
rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str);
/* Get TX VFO */
@ -3542,7 +3541,7 @@ int newcat_get_tx_vfo(RIG * rig, vfo_t * tx_vfo) {
return err;
}
c = priv->ret_data[2];
c = priv->ret_data[strlen (priv->cmd_str)];
switch (c) {
case '0':
*tx_vfo = RIG_VFO_A;

Wyświetl plik

@ -124,6 +124,9 @@ struct newcat_priv_data {
*
*/
int newcat_get_cmd(RIG * rig);
int newcat_set_cmd (RIG *rig);
int newcat_init(RIG *rig);
int newcat_cleanup(RIG *rig);
int newcat_open(RIG *rig);