| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2010-03-05 19:18:10 +00:00
										 |  |  |  * yaesu.c - (C) Stephane Fillod 2001-2010 | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This shared library provides an API for communicating | 
					
						
							|  |  |  |  * via serial interface to a Yaesu rig | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-08-23 02:26:44 +00:00
										 |  |  |  *   This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *   modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  *   License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  *   version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2002-12-01 03:08:05 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-08-23 02:26:44 +00:00
										 |  |  |  *   This library 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 | 
					
						
							|  |  |  |  *   Lesser General Public License for more details. | 
					
						
							| 
									
										
										
										
											2002-12-01 03:08:05 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-08-23 02:26:44 +00:00
										 |  |  |  *   You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  *   License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
					
						
							| 
									
										
										
										
											2002-12-01 03:08:05 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-07 22:42:11 +00:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>  /* String function definitions */
 | 
					
						
							|  |  |  | #include <unistd.h>  /* UNIX standard function definitions */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-07 22:42:11 +00:00
										 |  |  | #include "hamlib/rig.h"
 | 
					
						
							| 
									
										
										
										
											2001-12-16 11:14:47 +00:00
										 |  |  | #include "serial.h"
 | 
					
						
							|  |  |  | #include "misc.h"
 | 
					
						
							| 
									
										
										
										
											2003-04-16 22:30:43 +00:00
										 |  |  | #include "register.h"
 | 
					
						
							| 
									
										
										
										
											2001-06-15 07:08:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | #include "yaesu.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | struct yaesu_id { | 
					
						
							|  |  |  | 	rig_model_t model; | 
					
						
							|  |  |  | 	int id1, id2; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define UNKNOWN_ID -1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Identification number as returned by 0xFA opcode. | 
					
						
							|  |  |  |  * Note: On the FT736R, the 0xFA opcode sets CTCSS tone code | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Please, if the model number of your rig is listed as UNKNOWN_ID, | 
					
						
							|  |  |  |  * send the value to <fillods@users.sourceforge.net> for inclusion. Thanks --SF | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static const struct yaesu_id yaesu_id_list[] = { | 
					
						
							| 
									
										
										
										
											2017-01-01 11:13:31 +00:00
										 |  |  | 	{ RIG_MODEL_FT1000D, 0x10, 0x21 }, /* or 0x10, 0x00 ? */ | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 	{ RIG_MODEL_FT990, 0x09, 0x90 }, | 
					
						
							|  |  |  | 	{ RIG_MODEL_FT890, 0x08, 0x41 }, | 
					
						
							|  |  |  | 	{ RIG_MODEL_FRG100, 0x03, 0x92 }, /* TBC, inconsistency in manual */ | 
					
						
							|  |  |  | 	{ RIG_MODEL_FT1000MP, 0x03, 0x93 }, | 
					
						
							|  |  |  | 	{ RIG_MODEL_FT1000MPMKV, 0x03, 0x93 }, /* or 0x10, 0x00 ? */ | 
					
						
							|  |  |  | 	{ RIG_MODEL_FT1000MPMKVFLD, 0x03, 0x93 }, | 
					
						
							| 
									
										
										
										
											2011-02-16 23:49:58 +00:00
										 |  |  | 	{ RIG_MODEL_VX1700, 0x06, 0x04 }, | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 	{ RIG_MODEL_NONE, UNKNOWN_ID, UNKNOWN_ID },	/* end marker */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2001-12-28 20:28:04 +00:00
										 |  |  |  * initrigs_yaesu is called by rig_backend_load | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-16 22:30:43 +00:00
										 |  |  | DECLARE_INITRIG_BACKEND(yaesu) | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-03-09 04:43:38 +00:00
										 |  |  |   rig_debug(RIG_DEBUG_VERBOSE, "yaesu: %s called\n", __func__); | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-09 04:43:38 +00:00
										 |  |  |   rig_register(&ft100_caps); | 
					
						
							| 
									
										
										
										
											2007-11-23 03:31:26 +00:00
										 |  |  |   rig_register(&ft450_caps); | 
					
						
							| 
									
										
										
										
											2004-08-10 21:10:36 +00:00
										 |  |  |   rig_register(&ft736_caps); | 
					
						
							| 
									
										
										
										
											2003-03-09 04:43:38 +00:00
										 |  |  |   rig_register(&ft747_caps); | 
					
						
							| 
									
										
										
										
											2004-04-24 13:01:00 +00:00
										 |  |  |   rig_register(&ft757gx_caps); | 
					
						
							| 
									
										
										
										
											2004-08-08 19:15:31 +00:00
										 |  |  |   rig_register(&ft757gx2_caps); | 
					
						
							| 
									
										
										
										
											2019-03-04 22:47:51 +00:00
										 |  |  |   rig_register(&ft600_caps); | 
					
						
							| 
									
										
										
										
											2007-10-05 04:19:18 +00:00
										 |  |  |   rig_register(&ft767gx_caps); | 
					
						
							| 
									
										
										
										
											2001-12-15 03:23:14 +00:00
										 |  |  |   rig_register(&ft817_caps); | 
					
						
							| 
									
										
										
										
											2003-03-09 04:43:38 +00:00
										 |  |  |   rig_register(&ft847_caps); | 
					
						
							| 
									
										
										
										
											2003-08-11 21:20:35 +00:00
										 |  |  |   rig_register(&ft857_caps); | 
					
						
							| 
									
										
										
										
											2004-02-08 17:08:46 +00:00
										 |  |  |   rig_register(&ft897_caps); | 
					
						
							| 
									
										
										
										
											2009-01-04 10:40:34 +00:00
										 |  |  |   rig_register(&ft840_caps); | 
					
						
							| 
									
										
										
										
											2003-03-09 04:43:38 +00:00
										 |  |  |   rig_register(&ft890_caps); | 
					
						
							| 
									
										
										
										
											2003-04-14 03:05:32 +00:00
										 |  |  |   rig_register(&ft900_caps); | 
					
						
							| 
									
										
										
										
											2002-10-28 04:53:05 +00:00
										 |  |  |   rig_register(&ft920_caps); | 
					
						
							| 
									
										
										
										
											2008-09-22 21:32:38 +00:00
										 |  |  |   rig_register(&ft950_caps); | 
					
						
							| 
									
										
										
										
											2010-05-17 22:23:38 +00:00
										 |  |  |   rig_register(&ft980_caps); | 
					
						
							| 
									
										
										
										
											2003-10-12 18:04:02 +00:00
										 |  |  |   rig_register(&ft990_caps); | 
					
						
							| 
									
										
										
										
											2004-08-17 20:07:20 +00:00
										 |  |  |   rig_register(&ft1000d_caps); | 
					
						
							| 
									
										
										
										
											2002-11-21 23:09:28 +00:00
										 |  |  |   rig_register(&ft1000mp_caps); | 
					
						
							| 
									
										
										
										
											2005-02-26 23:13:48 +00:00
										 |  |  |   rig_register(&ft1000mpmkv_caps); | 
					
						
							|  |  |  |   rig_register(&ft1000mpmkvfld_caps); | 
					
						
							| 
									
										
										
										
											2008-12-14 20:02:03 +00:00
										 |  |  |   rig_register(&ft2000_caps); | 
					
						
							| 
									
										
										
										
											2018-10-28 20:57:28 +00:00
										 |  |  |   rig_register(&ftdx3000_caps); | 
					
						
							| 
									
										
										
										
											2010-10-06 07:25:14 +00:00
										 |  |  |   rig_register(&ftdx5000_caps); | 
					
						
							| 
									
										
										
										
											2008-12-14 20:02:03 +00:00
										 |  |  |   rig_register(&ft9000_caps); | 
					
						
							| 
									
										
										
										
											2004-08-10 21:10:36 +00:00
										 |  |  |   rig_register(&frg100_caps); | 
					
						
							| 
									
										
										
										
											2004-05-16 07:32:57 +00:00
										 |  |  |   rig_register(&frg8800_caps); | 
					
						
							| 
									
										
										
										
											2004-08-10 21:10:36 +00:00
										 |  |  |   rig_register(&frg9600_caps); | 
					
						
							| 
									
										
										
										
											2005-02-26 23:13:48 +00:00
										 |  |  |   rig_register(&vr5000_caps); | 
					
						
							| 
									
										
										
										
											2011-02-16 23:49:58 +00:00
										 |  |  |   rig_register(&vx1700_caps); | 
					
						
							| 
									
										
										
										
											2015-04-04 16:55:20 +00:00
										 |  |  |   rig_register(&ft1200_caps); | 
					
						
							| 
									
										
										
										
											2015-04-13 03:56:36 +00:00
										 |  |  |   rig_register(&ft991_caps); | 
					
						
							| 
									
										
										
										
											2017-01-06 17:20:38 +00:00
										 |  |  |   rig_register(&ft891_caps); | 
					
						
							| 
									
										
										
										
											2019-01-28 21:53:28 +00:00
										 |  |  |   rig_register(&ft847uni_caps); | 
					
						
							| 
									
										
										
										
											2001-06-04 21:07:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return RIG_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * proberigs_yaesu | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Notes: | 
					
						
							|  |  |  |  * There's only one rig possible per port. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * rig_model_t probeallrigs_yaesu(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data) | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | DECLARE_PROBERIG_BACKEND(yaesu) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-01 16:38:46 +00:00
										 |  |  | 	unsigned char idbuf[YAESU_CMD_LENGTH+1]; | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 	static const unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, 0x00, 0xfa}; | 
					
						
							|  |  |  | 	int id_len=-1, i, id1, id2; | 
					
						
							|  |  |  | 	int retval=-1; | 
					
						
							|  |  |  | 	int rates[] = { 4800, 57600, 9600, 38400, 0 };	/* possible baud rates */ | 
					
						
							|  |  |  | 	int rates_idx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!port) | 
					
						
							|  |  |  | 		return RIG_MODEL_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (port->type.rig != RIG_PORT_SERIAL) | 
					
						
							|  |  |  | 		return RIG_MODEL_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	port->write_delay = port->post_write_delay = 20; | 
					
						
							|  |  |  | 	port->parm.serial.stop_bits = 2; | 
					
						
							|  |  |  | 	port->retry = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * try for all different baud rates | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	for (rates_idx = 0; rates[rates_idx]; rates_idx++) { | 
					
						
							|  |  |  | 		port->parm.serial.rate = rates[rates_idx]; | 
					
						
							|  |  |  | 		port->timeout = 2*1000/rates[rates_idx] + 50; | 
					
						
							| 
									
										
										
										
											2011-08-23 02:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 		retval = serial_open(port); | 
					
						
							|  |  |  | 		if (retval != RIG_OK) | 
					
						
							|  |  |  | 			return RIG_MODEL_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* send READ STATUS cmd to rig  */ | 
					
						
							| 
									
										
										
										
											2006-10-07 15:51:38 +00:00
										 |  |  | 		retval = write_block(port, (char *) cmd, YAESU_CMD_LENGTH); | 
					
						
							|  |  |  | 		id_len = read_block(port, (char *) idbuf, YAESU_CMD_LENGTH); | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		close(port->fd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (retval != RIG_OK || id_len < 0) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (retval != RIG_OK || id_len < 0) | 
					
						
							|  |  |  | 		return RIG_MODEL_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-23 02:26:44 +00:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 	 * reply should be [Flag1,Flag2,Flag3,ID1,ID2] | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2016-04-14 16:47:46 +00:00
										 |  |  | 	if (id_len != 5 && id_len != 6) { | 
					
						
							| 
									
										
										
										
											2008-11-01 16:38:46 +00:00
										 |  |  | 		idbuf[YAESU_CMD_LENGTH] = '\0'; | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 		rig_debug(RIG_DEBUG_WARN,"probe_yaesu: protocol error," | 
					
						
							|  |  |  | 			" expected %d, received %d: %s\n", 6, id_len, idbuf); | 
					
						
							|  |  |  | 		return RIG_MODEL_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	id1 = idbuf[3]; | 
					
						
							| 
									
										
										
										
											2010-03-05 19:18:10 +00:00
										 |  |  | 	id2 = idbuf[4]; | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i=0; yaesu_id_list[i].model != RIG_MODEL_NONE; i++) { | 
					
						
							|  |  |  | 		if (id1 == yaesu_id_list[i].id1 && id2 == yaesu_id_list[i].id2) { | 
					
						
							|  |  |  | 			rig_debug(RIG_DEBUG_VERBOSE,"probe_yaesu: " | 
					
						
							|  |  |  | 					"found ID %02xH %02xH\n", id1, id2); | 
					
						
							|  |  |  | 			if (cfunc) | 
					
						
							|  |  |  | 				(*cfunc)(port, yaesu_id_list[i].model, data); | 
					
						
							|  |  |  | 			return yaesu_id_list[i].model; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2011-08-23 02:26:44 +00:00
										 |  |  | 	 * not found in known table.... | 
					
						
							| 
									
										
										
										
											2005-02-26 23:44:41 +00:00
										 |  |  | 	 * update yaesu_id_list[]! | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	rig_debug(RIG_DEBUG_WARN,"probe_yaesu: found unknown device " | 
					
						
							|  |  |  | 				"with ID %02xH %02xH, please report to Hamlib " | 
					
						
							|  |  |  | 				"developers.\n", id1, id2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return RIG_MODEL_NONE; | 
					
						
							|  |  |  | } |