kopia lustrzana https://github.com/Hamlib/Hamlib
rodzic
214ddfd22f
commit
32dfa04e25
|
@ -29,11 +29,11 @@
|
|||
#include <math.h>
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
#include <serial.h>
|
||||
#include <misc.h>
|
||||
#include <cal.h>
|
||||
#include <token.h>
|
||||
#include <register.h>
|
||||
#include "serial.h"
|
||||
#include "misc.h"
|
||||
#include "cal.h"
|
||||
#include "token.h"
|
||||
#include "register.h"
|
||||
|
||||
#include "barrett.h"
|
||||
|
||||
|
@ -53,11 +53,19 @@ static int barrett_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
|
|||
static int barrett_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt);
|
||||
static int barrett_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
|
||||
static int barrett_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
|
||||
static int barrett_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
|
||||
static int barrett_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode,
|
||||
pbwidth_t *width);
|
||||
|
||||
static int barrett_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq);
|
||||
static int barrett_set_split_vfo(RIG *rig, vfo_t rxvfo, split_t split, vfo_t txvfo);
|
||||
static int barrett_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo);
|
||||
static int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
|
||||
static int barrett_set_split_vfo(RIG *rig, vfo_t rxvfo, split_t split,
|
||||
vfo_t txvfo);
|
||||
|
||||
static int barrett_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split,
|
||||
vfo_t *txvfo);
|
||||
|
||||
static int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level,
|
||||
value_t *val);
|
||||
|
||||
static const char * barrett_get_info(RIG *rig);
|
||||
|
||||
|
||||
|
@ -228,8 +236,10 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result)
|
|||
|
||||
if (expected == 0) {
|
||||
// response format is 0x11,data...,0x0d,0x0a,0x13
|
||||
retval = read_string(&rs->rigport, priv->ret_data, sizeof(priv->ret_data), "\x11", 1);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: resultlen=%d\n", __FUNCTION__, strlen(priv->ret_data));
|
||||
retval = read_string(&rs->rigport, priv->ret_data, sizeof(priv->ret_data),
|
||||
"\x11", 1);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: resultlen=%d\n", __FUNCTION__,
|
||||
strlen(priv->ret_data));
|
||||
|
||||
if (retval < 0) {
|
||||
return retval;
|
||||
|
@ -252,14 +262,18 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result)
|
|||
rig_debug(RIG_DEBUG_ERR, "%s: removing xoff char\n", __FUNCTION__);
|
||||
p[strlen(p) - 1] = 0;
|
||||
} else {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: expected XOFF=0x13 as first and XON=0x11 as last byte, got %02x/%02x\n", __FUNCTION__, xon, xoff);
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: expected XOFF=0x13 as first and XON=0x11 as last byte, got %02x/%02x\n",
|
||||
__FUNCTION__, xon, xoff);
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: removing xon char\n", __FUNCTION__);
|
||||
// Remove the XON char if there
|
||||
p = memchr(priv->ret_data, 0x11, strlen(priv->ret_data));
|
||||
|
||||
if (p) { *p = 0; }
|
||||
if (p) {
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -267,25 +281,31 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result)
|
|||
|
||||
if (result != NULL) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: setting result\n", __FUNCTION__);
|
||||
|
||||
if (priv->ret_data[0] == 0x13) { // we'll return from the 1st good char
|
||||
*result = &(priv->ret_data[1]);
|
||||
}
|
||||
else { // some commands like IAL don't give XOFF but XON is there -- is this a bug?
|
||||
} else { // some commands like IAL don't give XOFF but XON is there -- is this a bug?
|
||||
*result = &(priv->ret_data[0]);
|
||||
}
|
||||
|
||||
// See how many CR's we have
|
||||
int n = 0;
|
||||
|
||||
for (p = *result; *p; ++p) {
|
||||
if (*p == 0x0d) { ++n; }
|
||||
if (*p == 0x0d) {
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
// if only 1 CR then we'll truncate string
|
||||
// Several commands can return multiline strings and we'll leave them alone
|
||||
if (n == 1) { strtok(*result, "\r"); }
|
||||
if (n == 1) {
|
||||
strtok(*result, "\r");
|
||||
}
|
||||
|
||||
dump_hex((const unsigned char *)*result, strlen(*result));
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: returning result=%s\n", __FUNCTION__, *result);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: returning result=%s\n", __FUNCTION__,
|
||||
*result);
|
||||
} else {
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: no result requested=%s\n", __FUNCTION__);
|
||||
}
|
||||
|
@ -293,10 +313,12 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
int barrett_init(RIG *rig)
|
||||
{
|
||||
struct barrett_priv_data *priv;
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __FUNCTION__, rig->caps->version);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __FUNCTION__,
|
||||
rig->caps->version);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
return -RIG_EINVAL;
|
||||
|
@ -313,6 +335,7 @@ int barrett_init(RIG *rig)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_cleanup
|
||||
*
|
||||
|
@ -371,6 +394,7 @@ int barrett_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_set_freq
|
||||
* assumes rig!=NULL, rig->state.priv!=NULL
|
||||
|
@ -381,7 +405,8 @@ int barrett_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
|||
int retval;
|
||||
struct barrett_priv_data *priv = rig->state.priv;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%.0f\n", __FUNCTION__, rig_strvfo(vfo), freq);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%.0f\n", __FUNCTION__,
|
||||
rig_strvfo(vfo), freq);
|
||||
|
||||
// If we are not explicity asking for VFO_B then we'll set the receive side also
|
||||
if (vfo != RIG_VFO_B) {
|
||||
|
@ -401,7 +426,9 @@ int barrett_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
|||
}
|
||||
}
|
||||
|
||||
if (priv->split == 0 || vfo == RIG_VFO_B) { // if we aren't in split mode we have to set the TX VFO too
|
||||
if (priv->split == 0
|
||||
|| vfo == RIG_VFO_B) { // if we aren't in split mode we have to set the TX VFO too
|
||||
|
||||
sprintf((char *) cmd_buf, "PT%08.0f", freq);
|
||||
char *response = NULL;
|
||||
retval = barrett_transaction(rig, cmd_buf, 0, &response);
|
||||
|
@ -454,6 +481,7 @@ int barrett_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_get_ptt
|
||||
* Assumes rig!=NULL
|
||||
|
@ -484,6 +512,7 @@ int barrett_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_set_mode
|
||||
* Assumes rig!=NULL
|
||||
|
@ -496,7 +525,8 @@ int barrett_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
|||
|
||||
//struct tt588_priv_data *priv = (struct tt588_priv_data *) rig->state.priv;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s mode=%d width=%d\n", __FUNCTION__, rig_strvfo(vfo), mode, width);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s mode=%d width=%d\n", __FUNCTION__,
|
||||
rig_strvfo(vfo), mode, width);
|
||||
|
||||
switch (mode) {
|
||||
case RIG_MODE_USB:
|
||||
|
@ -535,6 +565,7 @@ int barrett_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_get_mode
|
||||
* Assumes rig!=NULL
|
||||
|
@ -575,30 +606,37 @@ int barrett_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
|||
break;
|
||||
|
||||
default:
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Unknown mode='%c%c'\n", __FUNCTION__, result[0], result[1]);
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Unknown mode='%c%c'\n", __FUNCTION__, result[0],
|
||||
result[1]);
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
*width = 3000; // we'll default this to 3000 for now
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s mode=%s width=%d\n", __FUNCTION__, rig_strvfo(vfo), rig_strrmode(*mode), *width);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s mode=%s width=%d\n", __FUNCTION__,
|
||||
rig_strvfo(vfo), rig_strrmode(*mode), *width);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
int barrett_get_vfo(RIG *rig, vfo_t *vfo)
|
||||
{
|
||||
*vfo = RIG_VFO_A;
|
||||
|
||||
if (check_vfo(*vfo) == FALSE) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", __FUNCTION__, rig_strvfo(*vfo));
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", __FUNCTION__,
|
||||
rig_strvfo(*vfo));
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __FUNCTION__, rig_strvfo(*vfo));
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* barrett_set_split_freq
|
||||
*/
|
||||
|
@ -607,7 +645,8 @@ int barrett_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq)
|
|||
// The 2050 only has one RX and one TX VFO -- it's not treated as VFOA/VFOB
|
||||
char cmd_buf[MAXCMDLEN];
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%g\n", __FUNCTION__, rig_strvfo(vfo), tx_freq);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%g\n", __FUNCTION__,
|
||||
rig_strvfo(vfo), tx_freq);
|
||||
|
||||
sprintf((char *) cmd_buf, "PT%08.0f" EOM, tx_freq);
|
||||
|
||||
|
@ -620,17 +659,21 @@ int barrett_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
int barrett_set_split_vfo(RIG *rig, vfo_t rxvfo, split_t split, vfo_t txvfo)
|
||||
{
|
||||
struct barrett_priv_data *priv;
|
||||
|
||||
priv = rig->state.priv;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called rxvfo=%s, txvfo=%s, split=%d\n", __FUNCTION__, rig_strvfo(rxvfo), rig_strvfo(txvfo), split);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called rxvfo=%s, txvfo=%s, split=%d\n",
|
||||
__FUNCTION__, rig_strvfo(rxvfo), rig_strvfo(txvfo), split);
|
||||
priv->split = split;
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
int barrett_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo)
|
||||
{
|
||||
struct barrett_priv_data *priv;
|
||||
|
@ -639,10 +682,13 @@ int barrett_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo)
|
|||
|
||||
*split = priv->split;
|
||||
*txvfo = RIG_VFO_B; // constant
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called rxvfo=%s, txvfo=%s, split=%d\n", __FUNCTION__, rig_strvfo(rxvfo), rig_strvfo(*txvfo), *split);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called rxvfo=%s, txvfo=%s, split=%d\n",
|
||||
__FUNCTION__, rig_strvfo(rxvfo), rig_strvfo(*txvfo), *split);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_get_level
|
||||
*/
|
||||
|
@ -656,19 +702,22 @@ int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|||
retval = barrett_transaction(rig, "IAL", 0, &response);
|
||||
|
||||
if (retval < 0) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: invalid response=%s\n", __FUNCTION__, level);
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: invalid response=%s\n", __FUNCTION__,
|
||||
level);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int strength;
|
||||
int n = sscanf(response, "%2d", &strength);
|
||||
|
||||
if (n == 1) {
|
||||
val->i = strength;
|
||||
}
|
||||
else {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: unable to parse STRENGHT from %s\n", __FUNCTION__, response);
|
||||
} else {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: unable to parse STRENGHT from %s\n",
|
||||
__FUNCTION__, response);
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -676,11 +725,13 @@ int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s level=%d val=%d\n", __FUNCTION__, rig_strvfo(vfo), level, *val);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s level=%d val=%d\n", __FUNCTION__,
|
||||
rig_strvfo(vfo), level, *val);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* barrett_get_info
|
||||
*/
|
||||
|
@ -693,7 +744,8 @@ const char *barrett_get_info(RIG *rig)
|
|||
int retval = barrett_transaction(rig, "IVF", 0, &response);
|
||||
|
||||
if (retval == RIG_OK) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: result=%s\n", __FUNCTION__, response, strlen(response));
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: result=%s\n", __FUNCTION__, response,
|
||||
strlen(response));
|
||||
} else {
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Software Version %s\n", response);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue