Reformatted src directory

pull/1/head
Nate Bargmann 2017-08-05 09:09:12 -05:00
rodzic 01bef2d158
commit f76b354588
31 zmienionych plików z 9584 dodań i 7142 usunięć

Wyświetl plik

@ -39,6 +39,7 @@
/* add rig_set_cal(cal_table), rig_get_calstat(rawmin,rawmax,cal_table), */ /* add rig_set_cal(cal_table), rig_get_calstat(rawmin,rawmax,cal_table), */
/** /**
* \brief Convert raw S-meter data to calibated value, according to table * \brief Convert raw S-meter data to calibated value, according to table
* \param rawval input value * \param rawval input value
@ -52,7 +53,6 @@
* If a value is greater or equal to cal_table_t.table[cal_table_t.size-1].raw, * If a value is greater or equal to cal_table_t.table[cal_table_t.size-1].raw,
* rig_raw2val() will return cal_table_t.table[cal_table_t.size-1].val * rig_raw2val() will return cal_table_t.table[cal_table_t.size-1].val
*/ */
float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal) float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal)
{ {
#ifdef WANT_CHEAP_WNO_FP #ifdef WANT_CHEAP_WNO_FP
@ -65,33 +65,41 @@ float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal)
/* ASSERT(cal != NULL) */ /* ASSERT(cal != NULL) */
/* ASSERT(cal->size <= MAX_CAL_LENGTH) */ /* ASSERT(cal->size <= MAX_CAL_LENGTH) */
if (cal->size == 0) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (cal->size == 0) {
return rawval; return rawval;
}
for (i = 0; i < cal->size; i++) for (i = 0; i < cal->size; i++)
if (rawval < cal->table[i].raw) if (rawval < cal->table[i].raw) {
break; break;
}
if (i==0) if (i == 0) {
return cal->table[0].val; return cal->table[0].val;
}
if (i>=cal->size) if (i >= cal->size) {
return cal->table[i - 1].val; return cal->table[i - 1].val;
}
if (cal->table[i].raw == cal->table[i-1].raw) /* catch divide by 0 error */ /* catch divide by 0 error */
if (cal->table[i].raw == cal->table[i - 1].raw) {
return cal->table[i].val; return cal->table[i].val;
}
#ifdef WANT_CHEAP_WNO_FP #ifdef WANT_CHEAP_WNO_FP
/* cheap, less accurate, but no fp needed */ /* cheap, less accurate, but no fp needed */
interpolation = ((cal->table[i].raw - rawval) * interpolation = ((cal->table[i].raw - rawval)
(cal->table[i].val - cal->table[i-1].val)) / * (cal->table[i].val - cal->table[i - 1].val))
(cal->table[i].raw - cal->table[i-1].raw); / (cal->table[i].raw - cal->table[i - 1].raw);
return cal->table[i].val - interpolation; return cal->table[i].val - interpolation;
#else #else
interpolation = ((cal->table[i].raw - rawval) * interpolation = ((cal->table[i].raw - rawval)
(float)(cal->table[i].val - cal->table[i-1].val)) / * (float)(cal->table[i].val - cal->table[i - 1].val))
(float)(cal->table[i].raw - cal->table[i-1].raw); / (float)(cal->table[i].raw - cal->table[i - 1].raw);
#endif #endif
return cal->table[i].val - interpolation; return cal->table[i].val - interpolation;
} }

Wyświetl plik

@ -65,7 +65,7 @@
#include <linux/hidraw.h> #include <linux/hidraw.h>
#endif #endif
#include "hamlib/rig.h" #include <hamlib/rig.h>
#include "cm108.h" #include "cm108.h"
@ -74,73 +74,78 @@
* \param port * \param port
* \return file descriptor * \return file descriptor
*/ */
int cm108_open(hamlib_port_t *port) int cm108_open(hamlib_port_t *port)
{ {
int fd; int fd;
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108_open called \n"); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!port->pathname[0]) {
if (!port->pathname[0])
return -RIG_EINVAL; return -RIG_EINVAL;
}
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) { if (fd < 0) {
rig_debug(RIG_DEBUG_ERR, "cm108:Opening device \"%s\": %s\n", port->pathname, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n",
__func__,
port->pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
#ifdef HAVE_LINUX_HIDRAW_H #ifdef HAVE_LINUX_HIDRAW_H
// CM108 detection copied from Thomas Sailer's soundmodem code // CM108 detection copied from Thomas Sailer's soundmodem code
rig_debug(RIG_DEBUG_VERBOSE,"cm108:Checking for cm108 (or compatible) device \n"); rig_debug(RIG_DEBUG_VERBOSE,
"%s: checking for cm108 (or compatible) device\n",
__func__);
struct hidraw_devinfo hiddevinfo; struct hidraw_devinfo hiddevinfo;
if (!ioctl(fd, HIDIOCGRAWINFO, &hiddevinfo) if (!ioctl(fd, HIDIOCGRAWINFO, &hiddevinfo)
&& && ((hiddevinfo.vendor == 0x0d8c
( // CM108/109/119/119A
(hiddevinfo.vendor == 0x0d8c && // CM108/109/119/119A && ((hiddevinfo.product >= 0x0008
((hiddevinfo.product >= 0x0008 && && hiddevinfo.product <= 0x000f)
hiddevinfo.product <= 0x000f) || || hiddevinfo.product == 0x013a))
hiddevinfo.product == 0x013a) // SSS1621/23
) || (hiddevinfo.vendor == 0x0c76
|| && (hiddevinfo.product == 0x1605
(hiddevinfo.vendor == 0x0c76 && // SSS1621/23 || hiddevinfo.product == 0x1607
(hiddevinfo.product == 0x1605 || || hiddevinfo.product == 0x160b))))
hiddevinfo.product == 0x1607 ||
hiddevinfo.product == 0x160b)
)
)
)
{
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108 compatible device detected \n");
}
else
{ {
rig_debug(RIG_DEBUG_VERBOSE,
"%s: cm108 compatible device detected\n",
__func__);
} else {
close(fd); close(fd);
rig_debug(RIG_DEBUG_VERBOSE,"cm108:No cm108 (or compatible) device detected \n"); rig_debug(RIG_DEBUG_VERBOSE,
"%s: no cm108 (or compatible) device detected\n",
__func__);
return -RIG_EINVAL; return -RIG_EINVAL;
} }
#endif #endif
port->fd = fd; port->fd = fd;
return fd; return fd;
} }
/** /**
* \brief Close CM108 HID port * \brief Close CM108 HID port
* \param port * \param port
*/ */
int cm108_close(hamlib_port_t *port) int cm108_close(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108_close called \n"); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return close(port->fd); return close(port->fd);
} }
/** /**
* \brief Set or unset Push to talk bit on CM108 GPIO * \brief Set or unset Push to talk bit on CM108 GPIO
* \param p * \param p
@ -149,8 +154,7 @@ int cm108_close(hamlib_port_t *port)
*/ */
int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108_ptt_set called \n");
// For a CM108 USB audio device PTT is wired up to one of the GPIO // For a CM108 USB audio device PTT is wired up to one of the GPIO
// pins. Usually this is GPIO3 (bit 2 of the GPIO register) because it // pins. Usually this is GPIO3 (bit 2 of the GPIO register) because it
@ -160,8 +164,7 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
// we make the GPIO bit number configurable. // we make the GPIO bit number configurable.
switch (p->type.ptt) { switch (p->type.ptt) {
case RIG_PTT_CM108: case RIG_PTT_CM108: {
{
// Build a packet for CM108 HID to turn GPIO bit on or off. // Build a packet for CM108 HID to turn GPIO bit on or off.
// Packet is 4 bytes, preceded by a 'report number' byte // Packet is 4 bytes, preceded by a 'report number' byte
@ -172,8 +175,11 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
// byte 2: xxxx dcba GPIO3-0 data-direction register (1=output) // byte 2: xxxx dcba GPIO3-0 data-direction register (1=output)
// byte 3: xxxx xxxx SPDIF // byte 3: xxxx xxxx SPDIF
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108_ptt_set bit number %d to state %d\n", rig_debug(RIG_DEBUG_VERBOSE,
p->parm.cm108.ptt_bitnum, (pttx == RIG_PTT_ON) ? 1 : 0); "%s: bit number %d to state %d\n",
__func__,
p->parm.cm108.ptt_bitnum,
(pttx == RIG_PTT_ON) ? 1 : 0);
char out_rep[] = { char out_rep[] = {
0x00, // report number 0x00, // report number
@ -186,25 +192,32 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
ssize_t nw; ssize_t nw;
if (p->fd == -1) if (p->fd == -1) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
// Send the HID packet // Send the HID packet
nw = write(p->fd, out_rep, sizeof(out_rep)); nw = write(p->fd, out_rep, sizeof(out_rep));
if (nw < 0) { if (nw < 0) {
return -RIG_EIO; return -RIG_EIO;
} }
return RIG_OK; return RIG_OK;
} }
default: default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR,
"%s: unsupported PTT type %d\n",
__func__,
p->type.ptt); p->type.ptt);
return -RIG_EINVAL; return -RIG_EINVAL;
} }
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Get state of Push to Talk from CM108 GPIO * \brief Get state of Push to Talk from CM108 GPIO
* \param p * \param p
@ -213,20 +226,23 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
*/ */
int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx) int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108_ptt_get called \n"); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) { switch (p->type.ptt) {
case RIG_PTT_CM108: case RIG_PTT_CM108: {
{
int status; int status;
return -RIG_ENIMPL; return -RIG_ENIMPL;
return status; return status;
} }
default: default:
rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR,
"%s: unsupported PTT type %d\n",
__func__,
p->type.ptt); p->type.ptt);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
return RIG_OK; return RIG_OK;
} }
@ -238,7 +254,7 @@ int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx)
*/ */
int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx) int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
{ {
rig_debug(RIG_DEBUG_VERBOSE,"cm108:cm108_dcd_get called \n"); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
// On the CM108 and compatible chips the squelch line on the radio is // On the CM108 and compatible chips the squelch line on the radio is
// wired to Volume Down input pin. The state of this pin is reported // wired to Volume Down input pin. The state of this pin is reported
@ -246,17 +262,20 @@ int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
// to query this state on demand. // to query this state on demand.
switch (p->type.dcd) { switch (p->type.dcd) {
case RIG_DCD_CM108: case RIG_DCD_CM108: {
{
int status; int status;
return -RIG_ENIMPL; return -RIG_ENIMPL;
return status; return status;
} }
default: default:
rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n", rig_debug(RIG_DEBUG_ERR,
"%s: unsupported DCD type %d\n",
__func__,
p->type.dcd); p->type.dcd);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
return RIG_OK; return RIG_OK;
} }

Wyświetl plik

@ -36,12 +36,23 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx);
int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx); int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx);
int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx); int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx);
extern HAMLIB_EXPORT(int) cm108_write_data(hamlib_port_t *p, unsigned char data); extern HAMLIB_EXPORT(int) cm108_write_data(hamlib_port_t *p,
extern HAMLIB_EXPORT(int) cm108_write_control(hamlib_port_t *p, unsigned char control); unsigned char data);
extern HAMLIB_EXPORT(int) cm108_read_data(hamlib_port_t *p, unsigned char *data);
extern HAMLIB_EXPORT(int) cm108_read_control(hamlib_port_t *p, unsigned char *control); extern HAMLIB_EXPORT(int) cm108_write_control(hamlib_port_t *p,
extern HAMLIB_EXPORT(int) cm108_read_status(hamlib_port_t *p, unsigned char *status); unsigned char control);
extern HAMLIB_EXPORT(int) cm108_read_data(hamlib_port_t *p,
unsigned char *data);
extern HAMLIB_EXPORT(int) cm108_read_control(hamlib_port_t *p,
unsigned char *control);
extern HAMLIB_EXPORT(int) cm108_read_status(hamlib_port_t *p,
unsigned char *status);
extern HAMLIB_EXPORT(int) cm108_lock(hamlib_port_t *p); extern HAMLIB_EXPORT(int) cm108_lock(hamlib_port_t *p);
extern HAMLIB_EXPORT(int) cm108_unlock(hamlib_port_t *p); extern HAMLIB_EXPORT(int) cm108_unlock(hamlib_port_t *p);
__END_DECLS __END_DECLS

Wyświetl plik

