kopia lustrzana https://github.com/Hamlib/Hamlib
694 wiersze
18 KiB
C
694 wiersze
18 KiB
C
/*
|
|
* Hamlib Kenwood backend - TH-D7 description
|
|
* Copyright (c) 2000,2001 by Stephane Fillod
|
|
*
|
|
* $Id: thd7.c,v 1.5 2002-01-07 17:46:28 fgretief 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.
|
|
*
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h> /* Standard input/output definitions */
|
|
#include <string.h> /* String function definitions */
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
#include <fcntl.h> /* File control definitions */
|
|
#include <errno.h> /* Error number definitions */
|
|
#include <termios.h> /* POSIX terminal control definitions */
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <hamlib/rig.h>
|
|
#include <hamlib/riglist.h>
|
|
#include "kenwood.h"
|
|
#include "th.h"
|
|
|
|
#if 1
|
|
#define RIG_ASSERT(x) if (!(x)) { rig_debug(RIG_DEBUG_ERR, "Assertion failed on line %i\n",__LINE__); abort(); }
|
|
#else
|
|
#define RIG_ASSERT(x)
|
|
#endif
|
|
|
|
static int thd7_set_vfo(RIG *rig, vfo_t vfo);
|
|
static int thd7_get_vfo(RIG *rig, vfo_t *vfo);
|
|
static int thd7_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
|
|
static int thd7_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
|
|
static int thd7_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone);
|
|
static int thd7_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone);
|
|
static int thd7_set_trn(RIG *rig, int trn);
|
|
static int thd7_get_trn(RIG *rig, int *trn);
|
|
static const char *thd7_get_info(RIG *rig);
|
|
static int thd7_set_mem(RIG *rig, vfo_t vfo, int ch);
|
|
static int thd7_get_mem(RIG *rig, vfo_t vfo, int *ch);
|
|
static int thd7_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
|
|
|
|
#define THD7_MODES (RIG_MODE_FM|RIG_MODE_AM)
|
|
#define THD7_MODES_TX (RIG_MODE_FM)
|
|
|
|
#define THD7_FUNC_ALL (RIG_FUNC_TSQL| \
|
|
RIG_FUNC_AIP| \
|
|
RIG_FUNC_MON| \
|
|
RIG_FUNC_SQL| \
|
|
RIG_FUNC_TONE| \
|
|
RIG_FUNC_REV| \
|
|
RIG_FUNC_LOCK| \
|
|
RIG_FUNC_ARO| \
|
|
RIG_FUNC_LMP)
|
|
|
|
#define THD7_LEVEL_ALL (RIG_LEVEL_STRENGTH| \
|
|
RIG_LEVEL_SQL| \
|
|
RIG_LEVEL_SQLSTAT| \
|
|
RIG_LEVEL_AF| \
|
|
RIG_LEVEL_RF|\
|
|
RIG_LEVEL_MICGAIN)
|
|
|
|
#define THD7_VFO_OP (RIG_OP_UP|RIG_OP_DOWN)
|
|
|
|
/*
|
|
* TODO: Band A & B
|
|
*/
|
|
#define THD7_VFO (RIG_VFO_A|RIG_VFO_B)
|
|
|
|
const struct kenwood_priv_caps thd7_priv_caps = {
|
|
cmdtrm: "\r", /* Command termination character */
|
|
};
|
|
|
|
|
|
/*
|
|
* th-d7a rig capabilities.
|
|
*/
|
|
const struct rig_caps thd7a_caps = {
|
|
rig_model: RIG_MODEL_THD7A,
|
|
model_name:"TH-D7A",
|
|
mfg_name: "Kenwood",
|
|
version: "0.1",
|
|
copyright: "LGPL",
|
|
status: RIG_STATUS_ALPHA,
|
|
rig_type: RIG_TYPE_HANDHELD|RIG_FLAG_APRS|RIG_FLAG_TNC|RIG_FLAG_DXCLUSTER,
|
|
ptt_type: RIG_PTT_RIG,
|
|
dcd_type: RIG_DCD_RIG,
|
|
port_type: RIG_PORT_SERIAL,
|
|
serial_rate_min: 9600,
|
|
serial_rate_max: 9600,
|
|
serial_data_bits: 8,
|
|
serial_stop_bits: 1,
|
|
serial_parity: RIG_PARITY_NONE,
|
|
serial_handshake: RIG_HANDSHAKE_NONE,
|
|
write_delay: 0,
|
|
post_write_delay: 0,
|
|
timeout: 200,
|
|
retry: 3,
|
|
|
|
has_get_func: THD7_FUNC_ALL,
|
|
has_set_func: THD7_FUNC_ALL,
|
|
has_get_level: THD7_LEVEL_ALL,
|
|
has_set_level: RIG_LEVEL_SET(THD7_LEVEL_ALL),
|
|
has_get_parm: RIG_PARM_NONE,
|
|
has_set_parm: RIG_PARM_NONE, /* FIXME: parms */
|
|
level_gran: {}, /* FIXME: granularity */
|
|
parm_gran: {},
|
|
ctcss_list: kenwood38_ctcss_list,
|
|
dcs_list: NULL,
|
|
preamp: { RIG_DBLST_END, },
|
|
attenuator: { RIG_DBLST_END, },
|
|
max_rit: Hz(0),
|
|
max_xit: Hz(0),
|
|
max_ifshift: Hz(0),
|
|
vfo_ops: THD7_VFO_OP,
|
|
targetable_vfo: RIG_TARGETABLE_FREQ,
|
|
transceive: RIG_TRN_RIG,
|
|
bank_qty: 0,
|
|
chan_desc_sz: 0,
|
|
|
|
|
|
chan_list: { { 1, 200, RIG_MTYPE_MEM, 0 },
|
|
RIG_CHAN_END,
|
|
}, /* FIXME: memory channel list: 200 memories */
|
|
|
|
rx_range_list1: { RIG_FRNG_END, }, /* FIXME: enter region 1 setting */
|
|
tx_range_list1: { RIG_FRNG_END, },
|
|
rx_range_list2: {
|
|
{MHz(144),MHz(148),THD7_MODES,-1,-1,THD7_VFO},
|
|
{MHz(430),MHz(440),THD7_MODES,-1,-1,THD7_VFO},
|
|
RIG_FRNG_END,
|
|
}, /* rx range */
|
|
tx_range_list2: {
|
|
{MHz(144),MHz(148),THD7_MODES_TX,W(5.5),W(5.5),THD7_VFO},
|
|
{MHz(430),MHz(440),THD7_MODES_TX,W(5.5),W(5.5),THD7_VFO},
|
|
RIG_FRNG_END,
|
|
}, /* tx range */
|
|
tuning_steps: {
|
|
{THD7_MODES,kHz(5)},
|
|
{THD7_MODES,kHz(6.25)},
|
|
{THD7_MODES,kHz(10)},
|
|
{THD7_MODES,kHz(12.5)},
|
|
{THD7_MODES,kHz(15)},
|
|
{THD7_MODES,kHz(20)},
|
|
{THD7_MODES,kHz(25)},
|
|
{THD7_MODES,kHz(30)},
|
|
{THD7_MODES,kHz(50)},
|
|
{THD7_MODES,kHz(100)},
|
|
RIG_TS_END,
|
|
},
|
|
/* mode/filter list, remember: order matters! */
|
|
filters: {
|
|
{RIG_MODE_FM, kHz(14)},
|
|
{RIG_MODE_AM, kHz(9)},
|
|
RIG_FLT_END,
|
|
},
|
|
priv: (void *)&thd7_priv_caps,
|
|
rig_init: kenwood_init,
|
|
rig_cleanup: kenwood_cleanup,
|
|
rig_open: NULL,
|
|
rig_close: NULL,
|
|
|
|
set_freq: th_set_freq,
|
|
get_freq: th_get_freq,
|
|
set_mode: th_set_mode,
|
|
get_mode: th_get_mode,
|
|
set_vfo: th_set_vfo,
|
|
get_vfo: th_get_vfo,
|
|
set_ctcss_tone: thd7_set_ctcss_tone,
|
|
get_ctcss_tone: thd7_get_ctcss_tone,
|
|
set_mem: thd7_set_mem,
|
|
get_mem: thd7_get_mem,
|
|
set_trn: th_set_trn,
|
|
get_trn: th_get_trn,
|
|
|
|
get_func: th_get_func,
|
|
get_level: th_get_level,
|
|
get_info: thd7_get_info,
|
|
|
|
decode_event: th_decode_event,
|
|
};
|
|
|
|
#define EOM "\r"
|
|
|
|
|
|
/*
|
|
* thd7_set_vfo
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_set_vfo(RIG *rig, vfo_t vfo)
|
|
{
|
|
unsigned char vsel, vfobuf[16], ackbuf[24];
|
|
int retval, vfo_len, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__" called\n");
|
|
RIG_ASSERT(rig != NULL);
|
|
|
|
switch (vfo) {
|
|
case RIG_VFO_A: vsel = '0'; break;
|
|
case RIG_VFO_B: vsel = '1'; break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unsupported VFO %d\n", vfo);
|
|
return -RIG_EINVAL;
|
|
}
|
|
|
|
vfo_len = sprintf(vfobuf, "BC %c" EOM, vsel);
|
|
retval = kenwood_transaction (rig, vfobuf, vfo_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
return -RIG_ERJCTED;
|
|
}
|
|
return RIG_OK;
|
|
}
|
|
|
|
/*
|
|
* thd7_get_vfo
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_get_vfo(RIG *rig, vfo_t *vfo)
|
|
{
|
|
unsigned char ackbuf[16];
|
|
int retval, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__" called\n");
|
|
RIG_ASSERT(rig != NULL);
|
|
|
|
retval = kenwood_transaction (rig, "BC" EOM, 3, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
// if (ack_len != 5) { /* for some reason ack_len is zero */
|
|
if (ackbuf[0] != 'B' || ackbuf[1] != 'C' || ackbuf[2] != ' ') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", ackbuf, ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
switch (ackbuf[3]) {
|
|
case '0': *vfo = RIG_VFO_A; break;
|
|
case '1': *vfo = RIG_VFO_B; break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected VFO value %c\n",
|
|
ackbuf[3]);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
return RIG_OK;
|
|
}
|
|
|
|
/*
|
|
* thd7_set_mode
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
|
{
|
|
unsigned char mdbuf[24], ackbuf[24];
|
|
int retval, kmode, mdbuf_len, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__" called\n");
|
|
RIG_ASSERT(rig != NULL);
|
|
|
|
switch (mode) {
|
|
case RIG_MODE_FM: kmode = '0'; break;
|
|
case RIG_MODE_AM: kmode = '1'; break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR,__FUNCTION__": unsupported mode %d\n", mode);
|
|
return -RIG_EINVAL;
|
|
}
|
|
mdbuf_len = sprintf(mdbuf, "MD %c" EOM, kmode);
|
|
retval = kenwood_transaction (rig, mdbuf, mdbuf_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": ack NG, len=%d\n", ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
/*
|
|
* thd7_get_mode
|
|
* Assumes rig!=NULL, mode!=NULL
|
|
*/
|
|
static int
|
|
thd7_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
|
{
|
|
int retval, ack_len = 0;
|
|
unsigned char ackbuf[24];
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
RIG_ASSERT(rig != NULL);
|
|
RIG_ASSERT(mode != NULL);
|
|
memset(ackbuf, 0, sizeof(ackbuf)); /* for terminating zero of string */
|
|
|
|
retval = kenwood_transaction (rig, "MD" EOM, 3, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
/*if (ack_len != 5) { */ /* ack_len does not work. */
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": ack NG, len=%d\n", ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
if (ackbuf[0] != 'M' || ackbuf[1] != 'D' || ackbuf[2] != ' ') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unknown replay (%i) %s\n",
|
|
ack_len, ackbuf);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
if (width)
|
|
*width = RIG_PASSBAND_NORMAL;
|
|
|
|
switch (ackbuf[3]) {
|
|
case '0': *mode = RIG_MODE_FM; break;
|
|
case '1': *mode = RIG_MODE_AM; break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unsupported mode %c\n", ackbuf[3]);
|
|
return -RIG_EINVAL;
|
|
}
|
|
return RIG_OK;
|
|
}
|
|
|
|
#ifndef RIG_TONEMAX
|
|
#define RIG_TONEMAX 38
|
|
#endif
|
|
|
|
/*
|
|
* thd7_set_ctcss_tone
|
|
* Assumes rig!=NULL, rig->caps->ctcss_list != NULL
|
|
*/
|
|
static int
|
|
thd7_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
|
|
{
|
|
const struct rig_caps *caps;
|
|
unsigned char tonebuf[24], ackbuf[24];
|
|
int retval, tone_len, ack_len = 0;
|
|
int i;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
RIG_ASSERT(rig != NULL);
|
|
RIG_ASSERT(rig->caps != NULL && rig->caps->ctcss_list != NULL);
|
|
memset(ackbuf, 0, sizeof(ackbuf));
|
|
|
|
caps = rig->caps;
|
|
|
|
for (i = 0; caps->ctcss_list[i] != 0 && i < RIG_TONEMAX; i++) {
|
|
if (caps->ctcss_list[i] == tone)
|
|
break;
|
|
}
|
|
if (caps->ctcss_list[i] != tone)
|
|
return -RIG_EINVAL;
|
|
|
|
i += (i == 0) ? 1 : 2; /* Correct for TH-7D anomally */
|
|
tone_len = sprintf(tonebuf, "CTN %02d" EOM, i);
|
|
retval = kenwood_transaction (rig, tonebuf, tone_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
/* error/result checking */
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": negative acknowledgment\n");
|
|
return -RIG_ERJCTED;
|
|
}
|
|
if (ackbuf[0] != 'C' || ackbuf[1] != 'T' || ackbuf[2] != 'N') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", tonebuf, tone_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
return RIG_OK;
|
|
}
|
|
|
|
/*
|
|
* thd7_get_ctcss_tone
|
|
* Assumes rig!=NULL, rig->caps!=NULL
|
|
*/
|
|
static int
|
|
thd7_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
|
|
{
|
|
const struct rig_caps *caps;
|
|
unsigned char tonebuf[24];
|
|
int retval, tone_len = 0;
|
|
unsigned int tone_idx;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
RIG_ASSERT(rig != NULL);
|
|
RIG_ASSERT(rig->caps != NULL && rig->caps->ctcss_list != NULL);
|
|
memset(tonebuf, 0, sizeof(tonebuf)); /* for terminating zero of string */
|
|
|
|
caps = rig->caps;
|
|
|
|
retval = kenwood_transaction (rig, "CTN" EOM, 4, tonebuf, &tone_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (tonebuf[0] != 'C' || tonebuf[1] != 'T' || tonebuf[2] != 'N') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", tonebuf, tone_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
sscanf(tonebuf+3, "%u", (int*)&tone_idx);
|
|
|
|
/* verify tone index for TH-7D rig */
|
|
if (tone_idx <= 0 || tone_idx == 2 || tone_idx > 39) {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__
|
|
": Unexpected CTCSS no (%04d)\n", tone_idx);
|
|
return -RIG_EPROTO;
|
|
}
|
|
tone_idx -= (tone_idx == 1) ? 1 : 2; /* Correct for TH-7D anomaly */
|
|
*tone = caps->ctcss_list[tone_idx];
|
|
return RIG_OK;
|
|
}
|
|
|
|
#ifdef USE_TRN_FUNCS
|
|
/*
|
|
* th7d_set_trn
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_set_trn(RIG *rig, int trn)
|
|
{
|
|
unsigned char trnbuf[16], ackbuf[16];
|
|
int retval, trn_len, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
memset(ackbuf, 0, sizeof(ackbuf));
|
|
|
|
trn_len = sprintf(trnbuf, "AI %c" EOM,
|
|
(trn == RIG_TRN_RIG) ? '1' : '0');
|
|
|
|
retval = kenwood_transaction (rig, trnbuf, trn_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (ackbuf[0] != 'A' || ackbuf[1] != 'I') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", ackbuf, ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
return RIG_OK;
|
|
}
|
|
|
|
/*
|
|
* th7d_get_trn
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_get_trn(RIG *rig, int *trn)
|
|
{
|
|
unsigned char trnbuf[16];
|
|
int retval, trn_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
memset(trnbuf, 0, sizeof(trnbuf));
|
|
|
|
retval = kenwood_transaction(rig, "AI" EOM, 3, trnbuf, &trn_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (trnbuf[0] == 'N' && trnbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": ack NG, len=%d\n", trn_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
if (trnbuf[0] != 'A' || trnbuf[1] != 'I') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", trnbuf, trn_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
*trn = (trnbuf[4] != '0') ? RIG_TRN_RIG : RIG_TRN_OFF;
|
|
return RIG_OK;
|
|
}
|
|
#endif /* USE_TRN_FUNCS */
|
|
|
|
static const char *
|
|
thd7_get_info(RIG *rig) /* I hope this is the correct function for this command. */
|
|
{
|
|
static unsigned char firmbuf[16];
|
|
int retval, firm_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
|
|
memset(firmbuf, 0, sizeof(firmbuf));
|
|
retval = kenwood_transaction (rig, "ID" EOM, 3, firmbuf, &firm_len);
|
|
if (retval != RIG_OK)
|
|
return NULL;
|
|
#if 1
|
|
if (firm_len != 6) {
|
|
rig_debug(RIG_DEBUG_ERR,__FUNCTION__": wrong answer len=%d\n",
|
|
firm_len);
|
|
return NULL;
|
|
}
|
|
#endif
|
|
if (firmbuf[0] != 'I' || firmbuf[1] != 'D') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", firmbuf, firm_len);
|
|
return NULL;
|
|
}
|
|
|
|
return &firmbuf[2];
|
|
}
|
|
|
|
/*
|
|
* thd7_set_mem
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_set_mem(RIG *rig, vfo_t vfo, int ch)
|
|
{
|
|
unsigned char vsel, membuf[16], ackbuf[16];
|
|
int retval, mem_len, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
memset(ackbuf, 0, sizeof(ackbuf));
|
|
|
|
if (ch < 0 || ch > 200) {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": channel num out of range: %d\n", ch);
|
|
return -RIG_EINVAL;
|
|
}
|
|
switch (vfo) {
|
|
case RIG_VFO_A: vsel = '0'; break;
|
|
case RIG_VFO_B: vsel = '1'; break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unsupported VFO %d\n", vfo);
|
|
return -RIG_EINVAL;
|
|
}
|
|
|
|
mem_len = sprintf(membuf, "MC %c,%i" EOM, vsel, ch);
|
|
retval = kenwood_transaction(rig, membuf, mem_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": negative acknowledgment\n");
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
if (ackbuf[0] != 'M' || ackbuf[1] != 'C') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", ackbuf, ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
return RIG_OK;
|
|
}
|
|
|
|
static int
|
|
thd7_get_mem(RIG *rig, vfo_t vfo, int *ch)
|
|
{
|
|
unsigned char *membuf, ackbuf[16];
|
|
int retval, mem_len, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
memset(ackbuf, 0, sizeof(ackbuf));
|
|
|
|
switch (vfo) {
|
|
case RIG_VFO_A:
|
|
membuf = "MC 0" EOM;
|
|
break;
|
|
case RIG_VFO_B:
|
|
membuf = "MC 1" EOM;
|
|
break;
|
|
case RIG_VFO_CURR:
|
|
membuf = "MC" EOM;
|
|
break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unsupported VFO %d\n", vfo);
|
|
return -RIG_EINVAL;
|
|
}
|
|
|
|
mem_len = strlen(membuf);
|
|
retval = kenwood_transaction(rig, membuf, mem_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": negative acknowledgment\n");
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
if (ackbuf[0] != 'M' || ackbuf[1] != 'C') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", ackbuf, ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
*ch = atoi(&membuf[3]);
|
|
#if 0
|
|
if (*ch < 0 || *ch > 200) {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": channel num out of range: %d\n", ch);
|
|
return -RIG_EINVAL;
|
|
}
|
|
#endif
|
|
return RIG_OK;
|
|
}
|
|
|
|
/*
|
|
* thd7_get_level
|
|
* Assumes rig!=NULL
|
|
*/
|
|
static int
|
|
thd7_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|
{
|
|
unsigned char vsel, lvlbuf[16], ackbuf[16];
|
|
int retval, lvl_len, ack_len = 0;
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, __FUNCTION__": called\n");
|
|
memset(ackbuf, 0, sizeof(ackbuf));
|
|
|
|
switch (vfo) {
|
|
case RIG_VFO_A: vsel = '0'; break;
|
|
case RIG_VFO_B: vsel = '1'; break;
|
|
default:
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unsupported VFO %d\n", vfo);
|
|
return -RIG_EINVAL;
|
|
}
|
|
|
|
switch (level) {
|
|
case RIG_LEVEL_STRENGTH:
|
|
lvl_len = sprintf(lvlbuf, "SM %c" EOM, vsel);
|
|
retval = kenwood_transaction(rig, lvlbuf, lvl_len, ackbuf, &ack_len);
|
|
if (retval != RIG_OK)
|
|
return retval;
|
|
if (ackbuf[0] == 'N' && ackbuf[1] == '\n') {
|
|
rig_debug(RIG_DEBUG_ERR,__FUNCTION__": negative acknowledgment\n");
|
|
return -RIG_ERJCTED;
|
|
}
|
|
if (ackbuf[0] != 'S' || ackbuf[1] != 'M') {
|
|
rig_debug(RIG_DEBUG_ERR, __FUNCTION__": unexpected reply "
|
|
"'%s', len=%d\n", ackbuf, ack_len);
|
|
return -RIG_ERJCTED;
|
|
}
|
|
|
|
val->i = atoi(&ackbuf[3]);
|
|
break;
|
|
|
|
case RIG_LEVEL_SQLSTAT:
|
|
case RIG_LEVEL_PREAMP:
|
|
case RIG_LEVEL_ATT:
|
|
case RIG_LEVEL_AF:
|
|
case RIG_LEVEL_RF:
|
|
case RIG_LEVEL_SQL:
|
|
case RIG_LEVEL_MICGAIN:
|
|
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_AGC:
|
|
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;
|
|
}
|
|
return RIG_OK;
|
|
}
|
|
|
|
/* end of file */
|
|
|