2004-05-03 22:33:13 +00:00
|
|
|
/*
|
|
|
|
* Hamlib TenTenc backend - RX-340 description
|
2009-08-03 22:13:30 +00:00
|
|
|
* Copyright (c) 2003-2009 by Stephane Fillod
|
2004-05-03 22:33:13 +00:00
|
|
|
*
|
|
|
|
*
|
2011-08-22 01:22:00 +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.
|
2004-05-03 22:33:13 +00:00
|
|
|
*
|
2011-08-22 01:22:00 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2004-05-03 22:33:13 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-22 01:22:00 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2004-05-03 22:33:13 +00:00
|
|
|
*
|
2011-08-22 01:22:00 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2004-05-03 22:33:13 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2011-08-22 01:22:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-05-03 22:33:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2009-08-03 22:13:30 +00:00
|
|
|
#include <string.h>
|
2004-05-03 22:33:13 +00:00
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#include "hamlib/rig.h"
|
2004-05-03 22:33:13 +00:00
|
|
|
#include "bandplan.h"
|
2009-08-03 22:13:30 +00:00
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "num_stdio.h"
|
2004-05-03 22:33:13 +00:00
|
|
|
|
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#define RX340_MODES (RIG_MODE_FM|RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_DSB|\
|
2019-11-30 16:19:08 +00:00
|
|
|
RIG_MODE_AM|RIG_MODE_AMS)
|
2004-05-03 22:33:13 +00:00
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#define RX340_FUNCS (RIG_FUNC_NB)
|
2004-05-03 22:33:13 +00:00
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#define RX340_LEVELS (RIG_LEVEL_STRENGTH| \
|
2019-11-30 16:19:08 +00:00
|
|
|
RIG_LEVEL_RF|RIG_LEVEL_IF| \
|
2009-08-03 22:13:30 +00:00
|
|
|
RIG_LEVEL_NOTCHF|RIG_LEVEL_SQL| \
|
2019-11-30 16:19:08 +00:00
|
|
|
RIG_LEVEL_CWPITCH|RIG_LEVEL_AGC| \
|
|
|
|
RIG_LEVEL_ATT|RIG_LEVEL_PREAMP)
|
2004-05-03 22:33:13 +00:00
|
|
|
|
2011-08-22 01:22:00 +00:00
|
|
|
#define RX340_ANTS (RIG_ANT_1)
|
2004-05-03 22:33:13 +00:00
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#define RX340_PARMS (RIG_PARM_NONE)
|
2004-05-03 22:33:13 +00:00
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#define RX340_VFO (RIG_VFO_A)
|
2004-05-03 22:33:13 +00:00
|
|
|
|
|
|
|
#define RX340_VFO_OPS (RIG_OP_TO_VFO|RIG_OP_FROM_VFO)
|
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
/* TODO: levels.. */
|
|
|
|
#define RX340_MEM_CAP { \
|
|
|
|
.freq = 1, \
|
|
|
|
.mode = 1, \
|
|
|
|
.width = 1, \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int rx340_init(RIG *rig);
|
|
|
|
static int rx340_cleanup(RIG *rig);
|
|
|
|
#endif
|
|
|
|
static int rx340_open(RIG *rig);
|
|
|
|
static int rx340_close(RIG *rig);
|
|
|
|
static int rx340_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
|
|
|
|
static int rx340_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
|
|
|
|
static int rx340_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
|
|
|
|
static int rx340_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
|
|
|
|
static int rx340_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val);
|
|
|
|
static int rx340_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
|
2019-11-30 16:19:08 +00:00
|
|
|
static const char *rx340_get_info(RIG *rig);
|
2004-05-03 22:33:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RX340 receiver capabilities.
|
|
|
|
*
|
2011-08-22 01:22:00 +00:00
|
|
|
* Protocol is documented at
|
2019-11-30 16:19:08 +00:00
|
|
|
* http://radio.tentec.com/downloads/receivers/RX340
|
2004-05-03 22:33:13 +00:00
|
|
|
*
|
2009-08-03 22:13:30 +00:00
|
|
|
* TODO: from/to memory, scan, get_level, ..
|
|
|
|
* supposes non-multidrop
|
2004-05-03 22:33:13 +00:00
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct rig_caps rx340_caps =
|
|
|
|
{
|
2020-03-05 14:44:18 +00:00
|
|
|
RIG_MODEL(RIG_MODEL_RX340),
|
2019-11-30 16:19:08 +00:00
|
|
|
.model_name = "RX-340",
|
|
|
|
.mfg_name = "Ten-Tec",
|
2020-03-30 04:03:21 +00:00
|
|
|
.version = "20160409.0",
|
2019-11-30 16:19:08 +00:00
|
|
|
.copyright = "LGPL",
|
|
|
|
.status = RIG_STATUS_UNTESTED,
|
|
|
|
.rig_type = RIG_TYPE_RECEIVER,
|
|
|
|
.ptt_type = RIG_PTT_NONE,
|
|
|
|
.dcd_type = RIG_DCD_NONE,
|
|
|
|
.port_type = RIG_PORT_SERIAL,
|
|
|
|
.serial_rate_min = 75,
|
|
|
|
.serial_rate_max = 38400,
|
|
|
|
.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 = 400,
|
|
|
|
.retry = 3,
|
|
|
|
|
|
|
|
.has_get_func = RX340_FUNCS,
|
|
|
|
.has_set_func = RX340_FUNCS,
|
|
|
|
.has_get_level = RX340_LEVELS,
|
|
|
|
.has_set_level = RIG_LEVEL_SET(RX340_LEVELS),
|
|
|
|
.has_get_parm = RX340_PARMS,
|
|
|
|
.has_set_parm = RX340_PARMS,
|
|
|
|
.level_gran = {}, /* FIXME: granularity */
|
|
|
|
.parm_gran = {},
|
|
|
|
.ctcss_list = NULL,
|
|
|
|
.dcs_list = NULL,
|
|
|
|
.preamp = { 10, RIG_DBLST_END },
|
|
|
|
.attenuator = { 15, RIG_DBLST_END },
|
|
|
|
.max_rit = Hz(0),
|
|
|
|
.max_xit = Hz(0),
|
|
|
|
.max_ifshift = kHz(2),
|
|
|
|
.targetable_vfo = RIG_TARGETABLE_NONE,
|
|
|
|
.transceive = RIG_TRN_OFF,
|
|
|
|
.bank_qty = 0,
|
|
|
|
.chan_desc_sz = 0,
|
|
|
|
|
|
|
|
.chan_list = {
|
|
|
|
{ 1, 100, RIG_MTYPE_MEM, RX340_MEM_CAP },
|
|
|
|
},
|
|
|
|
|
|
|
|
.rx_range_list1 = {
|
|
|
|
{kHz(0), MHz(30), RX340_MODES, -1, -1, RX340_VFO, RX340_ANTS},
|
|
|
|
RIG_FRNG_END,
|
|
|
|
},
|
|
|
|
.tx_range_list1 = {
|
|
|
|
RIG_FRNG_END,
|
|
|
|
},
|
|
|
|
|
|
|
|
.rx_range_list2 = {
|
|
|
|
{kHz(0), MHz(30), RX340_MODES, -1, -1, RX340_VFO, RX340_ANTS},
|
|
|
|
RIG_FRNG_END,
|
|
|
|
},
|
|
|
|
.tx_range_list2 = {
|
|
|
|
RIG_FRNG_END,
|
|
|
|
},
|
|
|
|
|
|
|
|
.tuning_steps = {
|
|
|
|
{RX340_MODES, 1},
|
|
|
|
RIG_TS_END,
|
|
|
|
},
|
|
|
|
/* mode/filter list, remember: order matters! */
|
|
|
|
.filters = {
|
|
|
|
{RX340_MODES, kHz(3.2)},
|
|
|
|
{RX340_MODES, Hz(100)},
|
|
|
|
{RX340_MODES, kHz(16)},
|
|
|
|
{RX340_MODES, 0},
|
|
|
|
RIG_FLT_END,
|
|
|
|
},
|
|
|
|
.priv = (void *)NULL,
|
|
|
|
|
|
|
|
.rig_open = rx340_open,
|
|
|
|
.rig_close = rx340_close,
|
|
|
|
.set_freq = rx340_set_freq,
|
|
|
|
.get_freq = rx340_get_freq,
|
|
|
|
.set_mode = rx340_set_mode,
|
|
|
|
.get_mode = rx340_get_mode,
|
|
|
|
.set_level = rx340_set_level,
|
|
|
|
.get_level = rx340_get_level,
|
|
|
|
.get_info = rx340_get_info,
|
2004-05-03 22:33:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function definitions below
|
|
|
|
*/
|
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
#define BUFSZ 128
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
#define EOM "\015" /* CR */
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
#define RX340_AM '1'
|
|
|
|
#define RX340_FM '2'
|
|
|
|
#define RX340_CW '3'
|
|
|
|
#define RX340_CW1 '4'
|
|
|
|
#define RX340_ISB '5'
|
|
|
|
#define RX340_LSB '6'
|
|
|
|
#define RX340_USB '7'
|
|
|
|
#define RX340_SAM '8'
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_transaction
|
|
|
|
* read exactly data_len bytes
|
|
|
|
* We assume that rig!=NULL, rig->state!= NULL, data!=NULL, data_len!=NULL
|
|
|
|
* Otherwise, you'll get a nice seg fault. You've been warned!
|
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
static int rx340_transaction(RIG *rig, const char *cmd, int cmd_len, char *data,
|
|
|
|
int *data_len)
|
2009-08-03 22:13:30 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int retval;
|
|
|
|
struct rig_state *rs;
|
|
|
|
|
|
|
|
rs = &rig->state;
|
|
|
|
|
2020-06-23 14:01:46 +00:00
|
|
|
rig_flush(&rs->rigport);
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
retval = write_block(&rs->rigport, cmd, cmd_len);
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (retval != RIG_OK)
|
|
|
|
{
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no data expected, TODO: flush input? */
|
|
|
|
if (!data || !data_len)
|
|
|
|
{
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
retval = read_string(&rs->rigport, data, BUFSZ, EOM, 1);
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (retval < 0)
|
|
|
|
{
|
|
|
|
return retval;
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
*data_len = retval;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* rx340_init:
|
|
|
|
* Basically, it just sets up *priv
|
|
|
|
*/
|
|
|
|
int rx340_init(RIG *rig)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct rx340_priv_data *priv;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv = (struct rx340_priv_data *)malloc(sizeof(struct rx340_priv_data));
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
/* whoops! memory shortage! */
|
|
|
|
return -RIG_ENOMEM;
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
memset(priv, 0, sizeof(struct rx340_priv_data));
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/*
|
|
|
|
* set arbitrary initial status
|
|
|
|
*/
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig->state.priv = (rig_ptr_t)priv;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tentec generic rx340_cleanup routine
|
|
|
|
* the serial port is closed by the frontend
|
|
|
|
*/
|
|
|
|
int rx340_cleanup(RIG *rig)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
if (rig->state.priv)
|
|
|
|
{
|
|
|
|
free(rig->state.priv);
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig->state.priv = NULL;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int rx340_open(RIG *rig)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct rig_state *rs = &rig->state;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
#define REMOTE_CMD "*R1"EOM
|
2019-11-30 16:19:08 +00:00
|
|
|
return write_block(&rs->rigport, REMOTE_CMD, strlen(REMOTE_CMD));
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int rx340_close(RIG *rig)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct rig_state *rs = &rig->state;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
#define LOCAL_CMD "*R0"EOM
|
2019-11-30 16:19:08 +00:00
|
|
|
return write_block(&rs->rigport, LOCAL_CMD, strlen(LOCAL_CMD));
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_set_freq
|
|
|
|
*/
|
|
|
|
int rx340_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct rig_state *rs = &rig->state;
|
|
|
|
int freq_len, retval;
|
|
|
|
char freqbuf[16];
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
freq_len = num_sprintf(freqbuf, "F%.6f" EOM, freq / 1e6);
|
2011-08-22 01:22:00 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
retval = write_block(&rs->rigport, freqbuf, freq_len);
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return retval;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_get_freq
|
|
|
|
* Assumes rig!=NULL, freq!=NULL
|
|
|
|
*/
|
|
|
|
int rx340_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|
|
|
{
|
|
|
|
char buf[BUFSZ];
|
2020-04-04 22:31:35 +00:00
|
|
|
int buf_len = 0;
|
2009-08-03 22:13:30 +00:00
|
|
|
int retval;
|
|
|
|
double f;
|
|
|
|
|
|
|
|
#define REPORT_FREQ "TF"EOM
|
2019-11-30 16:19:08 +00:00
|
|
|
retval = rx340_transaction(rig, REPORT_FREQ, strlen(REPORT_FREQ), buf,
|
|
|
|
&buf_len);
|
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
if (retval < 0)
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2009-08-03 22:13:30 +00:00
|
|
|
return retval;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (buf_len < 2 || buf[0] != 'F' || num_sscanf(buf + 1, "%lf", &f) != 1)
|
|
|
|
{
|
2009-08-03 22:13:30 +00:00
|
|
|
return -RIG_EPROTO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2011-08-22 01:22:00 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
*freq = f * 1e6;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2017-06-28 17:00:20 +00:00
|
|
|
return RIG_OK;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_set_mode
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int rx340_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct rig_state *rs = &rig->state;
|
|
|
|
char dmode;
|
|
|
|
int mdbuf_len, retval;
|
|
|
|
char mdbuf[32];
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case RIG_MODE_USB: dmode = RX340_USB; break;
|
|
|
|
|
|
|
|
case RIG_MODE_LSB: dmode = RX340_LSB; break;
|
|
|
|
|
|
|
|
case RIG_MODE_CW: dmode = RX340_CW; break;
|
|
|
|
|
|
|
|
case RIG_MODE_FM: dmode = RX340_FM; break;
|
|
|
|
|
|
|
|
case RIG_MODE_AM: dmode = RX340_AM; break;
|
|
|
|
|
|
|
|
case RIG_MODE_AMS: dmode = RX340_SAM; break;
|
|
|
|
|
|
|
|
case RIG_MODE_DSB: dmode = RX340_ISB; break;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,
|
|
|
|
"%s: unsupported mode %s\n",
|
|
|
|
__func__, rig_strrmode(mode));
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width != RIG_PASSBAND_NOCHANGE)
|
|
|
|
{
|
|
|
|
if (width == RIG_PASSBAND_NORMAL)
|
|
|
|
{
|
|
|
|
width = rig_passband_normal(rig, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set DETECTION MODE and IF FILTER
|
|
|
|
*/
|
|
|
|
mdbuf_len = num_sprintf(mdbuf, "D%cI%.02f" EOM,
|
|
|
|
dmode, (float)width / 1e3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set DETECTION MODE
|
|
|
|
*/
|
|
|
|
mdbuf_len = num_sprintf(mdbuf, "D%c" EOM, dmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = write_block(&rs->rigport, mdbuf, mdbuf_len);
|
|
|
|
|
|
|
|
return retval;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_get_mode
|
|
|
|
* Assumes rig!=NULL, mode!=NULL
|
|
|
|
*/
|
|
|
|
int rx340_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
|
|
|
{
|
|
|
|
char buf[BUFSZ];
|
2020-04-04 22:31:35 +00:00
|
|
|
int buf_len = 0;
|
2009-08-03 22:13:30 +00:00
|
|
|
int retval;
|
|
|
|
double f;
|
|
|
|
|
|
|
|
#define REPORT_MODEFILTER "TDI"EOM
|
|
|
|
retval = rx340_transaction(rig, REPORT_MODEFILTER,
|
2019-11-30 16:19:08 +00:00
|
|
|
strlen(REPORT_MODEFILTER), buf, &buf_len);
|
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
if (retval < 0)
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2009-08-03 22:13:30 +00:00
|
|
|
return retval;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
if (buf_len < 4 || buf[0] != 'D' || buf[2] != 'I')
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
2009-08-03 22:13:30 +00:00
|
|
|
return -RIG_EPROTO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (buf[1])
|
|
|
|
{
|
|
|
|
case RX340_USB: *mode = RIG_MODE_USB; break;
|
|
|
|
|
|
|
|
case RX340_LSB: *mode = RIG_MODE_LSB; break;
|
|
|
|
|
|
|
|
case RX340_CW1:
|
|
|
|
case RX340_CW: *mode = RIG_MODE_CW; break;
|
2011-08-22 01:22:00 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case RX340_FM: *mode = RIG_MODE_FM; break;
|
|
|
|
|
|
|
|
case RX340_AM: *mode = RIG_MODE_AM; break;
|
|
|
|
|
|
|
|
case RX340_SAM: *mode = RIG_MODE_AMS; break;
|
|
|
|
|
|
|
|
case RX340_ISB: *mode = RIG_MODE_DSB; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,
|
|
|
|
"%s: unknown mode '%c'\n",
|
|
|
|
__func__, buf[1]);
|
|
|
|
return -RIG_EPROTO;
|
2017-06-28 17:00:20 +00:00
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (num_sscanf(buf + 3, "%lf", &f) != 1)
|
|
|
|
{
|
2009-08-03 22:13:30 +00:00
|
|
|
return -RIG_EPROTO;
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
2011-08-22 01:22:00 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
*width = f * 1e3;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2017-06-28 17:00:20 +00:00
|
|
|
return RIG_OK;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_set_level
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
* cannot support PREAMP and ATT both at same time (make sense though)
|
|
|
|
*/
|
|
|
|
int rx340_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct rig_state *rs = &rig->state;
|
|
|
|
int cmd_len, retval = RIG_OK;
|
|
|
|
char cmdbuf[32];
|
|
|
|
|
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case RIG_LEVEL_ATT:
|
|
|
|
cmd_len = sprintf(cmdbuf, "K%c" EOM, val.i ? '3' : '1');
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case RIG_LEVEL_PREAMP:
|
|
|
|
cmd_len = sprintf(cmdbuf, "K%c" EOM, val.i ? '2' : '1');
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case RIG_LEVEL_AGC:
|
|
|
|
/* default to MEDIUM */
|
|
|
|
cmd_len = sprintf(cmdbuf, "M%c" EOM,
|
|
|
|
val.i == RIG_AGC_SLOW ? '3' : (
|
|
|
|
val.i == RIG_AGC_FAST ? '1' : '2'));
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case RIG_LEVEL_RF:
|
|
|
|
cmd_len = sprintf(cmdbuf, "A%d" EOM, 120 - (int)(val.f * 120));
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
2011-08-22 01:22:00 +00:00
|
|
|
|
2009-08-03 22:13:30 +00:00
|
|
|
case RIG_LEVEL_SQL:
|
2019-11-30 16:19:08 +00:00
|
|
|
cmd_len = sprintf(cmdbuf, "Q%d" EOM, 150 - (int)(val.f * 150));
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_NOTCHF:
|
2019-11-30 16:19:08 +00:00
|
|
|
cmd_len = num_sprintf(cmdbuf, "N%f" EOM, ((float)val.i) / 1e3);
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_IF:
|
2019-11-30 16:19:08 +00:00
|
|
|
cmd_len = num_sprintf(cmdbuf, "P%f" EOM, ((float)val.i) / 1e3);
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_LEVEL_CWPITCH:
|
|
|
|
/* only in CW mode */
|
2019-11-30 16:19:08 +00:00
|
|
|
cmd_len = num_sprintf(cmdbuf, "B%f" EOM, ((float)val.i) / 1e3);
|
2009-08-03 22:13:30 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unsupported set_level %s\n",
|
|
|
|
__func__, rig_strlevel(level));
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
retval = write_block(&rs->rigport, cmdbuf, cmd_len);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_get_level
|
|
|
|
* Assumes rig!=NULL, val!=NULL
|
|
|
|
*/
|
|
|
|
int rx340_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int retval, lvl_len;
|
|
|
|
char lvlbuf[BUFSZ];
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case RIG_LEVEL_STRENGTH:
|
2009-08-03 22:13:30 +00:00
|
|
|
#define REPORT_STRENGTH "X"EOM
|
2019-11-30 16:19:08 +00:00
|
|
|
retval = rx340_transaction(rig, REPORT_STRENGTH,
|
|
|
|
strlen(REPORT_STRENGTH), lvlbuf, &lvl_len);
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (retval != RIG_OK)
|
|
|
|
{
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lvl_len < 2 || lvlbuf[0] != 'X')
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: wrong answer"
|
|
|
|
"len=%d\n", __func__, lvl_len);
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
/* range 0-150 covering the dynamic range
|
|
|
|
* of receiver -140..+10dBm
|
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
val->i = atoi(lvlbuf + 1) - 140 + 73;
|
|
|
|
break;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case RIG_LEVEL_AGC:
|
|
|
|
case RIG_LEVEL_ATT:
|
|
|
|
case RIG_LEVEL_PREAMP:
|
|
|
|
case RIG_LEVEL_RF:
|
2009-08-03 22:13:30 +00:00
|
|
|
case RIG_LEVEL_IF:
|
2019-11-30 16:19:08 +00:00
|
|
|
case RIG_LEVEL_SQL:
|
2009-08-03 22:13:30 +00:00
|
|
|
case RIG_LEVEL_CWPITCH:
|
|
|
|
case RIG_LEVEL_NOTCHF:
|
|
|
|
return -RIG_ENIMPL;
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unsupported get_level %s\n",
|
|
|
|
__func__, rig_strlevel(level));
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-08-03 22:13:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx340_get_info
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
const char *rx340_get_info(RIG *rig)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
static char buf[BUFSZ]; /* FIXME: reentrancy */
|
2020-06-10 03:37:03 +00:00
|
|
|
int firmware_len = 0, retval;
|
2009-08-03 22:13:30 +00:00
|
|
|
|
|
|
|
#define REPORT_FIRM "V"EOM
|
2019-11-30 16:19:08 +00:00
|
|
|
retval = rx340_transaction(rig, REPORT_FIRM, strlen(REPORT_FIRM), buf,
|
|
|
|
&firmware_len);
|
|
|
|
|
|
|
|
if ((retval != RIG_OK) || (firmware_len > 10))
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: ack NG, len=%d\n",
|
|
|
|
__func__, firmware_len);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
2009-08-03 22:13:30 +00:00
|
|
|
}
|
|
|
|
|
2004-05-03 22:33:13 +00:00
|
|
|
|