@ -43,58 +43,72 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#include "token.h" #include "token.h"
/* /*
* Configuration options available in the rig->state struct. * Configuration options available in the rig->state struct.
*/ */
static const struct confparams frontend_cfg_params[] = { static const struct confparams frontend_cfg_params[] = {
{ TOK_PATHNAME, "rig_pathname", "Rig path name", {
TOK_PATHNAME, "rig_pathname", "Rig path name",
"Path name to the device file of the rig", "Path name to the device file of the rig",
"/dev/rig", RIG_CONF_STRING, "/dev/rig", RIG_CONF_STRING,
}, },
{ TOK_WRITE_DELAY, "write_delay", "Write delay", {
TOK_WRITE_DELAY, "write_delay", "Write delay",
"Delay in ms between each byte sent out", "Delay in ms between each byte sent out",
"0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } }
}, },
{ TOK_POST_WRITE_DELAY, "post_write_delay", "Post write delay", {
TOK_POST_WRITE_DELAY, "post_write_delay", "Post write delay",
"Delay in ms between each command sent out", "Delay in ms between each command sent out",
"0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } }
}, },
{ TOK_TIMEOUT, "timeout", "Timeout", "Timeout in ms", {
TOK_TIMEOUT, "timeout", "Timeout", "Timeout in ms",
"0", RIG_CONF_NUMERIC, { .n = { 0, 10000, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 10000, 1 } }
}, },
{ TOK_RETRY, "retry", "Retry", "Max number of retry", {
TOK_RETRY, "retry", "Retry", "Max number of retry",
"0", RIG_CONF_NUMERIC, { .n = { 0, 10, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 10, 1 } }
}, },
{ TOK_ITU_REGION, "itu_region", "ITU region", {
TOK_ITU_REGION, "itu_region", "ITU region",
"ITU region this rig has been manufactured for (freq. band plan)", "ITU region this rig has been manufactured for (freq. band plan)",
"0", RIG_CONF_NUMERIC, { .n = { 1, 3, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 1, 3, 1 } }
}, },
{ TOK_VFO_COMP, "vfo_comp", "VFO compensation", {
TOK_VFO_COMP, "vfo_comp", "VFO compensation",
"VFO compensation in ppm", "VFO compensation in ppm",
"0", RIG_CONF_NUMERIC, { .n = { 0.0, 1000.0, .001 } } "0", RIG_CONF_NUMERIC, { .n = { 0.0, 1000.0, .001 } }
}, },
{ TOK_POLL_INTERVAL, "poll_interval", "Polling interval", {
TOK_POLL_INTERVAL, "poll_interval", "Polling interval",
"Polling interval in millisecond for transceive emulation", "Polling interval in millisecond for transceive emulation",
"500", RIG_CONF_NUMERIC, { .n = { 0, 1000000, 1 } } "500", RIG_CONF_NUMERIC, { .n = { 0, 1000000, 1 } }
}, },
{ TOK_PTT_TYPE, "ptt_type", "PTT type", {
TOK_PTT_TYPE, "ptt_type", "PTT type",
"Push-To-Talk interface type override", "Push-To-Talk interface type override",
"RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DTR", "RTS", "Parallel", "CM108", "None", NULL }} } "RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DTR", "RTS", "Parallel", "CM108", "None", NULL }} }
}, },
{ TOK_PTT_PATHNAME, "ptt_pathname", "PTT path name", {
TOK_PTT_PATHNAME, "ptt_pathname", "PTT path name",
"Path name to the device file of the Push-To-Talk", "Path name to the device file of the Push-To-Talk",
"/dev/rig", RIG_CONF_STRING, "/dev/rig", RIG_CONF_STRING,
}, },
{ TOK_PTT_BITNUM, "ptt_bitnum", "PTT bit [0-7]", {
TOK_PTT_BITNUM, "ptt_bitnum", "PTT bit [0-7]",
"Push-To-Talk GPIO bit number", "Push-To-Talk GPIO bit number",
"2", RIG_CONF_NUMERIC, { .n = { 0, 7, 1 } } "2", RIG_CONF_NUMERIC, { .n = { 0, 7, 1 } }
}, },
{ TOK_DCD_TYPE, "dcd_type", "DCD type", {
TOK_DCD_TYPE, "dcd_type", "DCD type",
"Data Carrier Detect (or squelch) interface type override", "Data Carrier Detect (or squelch) interface type override",
"RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DSR", "CTS", "CD", "Parallel", "CM108", "None", NULL }} } "RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DSR", "CTS", "CD", "Parallel", "CM108", "None", NULL }} }
}, },
{ TOK_DCD_PATHNAME, "dcd_pathname", "DCD path name", {
TOK_DCD_PATHNAME, "dcd_pathname", "DCD path name",
"Path name to the device file of the Data Carrier Detect (or squelch)", "Path name to the device file of the Data Carrier Detect (or squelch)",
"/dev/rig", RIG_CONF_STRING, "/dev/rig", RIG_CONF_STRING,
}, },
@ -104,32 +118,39 @@ static const struct confparams frontend_cfg_params[] = {
static const struct confparams frontend_serial_cfg_params[] = { static const struct confparams frontend_serial_cfg_params[] = {
{ TOK_SERIAL_SPEED, "serial_speed", "Serial speed", {
TOK_SERIAL_SPEED, "serial_speed", "Serial speed",
"Serial port baud rate", "Serial port baud rate",
"0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } }
}, },
{ TOK_DATA_BITS, "data_bits", "Serial data bits", {
TOK_DATA_BITS, "data_bits", "Serial data bits",
"Serial port data bits", "Serial port data bits",
"8", RIG_CONF_NUMERIC, { .n = { 5, 8, 1 } } "8", RIG_CONF_NUMERIC, { .n = { 5, 8, 1 } }
}, },
{ TOK_STOP_BITS, "stop_bits", "Serial stop bits", {
TOK_STOP_BITS, "stop_bits", "Serial stop bits",
"Serial port stop bits", "Serial port stop bits",
"1", RIG_CONF_NUMERIC, { .n = { 0, 3, 1 } } "1", RIG_CONF_NUMERIC, { .n = { 0, 3, 1 } }
}, },
{ TOK_PARITY, "serial_parity", "Serial parity", {
TOK_PARITY, "serial_parity", "Serial parity",
"Serial port parity", "Serial port parity",
"None", RIG_CONF_COMBO, { .c = {{ "None", "Odd", "Even", "Mark", "Space", NULL }} } "None", RIG_CONF_COMBO, { .c = {{ "None", "Odd", "Even", "Mark", "Space", NULL }} }
}, },
{ TOK_HANDSHAKE, "serial_handshake", "Serial handshake", {
TOK_HANDSHAKE, "serial_handshake", "Serial handshake",
"Serial port handshake", "Serial port handshake",
"None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} } "None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} }
}, },
{ TOK_RTS_STATE, "rts_state", "RTS state", {
TOK_RTS_STATE, "rts_state", "RTS state",
"Serial port set state of RTS signal for external powering", "Serial port set state of RTS signal for external powering",
"Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} }
}, },
{ TOK_DTR_STATE, "dtr_state", "DTR state", {
TOK_DTR_STATE, "dtr_state", "DTR state",
"Serial port set state of DTR signal for external powering", "Serial port set state of DTR signal for external powering",
"Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} }
}, },
@ -137,6 +158,7 @@ static const struct confparams frontend_serial_cfg_params[] = {
{ RIG_CONF_END, NULL, } { RIG_CONF_END, NULL, }
}; };
/* /*
* frontend_set_conf * frontend_set_conf
* assumes rig!=NULL, val!=NULL * assumes rig!=NULL, val!=NULL
@ -154,114 +176,152 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
case TOK_PATHNAME: case TOK_PATHNAME:
strncpy(rs->rigport.pathname, val, FILPATHLEN - 1); strncpy(rs->rigport.pathname, val, FILPATHLEN - 1);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.write_delay = val_i; rs->rigport.write_delay = val_i;
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.post_write_delay = val_i; rs->rigport.post_write_delay = val_i;
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.timeout = val_i; rs->rigport.timeout = val_i;
break; break;
case TOK_RETRY: case TOK_RETRY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.retry = val_i; rs->rigport.retry = val_i;
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.parm.serial.rate = val_i; rs->rigport.parm.serial.rate = val_i;
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.parm.serial.data_bits = val_i; rs->rigport.parm.serial.data_bits = val_i;
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->rigport.parm.serial.stop_bits = val_i; rs->rigport.parm.serial.stop_bits = val_i;
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strcmp(val, "None")) }
if (!strcmp(val, "None")) {
rs->rigport.parm.serial.parity = RIG_PARITY_NONE; rs->rigport.parm.serial.parity = RIG_PARITY_NONE;
else if (!strcmp(val, "Odd")) } else if (!strcmp(val, "Odd")) {
rs->rigport.parm.serial.parity = RIG_PARITY_ODD; rs->rigport.parm.serial.parity = RIG_PARITY_ODD;
else if (!strcmp(val, "Even")) } else if (!strcmp(val, "Even")) {
rs->rigport.parm.serial.parity = RIG_PARITY_EVEN; rs->rigport.parm.serial.parity = RIG_PARITY_EVEN;
else if (!strcmp(val, "Mark")) } else if (!strcmp(val, "Mark")) {
rs->rigport.parm.serial.parity = RIG_PARITY_MARK; rs->rigport.parm.serial.parity = RIG_PARITY_MARK;
else if (!strcmp(val, "Space")) } else if (!strcmp(val, "Space")) {
rs->rigport.parm.serial.parity = RIG_PARITY_SPACE; rs->rigport.parm.serial.parity = RIG_PARITY_SPACE;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strcmp(val, "None")) }
if (!strcmp(val, "None")) {
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
else if (!strcmp(val, "XONXOFF")) } else if (!strcmp(val, "XONXOFF")) {
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF;
else if (!strcmp(val, "Hardware")) } else if (!strcmp(val, "Hardware")) {
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_RTS_STATE: case TOK_RTS_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strcmp(val, "Unset")) }
if (!strcmp(val, "Unset")) {
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_UNSET; rs->rigport.parm.serial.rts_state = RIG_SIGNAL_UNSET;
else if (!strcmp(val, "ON")) } else if (!strcmp(val, "ON")) {
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_ON; rs->rigport.parm.serial.rts_state = RIG_SIGNAL_ON;
else if (!strcmp(val, "OFF")) } else if (!strcmp(val, "OFF")) {
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF; rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_DTR_STATE: case TOK_DTR_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strcmp(val, "Unset")) }
if (!strcmp(val, "Unset")) {
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_UNSET; rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_UNSET;
else if (!strcmp(val, "ON")) } else if (!strcmp(val, "ON")) {
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_ON; rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_ON;
else if (!strcmp(val, "OFF")) } else if (!strcmp(val, "OFF")) {
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF; rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_ITU_REGION: case TOK_ITU_REGION:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
switch (val_i) { switch (val_i) {
case RIG_ITU_REGION1: case RIG_ITU_REGION1:
rs->itu_region = val_i; rs->itu_region = val_i;
@ -270,6 +330,7 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
memcpy(rs->rx_range_list, caps->rx_range_list1, memcpy(rs->rx_range_list, caps->rx_range_list1,
sizeof(struct freq_range_list)*FRQRANGESIZ); sizeof(struct freq_range_list)*FRQRANGESIZ);
break; break;
case RIG_ITU_REGION2: case RIG_ITU_REGION2:
case RIG_ITU_REGION3: case RIG_ITU_REGION3:
rs->itu_region = val_i; rs->itu_region = val_i;
@ -278,28 +339,32 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
memcpy(rs->rx_range_list, caps->rx_range_list2, memcpy(rs->rx_range_list, caps->rx_range_list2,
sizeof(struct freq_range_list)*FRQRANGESIZ); sizeof(struct freq_range_list)*FRQRANGESIZ);
break; break;
default: default:
return -RIG_EINVAL; return -RIG_EINVAL;
} }
break; break;
case TOK_PTT_TYPE: case TOK_PTT_TYPE:
if (!strcmp(val, "RIG")) if (!strcmp(val, "RIG")) {
rs->pttport.type.ptt = RIG_PTT_RIG; rs->pttport.type.ptt = RIG_PTT_RIG;
else if (!strcmp(val, "RIGMICDATA")) } else if (!strcmp(val, "RIGMICDATA")) {
rs->pttport.type.ptt = RIG_PTT_RIG_MICDATA; rs->pttport.type.ptt = RIG_PTT_RIG_MICDATA;
else if (!strcmp(val, "DTR")) } else if (!strcmp(val, "DTR")) {
rs->pttport.type.ptt = RIG_PTT_SERIAL_DTR; rs->pttport.type.ptt = RIG_PTT_SERIAL_DTR;
else if (!strcmp(val, "RTS")) } else if (!strcmp(val, "RTS")) {
rs->pttport.type.ptt = RIG_PTT_SERIAL_RTS; rs->pttport.type.ptt = RIG_PTT_SERIAL_RTS;
else if (!strcmp(val, "Parallel")) } else if (!strcmp(val, "Parallel")) {
rs->pttport.type.ptt = RIG_PTT_PARALLEL; rs->pttport.type.ptt = RIG_PTT_PARALLEL;
else if (!strcmp(val, "CM108")) } else if (!strcmp(val, "CM108")) {
rs->pttport.type.ptt = RIG_PTT_CM108; rs->pttport.type.ptt = RIG_PTT_CM108;
else if (!strcmp(val, "None")) } else if (!strcmp(val, "None")) {
rs->pttport.type.ptt = RIG_PTT_NONE; rs->pttport.type.ptt = RIG_PTT_NONE;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_PTT_PATHNAME: case TOK_PTT_PATHNAME:
@ -310,26 +375,29 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
rs->pttport.parm.cm108.ptt_bitnum = val_i; rs->pttport.parm.cm108.ptt_bitnum = val_i;
break; break;
case TOK_DCD_TYPE: case TOK_DCD_TYPE:
if (!strcmp(val, "RIG")) if (!strcmp(val, "RIG")) {
rs->dcdport.type.dcd = RIG_DCD_RIG; rs->dcdport.type.dcd = RIG_DCD_RIG;
else if (!strcmp(val, "DSR")) } else if (!strcmp(val, "DSR")) {
rs->dcdport.type.dcd = RIG_DCD_SERIAL_DSR; rs->dcdport.type.dcd = RIG_DCD_SERIAL_DSR;
else if (!strcmp(val, "CTS")) } else if (!strcmp(val, "CTS")) {
rs->dcdport.type.dcd = RIG_DCD_SERIAL_CTS; rs->dcdport.type.dcd = RIG_DCD_SERIAL_CTS;
else if (!strcmp(val, "CD")) } else if (!strcmp(val, "CD")) {
rs->dcdport.type.dcd = RIG_DCD_SERIAL_CAR; rs->dcdport.type.dcd = RIG_DCD_SERIAL_CAR;
else if (!strcmp(val, "Parallel")) } else if (!strcmp(val, "Parallel")) {
rs->dcdport.type.dcd = RIG_DCD_PARALLEL; rs->dcdport.type.dcd = RIG_DCD_PARALLEL;
else if (!strcmp(val, "CM108")) } else if (!strcmp(val, "CM108")) {
rs->dcdport.type.dcd = RIG_DCD_CM108; rs->dcdport.type.dcd = RIG_DCD_CM108;
else if (!strcmp(val, "None")) } else if (!strcmp(val, "None")) {
rs->dcdport.type.dcd = RIG_DCD_NONE; rs->dcdport.type.dcd = RIG_DCD_NONE;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_DCD_PATHNAME: case TOK_DCD_PATHNAME:
@ -340,6 +408,7 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
case TOK_VFO_COMP: case TOK_VFO_COMP:
rs->vfo_comp = atof(val); rs->vfo_comp = atof(val);
break; break;
case TOK_POLL_INTERVAL: case TOK_POLL_INTERVAL:
rs->poll_interval = atof(val); rs->poll_interval = atof(val);
break; break;
@ -348,9 +417,11 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
default: default:
return -RIG_EINVAL; return -RIG_EINVAL;
} }
return RIG_OK; return RIG_OK;
} }
/* /*
* frontend_get_conf * frontend_get_conf
* assumes rig!=NULL, val!=NULL * assumes rig!=NULL, val!=NULL
@ -366,104 +437,202 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
case TOK_PATHNAME: case TOK_PATHNAME:
strcpy(val, rs->rigport.pathname); strcpy(val, rs->rigport.pathname);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
sprintf(val, "%d", rs->rigport.write_delay); sprintf(val, "%d", rs->rigport.write_delay);
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
sprintf(val, "%d", rs->rigport.post_write_delay); sprintf(val, "%d", rs->rigport.post_write_delay);
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
sprintf(val, "%d", rs->rigport.timeout); sprintf(val, "%d", rs->rigport.timeout);
break; break;
case TOK_RETRY: case TOK_RETRY:
sprintf(val, "%d", rs->rigport.retry); sprintf(val, "%d", rs->rigport.retry);
break; break;
case TOK_ITU_REGION: case TOK_ITU_REGION:
sprintf(val, "%d", sprintf(val, "%d",
rs->itu_region == 1 ? RIG_ITU_REGION1 : RIG_ITU_REGION2); rs->itu_region == 1 ? RIG_ITU_REGION1 : RIG_ITU_REGION2);
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
sprintf(val, "%d", rs->rigport.parm.serial.rate); sprintf(val, "%d", rs->rigport.parm.serial.rate);
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
sprintf(val, "%d", rs->rigport.parm.serial.data_bits); sprintf(val, "%d", rs->rigport.parm.serial.data_bits);
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
sprintf(val, "%d", rs->rigport.parm.serial.stop_bits); sprintf(val, "%d", rs->rigport.parm.serial.stop_bits);
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
switch (rs->rigport.parm.serial.parity) {
case RIG_PARITY_NONE: s = "None"; break;
case RIG_PARITY_ODD: s = "Odd"; break;
case RIG_PARITY_EVEN: s = "Even"; break;
case RIG_PARITY_MARK: s = "Mark"; break;
case RIG_PARITY_SPACE: s = "Space"; break;
default: return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.parity) {
case RIG_PARITY_NONE:
s = "None";
break;
case RIG_PARITY_ODD:
s = "Odd";
break;
case RIG_PARITY_EVEN:
s = "Even";
break;
case RIG_PARITY_MARK:
s = "Mark";
break;
case RIG_PARITY_SPACE:
s = "Space";
break;
default:
return -RIG_EINVAL;
}
strcpy(val, s); strcpy(val, s);
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
switch (rs->rigport.parm.serial.handshake) {
case RIG_HANDSHAKE_NONE: s = "None"; break;
case RIG_HANDSHAKE_XONXOFF: s = "XONXOFF"; break;
case RIG_HANDSHAKE_HARDWARE: s = "Hardware"; break;
default: return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.handshake) {
case RIG_HANDSHAKE_NONE:
s = "None";
break;
case RIG_HANDSHAKE_XONXOFF:
s = "XONXOFF";
break;
case RIG_HANDSHAKE_HARDWARE:
s = "Hardware";
break;
default:
return -RIG_EINVAL;
}
strcpy(val, s); strcpy(val, s);
break; break;
case TOK_RTS_STATE: case TOK_RTS_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
switch (rs->rigport.parm.serial.rts_state) {
case RIG_SIGNAL_UNSET: s = "Unset"; break;
case RIG_SIGNAL_ON: s = "ON"; break;
case RIG_SIGNAL_OFF: s = "OFF"; break;
default: return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.rts_state) {
case RIG_SIGNAL_UNSET:
s = "Unset";
break;
case RIG_SIGNAL_ON:
s = "ON";
break;
case RIG_SIGNAL_OFF:
s = "OFF";
break;
default:
return -RIG_EINVAL;
}
strcpy(val, s); strcpy(val, s);
break; break;
case TOK_DTR_STATE: case TOK_DTR_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
switch (rs->rigport.parm.serial.dtr_state) {
case RIG_SIGNAL_UNSET: s = "Unset"; break;
case RIG_SIGNAL_ON: s = "ON"; break;
case RIG_SIGNAL_OFF: s = "OFF"; break;
default: return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.dtr_state) {
case RIG_SIGNAL_UNSET:
s = "Unset";
break;
case RIG_SIGNAL_ON:
s = "ON";
break;
case RIG_SIGNAL_OFF:
s = "OFF";
break;
default:
return -RIG_EINVAL;
}
strcpy(val, s); strcpy(val, s);
break; break;
case TOK_VFO_COMP: case TOK_VFO_COMP:
sprintf(val, "%f", rs->vfo_comp); sprintf(val, "%f", rs->vfo_comp);
break; break;
case TOK_POLL_INTERVAL: case TOK_POLL_INTERVAL:
sprintf(val, "%d", rs->poll_interval); sprintf(val, "%d", rs->poll_interval);
break; break;
case TOK_PTT_TYPE: case TOK_PTT_TYPE:
switch (rs->pttport.type.ptt) { switch (rs->pttport.type.ptt) {
case RIG_PTT_RIG: s = "RIG"; break; case RIG_PTT_RIG:
case RIG_PTT_RIG_MICDATA: s = "RIGMICDATA"; break; s = "RIG";
case RIG_PTT_SERIAL_DTR: s = "DTR"; break; break;
case RIG_PTT_SERIAL_RTS: s = "RTS"; break;
case RIG_PTT_PARALLEL: s = "Parallel"; break; case RIG_PTT_RIG_MICDATA:
case RIG_PTT_CM108: s = "CM108"; break; s = "RIGMICDATA";
case RIG_PTT_NONE: s = "None"; break; break;
default: return -RIG_EINVAL;
case RIG_PTT_SERIAL_DTR:
s = "DTR";
break;
case RIG_PTT_SERIAL_RTS:
s = "RTS";
break;
case RIG_PTT_PARALLEL:
s = "Parallel";
break;
case RIG_PTT_CM108:
s = "CM108";
break;
case RIG_PTT_NONE:
s = "None";
break;
default:
return -RIG_EINVAL;
} }
strcpy(val, s); strcpy(val, s);
break; break;
@ -477,15 +646,38 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
case TOK_DCD_TYPE: case TOK_DCD_TYPE:
switch (rs->dcdport.type.dcd) { switch (rs->dcdport.type.dcd) {
case RIG_DCD_RIG: s = "RIG"; break; case RIG_DCD_RIG:
case RIG_DCD_SERIAL_DSR: s = "DSR"; break; s = "RIG";
case RIG_DCD_SERIAL_CTS: s = "CTS"; break; break;
case RIG_DCD_SERIAL_CAR: s = "CD"; break;
case RIG_DCD_PARALLEL: s = "Parallel"; break; case RIG_DCD_SERIAL_DSR:
case RIG_DCD_CM108: s = "CM108"; break; s = "DSR";
case RIG_DCD_NONE: s = "None"; break; break;
default: return -RIG_EINVAL;
case RIG_DCD_SERIAL_CTS:
s = "CTS";
break;
case RIG_DCD_SERIAL_CAR:
s = "CD";
break;
case RIG_DCD_PARALLEL:
s = "Parallel";
break;
case RIG_DCD_CM108:
s = "CM108";
break;
case RIG_DCD_NONE:
s = "None";
break;
default:
return -RIG_EINVAL;
} }
strcpy(val, s); strcpy(val, s);
break; break;
@ -500,6 +692,7 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief call a function against each configuration token of a rig * \brief call a function against each configuration token of a rig
* \param rig The rig handle * \param rig The rig handle
@ -514,26 +707,34 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
* a negative value if an error occured (in which case, cause is * a negative value if an error occured (in which case, cause is
* set appropriately). * set appropriately).
*/ */
int HAMLIB_API rig_token_foreach(RIG *rig, int (*cfunc)(const struct confparams *, rig_ptr_t), rig_ptr_t data) int HAMLIB_API rig_token_foreach(RIG *rig,
int (*cfunc)(const struct confparams *, rig_ptr_t),
rig_ptr_t data)
{ {
const struct confparams *cfp; const struct confparams *cfp;
if (!rig || !rig->caps || !cfunc) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !cfunc) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
for (cfp = frontend_cfg_params; cfp->name; cfp++) for (cfp = frontend_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) if ((*cfunc)(cfp, data) == 0) {
return RIG_OK;
if (rig->caps->port_type == RIG_PORT_SERIAL) {
for (cfp = frontend_serial_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0)
return RIG_OK; return RIG_OK;
} }
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) if (rig->caps->port_type == RIG_PORT_SERIAL) {
if ((*cfunc)(cfp, data) == 0) for (cfp = frontend_serial_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) {
return RIG_OK; return RIG_OK;
}
}
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) {
return RIG_OK;
}
return RIG_OK; return RIG_OK;
} }
@ -548,34 +749,42 @@ int HAMLIB_API rig_token_foreach(RIG *rig, int (*cfunc)(const struct confparams
* *
* \return a pointer to the confparams struct if found, otherwise NULL. * \return a pointer to the confparams struct if found, otherwise NULL.
*/ */
const struct confparams * HAMLIB_API rig_confparam_lookup(RIG *rig, const char *name) const struct confparams *HAMLIB_API rig_confparam_lookup(RIG *rig,
const char *name)
{ {
const struct confparams *cfp; const struct confparams *cfp;
token_t token; token_t token;
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return NULL; return NULL;
}
/* 0 returned for invalid format */ /* 0 returned for invalid format */
token = strtol(name, NULL, 0); token = strtol(name, NULL, 0);
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) if (!strcmp(cfp->name, name) || token == cfp->token) {
return cfp; return cfp;
}
for (cfp = frontend_cfg_params; cfp->name; cfp++) for (cfp = frontend_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) if (!strcmp(cfp->name, name) || token == cfp->token) {
return cfp; return cfp;
}
if (rig->caps->port_type == RIG_PORT_SERIAL) { if (rig->caps->port_type == RIG_PORT_SERIAL) {
for (cfp = frontend_serial_cfg_params; cfp->name; cfp++) for (cfp = frontend_serial_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) if (!strcmp(cfp->name, name) || token == cfp->token) {
return cfp; return cfp;
} }
}
return NULL; return NULL;
} }
/** /**
* \brief lookup a token id * \brief lookup a token id
* \param rig The rig handle * \param rig The rig handle
@ -589,13 +798,18 @@ token_t HAMLIB_API rig_token_lookup(RIG *rig, const char *name)
{ {
const struct confparams *cfp; const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
cfp = rig_confparam_lookup(rig, name); cfp = rig_confparam_lookup(rig, name);
if (!cfp)
if (!cfp) {
return RIG_CONF_END; return RIG_CONF_END;
}
return cfp->token; return cfp->token;
} }
/** /**
* \brief set a radio configuration parameter * \brief set a radio configuration parameter
* \param rig The rig handle * \param rig The rig handle
@ -612,28 +826,37 @@ token_t HAMLIB_API rig_token_lookup(RIG *rig, const char *name)
*/ */
int HAMLIB_API rig_set_conf(RIG *rig, token_t token, const char *val) int HAMLIB_API rig_set_conf(RIG *rig, token_t token, const char *val)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (rig_need_debug(RIG_DEBUG_VERBOSE)) { if (rig_need_debug(RIG_DEBUG_VERBOSE)) {
const struct confparams *cfp; const struct confparams *cfp;
char tokenstr[12]; char tokenstr[12];
sprintf(tokenstr, "%ld", token); sprintf(tokenstr, "%ld", token);
cfp = rig_confparam_lookup(rig, tokenstr); cfp = rig_confparam_lookup(rig, tokenstr);
if (!cfp)
if (!cfp) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val);
} }
if (IS_TOKEN_FRONTEND(token)) if (IS_TOKEN_FRONTEND(token)) {
return frontend_set_conf(rig, token, val); return frontend_set_conf(rig, token, val);
}
if (rig->caps->set_conf == NULL) if (rig->caps->set_conf == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rig->caps->set_conf(rig, token, val); return rig->caps->set_conf(rig, token, val);
} }
/** /**
* \brief get the value of a configuration parameter * \brief get the value of a configuration parameter
* \param rig The rig handle * \param rig The rig handle
@ -651,14 +874,19 @@ int HAMLIB_API rig_set_conf(RIG *rig, token_t token, const char *val)
*/ */
int HAMLIB_API rig_get_conf(RIG *rig, token_t token, char *val) int HAMLIB_API rig_get_conf(RIG *rig, token_t token, char *val)
{ {
if (!rig || !rig->caps || !val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !val) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (IS_TOKEN_FRONTEND(token)) if (IS_TOKEN_FRONTEND(token)) {
return frontend_get_conf(rig, token, val); return frontend_get_conf(rig, token, val);
}
if (rig->caps->get_conf == NULL) if (rig->caps->get_conf == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rig->caps->get_conf(rig, token, val); return rig->caps->get_conf(rig, token, val);
} }

Wyświetl plik

@ -48,16 +48,17 @@
#endif #endif
#include <hamlib/rig.h> #include <hamlib/rig.h>
#include "misc.h" #include "misc.h"
#define DUMP_HEX_WIDTH 16
static int rig_debug_level = RIG_DEBUG_TRACE; static int rig_debug_level = RIG_DEBUG_TRACE;
static FILE *rig_debug_stream; static FILE *rig_debug_stream;
static vprintf_cb_t rig_vprintf_cb; static vprintf_cb_t rig_vprintf_cb;
static rig_ptr_t rig_vprintf_arg; static rig_ptr_t rig_vprintf_arg;
#define DUMP_HEX_WIDTH 16
/** /**
* \param ptr Pointer to memory area * \param ptr Pointer to memory area
* \param size Number of chars to words to dump * \param size Number of chars to words to dump
@ -73,8 +74,9 @@ void dump_hex(const unsigned char ptr[], size_t size)
unsigned char c; unsigned char c;
int i; int i;
if (!rig_need_debug(RIG_DEBUG_TRACE)) if (!rig_need_debug(RIG_DEBUG_TRACE)) {
return; return;
}
line[sizeof(line) - 1] = '\0'; line[sizeof(line) - 1] = '\0';
@ -92,13 +94,15 @@ void dump_hex(const unsigned char ptr[], size_t size)
line[8 + 3 * (i % DUMP_HEX_WIDTH) + 2] = ' '; /* no \0 */ line[8 + 3 * (i % DUMP_HEX_WIDTH) + 2] = ' '; /* no \0 */
/* ascii print */ /* ascii print */
line[8 + 3 * DUMP_HEX_WIDTH + 4 + (i % DUMP_HEX_WIDTH)] = (c >= ' ' && c < 0x7f) ? c : '.'; line[8 + 3 * DUMP_HEX_WIDTH + 4 + (i % DUMP_HEX_WIDTH)] = (c >= ' '
&& c < 0x7f) ? c : '.';
/* actually print the line */ /* actually print the line */
if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1)) if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1)) {
rig_debug(RIG_DEBUG_TRACE, "%s\n", line); rig_debug(RIG_DEBUG_TRACE, "%s\n", line);
} }
} }
}
/** /**
@ -110,6 +114,7 @@ void HAMLIB_API rig_set_debug(enum rig_debug_level_e debug_level)
rig_debug_level = debug_level; rig_debug_level = debug_level;
} }
/** /**
* \param debug_level * \param debug_level
* \brief Useful for dump_hex, etc. * \brief Useful for dump_hex, etc.
@ -119,28 +124,30 @@ int HAMLIB_API rig_need_debug(enum rig_debug_level_e debug_level)
return (debug_level <= rig_debug_level); return (debug_level <= rig_debug_level);
} }
/** /**
* \param debug_level * \param debug_level
* \param fmt * \param fmt
* \brief Default is debugging messages are done through stderr * \brief Default is debugging messages are done through stderr
*/ */
void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, const char *fmt, ...) void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level,
const char *fmt, ...)
{ {
va_list ap; va_list ap;
if (!rig_need_debug(debug_level)) if (!rig_need_debug(debug_level)) {
return; return;
}
va_start(ap, fmt); va_start(ap, fmt);
if (rig_vprintf_cb) { if (rig_vprintf_cb) {
rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap); rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap);
} else { } else {
if (!rig_debug_stream) if (!rig_debug_stream) {
rig_debug_stream = stderr; rig_debug_stream = stderr;
}
vfprintf(rig_debug_stream, fmt, ap); vfprintf(rig_debug_stream, fmt, ap);
fflush(rig_debug_stream); fflush(rig_debug_stream);
@ -150,27 +157,41 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, const char *fmt, .
#ifdef ANDROID #ifdef ANDROID
int a; int a;
va_start(ap, fmt); va_start(ap, fmt);
switch (debug_level) { switch (debug_level) {
// case RIG_DEBUG_NONE: // case RIG_DEBUG_NONE:
case RIG_DEBUG_BUG: case RIG_DEBUG_BUG:
a = ANDROID_LOG_FATAL; break; a = ANDROID_LOG_FATAL;
break;
case RIG_DEBUG_ERR: case RIG_DEBUG_ERR:
a = ANDROID_LOG_ERROR; break; a = ANDROID_LOG_ERROR;
break;
case RIG_DEBUG_WARN: case RIG_DEBUG_WARN:
a = ANDROID_LOG_WARN; break; a = ANDROID_LOG_WARN;
break;
case RIG_DEBUG_VERBOSE: case RIG_DEBUG_VERBOSE:
a = ANDROID_LOG_VERBOSE; break; a = ANDROID_LOG_VERBOSE;
break;
case RIG_DEBUG_TRACE: case RIG_DEBUG_TRACE:
a = ANDROID_LOG_VERBOSE; break; a = ANDROID_LOG_VERBOSE;
break;
default: default:
a = ANDROID_LOG_DEBUG; break; a = ANDROID_LOG_DEBUG;
break;
} }
__android_log_vprint(a, PACKAGE_NAME, fmt, ap); __android_log_vprint(a, PACKAGE_NAME, fmt, ap);
va_end(ap); va_end(ap);
#endif #endif
} }
/** /**
* \brief set callback to handle debug messages * \brief set callback to handle debug messages
* \param cb The callback to install * \param cb The callback to install
@ -216,6 +237,7 @@ vprintf_cb_t HAMLIB_API rig_set_debug_callback(vprintf_cb_t cb, rig_ptr_t arg)
return prev_cb; return prev_cb;
} }
/** /**
* \brief change stderr to some different output * \brief change stderr to some different output
* \param stream The stream to set output to * \param stream The stream to set output to

Wyświetl plik

@ -53,7 +53,6 @@
#include <hamlib/rig.h> #include <hamlib/rig.h>
#include "event.h" #include "event.h"
#if defined(WIN32) && !defined(HAVE_TERMIOS_H) #if defined(WIN32) && !defined(HAVE_TERMIOS_H)
@ -78,9 +77,11 @@ static void sa_sigalrmhandler(int signum);
#endif #endif
#endif #endif
/* This one should be in an include file */ /* This one should be in an include file */
extern int foreach_opened_rig(int (*cfunc)(RIG *, rig_ptr_t), rig_ptr_t data); extern int foreach_opened_rig(int (*cfunc)(RIG *, rig_ptr_t), rig_ptr_t data);
/* /*
* add_trn_rig * add_trn_rig
* not exported in Hamlib API. * not exported in Hamlib API.
@ -112,27 +113,45 @@ int add_trn_rig(RIG *rig)
#endif #endif
status = sigaction(SIGIO, &act, &hamlib_trn_oldact); status = sigaction(SIGIO, &act, &hamlib_trn_oldact);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s: sigaction failed: %s\n", if (status < 0) {
__func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: sigaction failed: %s\n",
__func__,
strerror(errno));
}
status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid()); status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid());
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s: fcntl SETOWN failed: %s\n", if (status < 0) {
__func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETOWN failed: %s\n",
__func__,
strerror(errno));
}
#if defined(HAVE_SIGINFO_T) && defined(O_ASYNC) #if defined(HAVE_SIGINFO_T) && defined(O_ASYNC)
#ifdef F_SETSIG #ifdef F_SETSIG
status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO); status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s: fcntl SETSIG failed: %s\n", if (status < 0) {
__func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETSIG failed: %s\n",
__func__,
strerror(errno));
}
#endif #endif
status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC); status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s: fcntl SETASYNC failed: %s\n", if (status < 0) {
__func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETASYNC failed: %s\n",
__func__,
strerror(errno));
}
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
@ -144,6 +163,7 @@ int add_trn_rig(RIG *rig)
#endif /* !HAVE_SIGACTION */ #endif /* !HAVE_SIGACTION */
} }
/* /*
* remove_trn_rig * remove_trn_rig
* not exported in Hamlib API. * not exported in Hamlib API.
@ -158,15 +178,24 @@ int remove_trn_rig(RIG *rig)
#if defined(HAVE_SIGINFO_T) && defined(O_ASYNC) #if defined(HAVE_SIGINFO_T) && defined(O_ASYNC)
status = fcntl(rig->state.rigport.fd, F_SETFL, 0); status = fcntl(rig->state.rigport.fd, F_SETFL, 0);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s: fcntl SETASYNC failed: %s\n", if (status < 0) {
__func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETASYNC failed: %s\n",
__func__,
strerror(errno));
}
#endif #endif
status = sigaction(SIGIO, &hamlib_trn_oldact, NULL); status = sigaction(SIGIO, &hamlib_trn_oldact, NULL);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s: sigaction failed: %s\n", if (status < 0) {
__func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: sigaction failed: %s\n",
__func__,
strerror(errno));
}
return RIG_OK; return RIG_OK;
#else #else
@ -177,6 +206,7 @@ int remove_trn_rig(RIG *rig)
#ifdef HAVE_SIGACTION #ifdef HAVE_SIGACTION
/* /*
* add_trn_poll_rig * add_trn_poll_rig
* not exported in Hamlib API. * not exported in Hamlib API.
@ -202,10 +232,13 @@ static int add_trn_poll_rig(RIG *rig)
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
status = sigaction(SIGALRM, &act, &hamlib_trn_poll_oldact); status = sigaction(SIGALRM, &act, &hamlib_trn_poll_oldact);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s sigaction failed: %s\n", if (status < 0) {
rig_debug(RIG_DEBUG_ERR,
"%s sigaction failed: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
}
return RIG_OK; return RIG_OK;
@ -214,6 +247,7 @@ static int add_trn_poll_rig(RIG *rig)
#endif /* !HAVE_SIGINFO */ #endif /* !HAVE_SIGINFO */
} }
/* /*
* remove_trn_poll_rig * remove_trn_poll_rig
* not exported in Hamlib API. * not exported in Hamlib API.
@ -224,10 +258,13 @@ static int remove_trn_poll_rig(RIG *rig)
int status; int status;
status = sigaction(SIGALRM, &hamlib_trn_poll_oldact, NULL); status = sigaction(SIGALRM, &hamlib_trn_poll_oldact, NULL);
if (status < 0)
rig_debug(RIG_DEBUG_ERR,"%s sigaction failed: %s\n", if (status < 0) {
rig_debug(RIG_DEBUG_ERR,
"%s sigaction failed: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
}
return RIG_OK; return RIG_OK;
@ -253,16 +290,19 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
/* /*
* so far, only file oriented ports have event reporting support * so far, only file oriented ports have event reporting support
*/ */
if (rig->state.rigport.type.rig != RIG_PORT_SERIAL || if (rig->state.rigport.type.rig != RIG_PORT_SERIAL
rig->state.rigport.fd == -1) || rig->state.rigport.fd == -1) {
return -1; return -1;
}
/* FIXME: siginfo is not portable, however use it where available */ /* FIXME: siginfo is not portable, however use it where available */
#if 0&&defined(HAVE_SIGINFO_T) #if 0&&defined(HAVE_SIGINFO_T)
siginfo_t *si = (siginfo_t *)data; siginfo_t *si = (siginfo_t *)data;
if (rig->state.rigport.fd != si->si_fd) if (rig->state.rigport.fd != si->si_fd) {
return -1; return -1;
}
#else #else
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(rig->state.rigport.fd, &rfds); FD_SET(rig->state.rigport.fd, &rfds);
@ -275,25 +315,32 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
* REM: EINTR possible with 0sec timeout? retval==0? * REM: EINTR possible with 0sec timeout? retval==0?
*/ */
retval = select(rig->state.rigport.fd + 1, &rfds, NULL, NULL, &tv); retval = select(rig->state.rigport.fd + 1, &rfds, NULL, NULL, &tv);
if (retval < 0) { if (retval < 0) {
rig_debug(RIG_DEBUG_ERR, "search_rig_and_decode: select: %s\n", rig_debug(RIG_DEBUG_ERR,
"%s: select: %s\n",
__func__,
strerror(errno)); strerror(errno));
return -1; return -1;
} }
#endif #endif
/* /*
* Do not disturb, the backend is currently receiving data * Do not disturb, the backend is currently receiving data
*/ */
if (rig->state.hold_decode) if (rig->state.hold_decode) {
return -1; return -1;
}
if (rig->caps->decode_event) if (rig->caps->decode_event) {
rig->caps->decode_event(rig); rig->caps->decode_event(rig);
}
return 1; /* process each opened rig */ return 1; /* process each opened rig */
} }
/* /*
* This is used by sa_sigio, the SIGALRM handler * This is used by sa_sigio, the SIGALRM handler
* to poll each RIG in RIG_TRN_POLL mode. * to poll each RIG in RIG_TRN_POLL mode.
@ -305,13 +352,16 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
struct rig_state *rs = &rig->state; struct rig_state *rs = &rig->state;
int retval; int retval;
if (rig->state.transceive != RIG_TRN_POLL) if (rig->state.transceive != RIG_TRN_POLL) {
return -1; return -1;
}
/* /*
* Do not disturb, the backend is currently receiving data * Do not disturb, the backend is currently receiving data
*/ */
if (rig->state.hold_decode) if (rig->state.hold_decode) {
return -1; return -1;
}
rig->state.hold_decode = 2; rig->state.hold_decode = 2;
@ -319,35 +369,43 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
vfo_t vfo = RIG_VFO_CURR; vfo_t vfo = RIG_VFO_CURR;
retval = rig->caps->get_vfo(rig, &vfo); retval = rig->caps->get_vfo(rig, &vfo);
if (retval == RIG_OK) { if (retval == RIG_OK) {
if (vfo != rs->current_vfo) { if (vfo != rs->current_vfo) {
rig->callbacks.vfo_event(rig, vfo, rig->callbacks.vfo_arg); rig->callbacks.vfo_event(rig, vfo, rig->callbacks.vfo_arg);
} }
rs->current_vfo = vfo; rs->current_vfo = vfo;
} }
} }
if (rig->caps->get_freq && rig->callbacks.freq_event) { if (rig->caps->get_freq && rig->callbacks.freq_event) {
freq_t freq; freq_t freq;
retval = rig->caps->get_freq(rig, RIG_VFO_CURR, &freq); retval = rig->caps->get_freq(rig, RIG_VFO_CURR, &freq);
if (retval == RIG_OK) { if (retval == RIG_OK) {
if (freq != rs->current_freq) { if (freq != rs->current_freq) {
rig->callbacks.freq_event(rig, RIG_VFO_CURR, rig->callbacks.freq_event(rig, RIG_VFO_CURR,
freq, rig->callbacks.freq_arg); freq, rig->callbacks.freq_arg);
} }
rs->current_freq = freq; rs->current_freq = freq;
} }
} }
if (rig->caps->get_mode && rig->callbacks.mode_event) { if (rig->caps->get_mode && rig->callbacks.mode_event) {
rmode_t rmode; rmode_t rmode;
pbwidth_t width; pbwidth_t width;
retval = rig->caps->get_mode(rig, RIG_VFO_CURR, &rmode, &width); retval = rig->caps->get_mode(rig, RIG_VFO_CURR, &rmode, &width);
if (retval == RIG_OK) { if (retval == RIG_OK) {
if (rmode != rs->current_mode || width != rs->current_width) { if (rmode != rs->current_mode || width != rs->current_width) {
rig->callbacks.mode_event(rig, RIG_VFO_CURR, rig->callbacks.mode_event(rig, RIG_VFO_CURR,
rmode, width, rig->callbacks.mode_arg); rmode, width, rig->callbacks.mode_arg);
} }
rs->current_mode = rmode; rs->current_mode = rmode;
rs->current_width = width; rs->current_width = width;
} }
@ -369,7 +427,7 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
#ifdef HAVE_SIGINFO_T #ifdef HAVE_SIGINFO_T
static void sa_sigioaction(int signum, siginfo_t *si, rig_ptr_t data) static void sa_sigioaction(int signum, siginfo_t *si, rig_ptr_t data)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "sa_sigioaction: activity detected\n"); rig_debug(RIG_DEBUG_VERBOSE, "%s: activity detected\n", __func__);
foreach_opened_rig(search_rig_and_decode, si); foreach_opened_rig(search_rig_and_decode, si);
} }
@ -378,7 +436,7 @@ static void sa_sigioaction(int signum, siginfo_t *si, rig_ptr_t data)
static void sa_sigiohandler(int signum) static void sa_sigiohandler(int signum)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "sa_sigiohandler: activity detected\n"); rig_debug(RIG_DEBUG_VERBOSE, "%s: activity detected\n", __func__);
foreach_opened_rig(search_rig_and_decode, NULL); foreach_opened_rig(search_rig_and_decode, NULL);
} }
@ -396,7 +454,7 @@ static void sa_sigiohandler(int signum)
#ifdef HAVE_SIGINFO_T #ifdef HAVE_SIGINFO_T
static void sa_sigalrmaction(int signum, siginfo_t *si, rig_ptr_t data) static void sa_sigalrmaction(int signum, siginfo_t *si, rig_ptr_t data)
{ {
rig_debug(RIG_DEBUG_TRACE, "sa_sigalrmaction entered\n"); rig_debug(RIG_DEBUG_TRACE, "%s entered\n", __func__);
foreach_opened_rig(search_rig_and_poll, si); foreach_opened_rig(search_rig_and_poll, si);
} }
@ -405,7 +463,7 @@ static void sa_sigalrmaction(int signum, siginfo_t *si, rig_ptr_t data)
static void sa_sigalrmhandler(int signum) static void sa_sigalrmhandler(int signum)
{ {
rig_debug(RIG_DEBUG_TRACE, "sa_sigalrmhandler entered\n"); rig_debug(RIG_DEBUG_TRACE, "%s entered\n", __func__);
foreach_opened_rig(search_rig_and_poll, NULL); foreach_opened_rig(search_rig_and_poll, NULL);
} }
@ -416,6 +474,7 @@ static void sa_sigalrmhandler(int signum)
#endif /* !DOC_HIDDEN */ #endif /* !DOC_HIDDEN */
/** /**
* \brief set the callback for freq events * \brief set the callback for freq events
* \param rig The rig handle * \param rig The rig handle
@ -430,11 +489,13 @@ static void sa_sigalrmhandler(int signum)
* *
* \sa rig_set_trn() * \sa rig_set_trn()
*/ */
int HAMLIB_API rig_set_freq_callback(RIG *rig, freq_cb_t cb, rig_ptr_t arg) int HAMLIB_API rig_set_freq_callback(RIG *rig, freq_cb_t cb, rig_ptr_t arg)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig->callbacks.freq_event = cb; rig->callbacks.freq_event = cb;
rig->callbacks.freq_arg = arg; rig->callbacks.freq_arg = arg;
@ -442,6 +503,7 @@ int HAMLIB_API rig_set_freq_callback(RIG *rig, freq_cb_t cb, rig_ptr_t arg)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief set the callback for mode events * \brief set the callback for mode events
* \param rig The rig handle * \param rig The rig handle
@ -456,11 +518,13 @@ int HAMLIB_API rig_set_freq_callback(RIG *rig, freq_cb_t cb, rig_ptr_t arg)
* *
* \sa rig_set_trn() * \sa rig_set_trn()
*/ */
int HAMLIB_API rig_set_mode_callback(RIG *rig, mode_cb_t cb, rig_ptr_t arg) int HAMLIB_API rig_set_mode_callback(RIG *rig, mode_cb_t cb, rig_ptr_t arg)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig->callbacks.mode_event = cb; rig->callbacks.mode_event = cb;
rig->callbacks.mode_arg = arg; rig->callbacks.mode_arg = arg;
@ -468,6 +532,7 @@ int HAMLIB_API rig_set_mode_callback(RIG *rig, mode_cb_t cb, rig_ptr_t arg)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief set the callback for vfo events * \brief set the callback for vfo events
* \param rig The rig handle * \param rig The rig handle
@ -482,11 +547,13 @@ int HAMLIB_API rig_set_mode_callback(RIG *rig, mode_cb_t cb, rig_ptr_t arg)
* *
* \sa rig_set_trn() * \sa rig_set_trn()
*/ */
int HAMLIB_API rig_set_vfo_callback(RIG *rig, vfo_cb_t cb, rig_ptr_t arg) int HAMLIB_API rig_set_vfo_callback(RIG *rig, vfo_cb_t cb, rig_ptr_t arg)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig->callbacks.vfo_event = cb; rig->callbacks.vfo_event = cb;
rig->callbacks.vfo_arg = arg; rig->callbacks.vfo_arg = arg;
@ -494,6 +561,7 @@ int HAMLIB_API rig_set_vfo_callback(RIG *rig, vfo_cb_t cb, rig_ptr_t arg)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief set the callback for ptt events * \brief set the callback for ptt events
* \param rig The rig handle * \param rig The rig handle
@ -508,11 +576,13 @@ int HAMLIB_API rig_set_vfo_callback(RIG *rig, vfo_cb_t cb, rig_ptr_t arg)
* *
* \sa rig_set_trn() * \sa rig_set_trn()
*/ */
int HAMLIB_API rig_set_ptt_callback(RIG *rig, ptt_cb_t cb, rig_ptr_t arg) int HAMLIB_API rig_set_ptt_callback(RIG *rig, ptt_cb_t cb, rig_ptr_t arg)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig->callbacks.ptt_event = cb; rig->callbacks.ptt_event = cb;
rig->callbacks.ptt_arg = arg; rig->callbacks.ptt_arg = arg;
@ -520,6 +590,7 @@ int HAMLIB_API rig_set_ptt_callback(RIG *rig, ptt_cb_t cb, rig_ptr_t arg)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief set the callback for dcd events * \brief set the callback for dcd events
* \param rig The rig handle * \param rig The rig handle
@ -534,11 +605,13 @@ int HAMLIB_API rig_set_ptt_callback(RIG *rig, ptt_cb_t cb, rig_ptr_t arg)
* *
* \sa rig_set_trn() * \sa rig_set_trn()
*/ */
int HAMLIB_API rig_set_dcd_callback(RIG *rig, dcd_cb_t cb, rig_ptr_t arg) int HAMLIB_API rig_set_dcd_callback(RIG *rig, dcd_cb_t cb, rig_ptr_t arg)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig->callbacks.dcd_event = cb; rig->callbacks.dcd_event = cb;
rig->callbacks.dcd_arg = arg; rig->callbacks.dcd_arg = arg;
@ -546,6 +619,7 @@ int HAMLIB_API rig_set_dcd_callback(RIG *rig, dcd_cb_t cb, rig_ptr_t arg)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief set the callback for pipelined tuning module * \brief set the callback for pipelined tuning module
* \param rig The rig handle * \param rig The rig handle
@ -562,11 +636,13 @@ int HAMLIB_API rig_set_dcd_callback(RIG *rig, dcd_cb_t cb, rig_ptr_t arg)
* *
* \sa rig_set_trn() * \sa rig_set_trn()
*/ */
int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg) int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rig->callbacks.pltune = cb; rig->callbacks.pltune = cb;
rig->callbacks.pltune_arg = arg; rig->callbacks.pltune_arg = arg;
@ -574,6 +650,7 @@ int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief control the transceive mode * \brief control the transceive mode
* \param rig The rig handle * \param rig The rig handle
@ -587,7 +664,6 @@ int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg)
* *
* \sa rig_get_trn() * \sa rig_get_trn()
*/ */
int HAMLIB_API rig_set_trn(RIG *rig, int trn) int HAMLIB_API rig_set_trn(RIG *rig, int trn)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
@ -596,8 +672,11 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
struct itimerval value; struct itimerval value;
#endif #endif
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
@ -608,22 +687,27 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
} else { } else {
/* when going POLL<->RIG, transtition to OFF */ /* when going POLL<->RIG, transtition to OFF */
retcode = rig_set_trn(rig, RIG_TRN_OFF); retcode = rig_set_trn(rig, RIG_TRN_OFF);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
} }
} }
}
switch (trn) { switch (trn) {
case RIG_TRN_RIG: case RIG_TRN_RIG:
if (caps->transceive != RIG_TRN_RIG) if (caps->transceive != RIG_TRN_RIG) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
retcode = add_trn_rig(rig); retcode = add_trn_rig(rig);
/* some protocols (e.g. CI-V's) offer no way /* some protocols (e.g. CI-V's) offer no way
* to turn on/off the transceive mode */ * to turn on/off the transceive mode */
if (retcode == RIG_OK && caps->set_trn) { if (retcode == RIG_OK && caps->set_trn) {
retcode = caps->set_trn(rig, RIG_TRN_RIG); retcode = caps->set_trn(rig, RIG_TRN_RIG);
} }
break; break;
case RIG_TRN_POLL: case RIG_TRN_POLL:
@ -637,13 +721,16 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
value.it_interval.tv_sec = 0; value.it_interval.tv_sec = 0;
value.it_interval.tv_usec = rig->state.poll_interval * 1000; value.it_interval.tv_usec = rig->state.poll_interval * 1000;
retcode = setitimer(ITIMER_REAL, &value, NULL); retcode = setitimer(ITIMER_REAL, &value, NULL);
if (retcode == -1) { if (retcode == -1) {
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n", rig_debug(RIG_DEBUG_ERR,
"%s: setitimer: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
remove_trn_poll_rig(rig); remove_trn_poll_rig(rig);
return -RIG_EINTERNAL; return -RIG_EINTERNAL;
} }
#else #else
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
#endif #endif
@ -661,33 +748,39 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
value.it_interval.tv_usec = 0; value.it_interval.tv_usec = 0;
retcode = setitimer(ITIMER_REAL, &value, NULL); retcode = setitimer(ITIMER_REAL, &value, NULL);
if (retcode == -1) { if (retcode == -1) {
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n", rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
return -RIG_EINTERNAL; return -RIG_EINTERNAL;
} }
#else #else
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
#endif #endif
} else if (rig->state.transceive == RIG_TRN_RIG) { } else if (rig->state.transceive == RIG_TRN_RIG) {
retcode = remove_trn_rig(rig); retcode = remove_trn_rig(rig);
if (caps->set_trn && caps->transceive == RIG_TRN_RIG) { if (caps->set_trn && caps->transceive == RIG_TRN_RIG) {
retcode = caps->set_trn(rig, RIG_TRN_OFF); retcode = caps->set_trn(rig, RIG_TRN_OFF);
} }
} }
break; break;
default: default:
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (retcode == RIG_OK) if (retcode == RIG_OK) {
rig->state.transceive = trn; rig->state.transceive = trn;
}
return retcode; return retcode;
} }
/** /**
* \brief get the current transceive mode * \brief get the current transceive mode
* \param rig The rig handle * \param rig The rig handle
@ -704,11 +797,15 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
*/ */
int HAMLIB_API rig_get_trn(RIG *rig, int *trn) int HAMLIB_API rig_get_trn(RIG *rig, int *trn)
{ {
if (CHECK_RIG_ARG(rig) || !trn) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
if (rig->caps->get_trn != NULL) if (CHECK_RIG_ARG(rig) || !trn) {
return -RIG_EINVAL;
}
if (rig->caps->get_trn != NULL) {
return rig->caps->get_trn(rig, trn); return rig->caps->get_trn(rig, trn);
}
*trn = rig->state.transceive; *trn = rig->state.transceive;
return RIG_OK; return RIG_OK;

Wyświetl plik

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
*/ */
/** /**
* \addtogroup rig * \addtogroup rig
* @{ * @{
@ -48,7 +49,6 @@
#include "token.h" #include "token.h"
/** /**
* \param rig The rig handle * \param rig The rig handle
* \param cfunc callback function of each extlevel * \param cfunc callback function of each extlevel
@ -58,25 +58,37 @@
* A zero value means a normal end of iteration, and a negative value an abnormal end, * A zero value means a normal end of iteration, and a negative value an abnormal end,
* which will be the return value of rig_ext_level_foreach. * which will be the return value of rig_ext_level_foreach.
*/ */
int HAMLIB_API rig_ext_level_foreach(RIG *rig, int (*cfunc)(RIG *, const struct confparams *, rig_ptr_t), rig_ptr_t data) int HAMLIB_API rig_ext_level_foreach(RIG *rig,
int (*cfunc)(RIG *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data)
{ {
const struct confparams *cfp; const struct confparams *cfp;
int ret; int ret;
if (!rig || !rig->caps || !cfunc) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !cfunc) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) { for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) {
ret = (*cfunc)(rig, cfp, data); ret = (*cfunc)(rig, cfp, data);
if (ret == 0)
if (ret == 0) {
return RIG_OK; return RIG_OK;
if (ret < 0) }
if (ret < 0) {
return ret; return ret;
} }
}
return RIG_OK; return RIG_OK;
} }
/** /**
* \param rig The rig handle * \param rig The rig handle
* \param cfunc callback function of each extparm * \param cfunc callback function of each extparm
@ -86,25 +98,37 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig, int (*cfunc)(RIG *, const struct
* A zero value means a normal end of iteration, and a negative value an abnormal end, * A zero value means a normal end of iteration, and a negative value an abnormal end,
* which will be the return value of rig_ext_parm_foreach. * which will be the return value of rig_ext_parm_foreach.
*/ */
int HAMLIB_API rig_ext_parm_foreach(RIG *rig, int (*cfunc)(RIG *, const struct confparams *, rig_ptr_t), rig_ptr_t data) int HAMLIB_API rig_ext_parm_foreach(RIG *rig,
int (*cfunc)(RIG *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data)
{ {
const struct confparams *cfp; const struct confparams *cfp;
int ret; int ret;
if (!rig || !rig->caps || !cfunc) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !cfunc) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) { for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) {
ret = (*cfunc)(rig, cfp, data); ret = (*cfunc)(rig, cfp, data);
if (ret == 0)
if (ret == 0) {
return RIG_OK; return RIG_OK;
if (ret < 0) }
if (ret < 0) {
return ret; return ret;
} }
}
return RIG_OK; return RIG_OK;
} }
/** /**
* \param rig * \param rig
* \param name * \param name
@ -120,18 +144,26 @@ const struct confparams * HAMLIB_API rig_ext_lookup(RIG *rig, const char *name)
{ {
const struct confparams *cfp; const struct confparams *cfp;
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return NULL;
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) if (!rig || !rig->caps) {
if (!strcmp(cfp->name, name))
return cfp;
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name))
return cfp;
return NULL; return NULL;
} }
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name)) {
return cfp;
}
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name)) {
return cfp;
}
return NULL;
}
/** /**
* \param rig * \param rig
* \param token * \param token
@ -145,18 +177,26 @@ const struct confparams * HAMLIB_API rig_ext_lookup_tok(RIG *rig, token_t token)
{ {
const struct confparams *cfp; const struct confparams *cfp;
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return NULL;
for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++) if (!rig || !rig->caps) {
if (cfp->token == token)
return cfp;
for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++)
if (cfp->token == token)
return cfp;
return NULL; return NULL;
} }
for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++)
if (cfp->token == token) {
return cfp;
}
for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++)
if (cfp->token == token) {
return cfp;
}
return NULL;
}
/** /**
* \param rig * \param rig
* \param name * \param name
@ -166,9 +206,13 @@ token_t HAMLIB_API rig_ext_token_lookup(RIG *rig, const char *name)
{ {
const struct confparams *cfp; const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
cfp = rig_ext_lookup(rig, name); cfp = rig_ext_lookup(rig, name);
if (!cfp)
if (!cfp) {
return RIG_CONF_END; return RIG_CONF_END;
}
return cfp->token; return cfp->token;
} }

Wyświetl plik

@ -19,8 +19,6 @@
* *
*/ */
#include "gpio.h"
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
@ -28,6 +26,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "gpio.h"
int gpio_open(hamlib_port_t *port, int on_value) int gpio_open(hamlib_port_t *port, int on_value)
{ {
@ -39,29 +39,49 @@ int gpio_open(hamlib_port_t *port, int on_value)
snprintf(pathname, FILPATHLEN, "/sys/class/gpio/export"); snprintf(pathname, FILPATHLEN, "/sys/class/gpio/export");
fexp = fopen(pathname, "w"); fexp = fopen(pathname, "w");
if (!fexp) { if (!fexp) {
rig_debug(RIG_DEBUG_ERR, "Export GPIO%s (using %s): %s\n", rig_debug(RIG_DEBUG_ERR,
port->pathname, pathname, strerror(errno)); "Export GPIO%s (using %s): %s\n",
port->pathname,
pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
fprintf(fexp, "%s\n", port->pathname); fprintf(fexp, "%s\n", port->pathname);
fclose(fexp); fclose(fexp);
snprintf(pathname, FILPATHLEN, "/sys/class/gpio/gpio%s/direction", port->pathname); snprintf(pathname,
FILPATHLEN,
"/sys/class/gpio/gpio%s/direction",
port->pathname);
fdir = fopen(pathname, "w"); fdir = fopen(pathname, "w");
if (!fdir) { if (!fdir) {
rig_debug(RIG_DEBUG_ERR, "GPIO%s direction (using %s): %s\n", rig_debug(RIG_DEBUG_ERR,
port->pathname, pathname, strerror(errno)); "GPIO%s direction (using %s): %s\n",
port->pathname,
pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
fprintf(fdir, "out\n"); fprintf(fdir, "out\n");
fclose(fdir); fclose(fdir);
snprintf(pathname, FILPATHLEN, "/sys/class/gpio/gpio%s/value", port->pathname); snprintf(pathname,
FILPATHLEN,
"/sys/class/gpio/gpio%s/value",
port->pathname);
fd = open(pathname, O_WRONLY); fd = open(pathname, O_WRONLY);
if (fd < 0) { if (fd < 0) {
rig_debug(RIG_DEBUG_ERR, "GPIO%s opening value file %s: %s\n", rig_debug(RIG_DEBUG_ERR,
port->pathname, pathname, strerror(errno)); "GPIO%s opening value file %s: %s\n",
port->pathname,
pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
@ -69,33 +89,38 @@ int gpio_open(hamlib_port_t *port, int on_value)
return fd; return fd;
} }
int gpio_close(hamlib_port_t *port) int gpio_close(hamlib_port_t *port)
{ {
return close(port->fd); return close(port->fd);
} }
int gpio_ptt_set(hamlib_port_t *port, ptt_t pttx) int gpio_ptt_set(hamlib_port_t *port, ptt_t pttx)
{ {
char *val; char *val;
port->parm.gpio.value = pttx != RIG_PTT_OFF; port->parm.gpio.value = pttx != RIG_PTT_OFF;
if ((port->parm.gpio.value && port->parm.gpio.on_value) || if ((port->parm.gpio.value && port->parm.gpio.on_value)
(!port->parm.gpio.value && !port->parm.gpio.on_value)) { || (!port->parm.gpio.value && !port->parm.gpio.on_value)) {
val = "1\n"; val = "1\n";
} else { } else {
val = "0\n"; val = "0\n";
} }
if (write(port->fd, val, strlen(val)) <= 0) if (write(port->fd, val, strlen(val)) <= 0) {
return -RIG_EIO; return -RIG_EIO;
}
return RIG_OK; return RIG_OK;
} }
int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx) int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx)
{ {
if (port->parm.gpio.value) if (port->parm.gpio.value) {
return RIG_PTT_ON; return RIG_PTT_ON;
else } else {
return RIG_PTT_OFF; return RIG_PTT_OFF;
} }
}

Wyświetl plik

@ -44,7 +44,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "hamlib/rig.h" #include <hamlib/rig.h>
#include "iofunc.h" #include "iofunc.h"
#include "misc.h" #include "misc.h"
@ -64,60 +64,84 @@ int HAMLIB_API port_open(hamlib_port_t *p)
int status; int status;
int want_state_delay = 0; int want_state_delay = 0;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
p->fd = -1; p->fd = -1;
switch (p->type.rig) { switch (p->type.rig) {
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
status = serial_open(p); status = serial_open(p);
if (status < 0)
if (status < 0) {
return status; return status;
if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET && }
p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) {
if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET
&& p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) {
status = ser_set_rts(p, status = ser_set_rts(p,
p->parm.serial.rts_state == RIG_SIGNAL_ON); p->parm.serial.rts_state == RIG_SIGNAL_ON);
want_state_delay = 1; want_state_delay = 1;
} }
if (status != 0)
if (status != 0) {
return status; return status;
}
if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) { if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) {
status = ser_set_dtr(p, status = ser_set_dtr(p,
p->parm.serial.dtr_state == RIG_SIGNAL_ON); p->parm.serial.dtr_state == RIG_SIGNAL_ON);
want_state_delay = 1; want_state_delay = 1;
} }
if (status != 0)
if (status != 0) {
return status; return status;
}
/* /*
* Wait whatever electrolytics in the circuit come up to voltage. * Wait whatever electrolytics in the circuit come up to voltage.
* Is 100ms enough? Too much? * Is 100ms enough? Too much?
*/ */
if (want_state_delay) if (want_state_delay) {
usleep(100 * 1000); usleep(100 * 1000);
}
break; break;
case RIG_PORT_PARALLEL: case RIG_PORT_PARALLEL:
status = par_open(p); status = par_open(p);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
case RIG_PORT_CM108: case RIG_PORT_CM108:
status = cm108_open(p); status = cm108_open(p);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
case RIG_PORT_DEVICE: case RIG_PORT_DEVICE:
status = open(p->pathname, O_RDWR, 0); status = open(p->pathname, O_RDWR, 0);
if (status < 0)
if (status < 0) {
return -RIG_EIO; return -RIG_EIO;
}
p->fd = status; p->fd = status;
break; break;
case RIG_PORT_USB: case RIG_PORT_USB:
status = usb_port_open(p); status = usb_port_open(p);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
case RIG_PORT_NONE: case RIG_PORT_NONE:
@ -128,8 +152,11 @@ int HAMLIB_API port_open(hamlib_port_t *p)
case RIG_PORT_UDP_NETWORK: case RIG_PORT_UDP_NETWORK:
/* FIXME: hardcoded network port */ /* FIXME: hardcoded network port */
status = network_open(p, 4532); status = network_open(p, 4532);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
default: default:
@ -139,6 +166,7 @@ int HAMLIB_API port_open(hamlib_port_t *p)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Close a hamlib_port * \brief Close a hamlib_port
* \param p rig port descriptor * \param p rig port descriptor
@ -151,20 +179,26 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type)
{ {
int ret = RIG_OK; int ret = RIG_OK;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (p->fd != -1) { if (p->fd != -1) {
switch (port_type) { switch (port_type) {
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
ret = ser_close(p); ret = ser_close(p);
break; break;
case RIG_PORT_PARALLEL: case RIG_PORT_PARALLEL:
ret = par_close(p); ret = par_close(p);
break; break;
case RIG_PORT_CM108: case RIG_PORT_CM108:
ret = cm108_close(p); ret = cm108_close(p);
break; break;
case RIG_PORT_USB: case RIG_PORT_USB:
ret = usb_port_close(p); ret = usb_port_close(p);
break; break;
case RIG_PORT_NETWORK: case RIG_PORT_NETWORK:
case RIG_PORT_UDP_NETWORK: case RIG_PORT_UDP_NETWORK:
ret = network_close(p); ret = network_close(p);
@ -173,19 +207,23 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type)
default: default:
rig_debug(RIG_DEBUG_ERR, "%s(): Unknown port type %d\n", rig_debug(RIG_DEBUG_ERR, "%s(): Unknown port type %d\n",
__func__, port_type); __func__, port_type);
/* fall through */ /* fall through */
case RIG_PORT_DEVICE: case RIG_PORT_DEVICE:
ret = close(p->fd); ret = close(p->fd);
} }
p->fd = -1; p->fd = -1;
} }
return ret; return ret;
} }
#if defined(WIN32) && !defined(HAVE_TERMIOS_H) #if defined(WIN32) && !defined(HAVE_TERMIOS_H)
#include "win32termios.h" #include "win32termios.h"
/* On MinGW32/MSVC/.. the appropriate accessor must be used /* On MinGW32/MSVC/.. the appropriate accessor must be used
* depending on the port type, sigh. * depending on the port type, sigh.
*/ */
@ -196,49 +234,65 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
if (p->type.rig == RIG_PORT_SERIAL) { if (p->type.rig == RIG_PORT_SERIAL) {
ret = win32_serial_read(p->fd, buf, count); ret = win32_serial_read(p->fd, buf, count);
if (p->parm.serial.data_bits == 7) { if (p->parm.serial.data_bits == 7) {
unsigned char *pbuf = buf; unsigned char *pbuf = buf;
/* clear MSB */ /* clear MSB */
for (i = 0; i < ret; i++) { for (i = 0; i < ret; i++) {
pbuf[i] &= ~0x80; pbuf[i] &= ~0x80;
} }
} }
return ret; return ret;
} else if (p->type.rig == RIG_PORT_NETWORK || p->type.rig == RIG_PORT_UDP_NETWORK) } else if (p->type.rig == RIG_PORT_NETWORK
|| p->type.rig == RIG_PORT_UDP_NETWORK) {
return recv(p->fd, buf, count, 0); return recv(p->fd, buf, count, 0);
else } else {
return read(p->fd, buf, count); return read(p->fd, buf, count);
} }
}
static ssize_t port_write(hamlib_port_t *p, const void *buf, size_t count) static ssize_t port_write(hamlib_port_t *p, const void *buf, size_t count)
{ {
if (p->type.rig == RIG_PORT_SERIAL) if (p->type.rig == RIG_PORT_SERIAL) {
return win32_serial_write(p->fd, buf, count); return win32_serial_write(p->fd, buf, count);
else if (p->type.rig == RIG_PORT_NETWORK || p->type.rig == RIG_PORT_UDP_NETWORK) } else if (p->type.rig == RIG_PORT_NETWORK
|| p->type.rig == RIG_PORT_UDP_NETWORK) {
return send(p->fd, buf, count, 0); return send(p->fd, buf, count, 0);
else } else {
return write(p->fd, buf, count); return write(p->fd, buf, count);
} }
}
static int port_select(hamlib_port_t *p, int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
static int port_select(hamlib_port_t *p, int n, fd_set *readfds,
fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{ {
#if 1 #if 1
/* select does not work very well with writefds/exceptfds /* select does not work very well with writefds/exceptfds
* So let's pretend there's none of them * So let's pretend there's none of them
*/ */
if (exceptfds) if (exceptfds) {
FD_ZERO(exceptfds); FD_ZERO(exceptfds);
if (writefds) }
if (writefds) {
FD_ZERO(writefds); FD_ZERO(writefds);
}
writefds = NULL; writefds = NULL;
exceptfds = NULL; exceptfds = NULL;
#endif #endif
if (p->type.rig == RIG_PORT_SERIAL) if (p->type.rig == RIG_PORT_SERIAL) {
return win32_serial_select(n, readfds, writefds, exceptfds, timeout); return win32_serial_select(n, readfds, writefds, exceptfds, timeout);
else } else {
return select(n, readfds, writefds, exceptfds, timeout); return select(n, readfds, writefds, exceptfds, timeout);
} }
}
#else #else
@ -254,10 +308,12 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
unsigned char *pbuf = buf; unsigned char *pbuf = buf;
ret = read(p->fd, buf, count); ret = read(p->fd, buf, count);
/* clear MSB */ /* clear MSB */
for (i = 0; i < ret; i++) { for (i = 0; i < ret; i++) {
pbuf[i] &= ~0x80; pbuf[i] &= ~0x80;
} }
return ret; return ret;
} else { } else {
return read(p->fd, buf, count); return read(p->fd, buf, count);
@ -302,7 +358,10 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
{ {
int i, ret; int i, ret;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
if (p->post_write_date.tv_sec != 0) { if (p->post_write_date.tv_sec != 0) {
signed int date_delay; /* in us */ signed int date_delay; /* in us */
struct timeval tv; struct timeval tv;
@ -312,28 +371,34 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
date_delay = p->post_write_delay * 1000 - date_delay = p->post_write_delay * 1000 -
((tv.tv_sec - p->post_write_date.tv_sec) * 1000000 + ((tv.tv_sec - p->post_write_date.tv_sec) * 1000000 +
(tv.tv_usec - p->post_write_date.tv_usec)); (tv.tv_usec - p->post_write_date.tv_usec));
if (date_delay > 0) { if (date_delay > 0) {
/* /*
* optional delay after last write * optional delay after last write
*/ */
usleep(date_delay); usleep(date_delay);
} }
p->post_write_date.tv_sec = 0; p->post_write_date.tv_sec = 0;
} }
#endif #endif
if (p->write_delay > 0) { if (p->write_delay > 0) {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ret = port_write(p, txbuffer + i, 1); ret = port_write(p, txbuffer + i, 1);
if (ret != 1) { if (ret != 1) {
rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n", rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n",
__func__, __LINE__, ret, strerror(errno)); __func__, __LINE__, ret, strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
usleep(p->write_delay * 1000); usleep(p->write_delay * 1000);
} }
} else { } else {
ret = port_write(p, txbuffer, count); ret = port_write(p, txbuffer, count);
if (ret != count) { if (ret != count) {
rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n", rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n",
__func__, __LINE__, ret, strerror(errno)); __func__, __LINE__, ret, strerror(errno));
@ -350,13 +415,14 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
p->post_write_date.tv_sec = tv.tv_sec; p->post_write_date.tv_sec = tv.tv_sec;
p->post_write_date.tv_usec = tv.tv_usec; p->post_write_date.tv_usec = tv.tv_usec;
} } else
else
#endif #endif
usleep(p->post_write_delay * 1000); /* optional delay after last write */ usleep(p->post_write_delay * 1000); /* optional delay after last write */
/* otherwise some yaesu rigs get confused */ /* otherwise some yaesu rigs get confused */
/* with sequential fast writes*/ /* with sequential fast writes*/
} }
rig_debug(RIG_DEBUG_TRACE, "%s(): TX %d bytes\n", __func__, count); rig_debug(RIG_DEBUG_TRACE, "%s(): TX %d bytes\n", __func__, count);
dump_hex((unsigned char *) txbuffer, count); dump_hex((unsigned char *) txbuffer, count);
@ -389,6 +455,7 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
int rd_count, total_count = 0; int rd_count, total_count = 0;
int retval; int retval;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* /*
* Wait up to timeout ms. * Wait up to timeout ms.
@ -407,27 +474,39 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
efds = rfds; efds = rfds;
retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv);
if (retval == 0) { if (retval == 0) {
/* Record timeout time and caculate elapsed time */ /* Record timeout time and caculate elapsed time */
gettimeofday(&end_time, NULL); gettimeofday(&end_time, NULL);
timersub(&end_time, &start_time, &elapsed_time); timersub(&end_time, &start_time, &elapsed_time);
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_WARN, "%s(): Timed out %d.%d seconds after %d chars\n", rig_debug(RIG_DEBUG_WARN,
__func__, elapsed_time.tv_sec, elapsed_time.tv_usec, total_count); "%s(): Timed out %d.%d seconds after %d chars\n",
__func__,
elapsed_time.tv_sec,
elapsed_time.tv_usec,
total_count);
return -RIG_ETIMEOUT; return -RIG_ETIMEOUT;
} }
if (retval < 0) { if (retval < 0) {
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_ERR,"%s(): select() error after %d chars: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, total_count, strerror(errno)); "%s(): select() error after %d chars: %s\n",
__func__,
total_count,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
if (FD_ISSET(p->fd, &efds)) { if (FD_ISSET(p->fd, &efds)) {
rig_debug(RIG_DEBUG_ERR, "%s(): fd error after %d chars\n", rig_debug(RIG_DEBUG_ERR,
__func__, total_count); "%s(): fd error after %d chars\n",
__func__,
total_count);
return -RIG_EIO; return -RIG_EIO;
} }
@ -437,12 +516,16 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
* The file descriptor must have been set up non blocking. * The file descriptor must have been set up non blocking.
*/ */
rd_count = port_read(p, rxbuffer + total_count, count); rd_count = port_read(p, rxbuffer + total_count, count);
if (rd_count < 0) { if (rd_count < 0) {
rig_debug(RIG_DEBUG_ERR, "%s(): read() failed - %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, strerror(errno)); "%s(): read() failed - %s\n",
__func__,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
total_count += rd_count; total_count += rd_count;
count -= rd_count; count -= rd_count;
} }
@ -479,7 +562,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
* *
* Assumes rxbuffer!=NULL * Assumes rxbuffer!=NULL
*/ */
int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const char *stopset, int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
const char *stopset,
int stopset_len) int stopset_len)
{ {
fd_set rfds, efds; fd_set rfds, efds;
@ -487,8 +571,15 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
int rd_count, total_count = 0; int rd_count, total_count = 0;
int retval; int retval;
if (!p || !rxbuffer) return -RIG_EINVAL; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (rxmax < 1) return 0;
if (!p || !rxbuffer) {
return -RIG_EINVAL;
}
if (rxmax < 1) {
return 0;
}
/* /*
* Wait up to timeout ms. * Wait up to timeout ms.
@ -507,6 +598,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
efds = rfds; efds = rfds;
retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv);
if (retval == 0) { if (retval == 0) {
if (0 == total_count) { if (0 == total_count) {
/* Record timeout time and caculate elapsed time */ /* Record timeout time and caculate elapsed time */
@ -514,24 +606,35 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
timersub(&end_time, &start_time, &elapsed_time); timersub(&end_time, &start_time, &elapsed_time);
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_WARN, "%s(): Timed out %d.%d seconds after %d chars\n", rig_debug(RIG_DEBUG_WARN,
__func__, elapsed_time.tv_sec, elapsed_time.tv_usec, total_count); "%s(): Timed out %d.%d seconds after %d chars\n",
__func__,
elapsed_time.tv_sec,
elapsed_time.tv_usec,
total_count);
return -RIG_ETIMEOUT; return -RIG_ETIMEOUT;
} }
break; /* return what we have read */ break; /* return what we have read */
} }
if (retval < 0) { if (retval < 0) {
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_ERR, "%s(): select() error after %d chars: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, total_count, strerror(errno)); "%s(): select() error after %d chars: %s\n",
__func__,
total_count,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
if (FD_ISSET(p->fd, &efds)) { if (FD_ISSET(p->fd, &efds)) {
rig_debug(RIG_DEBUG_ERR, "%s(): fd error after %d chars\n", rig_debug(RIG_DEBUG_ERR,
__func__, total_count); "%s(): fd error after %d chars\n",
__func__,
total_count);
return -RIG_EIO; return -RIG_EIO;
} }
@ -541,24 +644,34 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
* The file descriptor must have been set up non blocking. * The file descriptor must have been set up non blocking.
*/ */
rd_count = port_read(p, &rxbuffer[total_count], 1); rd_count = port_read(p, &rxbuffer[total_count], 1);
if (rd_count < 0) { if (rd_count < 0) {
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_ERR, "%s(): read() failed - %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, strerror(errno)); "%s(): read() failed - %s\n",
__func__,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
++total_count; ++total_count;
if (stopset && memchr(stopset, rxbuffer[total_count-1], stopset_len))
if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len)) {
break; break;
} }
}
/* /*
* Doesn't hurt anyway. But be aware, some binary protocols may have * Doesn't hurt anyway. But be aware, some binary protocols may have
* null chars within th received buffer. * null chars within th received buffer.
*/ */
rxbuffer[total_count] = '\000'; rxbuffer[total_count] = '\000';
rig_debug(RIG_DEBUG_TRACE,"%s(): RX %d characters\n", __func__, total_count); rig_debug(RIG_DEBUG_TRACE,
"%s(): RX %d characters\n",
__func__,
total_count);
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
return total_count; /* return bytes count read */ return total_count; /* return bytes count read */

