kopia lustrzana https://github.com/Hamlib/Hamlib
applied astyle on thd74.c
rodzic
c907a512c8
commit
d06e4c306f
185
kenwood/thd74.c
185
kenwood/thd74.c
|
@ -62,7 +62,8 @@
|
|||
*/
|
||||
#define THD74_VFO (RIG_VFO_A|RIG_VFO_B)
|
||||
|
||||
static rmode_t td74_mode_table[KENWOOD_MODE_TABLE_MAX] = {
|
||||
static rmode_t td74_mode_table[KENWOOD_MODE_TABLE_MAX] =
|
||||
{
|
||||
[0] = RIG_MODE_FM,
|
||||
[1] = RIG_MODE_DR,
|
||||
[2] = RIG_MODE_AM,
|
||||
|
@ -75,7 +76,8 @@ static rmode_t td74_mode_table[KENWOOD_MODE_TABLE_MAX] = {
|
|||
[9] = RIG_MODE_CWR,
|
||||
};
|
||||
|
||||
static struct kenwood_priv_caps thd74_priv_caps = {
|
||||
static struct kenwood_priv_caps thd74_priv_caps =
|
||||
{
|
||||
.cmdtrm = EOM_TH, /* Command termination character */
|
||||
.mode_table = td74_mode_table,
|
||||
};
|
||||
|
@ -93,7 +95,8 @@ static int thd74_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt);
|
|||
/*
|
||||
* th-d72a rig capabilities.
|
||||
*/
|
||||
const struct rig_caps thd74_caps = {
|
||||
const struct rig_caps thd74_caps =
|
||||
{
|
||||
.rig_model = RIG_MODEL_THD74,
|
||||
.model_name = "TH-D74",
|
||||
.mfg_name = "Kenwood",
|
||||
|
@ -216,30 +219,38 @@ const struct rig_caps thd74_caps = {
|
|||
#define BLOCK_SZ 256
|
||||
#define BLOCK_COUNT 256
|
||||
|
||||
static char thd74_get_vfo_letter(RIG *rig, vfo_t vfo){
|
||||
static char thd74_get_vfo_letter(RIG *rig, vfo_t vfo)
|
||||
{
|
||||
unsigned char vfo_letter;
|
||||
vfo_t tvfo;
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
||||
|
||||
tvfo = (vfo==RIG_VFO_CURR || vfo==RIG_VFO_VFO) ? rig->state.current_vfo : vfo;
|
||||
switch (tvfo) {
|
||||
tvfo = (vfo == RIG_VFO_CURR
|
||||
|| vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo;
|
||||
|
||||
switch (tvfo)
|
||||
{
|
||||
case RIG_VFO_A:
|
||||
case RIG_VFO_MAIN:
|
||||
vfo_letter = '0';
|
||||
break;
|
||||
|
||||
case RIG_VFO_B:
|
||||
case RIG_VFO_SUB:
|
||||
vfo_letter = '1';
|
||||
break;
|
||||
|
||||
default:
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
return vfo_letter;
|
||||
}
|
||||
|
||||
static int thd74_get_block (RIG *rig, int block_num, char *block) {
|
||||
static int thd74_get_block(RIG *rig, int block_num, char *block)
|
||||
{
|
||||
hamlib_port_t *rp = &rig->state.rigport;
|
||||
char cmd[CMD_SZ] = "R\0\0\0\0";
|
||||
char resp[CMD_SZ];
|
||||
|
@ -249,37 +260,57 @@ static int thd74_get_block (RIG *rig, int block_num, char *block) {
|
|||
cmd[2] = block_num & 0xff;
|
||||
|
||||
ret = write_block(rp, cmd, CMD_SZ);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* read response first */
|
||||
ret = read_block(rp, resp, CMD_SZ);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (resp[0] != 'W' || memcmp(cmd + 1, resp + 1, CMD_SZ - 1))
|
||||
{
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
/* read block */
|
||||
ret = read_block(rp, block, BLOCK_SZ);
|
||||
|
||||
if (ret != BLOCK_SZ)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = write_block(rp, "\006", 1);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = read_block(rp, resp, 1);
|
||||
|
||||
if (ret != 1)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (resp[0] != 0x06)
|
||||
{
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
int thd74_get_chan_all_cb (RIG * rig, chan_cb_t chan_cb, rig_ptr_t arg) {
|
||||
int thd74_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
|
||||
{
|
||||
int i, j, ret;
|
||||
hamlib_port_t *rp = &rig->state.rigport;
|
||||
channel_t *chan;
|
||||
|
@ -289,8 +320,11 @@ int thd74_get_chan_all_cb (RIG * rig, chan_cb_t chan_cb, rig_ptr_t arg) {
|
|||
char resp[CMD_SZ];
|
||||
|
||||
ret = kenwood_transaction(rig, "0M PROGRAM", NULL, 0);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
rp->parm.serial.rate = 57600;
|
||||
|
||||
|
@ -302,8 +336,11 @@ int thd74_get_chan_all_cb (RIG * rig, chan_cb_t chan_cb, rig_ptr_t arg) {
|
|||
|
||||
/* setRTS or Hardware flow control? */
|
||||
ret = ser_set_rts(rp, 1);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* setting chan to NULL means the application
|
||||
|
@ -312,24 +349,35 @@ int thd74_get_chan_all_cb (RIG * rig, chan_cb_t chan_cb, rig_ptr_t arg) {
|
|||
*/
|
||||
chan = NULL;
|
||||
ret = chan_cb(rig, &chan, chan_next, chan_list, arg);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (chan == NULL)
|
||||
{
|
||||
return -RIG_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<BLOCK_COUNT; i++) {
|
||||
for (i = 0; i < BLOCK_COUNT; i++)
|
||||
{
|
||||
|
||||
ret = thd74_get_block(rig, i, block);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Most probably, there's 64 bytes per channel (256*256 / 1000+)
|
||||
*/
|
||||
#define CHAN_PER_BLOCK 4
|
||||
|
||||
for (j=0; j<CHAN_PER_BLOCK; j++) {
|
||||
for (j = 0; j < CHAN_PER_BLOCK; j++)
|
||||
{
|
||||
|
||||
char *block_chan = block + j * (BLOCK_SZ / CHAN_PER_BLOCK);
|
||||
|
||||
|
@ -339,12 +387,15 @@ int thd74_get_chan_all_cb (RIG * rig, chan_cb_t chan_cb, rig_ptr_t arg) {
|
|||
|
||||
/* What are the extra 64 channels ? */
|
||||
if (chan->channel_num >= 1000)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* non-empty channel ? */
|
||||
// if (block_chan[0] != 0xff) {
|
||||
// since block_chan is *signed* char, this maps to -1
|
||||
if (block_chan[0] != -1) {
|
||||
if (block_chan[0] != -1)
|
||||
{
|
||||
|
||||
memcpy(chan->channel_desc, block_chan, 8);
|
||||
/* TODO: chop off trailing chars */
|
||||
|
@ -365,21 +416,31 @@ int thd74_get_chan_all_cb (RIG * rig, chan_cb_t chan_cb, rig_ptr_t arg) {
|
|||
}
|
||||
|
||||
ret = write_block(rp, "E", 1);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = read_block(rp, resp, 1);
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
|
||||
if (resp[0] != 0x06) {
|
||||
if (ret != 1)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (resp[0] != 0x06)
|
||||
{
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
/* setRTS?? getCTS needed? */
|
||||
ret = ser_set_rts(rp, 1);
|
||||
|
||||
if (ret != RIG_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -393,7 +454,9 @@ int thd74_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !freq)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
char freqbuf[50];
|
||||
char cmdbuf[5];
|
||||
|
@ -401,16 +464,20 @@ int thd74_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
unsigned char vfo_letter;
|
||||
vfo_t tvfo;
|
||||
|
||||
tvfo = (vfo == RIG_VFO_CURR || vfo==RIG_VFO_VFO) ? rig->state.current_vfo : vfo;
|
||||
tvfo = (vfo == RIG_VFO_CURR
|
||||
|| vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo;
|
||||
|
||||
if (RIG_VFO_CURR == tvfo) {
|
||||
if (RIG_VFO_CURR == tvfo)
|
||||
{
|
||||
/* fetch from rig */
|
||||
retval = rig_get_vfo(rig, &tvfo);
|
||||
if (RIG_OK != retval) return retval;
|
||||
|
||||
if (RIG_OK != retval) { return retval; }
|
||||
}
|
||||
|
||||
/* memory frequency cannot be read with an Fx command, use IF */
|
||||
if (tvfo == RIG_VFO_MEM) {
|
||||
if (tvfo == RIG_VFO_MEM)
|
||||
{
|
||||
|
||||
return kenwood_get_freq_if(rig, vfo, freq);
|
||||
}
|
||||
|
@ -421,8 +488,11 @@ int thd74_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
rig_debug(RIG_DEBUG_ERR, "%s: cmd: %s\n", __func__, cmdbuf);
|
||||
|
||||
retval = kenwood_safe_transaction(rig, cmdbuf, freqbuf, 50, 15);
|
||||
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: response is %s\n", __func__, freqbuf);
|
||||
sscanf(freqbuf, "FQ %d,%10"SCNfreq, &retval, freq);
|
||||
|
@ -433,23 +503,29 @@ int thd74_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
/*
|
||||
* thd74_set_freq
|
||||
*/
|
||||
int thd74_set_freq(RIG *rig, vfo_t vfo, freq_t freq) {
|
||||
int thd74_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
char freqbuf[16], replybuf[16];
|
||||
unsigned char vfo_letter;
|
||||
int err;
|
||||
vfo_t tvfo;
|
||||
|
||||
tvfo = (vfo == RIG_VFO_CURR || vfo==RIG_VFO_VFO) ? rig->state.current_vfo : vfo;
|
||||
tvfo = (vfo == RIG_VFO_CURR
|
||||
|| vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo;
|
||||
|
||||
if (RIG_VFO_CURR == tvfo) {
|
||||
if (RIG_VFO_CURR == tvfo)
|
||||
{
|
||||
/* fetch from rig */
|
||||
err = rig_get_vfo(rig, &tvfo);
|
||||
if (RIG_OK != err) return err;
|
||||
|
||||
if (RIG_OK != err) { return err; }
|
||||
}
|
||||
|
||||
vfo_letter = thd74_get_vfo_letter(rig, vfo);
|
||||
|
@ -466,46 +542,61 @@ int thd74_set_freq(RIG *rig, vfo_t vfo, freq_t freq) {
|
|||
* thd74_get_mode
|
||||
* Assumes rig!=NULL, mode!=NULL
|
||||
*/
|
||||
int thd74_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) {
|
||||
int thd74_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||
{
|
||||
char buf[64];
|
||||
char modebuf[8];
|
||||
int retval;
|
||||
const struct kenwood_priv_caps *priv=(const struct kenwood_priv_caps *)rig->caps->priv;
|
||||
const struct kenwood_priv_caps *priv = (const struct kenwood_priv_caps *)
|
||||
rig->caps->priv;
|
||||
unsigned char vfo_letter;
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
||||
|
||||
if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo)
|
||||
{
|
||||
return kenwood_wrong_vfo(__func__, vfo);
|
||||
}
|
||||
|
||||
vfo_letter = thd74_get_vfo_letter(rig, vfo);
|
||||
|
||||
snprintf(modebuf, sizeof(modebuf), "MD %c", vfo_letter);
|
||||
retval = kenwood_safe_transaction(rig, modebuf, buf, sizeof(buf), 6);
|
||||
|
||||
//retval = kenwood_safe_transaction(rig, modebuf, buf, sizeof(buf), 0);
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: buf%s\n", __func__, buf);
|
||||
if (buf[5] < '0' || buf[5] > '9') {
|
||||
|
||||
if (buf[5] < '0' || buf[5] > '9')
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, buf);
|
||||
return -RIG_ERJCTED;
|
||||
}
|
||||
|
||||
if (priv->mode_table) {
|
||||
if (priv->mode_table)
|
||||
{
|
||||
*mode = kenwood2rmode(buf[5] - '0', priv->mode_table);
|
||||
if (*mode == RIG_MODE_NONE) {
|
||||
|
||||
if (*mode == RIG_MODE_NONE)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode (table)value '%c'\n",
|
||||
__func__, buf[5]);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (width)
|
||||
{
|
||||
*width = RIG_PASSBAND_NORMAL;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -513,39 +604,59 @@ int thd74_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) {
|
|||
* th_set_mode
|
||||
* Assumes rig!=NULL
|
||||
*/
|
||||
int thd74_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) {
|
||||
int thd74_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||
{
|
||||
char kmode, mdbuf[8], replybuf[8];
|
||||
int retval;
|
||||
const struct kenwood_priv_caps *priv=(const struct kenwood_priv_caps *)rig->caps->priv;
|
||||
const struct kenwood_priv_caps *priv = (const struct kenwood_priv_caps *)
|
||||
rig->caps->priv;
|
||||
unsigned char vfo_letter;
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
||||
|
||||
if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo) // FIXME thinkabout
|
||||
{
|
||||
return kenwood_wrong_vfo(__func__, vfo);
|
||||
}
|
||||
|
||||
vfo_letter = thd74_get_vfo_letter(rig, vfo);
|
||||
|
||||
if (priv->mode_table) {
|
||||
if (priv->mode_table)
|
||||
{
|
||||
kmode = rmode2kenwood(mode, priv->mode_table);
|
||||
if (kmode == -1) {
|
||||
|
||||
if (kmode == -1)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: Unsupported Mode value '%s'\n",
|
||||
__func__, rig_strrmode(mode));
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
kmode += '0';
|
||||
} else {
|
||||
switch (mode) {
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case RIG_MODE_FM: kmode = '0'; break;
|
||||
|
||||
case RIG_MODE_AM: kmode = '1'; break;
|
||||
|
||||
// case RIG_MODE_AM: kmode = '2'; break; // FIXME
|
||||
case RIG_MODE_LSB: kmode = '3'; break;
|
||||
|
||||
case RIG_MODE_USB: kmode = '4'; break;
|
||||
|
||||
case RIG_MODE_CW: kmode = '5'; break;
|
||||
|
||||
case RIG_MODE_FMN: kmode = '6'; break;
|
||||
|
||||
case RIG_MODE_DR: kmode = '7'; break;
|
||||
|
||||
case RIG_MODE_WFM: kmode = '8'; break;
|
||||
|
||||
case RIG_MODE_CWR: kmode = '9'; break;
|
||||
|
||||
default:
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode %d\n", __func__, mode);
|
||||
return -RIG_EINVAL;
|
||||
|
@ -557,13 +668,17 @@ int thd74_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) {
|
|||
|
||||
retval = kenwood_transaction(rig, mdbuf, replybuf, 7);
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: retval: %d\n", __func__, retval);
|
||||
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
static int thd74_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) {
|
||||
static int thd74_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
|
||||
{
|
||||
char buf[6];
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
||||
return kenwood_transaction(rig, (ptt == RIG_PTT_ON) ? "TX" : "RX", buf, 5);
|
||||
|
|
Ładowanie…
Reference in New Issue