diff --git a/yaesu/Makefile.am b/yaesu/Makefile.am index fc83d624c..d92977a6c 100644 --- a/yaesu/Makefile.am +++ b/yaesu/Makefile.am @@ -1,8 +1,9 @@ -YAESUSRC = ft747.c ft817.c ft847.c ft100.c ft920.c +YAESUSRC = ft747.c ft817.c ft847.c ft100.c ft920.c ft1000.c lib_LTLIBRARIES = hamlib-yaesu.la hamlib_yaesu_la_SOURCES = $(YAESUSRC) yaesu.c hamlib_yaesu_la_LDFLAGS = -no-undefined -module -avoid-version hamlib_yaesu_la_LIBADD = $(top_builddir)/src/libhamlib.la -noinst_HEADERS = ft747.h ft100.h ft817.h ft847.h ft920.h yaesu.h yaesu_tones.h +noinst_HEADERS = ft747.h ft100.h ft817.h ft847.h ft920.h ft1000.h \ + yaesu.h yaesu_tones.h diff --git a/yaesu/ft1000.c b/yaesu/ft1000.c new file mode 100644 index 000000000..c7eee95f4 --- /dev/null +++ b/yaesu/ft1000.c @@ -0,0 +1,822 @@ +/* + * ft1000.c - (C) Stephane Fillod 2002 (fillods@users.sourceforge.net) + * + * This shared library provides an API for communicating + * via serial interface to an FT-1000MP using the "CAT" interface + * + * $Id: ft1000.c,v 1.1 2002-11-21 23:09:28 fillods Exp $ + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* + * Right now, this FT-1000MP implementation is a big mess. + * This is actually a fast copy past (from ft920.c), + * just to make get_freq/set_freq and co to work for a friend of mine. + * I wouln't mind if someone could take over the maintenance + * of this piece of code, and eventually rewrite it. + * '02, Stephane + */ + + +#include +#include /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include /* POSIX terminal control definitions */ +#include + +#include +#include +#include "serial.h" +#include "misc.h" +#include "yaesu.h" +#include "ft1000.h" + + +/* Private helper function prototypes */ + +static int ft1000mp_get_update_data(RIG *rig, unsigned char ci, unsigned char rl); +static int ft1000mp_send_priv_cmd(RIG *rig, unsigned char ci); + +/* + * Native ft1000mp cmd set prototypes. These are READ ONLY as each + * rig instance will copy from these and modify if required. + * Complete sequences (1) can be read and used directly as a cmd sequence. + * Incomplete sequences (0) must be completed with extra parameters + * eg: mem number, or freq etc.. + * + */ + +static const yaesu_cmd_set_t ncmd[] = { + { 1, { 0x00, 0x00, 0x00, 0x00, 0x01 } }, /* split = off */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0x01 } }, /* split = on */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x02 } }, /* recall memory */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x03 } }, /* memory operations */ + { 1, { 0x00, 0x00, 0x00, 0x00, 0x05 } }, /* select vfo A */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0x05 } }, /* select vfo B */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x06 } }, /* copy memory data to vfo A */ +/* { 0, { 0x00, 0x00, 0x00, 0x00, 0x09 } }, */ /* clarifier operations */ +/* { 1, { 0x00, 0x00, 0x00, 0x01, 0x09 } }, */ /* RX clarifier on */ +/* { 1, { 0x00, 0x00, 0x00, 0x80, 0x09 } }, */ /* TX clarifier on */ +/* { 1, { 0x00, 0x00, 0x00, 0x81, 0x09 } }, */ /* TX clarifier on */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x0a } }, /* set VFOA freq */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x8a } }, /* set VFOB freq */ + + { 1, { 0x00, 0x00, 0x00, 0x00, 0x0c } }, /* vfo A mode set LSB */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0x0c } }, /* vfo A mode set USB */ + { 1, { 0x00, 0x00, 0x00, 0x02, 0x0c } }, /* vfo A mode set CW-USB */ + { 1, { 0x00, 0x00, 0x00, 0x03, 0x0c } }, /* vfo A mode set CW-LSB */ + { 1, { 0x00, 0x00, 0x00, 0x04, 0x0c } }, /* vfo A mode set AM */ + { 1, { 0x00, 0x00, 0x00, 0x05, 0x0c } }, /* vfo A mode set AM sync */ + { 1, { 0x00, 0x00, 0x00, 0x06, 0x0c } }, /* vfo A mode set FM */ + { 1, { 0x00, 0x00, 0x00, 0x07, 0x0c } }, /* vfo A mode set FMW? */ + { 1, { 0x00, 0x00, 0x00, 0x08, 0x0c } }, /* vfo A mode set RTTY-LSB */ + { 1, { 0x00, 0x00, 0x00, 0x09, 0x0c } }, /* vfo A mode set RTTY-USB */ + { 1, { 0x00, 0x00, 0x00, 0x0a, 0x0c } }, /* vfo A mode set DATA-LSB */ + { 1, { 0x00, 0x00, 0x00, 0x0b, 0x0c } }, /* vfo A mode set DATA-FM */ + +/* { 1, { 0x00, 0x00, 0x00, 0x80, 0x0c } }, */ /* vfo B mode set LSB */ +/* { 1, { 0x00, 0x00, 0x00, 0x81, 0x0c } }, */ /* vfo B mode set USB */ +/* { 1, { 0x00, 0x00, 0x00, 0x82, 0x0c } }, */ /* vfo B mode set CW-USB */ +/* { 1, { 0x00, 0x00, 0x00, 0x83, 0x0c } }, */ /* vfo B mode set CW-LSB */ +/* { 1, { 0x00, 0x00, 0x00, 0x84, 0x0c } }, */ /* vfo B mode set AM */ +/* { 1, { 0x00, 0x00, 0x00, 0x85, 0x0c } }, */ /* vfo B mode set AM */ +/* { 1, { 0x00, 0x00, 0x00, 0x86, 0x0c } }, */ /* vfo B mode set FM */ +/* { 1, { 0x00, 0x00, 0x00, 0x87, 0x0c } }, */ /* vfo B mode set FMN */ +/* { 1, { 0x00, 0x00, 0x00, 0x88, 0x0c } }, */ /* vfo B mode set DATA-LSB */ +/* { 1, { 0x00, 0x00, 0x00, 0x89, 0x0c } }, */ /* vfo B mode set DATA-LSB */ +/* { 1, { 0x00, 0x00, 0x00, 0x8a, 0x0c } }, */ /* vfo B mode set DATA-USB */ +/* { 1, { 0x00, 0x00, 0x00, 0x8b, 0x0c } }, */ /* vfo B mode set DATA-FM */ + + { 0, { 0x00, 0x00, 0x00, 0x00, 0x0e } }, /* update interval/pacing */ + { 1, { 0x00, 0x00, 0x00, 0x03, 0x10 } }, /* status update VFO A & B update */ + { 1, { 0x00, 0x00, 0x00, 0x02, 0x10 } }, /* status update operating data */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0xFA } }, /* Read status flags */ +/* { 0, { 0x00, 0x00, 0x00, 0x00, 0x70 } }, */ /* keyer commands */ +/* { 1, { 0x00, 0x00, 0x00, 0x00, 0x81 } }, */ /* tuner off */ +/* { 1, { 0x00, 0x00, 0x00, 0x01, 0x81 } }, */ /* tuner on */ +/* { 1, { 0x00, 0x00, 0x00, 0x00, 0x82 } }, */ /* tuner start*/ + +}; + + + +#define FT1000MP_ALL_RX_MODES (RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_RTTY|RIG_MODE_AM|RIG_MODE_FM) + +/* + * TX caps + */ + +#define FT1000MP_OTHER_TX_MODES (RIG_MODE_CW| RIG_MODE_SSB|RIG_MODE_RTTY|RIG_MODE_FM) /* 100 W class */ +#define FT1000MP_AM_TX_MODES (RIG_MODE_AM ) /* set 25W max */ + +#define FT1000MP_FUNC_ALL (RIG_FUNC_FAGC|RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_TONE|RIG_FUNC_TSQL|RIG_FUNC_SBKIN|RIG_FUNC_FBKIN|RIG_FUNC_LOCK /* |RIG_FUNC_TUNER */) /* FIXME */ + +#define FT1000MP_LEVEL_GET (RIG_LEVEL_STRENGTH|RIG_LEVEL_ALC|RIG_LEVEL_SWR|RIG_LEVEL_RFPOWER|RIG_LEVEL_COMP|RIG_LEVEL_MICGAIN|RIG_LEVEL_CWPITCH) + +#define FT1000MP_VFOS (RIG_VFO_A|RIG_VFO_B) +#define FT1000MP_ANTS 0 /* FIXME: declare antenna connectors: ANT-A, ANT-B, RX ANT */ + +#define FT1000MP_VFO_OPS (RIG_OP_TO_VFO|RIG_OP_FROM_VFO|RIG_OP_CPY|RIG_OP_UP|RIG_OP_DOWN) + +/** + * 33 CTCSS sub-audible tones + */ +const tone_t ft1000mp_ctcss_list[] = { + 670, 719, 770, 825, 885, + 948, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, + 1318, 1365, 1413, 1462, 1514, 1567, 1598, 1622, 1679, + 1738, 1799, 1862, 1928, + 2035, 2107, 2181, 2257, 2336, 2418, 2503, + 0, +}; + +#define FT1000MP_MEM_CAP { \ + .freq = 1, \ + .mode = 1, \ + .width = 1, \ + .ant = 1, \ + .rit = 1, \ + .xit = 1, \ + .rptr_shift = 1, \ + .flags = 1, \ + } +/* + * future - private data + * + */ + +struct ft1000mp_priv_data { + unsigned char pacing; /* pacing value */ + unsigned int read_update_delay; /* depends on pacing value */ + unsigned char current_vfo; /* active VFO from last cmd */ + unsigned char p_cmd[YAESU_CMD_LENGTH]; /* private copy of 1 constructed CAT cmd */ + yaesu_cmd_set_t pcs[FT1000MP_NATIVE_SIZE]; /* private cmd set */ + unsigned char update_data[2*FT1000MP_STATUS_UPDATE_LENGTH];/* returned data--max value, some are less */ +}; + + +/* + * ft1000mp rigs capabilities. + * Also this struct is READONLY! + * + */ + +const struct rig_caps ft1000mp_caps = { + .rig_model = RIG_MODEL_FT1000MP, + .model_name = "MARK-V FT-1000MP", + .mfg_name = "Yaesu", + .version = "0.0.4", + .copyright = "LGPL", + .status = RIG_STATUS_NEW, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_RIG, + .dcd_type = RIG_DCD_RIG, + .port_type = RIG_PORT_SERIAL, + .serial_rate_min = 4800, + .serial_rate_max = 4800, + .serial_data_bits = 8, + .serial_stop_bits = 2, + .serial_parity = RIG_PARITY_NONE, + .serial_handshake = RIG_HANDSHAKE_NONE, + .write_delay = FT1000MP_WRITE_DELAY, + .post_write_delay = FT1000MP_POST_WRITE_DELAY, + .timeout = 2000, + .retry = 0, + .has_get_func = FT1000MP_FUNC_ALL, + .has_set_func = FT1000MP_FUNC_ALL, + .has_get_level = FT1000MP_LEVEL_GET, + .has_set_level = RIG_LEVEL_NONE, /* as strange as it could be */ + .has_get_parm = RIG_PARM_NONE, + .has_set_parm = RIG_PARM_NONE, + .ctcss_list = ft1000mp_ctcss_list, + .dcs_list = NULL, + .vfo_ops = FT1000MP_VFO_OPS, + .preamp = { RIG_DBLST_END, }, + .attenuator = { RIG_DBLST_END, }, + .max_rit = Hz(9999), + .max_xit = Hz(9999), + .max_ifshift = kHz(1.12), + .targetable_vfo = RIG_TARGETABLE_FREQ, + .transceive = RIG_TRN_OFF, + .bank_qty = 0, + .chan_desc_sz = 0, + .chan_list = { + { 1, 99, RIG_MTYPE_MEM, FT1000MP_MEM_CAP }, + { 100, 108, RIG_MTYPE_EDGE }, /* P1 .. P9 */ + { 109, 113, RIG_MTYPE_MEMOPAD }, /* Q1 .. Q5 */ + RIG_CHAN_END, + }, + .rx_range_list1 = { + {kHz(100), MHz(30), FT1000MP_ALL_RX_MODES, -1, -1, FT1000MP_VFOS, FT1000MP_ANTS }, /* General coverage + ham */ + RIG_FRNG_END, + }, /* Region 1 rx ranges */ + + .tx_range_list1 = { + FRQ_RNG_HF(1,FT1000MP_OTHER_TX_MODES, W(5),W(100),FT1000MP_VFOS,FT1000MP_ANTS), + FRQ_RNG_HF(1,FT1000MP_AM_TX_MODES, W(2),W(25),FT1000MP_VFOS,FT1000MP_ANTS), /* AM class */ + RIG_FRNG_END, + }, /* region 1 TX ranges */ + + .rx_range_list2 = { + {kHz(100), MHz(30), FT1000MP_ALL_RX_MODES, -1, -1, FT1000MP_VFOS, FT1000MP_ANTS }, /* General coverage + ham */ + RIG_FRNG_END, + }, /* Region 2 rx ranges */ + + .tx_range_list2 = { + FRQ_RNG_HF(1,FT1000MP_OTHER_TX_MODES, W(5),W(100),FT1000MP_VFOS,FT1000MP_ANTS), + FRQ_RNG_HF(1,FT1000MP_AM_TX_MODES, W(2),W(25),FT1000MP_VFOS,FT1000MP_ANTS), /* AM class */ + RIG_FRNG_END, + }, /* region 2 TX ranges */ + + .tuning_steps = { + {RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_RTTY, Hz(10)}, /* Normal */ + {RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_RTTY, Hz(100)}, /* Fast */ + + {RIG_MODE_AM, Hz(100)}, /* Normal */ + {RIG_MODE_AM, kHz(1)}, /* Fast */ + + {RIG_MODE_FM, Hz(100)}, /* Normal */ + {RIG_MODE_FM, kHz(1)}, /* Fast */ + + RIG_TS_END, + + /* + * The FT-1000MP has a Fine tuning step which increments in 1 Hz steps + * for SSB_CW_RX_MODES, and 10 Hz steps for AM_RX_MODES and + * FM_RX_MODES. It doesn't appear that anything finer than 10 Hz + * is available through the CAT interface, however. -N0NB + * + */ + }, + + /* mode/filter list, .remember = order matters! */ + .filters = { + {RIG_MODE_SSB|RIG_MODE_CW|RIG_MODE_RTTY|RIG_MODE_AM, kHz(2.4)}, + {RIG_MODE_SSB|RIG_MODE_CW|RIG_MODE_RTTY, kHz(2.0)}, + {RIG_MODE_CW|RIG_MODE_RTTY, Hz(500)}, + {RIG_MODE_CW|RIG_MODE_RTTY, Hz(250)}, + {RIG_MODE_AM, kHz(5)}, /* wide */ + {RIG_MODE_FM, kHz(8)}, /* FM */ + + RIG_FLT_END, + }, + + .priv = NULL, /* private data */ + + .rig_init = ft1000mp_init, + .rig_cleanup = ft1000mp_cleanup, + .rig_open = ft1000mp_open, /* port opened */ + + .set_freq = ft1000mp_set_freq, /* set freq */ + .get_freq = ft1000mp_get_freq, /* get freq */ + .set_mode = ft1000mp_set_mode, /* set mode */ + .get_mode = ft1000mp_get_mode, /* get mode */ + .set_vfo = ft1000mp_set_vfo, /* set vfo */ + .get_vfo = ft1000mp_get_vfo, /* get vfo */ + + /* TODO: the remaining ... */ +}; + + +/* + * _init + * + */ + +int ft1000mp_init(RIG *rig) { + struct ft1000mp_priv_data *p; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: ft1000mp_init called \n"); + + if (!rig) + return -RIG_EINVAL; + + p = (struct ft1000mp_priv_data*)malloc(sizeof(struct ft1000mp_priv_data)); + if (!p) /* whoops! memory shortage! */ + return -RIG_ENOMEM; + + /* + * Copy native cmd set to private cmd storage area + */ + memcpy(p->pcs,ncmd,sizeof(ncmd)); + + /* TODO: read pacing from preferences */ + p->pacing = FT1000MP_PACING_DEFAULT_VALUE; /* set pacing to minimum for now */ + p->read_update_delay = FT1000MP_DEFAULT_READ_TIMEOUT; /* set update timeout to safe value */ + p->current_vfo = RIG_VFO_A; /* default to VFO_A ? */ + rig->state.priv = (void*)p; + + return RIG_OK; +} + + +/* + * ft1000mp_cleanup routine + * the serial port is closed by the frontend + * + */ + +int ft1000mp_cleanup(RIG *rig) { + + rig_debug(RIG_DEBUG_VERBOSE, "ft1000mp: ft1000mp_cleanup called\n"); + + if (!rig) + return -RIG_EINVAL; + + if (rig->state.priv) + free(rig->state.priv); + rig->state.priv = NULL; + + return RIG_OK; +} + + +/* + * ft1000mp_open routine + * + */ + +int ft1000mp_open(RIG *rig) { + struct rig_state *rig_s; + struct ft1000mp_priv_data *p; + unsigned char *cmd; /* points to sequence to send */ + + rig_debug(RIG_DEBUG_VERBOSE, "ft1000mp: ft1000mp_open called\n"); + + if (!rig) + return -RIG_EINVAL; + + rig_s = &rig->state; + p = (struct ft1000mp_priv_data *)rig_s->priv; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: rig_open: write_delay = %i msec \n", + rig_s->rigport.write_delay); + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: rig_open: post_write_delay = %i msec \n", + rig_s->rigport.post_write_delay); + + /* + * Copy native cmd PACING to private cmd storage area + */ + memcpy(&p->p_cmd, &ncmd[FT1000MP_NATIVE_PACING].nseq, YAESU_CMD_LENGTH); + p->p_cmd[3] = p->pacing; /* get pacing value, and store in private cmd */ + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: read pacing = %i\n",p->pacing); + + /* send PACING cmd to rig */ + cmd = p->p_cmd; + write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH); + + /* TODO */ + + return RIG_OK; +} + + + +/* + * Example of wrapping backend function inside frontend API + * + */ + +int ft1000mp_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { + struct rig_state *rig_s; + struct ft1000mp_priv_data *p; + unsigned char *cmd; /* points to sequence to send */ + int cmd_index = 0; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: ft1000mp_set_freq called\n"); + + if (!rig) + return -RIG_EINVAL; + + p = (struct ft1000mp_priv_data*)rig->state.priv; + + rig_s = &rig->state; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: requested freq = %lli Hz \n", freq); + + if (vfo == RIG_VFO_CURR) + vfo = p->current_vfo; + + switch (vfo) { + case RIG_VFO_A: + cmd_index = FT1000MP_NATIVE_FREQA_SET; + break; + case RIG_VFO_B: + cmd_index = FT1000MP_NATIVE_FREQB_SET; + break; + case RIG_VFO_MEM: + /* TODO, hint: store current memory number */ + return -RIG_ENIMPL; + default: + rig_debug(RIG_DEBUG_WARN,"ft1000mp: unknown VFO %d\n", vfo); + return -RIG_EINVAL; + } + /* + * Copy native cmd freq_set to private cmd storage area + */ + memcpy(&p->p_cmd,&ncmd[cmd_index].nseq,YAESU_CMD_LENGTH); + + to_bcd(p->p_cmd,freq/10,8); /* store bcd format in in p_cmd */ + /* TODO -- fix 10Hz resolution -- FS */ + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: requested freq after conversion = %lli Hz\n", + from_bcd(p->p_cmd,8)* 10 ); + + cmd = p->p_cmd; /* get native sequence */ + write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH); + + return RIG_OK; +} + + +/* + * Return Freq for a given VFO + * + */ + +int ft1000mp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { + struct ft1000mp_priv_data *priv; + unsigned char *p; + freq_t f; + int cmd_index, len, retval; + + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: ft1000mp_get_freq called\n"); + + if (!rig) + return -RIG_EINVAL; + + priv = (struct ft1000mp_priv_data*)rig->state.priv; + + + if (vfo == RIG_VFO_A || vfo == RIG_VFO_B) { + cmd_index = FT1000MP_NATIVE_VFO_UPDATE; + len = 2*FT1000MP_STATUS_UPDATE_LENGTH; + } else { + /* RIG_VFO_CURR or RIG_VFO_MEM */ + cmd_index = FT1000MP_NATIVE_CURR_VFO_UPDATE; + len = FT1000MP_STATUS_UPDATE_LENGTH; + } + + /* + * get record from rig + */ + retval = ft1000mp_get_update_data(rig, cmd_index, len); + if (retval < 0) + return retval; + + if (vfo == RIG_VFO_B) + p = &priv->update_data[FT1000MP_SUMO_VFO_B_FREQ]; + else + p = &priv->update_data[FT1000MP_SUMO_VFO_A_FREQ]; /* CURR_VFO has VFOA offset */ + + /* little endian BCD */ + f = from_bcd(p, 8) * 10; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: freq = %lli Hz for VFO [%x]\n", f, vfo); + + *freq = f; /* return diplayed frequency */ + + return RIG_OK; +} + + +/* + * set mode : eg AM, CW etc for a given VFO + * + */ + +int ft1000mp_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width ) { + unsigned char cmd_index = 0; /* index of sequence to send */ + + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: ft1000mp_set_mode called\n"); + + if (!rig) + return -RIG_EINVAL; + + /* frontend sets VFO for us */ + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: generic mode = %x\n", mode); + + /* + * translate mode from generic to ft1000mp specific + */ + switch(mode) { + case RIG_MODE_AM: + cmd_index = FT1000MP_NATIVE_MODE_SET_AM; + break; + case RIG_MODE_CW: + cmd_index = FT1000MP_NATIVE_MODE_SET_CW; + break; + case RIG_MODE_USB: + cmd_index = FT1000MP_NATIVE_MODE_SET_USB; + break; + case RIG_MODE_LSB: + cmd_index = FT1000MP_NATIVE_MODE_SET_LSB; + break; + case RIG_MODE_FM: + cmd_index = FT1000MP_NATIVE_MODE_SET_FM; + break; + case RIG_MODE_RTTY: + cmd_index = FT1000MP_NATIVE_MODE_SET_RTTY_LSB; + break; + default: + return -RIG_EINVAL; /* sorry, wrong MODE */ + } + + + /* + * Now set width + * FIXME: so far setting passband is buggy, only 0 is accepted + */ + + + /* + * phew! now send cmd to rig + */ + ft1000mp_send_priv_cmd(rig,cmd_index); + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: cmd_index = %i\n", cmd_index); + + return RIG_OK; /* good */ + +} + + +/* + * get mode : eg AM, CW etc for a given VFO + * + */ + +int ft1000mp_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { + struct ft1000mp_priv_data *priv; + unsigned char mymode; /* ft1000mp mode */ + int cmd_index, len, retval; + + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: ft1000mp_get_mode called\n"); + + if (!rig) + return -RIG_EINVAL; + + priv = (struct ft1000mp_priv_data*)rig->state.priv; + + if (vfo == RIG_VFO_A || vfo == RIG_VFO_B) { + cmd_index = FT1000MP_NATIVE_VFO_UPDATE; + len = 2*FT1000MP_STATUS_UPDATE_LENGTH; + } else { + /* RIG_VFO_CURR or RIG_VFO_MEM */ + cmd_index = FT1000MP_NATIVE_CURR_VFO_UPDATE; + len = FT1000MP_STATUS_UPDATE_LENGTH; + } + + /* + * get record from rig + */ + retval = ft1000mp_get_update_data(rig, cmd_index, len); + if (retval < 0) + return retval; + + if (vfo == RIG_VFO_B) + mymode = priv->update_data[FT1000MP_SUMO_VFO_B_MODE]; + else + mymode = priv->update_data[FT1000MP_SUMO_VFO_A_MODE]; /* CURR_VFO has VFOA offset */ + + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mymode = %x (before)\n", mymode); + mymode &= MODE_MASK; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mymode = %x (after)\n", mymode); + + /* + * translate mode from ft1000mp to generic. + * TODO: Add DATA, and Narrow modes. CW on LSB? -N0NB + * + * FIXME: don't know bit order. manual is not reliable!! -F8CFE + */ + switch(mymode) { + case MODE_FM: + (*mode) = RIG_MODE_FM; + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mode = FM\n"); + break; + case MODE_AM: + (*mode) = RIG_MODE_AM; + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mode = AM\n"); + break; + case MODE_CW_U: + (*mode) = RIG_MODE_CW; + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mode = CW_U\n"); + break; + case MODE_USB: + (*mode) = RIG_MODE_USB; + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mode = USB\n"); + break; + case MODE_LSB: + (*mode) = RIG_MODE_LSB; + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: mode = LSB\n"); + break; + + default: + return -RIG_EINVAL; /* sorry, wrong mode */ + break; + } + + *width = RIG_PASSBAND_NORMAL; + + return RIG_OK; +} + + +/* + * set vfo and store requested vfo for later RIG_VFO_CURR + * requests. + * + */ + +int ft1000mp_set_vfo(RIG *rig, vfo_t vfo) { + struct rig_state *rig_s; + struct ft1000mp_priv_data *p; + unsigned char cmd_index = 0; /* index of sequence to send */ + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: ft1000mp_set_vfo called\n"); + + if (!rig) + return -RIG_EINVAL; + + p = (struct ft1000mp_priv_data*)rig->state.priv; + rig_s = &rig->state; + + + /* + * RIG_VFO_VFO/RIG_VFO_MEM are not available + * so try to emulate them. + * looks like there's no RIG_VFO_MEM, maybe setting mem# + * switch to it automatically? + */ + + if (vfo == RIG_VFO_VFO) { + vfo = p->current_vfo; + } + + switch(vfo) { + case RIG_VFO_A: + cmd_index = FT1000MP_NATIVE_VFO_A; + p->current_vfo = vfo; /* update active VFO */ + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: vfo == RIG_VFO_A\n"); + break; + case RIG_VFO_B: + cmd_index = FT1000MP_NATIVE_VFO_B; + p->current_vfo = vfo; /* update active VFO */ + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: vfo == RIG_VFO_B\n"); + break; + case RIG_VFO_CURR: + /* do nothing, we're already at it! */ + break; + default: + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: Unknown default VFO %d\n", vfo); + return -RIG_EINVAL; /* sorry, wrong VFO */ + } + + /* + * phew! now send cmd to rig + */ + ft1000mp_send_priv_cmd(rig,cmd_index); + + return RIG_OK; + +} + + +/* + * get vfo and store requested vfo for later RIG_VFO_CURR + * requests. + * + */ + +int ft1000mp_get_vfo(RIG *rig, vfo_t *vfo) { + struct ft1000mp_priv_data *p; + int retval; + + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: ft1000mp_get_vfo called\n"); + + if (!rig) + return -RIG_EINVAL; + + p = (struct ft1000mp_priv_data*)rig->state.priv; + + /* Get flags for VFO status */ + retval = ft1000mp_get_update_data(rig, FT1000MP_NATIVE_UPDATE, + FT1000MP_STATUS_FLAGS_LENGTH); + if (retval < 0) + return retval; + + if (p->update_data[1] & 0x40) + *vfo = RIG_VFO_MEM; + else if (p->update_data[FT1000MP_SUMO_DISPLAYED_STATUS] & SF_VFOAB) + *vfo = p->current_vfo = RIG_VFO_B; + else + *vfo = p->current_vfo = RIG_VFO_A; + + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: vfo status = %x %x\n", p->update_data[0], p->update_data[1]); + + return RIG_OK; +} + + +/* + * private helper function. Retrieves update data from rig. + * using buffer indicated in *priv struct. + * Extended to be command agnostic as 1000mp has several ways to + * get data and several ways to return it. + * + * need to use this when doing ft1000mp_get_* stuff + * + * Variables: ci = command index, rl = read length of returned data + * + */ + +static int ft1000mp_get_update_data(RIG *rig, unsigned char ci, unsigned char rl) { + struct rig_state *rig_s; + struct ft1000mp_priv_data *p; + int n; /* for read_ */ + + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: ft1000mp_get_update_data called\n"); + + if (!rig) + return -RIG_EINVAL; + + p = (struct ft1000mp_priv_data*)rig->state.priv; + rig_s = &rig->state; + + /* send UPDATE comand to fetch data*/ + ft1000mp_send_priv_cmd(rig, ci); + + n = read_block(&rig_s->rigport, p->update_data, rl); + + return n; + +} + + +/* + * init_ft1000mp is called by rig_backend_load + * + */ + +int init_ft1000mp(void *be_handle) { + rig_debug(RIG_DEBUG_VERBOSE, "ft1000mp: _init called\n"); + rig_register(&ft1000mp_caps); + return RIG_OK; +} + + +/* + * private helper function to send a private command + * sequence . Must only be complete sequences. + * TODO: place variant of this in yaesu.c + * + */ + +static int ft1000mp_send_priv_cmd(RIG *rig, unsigned char ci) { + struct rig_state *rig_s; + struct ft1000mp_priv_data *p; + unsigned char *cmd; /* points to sequence to send */ + unsigned char cmd_index; /* index of sequence to send */ + + rig_debug(RIG_DEBUG_VERBOSE,"ft1000mp: ft1000mp_send_priv_cmd called\n"); + + if (!rig) + return -RIG_EINVAL; + + + p = (struct ft1000mp_priv_data*)rig->state.priv; + rig_s = &rig->state; + + cmd_index = ci; /* get command */ + + if (! p->pcs[cmd_index].ncomp) { + rig_debug(RIG_DEBUG_TRACE,"ft1000mp: Attempt to send incomplete sequence\n"); + return -RIG_EINVAL; + } + + cmd = (unsigned char *) p->pcs[cmd_index].nseq; /* get native sequence */ + write_block(&rig_s->rigport, cmd, YAESU_CMD_LENGTH); + + return RIG_OK; + +} diff --git a/yaesu/ft1000.h b/yaesu/ft1000.h new file mode 100644 index 000000000..e48f7d777 --- /dev/null +++ b/yaesu/ft1000.h @@ -0,0 +1,213 @@ +/* + * ft1000mp.h - (C) Stephane Fillod 2002 (fillods@users.sourceforge.net) + * + * This shared library provides an API for communicating + * via serial interface to an FT-1000MP using the "CAT" interface + * + * + * $Id: ft1000.h,v 1.1 2002-11-21 23:09:28 fillods Exp $ + * + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifndef _FT1000MP_H +#define _FT1000MP_H 1 + +#define FT1000MP_STATUS_FLAGS_LENGTH 6 /* 0xfa return size */ +#define FT1000MP_STATUS_UPDATE_LENGTH 16 /* 0x10 U = 02 return size */ + +#define FT1000MP_PACING_INTERVAL 5 +#define FT1000MP_PACING_DEFAULT_VALUE 0 +#define FT1000MP_WRITE_DELAY 50 + + +/* Delay sequential fast writes */ + +#define FT1000MP_POST_WRITE_DELAY 5 + + +/* Rough safe value for default timeout */ + +#define FT1000MP_DEFAULT_READ_TIMEOUT 28 * ( 3 + (FT1000MP_PACING_INTERVAL * FT1000MP_PACING_DEFAULT_VALUE)) + + +/* + * 8N2 and 1 start bit = 11 bits at 4800 bps => effective byte rate = 1 byte in 2.2917 msec + * => 28 bytes in 64 msec + * + * delay for 1 byte = 2.2917 + (pace_interval * 5) + * + * pace_interval time to read 345 bytes + * ------------ ---------------------- + * + * 0 64 msec + * 1 321 msec + * 2 642 msec + * 255 16.4 sec + * + */ + + + +/* + * Native FT1000MP functions. More to come :-) + * + */ + +enum ft1000mp_native_cmd_e { + FT1000MP_NATIVE_SPLIT_OFF = 0, + FT1000MP_NATIVE_SPLIT_ON, + FT1000MP_NATIVE_RECALL_MEM, + FT1000MP_NATIVE_VFO_TO_MEM, + FT1000MP_NATIVE_VFO_A, + FT1000MP_NATIVE_VFO_B, + FT1000MP_NATIVE_M_TO_VFO, + FT1000MP_NATIVE_FREQA_SET, + FT1000MP_NATIVE_FREQB_SET, + FT1000MP_NATIVE_MODE_SET_LSB, + FT1000MP_NATIVE_MODE_SET_USB, + FT1000MP_NATIVE_MODE_SET_CW, + FT1000MP_NATIVE_MODE_SET_CWR, + FT1000MP_NATIVE_MODE_SET_AM, + FT1000MP_NATIVE_MODE_SET_AMS, + FT1000MP_NATIVE_MODE_SET_FM, + FT1000MP_NATIVE_MODE_SET_FMW, + FT1000MP_NATIVE_MODE_SET_RTTY_LSB, + FT1000MP_NATIVE_MODE_SET_RTTY_USB, + FT1000MP_NATIVE_MODE_SET_DATA_LSB, + FT1000MP_NATIVE_MODE_SET_DATA_FM, + FT1000MP_NATIVE_PACING, + FT1000MP_NATIVE_VFO_UPDATE, + FT1000MP_NATIVE_CURR_VFO_UPDATE, + FT1000MP_NATIVE_UPDATE, + FT1000MP_NATIVE_SIZE /* end marker, value indicates number of */ + /* native cmd entries */ + +}; + +typedef enum ft1000mp_native_cmd_e ft1000mp_native_cmd_t; + + +/* + * Internal MODES - when setting modes via cmd_mode_set() + * + */ + +#define MODE_SET_LSB 0x00 +#define MODE_SET_USB 0x01 +#define MODE_SET_CW 0x02 +#define MODE_SET_CWR 0x03 +#define MODE_SET_AM 0x04 +#define MODE_SET_AMS 0x05 +#define MODE_SET_FM 0x06 +#define MODE_SET_FMW 0x07 /* what width is that? */ +#define MODE_SET_RTTYL 0x08 +#define MODE_SET_RTTYU 0x09 +#define MODE_SET_PKTL 0x0a +#define MODE_SET_PKTU 0x0b + + +/* + * Mode Bitmap. + * When READING modes + * + */ + +#define MODE_LSB 0x00 +#define MODE_CW_L 0x01 +#define MODE_AM 0x02 +#define MODE_FM 0x03 +#define MODE_DATA_L 0x04 +#define MODE_DATA_U 0x05 +#define MODE_DATA_F 0x06 +#define MODE_USB 0x40 +#define MODE_CW_U 0x41 +/* Narrow filter selected */ +#define MODE_LSBN 0x80 +#define MODE_CW_LN 0x81 +#define MODE_AMN 0x82 +#define MODE_FMN 0x83 +#define MODE_DATA_LN 0x84 +#define MODE_DATA_UN 0x85 +#define MODE_DATA_FN 0x86 +#define MODE_USBN 0xc0 +#define MODE_CW_UN 0xc1 + +/* relevent bits: 5,6,7 */ +#define MODE_MASK 0xe0 + + +/* + * Status Flag Masks when reading + * + */ + +#define SF_DLOCK 0x01 +#define SF_SPLITA 0x01 +#define SF_SPLITB 0x02 +#define SF_CLAR 0x04 +#define SF_VFOAB 0x10 /* Status byte 0, bit 4, VFO A == 0, VFO B == 1 */ +#define SF_VFOMR 0x10 +#define SF_RXTX 0x20 +#define SF_RESV 0x40 +#define SF_PRI 0x80 + + +/* + * Local VFO CMD's, according to spec + * + */ + +#define FT1000MP_VFO_A 0x00 +#define FT1000MP_VFO_B 0x01 + + +/* + * Some useful offsets in the status update map (offset) + * + */ + +#define FT1000MP_SUMO_DISPLAYED_STATUS 0x00 +#define FT1000MP_SUMO_DISPLAYED_FREQ 0x01 +#define FT1000MP_SUMO_VFO_A_FREQ 0x01 +#define FT1000MP_SUMO_VFO_B_FREQ 0x11 +#define FT1000MP_SUMO_VFO_A_MODE 0x07 +#define FT1000MP_SUMO_VFO_B_MODE 0x17 + + + +/* + * API local implementation + * + */ + +int ft1000mp_init(RIG *rig); +int ft1000mp_cleanup(RIG *rig); +int ft1000mp_open(RIG *rig); +int ft1000mp_close(RIG *rig); + +int ft1000mp_set_freq(RIG *rig, vfo_t vfo, freq_t freq); +int ft1000mp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); + +int ft1000mp_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); /* select mode */ +int ft1000mp_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); /* get mode */ + +int ft1000mp_set_vfo(RIG *rig, vfo_t vfo); /* select vfo */ +int ft1000mp_get_vfo(RIG *rig, vfo_t *vfo); /* get vfo */ + + +#endif /* _FT1000MP_H */ diff --git a/yaesu/yaesu.c b/yaesu/yaesu.c index af3f733a5..a323cb4af 100644 --- a/yaesu/yaesu.c +++ b/yaesu/yaesu.c @@ -7,7 +7,7 @@ * via serial interface to a Yaesu rig * * - * $Id: yaesu.c,v 1.8 2002-10-28 04:53:05 n0nb Exp $ + * $Id: yaesu.c,v 1.9 2002-11-21 23:09:28 fillods Exp $ * * * This program is free software; you can redistribute it and/or @@ -56,6 +56,7 @@ int initrigs_yaesu(void *be_handle) rig_register(&ft847_caps); rig_register(&ft100_caps); rig_register(&ft920_caps); + rig_register(&ft1000mp_caps); return RIG_OK; } diff --git a/yaesu/yaesu.h b/yaesu/yaesu.h index b524af725..6108123ed 100644 --- a/yaesu/yaesu.h +++ b/yaesu/yaesu.h @@ -6,7 +6,7 @@ * * Common yaesu declarations for hamlib * - * $Id: yaesu.h,v 1.11 2002-10-28 04:53:05 n0nb Exp $ + * $Id: yaesu.h,v 1.12 2002-11-21 23:09:28 fillods Exp $ * * * @@ -52,6 +52,7 @@ extern const struct rig_caps ft817_caps; extern const struct rig_caps ft847_caps; extern const struct rig_caps ft100_caps; extern const struct rig_caps ft920_caps; +extern const struct rig_caps ft1000mp_caps; extern BACKEND_EXPORT(int) initrigs_yaesu(void *be_handle);