Wyświetl plik

@ -29,9 +29,19 @@
extern HAMLIB_EXPORT(int) port_open(hamlib_port_t *p); extern HAMLIB_EXPORT(int) port_open(hamlib_port_t *p);
extern HAMLIB_EXPORT(int) port_close(hamlib_port_t *p, rig_port_t port_type); extern HAMLIB_EXPORT(int) port_close(hamlib_port_t *p, rig_port_t port_type);
extern HAMLIB_EXPORT(int) read_block(hamlib_port_t *p, char *rxbuffer, size_t count);
extern HAMLIB_EXPORT(int) write_block(hamlib_port_t *p, const char *txbuffer, size_t count); extern HAMLIB_EXPORT(int) read_block(hamlib_port_t *p,
extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const char *stopset, int stopset_len); char *rxbuffer,
size_t count);
extern HAMLIB_EXPORT(int) write_block(hamlib_port_t *p,
const char *txbuffer,
size_t count);
extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p,
char *rxbuffer,
size_t rxmax,
const char *stopset,
int stopset_len);
#endif /* _IOFUNC_H */ #endif /* _IOFUNC_H */

Wyświetl plik

@ -117,6 +117,7 @@ const static int loc_char_range[] = { 18, 10, 24, 10, 24, 10 };
#endif /* !DOC_HIDDEN */ #endif /* !DOC_HIDDEN */
/** /**
* \brief Convert DMS to decimal degrees * \brief Convert DMS to decimal degrees
* \param degrees Degrees, whole degrees * \param degrees Degrees, whole degrees
@ -137,24 +138,33 @@ const static int loc_char_range[] = { 18, 10, 24, 10, 24, 10 };
* *
* \sa dec2dms() * \sa dec2dms()
*/ */
double HAMLIB_API dms2dec(int degrees, int minutes, double seconds, int sw)
double HAMLIB_API dms2dec(int degrees, int minutes, double seconds, int sw) { {
double st; double st;
if (degrees < 0) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (degrees < 0) {
degrees = abs(degrees); degrees = abs(degrees);
if (minutes < 0) }
if (minutes < 0) {
minutes = abs(minutes); minutes = abs(minutes);
if (seconds < 0) }
if (seconds < 0) {
seconds = fabs(seconds); seconds = fabs(seconds);
}
st = (double)degrees + (double)minutes / 60. + seconds / 3600.; st = (double)degrees + (double)minutes / 60. + seconds / 3600.;
if (sw == 1) if (sw == 1) {
return -st; return -st;
else } else {
return st; return st;
} }
}
/** /**
* \brief Convert D M.MMM notation to decimal degrees * \brief Convert D M.MMM notation to decimal degrees
@ -177,22 +187,29 @@ double HAMLIB_API dms2dec(int degrees, int minutes, double seconds, int sw) {
* *
* \sa dec2dmmm() * \sa dec2dmmm()
*/ */
double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw)
double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw) { {
double st; double st;
if (degrees < 0) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (degrees < 0) {
degrees = abs(degrees); degrees = abs(degrees);
if (minutes < 0) }
if (minutes < 0) {
minutes = fabs(minutes); minutes = fabs(minutes);
}
st = (double)degrees + minutes / 60.; st = (double)degrees + minutes / 60.;
if (sw == 1) if (sw == 1) {
return -st; return -st;
else } else {
return st; return st;
} }
}
/** /**
* \brief Convert decimal degrees angle into DMS notation * \brief Convert decimal degrees angle into DMS notation
@ -221,14 +238,18 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw) {
* *
* \sa dms2dec() * \sa dms2dec()
*/ */
int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds, int *sw) { int *sw)
{
int deg, min; int deg, min;
double st; double st;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!degrees || !minutes || !seconds || !sw) if (!degrees || !minutes || !seconds || !sw) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
/* reverse the sign if dec has a magnitude greater /* reverse the sign if dec has a magnitude greater
* than 180 and factor out multiples of 360. * than 180 and factor out multiples of 360.
@ -237,19 +258,21 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
* passed 361 st will be set to 1, etc. If passed * passed 361 st will be set to 1, etc. If passed
* a value > -180 || < 180, value will be unchanged. * a value > -180 || < 180, value will be unchanged.
*/ */
if (dec >= 0.0) if (dec >= 0.0) {
st = fmod(dec + 180, 360) - 180; st = fmod(dec + 180, 360) - 180;
else } else {
st = fmod(dec - 180, 360) + 180; st = fmod(dec - 180, 360) + 180;
}
/* if after all of that st is negative, we want deg /* if after all of that st is negative, we want deg
* to be negative as well except for 180 which we want * to be negative as well except for 180 which we want
* to be positive. * to be positive.
*/ */
if (st < 0.0 && st != -180) if (st < 0.0 && st != -180) {
*sw = 1; *sw = 1;
else } else {
*sw = 0; *sw = 0;
}
/* work on st as a positive value to remove a /* work on st as a positive value to remove a
* bug introduced by the effect of floor() when * bug introduced by the effect of floor() when
@ -271,6 +294,7 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Convert a decimal angle into D M.MMM notation * \brief Convert a decimal angle into D M.MMM notation
* \param dec Decimal degrees * \param dec Decimal degrees
@ -297,24 +321,30 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
* *
* \sa dmmm2dec() * \sa dmmm2dec()
*/ */
int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw)
int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw) { {
int r, min; int r, min;
double sec; double sec;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!degrees || !minutes || !sw) if (!degrees || !minutes || !sw) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
r = dec2dms(dec, degrees, &min, &sec, sw); r = dec2dms(dec, degrees, &min, &sec, sw);
if (r != RIG_OK)
if (r != RIG_OK) {
return r; return r;
}
*minutes = (double)min + sec / 60; *minutes = (double)min + sec / 60;
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Convert Maidenhead grid locator to Longitude/Latitude * \brief Convert Maidenhead grid locator to Longitude/Latitude
* \param longitude Pointer for the calculated Longitude * \param longitude Pointer for the calculated Longitude
@ -342,24 +372,29 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw) {
*/ */
/* begin dph */ /* begin dph */
int HAMLIB_API locator2longlat(double *longitude, double *latitude,
int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char *locator) { const char *locator)
{
int x_or_y, paircount; int x_or_y, paircount;
int locvalue, pair; int locvalue, pair;
int divisions; int divisions;
double xy[2], ordinate; double xy[2], ordinate;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!longitude || !latitude) if (!longitude || !latitude) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
paircount = strlen(locator) / 2; paircount = strlen(locator) / 2;
/* verify paircount is within limits */ /* verify paircount is within limits */
if (paircount > MAX_LOCATOR_PAIRS) if (paircount > MAX_LOCATOR_PAIRS) {
paircount = MAX_LOCATOR_PAIRS; paircount = MAX_LOCATOR_PAIRS;
else if (paircount < MIN_LOCATOR_PAIRS) } else if (paircount < MIN_LOCATOR_PAIRS) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
/* For x(=longitude) and y(=latitude) */ /* For x(=longitude) and y(=latitude) */
for (x_or_y = 0; x_or_y < 2; ++x_or_y) { for (x_or_y = 0; x_or_y < 2; ++x_or_y) {
@ -374,12 +409,14 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char *
(isupper(locvalue)) ? 'A' : 'a'; (isupper(locvalue)) ? 'A' : 'a';
/* Check range for non-letter/digit or out of range */ /* Check range for non-letter/digit or out of range */
if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
divisions *= loc_char_range[pair]; divisions *= loc_char_range[pair];
ordinate += locvalue * 180.0 / divisions; ordinate += locvalue * 180.0 / divisions;
} }
/* Center ordinate in the Maidenhead "square" or "subsquare" */ /* Center ordinate in the Maidenhead "square" or "subsquare" */
ordinate += 90.0 / divisions; ordinate += 90.0 / divisions;
@ -393,6 +430,7 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char *
} }
/* end dph */ /* end dph */
/** /**
* \brief Convert longitude/latitude to Maidenhead grid locator * \brief Convert longitude/latitude to Maidenhead grid locator
* \param longitude Longitude, decimal degrees * \param longitude Longitude, decimal degrees
@ -416,16 +454,21 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char *
*/ */
/* begin dph */ /* begin dph */
int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, int pair_count) { int pair_count)
{
int x_or_y, pair, locvalue, divisions; int x_or_y, pair, locvalue, divisions;
double square_size, ordinate; double square_size, ordinate;
if (!locator) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
if (pair_count < MIN_LOCATOR_PAIRS || pair_count > MAX_LOCATOR_PAIRS) if (!locator) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (pair_count < MIN_LOCATOR_PAIRS || pair_count > MAX_LOCATOR_PAIRS) {
return -RIG_EINVAL;
}
for (x_or_y = 0; x_or_y < 2; ++x_or_y) { for (x_or_y = 0; x_or_y < 2; ++x_or_y) {
ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude;
@ -433,6 +476,7 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
/* The 1e-6 here guards against floating point rounding errors */ /* The 1e-6 here guards against floating point rounding errors */
ordinate = fmod(ordinate + 270.000001, 180.0); ordinate = fmod(ordinate + 270.000001, 180.0);
for (pair = 0; pair < pair_count; ++pair) { for (pair = 0; pair < pair_count; ++pair) {
divisions *= loc_char_range[pair]; divisions *= loc_char_range[pair];
square_size = 180.0 / divisions; square_size = 180.0 / divisions;
@ -443,13 +487,14 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
locator[pair * 2 + x_or_y] = locvalue; locator[pair * 2 + x_or_y] = locvalue;
} }
} }
locator[pair_count * 2] = '\0'; locator[pair_count * 2] = '\0';
return RIG_OK; return RIG_OK;
} }
/* end dph */ /* end dph */
/** /**
* \brief Calculate the distance and bearing between two points. * \brief Calculate the distance and bearing between two points.
* \param lon1 The local Longitude, decimal degrees * \param lon1 The local Longitude, decimal degrees
@ -475,30 +520,38 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
* *
* \sa distance_long_path(), azimuth_long_path() * \sa distance_long_path(), azimuth_long_path()
*/ */
int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2,
int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2, double *distance, double *azimuth) { double *distance, double *azimuth)
{
double delta_long, tmp, arc, az; double delta_long, tmp, arc, az;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!distance || !azimuth) if (!distance || !azimuth) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0)) if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0)) if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
/* Prevent ACOS() Domain Error */ /* Prevent ACOS() Domain Error */
if (lat1 == 90.0) if (lat1 == 90.0) {
lat1 = 89.999999999; lat1 = 89.999999999;
else if (lat1 == -90.0) } else if (lat1 == -90.0) {
lat1 = -89.999999999; lat1 = -89.999999999;
}
if (lat2 == 90.0) if (lat2 == 90.0) {
lat2 = 89.999999999; lat2 = 89.999999999;
else if (lat2 == -90.0) } else if (lat2 == -90.0) {
lat2 = -89.999999999; lat2 = -89.999999999;
}
/* Convert variables to Radians */ /* Convert variables to Radians */
lat1 /= RADIAN; lat1 /= RADIAN;
@ -536,26 +589,27 @@ int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2, double *d
* at the surface of the earth, 111.2 km, or 69.1 sm * at the surface of the earth, 111.2 km, or 69.1 sm
* This method is easier than the one in the handbook * This method is easier than the one in the handbook
*/ */
*distance = ARC_IN_KM * RADIAN * arc; *distance = ARC_IN_KM * RADIAN * arc;
/* Short Path */ /* Short Path */
/* Change to azimuth computation by Dave Freese, W1HKJ */ /* Change to azimuth computation by Dave Freese, W1HKJ */
az = RADIAN * atan2(sin(lon2 - lon1) * cos(lat2), az = RADIAN * atan2(sin(lon2 - lon1) * cos(lat2),
(cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1))); (cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1)));
az = fmod(360.0 + az, 360.0); az = fmod(360.0 + az, 360.0);
if (az < 0.0)
if (az < 0.0) {
az += 360.0; az += 360.0;
else if (az >= 360.0) } else if (az >= 360.0) {
az -= 360.0; az -= 360.0;
}
*azimuth = floor(az + 0.5); *azimuth = floor(az + 0.5);
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Calculate the long path distance between two points. * \brief Calculate the long path distance between two points.
* \param distance The shortpath distance * \param distance The shortpath distance
@ -567,11 +621,14 @@ int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2, double *d
* *
* \sa qrb() * \sa qrb()
*/ */
double HAMLIB_API distance_long_path(double distance)
{
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
double HAMLIB_API distance_long_path(double distance) {
return (ARC_IN_KM * 360.0) - distance; return (ARC_IN_KM * 360.0) - distance;
} }
/** /**
* \brief Calculate the long path bearing between two points. * \brief Calculate the long path bearing between two points.
* \param azimuth The shortpath bearing--0.0 to 360.0 degrees * \param azimuth The shortpath bearing--0.0 to 360.0 degrees
@ -584,18 +641,21 @@ double HAMLIB_API distance_long_path(double distance) {
* *
* \sa qrb() * \sa qrb()
*/ */
double HAMLIB_API azimuth_long_path(double azimuth)
{
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
double HAMLIB_API azimuth_long_path(double azimuth) { if (azimuth == 0.0 || azimuth == 360.0) {
if (azimuth == 0.0 || azimuth == 360.0)
return 180.0; return 180.0;
else if (azimuth > 0.0 && azimuth < 180.0) } else if (azimuth > 0.0 && azimuth < 180.0) {
return 180.0 + azimuth; return 180.0 + azimuth;
else if (azimuth == 180.0) } else if (azimuth == 180.0) {
return 0.0; return 0.0;
else if (azimuth > 180.0 && azimuth < 360.0) } else if (azimuth > 180.0 && azimuth < 360.0) {
return (180.0 - azimuth) * -1.0; return (180.0 - azimuth) * -1.0;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
} }
}
/*! @} */ /*! @} */

