diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index ba3407bee..185ae7557 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -69,6 +69,7 @@ #include "misc.h" #include "tones.h" #include "bandplan.h" +#include "cal.h" /* Native ft817 cmd set prototypes. These are READ ONLY as each */ @@ -159,12 +160,43 @@ enum ft817_digi { 0x0F, 60 } /* +60 */ \ } } +// Thanks to Olivier Schmitt sc.olivier@gmail.com for these tables +#define FT817_PWR_CAL { 9, \ + { \ + { 0x00, 0 }, \ + { 0x01, 10 }, \ + { 0x02, 14 }, \ + { 0x03, 20 }, \ + { 0x04, 34 }, \ + { 0x05, 50 }, \ + { 0x06, 66 }, \ + { 0x07, 82 }, \ + { 0x08, 100 } \ + } } + +#define FT817_ALC_CAL { 6, \ + { \ + { 0x00, 0 }, \ + { 0x01, 20 }, \ + { 0x02, 40 }, \ + { 0x03, 60 }, \ + { 0x04, 80 }, \ + { 0x05, 100 } \ + } } + +#define FT817_SWR_CAL { 2, \ + { \ + { 0, 0 }, \ + { 15, 100 } \ + } } + + const struct rig_caps ft817_caps = { RIG_MODEL(RIG_MODEL_FT817), .model_name = "FT-817", .mfg_name = "Yaesu", - .version = "20200903.0", + .version = "20201009.0", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -267,7 +299,10 @@ const struct rig_caps ft817_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, @@ -572,7 +607,7 @@ static int ft817_get_status(RIG *rig, int status) case FT817_NATIVE_CAT_GET_RX_STATUS: data = &p->rx_status; - len = 1; + len = 2; tv = &p->rx_status_tv; break; @@ -803,6 +838,37 @@ 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) +{ + 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->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; @@ -824,11 +890,9 @@ static int ft817_get_pometer_level(RIG *rig, value_t *val) */ if ((p->tx_status & 0x80) == 0) { - /* the rig has 10 bars on its display */ - val->f = (p->tx_status & 0x0F) / 10.0; - + val->f = rig_raw2val_float(p->tx_status >> 4, &rig->caps->rfpower_meter_cal); } - else + else // not transmitting so zero { val->f = 0.0; } @@ -836,7 +900,6 @@ static int ft817_get_pometer_level(RIG *rig, value_t *val) return RIG_OK; } - /* frontend will always use RAWSTR+cal_table */ static int ft817_get_smeter_level(RIG *rig, value_t *val) { @@ -919,6 +982,10 @@ int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return ft817_get_pometer_level(rig, val); break; + case RIG_LEVEL_ALC: + return ft817_get_alc_level(rig, val); + break; + default: return -RIG_EINVAL; } diff --git a/rigs/yaesu/ft817.h b/rigs/yaesu/ft817.h index d5f1a2192..d6fe017a5 100644 --- a/rigs/yaesu/ft817.h +++ b/rigs/yaesu/ft817.h @@ -33,7 +33,7 @@ /* * No need to wait between written characters. */ -#define FT817_WRITE_DELAY 1 +#define FT817_WRITE_DELAY 1 /* * Wait 'delay' milliseconds after writing a command sequence. @@ -45,19 +45,19 @@ * A non-zero value disables waiting for the ack. Processing a command * seems to take about 60 ms so set this to 80 or so to be safe. */ -#define FT817_POST_WRITE_DELAY 0 +#define FT817_POST_WRITE_DELAY 0 /* * Read timeout. */ -#define FT817_TIMEOUT 3000 +#define FT817_TIMEOUT 3000 /* * Return from TX to RX may have a delay. If status is not changed * on the first attempt, wait this amount of milliseconds before * each next next attempts. */ -#define FT817_RETRY_DELAY 100 +#define FT817_RETRY_DELAY 100 /* * The time the TX, RX and FREQ/MODE status are cached (in millisec). @@ -73,98 +73,102 @@ * * doesn't return a bogus (cached) value in the last rig_get_freq(). */ -#define FT817_CACHE_TIMEOUT 50 +#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, +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 */ + FT817_NATIVE_SIZE /* end marker */ }; typedef enum ft817_native_cmd_e ft817_native_cmd_t; -struct ft817_priv_data { - yaesu_cmd_set_t pcs[FT817_NATIVE_SIZE]; /* TODO: why? */ +struct ft817_priv_data +{ + yaesu_cmd_set_t pcs[FT817_NATIVE_SIZE]; /* TODO: why? */ - /* rx status */ - struct timeval rx_status_tv; - unsigned char rx_status; + /* rx status */ + struct timeval rx_status_tv; + unsigned char rx_status; - /* tx status */ - struct timeval tx_status_tv; - unsigned char tx_status; + /* tx status */ + struct timeval tx_status_tv; + unsigned char tx_status; - /* freq & mode status */ - struct timeval fm_status_tv; - unsigned char fm_status[YAESU_CMD_LENGTH+1]; + /* freq & mode status */ + struct timeval fm_status_tv; + unsigned char fm_status[YAESU_CMD_LENGTH + 1]; }; /* 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); +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); #endif /* _FT817_H */