Merge pull request #788 from wutje/ft817_improvements

FT817: add get_ant. Add SWR level. Fix ALC, PWR
pull/790/head
Michael Black 2021-09-04 16:52:40 -05:00 zatwierdzone przez GitHub
commit c7dbbfbc32
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 379 dodań i 212 usunięć

Wyświetl plik

@ -57,6 +57,7 @@
#include <stdlib.h>
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <stdbool.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
@ -71,6 +72,49 @@
#include "bandplan.h"
#include "cal.h"
enum ft817_native_cmd_e
{
FT817_NATIVE_CAT_LOCK_ON = 0,
FT817_NATIVE_CAT_LOCK_OFF,
FT817_NATIVE_CAT_PTT_ON,
FT817_NATIVE_CAT_PTT_OFF,
FT817_NATIVE_CAT_SET_FREQ,
FT817_NATIVE_CAT_SET_MODE_LSB,
FT817_NATIVE_CAT_SET_MODE_USB,
FT817_NATIVE_CAT_SET_MODE_CW,
FT817_NATIVE_CAT_SET_MODE_CWR,
FT817_NATIVE_CAT_SET_MODE_AM,
FT817_NATIVE_CAT_SET_MODE_FM,
FT817_NATIVE_CAT_SET_MODE_FM_N,
FT817_NATIVE_CAT_SET_MODE_DIG,
FT817_NATIVE_CAT_SET_MODE_PKT,
FT817_NATIVE_CAT_CLAR_ON,
FT817_NATIVE_CAT_CLAR_OFF,
FT817_NATIVE_CAT_SET_CLAR_FREQ,
FT817_NATIVE_CAT_SET_VFOAB,
FT817_NATIVE_CAT_SPLIT_ON,
FT817_NATIVE_CAT_SPLIT_OFF,
FT817_NATIVE_CAT_SET_RPT_SHIFT_MINUS,
FT817_NATIVE_CAT_SET_RPT_SHIFT_PLUS,
FT817_NATIVE_CAT_SET_RPT_SHIFT_SIMPLEX,
FT817_NATIVE_CAT_SET_RPT_OFFSET,
FT817_NATIVE_CAT_SET_DCS_ON,
FT817_NATIVE_CAT_SET_CTCSS_ON,
FT817_NATIVE_CAT_SET_CTCSS_ENC_ON,
FT817_NATIVE_CAT_SET_CTCSS_DCS_OFF,
FT817_NATIVE_CAT_SET_CTCSS_FREQ,
FT817_NATIVE_CAT_SET_DCS_CODE,
FT817_NATIVE_CAT_GET_RX_STATUS,
FT817_NATIVE_CAT_GET_TX_STATUS,
FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS,
FT817_NATIVE_CAT_PWR_WAKE,
FT817_NATIVE_CAT_PWR_ON,
FT817_NATIVE_CAT_PWR_OFF,
FT817_NATIVE_CAT_EEPROM_READ,
FT817_NATIVE_CAT_GET_TX_METERING,
FT817_NATIVE_SIZE /* end marker */
};
struct ft817_priv_data
{
/* rx status */
@ -79,15 +123,58 @@ struct ft817_priv_data
/* tx status */
struct timeval tx_status_tv;
unsigned char tx_status;
unsigned char tx_status; /* Raw data from rig. Highest bit 0 = PTT */
/* tx levels */
struct timeval tx_level_tv;
unsigned char swr_level;
unsigned char alc_level;
unsigned char mod_level;
unsigned char pwr_level; /* TX power level */
/* freq & mode status */
struct timeval fm_status_tv;
unsigned char fm_status[YAESU_CMD_LENGTH + 1];
unsigned char fm_status[5]; /* 5 bytes, NOT related to YAESU_CMD_LENGTH */
/* Digi mode is not part of regular fm_status reponse.
* So keep track of it in a separate variable. */
unsigned char dig_mode;
};
static int ft817_init(RIG *rig);
static int ft817_open(RIG *rig);
static int ft817_cleanup(RIG *rig);
static int ft817_close(RIG *rig);
static int ft817_get_vfo(RIG *rig, vfo_t *vfo);
static int ft817_set_vfo(RIG *rig, vfo_t vfo);
static int ft817_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
static int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
static int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
static int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
static int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt);
static int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
static int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
static int ft817_set_func(RIG *rig, vfo_t vfo, setting_t func, int status);
static int ft817_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code);
static int ft817_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone);
static int ft817_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code);
static int ft817_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone);
static int ft817_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t shift);
static int ft817_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs);
static int ft817_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit);
static int ft817_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd);
static int ft817_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op);
static int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split,
vfo_t *tx_vfo);
static int ft817_set_split_vfo(RIG *rig, vfo_t vfo, split_t split,
vfo_t tx_vfo);
static int ft817_power2mW(RIG *rig, unsigned int *mwpower, float power,
freq_t freq, rmode_t mode);
static int ft817_mW2power(RIG *rig, float *power, unsigned int mwpower,
freq_t freq, rmode_t mode);
static int ft817_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option,
ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx);
static int ft818_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option,
ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx);
/* Native ft817 cmd set prototypes. These are READ ONLY as each */
/* rig instance will copy from these and modify if required . */
@ -133,6 +220,7 @@ static const yaesu_cmd_set_t ncmd[] =
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x0f } }, /* pwr on */
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x8f } }, /* pwr off */
{ 0, { 0x00, 0x00, 0x00, 0x00, 0xbb } }, /* eeprom read */
{ 1, { 0x00, 0x00, 0x00, 0x00, 0xbd } }, /* get TX metering levels (PWR, SWR, MOD, ALC) */
};
enum ft817_digi
@ -155,7 +243,9 @@ enum ft817_digi
#define FT817_AM_TX_MODES (RIG_MODE_AM)
#define FT817_VFO_ALL (RIG_VFO_A|RIG_VFO_B)
#define FT817_ANTS 0
#define FT817_ANT_FRONT (RIG_ANT_1)
#define FT817_ANT_REAR (RIG_ANT_2)
#define FT817_ANTS (FT817_ANT_FRONT | FT817_ANT_REAR)
#define FT817_STR_CAL { 16, \
{ \
@ -232,7 +322,9 @@ const struct rig_caps ft817_caps =
.retry = 5,
.has_get_func = RIG_FUNC_NONE,
.has_set_func = RIG_FUNC_LOCK | RIG_FUNC_TONE | RIG_FUNC_TSQL,
.has_get_level = RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR | RIG_LEVEL_RFPOWER,
.has_get_level =
RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR | RIG_LEVEL_RFPOWER |
RIG_LEVEL_ALC | RIG_LEVEL_SWR,
.has_set_level = RIG_LEVEL_NONE,
.has_get_parm = RIG_PARM_NONE,
.has_set_parm = RIG_PARM_NONE,
@ -253,10 +345,10 @@ const struct rig_caps ft817_caps =
.chan_list = { RIG_CHAN_END, },
.rx_range_list1 = {
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1},
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
RIG_FRNG_END,
},
.tx_range_list1 = {
@ -277,10 +369,10 @@ const struct rig_caps ft817_caps =
.rx_range_list2 = {
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1},
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
RIG_FRNG_END,
},
@ -322,7 +414,7 @@ const struct rig_caps ft817_caps =
.rfpower_meter_cal = FT817_PWR_CAL,
.rig_init = ft817_init,
.rig_cleanup = ft817_cleanup,
.rig_cleanup = ft817_cleanup,
.rig_open = ft817_open,
.rig_close = ft817_close,
.get_vfo = ft817_get_vfo,
@ -331,24 +423,25 @@ const struct rig_caps ft817_caps =
.get_freq = ft817_get_freq,
.set_mode = ft817_set_mode,
.get_mode = ft817_get_mode,
.set_ptt = ft817_set_ptt,
.get_ptt = ft817_get_ptt,
.get_dcd = ft817_get_dcd,
.set_ptt = ft817_set_ptt,
.get_ptt = ft817_get_ptt,
.get_dcd = ft817_get_dcd,
.set_rptr_shift = ft817_set_rptr_shift,
.set_rptr_offs = ft817_set_rptr_offs,
.set_split_vfo = ft817_set_split_vfo,
.get_split_vfo = ft817_get_split_vfo,
.set_rit = ft817_set_rit,
.set_rit = ft817_set_rit,
.set_dcs_code = ft817_set_dcs_code,
.set_ctcss_tone = ft817_set_ctcss_tone,
.set_dcs_sql = ft817_set_dcs_sql,
.set_dcs_sql = ft817_set_dcs_sql,
.set_ctcss_sql = ft817_set_ctcss_sql,
.power2mW = ft817_power2mW,
.mW2power = ft817_mW2power,
.power2mW = ft817_power2mW,
.mW2power = ft817_mW2power,
.set_powerstat = ft817_set_powerstat,
.get_ant = ft817_get_ant,
.get_level = ft817_get_level,
.set_func = ft817_set_func,
.vfo_op = ft817_vfo_op,
.vfo_op = ft817_vfo_op,
};
const struct rig_caps ft818_caps =
@ -375,7 +468,9 @@ const struct rig_caps ft818_caps =
.retry = 5,
.has_get_func = RIG_FUNC_NONE,
.has_set_func = RIG_FUNC_LOCK | RIG_FUNC_TONE | RIG_FUNC_TSQL,
.has_get_level = RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR | RIG_LEVEL_RFPOWER,
.has_get_level =
RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR | RIG_LEVEL_RFPOWER |
RIG_LEVEL_ALC | RIG_LEVEL_SWR,
.has_set_level = RIG_LEVEL_NONE,
.has_get_parm = RIG_PARM_NONE,
.has_set_parm = RIG_PARM_NONE,
@ -396,16 +491,20 @@ const struct rig_caps ft818_caps =
.chan_list = { RIG_CHAN_END, },
.rx_range_list1 = {
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1},
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
RIG_FRNG_END,
},
.tx_range_list1 = {
FRQ_RNG_HF(1, FT817_OTHER_TX_MODES, W(0.5), W(5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_HF(1, FT817_AM_TX_MODES, W(0.5), W(1.5), FT817_VFO_ALL, FT817_ANTS),
/* One of the key differences between 817 and 818: the 818 has 60m! */
FRQ_RNG_60m(1, FT817_OTHER_TX_MODES, W(0.5), W(5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_60m(1, FT817_AM_TX_MODES, W(0.5), W(1.5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_6m(1, FT817_OTHER_TX_MODES, W(0.5), W(5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_6m(1, FT817_AM_TX_MODES, W(0.5), W(1.5), FT817_VFO_ALL, FT817_ANTS),
@ -420,17 +519,20 @@ const struct rig_caps ft818_caps =
.rx_range_list2 = {
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1},
{kHz(100), MHz(56), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(76), MHz(108), RIG_MODE_WFM, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(118), MHz(164), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
{MHz(420), MHz(470), FT817_ALL_RX_MODES, -1, -1, FT817_VFO_ALL, FT817_ANTS},
RIG_FRNG_END,
},
.tx_range_list2 = {
FRQ_RNG_HF(2, FT817_OTHER_TX_MODES, W(0.5), W(5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_HF(2, FT817_AM_TX_MODES, W(0.5), W(1.5), FT817_VFO_ALL, FT817_ANTS),
/* FIXME: 60 meters in US version */
/* One of the key differences between 817 and 818: the 818 has 60m! */
FRQ_RNG_60m(2, FT817_OTHER_TX_MODES, W(0.5), W(5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_60m(2, FT817_AM_TX_MODES, W(0.5), W(1.5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_6m(2, FT817_OTHER_TX_MODES, W(0.5), W(5), FT817_VFO_ALL, FT817_ANTS),
FRQ_RNG_6m(2, FT817_AM_TX_MODES, W(0.5), W(1.5), FT817_VFO_ALL, FT817_ANTS),
@ -459,10 +561,13 @@ const struct rig_caps ft818_caps =
RIG_FLT_END,
},
.str_cal = FT817_STR_CAL,
.str_cal = FT817_STR_CAL,
.swr_cal = FT817_SWR_CAL,
.alc_cal = FT817_ALC_CAL,
.rfpower_meter_cal = FT817_PWR_CAL,
.rig_init = ft817_init,
.rig_cleanup = ft817_cleanup,
.rig_cleanup = ft817_cleanup,
.rig_open = ft817_open,
.rig_close = ft817_close,
.get_vfo = ft817_get_vfo,
@ -471,29 +576,30 @@ const struct rig_caps ft818_caps =
.get_freq = ft817_get_freq,
.set_mode = ft817_set_mode,
.get_mode = ft817_get_mode,
.set_ptt = ft817_set_ptt,
.get_ptt = ft817_get_ptt,
.get_dcd = ft817_get_dcd,
.set_ptt = ft817_set_ptt,
.get_ptt = ft817_get_ptt,
.get_dcd = ft817_get_dcd,
.set_rptr_shift = ft817_set_rptr_shift,
.set_rptr_offs = ft817_set_rptr_offs,
.set_split_vfo = ft817_set_split_vfo,
.get_split_vfo = ft817_get_split_vfo,
.set_rit = ft817_set_rit,
.set_rit = ft817_set_rit,
.set_dcs_code = ft817_set_dcs_code,
.set_ctcss_tone = ft817_set_ctcss_tone,
.set_dcs_sql = ft817_set_dcs_sql,
.set_dcs_sql = ft817_set_dcs_sql,
.set_ctcss_sql = ft817_set_ctcss_sql,
.power2mW = ft817_power2mW,
.mW2power = ft817_mW2power,
.power2mW = ft817_power2mW,
.mW2power = ft817_mW2power,
.set_powerstat = ft817_set_powerstat,
.get_ant = ft818_get_ant,
.get_level = ft817_get_level,
.set_func = ft817_set_func,
.vfo_op = ft817_vfo_op,
.vfo_op = ft817_vfo_op,
};
/* ---------------------------------------------------------------------- */
int ft817_init(RIG *rig)
static int ft817_init(RIG *rig)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called, version %s\n", __func__,
rig->caps->version);
@ -506,28 +612,25 @@ int ft817_init(RIG *rig)
return RIG_OK;
}
int ft817_cleanup(RIG *rig)
static int ft817_cleanup(RIG *rig)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
if (rig->state.priv)
{
free(rig->state.priv);
}
free(rig->state.priv);
rig->state.priv = NULL;
return RIG_OK;
}
int ft817_open(RIG *rig)
static int ft817_open(RIG *rig)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called \n", __func__);
return RIG_OK;
}
int ft817_close(RIG *rig)
static int ft817_close(RIG *rig)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called \n", __func__);
@ -608,6 +711,7 @@ static int ft817_get_status(RIG *rig, int status)
int len;
int n;
int retries = rig->state.rigport.retry;
unsigned char result[2];
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
@ -615,7 +719,8 @@ static int ft817_get_status(RIG *rig, int status)
{
case FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS:
data = p->fm_status;
len = YAESU_CMD_LENGTH;
/* Answer is 5 long; 4 bytes BCD freq, 1 byte status */
len = 5;
tv = &p->fm_status_tv;
break;
@ -625,12 +730,19 @@ static int ft817_get_status(RIG *rig, int status)
tv = &p->rx_status_tv;
break;
case FT817_NATIVE_CAT_GET_TX_METERING:
data = result;
len = sizeof(result)/sizeof(result[0]); /* We expect two bytes */
tv = &p->tx_level_tv;
break;
case FT817_NATIVE_CAT_GET_TX_STATUS:
data = &p->tx_status;
len = 1;
tv = &p->tx_status_tv;
break;
default:
rig_debug(RIG_DEBUG_ERR, "%s: Internal error!\n", __func__);
return -RIG_EINTERNAL;
@ -652,17 +764,41 @@ static int ft817_get_status(RIG *rig, int status)
if (n != len)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: Length mismatch exp %d got %d!\n",
__func__, len, n);
return -RIG_EIO;
}
if (status == FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS)
switch(status)
{
if ((n = ft817_read_eeprom(rig, 0x0065, &p->fm_status[5])) < 0)
case FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS:
{
return n;
}
unsigned char dig_mode;
if ((n = ft817_read_eeprom(rig, 0x0065, &dig_mode)) < 0)
{
return n;
}
p->fm_status[5] >>= 5;
/* Top 3 bit define the digi mode */
p->dig_mode = dig_mode >> 5;
}
break;
case FT817_NATIVE_CAT_GET_TX_METERING:
/* FT-817 returns 2 bytes with 4 nibbles.
* Extract raw values here;
* convert to float when they are requested. */
p->swr_level = result[0] & 0xF;
p->pwr_level = result[0] >> 4;
p->alc_level = result[1] & 0xF;
p->mod_level = result[1] >> 4;
rig_debug(RIG_DEBUG_TRACE, "%s: swr: %d, pwr %d, alc %d, mod %d\n",
__func__,
p->swr_level,
p->pwr_level,
p->alc_level,
p->mod_level);
break;
}
gettimeofday(tv, NULL);
@ -672,7 +808,7 @@ static int ft817_get_status(RIG *rig, int status)
/* ---------------------------------------------------------------------- */
int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
static int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
freq_t f1 = 0, f2 = 0;
@ -693,7 +829,7 @@ int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
f1 = f2;
f2 = from_bcd_be(p->fm_status, 8);
dump_hex(p->fm_status, 5);
dump_hex(p->fm_status, sizeof(p->fm_status)/sizeof(p->fm_status[0]));
}
#if 1 // user must be twiddling the VFO
@ -716,7 +852,7 @@ int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
}
int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
static int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
@ -763,7 +899,7 @@ int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
break;
case 0x0a:
switch (p->fm_status[5])
switch (p->dig_mode)
{
case FT817_DIGI_RTTY: *mode = RIG_MODE_RTTYR; break;
@ -774,6 +910,9 @@ int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
case FT817_DIGI_USER_L: *mode = RIG_MODE_PKTLSB; break;
case FT817_DIGI_USER_U: *mode = RIG_MODE_PKTUSB; break;
default:
*mode = RIG_MODE_NONE;
}
break;
@ -798,7 +937,7 @@ int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
return RIG_OK;
}
int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo)
static int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
int n;
@ -831,7 +970,7 @@ int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo)
return RIG_OK;
}
int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
static int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
@ -852,64 +991,46 @@ int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
return RIG_OK;
}
static int ft817_get_alc_level(RIG *rig, value_t *val)
static int ft817_get_tx_level(RIG *rig, value_t *val, unsigned char *tx_level, const cal_table_float_t *cal)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
if (check_cache_timeout(&p->tx_status_tv))
if (check_cache_timeout(&p->tx_level_tv))
{
int n;
ptt_t ptt;
if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_STATUS)) < 0)
/* Default to not keyed */
*tx_level = 0;
/* TX metering is special; it sends 1 byte if not keyed and 2 if keyed.
* To handle this properly we first verify the rig is keyed.
* Otherwise we experience at least a full timeout and
* perhaps pointless retries + timeouts.
*/
n = ft817_get_ptt(rig, 0, &ptt);
if (n != RIG_OK)
{
return n;
}
if (ptt == RIG_PTT_OFF)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: rig not keyed\n", __func__);
return -RIG_ERJCTED; //Or return OK?
}
n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_METERING);
if (n != RIG_OK)
{
return n;
}
}
/* Valid only if PTT is on.
FT-817 returns the number of bars in the lowest 4 bits
*/
if ((p->tx_status & 0x80) == 0)
{
val->f = rig_raw2val_float(p->tx_status >> 4, &rig->caps->alc_cal);
}
else // not transmitting so zero
{
val->f = 0.0;
}
return RIG_OK;
}
static int ft817_get_pometer_level(RIG *rig, value_t *val)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
if (check_cache_timeout(&p->tx_status_tv))
{
int n;
if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_STATUS)) < 0)
{
return n;
}
}
/* Valid only if PTT is on.
FT-817 returns the number of bars in the lowest 4 bits
*/
if ((p->tx_status & 0x80) == 0)
{
val->f = rig_raw2val_float(p->tx_status >> 4, &rig->caps->rfpower_meter_cal);
}
else // not transmitting so zero
{
val->f = 0.0;
}
val->f = rig_raw2val_float(*tx_level, cal);
rig_debug(RIG_DEBUG_VERBOSE, "%s: level %f\n", __func__, val->f);
return RIG_OK;
}
@ -978,27 +1099,27 @@ static int ft817_get_raw_smeter_level(RIG *rig, value_t *val)
}
int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
static int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
switch (level)
{
case RIG_LEVEL_STRENGTH:
/* The front-end will always call for RAWSTR and use the cal_table */
return ft817_get_smeter_level(rig, val);
break;
case RIG_LEVEL_RAWSTR:
return ft817_get_raw_smeter_level(rig, val);
break;
case RIG_LEVEL_RFPOWER:
return ft817_get_pometer_level(rig, val);
break;
return ft817_get_tx_level(rig, val, &p->pwr_level, &rig->caps->rfpower_meter_cal);
case RIG_LEVEL_ALC:
return ft817_get_alc_level(rig, val);
break;
return ft817_get_tx_level(rig, val, &p->alc_level, &rig->caps->alc_cal);
case RIG_LEVEL_SWR:
return ft817_get_tx_level(rig, val, &p->swr_level, &rig->caps->swr_cal);
default:
return -RIG_EINVAL;
@ -1007,7 +1128,7 @@ int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
return RIG_OK;
}
int ft817_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
static int ft817_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
{
struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv;
@ -1036,6 +1157,132 @@ int ft817_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
return RIG_OK;
}
static int ft818_817_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option,
ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx, bool is817)
{
/* The FT818/817 has no RIG_TARGETABLE_ALL
* so rig.c switched the active VFO to the one requested */
int ret;
unsigned char eeprom_band, eeprom_ant;
/* Read eeprom for current 'band' for both VFO's */
ret = ft817_read_eeprom(rig, 0x59, &eeprom_band);
if (ret != RIG_OK)
{
return ret;
}
/* Read eeprom for antenna selection per band.
* The FT818/817 stores antenna per band not per VFO!
* So changing antenna will change for both VFO's */
ret = ft817_read_eeprom(rig, 0x7A, &eeprom_ant);
if (ret != RIG_OK)
{
return ret;
}
/* if CURR then get real VFO before parsing EEPROM */
if (vfo == RIG_VFO_CURR)
{
vfo = rig->state.current_vfo;
}
/* band info is 4 bit per VFO, for A lower nibble, B is upper nible */
switch (vfo) {
case RIG_VFO_A:
eeprom_band &= 0xF;
break;
case RIG_VFO_B:
eeprom_band = eeprom_band >> 4;
break;
default:
rig_debug(RIG_DEBUG_ERR, "%s: Unsupported VFO %d!\n",
__func__, vfo);
return -RIG_EINTERNAL;
}
/* The 818 and the 817 differ in bands: the 818 has 60m.
* The band selection flags for the 818 and 817 thus differ:
* 2 means 60m on 818 and 40m for 817.
* And the rest of the values are shifted.
*
* So to make the code simple: if we have a 817 and 2 or higher band then
* add 1 to the value to align it on the 818 mapping.
*/
if (is817 && eeprom_band >= 2)
{
eeprom_band++;
}
/* The 817/818 does not have a antenna selection per VFO but per band.
* So we read the band for the requested VFO and then map it to the
* selected antenna.
*/
switch (eeprom_band) {
case 0: /* 160M */
case 1: /* 80M */
case 2: /* 60M, 818 only */
case 3: /* 40M */
case 4: /* 30M */
case 5: /* 20M */
case 6: /* 17M */
case 7: /* 15M */
case 8: /* 12M */
case 9: /* 10M */
/* All HF use the same antenna setting, bit 0 */
eeprom_ant &= 1<<0;
break;
case 0xA: /* 6m, bit 1 */
eeprom_ant &= 1<<1;
break;
case 0xB: /* FM BCB 76Mhz - 108Mhz, bit 2 */
eeprom_ant &= 1<<2;
break;
case 0xC: /* Airband, bit 3 */
eeprom_ant &= 1<<3;
break;
case 0xD: /* 2M, bit 4 */
eeprom_ant &= 1<<4;
break;
case 0xE: /* 70cm / UHF, bit 5 */
eeprom_ant &= 1<<5;
break;
case 0xF: /* Free-tuning?, bit 6 */
eeprom_ant &= 1<<6;
break;
}
/* We have no split TX/RX capability per VFO.
* So only set ant_curr and leave rx/tx set to unknown. */
*ant_curr = eeprom_ant ? FT817_ANT_REAR : FT817_ANT_FRONT;
return RIG_OK;
}
static int ft817_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option,
ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx)
{
return ft818_817_get_ant(rig, vfo, ant, option, ant_curr, ant_tx, ant_rx,
true);
}
static int ft818_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option,
ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx)
{
return ft818_817_get_ant(rig, vfo, ant, option, ant_curr, ant_tx, ant_rx,
false);
}
/* ---------------------------------------------------------------------- */
int ft817_read_ack(RIG *rig)
@ -1149,9 +1396,7 @@ static int ft817_set_vfo(RIG *rig, vfo_t vfo)
return ft817_send_cmd(rig, FT817_NATIVE_CAT_SET_VFOAB);
}
int ft817_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
static int ft817_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
int retval;
@ -1169,7 +1414,7 @@ int ft817_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
return retval;
}
int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
static int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
int index; /* index of sequence to send */
@ -1227,7 +1472,7 @@ int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
return ft817_send_cmd(rig, index);
}
int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
static int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
{
int index;
ptt_t ptt_response = -1;
@ -1288,7 +1533,7 @@ int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
}
int ft817_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
static int ft817_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
@ -1329,7 +1574,7 @@ int ft817_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
}
}
int ft817_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
static int ft817_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
/* int n; */
@ -1356,7 +1601,7 @@ int ft817_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
return ft817_send_icmd(rig, FT817_NATIVE_CAT_SET_DCS_CODE, data);
}
int ft817_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
static int ft817_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
int n;
@ -1381,7 +1626,7 @@ int ft817_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
}
int ft817_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
static int ft817_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
int n;
@ -1406,7 +1651,7 @@ int ft817_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
}
int ft817_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
static int ft817_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
int n;
@ -1430,7 +1675,7 @@ int ft817_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
return ft817_send_cmd(rig, FT817_NATIVE_CAT_SET_CTCSS_ON);
}
int ft817_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t shift)
static int ft817_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t shift)
{
/* Note: this doesn't have effect unless FT817 is in FM mode
although the command is accepted in any mode.
@ -1454,7 +1699,7 @@ int ft817_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t shift)
return -RIG_EINVAL;
}
int ft817_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs)
static int ft817_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
@ -1466,7 +1711,7 @@ int ft817_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs)
return ft817_send_icmd(rig, FT817_NATIVE_CAT_SET_RPT_OFFSET, data);
}
int ft817_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit)
static int ft817_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit)
{
unsigned char data[YAESU_CMD_LENGTH - 1];
int n;
@ -1521,7 +1766,7 @@ int ft817_set_powerstat(RIG *rig, powerstat_t status)
}
}
int ft817_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op)
static int ft817_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
@ -1545,7 +1790,7 @@ int ft817_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op)
/* FIXME: this function silently ignores the vfo args and just turns
split ON or OFF.
*/
int ft817_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
static int ft817_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
{
int index, n;
@ -1588,7 +1833,7 @@ int ft817_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo)
3 bars = 1W
1 bar = 0.5W
*/
int ft817_power2mW(RIG *rig, unsigned int *mwpower, float power,
static int ft817_power2mW(RIG *rig, unsigned int *mwpower, float power,
freq_t freq, rmode_t mode)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
@ -1598,7 +1843,7 @@ int ft817_power2mW(RIG *rig, unsigned int *mwpower, float power,
/* FIXME: currently ignores mode and freq */
int ft817_mW2power(RIG *rig, float *power, unsigned int mwpower,
static int ft817_mW2power(RIG *rig, float *power, unsigned int mwpower,
freq_t freq, rmode_t mode)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);

Wyświetl plik

@ -75,83 +75,7 @@
*/
#define FT817_CACHE_TIMEOUT 50
enum ft817_native_cmd_e
{
FT817_NATIVE_CAT_LOCK_ON = 0,
FT817_NATIVE_CAT_LOCK_OFF,
FT817_NATIVE_CAT_PTT_ON,
FT817_NATIVE_CAT_PTT_OFF,
FT817_NATIVE_CAT_SET_FREQ,
FT817_NATIVE_CAT_SET_MODE_LSB,
FT817_NATIVE_CAT_SET_MODE_USB,
FT817_NATIVE_CAT_SET_MODE_CW,
FT817_NATIVE_CAT_SET_MODE_CWR,
FT817_NATIVE_CAT_SET_MODE_AM,
FT817_NATIVE_CAT_SET_MODE_FM,
FT817_NATIVE_CAT_SET_MODE_FM_N,
FT817_NATIVE_CAT_SET_MODE_DIG,
FT817_NATIVE_CAT_SET_MODE_PKT,
FT817_NATIVE_CAT_CLAR_ON,
FT817_NATIVE_CAT_CLAR_OFF,
FT817_NATIVE_CAT_SET_CLAR_FREQ,
FT817_NATIVE_CAT_SET_VFOAB,
FT817_NATIVE_CAT_SPLIT_ON,
FT817_NATIVE_CAT_SPLIT_OFF,
FT817_NATIVE_CAT_SET_RPT_SHIFT_MINUS,
FT817_NATIVE_CAT_SET_RPT_SHIFT_PLUS,
FT817_NATIVE_CAT_SET_RPT_SHIFT_SIMPLEX,
FT817_NATIVE_CAT_SET_RPT_OFFSET,
FT817_NATIVE_CAT_SET_DCS_ON,
FT817_NATIVE_CAT_SET_CTCSS_ON,
FT817_NATIVE_CAT_SET_CTCSS_ENC_ON,
FT817_NATIVE_CAT_SET_CTCSS_DCS_OFF,
FT817_NATIVE_CAT_SET_CTCSS_FREQ,
FT817_NATIVE_CAT_SET_DCS_CODE,
FT817_NATIVE_CAT_GET_RX_STATUS,
FT817_NATIVE_CAT_GET_TX_STATUS,
FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS,
FT817_NATIVE_CAT_PWR_WAKE,
FT817_NATIVE_CAT_PWR_ON,
FT817_NATIVE_CAT_PWR_OFF,
FT817_NATIVE_CAT_EEPROM_READ,
FT817_NATIVE_SIZE /* end marker */
};
typedef enum ft817_native_cmd_e ft817_native_cmd_t;
/* fixme: why declare static? it has no effect */
static int ft817_init(RIG *rig);
static int ft817_open(RIG *rig);
static int ft817_cleanup(RIG *rig);
static int ft817_close(RIG *rig);
static int ft817_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
static int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
static int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
static int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
static int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt);
static int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
static int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
static int ft817_set_func(RIG *rig, vfo_t vfo, setting_t func, int status);
static int ft817_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code);
static int ft817_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone);
static int ft817_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code);
static int ft817_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone);
static int ft817_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t shift);
static int ft817_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs);
static int ft817_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit);
static int ft817_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd);
int ft817_set_powerstat(RIG *rig, powerstat_t status);
static int ft817_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op);
static int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split,
vfo_t *tx_vfo);
static int ft817_set_split_vfo(RIG *rig, vfo_t vfo, split_t split,
vfo_t tx_vfo);
static int ft817_power2mW(RIG *rig, unsigned int *mwpower, float power,
freq_t freq, rmode_t mode);
static int ft817_mW2power(RIG *rig, float *power, unsigned int mwpower,
freq_t freq, rmode_t mode);
int ft817_read_ack(RIG *rig);
#endif /* _FT817_H */