536
src/mem.c

Plik diff jest za duży Load Diff

Wyświetl plik

@ -51,6 +51,7 @@
#include "misc.h" #include "misc.h"
/** /**
* \brief Convert from binary to 4-bit BCD digits, little-endian * \brief Convert from binary to 4-bit BCD digits, little-endian
* \param bcd_data * \param bcd_data
@ -71,11 +72,15 @@
* *
* \sa to_bcd_be * \sa to_bcd_be
*/ */
unsigned char * HAMLIB_API to_bcd(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len) unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
unsigned long long freq,
unsigned bcd_len)
{ {
int i; int i;
unsigned char a; unsigned char a;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* '450'/4-> 5,0;0,4 */ /* '450'/4-> 5,0;0,4 */
/* '450'/3-> 5,0;x,4 */ /* '450'/3-> 5,0;x,4 */
@ -86,6 +91,7 @@ unsigned char * HAMLIB_API to_bcd(unsigned char bcd_data[], unsigned long long f
freq /= 10; freq /= 10;
bcd_data[i] = a; bcd_data[i] = a;
} }
if (bcd_len & 1) { if (bcd_len & 1) {
bcd_data[i] &= 0xf0; bcd_data[i] &= 0xf0;
bcd_data[i] |= freq % 10; /* NB: high nibble is left uncleared */ bcd_data[i] |= freq % 10; /* NB: high nibble is left uncleared */
@ -94,6 +100,7 @@ unsigned char * HAMLIB_API to_bcd(unsigned char bcd_data[], unsigned long long f
return bcd_data; return bcd_data;
} }
/** /**
* \brief Convert BCD digits, little-endian, to a long long (e.g. frequency in Hz) * \brief Convert BCD digits, little-endian, to a long long (e.g. frequency in Hz)
* \param bcd_data * \param bcd_data
@ -111,13 +118,17 @@ unsigned char * HAMLIB_API to_bcd(unsigned char bcd_data[], unsigned long long f
* *
* \sa from_bcd_be * \sa from_bcd_be
*/ */
unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], unsigned bcd_len) unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[],
unsigned bcd_len)
{ {
int i; int i;
freq_t f = 0; freq_t f = 0;
if (bcd_len&1) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (bcd_len & 1) {
f = bcd_data[bcd_len / 2] & 0x0f; f = bcd_data[bcd_len / 2] & 0x0f;
}
for (i = (bcd_len / 2) - 1; i >= 0; i--) { for (i = (bcd_len / 2) - 1; i >= 0; i--) {
f *= 10; f *= 10;
@ -129,6 +140,7 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], unsigned
return f; return f;
} }
/** /**
* \brief Convert from binary to 4-bit BCD digits, big-endian * \brief Convert from binary to 4-bit BCD digits, big-endian
* \param bcd_data * \param bcd_data
@ -141,7 +153,9 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], unsigned
* *
* \sa to_bcd * \sa to_bcd
*/ */
unsigned char * HAMLIB_API to_bcd_be(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len) unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[],
unsigned long long freq,
unsigned bcd_len)
{ {
int i; int i;
unsigned char a; unsigned char a;
@ -149,11 +163,15 @@ unsigned char * HAMLIB_API to_bcd_be(unsigned char bcd_data[], unsigned long lon
/* '450'/4 -> 0,4;5,0 */ /* '450'/4 -> 0,4;5,0 */
/* '450'/3 -> 4,5;0,x */ /* '450'/3 -> 4,5;0,x */
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (bcd_len & 1) { if (bcd_len & 1) {
bcd_data[bcd_len / 2] &= 0x0f; bcd_data[bcd_len / 2] &= 0x0f;
bcd_data[bcd_len/2] |= (freq%10)<<4; /* NB: low nibble is left uncleared */ bcd_data[bcd_len / 2] |= (freq % 10) <<
4; /* NB: low nibble is left uncleared */
freq /= 10; freq /= 10;
} }
for (i = (bcd_len / 2) - 1; i >= 0; i--) { for (i = (bcd_len / 2) - 1; i >= 0; i--) {
a = freq % 10; a = freq % 10;
freq /= 10; freq /= 10;
@ -165,6 +183,7 @@ unsigned char * HAMLIB_API to_bcd_be(unsigned char bcd_data[], unsigned long lon
return bcd_data; return bcd_data;
} }
/** /**
* \brief Convert 4-bit BCD digits to binary, big-endian * \brief Convert 4-bit BCD digits to binary, big-endian
* \param bcd_data * \param bcd_data
@ -176,17 +195,21 @@ unsigned char * HAMLIB_API to_bcd_be(unsigned char bcd_data[], unsigned long lon
* *
* \sa from_bcd * \sa from_bcd
*/ */
unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[], unsigned bcd_len) unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[],
unsigned bcd_len)
{ {
int i; int i;
freq_t f = 0; freq_t f = 0;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0; i < bcd_len / 2; i++) { for (i = 0; i < bcd_len / 2; i++) {
f *= 10; f *= 10;
f += bcd_data[i] >> 4; f += bcd_data[i] >> 4;
f *= 10; f *= 10;
f += bcd_data[i] & 0x0f; f += bcd_data[i] & 0x0f;
} }
if (bcd_len & 1) { if (bcd_len & 1) {
f *= 10; f *= 10;
f += bcd_data[bcd_len / 2] >> 4; f += bcd_data[bcd_len / 2] >> 4;
@ -200,6 +223,7 @@ unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[], unsign
#define llabs(a) ((a)<0?-(a):(a)) #define llabs(a) ((a)<0?-(a):(a))
#endif #endif
/** /**
* \brief Pretty print a frequency * \brief Pretty print a frequency
* \param str for result (may need up to 17 char) * \param str for result (may need up to 17 char)
@ -214,6 +238,8 @@ int HAMLIB_API sprintf_freq(char *str, freq_t freq)
double f; double f;
char *hz; char *hz;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (llabs(freq) >= GHz(1)) { if (llabs(freq) >= GHz(1)) {
hz = "GHz"; hz = "GHz";
f = (double)freq / GHz(1); f = (double)freq / GHz(1);
@ -231,6 +257,7 @@ int HAMLIB_API sprintf_freq(char *str, freq_t freq)
return sprintf(str, "%g %s", f, hz); return sprintf(str, "%g %s", f, hz);
} }
/** /**
* \brief Convert enum RIG_STATUS_... to printable string * \brief Convert enum RIG_STATUS_... to printable string
* \param status RIG_STATUS_?? * \param status RIG_STATUS_??
@ -238,18 +265,25 @@ int HAMLIB_API sprintf_freq(char *str, freq_t freq)
*/ */
const char * HAMLIB_API rig_strstatus(enum rig_status_e status) const char * HAMLIB_API rig_strstatus(enum rig_status_e status)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (status) { switch (status) {
case RIG_STATUS_ALPHA: case RIG_STATUS_ALPHA:
return "Alpha"; return "Alpha";
case RIG_STATUS_UNTESTED: case RIG_STATUS_UNTESTED:
return "Untested"; return "Untested";
case RIG_STATUS_BETA: case RIG_STATUS_BETA:
return "Beta"; return "Beta";
case RIG_STATUS_STABLE: case RIG_STATUS_STABLE:
return "Stable"; return "Stable";
case RIG_STATUS_BUGGY: case RIG_STATUS_BUGGY:
return "Buggy"; return "Buggy";
} }
return ""; return "";
} }
@ -281,6 +315,7 @@ static struct {
{ RIG_MODE_NONE, "" }, { RIG_MODE_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to enum RIG_MODE * \brief Convert alpha string to enum RIG_MODE
* \param s input alpha string * \param s input alpha string
@ -292,12 +327,17 @@ rmode_t HAMLIB_API rig_parse_mode(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; mode_str[i].str[0] != '\0'; i++) for (i = 0 ; mode_str[i].str[0] != '\0'; i++)
if (!strcmp(s, mode_str[i].str)) if (!strcmp(s, mode_str[i].str)) {
return mode_str[i].mode; return mode_str[i].mode;
}
return RIG_MODE_NONE; return RIG_MODE_NONE;
} }
/** /**
* \brief Convert enum RIG_MODE to alpha string * \brief Convert enum RIG_MODE to alpha string
* \param mode RIG_MODE_... * \param mode RIG_MODE_...
@ -309,16 +349,21 @@ const char * HAMLIB_API rig_strrmode(rmode_t mode)
{ {
int i; int i;
if (mode == RIG_MODE_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (mode == RIG_MODE_NONE) {
return ""; return "";
}
for (i = 0 ; mode_str[i].str[0] != '\0'; i++) for (i = 0 ; mode_str[i].str[0] != '\0'; i++)
if (mode == mode_str[i].mode) if (mode == mode_str[i].mode) {
return mode_str[i].str; return mode_str[i].str;
}
return ""; return "";
} }
static struct { static struct {
vfo_t vfo; vfo_t vfo;
const char *str; const char *str;
@ -336,6 +381,7 @@ static struct {
{ RIG_VFO_NONE, "" }, { RIG_VFO_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to enum RIG_VFO_... * \brief Convert alpha string to enum RIG_VFO_...
* \param s input alpha string * \param s input alpha string
@ -347,12 +393,17 @@ vfo_t HAMLIB_API rig_parse_vfo(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; vfo_str[i].str[0] != '\0'; i++) for (i = 0 ; vfo_str[i].str[0] != '\0'; i++)
if (!strcmp(s, vfo_str[i].str)) if (!strcmp(s, vfo_str[i].str)) {
return vfo_str[i].vfo; return vfo_str[i].vfo;
}
return RIG_VFO_NONE; return RIG_VFO_NONE;
} }
/** /**
* \brief Convert enum RIG_VFO_... to alpha string * \brief Convert enum RIG_VFO_... to alpha string
* \param vfo RIG_VFO_... * \param vfo RIG_VFO_...
@ -364,16 +415,21 @@ const char * HAMLIB_API rig_strvfo(vfo_t vfo)
{ {
int i; int i;
if (vfo == RIG_VFO_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (vfo == RIG_VFO_NONE) {
return ""; return "";
}
for (i = 0 ; vfo_str[i].str[0] != '\0'; i++) for (i = 0 ; vfo_str[i].str[0] != '\0'; i++)
if (vfo == vfo_str[i].vfo) if (vfo == vfo_str[i].vfo) {
return vfo_str[i].str; return vfo_str[i].str;
}
return ""; return "";
} }
static struct { static struct {
setting_t func; setting_t func;
const char *str; const char *str;
@ -413,6 +469,7 @@ static struct {
{ RIG_FUNC_NONE, "" }, { RIG_FUNC_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to enum RIG_FUNC_... * \brief Convert alpha string to enum RIG_FUNC_...
* \param s input alpha string * \param s input alpha string
@ -424,13 +481,17 @@ setting_t HAMLIB_API rig_parse_func(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; func_str[i].str[0] != '\0'; i++) for (i = 0 ; func_str[i].str[0] != '\0'; i++)
if (!strcmp(s, func_str[i].str)) if (!strcmp(s, func_str[i].str)) {
return func_str[i].func; return func_str[i].func;
}
return RIG_FUNC_NONE; return RIG_FUNC_NONE;
} }
/** /**
* \brief Convert enum RIG_FUNC_... to alpha string * \brief Convert enum RIG_FUNC_... to alpha string
* \param func RIG_FUNC_... * \param func RIG_FUNC_...
@ -442,16 +503,21 @@ const char * HAMLIB_API rig_strfunc(setting_t func)
{ {
int i; int i;
if (func == RIG_FUNC_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (func == RIG_FUNC_NONE) {
return ""; return "";
}
for (i = 0; func_str[i].str[0] != '\0'; i++) for (i = 0; func_str[i].str[0] != '\0'; i++)
if (func == func_str[i].func) if (func == func_str[i].func) {
return func_str[i].str; return func_str[i].str;
}
return ""; return "";
} }
static struct { static struct {
setting_t level; setting_t level;
const char *str; const char *str;
@ -490,6 +556,7 @@ static struct {
{ RIG_LEVEL_NONE, "" }, { RIG_LEVEL_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to enum RIG_LEVEL_... * \brief Convert alpha string to enum RIG_LEVEL_...
* \param s input alpha string * \param s input alpha string
@ -501,13 +568,17 @@ setting_t HAMLIB_API rig_parse_level(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; level_str[i].str[0] != '\0'; i++) for (i = 0 ; level_str[i].str[0] != '\0'; i++)
if (!strcmp(s, level_str[i].str)) if (!strcmp(s, level_str[i].str)) {
return level_str[i].level; return level_str[i].level;
}
return RIG_LEVEL_NONE; return RIG_LEVEL_NONE;
} }
/** /**
* \brief Convert enum RIG_LEVEL_... to alpha string * \brief Convert enum RIG_LEVEL_... to alpha string
* \param level RIG_LEVEL_... * \param level RIG_LEVEL_...
@ -519,16 +590,21 @@ const char * HAMLIB_API rig_strlevel(setting_t level)
{ {
int i; int i;
if (level == RIG_LEVEL_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (level == RIG_LEVEL_NONE) {
return ""; return "";
}
for (i = 0; level_str[i].str[0] != '\0'; i++) for (i = 0; level_str[i].str[0] != '\0'; i++)
if (level == level_str[i].level) if (level == level_str[i].level) {
return level_str[i].str; return level_str[i].str;
}
return ""; return "";
} }
static struct { static struct {
setting_t parm; setting_t parm;
const char *str; const char *str;
@ -543,6 +619,7 @@ static struct {
{ RIG_PARM_NONE, "" }, { RIG_PARM_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to RIG_PARM_... * \brief Convert alpha string to RIG_PARM_...
* \param s input alpha string * \param s input alpha string
@ -554,13 +631,17 @@ setting_t HAMLIB_API rig_parse_parm(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; parm_str[i].str[0] != '\0'; i++) for (i = 0 ; parm_str[i].str[0] != '\0'; i++)
if (!strcmp(s, parm_str[i].str)) if (!strcmp(s, parm_str[i].str)) {
return parm_str[i].parm; return parm_str[i].parm;
}
return RIG_PARM_NONE; return RIG_PARM_NONE;
} }
/** /**
* \brief Convert enum RIG_PARM_... to alpha string * \brief Convert enum RIG_PARM_... to alpha string
* \param parm RIG_PARM_... * \param parm RIG_PARM_...
@ -572,16 +653,21 @@ const char * HAMLIB_API rig_strparm(setting_t parm)
{ {
int i; int i;
if (parm == RIG_PARM_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (parm == RIG_PARM_NONE) {
return ""; return "";
}
for (i = 0; parm_str[i].str[0] != '\0'; i++) for (i = 0; parm_str[i].str[0] != '\0'; i++)
if (parm == parm_str[i].parm) if (parm == parm_str[i].parm) {
return parm_str[i].str; return parm_str[i].str;
}
return ""; return "";
} }
static struct { static struct {
vfo_op_t vfo_op; vfo_op_t vfo_op;
const char *str; const char *str;
@ -602,6 +688,7 @@ static struct {
{ RIG_OP_NONE, "" }, { RIG_OP_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to enum RIG_OP_... * \brief Convert alpha string to enum RIG_OP_...
* \param s alpha string * \param s alpha string
@ -613,13 +700,17 @@ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; vfo_op_str[i].str[0] != '\0'; i++) for (i = 0 ; vfo_op_str[i].str[0] != '\0'; i++)
if (!strcmp(s, vfo_op_str[i].str)) if (!strcmp(s, vfo_op_str[i].str)) {
return vfo_op_str[i].vfo_op; return vfo_op_str[i].vfo_op;
}
return RIG_OP_NONE; return RIG_OP_NONE;
} }
/** /**
* \brief Convert enum RIG_OP_... to alpha string * \brief Convert enum RIG_OP_... to alpha string
* \param op RIG_OP_... * \param op RIG_OP_...
@ -631,16 +722,21 @@ const char * HAMLIB_API rig_strvfop(vfo_op_t op)
{ {
int i; int i;
if (op == RIG_OP_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (op == RIG_OP_NONE) {
return ""; return "";
}
for (i = 0; vfo_op_str[i].str[0] != '\0'; i++) for (i = 0; vfo_op_str[i].str[0] != '\0'; i++)
if (op == vfo_op_str[i].vfo_op) if (op == vfo_op_str[i].vfo_op) {
return vfo_op_str[i].str; return vfo_op_str[i].str;
}
return ""; return "";
} }
static struct { static struct {
scan_t rscan; scan_t rscan;
const char *str; const char *str;
@ -657,6 +753,7 @@ static struct {
{ -1, NULL } { -1, NULL }
}; };
/** /**
* \brief Convert alpha string to enum RIG_SCAN_... * \brief Convert alpha string to enum RIG_SCAN_...
* \param s alpha string * \param s alpha string
@ -668,14 +765,18 @@ scan_t HAMLIB_API rig_parse_scan(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; scan_str[i].str[0] != '\0'; i++) { for (i = 0 ; scan_str[i].str[0] != '\0'; i++) {
if (strcmp(s, scan_str[i].str) == 0) { if (strcmp(s, scan_str[i].str) == 0) {
return scan_str[i].rscan; return scan_str[i].rscan;
} }
} }
return RIG_SCAN_NONE; return RIG_SCAN_NONE;
} }
/** /**
* \brief Convert enum RIG_SCAN_... to alpha string * \brief Convert enum RIG_SCAN_... to alpha string
* \param rscan RIG_SCAN_... * \param rscan RIG_SCAN_...
@ -687,15 +788,21 @@ const char * HAMLIB_API rig_strscan(scan_t rscan)
{ {
int i; int i;
if (rscan == RIG_SCAN_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return "";
for (i=0; scan_str[i].str[0] != '\0'; i++) if (rscan == RIG_SCAN_NONE) {
if (rscan == scan_str[i].rscan)
return scan_str[i].str;
return ""; return "";
} }
for (i = 0; scan_str[i].str[0] != '\0'; i++)
if (rscan == scan_str[i].rscan) {
return scan_str[i].str;
}
return "";
}
/** /**
* \brief convert enum RIG_RPT_SHIFT_... to printable character * \brief convert enum RIG_RPT_SHIFT_... to printable character
* \param shift RIG_RPT_SHIFT_?? * \param shift RIG_RPT_SHIFT_??
@ -703,14 +810,23 @@ const char * HAMLIB_API rig_strscan(scan_t rscan)
*/ */
const char * HAMLIB_API rig_strptrshift(rptr_shift_t shift) const char * HAMLIB_API rig_strptrshift(rptr_shift_t shift)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (shift) { switch (shift) {
case RIG_RPT_SHIFT_MINUS: return "-"; case RIG_RPT_SHIFT_MINUS:
case RIG_RPT_SHIFT_PLUS: return "+"; return "-";
case RIG_RPT_SHIFT_NONE: return "None";
case RIG_RPT_SHIFT_PLUS:
return "+";
case RIG_RPT_SHIFT_NONE:
return "None";
} }
return NULL; return NULL;
} }
/** /**
* \brief Convert alpha char to enum RIG_RPT_SHIFT_... * \brief Convert alpha char to enum RIG_RPT_SHIFT_...
* \param s alpha char * \param s alpha char
@ -718,13 +834,17 @@ const char * HAMLIB_API rig_strptrshift(rptr_shift_t shift)
*/ */
rptr_shift_t HAMLIB_API rig_parse_rptr_shift(const char *s) rptr_shift_t HAMLIB_API rig_parse_rptr_shift(const char *s)
{ {
if (strcmp(s, "+") == 0) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (strcmp(s, "+") == 0) {
return RIG_RPT_SHIFT_PLUS; return RIG_RPT_SHIFT_PLUS;
else if (strcmp(s, "-") == 0) } else if (strcmp(s, "-") == 0) {
return RIG_RPT_SHIFT_MINUS; return RIG_RPT_SHIFT_MINUS;
else } else {
return RIG_RPT_SHIFT_NONE; return RIG_RPT_SHIFT_NONE;
} }
}
static struct { static struct {
chan_type_t mtype; chan_type_t mtype;
@ -740,6 +860,7 @@ static struct {
{ RIG_MTYPE_NONE, "" }, { RIG_MTYPE_NONE, "" },
}; };
/** /**
* \brief Convert alpha string to enum RIG_MTYPE_... * \brief Convert alpha string to enum RIG_MTYPE_...
* \param s alpha string * \param s alpha string
@ -751,14 +872,18 @@ chan_type_t HAMLIB_API rig_parse_mtype(const char *s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; mtype_str[i].str[0] != '\0'; i++) { for (i = 0 ; mtype_str[i].str[0] != '\0'; i++) {
if (strcmp(s, mtype_str[i].str) == 0) { if (strcmp(s, mtype_str[i].str) == 0) {
return mtype_str[i].mtype; return mtype_str[i].mtype;
} }
} }
return RIG_MTYPE_NONE; return RIG_MTYPE_NONE;
} }
/** /**
* \brief Convert enum RIG_MTYPE_... to alpha string * \brief Convert enum RIG_MTYPE_... to alpha string
* \param mtype RIG_MTYPE_... * \param mtype RIG_MTYPE_...
@ -770,12 +895,17 @@ const char * HAMLIB_API rig_strmtype(chan_type_t mtype)
{ {
int i; int i;
if (mtype == RIG_MTYPE_NONE) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (mtype == RIG_MTYPE_NONE) {
return ""; return "";
}
for (i = 0; mtype_str[i].str[0] != '\0'; i++) for (i = 0; mtype_str[i].str[0] != '\0'; i++)
if (mtype == mtype_str[i].mtype) if (mtype == mtype_str[i].mtype) {
return mtype_str[i].str; return mtype_str[i].str;
}
return ""; return "";
} }
@ -790,6 +920,7 @@ static long timediff(const struct timeval *tv1, const struct timeval *tv2)
return ((tv.tv_sec * 1000L) + (tv.tv_usec / 1000L)); return ((tv.tv_sec * 1000L) + (tv.tv_usec / 1000L));
} }
/** /**
* \brief Helper for checking cache timeout * \brief Helper for checking cache timeout
* \param tv pointer to timeval, date of cache * \param tv pointer to timeval, date of cache
@ -801,25 +932,35 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
struct timeval curr; struct timeval curr;
long t; long t;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (tv->tv_sec == 0 && tv->tv_usec == 0) { if (tv->tv_sec == 0 && tv->tv_usec == 0) {
rig_debug(RIG_DEBUG_VERBOSE, "forced cache timeout\n"); rig_debug(RIG_DEBUG_VERBOSE,
"%s: forced cache timeout\n",
__func__);
return 1; return 1;
} }
gettimeofday(&curr, NULL); gettimeofday(&curr, NULL);
t = timediff(&curr, tv); t = timediff(&curr, tv);
if (t < timeout) { if (t < timeout) {
rig_debug(RIG_DEBUG_VERBOSE, "%s: using cache (%ld ms)\n", rig_debug(RIG_DEBUG_VERBOSE,
__func__, t); "%s: using cache (%ld ms)\n",
__func__,
t);
return 0; return 0;
} else { } else {
rig_debug(RIG_DEBUG_VERBOSE, "%s: cache timed out (%ld ms)\n", rig_debug(RIG_DEBUG_VERBOSE,
__func__, t); "%s: cache timed out (%ld ms)\n",
__func__,
t);
return 1; return 1;
} }
} }
/** /**
* \brief Helper for forcing cache timeout next call * \brief Helper for forcing cache timeout next call
* *
@ -838,14 +979,20 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
*/ */
void HAMLIB_API rig_force_cache_timeout(struct timeval *tv) void HAMLIB_API rig_force_cache_timeout(struct timeval *tv)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
tv->tv_sec = 0; tv->tv_sec = 0;
tv->tv_usec = 0; tv->tv_usec = 0;
} }
int no_restore_ai; int no_restore_ai;
void HAMLIB_API rig_no_restore_ai() void HAMLIB_API rig_no_restore_ai()
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
no_restore_ai = -1; no_restore_ai = -1;
} }

