kopia lustrzana https://github.com/Hamlib/Hamlib
reworked rig2icom_mode and icom2rig_mode to better handle cases with no passband data
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1020 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.3
rodzic
b26d39f637
commit
cf86d350ff
57
icom/frame.c
57
icom/frame.c
|
@ -2,7 +2,7 @@
|
|||
* Hamlib CI-V backend - low level communication routines
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||
*
|
||||
* $Id: frame.c,v 1.15 2002-03-05 00:39:30 fillods Exp $
|
||||
* $Id: frame.c,v 1.16 2002-03-10 23:44:24 fillods 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
|
||||
|
@ -216,15 +216,24 @@ int read_icom_frame(port_t *p, unsigned char rxbuffer[])
|
|||
|
||||
|
||||
/*
|
||||
* convert mode and width as expressed by Hamlib frontend
|
||||
* to mode and passband data understandable by a CI-V rig
|
||||
*
|
||||
* if pd == -1, no passband data is to be sent
|
||||
*
|
||||
* return RIG_OK if everything's fine, negative value otherwise
|
||||
*
|
||||
* TODO: be more exhaustive
|
||||
* assumes rig!=NULL
|
||||
*/
|
||||
unsigned short rig2icom_mode(RIG *rig, rmode_t mode, pbwidth_t width)
|
||||
int rig2icom_mode(RIG *rig, rmode_t mode, pbwidth_t width,
|
||||
unsigned char *md, char *pd)
|
||||
{
|
||||
int icmode, icmode_ext;
|
||||
pbwidth_t norm_width;
|
||||
unsigned char icmode;
|
||||
char icmode_ext;
|
||||
pbwidth_t medium_width;
|
||||
|
||||
icmode_ext = 0;
|
||||
icmode_ext = -1;
|
||||
|
||||
switch (mode) {
|
||||
case RIG_MODE_AM: icmode = S_AM; break;
|
||||
|
@ -236,43 +245,45 @@ unsigned short rig2icom_mode(RIG *rig, rmode_t mode, pbwidth_t width)
|
|||
case RIG_MODE_WFM: icmode = S_WFM; break;
|
||||
default:
|
||||
rig_debug(RIG_DEBUG_ERR,"icom: Unsupported Hamlib mode %d\n",mode);
|
||||
icmode = 0xff;
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
norm_width = rig_passband_normal(rig, mode);
|
||||
if (width == norm_width || width == RIG_PASSBAND_NORMAL)
|
||||
icmode_ext = 0x00;
|
||||
else if (width < norm_width)
|
||||
icmode_ext = 0x02;
|
||||
medium_width = rig_passband_normal(rig, mode);
|
||||
if (width == medium_width || width == RIG_PASSBAND_NORMAL)
|
||||
icmode_ext = -1; /* medium, no passband data */
|
||||
else if (width < medium_width)
|
||||
icmode_ext = PD_NARROW;
|
||||
else
|
||||
icmode_ext = 0x01;
|
||||
icmode_ext = PD_WIDE;
|
||||
|
||||
if (rig->caps->rig_model == RIG_MODEL_ICR7000) {
|
||||
if (mode == RIG_MODE_USB || mode == RIG_MODE_LSB) {
|
||||
icmode = S_AM;
|
||||
icmode = S_R7000_SSB;
|
||||
icmode_ext = 0x00;
|
||||
} else if (mode == RIG_MODE_AM && icmode_ext == 0x00) {
|
||||
icmode_ext = 0x01; /* default to Wide */
|
||||
} else if (mode == RIG_MODE_AM && icmode_ext == -1) {
|
||||
icmode_ext = PD_WIDE; /* default to Wide */
|
||||
}
|
||||
}
|
||||
|
||||
return (icmode_ext<<8 | icmode);
|
||||
*md = icmode;
|
||||
*pd = icmode_ext;
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* assumes rig!=NULL, mode!=NULL, width!=NULL
|
||||
*/
|
||||
void icom2rig_mode(RIG *rig, unsigned short icmode, rmode_t *mode, pbwidth_t *width)
|
||||
void icom2rig_mode(RIG *rig, unsigned char md, char pd, rmode_t *mode, pbwidth_t *width)
|
||||
{
|
||||
*width = RIG_PASSBAND_NORMAL;
|
||||
|
||||
switch (icmode & 0xff) {
|
||||
switch (md) {
|
||||
case S_AM: *mode = RIG_MODE_AM; break;
|
||||
case S_CW: *mode = RIG_MODE_CW; break;
|
||||
case S_FM: if (rig->caps->rig_model == RIG_MODEL_ICR7000
|
||||
&& ((icmode>>8) & 0xff) == 0x00) {
|
||||
&& pd == 0x00) {
|
||||
*mode = RIG_MODE_USB;
|
||||
*width = rig_passband_normal(rig, *mode);
|
||||
*width = rig_passband_normal(rig, RIG_MODE_USB);
|
||||
return;
|
||||
} else
|
||||
*mode = RIG_MODE_FM;
|
||||
|
@ -285,16 +296,16 @@ void icom2rig_mode(RIG *rig, unsigned short icmode, rmode_t *mode, pbwidth_t *wi
|
|||
|
||||
default:
|
||||
rig_debug(RIG_DEBUG_ERR,"icom: Unsupported Icom mode %#.2x\n",
|
||||
icmode);
|
||||
md);
|
||||
*mode = RIG_MODE_NONE;
|
||||
}
|
||||
switch ((icmode>>8) & 0xff) {
|
||||
switch (pd) {
|
||||
case 0x00: *width = rig_passband_narrow(rig, *mode); break;
|
||||
case 0x01: *width = rig_passband_normal(rig, *mode); break;
|
||||
case 0x02: *width = rig_passband_wide(rig, *mode); break;
|
||||
default:
|
||||
rig_debug(RIG_DEBUG_ERR,"icom: Unsupported Icom mode width %#.2x\n",
|
||||
icmode);
|
||||
pd);
|
||||
*width = RIG_PASSBAND_NORMAL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Hamlib CI-V backend - low level communication header
|
||||
* Copyright (c) 2000,2001 by Stephane Fillod
|
||||
*
|
||||
* $Id: frame.h,v 1.9 2001-09-19 21:17:35 f4cfe Exp $
|
||||
* $Id: frame.h,v 1.10 2002-03-10 23:44:24 fillods 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
|
||||
|
@ -33,8 +33,8 @@ int read_icom_block(port_t *p, unsigned char *rxbuffer, size_t count);
|
|||
int icom_transaction (RIG *rig, int cmd, int subcmd, const char *payload, int payload_len, char *data, int *data_len);
|
||||
int read_icom_frame(port_t *p, unsigned char rxbuffer[]);
|
||||
|
||||
unsigned short rig2icom_mode(RIG *rig, rmode_t mode, pbwidth_t width);
|
||||
void icom2rig_mode(RIG *rig, unsigned short icmode, rmode_t *mode, pbwidth_t *width);
|
||||
int rig2icom_mode(RIG *rig, rmode_t mode, pbwidth_t width, unsigned char *md, char *pd);
|
||||
void icom2rig_mode(RIG *rig, unsigned char md, char pd, rmode_t *mode, pbwidth_t *width);
|
||||
|
||||
#endif /* _FRAME_H */
|
||||
|
||||
|
|
36
icom/icom.c
36
icom/icom.c
|
@ -2,7 +2,7 @@
|
|||
* Hamlib CI-V backend - main file
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||
*
|
||||
* $Id: icom.c,v 1.55 2002-03-06 21:10:56 fillods Exp $
|
||||
* $Id: icom.c,v 1.56 2002-03-10 23:44:24 fillods 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
|
||||
|
@ -418,17 +418,19 @@ int icom_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
|||
{
|
||||
struct icom_priv_data *priv;
|
||||
struct rig_state *rs;
|
||||
unsigned char ackbuf[16],icmode_ext[1];
|
||||
int ack_len, icmode, retval;
|
||||
unsigned char ackbuf[16];
|
||||
char icmode, icmode_ext;
|
||||
int ack_len, retval, err;
|
||||
|
||||
rs = &rig->state;
|
||||
priv = (struct icom_priv_data*)rs->priv;
|
||||
|
||||
icmode = rig2icom_mode(rig, mode,width);
|
||||
err = rig2icom_mode(rig, mode, width, &icmode, &icmode_ext);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
icmode_ext[0] = (icmode>>8) & 0xff;
|
||||
retval = icom_transaction (rig, C_SET_MODE, icmode & 0xff, icmode_ext,
|
||||
icmode_ext[0]?1:0, ackbuf, &ack_len);
|
||||
retval = icom_transaction (rig, C_SET_MODE, icmode, &icmode_ext,
|
||||
icmode_ext == -1 ? 0 : 1, ackbuf, &ack_len);
|
||||
if (retval != RIG_OK)
|
||||
return retval;
|
||||
|
||||
|
@ -474,7 +476,7 @@ int icom_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
|||
return -RIG_ERJCTED;
|
||||
}
|
||||
|
||||
icom2rig_mode(rig, modebuf[1]| modebuf[2]<<8, mode, width);
|
||||
icom2rig_mode(rig, modebuf[1], modebuf[2], mode, width);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -1877,7 +1879,8 @@ int icom_set_channel(RIG *rig, const channel_t *chan)
|
|||
struct rig_state *rs;
|
||||
unsigned char chanbuf[24], ackbuf[16];
|
||||
int chan_len, freq_len, ack_len, retval;
|
||||
int icmode;
|
||||
char icmode, icmode_ext;
|
||||
int err;
|
||||
|
||||
rs = &rig->state;
|
||||
priv = (struct icom_priv_data*)rs->priv;
|
||||
|
@ -1894,9 +1897,13 @@ int icom_set_channel(RIG *rig, const channel_t *chan)
|
|||
|
||||
chan_len = 3+freq_len+1;
|
||||
|
||||
icmode = rig2icom_mode(rig, chan->mode, RIG_PASSBAND_NORMAL);/* FIXME */
|
||||
chanbuf[chan_len++] = icmode&0xff;
|
||||
chanbuf[chan_len++] = icmode>>8;
|
||||
err = rig2icom_mode(rig, chan->mode, RIG_PASSBAND_NORMAL,
|
||||
&icmode, &icmode_ext);/* FIXME */
|
||||
if (err != RIG_OK)
|
||||
return err;
|
||||
|
||||
chanbuf[chan_len++] = icmode;
|
||||
chanbuf[chan_len++] = icmode_ext; /* FIXME */
|
||||
|
||||
to_bcd_be(chanbuf+chan_len++,
|
||||
chan->levels[rig_setting2idx(RIG_LEVEL_ATT)].i, 2);
|
||||
|
@ -1965,7 +1972,7 @@ int icom_get_channel(RIG *rig, channel_t *chan)
|
|||
|
||||
chan_len = 4+freq_len+1;
|
||||
|
||||
icom2rig_mode(rig, chanbuf[chan_len] | chanbuf[chan_len+1],
|
||||
icom2rig_mode(rig, chanbuf[chan_len], chanbuf[chan_len+1],
|
||||
&chan->mode, &width);
|
||||
chan_len += 2;
|
||||
chan->levels[rig_setting2idx(RIG_LEVEL_ATT)].i =
|
||||
|
@ -2294,7 +2301,7 @@ int icom_decode_event(RIG *rig)
|
|||
break;
|
||||
case C_SND_MODE:
|
||||
if (rig->callbacks.mode_event) {
|
||||
icom2rig_mode(rig, buf[5]| buf[6]<<8, &mode, &width);
|
||||
icom2rig_mode(rig, buf[5], buf[6], &mode, &width);
|
||||
return rig->callbacks.mode_event(rig, RIG_VFO_CURR,
|
||||
mode, width,
|
||||
rig->callbacks.mode_arg);
|
||||
|
@ -2420,6 +2427,7 @@ int initrigs_icom(void *be_handle)
|
|||
rig_register(&icall_caps);
|
||||
|
||||
rig_register(&os535_caps);
|
||||
rig_register(&os456_caps);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue