2000-12-23 08:40:14 +00:00
|
|
|
/*
|
2001-07-13 19:08:15 +00:00
|
|
|
* Hamlib Kenwood backend - main file
|
2005-01-25 00:22:14 +00:00
|
|
|
* Copyright (c) 2000-2005 by Stephane Fillod and others
|
2000-12-23 08:40:14 +00:00
|
|
|
*
|
2008-09-01 19:01:13 +00:00
|
|
|
* $Id: kenwood.c,v 1.98 2008-09-01 19:01:12 fillods Exp $
|
2000-12-23 08:40:14 +00:00
|
|
|
*
|
2001-07-13 19:08:15 +00:00
|
|
|
* 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.
|
2000-12-23 08:40:14 +00:00
|
|
|
*
|
2001-07-13 19:08:15 +00:00
|
|
|
* 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.
|
2000-12-23 08:40:14 +00:00
|
|
|
*
|
2001-07-13 19:08:15 +00:00
|
|
|
* 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.
|
2000-12-23 08:40:14 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-07-13 19:08:15 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-12-23 08:40:14 +00:00
|
|
|
#include <stdlib.h>
|
2003-10-01 19:32:04 +00:00
|
|
|
#include <stdio.h>
|
2000-12-23 08:40:14 +00:00
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
|
|
#include <math.h>
|
|
|
|
|
2003-04-07 22:42:11 +00:00
|
|
|
#include "hamlib/rig.h"
|
|
|
|
#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
|
|
|
|
2000-12-23 08:40:14 +00:00
|
|
|
#include "kenwood.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* modes in use by the "MD" command
|
|
|
|
*/
|
2001-05-15 22:05:26 +00:00
|
|
|
#define MD_NONE '0'
|
2000-12-23 08:40:14 +00:00
|
|
|
#define MD_LSB '1'
|
|
|
|
#define MD_USB '2'
|
|
|
|
#define MD_CW '3'
|
|
|
|
#define MD_FM '4'
|
2001-03-02 18:43:25 +00:00
|
|
|
#define MD_AM '5'
|
|
|
|
#define MD_FSK '6'
|
2001-05-15 22:05:26 +00:00
|
|
|
#define MD_CWR '7'
|
|
|
|
#define MD_FSKR '9'
|
|
|
|
|
|
|
|
struct kenwood_id {
|
|
|
|
rig_model_t model;
|
|
|
|
int id;
|
|
|
|
};
|
|
|
|
|
2001-10-18 20:43:13 +00:00
|
|
|
struct kenwood_id_string {
|
|
|
|
rig_model_t model;
|
|
|
|
const char *id;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
#define UNKNOWN_ID -1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Identification number as returned by "ID;"
|
|
|
|
* Please, if the model number of your rig is listed as UNKNOWN_ID,
|
2001-12-11 21:58:37 +00:00
|
|
|
* send the value to <fillods@users.sourceforge.net> for inclusion. Thanks --SF
|
2001-05-15 22:05:26 +00:00
|
|
|
*
|
|
|
|
* TODO: sort this list with most frequent rigs first.
|
|
|
|
*/
|
|
|
|
static const struct kenwood_id kenwood_id_list[] = {
|
2002-07-05 23:22:11 +00:00
|
|
|
{ RIG_MODEL_TS940, 1 },
|
|
|
|
{ RIG_MODEL_TS811, 2 },
|
|
|
|
{ RIG_MODEL_TS711, 3 },
|
|
|
|
{ RIG_MODEL_TS440, 4 },
|
2001-06-04 21:18:39 +00:00
|
|
|
{ RIG_MODEL_R5000, 5 },
|
2003-01-29 22:25:16 +00:00
|
|
|
{ RIG_MODEL_TS790, 7 },
|
2003-06-28 22:39:24 +00:00
|
|
|
{ RIG_MODEL_TS950SDX, 8 }, /* reported as RIG_MODEL_TS950SD originally */
|
2003-08-15 19:17:20 +00:00
|
|
|
{ RIG_MODEL_TS850, 9 },
|
2002-12-16 18:44:02 +00:00
|
|
|
{ RIG_MODEL_TS450S, 10 },
|
|
|
|
{ RIG_MODEL_TS690S, 11 },
|
2001-06-04 21:18:39 +00:00
|
|
|
{ RIG_MODEL_TS870S, 15 },
|
2002-11-13 20:35:18 +00:00
|
|
|
{ RIG_MODEL_TS570D, 17 }, /* Elecraft K2 also returns 17 */
|
2001-06-30 23:19:42 +00:00
|
|
|
{ RIG_MODEL_TS570S, 18 },
|
2001-06-04 21:18:39 +00:00
|
|
|
{ RIG_MODEL_TS2000, 19 },
|
2004-11-27 13:19:56 +00:00
|
|
|
{ RIG_MODEL_TS480, 20 },
|
2001-06-30 23:19:42 +00:00
|
|
|
{ RIG_MODEL_NONE, UNKNOWN_ID }, /* end marker */
|
2001-05-15 22:05:26 +00:00
|
|
|
};
|
|
|
|
|
2001-10-18 20:43:13 +00:00
|
|
|
static const struct kenwood_id_string kenwood_id_string_list[] = {
|
|
|
|
{ RIG_MODEL_THD7A, "TH-D7" },
|
|
|
|
{ RIG_MODEL_THD7AG, "TH-D7G" },
|
2004-02-08 17:05:55 +00:00
|
|
|
{ RIG_MODEL_TMD700, "TM-D700" },
|
2004-03-20 10:23:43 +00:00
|
|
|
{ RIG_MODEL_TMV7, "TM-V7" },
|
2001-11-09 15:44:38 +00:00
|
|
|
{ RIG_MODEL_THF6A, "TH-F6" },
|
|
|
|
{ RIG_MODEL_THF7E, "TH-F7" },
|
2003-09-28 16:14:00 +00:00
|
|
|
{ RIG_MODEL_THG71, "TH-G71" },
|
2001-10-18 20:43:13 +00:00
|
|
|
{ RIG_MODEL_NONE, NULL }, /* end marker */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
|
|
|
* 38 CTCSS sub-audible tones
|
|
|
|
*/
|
2006-03-09 19:45:10 +00:00
|
|
|
const tone_t kenwood38_ctcss_list[] = {
|
2001-05-15 22:05:26 +00:00
|
|
|
670, 719, 744, 770, 797, 825, 854, 885, 915, 948,
|
|
|
|
974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 1318,
|
|
|
|
1365, 1413, 1462, 1514, 1567, 1622, 1679, 1738, 1799, 1862,
|
|
|
|
1928, 2035, 2107, 2181, 2257, 2336, 2418, 2503, 17500,
|
|
|
|
0,
|
|
|
|
};
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2002-03-13 23:42:43 +00:00
|
|
|
#define cmd_trm(rig) ((struct kenwood_priv_caps *)(rig)->caps->priv)->cmdtrm
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2002-03-13 23:42:43 +00:00
|
|
|
/**
|
2001-06-30 23:19:42 +00:00
|
|
|
* kenwood_transaction
|
2002-03-13 23:42:43 +00:00
|
|
|
* Assumes rig!=NULL rig->state!=NULL rig->caps!=NULL
|
2001-06-30 23:19:42 +00:00
|
|
|
*
|
2002-03-13 23:42:43 +00:00
|
|
|
* cmdstr - Command to be sent to the rig. Cmdstr can also be NULL, indicating
|
|
|
|
* that only a reply is needed (nothing will be send).
|
|
|
|
* data - Buffer for reply string. Can be NULL, indicating that no reply is
|
|
|
|
* is needed and will return with RIG_OK after command was sent.
|
|
|
|
* datasize - in: Size of buffer. It is the caller's responsibily to provide
|
|
|
|
* a large enough buffer for all possible replies for a command.
|
|
|
|
* out: location where to store number of bytes read.
|
2001-12-11 21:58:37 +00:00
|
|
|
*
|
2002-03-13 23:42:43 +00:00
|
|
|
* returns:
|
|
|
|
* RIG_OK - if no error occured.
|
|
|
|
* RIG_EIO - if an I/O error occured while sending/receiving data.
|
|
|
|
* RIG_ETIMEOUT - if timeout expires without any characters received.
|
|
|
|
* RIG_REJECTED - if a negative acknowledge was received or command not
|
|
|
|
* recognized by rig.
|
2001-06-30 23:19:42 +00:00
|
|
|
*/
|
2002-03-13 23:42:43 +00:00
|
|
|
int
|
|
|
|
kenwood_transaction (RIG *rig, const char *cmdstr, int cmd_len,
|
|
|
|
char *data, size_t *datasize)
|
2001-06-30 23:19:42 +00:00
|
|
|
{
|
2002-03-13 23:42:43 +00:00
|
|
|
struct rig_state *rs;
|
|
|
|
int retval;
|
|
|
|
const char *cmdtrm = EOM_KEN; /* Default Command/Reply termination char */
|
|
|
|
int retry_read = 0;
|
|
|
|
|
|
|
|
rs = &rig->state;
|
|
|
|
rs->hold_decode = 1;
|
|
|
|
|
|
|
|
cmdtrm = cmd_trm(rig);
|
|
|
|
|
2004-03-29 20:54:26 +00:00
|
|
|
transaction_write:
|
|
|
|
|
|
|
|
serial_flush(&rs->rigport);
|
|
|
|
|
2002-03-13 23:42:43 +00:00
|
|
|
if (cmdstr) {
|
|
|
|
retval = write_block(&rs->rigport, cmdstr, strlen(cmdstr));
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
goto transaction_quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data == NULL || *datasize <= 0) {
|
|
|
|
rig->state.hold_decode = 0;
|
|
|
|
return RIG_OK; /* don't want a reply */
|
|
|
|
}
|
|
|
|
|
2007-09-04 15:01:23 +00:00
|
|
|
memset(data,0,*datasize);
|
2002-03-13 23:42:43 +00:00
|
|
|
retval = read_string(&rs->rigport, data, *datasize, cmdtrm, strlen(cmdtrm));
|
2004-03-29 20:54:26 +00:00
|
|
|
if (retval < 0) {
|
|
|
|
if (retry_read++ < rig->state.rigport.retry)
|
|
|
|
goto transaction_write;
|
|
|
|
goto transaction_quit;
|
|
|
|
} else
|
|
|
|
*datasize = retval;
|
2002-03-13 23:42:43 +00:00
|
|
|
|
|
|
|
/* Check that command termination is correct */
|
2004-03-29 20:54:26 +00:00
|
|
|
if (strchr(cmdtrm, data[strlen(data)-1])==NULL) {
|
2002-07-08 22:53:27 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n", __FUNCTION__, data);
|
2004-03-29 20:54:26 +00:00
|
|
|
if (retry_read++ < rig->state.rigport.retry)
|
|
|
|
goto transaction_write;
|
2002-03-13 23:42:43 +00:00
|
|
|
retval = -RIG_EPROTO;
|
|
|
|
goto transaction_quit;
|
|
|
|
}
|
|
|
|
|
2008-05-04 21:19:07 +00:00
|
|
|
if (strlen(data) == 2) {
|
|
|
|
switch (data[0]) {
|
|
|
|
case 'N':
|
|
|
|
/* Command recognised by rig but invalid data entered. */
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: NegAck for '%s'\n", __FUNCTION__, cmdstr);
|
|
|
|
retval = -RIG_ENAVAIL;
|
|
|
|
goto transaction_quit;
|
|
|
|
case 'O':
|
|
|
|
/* Too many characters send without a carriage return */
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Overflow for '%s'\n", __FUNCTION__, cmdstr);
|
|
|
|
retval = -RIG_EPROTO;
|
|
|
|
goto transaction_quit;
|
|
|
|
case '?':
|
|
|
|
/* Command not understood by rig */
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unknown command '%s'\n", __FUNCTION__, cmdstr);
|
|
|
|
retval = -RIG_ERJCTED;
|
|
|
|
goto transaction_quit;
|
|
|
|
}
|
2002-03-13 23:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CONFIG_STRIP_CMDTRM 1
|
|
|
|
#ifdef CONFIG_STRIP_CMDTRM
|
|
|
|
if (strlen(data) > 0)
|
|
|
|
data[strlen(data)-1] = '\0'; /* not very elegant, but should work. */
|
|
|
|
else
|
|
|
|
data[0] = '\0';
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Check that received the correct reply. The first two characters
|
|
|
|
* should be the same as command.
|
|
|
|
*/
|
|
|
|
if (cmdstr && (data[0] != cmdstr[0] || data[1] != cmdstr[1])) {
|
|
|
|
/*
|
|
|
|
* TODO: When RIG_TRN is enabled, we can pass the string
|
|
|
|
* to the decoder for callback. That way we don't ignore
|
|
|
|
* any commands.
|
|
|
|
*/
|
2002-07-08 22:53:27 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __FUNCTION__, data);
|
2004-03-29 20:54:26 +00:00
|
|
|
if (retry_read++ < rig->state.rigport.retry)
|
|
|
|
goto transaction_write;
|
|
|
|
|
2002-03-13 23:42:43 +00:00
|
|
|
retval = -RIG_EPROTO;
|
|
|
|
goto transaction_quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = RIG_OK;
|
|
|
|
transaction_quit:
|
|
|
|
rs->hold_decode = 0;
|
|
|
|
return retval;
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-04 21:19:07 +00:00
|
|
|
rmode_t kenwood2rmode(unsigned char mode, const rmode_t mode_table[])
|
|
|
|
{
|
|
|
|
if (mode >= KENWOOD_MODE_TABLE_MAX)
|
|
|
|
return RIG_MODE_NONE;
|
|
|
|
return mode_table[mode];
|
|
|
|
}
|
|
|
|
|
|
|
|
char rmode2kenwood(rmode_t mode, const rmode_t mode_table[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0; i<KENWOOD_MODE_TABLE_MAX;i++) {
|
|
|
|
if (mode_table[i] == mode)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-03-13 23:42:43 +00:00
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
|
|
|
* kenwood_set_vfo
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_set_vfo(RIG *rig, vfo_t vfo)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char cmdbuf[16], ackbuf[50];
|
|
|
|
int cmd_len, retval;
|
|
|
|
size_t ack_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
char vfo_function;
|
|
|
|
|
|
|
|
switch (vfo) {
|
|
|
|
case RIG_VFO_VFO:
|
|
|
|
case RIG_VFO_A: vfo_function = '0'; break;
|
|
|
|
case RIG_VFO_B: vfo_function = '1'; break;
|
|
|
|
case RIG_VFO_MEM: vfo_function = '2'; break;
|
|
|
|
case RIG_VFO_CURR: return RIG_OK;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_set_vfo: unsupported VFO %d\n",
|
|
|
|
vfo);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2002-03-13 23:42:43 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
cmd_len = sprintf(cmdbuf, "FR%c%s", vfo_function, cmd_trm(rig));
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/* set RX VFO */
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, cmdbuf, cmd_len, ackbuf, &ack_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/* set TX VFO */
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
cmdbuf[1] = 'T';
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, cmdbuf, 4, ackbuf, &ack_len);
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
2004-02-14 16:50:54 +00:00
|
|
|
int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char cmdbuf[16], ackbuf[50];
|
|
|
|
int cmd_len, retval;
|
|
|
|
size_t ack_len;
|
|
|
|
unsigned char vfo_function;
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
if(vfo !=RIG_VFO_CURR) {
|
|
|
|
switch (vfo) {
|
|
|
|
case RIG_VFO_VFO:
|
|
|
|
case RIG_VFO_A: vfo_function = '0'; break;
|
|
|
|
case RIG_VFO_B: vfo_function = '1'; break;
|
|
|
|
case RIG_VFO_MEM: vfo_function = '2'; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_set_split_vfo: unsupported VFO %d\n",
|
|
|
|
vfo);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set RX VFO */
|
|
|
|
cmd_len = sprintf(cmdbuf, "FR%c%s", vfo_function, cmd_trm(rig));
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, cmdbuf, cmd_len, ackbuf, &ack_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
}
|
2004-02-14 16:50:54 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if(split==RIG_SPLIT_ON) {
|
|
|
|
switch (txvfo) {
|
2004-02-14 16:50:54 +00:00
|
|
|
case RIG_VFO_VFO:
|
|
|
|
case RIG_VFO_A: vfo_function = '0'; break;
|
|
|
|
case RIG_VFO_B: vfo_function = '1'; break;
|
|
|
|
case RIG_VFO_MEM: vfo_function = '2'; break;
|
|
|
|
default:
|
2005-09-24 07:48:42 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_set_split_vfo: unsupported VFO %d\n", txvfo);
|
2004-02-14 16:50:54 +00:00
|
|
|
return -RIG_EINVAL;
|
2005-09-24 07:48:42 +00:00
|
|
|
}
|
|
|
|
/* set TX VFO */
|
|
|
|
cmd_len = sprintf(cmdbuf, "FT%c%s", vfo_function, cmd_trm(rig));
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, cmdbuf, cmd_len, ackbuf, &ack_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
} else
|
|
|
|
if(vfo==RIG_VFO_CURR)
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_set_split_vfo: unsupported VFO %d\n", vfo);
|
2005-01-31 16:41:49 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2004-02-14 16:50:54 +00:00
|
|
|
}
|
2002-07-10 21:45:44 +00:00
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
2003-06-23 17:48:27 +00:00
|
|
|
* kenwood_get_vfo using byte 31 of the IF information field
|
2001-05-15 22:05:26 +00:00
|
|
|
* Assumes rig!=NULL, !vfo
|
|
|
|
*/
|
|
|
|
int kenwood_get_vfo(RIG *rig, vfo_t *vfo)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char infobuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t info_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
info_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "IF;", 3, infobuf, &info_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (info_len != 38 || infobuf[1] != 'F') {
|
2003-06-23 17:48:27 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_vfo: wrong answer len=%d\n",
|
2005-09-24 07:48:42 +00:00
|
|
|
info_len);
|
2003-06-23 17:48:27 +00:00
|
|
|
return -RIG_ERJCTED;
|
2005-09-24 07:48:42 +00:00
|
|
|
}
|
|
|
|
switch (infobuf[30]) {
|
|
|
|
case '0': *vfo = RIG_VFO_A; break;
|
|
|
|
case '1': *vfo = RIG_VFO_B; break;
|
|
|
|
case '2': *vfo = RIG_VFO_MEM; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_vfo: unsupported VFO %c\n",
|
|
|
|
infobuf[30]);
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
return RIG_OK;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
2003-06-23 17:48:27 +00:00
|
|
|
|
2000-12-23 08:40:14 +00:00
|
|
|
/*
|
|
|
|
* kenwood_set_freq
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char freqbuf[16], ackbuf[50];
|
|
|
|
int freq_len, retval;
|
|
|
|
size_t ack_len;
|
|
|
|
unsigned char vfo_letter;
|
|
|
|
vfo_t tvfo;
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
tvfo = vfo==RIG_VFO_CURR ? rig->state.current_vfo : vfo;
|
2004-03-29 20:54:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
switch (tvfo) {
|
|
|
|
case RIG_VFO_A: vfo_letter = 'A'; break;
|
|
|
|
case RIG_VFO_B: vfo_letter = 'B'; break;
|
|
|
|
case RIG_VFO_C: vfo_letter = 'C'; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_set_freq: unsupported VFO %d\n",
|
|
|
|
vfo);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2006-04-10 18:00:38 +00:00
|
|
|
freq_len = sprintf(freqbuf,"F%c%011ld;", vfo_letter, (long)freq);
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, freqbuf, freq_len, ackbuf, &ack_len);
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return retval;
|
2000-12-23 08:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_freq
|
|
|
|
* Assumes rig!=NULL, freq!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char freqbuf[50];
|
|
|
|
char cmdbuf[4];
|
|
|
|
int cmd_len, retval;
|
|
|
|
size_t freq_len;
|
|
|
|
unsigned char vfo_letter;
|
|
|
|
vfo_t tvfo;
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
tvfo = vfo==RIG_VFO_CURR ? rig->state.current_vfo : vfo;
|
2004-03-29 20:54:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
switch (tvfo) {
|
|
|
|
case RIG_VFO_A: vfo_letter = 'A'; break;
|
|
|
|
case RIG_VFO_B: vfo_letter = 'B'; break;
|
|
|
|
case RIG_VFO_C: vfo_letter = 'C'; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"%s: unsupported VFO %d\n",
|
|
|
|
__FUNCTION__, vfo);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
cmd_len = sprintf(cmdbuf, "F%c%s", vfo_letter, cmd_trm(rig));
|
2002-03-13 23:42:43 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
freq_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, cmdbuf, cmd_len, freqbuf, &freq_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (freq_len != 14 || freqbuf[0] != 'F') {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"%s: unexpected answer %s, "
|
|
|
|
"len=%d\n", __FUNCTION__, freqbuf, freq_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2002-02-27 20:21:02 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
sscanf(freqbuf+2, "%"SCNfreq, freq);
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2000-12-23 08:40:14 +00:00
|
|
|
}
|
|
|
|
|
2002-09-03 18:55:05 +00:00
|
|
|
int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t * rit)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char infobuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t info_len;
|
2002-09-03 18:55:05 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
info_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "IF;", 3, infobuf, &info_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2002-09-03 18:55:05 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (info_len != 38 || infobuf[1] != 'F') {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_rit: wrong answer len=%d\n",
|
|
|
|
info_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2002-09-03 18:55:05 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
infobuf[23] = '\0';
|
|
|
|
*rit = atoi(&infobuf[18]);
|
2002-09-03 18:55:05 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2002-09-03 18:55:05 +00:00
|
|
|
}
|
|
|
|
|
2002-09-04 14:36:11 +00:00
|
|
|
/*
|
|
|
|
* rit can only move up/down by 10 Hz, so we use a loop...
|
|
|
|
*/
|
2002-09-03 18:55:05 +00:00
|
|
|
int kenwood_set_rit(RIG * rig, vfo_t vfo, shortfreq_t rit)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char buf[50], infobuf[50];
|
|
|
|
unsigned char c;
|
|
|
|
int retval, len, i;
|
|
|
|
size_t info_len;
|
2002-09-13 19:57:39 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
info_len = 0;
|
2002-09-03 18:55:05 +00:00
|
|
|
if (rit == 0)
|
2004-05-02 17:17:31 +00:00
|
|
|
return kenwood_transaction(rig, "RC;", 3, infobuf, &info_len);
|
2002-09-03 18:55:05 +00:00
|
|
|
|
|
|
|
if (rit > 0)
|
|
|
|
c = 'U';
|
|
|
|
else
|
|
|
|
c = 'D';
|
|
|
|
len = sprintf(buf, "R%c;", c);
|
|
|
|
|
2002-09-13 19:57:39 +00:00
|
|
|
info_len = 0;
|
2002-09-03 18:55:05 +00:00
|
|
|
retval = kenwood_transaction(rig, "RC;", 3, infobuf, &info_len);
|
2002-10-22 20:24:07 +00:00
|
|
|
for (i = 0; i < abs(rint(rit/10)); i++)
|
2002-09-13 19:57:39 +00:00
|
|
|
{
|
|
|
|
info_len = 0;
|
2002-09-03 18:55:05 +00:00
|
|
|
retval = kenwood_transaction(rig, buf, len, infobuf, &info_len);
|
2002-09-13 19:57:39 +00:00
|
|
|
}
|
2002-09-03 18:55:05 +00:00
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-04 17:32:42 +00:00
|
|
|
/*
|
|
|
|
* rit and xit are the same
|
|
|
|
*/
|
|
|
|
int kenwood_get_xit(RIG * rig, vfo_t vfo, shortfreq_t * rit)
|
|
|
|
{
|
|
|
|
return kenwood_get_rit(rig, vfo, rit);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kenwood_set_xit(RIG * rig, vfo_t vfo, shortfreq_t rit)
|
|
|
|
{
|
|
|
|
return kenwood_set_rit(rig, vfo, rit);
|
|
|
|
}
|
|
|
|
|
2004-05-02 17:17:31 +00:00
|
|
|
int kenwood_scan(RIG * rig, vfo_t vfo, scan_t scan, int ch)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char ackbuf[50];
|
|
|
|
size_t ack_len;
|
2004-05-02 17:17:31 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2004-05-02 17:17:31 +00:00
|
|
|
return kenwood_transaction (rig, scan==RIG_SCAN_STOP? "SC0;":"SC1;", 4,
|
|
|
|
ackbuf, &ack_len);
|
|
|
|
}
|
|
|
|
|
2002-09-03 18:55:05 +00:00
|
|
|
|
2000-12-23 08:40:14 +00:00
|
|
|
/*
|
|
|
|
* kenwood_set_mode
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char mdbuf[16], ackbuf[50];
|
|
|
|
int mdbuf_len, kmode, retval;
|
|
|
|
size_t ack_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case RIG_MODE_CW: kmode = MD_CW; break;
|
|
|
|
case RIG_MODE_CWR: kmode = MD_CWR; break;
|
|
|
|
case RIG_MODE_USB: kmode = MD_USB; break;
|
|
|
|
case RIG_MODE_LSB: kmode = MD_LSB; break;
|
|
|
|
case RIG_MODE_FM: kmode = MD_FM; break;
|
|
|
|
case RIG_MODE_AM: kmode = MD_AM; break;
|
|
|
|
case RIG_MODE_RTTY: kmode = MD_FSK; break;
|
|
|
|
case RIG_MODE_RTTYR: kmode = MD_FSKR; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_set_mode: "
|
|
|
|
"unsupported mode %d\n", mode);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
mdbuf_len = sprintf(mdbuf, "MD%c;", kmode);
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, mdbuf, mdbuf_len, ackbuf, &ack_len);
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return retval;
|
2000-12-23 08:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_mode
|
|
|
|
* Assumes rig!=NULL, mode!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char modebuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t mode_len;
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
mode_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "MD;", 3, modebuf, &mode_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (mode_len != 4 || modebuf[1] != 'D') {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_mode: unexpected answer, len=%d\n",
|
|
|
|
mode_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
switch (modebuf[2]) {
|
|
|
|
case MD_CW: *mode = RIG_MODE_CW; break;
|
|
|
|
case MD_CWR: *mode = RIG_MODE_CWR; break;
|
|
|
|
case MD_USB: *mode = RIG_MODE_USB; break;
|
|
|
|
case MD_LSB: *mode = RIG_MODE_LSB; break;
|
|
|
|
case MD_FM: *mode = RIG_MODE_FM; break;
|
|
|
|
case MD_AM: *mode = RIG_MODE_AM; break;
|
|
|
|
case MD_FSK: *mode = RIG_MODE_RTTY; break;
|
|
|
|
case MD_FSKR: *mode = RIG_MODE_RTTYR; break;
|
|
|
|
case MD_NONE: *mode = RIG_MODE_NONE; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_mode: "
|
|
|
|
"unsupported mode '%c'\n", modebuf[2]);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2002-12-20 10:39:41 +00:00
|
|
|
*width = rig_passband_normal(rig, *mode);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2000-12-23 08:40:14 +00:00
|
|
|
}
|
|
|
|
|
2002-01-03 21:42:53 +00:00
|
|
|
int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char levelbuf[16], ackbuf[50];
|
|
|
|
int level_len, retval;
|
2005-09-24 07:48:42 +00:00
|
|
|
int i, kenwood_val;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t ack_len;
|
2002-01-19 18:56:00 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (RIG_LEVEL_IS_FLOAT(level))
|
|
|
|
kenwood_val = val.f * 255;
|
|
|
|
else
|
|
|
|
kenwood_val = val.i;
|
2002-01-19 18:56:00 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
switch (level) {
|
|
|
|
case RIG_LEVEL_RFPOWER:
|
2002-03-25 00:22:41 +00:00
|
|
|
level_len = sprintf(levelbuf, "PC%03d;", kenwood_val);
|
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_AF:
|
2002-01-19 18:56:00 +00:00
|
|
|
level_len = sprintf(levelbuf, "AG%03d;", kenwood_val);
|
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_RF:
|
2002-01-19 18:56:00 +00:00
|
|
|
level_len = sprintf(levelbuf, "RG%03d;", kenwood_val);
|
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_SQL:
|
2002-01-19 18:56:00 +00:00
|
|
|
level_len = sprintf(levelbuf, "SQ%03d;", kenwood_val);
|
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_AGC:
|
2002-09-15 22:35:25 +00:00
|
|
|
if (kenwood_val > 3) kenwood_val = 3; /* 0.. 255 */
|
|
|
|
level_len = sprintf(levelbuf, "GT%03d;", 84*kenwood_val);
|
2002-09-15 22:22:39 +00:00
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_ATT:
|
2005-02-02 19:32:16 +00:00
|
|
|
/* set the attenuator if a correct value is entered */
|
|
|
|
for (i=0; i<MAXDBLSTSIZ; i++)
|
|
|
|
if (kenwood_val == rig->state.attenuator[i])
|
|
|
|
{
|
|
|
|
level_len = sprintf(levelbuf, "RA%02d;", kenwood_val/6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
level_len = sprintf(levelbuf, "RA00;");
|
|
|
|
break;
|
|
|
|
|
2007-08-18 12:55:46 +00:00
|
|
|
case RIG_LEVEL_SLOPE_HIGH:
|
|
|
|
if(val.i>20 || val.i < 0)
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
ack_len=0;
|
|
|
|
level_len = sprintf(levelbuf,"SH%02d;",(val.i));
|
|
|
|
return kenwood_transaction (rig, levelbuf, level_len, ackbuf, &ack_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_SLOPE_LOW:
|
|
|
|
if(val.i>20 || val.i < 0)
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
ack_len=0;
|
|
|
|
level_len = sprintf(levelbuf,"SL%02d;",(val.i));
|
|
|
|
return kenwood_transaction (rig, levelbuf, level_len, ackbuf, &ack_len);
|
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"Unsupported set_level %d", level);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2002-01-19 18:56:00 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, levelbuf, level_len, ackbuf, &ack_len);
|
2002-01-19 18:56:00 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2002-01-19 18:56:00 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2002-01-03 21:42:53 +00:00
|
|
|
}
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
|
|
|
* assumes f!=NULL
|
|
|
|
*/
|
2005-02-02 20:05:03 +00:00
|
|
|
int get_kenwood_level(RIG *rig, const char *cmd, int cmd_len, float *f)
|
2001-05-15 22:05:26 +00:00
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char lvlbuf[50];
|
|
|
|
int retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
int lvl;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t lvl_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2002-03-15 19:43:43 +00:00
|
|
|
lvl_len = 50;
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = kenwood_transaction (rig, cmd, cmd_len, lvlbuf, &lvl_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2002-01-06 17:47:23 +00:00
|
|
|
if (lvl_len != 6) {
|
2005-09-28 21:14:44 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"%s: wrong answer len=%d\n",
|
|
|
|
__FUNCTION__,lvl_len);
|
2001-05-15 22:05:26 +00:00
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 000..255
|
|
|
|
*/
|
|
|
|
sscanf(lvlbuf+2, "%d", &lvl);
|
|
|
|
*f = (float)lvl/255.0;
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_level
|
|
|
|
* Assumes rig!=NULL, val!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char lvlbuf[50];
|
|
|
|
int retval;
|
2005-09-24 07:48:42 +00:00
|
|
|
int lvl;
|
|
|
|
int i, ret, agclevel;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t lvl_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
lvl_len = 50;
|
|
|
|
switch (level) {
|
2005-09-28 21:14:44 +00:00
|
|
|
case RIG_LEVEL_RAWSTR:
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_STRENGTH:
|
|
|
|
retval = kenwood_transaction (rig, "SM;", 3, lvlbuf, &lvl_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (lvl_len != 7 || lvlbuf[1] != 'M') {
|
2005-09-28 21:14:44 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"%s: wrong answer len=%d\n",
|
|
|
|
__FUNCTION__, lvl_len);
|
2005-09-24 07:48:42 +00:00
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-28 21:14:44 +00:00
|
|
|
sscanf(lvlbuf+2, "%d", &val->i); /* rawstr */
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/* Frontend expects: -54 = S0, 0 = S9 */
|
2005-09-28 21:14:44 +00:00
|
|
|
if (level==RIG_LEVEL_STRENGTH)
|
2007-08-18 12:55:46 +00:00
|
|
|
val->i = (val->i * 4) - 54; // There is a better way of doing this with a calibration table. See ts850.c.
|
2005-09-24 07:48:42 +00:00
|
|
|
break;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_ATT:
|
|
|
|
retval = kenwood_transaction (rig, "RA;", 3, lvlbuf, &lvl_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (lvl_len != 5) {
|
2005-09-28 21:14:44 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"%s: unexpected answer len=%d\n",
|
|
|
|
__FUNCTION__, lvl_len);
|
2005-09-24 07:48:42 +00:00
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
sscanf(lvlbuf+2, "%d", &lvl);
|
|
|
|
if (lvl == 0) {
|
|
|
|
val->i = 0;
|
|
|
|
} else {
|
|
|
|
for (i=0; i<lvl && i<MAXDBLSTSIZ; i++)
|
|
|
|
if (rig->state.attenuator[i] == 0) {
|
2005-09-28 21:14:44 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"%s: "
|
|
|
|
"unexpected att level %d\n",
|
|
|
|
__FUNCTION__, lvl);
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
2005-09-24 07:48:42 +00:00
|
|
|
if (i != lvl)
|
|
|
|
return -RIG_EINTERNAL;
|
|
|
|
val->i = rig->state.attenuator[i-1];
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
2005-09-24 07:48:42 +00:00
|
|
|
break;
|
|
|
|
case RIG_LEVEL_RFPOWER:
|
|
|
|
return get_kenwood_level(rig, "PC;", 3, &val->f);
|
|
|
|
|
|
|
|
case RIG_LEVEL_AF:
|
|
|
|
return get_kenwood_level(rig, "AG;", 3, &val->f);
|
|
|
|
|
|
|
|
case RIG_LEVEL_RF:
|
|
|
|
return get_kenwood_level(rig, "RG;", 3, &val->f);
|
|
|
|
|
|
|
|
case RIG_LEVEL_SQL:
|
|
|
|
return get_kenwood_level(rig, "SQ;", 3, &val->f);
|
|
|
|
|
|
|
|
case RIG_LEVEL_MICGAIN:
|
|
|
|
return get_kenwood_level(rig, "MG;", 3, &val->f);
|
|
|
|
|
|
|
|
case RIG_LEVEL_AGC:
|
|
|
|
ret = get_kenwood_level(rig, "GT;", 3, &val->f);
|
|
|
|
agclevel = 255 * val->f;
|
|
|
|
if (agclevel == 0) val->i = 0;
|
|
|
|
else if (agclevel < 85) val->i = 1;
|
|
|
|
else if (agclevel < 170) val->i = 2;
|
|
|
|
else if (agclevel <= 255) val->i = 3;
|
|
|
|
return ret;
|
2007-08-18 12:55:46 +00:00
|
|
|
case RIG_LEVEL_SLOPE_LOW:
|
|
|
|
lvl_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "SL;", 3, lvlbuf, &lvl_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
lvlbuf[4]='\0';
|
|
|
|
val->i=atoi(&lvlbuf[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_SLOPE_HIGH:
|
|
|
|
lvl_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "SH;", 3, lvlbuf, &lvl_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
lvlbuf[4]='\0';
|
|
|
|
val->i=atoi(&lvlbuf[2]);
|
|
|
|
break;
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_LEVEL_PREAMP:
|
|
|
|
case RIG_LEVEL_IF:
|
|
|
|
case RIG_LEVEL_APF:
|
|
|
|
case RIG_LEVEL_NR:
|
|
|
|
case RIG_LEVEL_PBT_IN:
|
|
|
|
case RIG_LEVEL_PBT_OUT:
|
|
|
|
case RIG_LEVEL_CWPITCH:
|
|
|
|
case RIG_LEVEL_KEYSPD:
|
|
|
|
case RIG_LEVEL_NOTCHF:
|
|
|
|
case RIG_LEVEL_COMP:
|
|
|
|
case RIG_LEVEL_BKINDL:
|
|
|
|
case RIG_LEVEL_BALANCE:
|
|
|
|
return -RIG_ENIMPL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"Unsupported get_level %d", level);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
2002-01-03 21:42:53 +00:00
|
|
|
|
|
|
|
int kenwood_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char fctbuf[16], ackbuf[50];
|
|
|
|
int fct_len;
|
|
|
|
size_t ack_len;
|
2002-01-09 23:14:48 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/* Optimize:
|
|
|
|
* sort the switch cases with the most frequent first
|
|
|
|
*/
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
switch (func) {
|
|
|
|
case RIG_FUNC_NB:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"NB%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_ABM:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"AM%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_COMP:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"PR%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_TONE:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"TO%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_TSQL:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"CT%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_VOX:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"VX%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_FAGC:
|
2005-02-13 00:22:00 +00:00
|
|
|
fct_len = sprintf(fctbuf,"GT00%c;", (0==status)? '4':'2');
|
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_NR:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"NR%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_BC:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"BC%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_ANF:
|
2004-12-20 22:58:19 +00:00
|
|
|
fct_len = sprintf(fctbuf,"NT%c;", (0==status)?'0':'1');
|
2002-01-09 23:14:48 +00:00
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_LOCK:
|
2006-03-14 08:36:38 +00:00
|
|
|
fct_len = sprintf(fctbuf,"LK%c;", (0==status)?'0':'1');
|
|
|
|
return kenwood_transaction (rig, fctbuf, fct_len, ackbuf, &ack_len);
|
2007-08-18 12:55:46 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"Unsupported set_func %#x", func);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2002-01-09 23:14:48 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2002-01-03 21:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-30 23:19:42 +00:00
|
|
|
/*
|
|
|
|
* assumes status!=NULL
|
|
|
|
* works for any 'format 1' command
|
|
|
|
*/
|
|
|
|
static int get_kenwood_func(RIG *rig, const char *cmd, int cmd_len, int *status)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char fctbuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t fct_len;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2002-03-15 19:43:43 +00:00
|
|
|
fct_len = 50;
|
2001-06-30 23:19:42 +00:00
|
|
|
retval = kenwood_transaction (rig, cmd, cmd_len, fctbuf, &fct_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (fct_len != 4) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_func: wrong answer len=%d\n",
|
|
|
|
fct_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*status = fctbuf[2] == '0' ? 0 : 1;
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_func
|
|
|
|
* Assumes rig!=NULL, val!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char fctbuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t fct_len;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
fct_len = 50;
|
|
|
|
switch (func) {
|
|
|
|
case RIG_FUNC_FAGC:
|
|
|
|
retval = kenwood_transaction (rig, "GT;", 3, fctbuf, &fct_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (fct_len != 6) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_func: "
|
|
|
|
"wrong answer len=%d\n", fct_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
*status = fctbuf[4] != '4' ? 1 : 0;
|
|
|
|
break;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_NB:
|
|
|
|
return get_kenwood_func(rig, "NB;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_ABM:
|
|
|
|
return get_kenwood_func(rig, "AM;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_COMP:
|
|
|
|
return get_kenwood_func(rig, "PR;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_TONE:
|
|
|
|
return get_kenwood_func(rig, "TO;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_TSQL:
|
|
|
|
return get_kenwood_func(rig, "CT;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_VOX:
|
|
|
|
return get_kenwood_func(rig, "VX;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_NR:
|
|
|
|
return get_kenwood_func(rig, "NR;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/* FIXME on TS2000 */
|
|
|
|
case RIG_FUNC_BC:
|
|
|
|
return get_kenwood_func(rig, "BC;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_ANF:
|
|
|
|
return get_kenwood_func(rig, "NT;", 3, status);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
case RIG_FUNC_LOCK:
|
|
|
|
return get_kenwood_func(rig, "LK;", 3, status);
|
|
|
|
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"Unsupported get_func %#x", func);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
2001-07-01 11:46:17 +00:00
|
|
|
* kenwood_set_ctcss_tone
|
2001-05-15 22:05:26 +00:00
|
|
|
* Assumes rig!=NULL, rig->caps->ctcss_list != NULL
|
|
|
|
*
|
|
|
|
* Warning! This is untested stuff! May work at least on TS-870S
|
2001-12-11 21:58:37 +00:00
|
|
|
* Please owners report to me <fillods@users.sourceforge.net>, thanks. --SF
|
2001-05-15 22:05:26 +00:00
|
|
|
|
|
|
|
* TODO: TS-2000 uses CN/CT
|
|
|
|
*/
|
2001-07-01 11:46:17 +00:00
|
|
|
int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
|
2001-05-15 22:05:26 +00:00
|
|
|
{
|
|
|
|
const struct rig_caps *caps;
|
2006-03-07 19:48:20 +00:00
|
|
|
char tonebuf[16], ackbuf[50];
|
|
|
|
int tone_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
int i;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t ack_len;
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
caps = rig->caps;
|
|
|
|
|
2001-05-22 21:59:26 +00:00
|
|
|
/* TODO: replace 200 by something like RIGTONEMAX */
|
2001-05-15 22:05:26 +00:00
|
|
|
for (i = 0; caps->ctcss_list[i] != 0 && i<200; i++) {
|
2005-09-24 07:48:42 +00:00
|
|
|
if (caps->ctcss_list[i] == tone)
|
|
|
|
break;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
if (caps->ctcss_list[i] != tone)
|
2005-09-24 07:48:42 +00:00
|
|
|
return -RIG_EINVAL;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
|
|
|
/* TODO: replace menu no 57 by a define */
|
|
|
|
tone_len = sprintf(tonebuf,"EX%03d%04d;", 57, i+1);
|
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2001-06-12 07:07:11 +00:00
|
|
|
return kenwood_transaction (rig, tonebuf, tone_len, ackbuf, &ack_len);
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-07-01 11:46:17 +00:00
|
|
|
* kenwood_get_ctcss_tone
|
2001-05-15 22:05:26 +00:00
|
|
|
* Assumes rig!=NULL, rig->state.priv!=NULL
|
|
|
|
*/
|
2001-07-01 11:46:17 +00:00
|
|
|
int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
|
2001-05-15 22:05:26 +00:00
|
|
|
{
|
|
|
|
const struct rig_caps *caps;
|
2006-03-07 19:48:20 +00:00
|
|
|
char tonebuf[50];
|
|
|
|
int i, retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
unsigned int tone_idx;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t tone_len;
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
caps = rig->caps;
|
|
|
|
|
2002-03-15 19:43:43 +00:00
|
|
|
tone_len = 50;
|
2002-09-04 15:08:23 +00:00
|
|
|
retval = kenwood_transaction (rig, "IF;", 3, tonebuf, &tone_len);
|
2001-06-12 07:07:11 +00:00
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2002-09-04 15:08:23 +00:00
|
|
|
if (tone_len != 38 || tonebuf[1] != 'F') {
|
2002-09-04 15:10:21 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_ctcss_tone: wrong answer len=%d\n",
|
2002-09-04 15:08:23 +00:00
|
|
|
tone_len);
|
|
|
|
return -RIG_ERJCTED;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
2002-09-04 15:08:23 +00:00
|
|
|
tonebuf[36] = '\0';
|
|
|
|
tone_idx = atoi(&tonebuf[34]);
|
2001-05-15 22:05:26 +00:00
|
|
|
|
|
|
|
if (tone_idx == 0) {
|
2005-09-24 07:48:42 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_ctcss_tone: Unexpected CTCSS "
|
2001-07-01 11:46:17 +00:00
|
|
|
"no (%04d)\n", tone_idx);
|
2001-05-15 22:05:26 +00:00
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check this tone exists. That's better than nothing. */
|
|
|
|
for (i = 0; i<tone_idx; i++) {
|
|
|
|
if (caps->ctcss_list[i] == 0) {
|
2001-07-01 11:46:17 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_ctcss_tone: CTCSS NG "
|
2001-05-15 22:05:26 +00:00
|
|
|
"(%04d)\n", tone_idx);
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*tone = caps->ctcss_list[tone_idx-1];
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-01 11:20:30 +00:00
|
|
|
/*
|
|
|
|
* set the aerial/antenna to use
|
|
|
|
*/
|
|
|
|
int kenwood_set_ant (RIG * rig, vfo_t vfo, ant_t ant)
|
|
|
|
{
|
|
|
|
char ackbuf[50];
|
|
|
|
const char *cmd;
|
|
|
|
size_t ack_len = 0;
|
|
|
|
|
|
|
|
switch (ant) {
|
|
|
|
case RIG_ANT_1:
|
|
|
|
cmd = "AN1;";
|
|
|
|
case RIG_ANT_2:
|
|
|
|
cmd = "AN2;";
|
|
|
|
case RIG_ANT_3:
|
|
|
|
cmd = "AN3;";
|
|
|
|
case RIG_ANT_4:
|
|
|
|
cmd = "AN4;";
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kenwood_transaction (rig, cmd, 4, ackbuf, &ack_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the aerial/antenna in use
|
|
|
|
*/
|
|
|
|
int kenwood_get_ant (RIG * rig, vfo_t vfo, ant_t * ant)
|
|
|
|
{
|
|
|
|
char ackbuf[50];
|
|
|
|
size_t ack_len = 50;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = kenwood_transaction (rig, "AN;", 3, ackbuf, &ack_len);
|
|
|
|
if (RIG_OK != retval)
|
|
|
|
return retval;
|
|
|
|
if (4 != ack_len)
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
|
|
|
|
if (ackbuf[2] < '1' || ackbuf[2] > '9')
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
|
|
|
|
*ant = RIG_ANT_N(ackbuf[2]-'1');
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-18 18:26:08 +00:00
|
|
|
/*
|
|
|
|
* kenwood_get_ptt
|
|
|
|
* Assumes rig!=NULL, ptt!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char infobuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t info_len;
|
2002-02-18 18:26:08 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
info_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "IF;", 3, infobuf, &info_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2002-02-18 18:26:08 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (info_len != 38 || infobuf[1] != 'F') {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_ptt: wrong answer len=%d\n",
|
|
|
|
info_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
2002-02-18 18:26:08 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
*ptt = infobuf[28] == '0' ? RIG_PTT_OFF : RIG_PTT_ON;
|
2002-02-18 18:26:08 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2002-02-18 18:26:08 +00:00
|
|
|
}
|
|
|
|
|
2004-05-02 17:17:31 +00:00
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
|
|
|
* kenwood_set_ptt
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
2001-05-22 21:59:26 +00:00
|
|
|
int kenwood_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
|
2001-05-15 22:05:26 +00:00
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char ackbuf[50];
|
|
|
|
size_t ack_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
return kenwood_transaction (rig, ptt==RIG_PTT_ON? "TX;":"RX;", 3,
|
|
|
|
ackbuf, &ack_len);
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_dcd
|
|
|
|
* Assumes rig!=NULL, dcd!=NULL
|
|
|
|
*/
|
2001-05-22 21:59:26 +00:00
|
|
|
int kenwood_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
2001-05-15 22:05:26 +00:00
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char busybuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t busy_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2002-03-15 19:43:43 +00:00
|
|
|
busy_len = 50;
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = kenwood_transaction (rig, "BY;", 3, busybuf, &busy_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
|
|
|
if (busy_len != 4) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_dcd: wrong answer len=%d\n",
|
|
|
|
busy_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dcd = (busybuf[2] == 0x01) ? RIG_DCD_ON : RIG_DCD_OFF;
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-04 13:08:33 +00:00
|
|
|
/*
|
|
|
|
* kenwood_set_trn
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
2001-12-20 07:46:13 +00:00
|
|
|
int kenwood_set_trn(RIG *rig, int trn)
|
2001-03-04 13:08:33 +00:00
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char trnbuf[16], ackbuf[50];
|
|
|
|
int trn_len;
|
|
|
|
size_t ack_len;
|
2001-03-04 13:08:33 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
trn_len = sprintf(trnbuf,"AI%c;", trn==RIG_TRN_RIG?'1':'0');
|
2001-03-04 13:08:33 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
return kenwood_transaction (rig, trnbuf, trn_len, ackbuf, &ack_len);
|
2001-03-04 13:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_trn
|
|
|
|
* Assumes rig!=NULL, trn!=NULL
|
|
|
|
*/
|
2001-12-20 07:46:13 +00:00
|
|
|
int kenwood_get_trn(RIG *rig, int *trn)
|
2001-03-04 13:08:33 +00:00
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char trnbuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t trn_len;
|
2001-03-04 13:08:33 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
trn_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "AI;", 3, trnbuf, &trn_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (trn_len != 4) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_trn: wrong answer"
|
|
|
|
"len=%d\n", trn_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
*trn = trnbuf[2] != '0' ? RIG_TRN_RIG : RIG_TRN_OFF;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_set_powerstat
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_set_powerstat(RIG *rig, powerstat_t status)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char pwrbuf[16], ackbuf[50];
|
|
|
|
int pwr_len;
|
|
|
|
size_t ack_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
pwr_len = sprintf(pwrbuf,"PS%c;", status==RIG_POWER_ON?'1':'0');
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
return kenwood_transaction (rig, pwrbuf, pwr_len, ackbuf, &ack_len);
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_powerstat
|
|
|
|
* Assumes rig!=NULL, trn!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_powerstat(RIG *rig, powerstat_t *status)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char pwrbuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t pwr_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2006-03-07 19:48:20 +00:00
|
|
|
pwr_len = 50;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, "PS;", 3, pwrbuf, &pwr_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (pwr_len != 4) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_powerstat: wrong answer "
|
|
|
|
"len=%d\n", pwr_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
*status = pwrbuf[2] == '0' ? RIG_POWER_OFF : RIG_POWER_ON;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
2001-03-04 13:08:33 +00:00
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
|
|
|
* kenwood_reset
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_reset(RIG *rig, reset_t reset)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char rstbuf[16], ackbuf[50];
|
|
|
|
int rst_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
char rst;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t ack_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
switch(reset) {
|
|
|
|
case RIG_RESET_VFO: rst='1'; break;
|
|
|
|
case RIG_RESET_MASTER: rst='2'; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_reset: unsupported reset %d\n",
|
|
|
|
reset);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
rst_len = sprintf(rstbuf,"SR%c;", rst);
|
2001-03-04 13:08:33 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
return kenwood_transaction (rig, rstbuf, rst_len, ackbuf, &ack_len);
|
2001-03-04 13:08:33 +00:00
|
|
|
}
|
|
|
|
|
2001-05-15 22:05:26 +00:00
|
|
|
/*
|
|
|
|
* kenwood_send_morse
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char morsebuf[30], m2[30], ackbuf[50];
|
|
|
|
int morse_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
int msg_len, buff_len, retval;
|
|
|
|
const char *p;
|
2006-03-07 19:48:20 +00:00
|
|
|
size_t ack_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
p = msg;
|
|
|
|
msg_len = strlen(msg);
|
|
|
|
|
|
|
|
while(msg_len > 0) {
|
|
|
|
/*
|
|
|
|
* TODO: check with "KY;" if char buffer is available.
|
|
|
|
* if not, sleep.
|
|
|
|
*
|
|
|
|
* Make the total message segments 28 characters
|
|
|
|
* in length because Kenwood demands it.
|
|
|
|
* Spaces fill in the message end.
|
|
|
|
*/
|
|
|
|
buff_len = msg_len > 24 ? 24 : msg_len;
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
strncpy(m2, p, 24);
|
|
|
|
m2[24] = '\0';
|
|
|
|
|
|
|
|
/* morse_len must be 28 */
|
|
|
|
morse_len = sprintf(morsebuf,"KY %-24s;", m2);
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
retval = kenwood_transaction (rig, morsebuf, morse_len,
|
|
|
|
ackbuf, &ack_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
msg_len -= buff_len;
|
|
|
|
p += buff_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
2001-05-15 22:05:26 +00:00
|
|
|
}
|
|
|
|
|
2001-06-30 23:19:42 +00:00
|
|
|
/*
|
|
|
|
* kenwood_vfo_op
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char *cmd, ackbuf[50];
|
|
|
|
size_t ack_len;
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
switch(op) {
|
|
|
|
case RIG_OP_UP: cmd="UP;"; break;
|
|
|
|
case RIG_OP_DOWN: cmd="DN;"; break;
|
|
|
|
case RIG_OP_BAND_UP: cmd="BD;"; break;
|
|
|
|
case RIG_OP_BAND_DOWN: cmd="BU;"; break;
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_vfo_op: unsupported op %#x\n",
|
|
|
|
op);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
return kenwood_transaction (rig, cmd, 3, ackbuf, &ack_len);
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_set_mem
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_set_mem(RIG *rig, vfo_t vfo, int ch)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char membuf[16], ackbuf[16];
|
|
|
|
int mem_len;
|
|
|
|
size_t ack_len;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/*
|
|
|
|
* "MCbmm;"
|
|
|
|
* where b is the bank number, mm the memory number.
|
|
|
|
* b can be a space
|
|
|
|
*/
|
|
|
|
mem_len = sprintf(membuf, "MC %02d;", ch);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2006-03-14 08:36:38 +00:00
|
|
|
ack_len = 0;
|
2005-09-24 07:48:42 +00:00
|
|
|
return kenwood_transaction (rig, membuf, mem_len, ackbuf, &ack_len);
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_mem
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int kenwood_get_mem(RIG *rig, vfo_t vfo, int *ch)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char membuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t mem_len;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
/*
|
|
|
|
* "MCbmm;"
|
|
|
|
* where b is the bank number, mm the memory number.
|
|
|
|
* b can be a space
|
|
|
|
*/
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
mem_len = 50;
|
|
|
|
retval = kenwood_transaction (rig, "MC;", 3, membuf, &mem_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
if (mem_len != 6) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_mem: wrong answer "
|
|
|
|
"len=%d\n", mem_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
*ch = atoi(membuf+2);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kenwood_get_info
|
|
|
|
* supposed to work only for TS2000...
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
const char* kenwood_get_info(RIG *rig)
|
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char firmbuf[50];
|
|
|
|
int retval;
|
|
|
|
size_t firm_len;
|
|
|
|
|
2002-03-15 19:43:43 +00:00
|
|
|
firm_len = 50;
|
2001-06-30 23:19:42 +00:00
|
|
|
retval = kenwood_transaction (rig, "TY;", 3, firmbuf, &firm_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (firm_len != 6) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"kenwood_get_info: wrong answer len=%d\n",
|
|
|
|
firm_len);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (firmbuf[4]) {
|
2005-09-24 07:48:42 +00:00
|
|
|
case '0': return "Firmware: Overseas type";
|
|
|
|
case '1': return "Firmware: Japanese 100W type";
|
|
|
|
case '2': return "Firmware: Japanese 20W type";
|
|
|
|
default: return "Firmware: unknown";
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-13 23:42:43 +00:00
|
|
|
#define IDBUFSZ 16
|
2001-06-30 23:19:42 +00:00
|
|
|
|
|
|
|
/*
|
2003-03-10 08:26:09 +00:00
|
|
|
* proberigs_kenwood
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* There's only one rig possible per port.
|
2003-04-16 22:30:43 +00:00
|
|
|
*
|
|
|
|
* rig_model_t probeallrigs_kenwood(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)
|
2001-06-30 23:19:42 +00:00
|
|
|
*/
|
2003-04-16 22:30:43 +00:00
|
|
|
DECLARE_PROBERIG_BACKEND(kenwood)
|
2001-06-30 23:19:42 +00:00
|
|
|
{
|
2006-03-07 19:48:20 +00:00
|
|
|
char idbuf[IDBUFSZ];
|
2003-03-15 23:58:41 +00:00
|
|
|
int id_len=-1, i, k_id;
|
|
|
|
int retval=-1;
|
2004-12-20 22:58:19 +00:00
|
|
|
int rates[] = { 115200, 57600, 9600, 4800, 1200, 0 }; /* possible baud rates */
|
2003-03-10 08:26:09 +00:00
|
|
|
int rates_idx;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
|
|
|
if (!port)
|
2003-03-10 08:26:09 +00:00
|
|
|
return RIG_MODEL_NONE;
|
|
|
|
|
|
|
|
if (port->type.rig != RIG_PORT_SERIAL)
|
|
|
|
return RIG_MODEL_NONE;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
|
|
|
port->write_delay = port->post_write_delay = 0;
|
2003-03-10 08:26:09 +00:00
|
|
|
port->parm.serial.stop_bits = 2;
|
2001-06-30 23:19:42 +00:00
|
|
|
port->retry = 1;
|
|
|
|
|
2003-03-10 08:26:09 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
retval = serial_open(port);
|
|
|
|
if (retval != RIG_OK)
|
2001-06-30 23:19:42 +00:00
|
|
|
return RIG_MODEL_NONE;
|
2003-03-10 08:26:09 +00:00
|
|
|
|
|
|
|
retval = write_block(port, "ID;", 3);
|
|
|
|
id_len = read_string(port, idbuf, IDBUFSZ, EOM_KEN EOM_TH, strlen(EOM_KEN EOM_TH));
|
|
|
|
close(port->fd);
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2003-03-10 08:26:09 +00:00
|
|
|
if (retval != RIG_OK || id_len < 0)
|
|
|
|
continue;
|
|
|
|
}
|
2001-06-30 23:19:42 +00:00
|
|
|
|
2003-03-10 08:26:09 +00:00
|
|
|
if (retval != RIG_OK || id_len < 0 || !strcmp(idbuf, "ID;"))
|
|
|
|
return RIG_MODEL_NONE;
|
2001-06-30 23:19:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* reply should be something like 'IDxxx;'
|
|
|
|
*/
|
2001-10-18 20:43:13 +00:00
|
|
|
if (id_len != 5 || id_len != 6) {
|
2005-09-24 07:48:42 +00:00
|
|
|
idbuf[7] = '\0';
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: protocol error,"
|
|
|
|
" expected %d, received %d: %s\n",
|
|
|
|
6, id_len, idbuf);
|
|
|
|
return RIG_MODEL_NONE;
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
|
2001-10-18 20:43:13 +00:00
|
|
|
|
|
|
|
/* first, try ID string */
|
|
|
|
for (i=0; kenwood_id_string_list[i].model != RIG_MODEL_NONE; i++) {
|
2005-09-24 07:48:42 +00:00
|
|
|
if (!strncmp(kenwood_id_string_list[i].id, idbuf+2, 16)) {
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: "
|
|
|
|
"found %s\n", idbuf+2);
|
|
|
|
if (cfunc)
|
|
|
|
(*cfunc)(port, kenwood_id_string_list[i].model, data);
|
|
|
|
return kenwood_id_string_list[i].model;
|
|
|
|
}
|
2001-10-18 20:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* then, try ID numbers */
|
|
|
|
|
2001-06-30 23:19:42 +00:00
|
|
|
k_id = atoi(idbuf+2);
|
|
|
|
|
2002-11-13 20:35:18 +00:00
|
|
|
/*
|
|
|
|
* Elecraft K2 returns same ID as TS570
|
|
|
|
*/
|
|
|
|
if (k_id == 17) {
|
|
|
|
retval = serial_open(port);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return RIG_MODEL_NONE;
|
|
|
|
retval = write_block(port, "K2;", 3);
|
|
|
|
id_len = read_string(port, idbuf, IDBUFSZ, EOM_KEN EOM_TH, 2);
|
|
|
|
close(port->fd);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return RIG_MODEL_NONE;
|
|
|
|
/*
|
|
|
|
* reply should be something like 'K2n;'
|
|
|
|
*/
|
|
|
|
if (id_len == 4 || !strcmp(idbuf, "K2")) {
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: found K2\n");
|
2003-03-10 08:26:09 +00:00
|
|
|
if (cfunc)
|
|
|
|
(*cfunc)(port, RIG_MODEL_K2, data);
|
2002-11-13 20:35:18 +00:00
|
|
|
return RIG_MODEL_K2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-30 23:19:42 +00:00
|
|
|
for (i=0; kenwood_id_list[i].model != RIG_MODEL_NONE; i++) {
|
2002-11-13 20:35:18 +00:00
|
|
|
if (kenwood_id_list[i].id == k_id) {
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: "
|
|
|
|
"found %03d\n", k_id);
|
2003-03-10 08:26:09 +00:00
|
|
|
if (cfunc)
|
|
|
|
(*cfunc)(port, kenwood_id_list[i].model, data);
|
2002-11-13 20:35:18 +00:00
|
|
|
return kenwood_id_list[i].model;
|
|
|
|
}
|
2001-06-30 23:19:42 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* not found in known table....
|
|
|
|
* update kenwood_id_list[]!
|
|
|
|
*/
|
|
|
|
rig_debug(RIG_DEBUG_WARN,"probe_kenwood: found unknown device "
|
|
|
|
"with ID %03d, please report to Hamlib "
|
|
|
|
"developers.\n", k_id);
|
|
|
|
|
|
|
|
return RIG_MODEL_NONE;
|
|
|
|
}
|
2001-05-15 22:05:26 +00:00
|
|
|
|
2001-03-04 13:08:33 +00:00
|
|
|
|
2000-12-23 08:40:14 +00:00
|
|
|
/*
|
2001-12-28 20:28:04 +00:00
|
|
|
* initrigs_kenwood is called by rig_backend_load
|
2000-12-23 08:40:14 +00:00
|
|
|
*/
|
2003-04-16 22:30:43 +00:00
|
|
|
DECLARE_INITRIG_BACKEND(kenwood)
|
2000-12-23 08:40:14 +00:00
|
|
|
{
|
2005-09-24 07:48:42 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "kenwood: _init called\n");
|
|
|
|
|
|
|
|
rig_register(&ts950sdx_caps);
|
|
|
|
rig_register(&ts50s_caps);
|
|
|
|
rig_register(&ts140_caps);
|
|
|
|
rig_register(&ts450s_caps);
|
|
|
|
rig_register(&ts570d_caps);
|
|
|
|
rig_register(&ts570s_caps);
|
|
|
|
rig_register(&ts680s_caps);
|
|
|
|
rig_register(&ts690s_caps);
|
|
|
|
rig_register(&ts790_caps);
|
|
|
|
rig_register(&ts850_caps);
|
|
|
|
rig_register(&ts870s_caps);
|
|
|
|
rig_register(&ts930_caps);
|
|
|
|
rig_register(&ts2000_caps);
|
|
|
|
rig_register(&k2_caps);
|
2008-09-01 19:01:13 +00:00
|
|
|
rig_register(&k3_caps);
|
2005-09-24 07:48:42 +00:00
|
|
|
|
|
|
|
rig_register(&ts440_caps);
|
|
|
|
rig_register(&ts940_caps);
|
|
|
|
rig_register(&ts711_caps);
|
|
|
|
rig_register(&ts811_caps);
|
|
|
|
rig_register(&r5000_caps);
|
|
|
|
|
|
|
|
rig_register(&tmd700_caps);
|
|
|
|
rig_register(&thd7a_caps);
|
|
|
|
rig_register(&thf7e_caps);
|
|
|
|
rig_register(&thg71_caps);
|
|
|
|
rig_register(&tmv7_caps);
|
|
|
|
|
|
|
|
rig_register(&ts480_caps);
|
2000-12-23 08:40:14 +00:00
|
|
|
|
2005-09-24 07:48:42 +00:00
|
|
|
return RIG_OK;
|
2000-12-23 08:40:14 +00:00
|
|
|
}
|
|
|
|
|