Wyświetl plik

@ -26,7 +26,7 @@
/* /*
* Carefull!! These marcos are NOT reentrant! * Carefull!! These macros are NOT reentrant!
* ie. they may not be executed atomically, * ie. they may not be executed atomically,
* thus not ensure mutual exclusion. * thus not ensure mutual exclusion.
* Fix it when making Hamlib reentrant! --SF * Fix it when making Hamlib reentrant! --SF
@ -44,20 +44,31 @@ void dump_hex(const unsigned char ptr[], size_t size);
/* /*
* BCD conversion routines. * BCD conversion routines.
* to_bcd converts a long long int to a little endian BCD array, *
* to_bcd() converts a long long int to a little endian BCD array,
* and return a pointer to this array. * and return a pointer to this array.
* from_bcd converts a little endian BCD array to long long int *
* from_bcd() converts a little endian BCD array to long long int
* reprensentation, and return it. * reprensentation, and return it.
*
* bcd_len is the number of digits in the BCD array. * bcd_len is the number of digits in the BCD array.
*/ */
extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len); extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[],
extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char bcd_data[], unsigned bcd_len); unsigned long long freq,
unsigned bcd_len);
extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char bcd_data[],
unsigned bcd_len);
/* /*
* same as to_bcd and from_bcd, but in Big Endian mode * same as to_bcd() and from_bcd(), but in Big Endian mode
*/ */
extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len); extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[],
extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char bcd_data[], unsigned bcd_len); unsigned long long freq,
unsigned bcd_len);
extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char bcd_data[],
unsigned bcd_len);
extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t); extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
@ -77,7 +88,9 @@ extern int no_restore_ai;
#include <sys/time.h> #include <sys/time.h>
#endif #endif
extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv, int timeout); extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv,
int timeout);
extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv); extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv);

Wyświetl plik

@ -65,7 +65,7 @@
# endif # endif
#endif #endif
#include "hamlib/rig.h" #include <hamlib/rig.h>
#include "network.h" #include "network.h"
#include "misc.h" #include "misc.h"
@ -84,28 +84,29 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
lpMsgBuf = (LPVOID)"Unknown error"; lpMsgBuf = (LPVOID)"Unknown error";
e = WSAGetLastError(); e = WSAGetLastError();
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
FORMAT_MESSAGE_FROM_SYSTEM | | FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_IGNORE_INSERTS, | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, e, NULL, e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language // Default language
(LPTSTR)&lpMsgBuf, 0, NULL)) (LPTSTR)&lpMsgBuf,
{ 0,
NULL)) {
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
} } else {
else
{
rig_debug(lvl, "%s: Network error %d\n", msg, e); rig_debug(lvl, "%s: Network error %d\n", msg, e);
} }
#else #else
e = errno; e = errno;
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
#endif #endif
} }
/** /**
* \brief Open network port using rig.state data * \brief Open network port using rig.state data
* *
@ -125,69 +126,78 @@ int network_open(hamlib_port_t *rp, int default_port)
char hostname[FILPATHLEN]; char hostname[FILPATHLEN];
char defaultportstr[8]; char defaultportstr[8];
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef __MINGW32__ #ifdef __MINGW32__
WSADATA wsadata; WSADATA wsadata;
if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
rig_debug(RIG_DEBUG_ERR, "Error creating socket\n"); rig_debug(RIG_DEBUG_ERR, "%s: error creating socket\n", __func__);
return -RIG_EIO; return -RIG_EIO;
} }
#endif #endif
if (!rp) if (!rp) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC; hints.ai_family = PF_UNSPEC;
if (rp->type.rig == RIG_PORT_UDP_NETWORK)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
hoststr = NULL; /* default of all local interfaces */ if (rp->type.rig == RIG_PORT_UDP_NETWORK) {
if (rp->pathname[0] == ':') hints.ai_socktype = SOCK_DGRAM;
{ } else {
portstr = rp->pathname + 1; hints.ai_socktype = SOCK_STREAM;
} }
else
{ /* default of all local interfaces */
if (strlen (rp->pathname)) hoststr = NULL;
{
if (rp->pathname[0] == ':') {
portstr = rp->pathname + 1;
} else {
if (strlen(rp->pathname)) {
strncpy(hostname, rp->pathname, FILPATHLEN - 1); strncpy(hostname, rp->pathname, FILPATHLEN - 1);
hoststr = hostname; hoststr = hostname;
/* look for IPv6 numeric form [<addr>] */ /* look for IPv6 numeric form [<addr>] */
bracketstr1 = strchr(hoststr, '['); bracketstr1 = strchr(hoststr, '[');
bracketstr2 = strrchr(hoststr, ']'); bracketstr2 = strrchr(hoststr, ']');
if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1)
{ if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1) {
hoststr = bracketstr1 + 1; hoststr = bracketstr1 + 1;
*bracketstr2 = '\0'; *bracketstr2 = '\0';
portstr = bracketstr2 + 1; /* possible port after ]: */ portstr = bracketstr2 + 1; /* possible port after ]: */
} } else {
else
{
bracketstr2 = NULL; bracketstr2 = NULL;
portstr = hoststr; /* possible port after : */ portstr = hoststr; /* possible port after : */
} }
/* search last ':' */ /* search last ':' */
portstr = strrchr(portstr, ':'); portstr = strrchr(portstr, ':');
if (portstr)
{ if (portstr) {
*portstr++ = '\0'; *portstr++ = '\0';
} }
} }
if (!portstr)
{ if (!portstr) {
sprintf(defaultportstr, "%d", default_port); sprintf(defaultportstr, "%d", default_port);
portstr = defaultportstr; portstr = defaultportstr;
} }
} }
status = getaddrinfo(hoststr, portstr, &hints, &res); status = getaddrinfo(hoststr, portstr, &hints, &res);
if (status != 0) { if (status != 0) {
rig_debug(RIG_DEBUG_ERR, "Cannot get host \"%s\": %s\n", rig_debug(RIG_DEBUG_ERR,
rp->pathname, gai_strerror(errno)); "%s: cannot get host \"%s\": %s\n",
__func__,
rp->pathname,
gai_strerror(errno));
return -RIG_ECONF; return -RIG_ECONF;
} }
saved_res = res; saved_res = res;
/* we don't want a signal when connection get broken */ /* we don't want a signal when connection get broken */
@ -195,20 +205,19 @@ int network_open(hamlib_port_t *rp, int default_port)
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif #endif
do do {
{
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (fd < 0)
{ if (fd < 0) {
handle_error(RIG_DEBUG_ERR, "socket"); handle_error(RIG_DEBUG_ERR, "socket");
freeaddrinfo(saved_res); freeaddrinfo(saved_res);
return -RIG_EIO; return -RIG_EIO;
} }
if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0) if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0) {
{
break; break;
} }
handle_error(RIG_DEBUG_WARN, "connect (trying next interface)"); handle_error(RIG_DEBUG_WARN, "connect (trying next interface)");
#ifdef __MINGW32__ #ifdef __MINGW32__
@ -221,14 +230,19 @@ int network_open(hamlib_port_t *rp, int default_port)
freeaddrinfo(saved_res); freeaddrinfo(saved_res);
if (NULL == res) { if (NULL == res) {
rig_debug (RIG_DEBUG_ERR, "Failed to connect to %s\n" , rp->pathname); rig_debug(RIG_DEBUG_ERR,
"%s: failed to connect to %s\n",
__func__,
rp->pathname);
return -RIG_EIO; return -RIG_EIO;
} }
rp->fd = fd; rp->fd = fd;
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Clears any data in the read buffer of the socket * \brief Clears any data in the read buffer of the socket
* *
@ -243,28 +257,42 @@ void network_flush(hamlib_port_t* rp)
#endif #endif
char buffer[NET_BUFFER_SIZE] = { 0 }; char buffer[NET_BUFFER_SIZE] = { 0 };
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (;;) { for (;;) {
#ifdef __MINGW32__ #ifdef __MINGW32__
ioctlsocket(rp->fd, FIONREAD, &len); ioctlsocket(rp->fd, FIONREAD, &len);
#else #else
ioctl(rp->fd, FIONREAD, &len); ioctl(rp->fd, FIONREAD, &len);
#endif #endif
if (len > 0) { if (len > 0) {
len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE); len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE);
rig_debug(RIG_DEBUG_WARN, "Network data cleared: %s\n", buffer); rig_debug(RIG_DEBUG_WARN,
"%s: network data cleared: %s\n",
__func__,
buffer);
} else { } else {
break; break;
} }
} }
} }
int network_close(hamlib_port_t *rp) int network_close(hamlib_port_t *rp)
{ {
int ret; int ret;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef __MINGW32__ #ifdef __MINGW32__
ret = closesocket(rp->fd); ret = closesocket(rp->fd);
if (--wsstarted)
if (--wsstarted) {
WSACleanup(); WSACleanup();
}
#else #else
ret = close(rp->fd); ret = close(rp->fd);
#endif #endif

Wyświetl plik

@ -28,8 +28,7 @@
*/ */
/* The status pin functions operate in terms of these bits: */ /* The status pin functions operate in terms of these bits: */
enum ieee1284_status_bits enum ieee1284_status_bits {
{
S1284_NFAULT = 0x08, S1284_NFAULT = 0x08,
S1284_SELECT = 0x10, S1284_SELECT = 0x10,
S1284_PERROR = 0x20, S1284_PERROR = 0x20,
@ -40,16 +39,15 @@ enum ieee1284_status_bits
}; };
/* The control pin functions operate in terms of these bits: */ /* The control pin functions operate in terms of these bits: */
enum ieee1284_control_bits enum ieee1284_control_bits {
{
C1284_NSTROBE = 0x01, C1284_NSTROBE = 0x01,
C1284_NAUTOFD = 0x02, C1284_NAUTOFD = 0x02,
C1284_NINIT = 0x04, C1284_NINIT = 0x04,
C1284_NSELECTIN = 0x08, C1284_NSELECTIN = 0x08,
/* To convert those values into PC-style register values, use this: */ /* To convert those values into PC-style register values, use this: */
C1284_INVERTED = (C1284_NSTROBE| C1284_INVERTED = (C1284_NSTROBE
C1284_NAUTOFD| | C1284_NAUTOFD
C1284_NSELECTIN) | C1284_NSELECTIN)
}; };
#endif /* _PAR_NT_H */ #endif /* _PAR_NT_H */

Wyświetl plik

@ -60,7 +60,7 @@
#include <winbase.h> #include <winbase.h>
#endif #endif
#include "hamlib/rig.h" #include <hamlib/rig.h>
#include "parallel.h" #include "parallel.h"
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
@ -112,6 +112,7 @@
* means low true, e.g., *Strobe. * means low true, e.g., *Strobe.
*/ */
/** /**
* \brief Open Parallel Port * \brief Open Parallel Port
* \param port * \param port
@ -120,10 +121,12 @@
* TODO: to be called before exiting: atexit(parport_cleanup) * TODO: to be called before exiting: atexit(parport_cleanup)
* void parport_cleanup() { ioctl(fd, PPRELEASE); } * void parport_cleanup() { ioctl(fd, PPRELEASE); }
*/ */
int par_open(hamlib_port_t *port) int par_open(hamlib_port_t *port)
{ {
int fd; int fd;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int mode; int mode;
#endif #endif
@ -132,22 +135,30 @@ int par_open(hamlib_port_t *port)
HANDLE handle; HANDLE handle;
#endif #endif
if (!port->pathname[0]) if (!port->pathname[0]) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
/* TODO: open with O_NONBLOCK ? */ /* TODO: open with O_NONBLOCK ? */
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) { if (fd < 0) {
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n",
__func__,
port->pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
mode = IEEE1284_MODE_COMPAT; mode = IEEE1284_MODE_COMPAT;
if (ioctl(fd, PPSETMODE, &mode) != 0) { if (ioctl(fd, PPSETMODE, &mode) != 0) {
rig_debug(RIG_DEBUG_ERR, "PPSETMODE \"%s\": %s\n", port->pathname, strerror(errno)); rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n",
__func__,
port->pathname,
strerror(errno));
close(fd); close(fd);
return -RIG_EIO; return -RIG_EIO;
} }
@ -157,7 +168,11 @@ int par_open(hamlib_port_t *port)
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) { if (fd < 0) {
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n",
__func__,
port->pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
@ -166,15 +181,19 @@ int par_open(hamlib_port_t *port)
0, NULL, OPEN_EXISTING, 0, NULL); 0, NULL, OPEN_EXISTING, 0, NULL);
if (handle == INVALID_HANDLE_VALUE) { if (handle == INVALID_HANDLE_VALUE) {
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\"\n", port->pathname); rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\"\n",
__func__,
port->pathname);
CloseHandle(handle); CloseHandle(handle);
return -RIG_EIO; return -RIG_EIO;
} else { } else {
fd = _open_osfhandle((intptr_t)handle, _O_APPEND | _O_RDONLY); fd = _open_osfhandle((intptr_t)handle, _O_APPEND | _O_RDONLY);
if (fd == -1) if (fd == -1) {
return -RIG_EIO; return -RIG_EIO;
} }
}
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
@ -183,12 +202,15 @@ int par_open(hamlib_port_t *port)
return fd; return fd;
} }
/** /**
* \brief Close Parallel Port * \brief Close Parallel Port
* \param port * \param port
*/ */
int par_close(hamlib_port_t *port) int par_close(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
@ -199,6 +221,7 @@ int par_close(hamlib_port_t *port)
return close(port->fd); return close(port->fd);
} }
/** /**
* \brief Send data on Parallel port * \brief Send data on Parallel port
* \param port * \param port
@ -206,6 +229,8 @@ int par_close(hamlib_port_t *port)
*/ */
int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data) int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
status = ioctl(port->fd, PPWDATA, &data); status = ioctl(port->fd, PPWDATA, &data);
@ -224,7 +249,7 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_DATA, &data, sizeof(data), if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_DATA, &data, sizeof(data),
NULL, 0, (LPDWORD)&dummy, NULL))) { NULL, 0, (LPDWORD)&dummy, NULL))) {
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __FUNCTION__); rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
return -RIG_EIO; return -RIG_EIO;
} }
} }
@ -235,6 +260,7 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
#endif #endif
} }
/** /**
* \brief Receive data on Parallel port * \brief Receive data on Parallel port
* \param port * \param port
@ -242,6 +268,8 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
*/ */
int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
status = ioctl(port->fd, PPRDATA, data); status = ioctl(port->fd, PPRDATA, data);
@ -261,7 +289,7 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret, if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret,
sizeof(ret), (LPDWORD)&dummy, NULL))) { sizeof(ret), (LPDWORD)&dummy, NULL))) {
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __FUNCTION__); rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
return -RIG_EIO; return -RIG_EIO;
} }
} }
@ -273,6 +301,7 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
#endif #endif
} }
/** /**
* \brief Set control data for Parallel Port * \brief Set control data for Parallel Port
* \param port * \param port
@ -280,13 +309,19 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
*/ */
int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS; unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
status = ioctl(port->fd, PPWCONTROL, &ctrl); status = ioctl(port->fd, PPWCONTROL, &ctrl);
if (status < 0) if (status < 0) {
rig_debug(RIG_DEBUG_ERR, "ioctl(PPWCONTROL) failed: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(PPWCONTROL) failed: %s\n",
__func__,
strerror(errno));
}
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
@ -298,14 +333,16 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
unsigned char ctr = control; unsigned char ctr = control;
unsigned char dummyc; unsigned char dummyc;
unsigned int dummy; unsigned int dummy;
const unsigned char wm = (C1284_NSTROBE | const unsigned char wm = (C1284_NSTROBE
C1284_NAUTOFD | | C1284_NAUTOFD
C1284_NINIT | | C1284_NINIT
C1284_NSELECTIN); | C1284_NSELECTIN);
intptr_t handle; intptr_t handle;
if (ctr & 0x20) { if (ctr & 0x20) {
rig_debug(RIG_DEBUG_WARN, "use ieee1284_data_dir to change data line direction!\n"); rig_debug(RIG_DEBUG_WARN,
"%s: use ieee1284_data_dir to change data line direction!\n",
__func__);
} }
/* Deal with inversion issues. */ /* Deal with inversion issues. */
@ -315,9 +352,17 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
handle = _get_osfhandle(port->fd); handle = _get_osfhandle(port->fd);
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, &ctr, if (!(DeviceIoControl((HANDLE)handle,
sizeof(ctr), &dummyc, sizeof(dummyc), (LPDWORD)&dummy, NULL))) { NT_IOCTL_CONTROL,
rig_debug(RIG_DEBUG_ERR, "frob_control: DeviceIoControl failed!\n"); &ctr,
sizeof(ctr),
&dummyc,
sizeof(dummyc),
(LPDWORD)&dummy,
NULL))) {
rig_debug(RIG_DEBUG_ERR,
"%s: frob_control: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; return -RIG_EIO;
} }
} }
@ -328,6 +373,7 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
#endif #endif
} }
/** /**
* \brief Read control data for Parallel Port * \brief Read control data for Parallel Port
* \param port * \param port
@ -335,13 +381,19 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
*/ */
int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
unsigned char ctrl; unsigned char ctrl;
status = ioctl(port->fd, PPRCONTROL, &ctrl); status = ioctl(port->fd, PPRCONTROL, &ctrl);
if (status < 0) if (status < 0) {
rig_debug(RIG_DEBUG_ERR, "ioctl(PPRCONTROL) failed: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(PPRCONTROL) failed: %s\n",
__func__,
strerror(errno));
}
*control = ctrl ^ CP_ACTIVE_LOW_BITS; *control = ctrl ^ CP_ACTIVE_LOW_BITS;
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
@ -362,18 +414,20 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, NULL, 0, &ret, if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, NULL, 0, &ret,
sizeof(ret), (LPDWORD)&dummy, NULL))) { sizeof(ret), (LPDWORD)&dummy, NULL))) {
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __FUNCTION__); rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
return -RIG_EIO; return -RIG_EIO;
} }
} }
*control = ret ^ S1284_INVERTED; *control = ret ^ S1284_INVERTED;
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
/** /**
* \brief Get parallel port status * \brief Get parallel port status
* \param port * \param port
@ -382,6 +436,8 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
*/ */
int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int ret; int ret;
unsigned char sta; unsigned char sta;
@ -405,18 +461,20 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret, if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret,
sizeof(ret), (LPDWORD)&dummy, NULL))) { sizeof(ret), (LPDWORD)&dummy, NULL))) {
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __FUNCTION__); rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
return -RIG_EIO; return -RIG_EIO;
} }
} }
*status = ret ^ S1284_INVERTED; *status = ret ^ S1284_INVERTED;
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
/** /**
* \brief Get a lock on the Parallel Port * \brief Get a lock on the Parallel Port
* \param port * \param port
@ -424,10 +482,16 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
*/ */
int HAMLIB_API par_lock(hamlib_port_t *port) int HAMLIB_API par_lock(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPCLAIM) < 0) { if (ioctl(port->fd, PPCLAIM) < 0) {
rig_debug(RIG_DEBUG_ERR, "Claiming device \"%s\": %s\n", port->pathname, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: claiming device \"%s\": %s\n",
__func__,
port->pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
@ -441,6 +505,7 @@ int HAMLIB_API par_lock(hamlib_port_t *port)
#endif #endif
} }
/** /**
* \brief Release lock on Parallel Port * \brief Release lock on Parallel Port
* \param port * \param port
@ -448,10 +513,16 @@ int HAMLIB_API par_lock(hamlib_port_t *port)
*/ */
int HAMLIB_API par_unlock(hamlib_port_t *port) int HAMLIB_API par_unlock(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPRELEASE) < 0) { if (ioctl(port->fd, PPRELEASE) < 0) {
rig_debug(RIG_DEBUG_ERR, "Releasing device \"%s\": %s\n", port->pathname, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: releasing device \"%s\": %s\n",
__func__,
port->pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
@ -465,6 +536,7 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
#endif #endif
} }
#ifndef PARPORT_CONTROL_STROBE #ifndef PARPORT_CONTROL_STROBE
#define PARPORT_CONTROL_STROBE 0x1 #define PARPORT_CONTROL_STROBE 0x1
#endif #endif
@ -472,6 +544,7 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
#define PARPORT_CONTROL_INIT 0x4 #define PARPORT_CONTROL_INIT 0x4
#endif #endif
/** /**
* \brief Set or unset Push to talk bit on Parallel Port * \brief Set or unset Push to talk bit on Parallel Port
* \param p * \param p
@ -480,6 +553,8 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
*/ */
int par_ptt_set(hamlib_port_t *p, ptt_t pttx) int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) { switch (p->type.ptt) {
case RIG_PTT_PARALLEL: { case RIG_PTT_PARALLEL: {
unsigned char ctl; unsigned char ctl;
@ -488,8 +563,9 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
par_lock(p); par_lock(p);
status = par_read_control(p, &ctl); status = par_read_control(p, &ctl);
if (status != RIG_OK) if (status != RIG_OK) {
return status; return status;
}
/* Enable CW & PTT - /STROBE bit (pin 1) */ /* Enable CW & PTT - /STROBE bit (pin 1) */
ctl &= ~PARPORT_CONTROL_STROBE; ctl &= ~PARPORT_CONTROL_STROBE;
@ -497,10 +573,11 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
/* TODO: kill parm.parallel.pin? */ /* TODO: kill parm.parallel.pin? */
/* PTT keying - /INIT bit (pin 16) (inverted) */ /* PTT keying - /INIT bit (pin 16) (inverted) */
if (pttx == RIG_PTT_ON) if (pttx == RIG_PTT_ON) {
ctl |= PARPORT_CONTROL_INIT; ctl |= PARPORT_CONTROL_INIT;
else } else {
ctl &= ~PARPORT_CONTROL_INIT; ctl &= ~PARPORT_CONTROL_INIT;
}
status = par_write_control(p, ctl); status = par_write_control(p, ctl);
par_unlock(p); par_unlock(p);
@ -508,7 +585,9 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
} }
default: default:
rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR,
"%s: unsupported PTT type %d\n",
__func__,
p->type.ptt); p->type.ptt);
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -516,6 +595,7 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Get state of Push to Talk from Parallel Port * \brief Get state of Push to Talk from Parallel Port
* \param p * \param p
@ -524,6 +604,8 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
*/ */
int par_ptt_get(hamlib_port_t *p, ptt_t *pttx) int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) { switch (p->type.ptt) {
case RIG_PTT_PARALLEL: { case RIG_PTT_PARALLEL: {
unsigned char ctl; unsigned char ctl;
@ -540,7 +622,9 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
} }
default: default:
rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n", rig_debug(RIG_DEBUG_ERR,
"Unsupported PTT type %d\n",
__func__,
p->type.ptt); p->type.ptt);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -548,6 +632,7 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief get Data Carrier Detect (squelch) from Parallel Port * \brief get Data Carrier Detect (squelch) from Parallel Port
* \param p * \param p
@ -556,6 +641,8 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
*/ */
int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx) int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.dcd) { switch (p->type.dcd) {
case RIG_DCD_PARALLEL: { case RIG_DCD_PARALLEL: {
unsigned char reg; unsigned char reg;
@ -568,7 +655,9 @@ int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
} }
default: default:
rig_debug(RIG_DEBUG_ERR, "Unsupported DCD type %d\n", rig_debug(RIG_DEBUG_ERR,
"%s: unsupported DCD type %d\n",
__func__,
p->type.dcd); p->type.dcd);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }

Wyświetl plik

@ -69,10 +69,16 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx);
int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx); int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx);
extern HAMLIB_EXPORT(int) par_write_data(hamlib_port_t *p, unsigned char data); extern HAMLIB_EXPORT(int) par_write_data(hamlib_port_t *p, unsigned char data);
extern HAMLIB_EXPORT(int) par_write_control(hamlib_port_t *p, unsigned char control); extern HAMLIB_EXPORT(int) par_write_control(hamlib_port_t *p,
unsigned char control);
extern HAMLIB_EXPORT(int) par_read_data(hamlib_port_t *p, unsigned char *data); extern HAMLIB_EXPORT(int) par_read_data(hamlib_port_t *p, unsigned char *data);
extern HAMLIB_EXPORT(int) par_read_control(hamlib_port_t *p, unsigned char *control); extern HAMLIB_EXPORT(int) par_read_control(hamlib_port_t *p,
extern HAMLIB_EXPORT(int) par_read_status(hamlib_port_t *p, unsigned char *status); unsigned char *control);
extern HAMLIB_EXPORT(int) par_read_status(hamlib_port_t *p,
unsigned char *status);
extern HAMLIB_EXPORT(int) par_lock(hamlib_port_t *p); extern HAMLIB_EXPORT(int) par_lock(hamlib_port_t *p);
extern HAMLIB_EXPORT(int) par_unlock(hamlib_port_t *p); extern HAMLIB_EXPORT(int) par_unlock(hamlib_port_t *p);

Wyświetl plik