Wyświetl plik

@ -70,6 +70,7 @@
#include "serial.h"
#include "yaesu.h"
#include "ft857.h"
#include "ft817.h" /* We use functions from the 817 code */
#include "misc.h"
#include "tones.h"
#include "bandplan.h"
@ -240,8 +241,6 @@ enum ft857_digi
#define FT857_VFO_ALL (RIG_VFO_A|RIG_VFO_B)
#define FT857_ANTS 0
extern int ft817_read_ack(RIG *rig);
extern int ft817_set_powerstat(RIG *rig, powerstat_t status);
static int ft857_send_icmd(RIG *rig, int index, unsigned char *data);
const struct rig_caps ft857_caps =

Wyświetl plik

@ -75,6 +75,7 @@
#include "serial.h"
#include "yaesu.h"
#include "ft897.h"
#include "ft817.h" /* We use functions from the 817 code */
#include "ft857.h" //Needed for ft857_set_vfo, ft857_get_vfo
#include "misc.h"
#include "tones.h"
@ -170,8 +171,6 @@ static int ft897_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift);
static int ft897_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs);
static int ft897_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit);
static int ft897_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd);
extern int ft817_read_ack(RIG *rig);
extern int ft817_set_powerstat(RIG *rig, powerstat_t status);
/* Native ft897 cmd set prototypes. These are READ ONLY as each */
/* rig instance will copy from these and modify if required . */