From: Derry H. <ras...@gm...> - 2007-10-06 07:07:39
|
This patch adds get_vfo and set_vfo support using information from http://www.ka7oei.com/ft817_meow.html. It also adds helper functions ft817_read_eeprom, ft817_write_eeprom, and ft817_send_icmd_nack. It has been tested against my FT-17 and appears fully operational. Derry Hamilton, GM4FH Index: yaesu/ft817.c =================================================================== RCS file: /cvsroot/hamlib/hamlib/yaesu/ft817.c,v retrieving revision 1.14 diff -u -r1.14 ft817.c --- yaesu/ft817.c 7 Oct 2006 15:51:38 -0000 1.14 +++ yaesu/ft817.c 6 Oct 2007 06:59:32 -0000 @@ -116,6 +116,8 @@ { 1, { 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* pwr wakeup sequence */ { 1, { 0x00, 0x00, 0x00, 0x00, 0x0f } }, /* pwr on */ { 1, { 0x00, 0x00, 0x00, 0x00, 0x8f } }, /* pwr off */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0xbb } }, /* Read Memory location */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0xbc } }, /* Read Memory location */ }; static const tone_t static_ft817_dcs_list[] = { @@ -261,8 +263,8 @@ .get_freq = ft817_get_freq, .set_mode = ft817_set_mode, .get_mode = ft817_get_mode, - .set_vfo = NULL, - .get_vfo = NULL, + .set_vfo = ft817_set_vfo, + .get_vfo = ft817_get_vfo, .set_ptt = ft817_set_ptt, .get_ptt = ft817_get_ptt, .get_dcd = ft817_get_dcd, @@ -712,6 +714,61 @@ return ft817_read_ack(rig); } +/* + * The same for incomplete commands that return data, rather than an ack. + */ +static int ft817_send_icmd_nack(RIG *rig, int index, unsigned char *data) +{ + struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; + unsigned char cmd[YAESU_CMD_LENGTH]; + + if (p->pcs[index].ncomp == 1) { + rig_debug(RIG_DEBUG_VERBOSE, "ft817: Complete sequence\n"); + return -RIG_EINTERNAL; + } + + cmd[YAESU_CMD_LENGTH - 1] = p->pcs[index].nseq[YAESU_CMD_LENGTH - 1]; + memcpy(cmd, data, YAESU_CMD_LENGTH - 1); + + write_block(&rig->state.rigport, (char *) cmd, YAESU_CMD_LENGTH); + return RIG_OK; +} + +static int ft817_read_eeprom(RIG *rig, char msb,char lsb,unsigned char* eeprom_data){ + unsigned char cmd_data[YAESU_CMD_LENGTH - 1] = {0x00,0x00,0x00,0x00}; + int n; + int ret; + + cmd_data[0] = msb; + cmd_data[1] = lsb; + + ret = ft817_send_icmd_nack(rig, FT817_NATIVE_CAT_READ_MEM, cmd_data); + if(ret != RIG_OK) + return ret; + + n = read_block(&rig->state.rigport, (char*) eeprom_data, 2); + if (n != 2){ + char* errfmt = "We didn't get 2 bytes, we got %d\n"; + rig_debug(RIG_DEBUG_VERBOSE, errfmt,n); + return -RIG_EIO; + } + return RIG_OK; +} + +static int ft817_write_eeprom (RIG *rig, char msb,char lsb,char* eeprom_data){ + unsigned char cmd_data[YAESU_CMD_LENGTH - 1] = {0x00,0x00,0x00,0x00}; + int n; + int ret; + + cmd_data[0] = msb; + cmd_data[1] = lsb; + + cmd_data[2] = eeprom_data[0]; + cmd_data[3] = eeprom_data[1]; + return ft817_send_icmd(rig, FT817_NATIVE_CAT_WRITE_MEM, cmd_data); +} + + /* ---------------------------------------------------------------------- */ int ft817_set_freq(RIG *rig, vfo_t vfo, freq_t freq) @@ -1075,6 +1132,59 @@ } +static int ft817_set_vfo (RIG *rig, vfo_t vfo){ + unsigned char cmd_data[YAESU_CMD_LENGTH - 1] = {0x00,0x55,0x00,0x00}; + unsigned char vfo_data[2]; + int n; + int ret; + + ft817_read_eeprom(rig,0x00,0x55,vfo_data); + + switch(vfo){ + case RIG_VFO_A: + vfo_data[0] &= 0xFE; + break; + case RIG_VFO_B: + vfo_data[0] |= 0x01; + break; + default: + //NOTREACHED + rig_debug (RIG_DEBUG_BUG,"ft817: ft817_set_vfo switch NOTREACHED reached!\n"); + return -RIG_EINVAL; + } + /*cmd_data[2] = vfo_data[0]; + cmd_data[3] = vfo_data[1]; + return ft817_send_icmd(rig, FT817_NATIVE_CAT_WRITE_MEM, cmd_data);*/ + return ft817_write_eeprom(rig,0x00,0x55,vfo_data); +} + +static int ft817_get_vfo (RIG *rig, vfo_t *vfo){ + //unsigned char cmd_data[YAESU_CMD_LENGTH - 1] = {0x00,0x55,0x00,0x00}; + unsigned char vfo_data[2]; + int n; + + ft817_read_eeprom(rig,0x00,0x55,vfo_data); + + vfo_data[0] &= 0x01; //VFO state is in bit 0 + switch(vfo_data[0]){ + case 0x00: + *vfo = RIG_VFO_A; + return RIG_OK; + case 0x01: + *vfo = RIG_VFO_B; + return RIG_OK; + default: + rig_debug (RIG_DEBUG_BUG,"ft817: ft817_get_vfo switch invalid VFO reached!\n"); + return -RIG_EINVAL; + } + + //NOTREACHED + rig_debug (RIG_DEBUG_BUG,"ft817: ft817_get_vfo end NOTREACHED reached!\n"); + return RIG_ENIMPL; +} + + /* ---------------------------------------------------------------------- */ Index: yaesu/ft817.h =================================================================== RCS file: /cvsroot/hamlib/hamlib/yaesu/ft817.h,v retrieving revision 1.5 diff -u -r1.5 ft817.h --- yaesu/ft817.h 4 Sep 2005 10:44:23 -0000 1.5 +++ yaesu/ft817.h 6 Oct 2007 06:59:32 -0000 @@ -109,6 +109,8 @@ FT817_NATIVE_CAT_PWR_WAKE, FT817_NATIVE_CAT_PWR_ON, FT817_NATIVE_CAT_PWR_OFF, + FT817_NATIVE_CAT_READ_MEM, + FT817_NATIVE_CAT_WRITE_MEM, FT817_NATIVE_SIZE /* end marker */ }; @@ -156,6 +158,9 @@ static 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_set_split_vfo (RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo); +static int ft817_set_vfo (RIG *rig, vfo_t vfo); /* select vfo */ +static int ft817_get_vfo (RIG *rig, vfo_t *vfo); /* get vfo */ + #endif /* _FT817_H */ |