@ -57,11 +57,8 @@
#define RIG_FUNCNAM(backend) RIG_FUNCNAMA(backend),RIG_FUNCNAMB(backend) #define RIG_FUNCNAM(backend) RIG_FUNCNAMA(backend),RIG_FUNCNAMB(backend)
/* /*
* RIG_BACKEND_LIST is defined here, please keep it up to data, * RIG_BACKEND_LIST is defined here, please keep it up to date,
* ie. each time you give birth to a new backend * i.e. each time you implement a new backend.
* Also, it should be possible to register "external" backend,
* that is backend that were not known by Hamlib at compile time.
* Maybe, riglist.h should reserve some numbers for them? --SF
*/ */
DEFINE_INITRIG_BACKEND(dummy); DEFINE_INITRIG_BACKEND(dummy);
DEFINE_INITRIG_BACKEND(yaesu); DEFINE_INITRIG_BACKEND(yaesu);
@ -108,8 +105,7 @@ static struct {
const char *be_name; const char *be_name;
int (* be_init_all)(void *handle); int (* be_init_all)(void *handle);
rig_model_t (* be_probe_all)(hamlib_port_t *, rig_probe_func_t, rig_ptr_t); rig_model_t (* be_probe_all)(hamlib_port_t *, rig_probe_func_t, rig_ptr_t);
} rig_backend_list[RIG_BACKEND_MAX] = } rig_backend_list[RIG_BACKEND_MAX] = {
{
{ RIG_DUMMY, RIG_BACKEND_DUMMY, RIG_FUNCNAMA(dummy) }, { RIG_DUMMY, RIG_BACKEND_DUMMY, RIG_FUNCNAMA(dummy) },
{ RIG_YAESU, RIG_BACKEND_YAESU, RIG_FUNCNAM(yaesu) }, { RIG_YAESU, RIG_BACKEND_YAESU, RIG_FUNCNAM(yaesu) },
{ RIG_KENWOOD, RIG_BACKEND_KENWOOD, RIG_FUNCNAM(kenwood) }, { RIG_KENWOOD, RIG_BACKEND_KENWOOD, RIG_FUNCNAM(kenwood) },
@ -143,6 +139,7 @@ static struct {
{ 0, NULL }, /* end */ { 0, NULL }, /* end */
}; };
/* /*
* This struct to keep track of known rig models. * This struct to keep track of known rig models.
* It is chained, and used in a hash table, see below. * It is chained, and used in a hash table, see below.
@ -152,9 +149,11 @@ struct rig_list {
struct rig_list *next; struct rig_list *next;
}; };
#define RIGLSTHASHSZ 16 #define RIGLSTHASHSZ 16
#define HASH_FUNC(a) ((a)%RIGLSTHASHSZ) #define HASH_FUNC(a) ((a)%RIGLSTHASHSZ)
/* /*
* The rig_hash_table is a hash table pointing to a list of next==NULL * The rig_hash_table is a hash table pointing to a list of next==NULL
* terminated caps. * terminated caps.
@ -164,6 +163,7 @@ static struct rig_list *rig_hash_table[RIGLSTHASHSZ] = { NULL, };
static int rig_lookup_backend(rig_model_t rig_model); static int rig_lookup_backend(rig_model_t rig_model);
/* /*
* Basically, this is a hash insert function that doesn't check for dup! * Basically, this is a hash insert function that doesn't check for dup!
*/ */
@ -172,19 +172,30 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
int hval; int hval;
struct rig_list *p; struct rig_list *p;
if (!caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
rig_debug(RIG_DEBUG_VERBOSE, "rig_register (%d)\n",caps->rig_model); if (!caps) {
return -RIG_EINVAL;
}
rig_debug(RIG_DEBUG_VERBOSE,
"%s: rig_register (%d)\n",
__func__,
caps->rig_model);
#ifndef DONT_WANT_DUP_CHECK #ifndef DONT_WANT_DUP_CHECK
if (rig_get_caps(caps->rig_model)!=NULL)
if (rig_get_caps(caps->rig_model) != NULL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
#endif #endif
p = (struct rig_list *)malloc(sizeof(struct rig_list)); p = (struct rig_list *)malloc(sizeof(struct rig_list));
if (!p)
if (!p) {
return -RIG_ENOMEM; return -RIG_ENOMEM;
}
hval = HASH_FUNC(caps->rig_model); hval = HASH_FUNC(caps->rig_model);
p->caps = caps; p->caps = caps;
@ -205,9 +216,10 @@ const struct rig_caps * HAMLIB_API rig_get_caps(rig_model_t rig_model)
struct rig_list *p; struct rig_list *p;
for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next) { for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next) {
if (p->caps->rig_model == rig_model) if (p->caps->rig_model == rig_model) {
return p->caps; return p->caps;
} }
}
return NULL; /* sorry, caps not registered! */ return NULL; /* sorry, caps not registered! */
} }
@ -223,9 +235,10 @@ static int rig_lookup_backend(rig_model_t rig_model)
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
if (RIG_BACKEND_NUM(rig_model) == if (RIG_BACKEND_NUM(rig_model) ==
rig_backend_list[i].be_num) rig_backend_list[i].be_num) {
return i; return i;
} }
}
return -1; return -1;
} }
@ -244,8 +257,10 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model)
/* already loaded ? */ /* already loaded ? */
caps = rig_get_caps(rig_model); caps = rig_get_caps(rig_model);
if (caps)
if (caps) {
return RIG_OK; return RIG_OK;
}
be_idx = rig_lookup_backend(rig_model); be_idx = rig_lookup_backend(rig_model);
@ -273,16 +288,19 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model)
hval = HASH_FUNC(rig_model); hval = HASH_FUNC(rig_model);
q = NULL; q = NULL;
for (p = rig_hash_table[hval]; p; p = p->next) { for (p = rig_hash_table[hval]; p; p = p->next) {
if (p->caps->rig_model == rig_model) { if (p->caps->rig_model == rig_model) {
if (q == NULL) if (q == NULL) {
rig_hash_table[hval] = p->next; rig_hash_table[hval] = p->next;
else } else {
q->next = p->next; q->next = p->next;
}
free(p); free(p);
return RIG_OK; return RIG_OK;
} }
q = p; q = p;
} }
@ -293,27 +311,33 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model)
* rig_list_foreach * rig_list_foreach
* executes cfunc on all the elements stored in the rig hash list * executes cfunc on all the elements stored in the rig hash list
*/ */
int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps*, rig_ptr_t),rig_ptr_t data) int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *,
rig_ptr_t), rig_ptr_t data)
{ {
struct rig_list *p; struct rig_list *p;
int i; int i;
if (!cfunc) if (!cfunc) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
for (i = 0; i < RIGLSTHASHSZ; i++) { for (i = 0; i < RIGLSTHASHSZ; i++) {
struct rig_list *next = NULL; struct rig_list *next = NULL;
for (p = rig_hash_table[i]; p; p = next) { for (p = rig_hash_table[i]; p; p = next) {
next = p->next; /* read before call in case it is unregistered */ next = p->next; /* read before call in case it is unregistered */
if ((*cfunc)(p->caps,data) == 0)
if ((*cfunc)(p->caps, data) == 0) {
return RIG_OK; return RIG_OK;
} }
} }
}
return RIG_OK; return RIG_OK;
} }
static int dummy_rig_probe(const hamlib_port_t *p, rig_model_t model, rig_ptr_t data) static int dummy_rig_probe(const hamlib_port_t *p, rig_model_t model,
rig_ptr_t data)
{ {
rig_debug(RIG_DEBUG_TRACE, "Found rig, model %d\n", model); rig_debug(RIG_DEBUG_TRACE, "Found rig, model %d\n", model);
return RIG_OK; return RIG_OK;
@ -330,12 +354,16 @@ rig_model_t rig_probe_first(hamlib_port_t *p)
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
if (rig_backend_list[i].be_probe_all) { if (rig_backend_list[i].be_probe_all) {
model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe, (rig_ptr_t)NULL); model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe,
(rig_ptr_t)NULL);
/* stop at first one found */ /* stop at first one found */
if (model != RIG_MODEL_NONE) if (model != RIG_MODEL_NONE) {
return model; return model;
} }
} }
}
return RIG_MODEL_NONE; return RIG_MODEL_NONE;
} }
@ -343,7 +371,8 @@ rig_model_t rig_probe_first(hamlib_port_t *p)
* rig_probe_all_backends * rig_probe_all_backends
* called straight by rig_probe_all * called straight by rig_probe_all
*/ */
int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc, rig_ptr_t data) int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc,
rig_ptr_t data)
{ {
int i; int i;
@ -352,6 +381,7 @@ int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc, rig_ptr_t d
(*rig_backend_list[i].be_probe_all)(p, cfunc, data); (*rig_backend_list[i].be_probe_all)(p, cfunc, data);
} }
} }
return RIG_OK; return RIG_OK;
} }
@ -381,12 +411,10 @@ int HAMLIB_API rig_load_backend(const char *be_name)
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
if (!strcmp(be_name, rig_backend_list[i].be_name)) { if (!strcmp(be_name, rig_backend_list[i].be_name)) {
be_init = rig_backend_list[i].be_init_all ; be_init = rig_backend_list[i].be_init_all ;
if(be_init)
{ if (be_init) {
return (*be_init)(NULL); return (*be_init)(NULL);
} } else {
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
} }

Wyświetl plik

@ -42,15 +42,31 @@
#define PREFIX_INITRIG initrigs #define PREFIX_INITRIG initrigs
#define PREFIX_PROBERIG probeallrigs #define PREFIX_PROBERIG probeallrigs
#define DECLARE_INITRIG_BACKEND(backend) EXTERN_C BACKEND_EXPORT(int) MAKE_VERSIONED_FN(PREFIX_INITRIG, ABI_VERSION, backend(void *be_handle)) #define DECLARE_INITRIG_BACKEND(backend) \
EXTERN_C BACKEND_EXPORT(int) \
MAKE_VERSIONED_FN(PREFIX_INITRIG, ABI_VERSION, backend(void *be_handle))
#define DECLARE_PROBERIG_BACKEND(backend) EXTERN_C BACKEND_EXPORT(rig_model_t) MAKE_VERSIONED_FN(PREFIX_PROBERIG, ABI_VERSION, backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)) #define DECLARE_PROBERIG_BACKEND(backend) \
EXTERN_C BACKEND_EXPORT(rig_model_t) \
MAKE_VERSIONED_FN(PREFIX_PROBERIG, \
ABI_VERSION, \
backend(hamlib_port_t *port, \
rig_probe_func_t cfunc, \
rig_ptr_t data))
#define PREFIX_INITROTS initrots #define PREFIX_INITROTS initrots
#define PREFIX_PROBEROTS probeallrots #define PREFIX_PROBEROTS probeallrots
#define DECLARE_INITROT_BACKEND(backend) EXTERN_C BACKEND_EXPORT(int) MAKE_VERSIONED_FN(PREFIX_INITROTS, ABI_VERSION, backend(void *be_handle)) #define DECLARE_INITROT_BACKEND(backend) \
EXTERN_C BACKEND_EXPORT(int) \
MAKE_VERSIONED_FN(PREFIX_INITROTS, ABI_VERSION, backend(void *be_handle))
#define DECLARE_PROBEROT_BACKEND(backend) EXTERN_C BACKEND_EXPORT(rot_model_t) MAKE_VERSIONED_FN(PREFIX_PROBEROTS, ABI_VERSION, backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)) #define DECLARE_PROBEROT_BACKEND(backend) \
EXTERN_C BACKEND_EXPORT(rot_model_t) \
MAKE_VERSIONED_FN(PREFIX_PROBEROTS, \
ABI_VERSION, \
backend(hamlib_port_t *port, \
rig_probe_func_t cfunc, \
rig_ptr_t data))
#endif /* _REGISTER_H */ #endif /* _REGISTER_H */

1724
src/rig.c

Plik diff jest za duży Load Diff

Wyświetl plik

@ -49,38 +49,47 @@
* Configuration options available in the rot->state struct. * Configuration options available in the rot->state struct.
*/ */
static const struct confparams rotfrontend_cfg_params[] = { static const struct confparams rotfrontend_cfg_params[] = {
{ TOK_PATHNAME, "rot_pathname", "Rig path name", {
TOK_PATHNAME, "rot_pathname", "Rig path name",
"Path name to the device file of the rotator", "Path name to the device file of the rotator",
"/dev/rotator", RIG_CONF_STRING, "/dev/rotator", RIG_CONF_STRING,
}, },
{ TOK_WRITE_DELAY, "write_delay", "Write delay", {
TOK_WRITE_DELAY, "write_delay", "Write delay",
"Delay in ms between each byte sent out", "Delay in ms between each byte sent out",
"0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } }
}, },
{ TOK_POST_WRITE_DELAY, "post_write_delay", "Post write delay", {
TOK_POST_WRITE_DELAY, "post_write_delay", "Post write delay",
"Delay in ms between each command sent out", "Delay in ms between each command sent out",
"0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 1000, 1 } }
}, },
{ TOK_TIMEOUT, "timeout", "Timeout", "Timeout in ms", {
TOK_TIMEOUT, "timeout", "Timeout", "Timeout in ms",
"0", RIG_CONF_NUMERIC, { .n = { 0, 10000, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 10000, 1 } }
}, },
{ TOK_RETRY, "retry", "Retry", "Max number of retry", {
TOK_RETRY, "retry", "Retry", "Max number of retry",
"0", RIG_CONF_NUMERIC, { .n = { 0, 10, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 0, 10, 1 } }
}, },
{ TOK_MIN_AZ, "min_az", "Minimum azimuth", {
TOK_MIN_AZ, "min_az", "Minimum azimuth",
"Minimum rotator azimuth in degrees", "Minimum rotator azimuth in degrees",
"-180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } "-180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } }
}, },
{ TOK_MAX_AZ, "max_az", "Maximum azimuth", {
TOK_MAX_AZ, "max_az", "Maximum azimuth",
"Maximum rotator azimuth in degrees", "Maximum rotator azimuth in degrees",
"180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } "180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } }
}, },
{ TOK_MIN_EL, "min_el", "Minimum elevation", {
TOK_MIN_EL, "min_el", "Minimum elevation",
"Minimum rotator elevation in degrees", "Minimum rotator elevation in degrees",
"0", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } "0", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } }
}, },
{ TOK_MAX_EL, "max_el", "Maximum elevation", {
TOK_MAX_EL, "max_el", "Maximum elevation",
"Maximum rotator elevation in degrees", "Maximum rotator elevation in degrees",
"90", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } "90", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } }
}, },
@ -88,24 +97,30 @@ static const struct confparams rotfrontend_cfg_params[] = {
{ RIG_CONF_END, NULL, } { RIG_CONF_END, NULL, }
}; };
static const struct confparams rotfrontend_serial_cfg_params[] = { static const struct confparams rotfrontend_serial_cfg_params[] = {
{ TOK_SERIAL_SPEED, "serial_speed", "Serial speed", {
TOK_SERIAL_SPEED, "serial_speed", "Serial speed",
"Serial port baud rate", "Serial port baud rate",
"0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } } "0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } }
}, },
{ TOK_DATA_BITS, "data_bits", "Serial data bits", {
TOK_DATA_BITS, "data_bits", "Serial data bits",
"Serial port data bits", "Serial port data bits",
"8", RIG_CONF_NUMERIC, { .n = { 5, 8, 1 } } "8", RIG_CONF_NUMERIC, { .n = { 5, 8, 1 } }
}, },
{ TOK_STOP_BITS, "stop_bits", "Serial stop bits", {
TOK_STOP_BITS, "stop_bits", "Serial stop bits",
"Serial port stop bits", "Serial port stop bits",
"1", RIG_CONF_NUMERIC, { .n = { 0, 3, 1 } } "1", RIG_CONF_NUMERIC, { .n = { 0, 3, 1 } }
}, },
{ TOK_PARITY, "serial_parity", "Serial parity", {
TOK_PARITY, "serial_parity", "Serial parity",
"Serial port parity", "Serial port parity",
"None", RIG_CONF_COMBO, { .c = {{ "None", "Odd", "Even", "Mark", "Space", NULL }} } "None", RIG_CONF_COMBO, { .c = {{ "None", "Odd", "Even", "Mark", "Space", NULL }} }
}, },
{ TOK_HANDSHAKE, "serial_handshake", "Serial handshake", {
TOK_HANDSHAKE, "serial_handshake", "Serial handshake",
"Serial port handshake", "Serial port handshake",
"None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} } "None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} }
}, },
@ -113,6 +128,7 @@ static const struct confparams rotfrontend_serial_cfg_params[] = {
{ RIG_CONF_END, NULL, } { RIG_CONF_END, NULL, }
}; };
/** /**
* \brief Set rotator state info from alpha input * \brief Set rotator state info from alpha input
* \param rot * \param rot
@ -129,90 +145,131 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
rs = &rot->state; rs = &rot->state;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (token) { switch (token) {
case TOK_PATHNAME: case TOK_PATHNAME:
strncpy(rs->rotport.pathname, val, FILPATHLEN - 1); strncpy(rs->rotport.pathname, val, FILPATHLEN - 1);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.write_delay = val_i; rs->rotport.write_delay = val_i;
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.post_write_delay = val_i; rs->rotport.post_write_delay = val_i;
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
if (1 != sscanf(val, "%d", &val_i)) if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.timeout = val_i; rs->rotport.timeout = val_i;
break; break;
case TOK_RETRY: case TOK_RETRY:
if (1 != sscanf(val, "%d", &val_i)) if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.retry = val_i; rs->rotport.retry = val_i;
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (1 != sscanf(val, "%d", &val_i)) }
if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.parm.serial.rate = val_i; rs->rotport.parm.serial.rate = val_i;
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (1 != sscanf(val, "%d", &val_i)) }
if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.parm.serial.data_bits = val_i; rs->rotport.parm.serial.data_bits = val_i;
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (1 != sscanf(val, "%d", &val_i)) }
if (1 != sscanf(val, "%d", &val_i)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.parm.serial.stop_bits = val_i; rs->rotport.parm.serial.stop_bits = val_i;
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strcmp(val, "None")) }
if (!strcmp(val, "None")) {
rs->rotport.parm.serial.parity = RIG_PARITY_NONE; rs->rotport.parm.serial.parity = RIG_PARITY_NONE;
else if (!strcmp(val, "Odd")) } else if (!strcmp(val, "Odd")) {
rs->rotport.parm.serial.parity = RIG_PARITY_ODD; rs->rotport.parm.serial.parity = RIG_PARITY_ODD;
else if (!strcmp(val, "Even")) } else if (!strcmp(val, "Even")) {
rs->rotport.parm.serial.parity = RIG_PARITY_EVEN; rs->rotport.parm.serial.parity = RIG_PARITY_EVEN;
else if (!strcmp(val, "Mark")) } else if (!strcmp(val, "Mark")) {
rs->rotport.parm.serial.parity = RIG_PARITY_MARK; rs->rotport.parm.serial.parity = RIG_PARITY_MARK;
else if (!strcmp(val, "Space")) } else if (!strcmp(val, "Space")) {
rs->rotport.parm.serial.parity = RIG_PARITY_SPACE; rs->rotport.parm.serial.parity = RIG_PARITY_SPACE;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strcmp(val, "None")) }
if (!strcmp(val, "None")) {
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_NONE; rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
else if (!strcmp(val, "XONXOFF")) } else if (!strcmp(val, "XONXOFF")) {
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF;
else if (!strcmp(val, "Hardware")) } else if (!strcmp(val, "Hardware")) {
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
else } else {
return -RIG_EINVAL; return -RIG_EINVAL;
}
break; break;
case TOK_MIN_AZ: case TOK_MIN_AZ:
rs->min_az = atof(val); rs->min_az = atof(val);
break; break;
case TOK_MAX_AZ: case TOK_MAX_AZ:
rs->max_az = atof(val); rs->max_az = atof(val);
break; break;
case TOK_MIN_EL: case TOK_MIN_EL:
rs->min_el = atof(val); rs->min_el = atof(val);
break; break;
case TOK_MAX_EL: case TOK_MAX_EL:
rs->max_el = atof(val); rs->max_el = atof(val);
break; break;
@ -220,9 +277,11 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
default: default:
return -RIG_EINVAL; return -RIG_EINVAL;
} }
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Get data from rotator state in alpha form * \brief Get data from rotator state in alpha form
* \param rot non-null * \param rot non-null
@ -237,79 +296,135 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
rs = &rot->state; rs = &rot->state;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (token) { switch (token) {
case TOK_PATHNAME: case TOK_PATHNAME:
strcpy(val, rs->rotport.pathname); strcpy(val, rs->rotport.pathname);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
sprintf(val, "%d", rs->rotport.write_delay); sprintf(val, "%d", rs->rotport.write_delay);
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
sprintf(val, "%d", rs->rotport.post_write_delay); sprintf(val, "%d", rs->rotport.post_write_delay);
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
sprintf(val, "%d", rs->rotport.timeout); sprintf(val, "%d", rs->rotport.timeout);
break; break;
case TOK_RETRY: case TOK_RETRY:
sprintf(val, "%d", rs->rotport.retry); sprintf(val, "%d", rs->rotport.retry);
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
sprintf(val, "%d", rs->rotport.parm.serial.rate); sprintf(val, "%d", rs->rotport.parm.serial.rate);
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
sprintf(val, "%d", rs->rotport.parm.serial.data_bits); sprintf(val, "%d", rs->rotport.parm.serial.data_bits);
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
sprintf(val, "%d", rs->rotport.parm.serial.stop_bits); sprintf(val, "%d", rs->rotport.parm.serial.stop_bits);
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
switch (rs->rotport.parm.serial.parity) { switch (rs->rotport.parm.serial.parity) {
case RIG_PARITY_NONE: s = "None"; break; case RIG_PARITY_NONE:
case RIG_PARITY_ODD: s = "Odd"; break; s = "None";
case RIG_PARITY_EVEN: s = "Even"; break;
case RIG_PARITY_MARK: s = "Mark"; break;
case RIG_PARITY_SPACE: s = "Space"; break;
default: return -RIG_EINVAL;
}
strcpy(val, s);
break; break;
case TOK_HANDSHAKE:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) case RIG_PARITY_ODD:
return -RIG_EINVAL; s = "Odd";
switch (rs->rotport.parm.serial.handshake) {
case RIG_HANDSHAKE_NONE: s = "None"; break;
case RIG_HANDSHAKE_XONXOFF: s = "XONXOFF"; break;
case RIG_HANDSHAKE_HARDWARE: s = "Hardware"; break;
default: return -RIG_EINVAL;
}
strcpy(val, s);
break; break;
case TOK_MIN_AZ:
sprintf(val, "%f", rs->min_az); case RIG_PARITY_EVEN:
s = "Even";
break; break;
case TOK_MAX_AZ:
sprintf(val, "%f", rs->max_az); case RIG_PARITY_MARK:
s = "Mark";
break; break;
case TOK_MIN_EL:
sprintf(val, "%f", rs->min_el); case RIG_PARITY_SPACE:
break; s = "Space";
case TOK_MAX_EL:
sprintf(val, "%f", rs->max_el);
break; break;
default: default:
return -RIG_EINVAL; return -RIG_EINVAL;
} }
strcpy(val, s);
break;
case TOK_HANDSHAKE:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
return -RIG_EINVAL;
}
switch (rs->rotport.parm.serial.handshake) {
case RIG_HANDSHAKE_NONE:
s = "None";
break;
case RIG_HANDSHAKE_XONXOFF:
s = "XONXOFF";
break;
case RIG_HANDSHAKE_HARDWARE:
s = "Hardware";
break;
default:
return -RIG_EINVAL;
}
strcpy(val, s);
break;
case TOK_MIN_AZ:
sprintf(val, "%f", rs->min_az);
break;
case TOK_MAX_AZ:
sprintf(val, "%f", rs->max_az);
break;
case TOK_MIN_EL:
sprintf(val, "%f", rs->min_el);
break;
case TOK_MAX_EL:
sprintf(val, "%f", rs->max_el);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Executes cfunc on all the elements stored in the conf table * \brief Executes cfunc on all the elements stored in the conf table
* \param rot non-null * \param rot non-null
@ -318,26 +433,37 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
* *
* start first with backend conf table, then finish with frontend table * start first with backend conf table, then finish with frontend table
*/ */
int HAMLIB_API rot_token_foreach(ROT *rot, int (*cfunc)(const struct confparams *, rig_ptr_t), rig_ptr_t data) int HAMLIB_API rot_token_foreach(ROT *rot,
int (*cfunc)(const struct confparams *, rig_ptr_t),
rig_ptr_t data)
{ {
const struct confparams *cfp; const struct confparams *cfp;
if (!rot || !rot->caps || !cfunc) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !cfunc) {
return -RIG_EINVAL; return -RIG_EINVAL;
for (cfp = rotfrontend_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0)
return RIG_OK;
if (rot->caps->port_type == RIG_PORT_SERIAL) {
for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0)
return RIG_OK;
} }
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) {
if ((*cfunc)(cfp, data) == 0) if ((*cfunc)(cfp, data) == 0) {
return RIG_OK; return RIG_OK;
}
}
if (rot->caps->port_type == RIG_PORT_SERIAL) {
for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) {
if ((*cfunc)(cfp, data) == 0) {
return RIG_OK;
}
}
}
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) {
if ((*cfunc)(cfp, data) == 0) {
return RIG_OK;
}
}
return RIG_OK; return RIG_OK;
} }
@ -352,31 +478,45 @@ int HAMLIB_API rot_token_foreach(ROT *rot, int (*cfunc)(const struct confparams
* lookup backend config table first, then fall back to frontend. * lookup backend config table first, then fall back to frontend.
* TODO: should use Lex to speed it up, strcmp hurts! * TODO: should use Lex to speed it up, strcmp hurts!
*/ */
const struct confparams * HAMLIB_API rot_confparam_lookup(ROT *rot, const char *name) const struct confparams * HAMLIB_API rot_confparam_lookup(ROT *rot,
const char *name)
{ {
const struct confparams *cfp; const struct confparams *cfp;
token_t token; token_t token;
if (!rot || !rot->caps) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) {
return NULL; return NULL;
}
/* 0 returned for invalid format */ /* 0 returned for invalid format */
token = strtol(name, NULL, 0); token = strtol(name, NULL, 0);
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) {
if (!strcmp(cfp->name, name) || token == cfp->token) if (!strcmp(cfp->name, name) || token == cfp->token) {
return cfp;
for (cfp = rotfrontend_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token)
return cfp;
if (rot->caps->port_type == RIG_PORT_SERIAL) {
for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token)
return cfp; return cfp;
} }
}
for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) {
if (!strcmp(cfp->name, name) || token == cfp->token) {
return cfp;
}
}
if (rot->caps->port_type == RIG_PORT_SERIAL) {
for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) {
if (!strcmp(cfp->name, name) || token == cfp->token) {
return cfp;
}
}
}
return NULL; return NULL;
} }
/** /**
* \brief Simple lookup returning token id associated with name * \brief Simple lookup returning token id associated with name
* \param rot * \param rot
@ -387,13 +527,18 @@ token_t HAMLIB_API rot_token_lookup(ROT *rot, const char *name)
{ {
const struct confparams *cfp; const struct confparams *cfp;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
cfp = rot_confparam_lookup(rot, name); cfp = rot_confparam_lookup(rot, name);
if (!cfp)
if (!cfp) {
return RIG_CONF_END; return RIG_CONF_END;
}
return cfp->token; return cfp->token;
} }
/** /**
* \brief set a rotator configuration parameter * \brief set a rotator configuration parameter
* \param rot The rot handle * \param rot The rot handle
@ -410,28 +555,37 @@ token_t HAMLIB_API rot_token_lookup(ROT *rot, const char *name)
*/ */
int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val) int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val)
{ {
if (!rot || !rot->caps) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (rig_need_debug(RIG_DEBUG_VERBOSE)) { if (rig_need_debug(RIG_DEBUG_VERBOSE)) {
const struct confparams *cfp; const struct confparams *cfp;
char tokenstr[12]; char tokenstr[12];
sprintf(tokenstr, "%ld", token); sprintf(tokenstr, "%ld", token);
cfp = rot_confparam_lookup(rot, tokenstr); cfp = rot_confparam_lookup(rot, tokenstr);
if (!cfp)
if (!cfp) {
return -RIG_EINVAL; return -RIG_EINVAL;
rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val);
} }
if (IS_TOKEN_FRONTEND(token)) rot_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val);
return frontrot_set_conf(rot, token, val); }
if (rot->caps->set_conf == NULL) if (IS_TOKEN_FRONTEND(token)) {
return frontrot_set_conf(rot, token, val);
}
if (rot->caps->set_conf == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rot->caps->set_conf(rot, token, val); return rot->caps->set_conf(rot, token, val);
} }
/** /**
* \brief get the value of a configuration parameter * \brief get the value of a configuration parameter
* \param rot The rot handle * \param rot The rot handle
@ -448,14 +602,19 @@ int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val)
*/ */
int HAMLIB_API rot_get_conf(ROT *rot, token_t token, char *val) int HAMLIB_API rot_get_conf(ROT *rot, token_t token, char *val)
{ {
if (!rot || !rot->caps || !val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !val) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (IS_TOKEN_FRONTEND(token)) if (IS_TOKEN_FRONTEND(token)) {
return frontrot_get_conf(rot, token, val); return frontrot_get_conf(rot, token, val);
}
if (rot->caps->get_conf == NULL) if (rot->caps->get_conf == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rot->caps->get_conf(rot, token, val); return rot->caps->get_conf(rot, token, val);
} }

Wyświetl plik

@ -49,9 +49,14 @@
#define ROT_BACKEND_MAX 32 #define ROT_BACKEND_MAX 32
#define DEFINE_INITROT_BACKEND(backend) \ #define DEFINE_INITROT_BACKEND(backend) \
int MAKE_VERSIONED_FN(PREFIX_INITROTS, ABI_VERSION, backend(void *be_handle)); \ int MAKE_VERSIONED_FN(PREFIX_INITROTS, \
rig_model_t MAKE_VERSIONED_FN(PREFIX_PROBEROTS, ABI_VERSION, backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)) ABI_VERSION, \
backend(void *be_handle)); \
rig_model_t MAKE_VERSIONED_FN(PREFIX_PROBEROTS, \
ABI_VERSION, \
backend(hamlib_port_t *port, \
rig_probe_func_t cfunc, \
rig_ptr_t data))
#define ROT_FUNCNAMA(backend) MAKE_VERSIONED_FN(PREFIX_INITROTS, ABI_VERSION, backend) #define ROT_FUNCNAMA(backend) MAKE_VERSIONED_FN(PREFIX_INITROTS, ABI_VERSION, backend)
#define ROT_FUNCNAMB(backend) MAKE_VERSIONED_FN(PREFIX_PROBEROTS, ABI_VERSION, backend) #define ROT_FUNCNAMB(backend) MAKE_VERSIONED_FN(PREFIX_PROBEROTS, ABI_VERSION, backend)
@ -77,6 +82,7 @@ DEFINE_INITROT_BACKEND(ether6);
DEFINE_INITROT_BACKEND(cnctrk); DEFINE_INITROT_BACKEND(cnctrk);
DEFINE_INITROT_BACKEND(prosistel); DEFINE_INITROT_BACKEND(prosistel);
/*! \def ROT_BACKEND_LIST /*! \def ROT_BACKEND_LIST
* \brief Static list of rotator models. * \brief Static list of rotator models.
* *
@ -91,8 +97,7 @@ static struct {
const char *be_name; const char *be_name;
int (*be_init)(void *); int (*be_init)(void *);
rot_model_t (*be_probe)(hamlib_port_t *); rot_model_t (*be_probe)(hamlib_port_t *);
} rot_backend_list[ROT_BACKEND_MAX] = } rot_backend_list[ROT_BACKEND_MAX] = {
{
{ ROT_DUMMY, ROT_BACKEND_DUMMY, ROT_FUNCNAMA(dummy) }, { ROT_DUMMY, ROT_BACKEND_DUMMY, ROT_FUNCNAMA(dummy) },
{ ROT_EASYCOMM, ROT_BACKEND_EASYCOMM, ROT_FUNCNAMA(easycomm) }, { ROT_EASYCOMM, ROT_BACKEND_EASYCOMM, ROT_FUNCNAMA(easycomm) },
{ ROT_FODTRACK, ROT_BACKEND_FODTRACK, ROT_FUNCNAMA(fodtrack) }, { ROT_FODTRACK, ROT_BACKEND_FODTRACK, ROT_FUNCNAMA(fodtrack) },
@ -113,14 +118,12 @@ static struct {
{ 0, NULL }, /* end */ { 0, NULL }, /* end */
}; };
// Apparently, no rotator can be probed. // Apparently, no rotator can be probed.
/* /*
* ROT_BACKEND_LIST is here, please keep it up to data, * ROT_BACKEND_LIST is here, please keep it up to date,
* ie. each time you give birth to a new backend * i.e. each time you implement a new backend.
* Also, it should be possible to register "external" backend,
* that is backend that were not known by Hamlib at compile time.
* Maybe, rotlist.h should reserve some numbers for them? --SF
*/ */
@ -133,9 +136,11 @@ struct rot_list {
struct rot_list *next; struct rot_list *next;
}; };
#define ROTLSTHASHSZ 16 #define ROTLSTHASHSZ 16
#define HASH_FUNC(a) ((a)%ROTLSTHASHSZ) #define HASH_FUNC(a) ((a)%ROTLSTHASHSZ)
/* /*
* The rot_hash_table is a hash table pointing to a list of next==NULL * The rot_hash_table is a hash table pointing to a list of next==NULL
* terminated caps. * terminated caps.
@ -145,6 +150,7 @@ static struct rot_list *rot_hash_table[ROTLSTHASHSZ] = { NULL, };
static int rot_lookup_backend(rot_model_t rot_model); static int rot_lookup_backend(rot_model_t rot_model);
/* /*
* Basically, this is a hash insert function that doesn't check for dup! * Basically, this is a hash insert function that doesn't check for dup!
*/ */
@ -153,19 +159,25 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
int hval; int hval;
struct rot_list *p; struct rot_list *p;
if (!caps) if (!caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rot_debug(RIG_DEBUG_VERBOSE, "rot_register (%d)\n", caps->rot_model); rot_debug(RIG_DEBUG_VERBOSE, "rot_register (%d)\n", caps->rot_model);
#ifndef DONT_WANT_DUP_CHECK #ifndef DONT_WANT_DUP_CHECK
if (rot_get_caps(caps->rot_model)!=NULL)
if (rot_get_caps(caps->rot_model) != NULL) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
#endif #endif
p = (struct rot_list *)malloc(sizeof(struct rot_list)); p = (struct rot_list *)malloc(sizeof(struct rot_list));
if (!p)
if (!p) {
return -RIG_ENOMEM; return -RIG_ENOMEM;
}
hval = HASH_FUNC(caps->rot_model); hval = HASH_FUNC(caps->rot_model);
p->caps = caps; p->caps = caps;
@ -176,22 +188,25 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
return RIG_OK; return RIG_OK;
} }
/* /*
* Get rot capabilities. * Get rot capabilities.
* ie. rot_hash_table lookup * i.e. rot_hash_table lookup
*/ */
const struct rot_caps * HAMLIB_API rot_get_caps(rot_model_t rot_model) const struct rot_caps * HAMLIB_API rot_get_caps(rot_model_t rot_model)
{ {
struct rot_list *p; struct rot_list *p;
for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next) { for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next) {
if (p->caps->rot_model == rot_model) if (p->caps->rot_model == rot_model) {
return p->caps; return p->caps;
} }
}
return NULL; /* sorry, caps not registered! */ return NULL; /* sorry, caps not registered! */
} }
/* /*
* lookup for backend index in rot_backend_list table, * lookup for backend index in rot_backend_list table,
* according to BACKEND_NUM * according to BACKEND_NUM
@ -203,12 +218,15 @@ static int rot_lookup_backend(rot_model_t rot_model)
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) {
if (ROT_BACKEND_NUM(rot_model) == if (ROT_BACKEND_NUM(rot_model) ==
rot_backend_list[i].be_num) rot_backend_list[i].be_num) {
return i; return i;
} }
}
return -1; return -1;
} }
/* /*
* rot_check_backend * rot_check_backend
* check the backend declaring this model has been loaded * check the backend declaring this model has been loaded
@ -223,8 +241,10 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
/* already loaded ? */ /* already loaded ? */
caps = rot_get_caps(rot_model); caps = rot_get_caps(rot_model);
if (caps)
if (caps) {
return RIG_OK; return RIG_OK;
}
be_idx = rot_lookup_backend(rot_model); be_idx = rot_lookup_backend(rot_model);
@ -232,9 +252,11 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
* Never heard about this backend family! * Never heard about this backend family!
*/ */
if (be_idx == -1) { if (be_idx == -1) {
rot_debug(RIG_DEBUG_VERBOSE, "rot_check_backend: unsupported " rot_debug(RIG_DEBUG_VERBOSE,
"backend %d for model %d\n", "%s: unsupported backend %d for model %d\n",
__func__,
ROT_BACKEND_NUM(rot_model), rot_model); ROT_BACKEND_NUM(rot_model), rot_model);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -244,7 +266,6 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
} }
int HAMLIB_API rot_unregister(rot_model_t rot_model) int HAMLIB_API rot_unregister(rot_model_t rot_model)
{ {
int hval; int hval;
@ -252,40 +273,51 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model)
hval = HASH_FUNC(rot_model); hval = HASH_FUNC(rot_model);
q = NULL; q = NULL;
for (p = rot_hash_table[hval]; p; p = p->next) { for (p = rot_hash_table[hval]; p; p = p->next) {
if (p->caps->rot_model == rot_model) { if (p->caps->rot_model == rot_model) {
if (q == NULL) if (q == NULL) {
rot_hash_table[hval] = p->next; rot_hash_table[hval] = p->next;
else } else {
q->next = p->next; q->next = p->next;
}
free(p); free(p);
return RIG_OK; return RIG_OK;
} }
q = p; q = p;
} }
return -RIG_EINVAL; /* sorry, caps not registered! */ return -RIG_EINVAL; /* sorry, caps not registered! */
} }
/* /*
* rot_list_foreach * rot_list_foreach
* executes cfunc on all the elements stored in the rot hash list * executes cfunc on all the elements stored in the rot hash list
*/ */
int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps*, rig_ptr_t),rig_ptr_t data) int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps *, rig_ptr_t),
rig_ptr_t data)
{ {
struct rot_list *p; struct rot_list *p;
int i; int i;
if (!cfunc) if (!cfunc) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
for (i = 0; i < ROTLSTHASHSZ; i++) { for (i = 0; i < ROTLSTHASHSZ; i++) {
for (p = rot_hash_table[i]; p; p = p->next) for (p = rot_hash_table[i]; p; p = p->next)
if ((*cfunc)(p->caps,data) == 0) if ((*cfunc)(p->caps, data) == 0) {
return RIG_OK; return RIG_OK;
} }
}
return RIG_OK; return RIG_OK;
} }
/* /*
* rot_probe_all * rot_probe_all
* called straight by rot_probe * called straight by rot_probe
@ -298,10 +330,13 @@ rot_model_t HAMLIB_API rot_probe_all(hamlib_port_t *p)
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) {
if (rot_backend_list[i].be_probe) { if (rot_backend_list[i].be_probe) {
rot_model = (*rot_backend_list[i].be_probe)(p); rot_model = (*rot_backend_list[i].be_probe)(p);
if (rot_model != ROT_MODEL_NONE)
if (rot_model != ROT_MODEL_NONE) {
return rot_model; return rot_model;
} }
} }
}
return ROT_MODEL_NONE; return ROT_MODEL_NONE;
} }
@ -313,9 +348,11 @@ int rot_load_all_backends()
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) {
rot_load_backend(rot_backend_list[i].be_name); rot_load_backend(rot_backend_list[i].be_name);
} }
return RIG_OK; return RIG_OK;
} }
/* /*
* rot_load_backend * rot_load_backend
* Dynamically load a rot backend through dlopen mechanism * Dynamically load a rot backend through dlopen mechanism
@ -329,11 +366,12 @@ int HAMLIB_API rot_load_backend(const char *be_name)
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) {
if (!strcmp(be_name, rot_backend_list[i].be_name)) { if (!strcmp(be_name, rot_backend_list[i].be_name)) {
be_init = rot_backend_list[i].be_init; be_init = rot_backend_list[i].be_init;
if( be_init == NULL )
{ if (be_init == NULL) {
printf("Null\n"); printf("Null\n");
return -EINVAL; return -EINVAL;
} }
status = (*be_init)(NULL); status = (*be_init)(NULL);
return status; return status;
} }

Wyświetl plik

@ -54,7 +54,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "hamlib/rotator.h" #include <hamlib/rotator.h>
#include "serial.h" #include "serial.h"
#include "parallel.h" #include "parallel.h"
#include "usb_port.h" #include "usb_port.h"
@ -85,6 +85,7 @@
#define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) #define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
/* /*
* Data structure to track the opened rot (by rot_open) * Data structure to track the opened rot (by rot_open)
*/ */
@ -94,6 +95,7 @@ struct opened_rot_l {
}; };
static struct opened_rot_l *opened_rot_list = { NULL }; static struct opened_rot_l *opened_rot_list = { NULL };
/* /*
* track which rot is opened (with rot_open) * track which rot is opened (with rot_open)
* needed at least for transceive mode * needed at least for transceive mode
@ -102,14 +104,18 @@ static int add_opened_rot(ROT *rot)
{ {
struct opened_rot_l *p; struct opened_rot_l *p;
p = (struct opened_rot_l *)malloc(sizeof(struct opened_rot_l)); p = (struct opened_rot_l *)malloc(sizeof(struct opened_rot_l));
if (!p)
if (!p) {
return -RIG_ENOMEM; return -RIG_ENOMEM;
}
p->rot = rot; p->rot = rot;
p->next = opened_rot_list; p->next = opened_rot_list;
opened_rot_list = p; opened_rot_list = p;
return RIG_OK; return RIG_OK;
} }
static int remove_opened_rot(ROT *rot) static int remove_opened_rot(ROT *rot)
{ {
struct opened_rot_l *p, *q; struct opened_rot_l *p, *q;
@ -122,15 +128,19 @@ static int remove_opened_rot(ROT *rot)
} else { } else {
q->next = p->next; q->next = p->next;
} }
free(p); free(p);
return RIG_OK; return RIG_OK;
} }
q = p; q = p;
} }
return -RIG_EINVAL; /* Not found in list ! */ return -RIG_EINVAL; /* Not found in list ! */
} }
#endif /* !DOC_HIDDEN */ #endif /* !DOC_HIDDEN */
/** /**
* \brief execs cfunc() on each opened rot * \brief execs cfunc() on each opened rot
* \param cfunc The function to be executed on each rot * \param cfunc The function to be executed on each rot
@ -149,18 +159,22 @@ static int remove_opened_rot(ROT *rot)
* *
* \return always RIG_OK. * \return always RIG_OK.
*/ */
int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data) int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data)
{ {
struct opened_rot_l *p; struct opened_rot_l *p;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (p = opened_rot_list; p; p = p->next) { for (p = opened_rot_list; p; p = p->next) {
if ((*cfunc)(p->rot,data) == 0) if ((*cfunc)(p->rot, data) == 0) {
return RIG_OK; return RIG_OK;
} }
}
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief allocate a new #ROT handle * \brief allocate a new #ROT handle
* \param rot_model The rot model for this new handle * \param rot_model The rot model for this new handle
@ -173,7 +187,6 @@ int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data)
* *
* \sa rot_cleanup(), rot_open() * \sa rot_cleanup(), rot_open()
*/ */
ROT *HAMLIB_API rot_init(rot_model_t rot_model) ROT *HAMLIB_API rot_init(rot_model_t rot_model)
{ {
ROT *rot; ROT *rot;
@ -181,19 +194,22 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
struct rot_state *rs; struct rot_state *rs;
int retcode; int retcode;
rot_debug(RIG_DEBUG_VERBOSE,"rot:rot_init called \n"); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rot_check_backend(rot_model); rot_check_backend(rot_model);
caps = rot_get_caps(rot_model); caps = rot_get_caps(rot_model);
if (!caps)
if (!caps) {
return NULL; return NULL;
}
/* /*
* okay, we've found it. Allocate some memory and set it to zeros, * okay, we've found it. Allocate some memory and set it to zeros,
* and especially the initialize the callbacks * and especially the initialize the callbacks
*/ */
rot = calloc(1, sizeof(ROT)); rot = calloc(1, sizeof(ROT));
if (rot == NULL) { if (rot == NULL) {
/* /*
* FIXME: how can the caller know it's a memory shortage, * FIXME: how can the caller know it's a memory shortage,
@ -203,14 +219,13 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
} }
/* caps is const, so we need to tell compiler /* caps is const, so we need to tell compiler
that we now what we are doing */ that we know what we are doing */
rot->caps = (struct rot_caps *) caps; rot->caps = (struct rot_caps *) caps;
/* /*
* populate the rot->state * populate the rot->state
* TODO: read the Preferences here! * TODO: read the Preferences here!
*/ */
rs = &rot->state; rs = &rot->state;
rs->comm_state = 0; rs->comm_state = 0;
@ -258,8 +273,11 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
*/ */
if (caps->rot_init != NULL) { if (caps->rot_init != NULL) {
retcode = caps->rot_init(rot); retcode = caps->rot_init(rot);
if (retcode != RIG_OK) { if (retcode != RIG_OK) {
rot_debug(RIG_DEBUG_VERBOSE,"rot:backend_init failed!\n"); rot_debug(RIG_DEBUG_VERBOSE,
"%s: backend_init failed!\n",
__func__);
/* cleanup and exit */ /* cleanup and exit */
free(rot); free(rot);
return NULL; return NULL;
@ -269,6 +287,7 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
return rot; return rot;
} }
/** /**
* \brief open the communication to the rot * \brief open the communication to the rot
* \param rot The #ROT handle of the rotator to be opened * \param rot The #ROT handle of the rotator to be opened
@ -285,50 +304,63 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
* *
* \sa rot_init(), rot_close() * \sa rot_init(), rot_close()
*/ */
int HAMLIB_API rot_open(ROT *rot) int HAMLIB_API rot_open(ROT *rot)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
struct rot_state *rs; struct rot_state *rs;
int status; int status;
rot_debug(RIG_DEBUG_VERBOSE,"rot:rot_open called \n"); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) if (!rot || !rot->caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
rs = &rot->state; rs = &rot->state;
if (rs->comm_state) if (rs->comm_state) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
rs->rotport.fd = -1; rs->rotport.fd = -1;
switch (rs->rotport.type.rig) { switch (rs->rotport.type.rig) {
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
status = serial_open(&rs->rotport); status = serial_open(&rs->rotport);
if (status != 0)
if (status != 0) {
return status; return status;
}
break; break;
case RIG_PORT_PARALLEL: case RIG_PORT_PARALLEL:
status = par_open(&rs->rotport); status = par_open(&rs->rotport);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
case RIG_PORT_DEVICE: case RIG_PORT_DEVICE:
status = open(rs->rotport.pathname, O_RDWR, 0); status = open(rs->rotport.pathname, O_RDWR, 0);
if (status < 0)
if (status < 0) {
return -RIG_EIO; return -RIG_EIO;
}
rs->rotport.fd = status; rs->rotport.fd = status;
break; break;
case RIG_PORT_USB: case RIG_PORT_USB:
status = usb_port_open(&rs->rotport); status = usb_port_open(&rs->rotport);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
case RIG_PORT_NONE: case RIG_PORT_NONE:
@ -339,8 +371,11 @@ int HAMLIB_API rot_open(ROT *rot)
case RIG_PORT_UDP_NETWORK: case RIG_PORT_UDP_NETWORK:
/* FIXME: default port */ /* FIXME: default port */
status = network_open(&rs->rotport, 4533); status = network_open(&rs->rotport, 4533);
if (status < 0)
if (status < 0) {
return status; return status;
}
break; break;
default: default:
@ -358,6 +393,7 @@ int HAMLIB_API rot_open(ROT *rot)
*/ */
if (caps->rot_open != NULL) { if (caps->rot_open != NULL) {
status = caps->rot_open(rot); status = caps->rot_open(rot);
if (status != RIG_OK) { if (status != RIG_OK) {
return status; return status;
} }
@ -366,6 +402,7 @@ int HAMLIB_API rot_open(ROT *rot)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief close the communication to the rot * \brief close the communication to the rot
* \param rot The #ROT handle of the rotator to be closed * \param rot The #ROT handle of the rotator to be closed
@ -379,29 +416,31 @@ int HAMLIB_API rot_open(ROT *rot)
* *
* \sa rot_cleanup(), rot_open() * \sa rot_cleanup(), rot_open()
*/ */
int HAMLIB_API rot_close(ROT *rot) int HAMLIB_API rot_close(ROT *rot)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
struct rot_state *rs; struct rot_state *rs;
rot_debug(RIG_DEBUG_VERBOSE,"rot:rot_close called \n"); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) if (!rot || !rot->caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
rs = &rot->state; rs = &rot->state;
if (!rs->comm_state) if (!rs->comm_state) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
/* /*
* Let the backend say 73s to the rot. * Let the backend say 73s to the rot.
* and ignore the return code. * and ignore the return code.
*/ */
if (caps->rot_close) if (caps->rot_close) {
caps->rot_close(rot); caps->rot_close(rot);
}
if (rs->rotport.fd != -1) { if (rs->rotport.fd != -1) {
@ -409,19 +448,24 @@ int HAMLIB_API rot_close(ROT *rot)
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
ser_close(&rs->rotport); ser_close(&rs->rotport);
break; break;
case RIG_PORT_PARALLEL: case RIG_PORT_PARALLEL:
par_close(&rs->rotport); par_close(&rs->rotport);
break; break;
case RIG_PORT_USB: case RIG_PORT_USB:
usb_port_close(&rs->rotport); usb_port_close(&rs->rotport);
break; break;
case RIG_PORT_NETWORK: case RIG_PORT_NETWORK:
case RIG_PORT_UDP_NETWORK: case RIG_PORT_UDP_NETWORK:
network_close(&rs->rotport); network_close(&rs->rotport);
break; break;
default: default:
close(rs->rotport.fd); close(rs->rotport.fd);
} }
rs->rotport.fd = -1; rs->rotport.fd = -1;
} }
@ -432,6 +476,7 @@ int HAMLIB_API rot_close(ROT *rot)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief release a rot handle and free associated memory * \brief release a rot handle and free associated memory
* \param rot The #ROT handle of the radio to be closed * \param rot The #ROT handle of the radio to be closed
@ -445,31 +490,34 @@ int HAMLIB_API rot_close(ROT *rot)
* *
* \sa rot_init(), rot_close() * \sa rot_init(), rot_close()
*/ */
int HAMLIB_API rot_cleanup(ROT *rot) int HAMLIB_API rot_cleanup(ROT *rot)
{ {
rot_debug(RIG_DEBUG_VERBOSE,"rot:rot_cleanup called \n"); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) if (!rot || !rot->caps) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
/* /*
* check if they forgot to close the rot * check if they forgot to close the rot
*/ */
if (rot->state.comm_state) if (rot->state.comm_state) {
rot_close(rot); rot_close(rot);
}
/* /*
* basically free up the priv struct * basically free up the priv struct
*/ */
if (rot->caps->rot_cleanup) if (rot->caps->rot_cleanup) {
rot->caps->rot_cleanup(rot); rot->caps->rot_cleanup(rot);
}
free(rot); free(rot);
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief set the azimuth and elevation of the rotator * \brief set the azimuth and elevation of the rotator
* \param rot The rot handle * \param rot The rot handle
@ -484,28 +532,36 @@ int HAMLIB_API rot_cleanup(ROT *rot)
* *
* \sa rot_get_position() * \sa rot_get_position()
*/ */
int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
int HAMLIB_API rot_set_position (ROT *rot, azimuth_t azimuth, elevation_t elevation) elevation_t elevation)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
const struct rot_state *rs; const struct rot_state *rs;
if (CHECK_ROT_ARG(rot)) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
rs = &rot->state; rs = &rot->state;
if (azimuth < rs->min_az || azimuth > rs->max_az || if (azimuth < rs->min_az
elevation < rs->min_el || elevation > rs->max_el) || azimuth > rs->max_az
|| elevation < rs->min_el
|| elevation > rs->max_el) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
if (caps->set_position == NULL) if (caps->set_position == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return caps->set_position(rot, azimuth, elevation); return caps->set_position(rot, azimuth, elevation);
} }
/** /**
* \brief get the azimuth and elevation of the rotator * \brief get the azimuth and elevation of the rotator
* \param rot The rot handle * \param rot The rot handle
@ -520,22 +576,27 @@ int HAMLIB_API rot_set_position (ROT *rot, azimuth_t azimuth, elevation_t elevat
* *
* \sa rot_set_position() * \sa rot_set_position()
*/ */
int HAMLIB_API rot_get_position(ROT *rot, azimuth_t *azimuth,
int HAMLIB_API rot_get_position (ROT *rot, azimuth_t *azimuth, elevation_t *elevation) elevation_t *elevation)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
if (CHECK_ROT_ARG(rot) || !azimuth || !elevation) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !azimuth || !elevation) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
if (caps->get_position == NULL) if (caps->get_position == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return caps->get_position(rot, azimuth, elevation); return caps->get_position(rot, azimuth, elevation);
} }
/** /**
* \brief park the antenna * \brief park the antenna
* \param rot The rot handle * \param rot The rot handle
@ -547,22 +608,26 @@ int HAMLIB_API rot_get_position (ROT *rot, azimuth_t *azimuth, elevation_t *elev
* set appropriately). * set appropriately).
* *
*/ */
int HAMLIB_API rot_park(ROT *rot) int HAMLIB_API rot_park(ROT *rot)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
if (CHECK_ROT_ARG(rot)) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
if (caps->park == NULL) if (caps->park == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return caps->park(rot); return caps->park(rot);
} }
/** /**
* \brief stop the rotator * \brief stop the rotator
* \param rot The rot handle * \param rot The rot handle
@ -574,22 +639,26 @@ int HAMLIB_API rot_park (ROT *rot)
* set appropriately). * set appropriately).
* *
*/ */
int HAMLIB_API rot_stop(ROT *rot) int HAMLIB_API rot_stop(ROT *rot)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
if (CHECK_ROT_ARG(rot)) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
if (caps->stop == NULL) if (caps->stop == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return caps->stop(rot); return caps->stop(rot);
} }
/** /**
* \brief reset the rotator * \brief reset the rotator
* \param rot The rot handle * \param rot The rot handle
@ -602,22 +671,26 @@ int HAMLIB_API rot_stop (ROT *rot)
* set appropriately). * set appropriately).
* *
*/ */
int HAMLIB_API rot_reset(ROT *rot, rot_reset_t reset) int HAMLIB_API rot_reset(ROT *rot, rot_reset_t reset)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
if (CHECK_ROT_ARG(rot)) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
if (caps->reset == NULL) if (caps->reset == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return caps->reset(rot, reset); return caps->reset(rot, reset);
} }
/** /**
* \brief move the rotator in the specified direction * \brief move the rotator in the specified direction
* \param rot The rot handle * \param rot The rot handle
@ -631,17 +704,22 @@ int HAMLIB_API rot_move (ROT *rot, int direction, int speed)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
if (CHECK_ROT_ARG(rot)) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rot->caps; caps = rot->caps;
if (caps->move == NULL) if (caps->move == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return caps->move(rot, direction, speed); return caps->move(rot, direction, speed);
} }
/** /**
* \brief get general information from the rotator * \brief get general information from the rotator
* \param rot The rot handle * \param rot The rot handle
@ -655,11 +733,15 @@ int HAMLIB_API rot_move (ROT *rot, int direction, int speed)
*/ */
const char *HAMLIB_API rot_get_info(ROT *rot) const char *HAMLIB_API rot_get_info(ROT *rot)
{ {
if (CHECK_ROT_ARG(rot)) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return NULL;
if (rot->caps->get_info == NULL) if (CHECK_ROT_ARG(rot)) {
return NULL; return NULL;
}
if (rot->caps->get_info == NULL) {
return NULL;
}
return rot->caps->get_info(rot); return rot->caps->get_info(rot);
} }

Wyświetl plik

@ -82,18 +82,23 @@
#include <sys/ioccom.h> #include <sys/ioccom.h>
#endif #endif
/** /**
* \brief Open serial port using rig.state data * \brief Open serial port using rig.state data
* \param rp port data structure (must spec port id eg /dev/ttyS1) * \param rp port data structure (must spec port id eg /dev/ttyS1)
* \return RIG_OK or < 0 if error * \return RIG_OK or < 0 if error
*/ */
int HAMLIB_API serial_open(hamlib_port_t *rp) { int HAMLIB_API serial_open(hamlib_port_t *rp)
{
int fd; /* File descriptor for the port */ int fd; /* File descriptor for the port */
int err; int err;
if (!rp) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rp) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
/* /*
* Open in Non-blocking mode. Watch for EAGAIN errors! * Open in Non-blocking mode. Watch for EAGAIN errors!
@ -101,17 +106,19 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) {
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY); fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) { if (fd == -1) {
/* Could not open the port. */ /* Could not open the port. */
rig_debug(RIG_DEBUG_ERR,
rig_debug(RIG_DEBUG_ERR, "%s: Unable to open %s - %s\n", "%s: Unable to open %s - %s\n",
__func__, rp->pathname, strerror(errno)); __func__,
rp->pathname,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
rp->fd = fd; rp->fd = fd;
err = serial_setup(rp); err = serial_setup(rp);
if (err != RIG_OK) { if (err != RIG_OK) {
CLOSE(fd); CLOSE(fd);
return err; return err;
@ -120,6 +127,7 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) {
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Set up Serial port according to requests in port * \brief Set up Serial port according to requests in port
* \param rp * \param rp
@ -140,15 +148,17 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
#error "No term control supported!" #error "No term control supported!"
#endif #endif
if (!rp) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rp) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
fd = rp->fd; fd = rp->fd;
/* /*
* Get the current options for the port... * Get the current options for the port...
*/ */
#if defined(HAVE_TERMIOS_H) #if defined(HAVE_TERMIOS_H)
tcgetattr(fd, &options); tcgetattr(fd, &options);
#elif defined(HAVE_TERMIO_H) #elif defined(HAVE_TERMIO_H)
@ -158,53 +168,68 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
#endif #endif
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
cfmakeraw(&options); /* Set serial port to RAW mode by default. */ /* Set serial port to RAW mode by default. */
cfmakeraw(&options);
#endif #endif
/* /*
* Set the baud rates to requested values * Set the baud rates to requested values
*/ */
switch (rp->parm.serial.rate) { switch (rp->parm.serial.rate) {
case 150: case 150:
speed = B150; /* yikes... */ speed = B150; /* yikes... */
break; break;
case 300: case 300:
speed = B300; /* yikes... */ speed = B300; /* yikes... */
break; break;
case 600: case 600:
speed = B600; speed = B600;
break; break;
case 1200: case 1200:
speed = B1200; speed = B1200;
break; break;
case 2400: case 2400:
speed = B2400; speed = B2400;
break; break;
case 4800: case 4800:
speed = B4800; speed = B4800;
break; break;
case 9600: case 9600:
speed = B9600; speed = B9600;
break; break;
case 19200: case 19200:
speed = B19200; speed = B19200;
break; break;
case 38400: case 38400:
speed = B38400; speed = B38400;
break; break;
case 57600: case 57600:
speed = B57600; /* cool.. */ speed = B57600; /* cool.. */
break; break;
case 115200: case 115200:
speed = B115200; /* awsome! */ speed = B115200; /* awesome! */
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "%s: unsupported rate specified: %d\n", rig_debug(RIG_DEBUG_ERR,
__func__, rp->parm.serial.rate); "%s: unsupported rate specified: %d\n",
__func__,
rp->parm.serial.rate);
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; return -RIG_ECONF;
} }
/* TODO */ /* TODO */
cfsetispeed(&options, speed); cfsetispeed(&options, speed);
cfsetospeed(&options, speed); cfsetospeed(&options, speed);
@ -212,7 +237,6 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
/* /*
* Enable the receiver and set local mode... * Enable the receiver and set local mode...
*/ */
options.c_cflag |= (CLOCAL | CREAD); options.c_cflag |= (CLOCAL | CREAD);
/* /*
@ -224,20 +248,24 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set data to requested values. * Set data to requested values.
* *
*/ */
switch (rp->parm.serial.data_bits) { switch (rp->parm.serial.data_bits) {
case 7: case 7:
options.c_cflag &= ~CSIZE; options.c_cflag &= ~CSIZE;
options.c_cflag |= CS7; options.c_cflag |= CS7;
break; break;
case 8: case 8:
options.c_cflag &= ~CSIZE; options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8; options.c_cflag |= CS8;
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "%s: unsupported serial_data_bits " rig_debug(RIG_DEBUG_ERR,
"specified: %d\n", __func__, rp->parm.serial.data_bits); "%s: unsupported serial_data_bits specified: %d\n",
__func__,
rp->parm.serial.data_bits);
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
} }
@ -246,20 +274,22 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set stop bits to requested values. * Set stop bits to requested values.
* *
*/ */
switch (rp->parm.serial.stop_bits) { switch (rp->parm.serial.stop_bits) {
case 1: case 1:
options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSTOPB;
break; break;
case 2: case 2:
options.c_cflag |= CSTOPB; options.c_cflag |= CSTOPB;
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "%s: unsupported serial_stop_bits " rig_debug(RIG_DEBUG_ERR,
"specified: %d\n", __func__, "%s: unsupported serial_stop_bits specified: %d\n",
__func__,
rp->parm.serial.stop_bits); rp->parm.serial.stop_bits);
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
} }
@ -268,35 +298,41 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set parity to requested values. * Set parity to requested values.
* *
*/ */
switch (rp->parm.serial.parity) { switch (rp->parm.serial.parity) {
case RIG_PARITY_NONE: case RIG_PARITY_NONE:
options.c_cflag &= ~PARENB; options.c_cflag &= ~PARENB;
break; break;
case RIG_PARITY_EVEN: case RIG_PARITY_EVEN:
options.c_cflag |= PARENB; options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD; options.c_cflag &= ~PARODD;
break; break;
case RIG_PARITY_ODD: case RIG_PARITY_ODD:
options.c_cflag |= PARENB; options.c_cflag |= PARENB;
options.c_cflag |= PARODD; options.c_cflag |= PARODD;
break; break;
/* CMSPAR is not POSIX */ /* CMSPAR is not POSIX */
#ifdef CMSPAR #ifdef CMSPAR
case RIG_PARITY_MARK: case RIG_PARITY_MARK:
options.c_cflag |= PARENB | CMSPAR; options.c_cflag |= PARENB | CMSPAR;
options.c_cflag |= PARODD; options.c_cflag |= PARODD;
break; break;
case RIG_PARITY_SPACE: case RIG_PARITY_SPACE:
options.c_cflag |= PARENB | CMSPAR; options.c_cflag |= PARENB | CMSPAR;
options.c_cflag &= ~PARODD; options.c_cflag &= ~PARODD;
break; break;
#endif #endif
default: default:
rig_debug(RIG_DEBUG_ERR, "%s: unsupported serial_parity " rig_debug(RIG_DEBUG_ERR,
"specified: %d\n", __func__, "%s: unsupported serial_parity specified: %d\n",
__func__,
rp->parm.serial.parity); rp->parm.serial.parity);
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
} }
@ -306,25 +342,29 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set flow control to requested mode * Set flow control to requested mode
* *
*/ */
switch (rp->parm.serial.handshake) { switch (rp->parm.serial.handshake) {
case RIG_HANDSHAKE_NONE: case RIG_HANDSHAKE_NONE:
options.c_cflag &= ~CRTSCTS; options.c_cflag &= ~CRTSCTS;
options.c_iflag &= ~IXON; options.c_iflag &= ~IXON;
break; break;
case RIG_HANDSHAKE_XONXOFF: case RIG_HANDSHAKE_XONXOFF:
options.c_cflag &= ~CRTSCTS; options.c_cflag &= ~CRTSCTS;
options.c_iflag |= IXON; /* Enable Xon/Xoff software handshaking */ options.c_iflag |= IXON; /* Enable Xon/Xoff software handshaking */
break; break;
case RIG_HANDSHAKE_HARDWARE: case RIG_HANDSHAKE_HARDWARE:
options.c_cflag |= CRTSCTS; /* Enable Hardware handshaking */ options.c_cflag |= CRTSCTS; /* Enable Hardware handshaking */
options.c_iflag &= ~IXON; options.c_iflag &= ~IXON;
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR, "%s: unsupported flow_control " rig_debug(RIG_DEBUG_ERR,
"specified: %d\n", __func__, "%s: unsupported flow_control specified: %d\n",
__func__,
rp->parm.serial.handshake); rp->parm.serial.handshake);
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; return -RIG_ECONF;
break; break;
} }
@ -332,14 +372,12 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
/* /*
* Choose raw input, no preprocessing please .. * Choose raw input, no preprocessing please ..
*/ */
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H) #if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
/* /*
* Choose raw output, no preprocessing please .. * Choose raw output, no preprocessing please ..
*/ */
options.c_oflag &= ~OPOST; options.c_oflag &= ~OPOST;
#else /* sgtty */ #else /* sgtty */
@ -355,34 +393,47 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
/* /*
* Flush serial port * Flush serial port
*/ */
tcflush(fd, TCIFLUSH); tcflush(fd, TCIFLUSH);
/* /*
* Finally, set the new options for the port... * Finally, set the new options for the port...
*/ */
#if defined(HAVE_TERMIOS_H) #if defined(HAVE_TERMIOS_H)
if (tcsetattr(fd, TCSANOW, &options) == -1) { if (tcsetattr(fd, TCSANOW, &options) == -1) {
rig_debug(RIG_DEBUG_ERR, "%s: tcsetattr failed: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, strerror(errno)); "%s: tcsetattr failed: %s\n",
__func__,
strerror(errno));
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; /* arg, so close! */ return -RIG_ECONF; /* arg, so close! */
} }
#elif defined(HAVE_TERMIO_H) #elif defined(HAVE_TERMIO_H)
if (IOCTL(fd, TCSETA, &options) == -1) { if (IOCTL(fd, TCSETA, &options) == -1) {
rig_debug(RIG_DEBUG_ERR, "%s: ioctl(TCSETA) failed: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, strerror(errno)); "%s: ioctl(TCSETA) failed: %s\n",
__func__,
strerror(errno));
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; /* arg, so close! */ return -RIG_ECONF; /* arg, so close! */
} }
#else /* sgtty */
#else
/* sgtty */
if (IOCTL(fd, TIOCSETP, &sg) == -1) { if (IOCTL(fd, TIOCSETP, &sg) == -1) {
rig_debug(RIG_DEBUG_ERR, "%s: ioctl(TIOCSETP) failed: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, strerror(errno)); "%s: ioctl(TIOCSETP) failed: %s\n",
__func__,
strerror(errno));
CLOSE(fd); CLOSE(fd);
return -RIG_ECONF; /* arg, so close! */ return -RIG_ECONF; /* arg, so close! */
} }
#endif #endif
return RIG_OK; return RIG_OK;
@ -396,11 +447,14 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
*/ */
int HAMLIB_API serial_flush(hamlib_port_t *p) int HAMLIB_API serial_flush(hamlib_port_t *p)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
tcflush(p->fd, TCIFLUSH); tcflush(p->fd, TCIFLUSH);
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Open serial port * \brief Open serial port
* \param p * \param p
@ -408,9 +462,12 @@ int HAMLIB_API serial_flush(hamlib_port_t *p )
*/ */
int ser_open(hamlib_port_t *p) int ser_open(hamlib_port_t *p)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return (p->fd = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY)); return (p->fd = OPEN(p->pathname, O_RDWR | O_NOCTTY | O_NDELAY));
} }
/** /**
* \brief Close serial port * \brief Close serial port
* \param p fd * \param p fd
@ -418,11 +475,14 @@ int ser_open(hamlib_port_t *p)
*/ */
int ser_close(hamlib_port_t *p) int ser_close(hamlib_port_t *p)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
int rc = CLOSE(p->fd); int rc = CLOSE(p->fd);
p->fd = -1; p->fd = -1;
return rc; return rc;
} }
/** /**
* \brief Set Request to Send (RTS) bit * \brief Set Request to Send (RTS) bit
* \param p * \param p
@ -434,29 +494,39 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state)
unsigned int y = TIOCM_RTS; unsigned int y = TIOCM_RTS;
int rc; int rc;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rig_debug(RIG_DEBUG_VERBOSE, "%s: RTS=%d\n", __func__, state); rig_debug(RIG_DEBUG_VERBOSE, "%s: RTS=%d\n", __func__, state);
#if defined(TIOCMBIS) && defined(TIOCMBIC) #if defined(TIOCMBIS) && defined(TIOCMBIC)
rc = IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y); rc = IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y);
#else #else
rc = IOCTL(p->fd, TIOCMGET, &y); rc = IOCTL(p->fd, TIOCMGET, &y);
if (rc >= 0)
{ if (rc >= 0) {
if (state) if (state) {
y |= TIOCM_RTS; y |= TIOCM_RTS;
else } else {
y &= ~TIOCM_RTS; y &= ~TIOCM_RTS;
}
rc = IOCTL(p->fd, TIOCMSET, &y); rc = IOCTL(p->fd, TIOCMSET, &y);
} }
#endif #endif
if (rc < 0)
{ if (rc < 0) {
rig_debug(RIG_DEBUG_ERR, "%s: Cannot change RTS - %s\n", __func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: Cannot change RTS - %s\n",
__func__,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Get RTS bit * \brief Get RTS bit
* \param p supposed to be &rig->state.rigport * \param p supposed to be &rig->state.rigport
@ -467,12 +537,15 @@ int HAMLIB_API ser_get_rts(hamlib_port_t *p, int *state)
int retcode; int retcode;
unsigned int y; unsigned int y;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
retcode = IOCTL(p->fd, TIOCMGET, &y); retcode = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_RTS) == TIOCM_RTS; *state = (y & TIOCM_RTS) == TIOCM_RTS;
return retcode < 0 ? -RIG_EIO : RIG_OK; return retcode < 0 ? -RIG_EIO : RIG_OK;
} }
/** /**
* \brief Set Data Terminal Ready (DTR) bit * \brief Set Data Terminal Ready (DTR) bit
* \param p * \param p
@ -484,29 +557,39 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state)
unsigned int y = TIOCM_DTR; unsigned int y = TIOCM_DTR;
int rc; int rc;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rig_debug(RIG_DEBUG_VERBOSE, "%s: DTR=%d\n", __func__, state); rig_debug(RIG_DEBUG_VERBOSE, "%s: DTR=%d\n", __func__, state);
#if defined(TIOCMBIS) && defined(TIOCMBIC) #if defined(TIOCMBIS) && defined(TIOCMBIC)
rc = IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y); rc = IOCTL(p->fd, state ? TIOCMBIS : TIOCMBIC, &y);
#else #else
rc = IOCTL(p->fd, TIOCMGET, &y); rc = IOCTL(p->fd, TIOCMGET, &y);
if (rc >= 0)
{ if (rc >= 0) {
if (state) if (state) {
y |= TIOCM_DTR; y |= TIOCM_DTR;
else } else {
y &= ~TIOCM_DTR; y &= ~TIOCM_DTR;
}
rc = IOCTL(p->fd, TIOCMSET, &y); rc = IOCTL(p->fd, TIOCMSET, &y);
} }
#endif #endif
if (rc < 0)
{ if (rc < 0) {
rig_debug(RIG_DEBUG_ERR, "%s: Cannot change DTR - %s\n", __func__, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s: Cannot change DTR - %s\n",
__func__,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Get DTR bit * \brief Get DTR bit
* \param p supposed to be &rig->state.rigport * \param p supposed to be &rig->state.rigport
@ -517,12 +600,15 @@ int HAMLIB_API ser_get_dtr(hamlib_port_t *p, int *state)
int retcode; int retcode;
unsigned int y; unsigned int y;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
retcode = IOCTL(p->fd, TIOCMGET, &y); retcode = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_DTR) == TIOCM_DTR; *state = (y & TIOCM_DTR) == TIOCM_DTR;
return retcode < 0 ? -RIG_EIO : RIG_OK; return retcode < 0 ? -RIG_EIO : RIG_OK;
} }
/** /**
* \brief Set Break * \brief Set Break
* \param p * \param p
@ -531,6 +617,8 @@ int HAMLIB_API ser_get_dtr(hamlib_port_t *p, int *state)
*/ */
int HAMLIB_API ser_set_brk(hamlib_port_t *p, int state) int HAMLIB_API ser_set_brk(hamlib_port_t *p, int state)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#if defined(TIOCSBRK) && defined(TIOCCBRK) #if defined(TIOCSBRK) && defined(TIOCCBRK)
return IOCTL(p->fd, state ? TIOCSBRK : TIOCCBRK, 0) < 0 ? return IOCTL(p->fd, state ? TIOCSBRK : TIOCCBRK, 0) < 0 ?
-RIG_EIO : RIG_OK; -RIG_EIO : RIG_OK;
@ -539,6 +627,7 @@ int HAMLIB_API ser_set_brk(hamlib_port_t *p, int state)
#endif #endif
} }
/** /**
* \brief Get Carrier (CI?) bit * \brief Get Carrier (CI?) bit
* \param p supposed to be &rig->state.rigport * \param p supposed to be &rig->state.rigport
@ -549,12 +638,15 @@ int HAMLIB_API ser_get_car(hamlib_port_t *p, int *state)
int retcode; int retcode;
unsigned int y; unsigned int y;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
retcode = IOCTL(p->fd, TIOCMGET, &y); retcode = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_CAR) == TIOCM_CAR; *state = (y & TIOCM_CAR) == TIOCM_CAR;
return retcode < 0 ? -RIG_EIO : RIG_OK; return retcode < 0 ? -RIG_EIO : RIG_OK;
} }
/** /**
* \brief Get Clear to Send (CTS) bit * \brief Get Clear to Send (CTS) bit
* \param p supposed to be &rig->state.rigport * \param p supposed to be &rig->state.rigport
@ -565,12 +657,15 @@ int HAMLIB_API ser_get_cts(hamlib_port_t *p, int *state)
int retcode; int retcode;
unsigned int y; unsigned int y;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
retcode = IOCTL(p->fd, TIOCMGET, &y); retcode = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_CTS) == TIOCM_CTS; *state = (y & TIOCM_CTS) == TIOCM_CTS;
return retcode < 0 ? -RIG_EIO : RIG_OK; return retcode < 0 ? -RIG_EIO : RIG_OK;
} }
/** /**
* \brief Get Data Set Ready (DSR) bit * \brief Get Data Set Ready (DSR) bit
* \param p supposed to be &rig->state.rigport * \param p supposed to be &rig->state.rigport
@ -581,6 +676,8 @@ int HAMLIB_API ser_get_dsr(hamlib_port_t *p, int *state)
int retcode; int retcode;
unsigned int y; unsigned int y;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
retcode = IOCTL(p->fd, TIOCMGET, &y); retcode = IOCTL(p->fd, TIOCMGET, &y);
*state = (y & TIOCM_DSR) == TIOCM_DSR; *state = (y & TIOCM_DSR) == TIOCM_DSR;

Wyświetl plik

@ -45,7 +45,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "hamlib/rig.h" #include <hamlib/rig.h>
#include "cal.h" #include "cal.h"
@ -79,30 +79,41 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_level == NULL || !rig_has_set_level(rig,level)) if (caps->set_level == NULL || !rig_has_set_level(rig, level)) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo&RIG_TARGETABLE_PURE) || if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) || vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
return caps->set_level(rig, vfo, level, val); return caps->set_level(rig, vfo, level, val);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_level(rig, vfo, level, val); retcode = caps->set_level(rig, vfo, level, val);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the value of a level * \brief get the value of a level
* \param rig The rig handle * \param rig The rig handle
@ -133,48 +144,63 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !val) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_level == NULL || !rig_has_get_level(rig,level)) if (caps->get_level == NULL || !rig_has_get_level(rig, level)) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
/* /*
* Special case(frontend emulation): calibrated S-meter reading * Special case(frontend emulation): calibrated S-meter reading
*/ */
if (level == RIG_LEVEL_STRENGTH && if (level == RIG_LEVEL_STRENGTH
(caps->has_get_level & RIG_LEVEL_STRENGTH) == 0 && && (caps->has_get_level & RIG_LEVEL_STRENGTH) == 0
rig_has_get_level(rig,RIG_LEVEL_RAWSTR) && && rig_has_get_level(rig, RIG_LEVEL_RAWSTR)
rig->state.str_cal.size) { && rig->state.str_cal.size) {
value_t rawstr; value_t rawstr;
retcode = rig_get_level(rig, vfo, RIG_LEVEL_RAWSTR, &rawstr); retcode = rig_get_level(rig, vfo, RIG_LEVEL_RAWSTR, &rawstr);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal); val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal);
return RIG_OK; return RIG_OK;
} }
if ((caps->targetable_vfo&RIG_TARGETABLE_PURE) || if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) || vfo == RIG_VFO_CURR
return caps->get_level(rig, vfo, level, val); || vfo == rig->state.current_vfo) {
if (!caps->set_vfo) return caps->get_level(rig, vfo, level, val);
}
if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_level(rig, vfo, level, val); retcode = caps->get_level(rig, vfo, level, val);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief set a radio parameter * \brief set a radio parameter
* \param rig The rig handle * \param rig The rig handle
@ -193,15 +219,20 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
*/ */
int HAMLIB_API rig_set_parm(RIG *rig, setting_t parm, value_t val) int HAMLIB_API rig_set_parm(RIG *rig, setting_t parm, value_t val)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
if (rig->caps->set_parm == NULL || !rig_has_set_parm(rig,parm)) if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL;
}
if (rig->caps->set_parm == NULL || !rig_has_set_parm(rig, parm)) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rig->caps->set_parm(rig, parm, val); return rig->caps->set_parm(rig, parm, val);
} }
/** /**
* \brief get the value of a parameter * \brief get the value of a parameter
* \param rig The rig handle * \param rig The rig handle
@ -220,15 +251,20 @@ int HAMLIB_API rig_set_parm(RIG *rig, setting_t parm, value_t val)
*/ */
int HAMLIB_API rig_get_parm(RIG *rig, setting_t parm, value_t *val) int HAMLIB_API rig_get_parm(RIG *rig, setting_t parm, value_t *val)
{ {
if (CHECK_RIG_ARG(rig) || !val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
if (rig->caps->get_parm == NULL || !rig_has_get_parm(rig,parm)) if (CHECK_RIG_ARG(rig) || !val) {
return -RIG_EINVAL;
}
if (rig->caps->get_parm == NULL || !rig_has_get_parm(rig, parm)) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rig->caps->get_parm(rig, parm, val); return rig->caps->get_parm(rig, parm, val);
} }
/** /**
* \brief check retrieval ability of level settings * \brief check retrieval ability of level settings
* \param rig The rig handle * \param rig The rig handle
@ -247,8 +283,11 @@ int HAMLIB_API rig_get_parm(RIG *rig, setting_t parm, value_t *val)
*/ */
setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level) setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return 0; return 0;
}
return (rig->state.has_get_level & level); return (rig->state.has_get_level & level);
} }
@ -272,12 +311,16 @@ setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level)
*/ */
setting_t HAMLIB_API rig_has_set_level(RIG *rig, setting_t level) setting_t HAMLIB_API rig_has_set_level(RIG *rig, setting_t level)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return 0; return 0;
}
return (rig->state.has_set_level & level); return (rig->state.has_set_level & level);
} }
/** /**
* \brief check retrieval ability of parameter settings * \brief check retrieval ability of parameter settings
* \param rig The rig handle * \param rig The rig handle
@ -296,8 +339,11 @@ setting_t HAMLIB_API rig_has_set_level(RIG *rig, setting_t level)
*/ */
setting_t HAMLIB_API rig_has_get_parm(RIG *rig, setting_t parm) setting_t HAMLIB_API rig_has_get_parm(RIG *rig, setting_t parm)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return 0; return 0;
}
return (rig->state.has_get_parm & parm); return (rig->state.has_get_parm & parm);
} }
@ -321,12 +367,16 @@ setting_t HAMLIB_API rig_has_get_parm(RIG *rig, setting_t parm)
*/ */
setting_t HAMLIB_API rig_has_set_parm(RIG *rig, setting_t parm) setting_t HAMLIB_API rig_has_set_parm(RIG *rig, setting_t parm)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return 0; return 0;
}
return (rig->state.has_set_parm & parm); return (rig->state.has_set_parm & parm);
} }
/** /**
* \brief check ability of radio functions * \brief check ability of radio functions
* \param rig The rig handle * \param rig The rig handle
@ -345,12 +395,16 @@ setting_t HAMLIB_API rig_has_set_parm(RIG *rig, setting_t parm)
*/ */
setting_t HAMLIB_API rig_has_get_func(RIG *rig, setting_t func) setting_t HAMLIB_API rig_has_get_func(RIG *rig, setting_t func)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return 0; return 0;
}
return (rig->state.has_get_func & func); return (rig->state.has_get_func & func);
} }
/** /**
* \brief check ability of radio functions * \brief check ability of radio functions
* \param rig The rig handle * \param rig The rig handle
@ -369,12 +423,16 @@ setting_t HAMLIB_API rig_has_get_func(RIG *rig, setting_t func)
*/ */
setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func) setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func)
{ {
if (!rig || !rig->caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) {
return 0; return 0;
}
return (rig->state.has_set_func & func); return (rig->state.has_set_func & func);
} }
/** /**
* \brief activate/de-activate functions of radio * \brief activate/de-activate functions of radio
* \param rig The rig handle * \param rig The rig handle
@ -393,37 +451,48 @@ setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func)
* *
* \sa rig_get_func() * \sa rig_get_func()
*/ */
int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_func == NULL || !rig_has_set_func(rig,func)) if (caps->set_func == NULL || !rig_has_set_func(rig, func)) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_FUNC) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->set_func(rig, vfo, func, status); return caps->set_func(rig, vfo, func, status);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_func(rig, vfo, func, status); retcode = caps->set_func(rig, vfo, func, status);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the status of functions of the radio * \brief get the status of functions of the radio
* \param rig The rig handle * \param rig The rig handle
@ -449,30 +518,43 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !func) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !func) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_func == NULL || !rig_has_get_func(rig,func)) if (caps->get_func == NULL || !rig_has_get_func(rig, func)) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_FUNC) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->get_func(rig, vfo, func, status); return caps->get_func(rig, vfo, func, status);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_func(rig, vfo, func, status); retcode = caps->get_func(rig, vfo, func, status);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief set a radio level extra parameter * \brief set a radio level extra parameter
* \param rig The rig handle * \param rig The rig handle
@ -488,36 +570,50 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
* *
* \sa rig_get_ext_level() * \sa rig_get_ext_level()
*/ */
int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val) int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token,
value_t val)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_ext_level == NULL) if (caps->set_ext_level == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_PURE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->set_ext_level(rig, vfo, token, val); return caps->set_ext_level(rig, vfo, token, val);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_ext_level(rig, vfo, token, val); retcode = caps->set_ext_level(rig, vfo, token, val);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the value of a level extra parameter * \brief get the value of a level extra parameter
* \param rig The rig handle * \param rig The rig handle
@ -533,36 +629,50 @@ int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val
* *
* \sa rig_set_ext_level() * \sa rig_set_ext_level()
*/ */
int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *val) int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token,
value_t *val)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !val) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_ext_level == NULL) if (caps->get_ext_level == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_PURE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->get_ext_level(rig, vfo, token, val); return caps->get_ext_level(rig, vfo, token, val);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_ext_level(rig, vfo, token, val); retcode = caps->get_ext_level(rig, vfo, token, val);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief set a radio parm extra parameter * \brief set a radio parm extra parameter
* \param rig The rig handle * \param rig The rig handle
@ -579,15 +689,20 @@ int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *va
*/ */
int HAMLIB_API rig_set_ext_parm(RIG *rig, token_t token, value_t val) int HAMLIB_API rig_set_ext_parm(RIG *rig, token_t token, value_t val)
{ {
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
if (rig->caps->set_ext_parm == NULL) if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL;
}
if (rig->caps->set_ext_parm == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rig->caps->set_ext_parm(rig, token, val); return rig->caps->set_ext_parm(rig, token, val);
} }
/** /**
* \brief get the value of a parm extra parameter * \brief get the value of a parm extra parameter
* \param rig The rig handle * \param rig The rig handle
@ -604,11 +719,15 @@ int HAMLIB_API rig_set_ext_parm(RIG *rig, token_t token, value_t val)
*/ */
int HAMLIB_API rig_get_ext_parm(RIG *rig, token_t token, value_t *val) int HAMLIB_API rig_get_ext_parm(RIG *rig, token_t token, value_t *val)
{ {
if (CHECK_RIG_ARG(rig) || !val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_EINVAL;
if (rig->caps->get_ext_parm == NULL) if (CHECK_RIG_ARG(rig) || !val) {
return -RIG_EINVAL;
}
if (rig->caps->get_ext_parm == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
return rig->caps->get_ext_parm(rig, token, val); return rig->caps->get_ext_parm(rig, token, val);
} }
@ -627,10 +746,13 @@ int HAMLIB_API rig_setting2idx(setting_t s)
{ {
int i; int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0; i < RIG_SETTING_MAX; i++) { for (i = 0; i < RIG_SETTING_MAX; i++) {
if (s & rig_idx2setting(i)) if (s & rig_idx2setting(i)) {
return i; return i;
} }
}
return 0; return 0;
} }

Wyświetl plik

@ -36,7 +36,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "hamlib/rig.h" #include <hamlib/rig.h>
#include "tones.h" #include "tones.h"
#if !defined(_WIN32) && !defined(__CYGWIN__) #if !defined(_WIN32) && !defined(__CYGWIN__)
@ -97,37 +97,49 @@ const tone_t full_dcs_list[] = { FULL_DCS_LIST };
* *
* \sa rig_get_ctcss_tone(), rig_set_ctcss_sql() * \sa rig_get_ctcss_tone(), rig_set_ctcss_sql()
*/ */
int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_ctcss_tone == NULL) if (caps->set_ctcss_tone == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->set_ctcss_tone(rig, vfo, tone); return caps->set_ctcss_tone(rig, vfo, tone);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_ctcss_tone(rig, vfo, tone); retcode = caps->set_ctcss_tone(rig, vfo, tone);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the current CTCSS sub-tone frequency * \brief get the current CTCSS sub-tone frequency
* \param rig The rig handle * \param rig The rig handle
@ -153,30 +165,43 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !tone) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_ctcss_tone == NULL) if (caps->get_ctcss_tone == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->get_ctcss_tone(rig, vfo, tone); return caps->get_ctcss_tone(rig, vfo, tone);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_ctcss_tone(rig, vfo, tone); retcode = caps->get_ctcss_tone(rig, vfo, tone);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief set the current encoding DCS code * \brief set the current encoding DCS code
* \param rig The rig handle * \param rig The rig handle
@ -198,30 +223,43 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_dcs_code == NULL) if (caps->set_dcs_code == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->set_dcs_code(rig, vfo, code); return caps->set_dcs_code(rig, vfo, code);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_dcs_code(rig, vfo, code); retcode = caps->set_dcs_code(rig, vfo, code);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the current encoding DCS code * \brief get the current encoding DCS code
* \param rig The rig handle * \param rig The rig handle
@ -242,30 +280,43 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !code) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_dcs_code == NULL) if (caps->get_dcs_code == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->get_dcs_code(rig, vfo, code); return caps->get_dcs_code(rig, vfo, code);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_dcs_code(rig, vfo, code); retcode = caps->get_dcs_code(rig, vfo, code);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief set CTCSS squelch * \brief set CTCSS squelch
* \param rig The rig handle * \param rig The rig handle
@ -288,37 +339,49 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
* *
* \sa rig_get_ctcss_sql(), rig_set_ctcss_tone() * \sa rig_get_ctcss_sql(), rig_set_ctcss_tone()
*/ */
int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_ctcss_sql == NULL) if (caps->set_ctcss_sql == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->set_ctcss_sql(rig, vfo, tone); return caps->set_ctcss_sql(rig, vfo, tone);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_ctcss_sql(rig, vfo, tone); retcode = caps->set_ctcss_sql(rig, vfo, tone);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the current CTCSS squelch * \brief get the current CTCSS squelch
* \param rig The rig handle * \param rig The rig handle
@ -344,30 +407,43 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !tone) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_ctcss_sql == NULL) if (caps->get_ctcss_sql == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->get_ctcss_sql(rig, vfo, tone); return caps->get_ctcss_sql(rig, vfo, tone);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_ctcss_sql(rig, vfo, tone); retcode = caps->get_ctcss_sql(rig, vfo, tone);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief set the current DCS code * \brief set the current DCS code
* \param rig The rig handle * \param rig The rig handle
@ -382,37 +458,49 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
* *
* \sa rig_get_dcs_sql(), rig_set_dcs_code() * \sa rig_get_dcs_sql(), rig_set_dcs_code()
*/ */
int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
{ {
const struct rig_caps *caps; const struct rig_caps *caps;
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig)) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->set_dcs_sql == NULL) if (caps->set_dcs_sql == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->set_dcs_sql(rig, vfo, code); return caps->set_dcs_sql(rig, vfo, code);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->set_dcs_sql(rig, vfo, code); retcode = caps->set_dcs_sql(rig, vfo, code);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
/** /**
* \brief get the current DCS code * \brief get the current DCS code
* \param rig The rig handle * \param rig The rig handle
@ -433,27 +521,39 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code)
int retcode; int retcode;
vfo_t curr_vfo; vfo_t curr_vfo;
if (CHECK_RIG_ARG(rig) || !code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !code) {
return -RIG_EINVAL; return -RIG_EINVAL;
}
caps = rig->caps; caps = rig->caps;
if (caps->get_dcs_sql == NULL) if (caps->get_dcs_sql == NULL) {
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) {
if ((caps->targetable_vfo&RIG_TARGETABLE_TONE) ||
vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)
return caps->get_dcs_sql(rig, vfo, code); return caps->get_dcs_sql(rig, vfo, code);
}
if (!caps->set_vfo) if (!caps->set_vfo) {
return -RIG_ENTARGET; return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
if (retcode != RIG_OK) {
return retcode; return retcode;
}
retcode = caps->get_dcs_sql(rig, vfo, code); retcode = caps->get_dcs_sql(rig, vfo, code);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }

Wyświetl plik

@ -23,7 +23,7 @@
#define _TONES_H 1 #define _TONES_H 1
#include "hamlib/rig.h" /* and implicitly rig_dll.h */ #include <hamlib/rig.h> /* and implicitly rig_dll.h */
/* /*
@ -41,6 +41,7 @@ static const tone_t static_full_ctcss_list[] = {
FULL_CTCSS_LIST FULL_CTCSS_LIST
}; };
/* /*
* 50 CTCSS sub-audible tones, from 67.0Hz to 254.1Hz * 50 CTCSS sub-audible tones, from 67.0Hz to 254.1Hz
* *
@ -60,6 +61,7 @@ static const tone_t static_common_ctcss_list[] = {
COMMON_CTCSS_LIST COMMON_CTCSS_LIST
}; };
/* /*
* 104 DCS codes * 104 DCS codes
*/ */
@ -79,6 +81,7 @@ static const tone_t static_common_dcs_list[] = {
COMMON_DCS_LIST COMMON_DCS_LIST
}; };
/* /*
* 106 DCS codes * 106 DCS codes
*/ */
@ -98,6 +101,7 @@ static const tone_t static_full_dcs_list[] = {
FULL_DCS_LIST FULL_DCS_LIST
}; };
/* /*
* These arrays cannot be shared on Win32 systems, * These arrays cannot be shared on Win32 systems,
* because DLL's vars don't have constant address. * because DLL's vars don't have constant address.

Wyświetl plik

@ -35,7 +35,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include "hamlib/rig.h" #include <hamlib/rig.h>
/* /*
* Compile only if libusb is available * Compile only if libusb is available
@ -60,7 +60,6 @@
#include "usb_port.h" #include "usb_port.h"
/** /**
* \brief Find and open USB device * \brief Find and open USB device
* \param port * \param port
@ -74,14 +73,22 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
char string[256]; char string[256];
int i, r; int i, r;
rig_debug(RIG_DEBUG_VERBOSE, "%s: looking for device %04x:%04x...", rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
__func__, port->parm.usb.vid, port->parm.usb.pid);
rig_debug(RIG_DEBUG_VERBOSE,
"%s: looking for device %04x:%04x...",
__func__,
port->parm.usb.vid,
port->parm.usb.pid);
r = libusb_get_device_list(NULL, &devs); r = libusb_get_device_list(NULL, &devs);
if (r < 0) { if (r < 0) {
rig_debug(RIG_DEBUG_ERR, "%s: failed getting usb device list: %s", rig_debug(RIG_DEBUG_ERR,
__func__, libusb_error_name(r)); "%s: failed getting usb device list: %s",
__func__,
libusb_error_name(r));
return NULL; return NULL;
} }
@ -89,18 +96,23 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
libusb_get_device_descriptor(dev, &desc); libusb_get_device_descriptor(dev, &desc);
rig_debug(RIG_DEBUG_VERBOSE, " %04x:%04x,", rig_debug(RIG_DEBUG_VERBOSE,
desc.idVendor, desc.idProduct); " %04x:%04x,",
desc.idVendor,
desc.idProduct);
if (desc.idVendor == port->parm.usb.vid && if (desc.idVendor == port->parm.usb.vid
desc.idProduct == port->parm.usb.pid) { && desc.idProduct == port->parm.usb.pid) {
/* we need to open the device in order to query strings */ /* we need to open the device in order to query strings */
r = libusb_open(dev, &udh); r = libusb_open(dev, &udh);
if (r < 0) { if (r < 0) {
rig_debug(RIG_DEBUG_WARN, "%s: Warning: Cannot open USB device: %s\n", rig_debug(RIG_DEBUG_WARN,
__func__, libusb_error_name(r)); "%s: Warning: Cannot open USB device: %s\n",
__func__,
libusb_error_name(r));
continue; continue;
} }
@ -108,10 +120,16 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
if (port->parm.usb.vendor_name) { if (port->parm.usb.vendor_name) {
string[0] = '\0'; string[0] = '\0';
r = libusb_get_string_descriptor_ascii(udh, desc.iManufacturer, (unsigned char *)string, sizeof(string)); r = libusb_get_string_descriptor_ascii(udh,
desc.iManufacturer,
(unsigned char *)string,
sizeof(string));
if (r < 0) { if (r < 0) {
rig_debug(RIG_DEBUG_WARN, "Warning: cannot query manufacturer for USB device: %s\n", libusb_error_name(r)); rig_debug(RIG_DEBUG_WARN,
"Warning: cannot query manufacturer for USB device: %s\n",
libusb_error_name(r));
libusb_close(udh); libusb_close(udh);
continue; continue;
} }
@ -119,7 +137,10 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
rig_debug(RIG_DEBUG_VERBOSE, " vendor >%s<", string); rig_debug(RIG_DEBUG_VERBOSE, " vendor >%s<", string);
if (strcmp(string, port->parm.usb.vendor_name) != 0) { if (strcmp(string, port->parm.usb.vendor_name) != 0) {
rig_debug(RIG_DEBUG_WARN, "%s: Warning: Vendor name string mismatch!\n", __func__); rig_debug(RIG_DEBUG_WARN,
"%s: Warning: Vendor name string mismatch!\n",
__func__);
libusb_close(udh); libusb_close(udh);
continue; continue;
} }
@ -128,10 +149,16 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
if (port->parm.usb.product) { if (port->parm.usb.product) {
string[0] = '\0'; string[0] = '\0';
r = libusb_get_string_descriptor_ascii(udh, desc.iProduct, (unsigned char *)string, sizeof(string)); r = libusb_get_string_descriptor_ascii(udh,
desc.iProduct,
(unsigned char *)string,
sizeof(string));
if (r < 0) { if (r < 0) {
rig_debug(RIG_DEBUG_WARN, "Warning: cannot query product for USB device: %s\n", libusb_error_name(r)); rig_debug(RIG_DEBUG_WARN,
"Warning: cannot query product for USB device: %s\n",
libusb_error_name(r));
libusb_close(udh); libusb_close(udh);
continue; continue;
} }
@ -139,14 +166,21 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
rig_debug(RIG_DEBUG_VERBOSE, " product >%s<", string); rig_debug(RIG_DEBUG_VERBOSE, " product >%s<", string);
if (strcmp(string, port->parm.usb.product) != 0) { if (strcmp(string, port->parm.usb.product) != 0) {
/* Now testing with strncasecmp() for case insensitive /* Now testing with strncasecmp() for case insensitive
* match. Updating firmware on FUNcube Dongle to v18f resulted * match. Updating firmware on FUNcube Dongle to v18f resulted
* in product string changing from "FunCube Dongle" to * in product string changing from "FunCube Dongle" to
* "FUNcube Dongle". As new dongles are shipped with * "FUNcube Dongle". As new dongles are shipped with
* older firmware, both product strings are valid. Sigh... * older firmware, both product strings are valid. Sigh...
*/ */
if (strncasecmp(string, port->parm.usb.product, sizeof(port->parm.usb.product - 1)) != 0) { if (strncasecmp(string,
rig_debug(RIG_DEBUG_WARN, "%s: Warning: Product string mismatch!\n", __func__); port->parm.usb.product,
sizeof(port->parm.usb.product - 1)) != 0) {
rig_debug(RIG_DEBUG_WARN,
"%s: Warning: Product string mismatch!\n",
__func__);
libusb_close(udh); libusb_close(udh);
continue; continue;
} }
@ -156,6 +190,7 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
libusb_free_device_list(devs, 1); libusb_free_device_list(devs, 1);
rig_debug(RIG_DEBUG_VERBOSE, " -> found\n"); rig_debug(RIG_DEBUG_VERBOSE, " -> found\n");
return udh; return udh;
} }
} }
@ -163,6 +198,7 @@ static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
libusb_free_device_list(devs, 1); libusb_free_device_list(devs, 1);
rig_debug(RIG_DEBUG_VERBOSE, " -> not found\n"); rig_debug(RIG_DEBUG_VERBOSE, " -> not found\n");
return NULL; /* not found */ return NULL; /* not found */
} }
@ -179,12 +215,17 @@ int usb_port_open(hamlib_port_t *port)
char *p, *q; char *p, *q;
int r; int r;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* init defaut libusb-1.0 library contexte, if needed */ /* init defaut libusb-1.0 library contexte, if needed */
r = libusb_init(NULL); r = libusb_init(NULL);
if (r < 0) { if (r < 0) {
rig_debug(RIG_DEBUG_ERR, "%s: libusb_init failed: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, libusb_error_name(r)); "%s: libusb_init failed: %s\n",
__func__,
libusb_error_name(r));
return -RIG_EIO; return -RIG_EIO;
} }
@ -243,38 +284,57 @@ int usb_port_open(hamlib_port_t *port)
#ifdef _WIN32 #ifdef _WIN32
/* Is it still needed with libusb-1.0 ? */ /* Is it still needed with libusb-1.0 ? */
if (port->parm.usb.conf >= 0 && if (port->parm.usb.conf >= 0
(r = libusb_set_configuration(udh, port->parm.usb.conf)) < 0) { && (r = libusb_set_configuration(udh, port->parm.usb.conf)) < 0) {
rig_debug(RIG_DEBUG_ERR, "%s: libusb_set_configuration: failed conf %d: %s\n",
__func__, port->parm.usb.conf, libusb_error_name(r)); rig_debug(RIG_DEBUG_ERR,
"%s: libusb_set_configuration: failed conf %d: %s\n",
__func__,
port->parm.usb.conf,
libusb_error_name(r));
libusb_close(udh); libusb_close(udh);
libusb_exit(NULL); libusb_exit(NULL);
return -RIG_EIO; return -RIG_EIO;
} }
#endif #endif
rig_debug(RIG_DEBUG_VERBOSE, "%s: claiming %d\n", __func__, port->parm.usb.iface); rig_debug(RIG_DEBUG_VERBOSE,
"%s: claiming %d\n",
__func__,
port->parm.usb.iface);
r = libusb_claim_interface(udh, port->parm.usb.iface); r = libusb_claim_interface(udh, port->parm.usb.iface);
if (r < 0) { if (r < 0) {
rig_debug(RIG_DEBUG_ERR, "%s:libusb_claim_interface: failed interface %d: %s\n", rig_debug(RIG_DEBUG_ERR,
__func__, port->parm.usb.iface, libusb_error_name(r)); "%s:libusb_claim_interface: failed interface %d: %s\n",
__func__,
port->parm.usb.iface,
libusb_error_name(r));
libusb_close(udh); libusb_close(udh);
libusb_exit(NULL); libusb_exit(NULL);
return -RIG_EIO; return -RIG_EIO;
} }
#if 0 #if 0
r = libusb_set_interface_alt_setting(udh, port->parm.usb.iface, port->parm.usb.alt); r = libusb_set_interface_alt_setting(udh, port->parm.usb.iface,
port->parm.usb.alt);
if (r < 0) { if (r < 0) {
fprintf(stderr, "%s:usb_set_alt_interface: failed: %s\n", __func__, fprintf(stderr,
"%s:usb_set_alt_interface: failed: %s\n",
__func__,
libusb_error_name(r)); libusb_error_name(r));
libusb_release_interface(udh, port->parm.usb.iface); libusb_release_interface(udh, port->parm.usb.iface);
libusb_close(udh); libusb_close(udh);
libusb_exit(NULL); libusb_exit(NULL);
return -RIG_EIO; return -RIG_EIO;
} }
@ -287,6 +347,7 @@ int usb_port_open(hamlib_port_t *port)
return RIG_OK; return RIG_OK;
} }
/** /**
* \brief Close hamlib_port of USB device * \brief Close hamlib_port of USB device
* \param port * \param port
@ -294,6 +355,8 @@ int usb_port_open(hamlib_port_t *port)
*/ */
int usb_port_close(hamlib_port_t *port) int usb_port_close(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
libusb_device_handle *udh = port->handle; libusb_device_handle *udh = port->handle;
libusb_release_interface(udh, port->parm.usb.iface); libusb_release_interface(udh, port->parm.usb.iface);
@ -309,11 +372,16 @@ int usb_port_close(hamlib_port_t *port)
int usb_port_open(hamlib_port_t *port) int usb_port_open(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
int usb_port_close(hamlib_port_t *port) int usb_port_close(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }