kopia lustrzana https://github.com/Hamlib/Hamlib
Formatted src/ to final coding guidelines
rodzic
ef3620defb
commit
ab3e6bb5a5
23
src/cal.c
23
src/cal.c
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -67,25 +67,32 @@ float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (cal->size == 0) {
|
||||
if (cal->size == 0)
|
||||
{
|
||||
return rawval;
|
||||
}
|
||||
|
||||
for (i = 0; i < cal->size; i++)
|
||||
if (rawval < cal->table[i].raw) {
|
||||
{
|
||||
if (rawval < cal->table[i].raw)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
if (i == 0)
|
||||
{
|
||||
return cal->table[0].val;
|
||||
}
|
||||
|
||||
if (i >= cal->size) {
|
||||
if (i >= cal->size)
|
||||
{
|
||||
return cal->table[i - 1].val;
|
||||
}
|
||||
|
||||
/* catch divide by 0 error */
|
||||
if (cal->table[i].raw == cal->table[i - 1].raw) {
|
||||
if (cal->table[i].raw == cal->table[i - 1].raw)
|
||||
{
|
||||
return cal->table[i].val;
|
||||
}
|
||||
|
||||
|
@ -93,13 +100,13 @@ float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal)
|
|||
/* cheap, less accurate, but no fp needed */
|
||||
interpolation = ((cal->table[i].raw - rawval)
|
||||
* (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;
|
||||
#else
|
||||
interpolation = ((cal->table[i].raw - rawval)
|
||||
* (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
|
||||
return cal->table[i].val - interpolation;
|
||||
}
|
||||
|
|
66
src/cm108.c
66
src/cm108.c
|
@ -30,7 +30,7 @@
|
|||
* \file cm108.c
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -42,27 +42,30 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#include "par_nt.h"
|
||||
# include <windows.h>
|
||||
# include "par_nt.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINIOCTL_H
|
||||
#include <winioctl.h>
|
||||
# include <winioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINBASE_H
|
||||
#include <winbase.h>
|
||||
# include <winbase.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUX_HIDRAW_H
|
||||
#include <linux/hidraw.h>
|
||||
# include <linux/hidraw.h>
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -80,13 +83,15 @@ int cm108_open(hamlib_port_t *port)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!port->pathname[0]) {
|
||||
if (!port->pathname[0])
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
fd = open(port->pathname, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
if (fd < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: opening device \"%s\": %s\n",
|
||||
__func__,
|
||||
|
@ -100,7 +105,7 @@ int cm108_open(hamlib_port_t *port)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: checking for cm108 (or compatible) device\n",
|
||||
__func__);
|
||||
__func__);
|
||||
|
||||
struct hidraw_devinfo hiddevinfo;
|
||||
|
||||
|
@ -116,14 +121,16 @@ int cm108_open(hamlib_port_t *port)
|
|||
|| hiddevinfo.product == 0x1607
|
||||
|| hiddevinfo.product == 0x160b))))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: cm108 compatible device detected\n",
|
||||
__func__);
|
||||
} else {
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: cm108 compatible device detected\n",
|
||||
__func__);
|
||||
}
|
||||
else
|
||||
{
|
||||
close(fd);
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: no cm108 (or compatible) device detected\n",
|
||||
__func__);
|
||||
__func__);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -163,8 +170,10 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
|
|||
// pins are accessible. The SSS1623 chips have a different pinout, so
|
||||
// we make the GPIO bit number configurable.
|
||||
|
||||
switch (p->type.ptt) {
|
||||
case RIG_PTT_CM108: {
|
||||
switch (p->type.ptt)
|
||||
{
|
||||
case RIG_PTT_CM108:
|
||||
{
|
||||
|
||||
// Build a packet for CM108 HID to turn GPIO bit on or off.
|
||||
// Packet is 4 bytes, preceded by a 'report number' byte
|
||||
|
@ -181,7 +190,8 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
|
|||
p->parm.cm108.ptt_bitnum,
|
||||
(pttx == RIG_PTT_ON) ? 1 : 0);
|
||||
|
||||
char out_rep[] = {
|
||||
char out_rep[] =
|
||||
{
|
||||
0x00, // report number
|
||||
// HID output report
|
||||
0x00,
|
||||
|
@ -192,14 +202,16 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
|
|||
|
||||
ssize_t nw;
|
||||
|
||||
if (p->fd == -1) {
|
||||
if (p->fd == -1)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
// Send the HID packet
|
||||
nw = write(p->fd, out_rep, sizeof(out_rep));
|
||||
|
||||
if (nw < 0) {
|
||||
if (nw < 0)
|
||||
{
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
|
@ -228,8 +240,10 @@ int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
switch (p->type.ptt) {
|
||||
case RIG_PTT_CM108: {
|
||||
switch (p->type.ptt)
|
||||
{
|
||||
case RIG_PTT_CM108:
|
||||
{
|
||||
int status;
|
||||
return -RIG_ENIMPL;
|
||||
return status;
|
||||
|
@ -261,8 +275,10 @@ int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
|
|||
// in HID messages from the CM108 device, but I am not sure how
|
||||
// to query this state on demand.
|
||||
|
||||
switch (p->type.dcd) {
|
||||
case RIG_DCD_CM108: {
|
||||
switch (p->type.dcd)
|
||||
{
|
||||
case RIG_DCD_CM108:
|
||||
{
|
||||
int status;
|
||||
return -RIG_ENIMPL;
|
||||
return status;
|
||||
|
|
314
src/conf.c
314
src/conf.c
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -47,7 +47,8 @@
|
|||
/*
|
||||
* 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",
|
||||
"Path name to the device file of the rig",
|
||||
|
@ -117,7 +118,8 @@ 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",
|
||||
"Serial port baud rate",
|
||||
|
@ -172,13 +174,15 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
caps = rig->caps;
|
||||
rs = &rig->state;
|
||||
|
||||
switch (token) {
|
||||
switch (token)
|
||||
{
|
||||
case TOK_PATHNAME:
|
||||
strncpy(rs->rigport.pathname, val, FILPATHLEN - 1);
|
||||
break;
|
||||
|
||||
case TOK_WRITE_DELAY:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -186,7 +190,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -194,7 +199,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_TIMEOUT:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -202,7 +208,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_RETRY:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -210,11 +217,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_SERIAL_SPEED:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -222,11 +231,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_DATA_BITS:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -234,11 +245,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_STOP_BITS:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -246,83 +259,121 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_PARITY:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(val, "None")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Even")) {
|
||||
}
|
||||
else if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Space")) {
|
||||
}
|
||||
else if (!strcmp(val, "Space"))
|
||||
{
|
||||
rs->rigport.parm.serial.parity = RIG_PARITY_SPACE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TOK_HANDSHAKE:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(val, "None")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Hardware")) {
|
||||
}
|
||||
else if (!strcmp(val, "Hardware"))
|
||||
{
|
||||
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TOK_RTS_STATE:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(val, "Unset")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "OFF")) {
|
||||
}
|
||||
else if (!strcmp(val, "OFF"))
|
||||
{
|
||||
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TOK_DTR_STATE:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(val, "Unset")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "OFF")) {
|
||||
}
|
||||
else if (!strcmp(val, "OFF"))
|
||||
{
|
||||
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TOK_ITU_REGION:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
switch (val_i) {
|
||||
switch (val_i)
|
||||
{
|
||||
case RIG_ITU_REGION1:
|
||||
rs->itu_region = val_i;
|
||||
memcpy(rs->tx_range_list, caps->tx_range_list1,
|
||||
|
@ -347,21 +398,36 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_PTT_TYPE:
|
||||
if (!strcmp(val, "RIG")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "DTR")) {
|
||||
}
|
||||
else if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Parallel")) {
|
||||
}
|
||||
else if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "None")) {
|
||||
}
|
||||
else if (!strcmp(val, "None"))
|
||||
{
|
||||
rs->pttport.type.ptt = RIG_PTT_NONE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -372,7 +438,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_PTT_BITNUM:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;//value format error
|
||||
}
|
||||
|
||||
|
@ -380,21 +447,36 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_DCD_TYPE:
|
||||
if (!strcmp(val, "RIG")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "CTS")) {
|
||||
}
|
||||
else if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Parallel")) {
|
||||
}
|
||||
else if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "None")) {
|
||||
}
|
||||
else if (!strcmp(val, "None"))
|
||||
{
|
||||
rs->dcdport.type.dcd = RIG_DCD_NONE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -433,7 +515,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
|
||||
rs = &rig->state;
|
||||
|
||||
switch (token) {
|
||||
switch (token)
|
||||
{
|
||||
case TOK_PATHNAME:
|
||||
strcpy(val, rs->rigport.pathname);
|
||||
break;
|
||||
|
@ -460,7 +543,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_SERIAL_SPEED:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -468,7 +552,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_DATA_BITS:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -476,7 +561,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_STOP_BITS:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -484,11 +570,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_PARITY:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
switch (rs->rigport.parm.serial.parity) {
|
||||
switch (rs->rigport.parm.serial.parity)
|
||||
{
|
||||
case RIG_PARITY_NONE:
|
||||
s = "None";
|
||||
break;
|
||||
|
@ -517,11 +605,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_HANDSHAKE:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
switch (rs->rigport.parm.serial.handshake) {
|
||||
switch (rs->rigport.parm.serial.handshake)
|
||||
{
|
||||
case RIG_HANDSHAKE_NONE:
|
||||
s = "None";
|
||||
break;
|
||||
|
@ -542,11 +632,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_RTS_STATE:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
switch (rs->rigport.parm.serial.rts_state) {
|
||||
switch (rs->rigport.parm.serial.rts_state)
|
||||
{
|
||||
case RIG_SIGNAL_UNSET:
|
||||
s = "Unset";
|
||||
break;
|
||||
|
@ -567,11 +659,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_DTR_STATE:
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rigport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
switch (rs->rigport.parm.serial.dtr_state) {
|
||||
switch (rs->rigport.parm.serial.dtr_state)
|
||||
{
|
||||
case RIG_SIGNAL_UNSET:
|
||||
s = "Unset";
|
||||
break;
|
||||
|
@ -600,7 +694,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_PTT_TYPE:
|
||||
switch (rs->pttport.type.ptt) {
|
||||
switch (rs->pttport.type.ptt)
|
||||
{
|
||||
case RIG_PTT_RIG:
|
||||
s = "RIG";
|
||||
break;
|
||||
|
@ -645,7 +740,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_DCD_TYPE:
|
||||
switch (rs->dcdport.type.dcd) {
|
||||
switch (rs->dcdport.type.dcd)
|
||||
{
|
||||
case RIG_DCD_RIG:
|
||||
s = "RIG";
|
||||
break;
|
||||
|
@ -697,9 +793,9 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
* \brief call a function against each configuration token of a rig
|
||||
* \param rig The rig handle
|
||||
* \param cfunc The function to perform on each token
|
||||
* \param data Any data to be passed to cfunc
|
||||
* \param data Any data to be passed to cfunc()
|
||||
*
|
||||
* Executes \a cfunc on all the elements stored in the conf table.
|
||||
* Executes \a cfunc() on all the elements stored in the conf table.
|
||||
* rig_token_foreach starts first with backend conf table, then finish
|
||||
* with frontend table.
|
||||
*
|
||||
|
@ -708,33 +804,45 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
* set appropriately).
|
||||
*/
|
||||
int HAMLIB_API rig_token_foreach(RIG *rig,
|
||||
int (*cfunc)(const struct confparams *, rig_ptr_t),
|
||||
int (*cfunc)(const struct confparams *,
|
||||
rig_ptr_t),
|
||||
rig_ptr_t data)
|
||||
{
|
||||
const struct confparams *cfp;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps || !cfunc) {
|
||||
if (!rig || !rig->caps || !cfunc)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (rig->caps->port_type == RIG_PORT_SERIAL)
|
||||
{
|
||||
for (cfp = frontend_serial_cfg_params; cfp->name; cfp++)
|
||||
if ((*cfunc)(cfp, data) == 0) {
|
||||
{
|
||||
if ((*cfunc)(cfp, data) == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++)
|
||||
if ((*cfunc)(cfp, data) == 0) {
|
||||
{
|
||||
if ((*cfunc)(cfp, data) == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -749,15 +857,16 @@ int HAMLIB_API rig_token_foreach(RIG *rig,
|
|||
*
|
||||
* \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;
|
||||
token_t token;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -765,20 +874,30 @@ const struct confparams *HAMLIB_API rig_confparam_lookup(RIG *rig,
|
|||
token = strtol(name, NULL, 0);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
if (!strcmp(cfp->name, name) || token == cfp->token) {
|
||||
{
|
||||
if (!strcmp(cfp->name, name) || token == cfp->token)
|
||||
{
|
||||
return cfp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -802,7 +921,8 @@ token_t HAMLIB_API rig_token_lookup(RIG *rig, const char *name)
|
|||
|
||||
cfp = rig_confparam_lookup(rig, name);
|
||||
|
||||
if (!cfp) {
|
||||
if (!cfp)
|
||||
{
|
||||
return RIG_CONF_END;
|
||||
}
|
||||
|
||||
|
@ -828,28 +948,33 @@ int HAMLIB_API rig_set_conf(RIG *rig, token_t token, const char *val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig_need_debug(RIG_DEBUG_VERBOSE)) {
|
||||
if (rig_need_debug(RIG_DEBUG_VERBOSE))
|
||||
{
|
||||
const struct confparams *cfp;
|
||||
char tokenstr[12];
|
||||
sprintf(tokenstr, "%ld", token);
|
||||
cfp = rig_confparam_lookup(rig, tokenstr);
|
||||
|
||||
if (!cfp) {
|
||||
if (!cfp)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (rig->caps->set_conf == NULL) {
|
||||
if (rig->caps->set_conf == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -876,15 +1001,18 @@ int HAMLIB_API rig_get_conf(RIG *rig, token_t token, char *val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps || !val) {
|
||||
if (!rig || !rig->caps || !val)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (IS_TOKEN_FRONTEND(token)) {
|
||||
if (IS_TOKEN_FRONTEND(token))
|
||||
{
|
||||
return frontend_get_conf(rig, token, val);
|
||||
}
|
||||
|
||||
if (rig->caps->get_conf == NULL) {
|
||||
if (rig->caps->get_conf == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
|
32
src/debug.c
32
src/debug.c
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -44,7 +44,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
# include <android/log.h>
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -74,14 +74,17 @@ void dump_hex(const unsigned char ptr[], size_t size)
|
|||
unsigned char c;
|
||||
int i;
|
||||
|
||||
if (!rig_need_debug(RIG_DEBUG_TRACE)) {
|
||||
if (!rig_need_debug(RIG_DEBUG_TRACE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
|
||||
for (i = 0; i < size; ++i) {
|
||||
if (i % DUMP_HEX_WIDTH == 0) {
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
if (i % DUMP_HEX_WIDTH == 0)
|
||||
{
|
||||
/* new line */
|
||||
sprintf(line + 0, "%04x", i);
|
||||
memset(line + 4, ' ', sizeof(line) - 4 - 1);
|
||||
|
@ -98,7 +101,8 @@ void dump_hex(const unsigned char ptr[], size_t size)
|
|||
&& c < 0x7f) ? c : '.';
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
@ -135,17 +139,22 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level,
|
|||
{
|
||||
va_list ap;
|
||||
|
||||
if (!rig_need_debug(debug_level)) {
|
||||
if (!rig_need_debug(debug_level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
if (rig_vprintf_cb) {
|
||||
if (rig_vprintf_cb)
|
||||
{
|
||||
rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap);
|
||||
} else {
|
||||
if (!rig_debug_stream) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!rig_debug_stream)
|
||||
{
|
||||
rig_debug_stream = stderr;
|
||||
}
|
||||
|
||||
|
@ -158,7 +167,8 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level,
|
|||
int a;
|
||||
va_start(ap, fmt);
|
||||
|
||||
switch (debug_level) {
|
||||
switch (debug_level)
|
||||
{
|
||||
// case RIG_DEBUG_NONE:
|
||||
case RIG_DEBUG_BUG:
|
||||
a = ANDROID_LOG_FATAL;
|
||||
|
|
169
src/event.c
169
src/event.c
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -40,13 +40,17 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
@ -56,8 +60,8 @@
|
|||
#include "event.h"
|
||||
|
||||
#if defined(WIN32) && !defined(HAVE_TERMIOS_H)
|
||||
#include "win32termios.h"
|
||||
#define select win32_serial_select
|
||||
# include "win32termios.h"
|
||||
# define select win32_serial_select
|
||||
#endif
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
|
@ -114,7 +118,8 @@ int add_trn_rig(RIG *rig)
|
|||
|
||||
status = sigaction(SIGIO, &act, &hamlib_trn_oldact);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: sigaction failed: %s\n",
|
||||
__func__,
|
||||
|
@ -123,7 +128,8 @@ int add_trn_rig(RIG *rig)
|
|||
|
||||
status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid());
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: fcntl SETOWN failed: %s\n",
|
||||
__func__,
|
||||
|
@ -134,7 +140,8 @@ int add_trn_rig(RIG *rig)
|
|||
#ifdef F_SETSIG
|
||||
status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: fcntl SETSIG failed: %s\n",
|
||||
__func__,
|
||||
|
@ -145,7 +152,8 @@ int add_trn_rig(RIG *rig)
|
|||
|
||||
status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: fcntl SETASYNC failed: %s\n",
|
||||
__func__,
|
||||
|
@ -179,7 +187,8 @@ int remove_trn_rig(RIG *rig)
|
|||
#if defined(HAVE_SIGINFO_T) && defined(O_ASYNC)
|
||||
status = fcntl(rig->state.rigport.fd, F_SETFL, 0);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: fcntl SETASYNC failed: %s\n",
|
||||
__func__,
|
||||
|
@ -190,7 +199,8 @@ int remove_trn_rig(RIG *rig)
|
|||
|
||||
status = sigaction(SIGIO, &hamlib_trn_oldact, NULL);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: sigaction failed: %s\n",
|
||||
__func__,
|
||||
|
@ -233,7 +243,8 @@ static int add_trn_poll_rig(RIG *rig)
|
|||
|
||||
status = sigaction(SIGALRM, &act, &hamlib_trn_poll_oldact);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s sigaction failed: %s\n",
|
||||
__func__,
|
||||
|
@ -259,7 +270,8 @@ static int remove_trn_poll_rig(RIG *rig)
|
|||
|
||||
status = sigaction(SIGALRM, &hamlib_trn_poll_oldact, NULL);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s sigaction failed: %s\n",
|
||||
__func__,
|
||||
|
@ -291,15 +303,17 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
|
|||
* so far, only file oriented ports have event reporting support
|
||||
*/
|
||||
if (rig->state.rigport.type.rig != RIG_PORT_SERIAL
|
||||
|| rig->state.rigport.fd == -1) {
|
||||
return -1;
|
||||
|| rig->state.rigport.fd == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* FIXME: siginfo is not portable, however use it where available */
|
||||
#if 0&&defined(HAVE_SIGINFO_T)
|
||||
siginfo_t *si = (siginfo_t *)data;
|
||||
|
||||
if (rig->state.rigport.fd != si->si_fd) {
|
||||
if (rig->state.rigport.fd != si->si_fd)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -316,7 +330,8 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
|
|||
*/
|
||||
retval = select(rig->state.rigport.fd + 1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
if (retval < 0) {
|
||||
if (retval < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: select: %s\n",
|
||||
__func__,
|
||||
|
@ -329,11 +344,13 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
|
|||
/*
|
||||
* Do not disturb, the backend is currently receiving data
|
||||
*/
|
||||
if (rig->state.hold_decode) {
|
||||
if (rig->state.hold_decode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rig->caps->decode_event) {
|
||||
if (rig->caps->decode_event)
|
||||
{
|
||||
rig->caps->decode_event(rig);
|
||||
}
|
||||
|
||||
|
@ -352,26 +369,31 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
|
|||
struct rig_state *rs = &rig->state;
|
||||
int retval;
|
||||
|
||||
if (rig->state.transceive != RIG_TRN_POLL) {
|
||||
if (rig->state.transceive != RIG_TRN_POLL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not disturb, the backend is currently receiving data
|
||||
*/
|
||||
if (rig->state.hold_decode) {
|
||||
if (rig->state.hold_decode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
rig->state.hold_decode = 2;
|
||||
|
||||
if (rig->caps->get_vfo && rig->callbacks.vfo_event) {
|
||||
if (rig->caps->get_vfo && rig->callbacks.vfo_event)
|
||||
{
|
||||
vfo_t vfo = RIG_VFO_CURR;
|
||||
|
||||
retval = rig->caps->get_vfo(rig, &vfo);
|
||||
|
||||
if (retval == RIG_OK) {
|
||||
if (vfo != rs->current_vfo) {
|
||||
if (retval == RIG_OK)
|
||||
{
|
||||
if (vfo != rs->current_vfo)
|
||||
{
|
||||
rig->callbacks.vfo_event(rig, vfo, rig->callbacks.vfo_arg);
|
||||
}
|
||||
|
||||
|
@ -379,31 +401,42 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
|
|||
}
|
||||
}
|
||||
|
||||
if (rig->caps->get_freq && rig->callbacks.freq_event) {
|
||||
if (rig->caps->get_freq && rig->callbacks.freq_event)
|
||||
{
|
||||
freq_t freq;
|
||||
|
||||
retval = rig->caps->get_freq(rig, RIG_VFO_CURR, &freq);
|
||||
|
||||
if (retval == RIG_OK) {
|
||||
if (freq != rs->current_freq) {
|
||||
rig->callbacks.freq_event(rig, RIG_VFO_CURR,
|
||||
freq, rig->callbacks.freq_arg);
|
||||
if (retval == RIG_OK)
|
||||
{
|
||||
if (freq != rs->current_freq)
|
||||
{
|
||||
rig->callbacks.freq_event(rig,
|
||||
RIG_VFO_CURR,
|
||||
freq,
|
||||
rig->callbacks.freq_arg);
|
||||
}
|
||||
|
||||
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;
|
||||
pbwidth_t width;
|
||||
|
||||
retval = rig->caps->get_mode(rig, RIG_VFO_CURR, &rmode, &width);
|
||||
|
||||
if (retval == RIG_OK) {
|
||||
if (rmode != rs->current_mode || width != rs->current_width) {
|
||||
rig->callbacks.mode_event(rig, RIG_VFO_CURR,
|
||||
rmode, width, rig->callbacks.mode_arg);
|
||||
if (retval == RIG_OK)
|
||||
{
|
||||
if (rmode != rs->current_mode || width != rs->current_width)
|
||||
{
|
||||
rig->callbacks.mode_event(rig,
|
||||
RIG_VFO_CURR,
|
||||
rmode,
|
||||
width,
|
||||
rig->callbacks.mode_arg);
|
||||
}
|
||||
|
||||
rs->current_mode = rmode;
|
||||
|
@ -493,7 +526,8 @@ int HAMLIB_API rig_set_freq_callback(RIG *rig, freq_cb_t cb, rig_ptr_t arg)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -522,7 +556,8 @@ int HAMLIB_API rig_set_mode_callback(RIG *rig, mode_cb_t cb, rig_ptr_t arg)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -551,7 +586,8 @@ int HAMLIB_API rig_set_vfo_callback(RIG *rig, vfo_cb_t cb, rig_ptr_t arg)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -580,7 +616,8 @@ int HAMLIB_API rig_set_ptt_callback(RIG *rig, ptt_cb_t cb, rig_ptr_t arg)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -609,7 +646,8 @@ int HAMLIB_API rig_set_dcd_callback(RIG *rig, dcd_cb_t cb, rig_ptr_t arg)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -640,7 +678,8 @@ int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -674,29 +713,37 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
/* detect whether tranceive is active already */
|
||||
if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF) {
|
||||
if (trn == rig->state.transceive) {
|
||||
if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF)
|
||||
{
|
||||
if (trn == rig->state.transceive)
|
||||
{
|
||||
return RIG_OK;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* when going POLL<->RIG, transtition to OFF */
|
||||
retcode = rig_set_trn(rig, RIG_TRN_OFF);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (trn) {
|
||||
switch (trn)
|
||||
{
|
||||
case RIG_TRN_RIG:
|
||||
if (caps->transceive != RIG_TRN_RIG) {
|
||||
if (caps->transceive != RIG_TRN_RIG)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -704,7 +751,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
|
||||
/* some protocols (e.g. CI-V's) offer no way
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
@ -722,7 +770,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
value.it_interval.tv_usec = rig->state.poll_interval * 1000;
|
||||
retcode = setitimer(ITIMER_REAL, &value, NULL);
|
||||
|
||||
if (retcode == -1) {
|
||||
if (retcode == -1)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: setitimer: %s\n",
|
||||
__func__,
|
||||
|
@ -737,7 +786,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
break;
|
||||
|
||||
case RIG_TRN_OFF:
|
||||
if (rig->state.transceive == RIG_TRN_POLL) {
|
||||
if (rig->state.transceive == RIG_TRN_POLL)
|
||||
{
|
||||
#ifdef HAVE_SETITIMER
|
||||
|
||||
retcode = remove_trn_poll_rig(rig);
|
||||
|
@ -749,7 +799,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
|
||||
retcode = setitimer(ITIMER_REAL, &value, NULL);
|
||||
|
||||
if (retcode == -1) {
|
||||
if (retcode == -1)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
|
||||
__func__,
|
||||
strerror(errno));
|
||||
|
@ -759,10 +810,13 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
#else
|
||||
return -RIG_ENAVAIL;
|
||||
#endif
|
||||
} else if (rig->state.transceive == RIG_TRN_RIG) {
|
||||
}
|
||||
else if (rig->state.transceive == RIG_TRN_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);
|
||||
}
|
||||
}
|
||||
|
@ -773,7 +827,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
|||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (retcode == RIG_OK) {
|
||||
if (retcode == RIG_OK)
|
||||
{
|
||||
rig->state.transceive = trn;
|
||||
}
|
||||
|
||||
|
@ -799,11 +854,13 @@ int HAMLIB_API rig_get_trn(RIG *rig, int *trn)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !trn) {
|
||||
if (CHECK_RIG_ARG(rig) || !trn)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig->caps->get_trn != NULL) {
|
||||
if (rig->caps->get_trn != NULL)
|
||||
{
|
||||
return rig->caps->get_trn(rig, trn);
|
||||
}
|
||||
|
||||
|
|
81
src/ext.c
81
src/ext.c
|
@ -28,14 +28,14 @@
|
|||
* \file ext.c
|
||||
* \brief Extension request parameter interface
|
||||
*
|
||||
* An open-ended set of extension parameters and levels are available for each rig,
|
||||
* as provided in the rigcaps extparms and extlevels lists. These provide a way
|
||||
* to work with rig-specific functions that don't fit into the basic "virtual rig" of
|
||||
* Hamlib. See icom/ic746.c for an example.
|
||||
* An open-ended set of extension parameters and levels are available for each
|
||||
* rig, as provided in the rigcaps extparms and extlevels lists. These
|
||||
* provide a way to work with rig-specific functions that don't fit into the
|
||||
* basic "virtual rig" of Hamlib. See icom/ic746.c for an example.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -54,9 +54,11 @@
|
|||
* \param cfunc callback function of each extlevel
|
||||
* \param data cookie to be passed to \a cfunc callback
|
||||
* \brief Executes cfunc on all the elements stored in the extlevels table
|
||||
* The callback \a cfunc is called until it returns a value which is not strictly positive.
|
||||
* 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.
|
||||
*
|
||||
* The callback \a cfunc is called until it returns a value which is not
|
||||
* strictly positive. 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.
|
||||
*/
|
||||
int HAMLIB_API rig_ext_level_foreach(RIG *rig,
|
||||
int (*cfunc)(RIG *,
|
||||
|
@ -69,18 +71,22 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig,
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps || !cfunc) {
|
||||
if (!rig || !rig->caps || !cfunc)
|
||||
{
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
if (ret == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -94,9 +100,11 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig,
|
|||
* \param cfunc callback function of each extparm
|
||||
* \param data cookie to be passed to \a cfunc callback
|
||||
* \brief Executes cfunc on all the elements stored in the extparms table
|
||||
* The callback \a cfunc is called until it returns a value which is not strictly positive.
|
||||
* 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.
|
||||
*
|
||||
* The callback \a cfunc is called until it returns a value which is not
|
||||
* strictly positive. 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.
|
||||
*/
|
||||
int HAMLIB_API rig_ext_parm_foreach(RIG *rig,
|
||||
int (*cfunc)(RIG *,
|
||||
|
@ -109,18 +117,22 @@ int HAMLIB_API rig_ext_parm_foreach(RIG *rig,
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps || !cfunc) {
|
||||
if (!rig || !rig->caps || !cfunc)
|
||||
{
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
if (ret == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -140,25 +152,32 @@ int HAMLIB_API rig_ext_parm_foreach(RIG *rig,
|
|||
*
|
||||
* TODO: should use Lex to speed it up, strcmp hurts!
|
||||
*/
|
||||
const struct confparams * HAMLIB_API rig_ext_lookup(RIG *rig, const char *name)
|
||||
const struct confparams *HAMLIB_API rig_ext_lookup(RIG *rig, const char *name)
|
||||
{
|
||||
const struct confparams *cfp;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
|
||||
if (!strcmp(cfp->name, name)) {
|
||||
{
|
||||
if (!strcmp(cfp->name, name))
|
||||
{
|
||||
return cfp;
|
||||
}
|
||||
}
|
||||
|
||||
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
|
||||
if (!strcmp(cfp->name, name)) {
|
||||
{
|
||||
if (!strcmp(cfp->name, name))
|
||||
{
|
||||
return cfp;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -179,19 +198,26 @@ const struct confparams * HAMLIB_API rig_ext_lookup_tok(RIG *rig, token_t token)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++)
|
||||
if (cfp->token == token) {
|
||||
{
|
||||
if (cfp->token == token)
|
||||
{
|
||||
return cfp;
|
||||
}
|
||||
}
|
||||
|
||||
for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++)
|
||||
if (cfp->token == token) {
|
||||
{
|
||||
if (cfp->token == token)
|
||||
{
|
||||
return cfp;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -210,7 +236,8 @@ token_t HAMLIB_API rig_ext_token_lookup(RIG *rig, const char *name)
|
|||
|
||||
cfp = rig_ext_lookup(rig, name);
|
||||
|
||||
if (!cfp) {
|
||||
if (!cfp)
|
||||
{
|
||||
return RIG_CONF_END;
|
||||
}
|
||||
|
||||
|
|
28
src/gpio.c
28
src/gpio.c
|
@ -40,7 +40,8 @@ int gpio_open(hamlib_port_t *port, int on_value)
|
|||
snprintf(pathname, FILPATHLEN, "/sys/class/gpio/export");
|
||||
fexp = fopen(pathname, "w");
|
||||
|
||||
if (!fexp) {
|
||||
if (!fexp)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"Export GPIO%s (using %s): %s\n",
|
||||
port->pathname,
|
||||
|
@ -58,7 +59,8 @@ int gpio_open(hamlib_port_t *port, int on_value)
|
|||
port->pathname);
|
||||
fdir = fopen(pathname, "w");
|
||||
|
||||
if (!fdir) {
|
||||
if (!fdir)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"GPIO%s direction (using %s): %s\n",
|
||||
port->pathname,
|
||||
|
@ -76,7 +78,8 @@ int gpio_open(hamlib_port_t *port, int on_value)
|
|||
port->pathname);
|
||||
fd = open(pathname, O_WRONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
if (fd < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"GPIO%s opening value file %s: %s\n",
|
||||
port->pathname,
|
||||
|
@ -102,13 +105,17 @@ int gpio_ptt_set(hamlib_port_t *port, ptt_t pttx)
|
|||
port->parm.gpio.value = pttx != RIG_PTT_OFF;
|
||||
|
||||
if ((port->parm.gpio.value && port->parm.gpio.on_value)
|
||||
|| (!port->parm.gpio.value && !port->parm.gpio.on_value)) {
|
||||
val = "1\n";
|
||||
} else {
|
||||
|| (!port->parm.gpio.value && !port->parm.gpio.on_value))
|
||||
{
|
||||
val = "1\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
val = "0\n";
|
||||
}
|
||||
|
||||
if (write(port->fd, val, strlen(val)) <= 0) {
|
||||
if (write(port->fd, val, strlen(val)) <= 0)
|
||||
{
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
|
@ -118,9 +125,12 @@ int gpio_ptt_set(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;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return RIG_PTT_OFF;
|
||||
}
|
||||
}
|
||||
|
|
223
src/iofunc.c
223
src/iofunc.c
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -68,32 +68,38 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
|
||||
p->fd = -1;
|
||||
|
||||
switch (p->type.rig) {
|
||||
switch (p->type.rig)
|
||||
{
|
||||
case RIG_PORT_SERIAL:
|
||||
status = serial_open(p);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET
|
||||
&& p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) {
|
||||
status = ser_set_rts(p,
|
||||
p->parm.serial.rts_state == RIG_SIGNAL_ON);
|
||||
want_state_delay = 1;
|
||||
&& p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE)
|
||||
{
|
||||
status = ser_set_rts(p,
|
||||
p->parm.serial.rts_state == RIG_SIGNAL_ON);
|
||||
want_state_delay = 1;
|
||||
}
|
||||
|
||||
if (status != 0) {
|
||||
if (status != 0)
|
||||
{
|
||||
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,
|
||||
p->parm.serial.dtr_state == RIG_SIGNAL_ON);
|
||||
want_state_delay = 1;
|
||||
}
|
||||
|
||||
if (status != 0) {
|
||||
if (status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -101,7 +107,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
* Wait whatever electrolytics in the circuit come up to voltage.
|
||||
* Is 100ms enough? Too much?
|
||||
*/
|
||||
if (want_state_delay) {
|
||||
if (want_state_delay)
|
||||
{
|
||||
usleep(100 * 1000);
|
||||
}
|
||||
|
||||
|
@ -110,7 +117,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
case RIG_PORT_PARALLEL:
|
||||
status = par_open(p);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -119,7 +127,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
case RIG_PORT_CM108:
|
||||
status = cm108_open(p);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -128,7 +137,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
case RIG_PORT_DEVICE:
|
||||
status = open(p->pathname, O_RDWR, 0);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
|
@ -138,7 +148,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
case RIG_PORT_USB:
|
||||
status = usb_port_open(p);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -153,7 +164,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
|
|||
/* FIXME: hardcoded network port */
|
||||
status = network_open(p, 4532);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -181,8 +193,10 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (p->fd != -1) {
|
||||
switch (port_type) {
|
||||
if (p->fd != -1)
|
||||
{
|
||||
switch (port_type)
|
||||
{
|
||||
case RIG_PORT_SERIAL:
|
||||
ret = ser_close(p);
|
||||
break;
|
||||
|
@ -221,7 +235,7 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type)
|
|||
|
||||
|
||||
#if defined(WIN32) && !defined(HAVE_TERMIOS_H)
|
||||
#include "win32termios.h"
|
||||
# include "win32termios.h"
|
||||
|
||||
extern int is_uh_radio_fd(int fd);
|
||||
|
||||
|
@ -239,27 +253,35 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
|
|||
* Note that we always have RIG_PORT_SERIAL in the
|
||||
* microHam case.
|
||||
*/
|
||||
if (is_uh_radio_fd(p->fd)) {
|
||||
if (is_uh_radio_fd(p->fd))
|
||||
{
|
||||
return read(p->fd, buf, count);
|
||||
}
|
||||
|
||||
if (p->type.rig == RIG_PORT_SERIAL) {
|
||||
if (p->type.rig == RIG_PORT_SERIAL)
|
||||
{
|
||||
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;
|
||||
|
||||
/* clear MSB */
|
||||
for (i = 0; i < ret; i++) {
|
||||
for (i = 0; i < ret; i++)
|
||||
{
|
||||
pbuf[i] &= ~0x80;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
} else if (p->type.rig == RIG_PORT_NETWORK
|
||||
|| p->type.rig == RIG_PORT_UDP_NETWORK) {
|
||||
return recv(p->fd, buf, count, 0);
|
||||
} else {
|
||||
}
|
||||
else if (p->type.rig == RIG_PORT_NETWORK
|
||||
|| p->type.rig == RIG_PORT_UDP_NETWORK)
|
||||
{
|
||||
return recv(p->fd, buf, count, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return read(p->fd, buf, count);
|
||||
}
|
||||
}
|
||||
|
@ -272,23 +294,32 @@ static ssize_t port_write(hamlib_port_t *p, const void *buf, size_t count)
|
|||
* Note that we always have RIG_PORT_SERIAL in the
|
||||
* microHam case.
|
||||
*/
|
||||
if (is_uh_radio_fd(p->fd)) {
|
||||
if (is_uh_radio_fd(p->fd))
|
||||
{
|
||||
return write(p->fd, buf, count);
|
||||
}
|
||||
|
||||
if (p->type.rig == RIG_PORT_SERIAL) {
|
||||
if (p->type.rig == RIG_PORT_SERIAL)
|
||||
{
|
||||
return win32_serial_write(p->fd, buf, count);
|
||||
} else if (p->type.rig == RIG_PORT_NETWORK
|
||||
|| p->type.rig == RIG_PORT_UDP_NETWORK) {
|
||||
return send(p->fd, buf, count, 0);
|
||||
} else {
|
||||
}
|
||||
else if (p->type.rig == RIG_PORT_NETWORK
|
||||
|| p->type.rig == RIG_PORT_UDP_NETWORK)
|
||||
{
|
||||
return send(p->fd, buf, count, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
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,
|
||||
static int port_select(hamlib_port_t *p,
|
||||
int n,
|
||||
fd_set *readfds,
|
||||
fd_set *writefds,
|
||||
fd_set *exceptfds,
|
||||
struct timeval *timeout)
|
||||
{
|
||||
#if 1
|
||||
|
@ -296,11 +327,13 @@ static int port_select(hamlib_port_t *p, int n, fd_set *readfds,
|
|||
/* select does not work very well with writefds/exceptfds
|
||||
* So let's pretend there's none of them
|
||||
*/
|
||||
if (exceptfds) {
|
||||
if (exceptfds)
|
||||
{
|
||||
FD_ZERO(exceptfds);
|
||||
}
|
||||
|
||||
if (writefds) {
|
||||
if (writefds)
|
||||
{
|
||||
FD_ZERO(writefds);
|
||||
}
|
||||
|
||||
|
@ -314,13 +347,17 @@ static int port_select(hamlib_port_t *p, int n, fd_set *readfds,
|
|||
* Note that we always have RIG_PORT_SERIAL in the
|
||||
* microHam case.
|
||||
*/
|
||||
if (is_uh_radio_fd(p->fd)) {
|
||||
if (is_uh_radio_fd(p->fd))
|
||||
{
|
||||
return select(n, readfds, writefds, exceptfds, timeout);
|
||||
}
|
||||
|
||||
if (p->type.rig == RIG_PORT_SERIAL) {
|
||||
if (p->type.rig == RIG_PORT_SERIAL)
|
||||
{
|
||||
return win32_serial_select(n, readfds, writefds, exceptfds, timeout);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return select(n, readfds, writefds, exceptfds, timeout);
|
||||
}
|
||||
}
|
||||
|
@ -335,18 +372,22 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
|
|||
int i;
|
||||
ssize_t ret;
|
||||
|
||||
if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7) {
|
||||
if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7)
|
||||
{
|
||||
unsigned char *pbuf = buf;
|
||||
|
||||
ret = read(p->fd, buf, count);
|
||||
|
||||
/* clear MSB */
|
||||
for (i = 0; i < ret; i++) {
|
||||
for (i = 0; i < ret; i++)
|
||||
{
|
||||
pbuf[i] &= ~0x80;
|
||||
}
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return read(p->fd, buf, count);
|
||||
}
|
||||
}
|
||||
|
@ -393,7 +434,8 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
|
|||
|
||||
#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 */
|
||||
struct timeval tv;
|
||||
|
||||
|
@ -403,7 +445,8 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
|
|||
((tv.tv_sec - p->post_write_date.tv_sec) * 1000000 +
|
||||
(tv.tv_usec - p->post_write_date.tv_usec));
|
||||
|
||||
if (date_delay > 0) {
|
||||
if (date_delay > 0)
|
||||
{
|
||||
/*
|
||||
* optional delay after last write
|
||||
*/
|
||||
|
@ -415,38 +458,57 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
|
|||
|
||||
#endif
|
||||
|
||||
if (p->write_delay > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
if (p->write_delay > 0)
|
||||
{
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
ret = port_write(p, txbuffer + i, 1);
|
||||
|
||||
if (ret != 1) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n",
|
||||
__func__, __LINE__, ret, strerror(errno));
|
||||
if (ret != 1)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s():%d failed %d - %s\n",
|
||||
__func__,
|
||||
__LINE__,
|
||||
ret,
|
||||
strerror(errno));
|
||||
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
usleep(p->write_delay * 1000);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = port_write(p, txbuffer, count);
|
||||
|
||||
if (ret != count) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n",
|
||||
__func__, __LINE__, ret, strerror(errno));
|
||||
if (ret != count)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s():%d failed %d - %s\n",
|
||||
__func__,
|
||||
__LINE__,
|
||||
ret,
|
||||
strerror(errno));
|
||||
|
||||
return -RIG_EIO;
|
||||
}
|
||||
}
|
||||
|
||||
if (p->post_write_delay > 0) {
|
||||
if (p->post_write_delay > 0)
|
||||
{
|
||||
#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
|
||||
#define POST_WRITE_DELAY_TRSHLD 10
|
||||
|
||||
if (p->post_write_delay > POST_WRITE_DELAY_TRSHLD) {
|
||||
if (p->post_write_delay > POST_WRITE_DELAY_TRSHLD)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
p->post_write_date.tv_sec = tv.tv_sec;
|
||||
p->post_write_date.tv_usec = tv.tv_usec;
|
||||
} else
|
||||
}
|
||||
else
|
||||
#endif
|
||||
usleep(p->post_write_delay * 1000); /* optional delay after last write */
|
||||
|
||||
|
@ -497,7 +559,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
|
|||
/* Store the time of the read loop start */
|
||||
gettimeofday(&start_time, NULL);
|
||||
|
||||
while (count > 0) {
|
||||
while (count > 0)
|
||||
{
|
||||
tv = tv_timeout; /* select may have updated it */
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
|
@ -506,7 +569,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
|
|||
|
||||
retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv);
|
||||
|
||||
if (retval == 0) {
|
||||
if (retval == 0)
|
||||
{
|
||||
/* Record timeout time and caculate elapsed time */
|
||||
gettimeofday(&end_time, NULL);
|
||||
timersub(&end_time, &start_time, &elapsed_time);
|
||||
|
@ -522,7 +586,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
|
|||
return -RIG_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (retval < 0) {
|
||||
if (retval < 0)
|
||||
{
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s(): select() error after %d chars: %s\n",
|
||||
|
@ -533,7 +598,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
|
|||
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",
|
||||
__func__,
|
||||
|
@ -548,7 +614,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t 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",
|
||||
__func__,
|
||||
|
@ -593,7 +660,9 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
|
|||
*
|
||||
* Assumes rxbuffer!=NULL
|
||||
*/
|
||||
int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
||||
int HAMLIB_API read_string(hamlib_port_t *p,
|
||||
char *rxbuffer,
|
||||
size_t rxmax,
|
||||
const char *stopset,
|
||||
int stopset_len)
|
||||
{
|
||||
|
@ -604,11 +673,13 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!p || !rxbuffer) {
|
||||
if (!p || !rxbuffer)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rxmax < 1) {
|
||||
if (rxmax < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -621,7 +692,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
/* Store the time of the read loop start */
|
||||
gettimeofday(&start_time, NULL);
|
||||
|
||||
while (total_count < rxmax - 1) {
|
||||
while (total_count < rxmax - 1)
|
||||
{
|
||||
tv = tv_timeout; /* select may have updated it */
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
|
@ -630,8 +702,10 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
|
||||
retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv);
|
||||
|
||||
if (retval == 0) {
|
||||
if (0 == total_count) {
|
||||
if (retval == 0)
|
||||
{
|
||||
if (0 == total_count)
|
||||
{
|
||||
/* Record timeout time and caculate elapsed time */
|
||||
gettimeofday(&end_time, NULL);
|
||||
timersub(&end_time, &start_time, &elapsed_time);
|
||||
|
@ -650,7 +724,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
break; /* return what we have read */
|
||||
}
|
||||
|
||||
if (retval < 0) {
|
||||
if (retval < 0)
|
||||
{
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s(): select() error after %d chars: %s\n",
|
||||
|
@ -661,7 +736,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
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",
|
||||
__func__,
|
||||
|
@ -676,7 +752,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
*/
|
||||
rd_count = port_read(p, &rxbuffer[total_count], 1);
|
||||
|
||||
if (rd_count < 0) {
|
||||
if (rd_count < 0)
|
||||
{
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s(): read() failed - %s\n",
|
||||
|
@ -688,7 +765,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
|
||||
++total_count;
|
||||
|
||||
if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len)) {
|
||||
if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -703,6 +781,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
|
|||
"%s(): RX %d characters\n",
|
||||
__func__,
|
||||
total_count);
|
||||
|
||||
dump_hex((unsigned char *) rxbuffer, total_count);
|
||||
|
||||
return total_count; /* return bytes count read */
|
||||
|
|
172
src/locator.c
172
src/locator.c
|
@ -54,7 +54,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -144,23 +144,29 @@ double HAMLIB_API dms2dec(int degrees, int minutes, double seconds, int sw)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (degrees < 0) {
|
||||
if (degrees < 0)
|
||||
{
|
||||
degrees = abs(degrees);
|
||||
}
|
||||
|
||||
if (minutes < 0) {
|
||||
if (minutes < 0)
|
||||
{
|
||||
minutes = abs(minutes);
|
||||
}
|
||||
|
||||
if (seconds < 0) {
|
||||
if (seconds < 0)
|
||||
{
|
||||
seconds = fabs(seconds);
|
||||
}
|
||||
|
||||
st = (double)degrees + (double)minutes / 60. + seconds / 3600.;
|
||||
|
||||
if (sw == 1) {
|
||||
if (sw == 1)
|
||||
{
|
||||
return -st;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return st;
|
||||
}
|
||||
}
|
||||
|
@ -193,19 +199,24 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (degrees < 0) {
|
||||
if (degrees < 0)
|
||||
{
|
||||
degrees = abs(degrees);
|
||||
}
|
||||
|
||||
if (minutes < 0) {
|
||||
if (minutes < 0)
|
||||
{
|
||||
minutes = fabs(minutes);
|
||||
}
|
||||
|
||||
st = (double)degrees + minutes / 60.;
|
||||
|
||||
if (sw == 1) {
|
||||
if (sw == 1)
|
||||
{
|
||||
return -st;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return st;
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +249,10 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw)
|
|||
*
|
||||
* \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 deg, min;
|
||||
|
@ -247,7 +261,8 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
|
|||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
/* bail if NULL pointers passed */
|
||||
if (!degrees || !minutes || !seconds || !sw) {
|
||||
if (!degrees || !minutes || !seconds || !sw)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -258,9 +273,12 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
|
|||
* passed 361 st will be set to 1, etc. If passed
|
||||
* a value > -180 || < 180, value will be unchanged.
|
||||
*/
|
||||
if (dec >= 0.0) {
|
||||
if (dec >= 0.0)
|
||||
{
|
||||
st = fmod(dec + 180, 360) - 180;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
st = fmod(dec - 180, 360) + 180;
|
||||
}
|
||||
|
||||
|
@ -268,9 +286,12 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds,
|
|||
* to be negative as well except for 180 which we want
|
||||
* to be positive.
|
||||
*/
|
||||
if (st < 0.0 && st != -180) {
|
||||
if (st < 0.0 && st != -180)
|
||||
{
|
||||
*sw = 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
*sw = 0;
|
||||
}
|
||||
|
||||
|
@ -329,13 +350,15 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw)
|
|||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
/* bail if NULL pointers passed */
|
||||
if (!degrees || !minutes || !sw) {
|
||||
if (!degrees || !minutes || !sw)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
r = dec2dms(dec, degrees, &min, &sec, sw);
|
||||
|
||||
if (r != RIG_OK) {
|
||||
if (r != RIG_OK)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -370,9 +393,9 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw)
|
|||
*
|
||||
* \sa longlat2locator()
|
||||
*/
|
||||
|
||||
/* begin dph */
|
||||
int HAMLIB_API locator2longlat(double *longitude, double *latitude,
|
||||
int HAMLIB_API locator2longlat(double *longitude,
|
||||
double *latitude,
|
||||
const char *locator)
|
||||
{
|
||||
int x_or_y, paircount;
|
||||
|
@ -383,33 +406,40 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude,
|
|||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
/* bail if NULL pointers passed */
|
||||
if (!longitude || !latitude) {
|
||||
if (!longitude || !latitude)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
paircount = strlen(locator) / 2;
|
||||
|
||||
/* verify paircount is within limits */
|
||||
if (paircount > MAX_LOCATOR_PAIRS) {
|
||||
if (paircount > MAX_LOCATOR_PAIRS)
|
||||
{
|
||||
paircount = MAX_LOCATOR_PAIRS;
|
||||
} else if (paircount < MIN_LOCATOR_PAIRS) {
|
||||
}
|
||||
else if (paircount < MIN_LOCATOR_PAIRS)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
ordinate = -90.0;
|
||||
divisions = 1;
|
||||
|
||||
for (pair = 0; pair < paircount; ++pair) {
|
||||
for (pair = 0; pair < paircount; ++pair)
|
||||
{
|
||||
locvalue = locator[pair * 2 + x_or_y];
|
||||
|
||||
/* Value of digit or letter */
|
||||
locvalue -= (loc_char_range[pair] == 10) ? '0' :
|
||||
(isupper(locvalue)) ? 'A' : 'a';
|
||||
(isupper(locvalue)) ? 'A' : 'a';
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -452,9 +482,10 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude,
|
|||
*
|
||||
* \sa locator2longlat()
|
||||
*/
|
||||
|
||||
/* 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 x_or_y, pair, locvalue, divisions;
|
||||
|
@ -462,22 +493,26 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!locator) {
|
||||
if (!locator)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (pair_count < MIN_LOCATOR_PAIRS || pair_count > MAX_LOCATOR_PAIRS) {
|
||||
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;
|
||||
divisions = 1;
|
||||
|
||||
/* The 1e-6 here guards against floating point rounding errors */
|
||||
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];
|
||||
square_size = 180.0 / divisions;
|
||||
|
||||
|
@ -520,57 +555,72 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
|
|||
*
|
||||
* \sa distance_long_path(), azimuth_long_path()
|
||||
*/
|
||||
int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2,
|
||||
double *distance, double *azimuth)
|
||||
int HAMLIB_API qrb(double lon1,
|
||||
double lat1,
|
||||
double lon2,
|
||||
double lat2,
|
||||
double *distance,
|
||||
double *azimuth)
|
||||
{
|
||||
double delta_long, tmp, arc, az;
|
||||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
/* bail if NULL pointers passed */
|
||||
if (!distance || !azimuth) {
|
||||
if (!distance || !azimuth)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* Prevent ACOS() Domain Error */
|
||||
if (lat1 == 90.0) {
|
||||
if (lat1 == 90.0)
|
||||
{
|
||||
lat1 = 89.999999999;
|
||||
} else if (lat1 == -90.0) {
|
||||
}
|
||||
else if (lat1 == -90.0)
|
||||
{
|
||||
lat1 = -89.999999999;
|
||||
}
|
||||
|
||||
if (lat2 == 90.0) {
|
||||
if (lat2 == 90.0)
|
||||
{
|
||||
lat2 = 89.999999999;
|
||||
} else if (lat2 == -90.0) {
|
||||
}
|
||||
else if (lat2 == -90.0)
|
||||
{
|
||||
lat2 = -89.999999999;
|
||||
}
|
||||
|
||||
/* Convert variables to Radians */
|
||||
lat1 /= RADIAN;
|
||||
lon1 /= RADIAN;
|
||||
lat2 /= RADIAN;
|
||||
lon2 /= RADIAN;
|
||||
lat1 /= RADIAN;
|
||||
lon1 /= RADIAN;
|
||||
lat2 /= RADIAN;
|
||||
lon2 /= RADIAN;
|
||||
|
||||
delta_long = lon2 - lon1;
|
||||
|
||||
tmp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(delta_long);
|
||||
|
||||
if (tmp > .999999999999999) {
|
||||
if (tmp > .999999999999999)
|
||||
{
|
||||
/* Station points coincide, use an Omni! */
|
||||
*distance = 0.0;
|
||||
*azimuth = 0.0;
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
if (tmp < -.999999) {
|
||||
if (tmp < -.999999)
|
||||
{
|
||||
/*
|
||||
* points are antipodal, it's straight down.
|
||||
* Station is equal distance in all Azimuths.
|
||||
|
@ -598,9 +648,12 @@ int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2,
|
|||
|
||||
az = fmod(360.0 + az, 360.0);
|
||||
|
||||
if (az < 0.0) {
|
||||
if (az < 0.0)
|
||||
{
|
||||
az += 360.0;
|
||||
} else if (az >= 360.0) {
|
||||
}
|
||||
else if (az >= 360.0)
|
||||
{
|
||||
az -= 360.0;
|
||||
}
|
||||
|
||||
|
@ -645,15 +698,24 @@ double HAMLIB_API azimuth_long_path(double azimuth)
|
|||
{
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (azimuth == 0.0 || azimuth == 360.0) {
|
||||
if (azimuth == 0.0 || azimuth == 360.0)
|
||||
{
|
||||
return 180.0;
|
||||
} else if (azimuth > 0.0 && azimuth < 180.0) {
|
||||
}
|
||||
else if (azimuth > 0.0 && azimuth < 180.0)
|
||||
{
|
||||
return 180.0 + azimuth;
|
||||
} else if (azimuth == 180.0) {
|
||||
}
|
||||
else if (azimuth == 180.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;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
1000
src/microham.c
1000
src/microham.c
Plik diff jest za duży
Load Diff
|
@ -1,3 +1,24 @@
|
|||
/*
|
||||
* Hamlib Interface - Microham device support for POSIX systems
|
||||
* Copyright (c) 2017 by Christoph van Wüllen
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
// declaration of functions implemented in microham.c
|
||||
//
|
||||
|
@ -9,4 +30,3 @@ extern void uh_set_ptt(int ptt);
|
|||
extern int uh_get_ptt();
|
||||
extern void uh_close_radio();
|
||||
extern void uh_close_ptt();
|
||||
|
||||
|
|
273
src/misc.c
273
src/misc.c
|
@ -29,7 +29,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -39,12 +39,15 @@
|
|||
#include <unistd.h> /* UNIX standard function definitions */
|
||||
#include <fcntl.h> /* File control definitions */
|
||||
#include <errno.h> /* Error number definitions */
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -70,11 +73,11 @@
|
|||
*
|
||||
* Returns a pointer to (unsigned char *)bcd_data.
|
||||
*
|
||||
* \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;
|
||||
unsigned char a;
|
||||
|
@ -84,7 +87,8 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
|
|||
/* '450'/4-> 5,0;0,4 */
|
||||
/* '450'/3-> 5,0;x,4 */
|
||||
|
||||
for (i = 0; i < bcd_len / 2; i++) {
|
||||
for (i = 0; i < bcd_len / 2; i++)
|
||||
{
|
||||
a = freq % 10;
|
||||
freq /= 10;
|
||||
a |= (freq % 10) << 4;
|
||||
|
@ -92,7 +96,8 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
|
|||
bcd_data[i] = a;
|
||||
}
|
||||
|
||||
if (bcd_len & 1) {
|
||||
if (bcd_len & 1)
|
||||
{
|
||||
bcd_data[i] &= 0xf0;
|
||||
bcd_data[i] |= freq % 10; /* NB: high nibble is left uncleared */
|
||||
}
|
||||
|
@ -116,7 +121,7 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
|
|||
*
|
||||
* Returns frequency in Hz an unsigned long long integer.
|
||||
*
|
||||
* \sa from_bcd_be
|
||||
* \sa from_bcd_be()
|
||||
*/
|
||||
unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[],
|
||||
unsigned bcd_len)
|
||||
|
@ -126,11 +131,13 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[],
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (bcd_len & 1) {
|
||||
if (bcd_len & 1)
|
||||
{
|
||||
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 += bcd_data[i] >> 4;
|
||||
f *= 10;
|
||||
|
@ -151,11 +158,11 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[],
|
|||
* Same as to_bcd, but in big-endian order
|
||||
* (e.g. byte order 12 34 56 78 90 for 1234567890 Hz)
|
||||
*
|
||||
* \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;
|
||||
unsigned char a;
|
||||
|
@ -165,14 +172,16 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[],
|
|||
|
||||
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] |= (freq % 10) <<
|
||||
4; /* NB: low nibble is left uncleared */
|
||||
freq /= 10;
|
||||
}
|
||||
|
||||
for (i = (bcd_len / 2) - 1; i >= 0; i--) {
|
||||
for (i = (bcd_len / 2) - 1; i >= 0; i--)
|
||||
{
|
||||
a = freq % 10;
|
||||
freq /= 10;
|
||||
a |= (freq % 10) << 4;
|
||||
|
@ -193,7 +202,7 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[],
|
|||
* Same as from_bcd, but in big-endian order
|
||||
* (e.g. byte order 12 34 56 78 90 for 1234567890 Hz)
|
||||
*
|
||||
* \sa from_bcd
|
||||
* \sa from_bcd()
|
||||
*/
|
||||
unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[],
|
||||
unsigned bcd_len)
|
||||
|
@ -203,14 +212,16 @@ unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[],
|
|||
|
||||
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 += bcd_data[i] >> 4;
|
||||
f *= 10;
|
||||
f += bcd_data[i] & 0x0f;
|
||||
}
|
||||
|
||||
if (bcd_len & 1) {
|
||||
if (bcd_len & 1)
|
||||
{
|
||||
f *= 10;
|
||||
f += bcd_data[bcd_len / 2] >> 4;
|
||||
}
|
||||
|
@ -240,16 +251,23 @@ int HAMLIB_API sprintf_freq(char *str, freq_t freq)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (llabs(freq) >= GHz(1)) {
|
||||
if (llabs(freq) >= GHz(1))
|
||||
{
|
||||
hz = "GHz";
|
||||
f = (double)freq / GHz(1);
|
||||
} else if (llabs(freq) >= MHz(1)) {
|
||||
}
|
||||
else if (llabs(freq) >= MHz(1))
|
||||
{
|
||||
hz = "MHz";
|
||||
f = (double)freq / MHz(1);
|
||||
} else if (llabs(freq) >= kHz(1)) {
|
||||
}
|
||||
else if (llabs(freq) >= kHz(1))
|
||||
{
|
||||
hz = "kHz";
|
||||
f = (double)freq / kHz(1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
hz = "Hz";
|
||||
f = (double)freq;
|
||||
}
|
||||
|
@ -267,7 +285,8 @@ 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:
|
||||
return "Alpha";
|
||||
|
||||
|
@ -288,10 +307,12 @@ const char * HAMLIB_API rig_strstatus(enum rig_status_e status)
|
|||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
rmode_t mode;
|
||||
const char *str;
|
||||
} mode_str[] = {
|
||||
} mode_str[] =
|
||||
{
|
||||
{ RIG_MODE_AM, "AM" },
|
||||
{ RIG_MODE_CW, "CW" },
|
||||
{ RIG_MODE_USB, "USB" },
|
||||
|
@ -330,9 +351,12 @@ rmode_t HAMLIB_API rig_parse_mode(const char *s)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
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 RIG_MODE_NONE;
|
||||
}
|
||||
|
@ -351,23 +375,29 @@ const char * HAMLIB_API rig_strrmode(rmode_t mode)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (mode == RIG_MODE_NONE) {
|
||||
if (mode == RIG_MODE_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
vfo_t vfo;
|
||||
const char *str;
|
||||
} vfo_str[] = {
|
||||
} vfo_str[] =
|
||||
{
|
||||
{ RIG_VFO_A, "VFOA" },
|
||||
{ RIG_VFO_B, "VFOB" },
|
||||
{ RIG_VFO_C, "VFOC" },
|
||||
|
@ -396,9 +426,12 @@ vfo_t HAMLIB_API rig_parse_vfo(const char *s)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
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 RIG_VFO_NONE;
|
||||
}
|
||||
|
@ -417,23 +450,29 @@ const char * HAMLIB_API rig_strvfo(vfo_t vfo)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (vfo == RIG_VFO_NONE) {
|
||||
if (vfo == RIG_VFO_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
setting_t func;
|
||||
const char *str;
|
||||
} func_str[] = {
|
||||
} func_str[] =
|
||||
{
|
||||
{ RIG_FUNC_FAGC, "FAGC" },
|
||||
{ RIG_FUNC_NB, "NB" },
|
||||
{ RIG_FUNC_COMP, "COMP" },
|
||||
|
@ -475,7 +514,7 @@ static struct {
|
|||
* \param s input alpha string
|
||||
* \return RIG_FUNC_...
|
||||
*
|
||||
* \sa rig_func_e
|
||||
* \sa rig_func_e()
|
||||
*/
|
||||
setting_t HAMLIB_API rig_parse_func(const char *s)
|
||||
{
|
||||
|
@ -484,9 +523,12 @@ setting_t HAMLIB_API rig_parse_func(const char *s)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
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 RIG_FUNC_NONE;
|
||||
}
|
||||
|
@ -497,7 +539,7 @@ setting_t HAMLIB_API rig_parse_func(const char *s)
|
|||
* \param func RIG_FUNC_...
|
||||
* \return alpha string
|
||||
*
|
||||
* \sa rig_func_e
|
||||
* \sa rig_func_e()
|
||||
*/
|
||||
const char * HAMLIB_API rig_strfunc(setting_t func)
|
||||
{
|
||||
|
@ -505,23 +547,29 @@ const char * HAMLIB_API rig_strfunc(setting_t func)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (func == RIG_FUNC_NONE) {
|
||||
if (func == RIG_FUNC_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
setting_t level;
|
||||
const char *str;
|
||||
} level_str[] = {
|
||||
} level_str[] =
|
||||
{
|
||||
{ RIG_LEVEL_PREAMP, "PREAMP" },
|
||||
{ RIG_LEVEL_ATT, "ATT" },
|
||||
{ RIG_LEVEL_VOX, "VOX" },
|
||||
|
@ -562,7 +610,7 @@ static struct {
|
|||
* \param s input alpha string
|
||||
* \return RIG_LEVEL_...
|
||||
*
|
||||
* \sa rig_level_e
|
||||
* \sa rig_level_e()
|
||||
*/
|
||||
setting_t HAMLIB_API rig_parse_level(const char *s)
|
||||
{
|
||||
|
@ -571,9 +619,12 @@ setting_t HAMLIB_API rig_parse_level(const char *s)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
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 RIG_LEVEL_NONE;
|
||||
}
|
||||
|
@ -584,7 +635,7 @@ setting_t HAMLIB_API rig_parse_level(const char *s)
|
|||
* \param level RIG_LEVEL_...
|
||||
* \return alpha string
|
||||
*
|
||||
* \sa rig_level_e
|
||||
* \sa rig_level_e()
|
||||
*/
|
||||
const char * HAMLIB_API rig_strlevel(setting_t level)
|
||||
{
|
||||
|
@ -592,23 +643,29 @@ const char * HAMLIB_API rig_strlevel(setting_t level)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (level == RIG_LEVEL_NONE) {
|
||||
if (level == RIG_LEVEL_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
setting_t parm;
|
||||
const char *str;
|
||||
} parm_str[] = {
|
||||
} parm_str[] =
|
||||
{
|
||||
{ RIG_PARM_ANN, "ANN" },
|
||||
{ RIG_PARM_APO, "APO" },
|
||||
{ RIG_PARM_BACKLIGHT, "BACKLIGHT" },
|
||||
|
@ -625,7 +682,7 @@ static struct {
|
|||
* \param s input alpha string
|
||||
* \return RIG_PARM_...
|
||||
*
|
||||
* \sa rig_parm_e
|
||||
* \sa rig_parm_e()
|
||||
*/
|
||||
setting_t HAMLIB_API rig_parse_parm(const char *s)
|
||||
{
|
||||
|
@ -634,9 +691,12 @@ setting_t HAMLIB_API rig_parse_parm(const char *s)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
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 RIG_PARM_NONE;
|
||||
}
|
||||
|
@ -647,7 +707,7 @@ setting_t HAMLIB_API rig_parse_parm(const char *s)
|
|||
* \param parm RIG_PARM_...
|
||||
* \return alpha string
|
||||
*
|
||||
* \sa rig_parm_e
|
||||
* \sa rig_parm_e()
|
||||
*/
|
||||
const char * HAMLIB_API rig_strparm(setting_t parm)
|
||||
{
|
||||
|
@ -655,23 +715,29 @@ const char * HAMLIB_API rig_strparm(setting_t parm)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (parm == RIG_PARM_NONE) {
|
||||
if (parm == RIG_PARM_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
vfo_op_t vfo_op;
|
||||
const char *str;
|
||||
} vfo_op_str[] = {
|
||||
} vfo_op_str[] =
|
||||
{
|
||||
{ RIG_OP_CPY, "CPY" },
|
||||
{ RIG_OP_XCHG, "XCHG" },
|
||||
{ RIG_OP_FROM_VFO, "FROM_VFO" },
|
||||
|
@ -694,7 +760,7 @@ static struct {
|
|||
* \param s alpha string
|
||||
* \return RIG_OP_...
|
||||
*
|
||||
* \sa vfo_op_t
|
||||
* \sa vfo_op_t()
|
||||
*/
|
||||
vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s)
|
||||
{
|
||||
|
@ -703,9 +769,12 @@ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s)
|
|||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
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 RIG_OP_NONE;
|
||||
}
|
||||
|
@ -716,7 +785,7 @@ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s)
|
|||
* \param op RIG_OP_...
|
||||
* \return alpha string
|
||||
*
|
||||
* \sa vfo_op_t
|
||||
* \sa vfo_op_t()
|
||||
*/
|
||||
const char * HAMLIB_API rig_strvfop(vfo_op_t op)
|
||||
{
|
||||
|
@ -724,23 +793,28 @@ const char * HAMLIB_API rig_strvfop(vfo_op_t op)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (op == RIG_OP_NONE) {
|
||||
if (op == RIG_OP_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
scan_t rscan;
|
||||
const char *str;
|
||||
} scan_str[] = {
|
||||
} scan_str[] =
|
||||
{
|
||||
{ RIG_SCAN_STOP, "STOP" },
|
||||
{ RIG_SCAN_MEM, "MEM" },
|
||||
{ RIG_SCAN_SLCT, "SLCT" },
|
||||
|
@ -759,7 +833,7 @@ static struct {
|
|||
* \param s alpha string
|
||||
* \return RIG_SCAN_...
|
||||
*
|
||||
* \sa scan_t
|
||||
* \sa scan_t()
|
||||
*/
|
||||
scan_t HAMLIB_API rig_parse_scan(const char *s)
|
||||
{
|
||||
|
@ -767,8 +841,10 @@ scan_t HAMLIB_API rig_parse_scan(const char *s)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
for (i = 0 ; scan_str[i].str[0] != '\0'; i++) {
|
||||
if (strcmp(s, scan_str[i].str) == 0) {
|
||||
for (i = 0 ; scan_str[i].str[0] != '\0'; i++)
|
||||
{
|
||||
if (strcmp(s, scan_str[i].str) == 0)
|
||||
{
|
||||
return scan_str[i].rscan;
|
||||
}
|
||||
}
|
||||
|
@ -782,7 +858,7 @@ scan_t HAMLIB_API rig_parse_scan(const char *s)
|
|||
* \param rscan RIG_SCAN_...
|
||||
* \return alpha string
|
||||
*
|
||||
* \sa scan_t
|
||||
* \sa scan_t()
|
||||
*/
|
||||
const char * HAMLIB_API rig_strscan(scan_t rscan)
|
||||
{
|
||||
|
@ -790,14 +866,17 @@ const char * HAMLIB_API rig_strscan(scan_t rscan)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (rscan == RIG_SCAN_NONE) {
|
||||
if (rscan == RIG_SCAN_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
for (i = 0; scan_str[i].str[0] != '\0'; i++)
|
||||
if (rscan == scan_str[i].rscan) {
|
||||
{ if (rscan == scan_str[i].rscan)
|
||||
{
|
||||
return scan_str[i].str;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
@ -808,11 +887,12 @@ const char * HAMLIB_API rig_strscan(scan_t rscan)
|
|||
* \param shift RIG_RPT_SHIFT_??
|
||||
* \return alpha character
|
||||
*/
|
||||
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 "-";
|
||||
|
||||
|
@ -836,20 +916,27 @@ rptr_shift_t HAMLIB_API rig_parse_rptr_shift(const char *s)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (strcmp(s, "+") == 0) {
|
||||
if (strcmp(s, "+") == 0)
|
||||
{
|
||||
return RIG_RPT_SHIFT_PLUS;
|
||||
} else if (strcmp(s, "-") == 0) {
|
||||
}
|
||||
else if (strcmp(s, "-") == 0)
|
||||
{
|
||||
return RIG_RPT_SHIFT_MINUS;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return RIG_RPT_SHIFT_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
chan_type_t mtype;
|
||||
const char *str;
|
||||
} mtype_str[] = {
|
||||
} mtype_str[] =
|
||||
{
|
||||
{ RIG_MTYPE_MEM, "MEM" },
|
||||
{ RIG_MTYPE_EDGE, "EDGE" },
|
||||
{ RIG_MTYPE_CALL, "CALL" },
|
||||
|
@ -866,7 +953,7 @@ static struct {
|
|||
* \param s alpha string
|
||||
* \return RIG_MTYPE_...
|
||||
*
|
||||
* \sa chan_type_t
|
||||
* \sa chan_type_t()
|
||||
*/
|
||||
chan_type_t HAMLIB_API rig_parse_mtype(const char *s)
|
||||
{
|
||||
|
@ -874,8 +961,10 @@ chan_type_t HAMLIB_API rig_parse_mtype(const char *s)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
for (i = 0 ; mtype_str[i].str[0] != '\0'; i++) {
|
||||
if (strcmp(s, mtype_str[i].str) == 0) {
|
||||
for (i = 0 ; mtype_str[i].str[0] != '\0'; i++)
|
||||
{
|
||||
if (strcmp(s, mtype_str[i].str) == 0)
|
||||
{
|
||||
return mtype_str[i].mtype;
|
||||
}
|
||||
}
|
||||
|
@ -889,7 +978,7 @@ chan_type_t HAMLIB_API rig_parse_mtype(const char *s)
|
|||
* \param mtype RIG_MTYPE_...
|
||||
* \return alpha string
|
||||
*
|
||||
* \sa chan_type_t
|
||||
* \sa chan_type_t()
|
||||
*/
|
||||
const char * HAMLIB_API rig_strmtype(chan_type_t mtype)
|
||||
{
|
||||
|
@ -897,14 +986,18 @@ const char * HAMLIB_API rig_strmtype(chan_type_t mtype)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (mtype == RIG_MTYPE_NONE) {
|
||||
if (mtype == RIG_MTYPE_NONE)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
@ -934,7 +1027,8 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
|
|||
|
||||
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,
|
||||
"%s: forced cache timeout\n",
|
||||
__func__);
|
||||
|
@ -945,13 +1039,16 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
|
|||
|
||||
t = timediff(&curr, tv);
|
||||
|
||||
if (t < timeout) {
|
||||
if (t < timeout)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: using cache (%ld ms)\n",
|
||||
__func__,
|
||||
t);
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: cache timed out (%ld ms)\n",
|
||||
__func__,
|
||||
|
|
35
src/misc.h
35
src/misc.h
|
@ -57,7 +57,8 @@ extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[],
|
|||
unsigned long long freq,
|
||||
unsigned bcd_len);
|
||||
|
||||
extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char bcd_data[],
|
||||
extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char
|
||||
bcd_data[],
|
||||
unsigned bcd_len);
|
||||
|
||||
/*
|
||||
|
@ -67,7 +68,8 @@ extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[],
|
|||
unsigned long long freq,
|
||||
unsigned bcd_len);
|
||||
|
||||
extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char bcd_data[],
|
||||
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);
|
||||
|
@ -82,10 +84,11 @@ extern int no_restore_ai;
|
|||
|
||||
/* needs config.h included beforehand in .c file */
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv,
|
||||
|
@ -96,24 +99,24 @@ extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv);
|
|||
|
||||
#ifdef PRId64
|
||||
/** \brief printf(3) format to be used for long long (64bits) type */
|
||||
#define PRIll PRId64
|
||||
# define PRIll PRId64
|
||||
#else
|
||||
#ifdef FBSD4
|
||||
#define PRIll "qd"
|
||||
#else
|
||||
#define PRIll "lld"
|
||||
#endif
|
||||
# ifdef FBSD4
|
||||
# define PRIll "qd"
|
||||
# else
|
||||
# define PRIll "lld"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef SCNd64
|
||||
/** \brief scanf(3) format to be used for long long (64bits) type */
|
||||
#define SCNll SCNd64
|
||||
# define SCNll SCNd64
|
||||
#else
|
||||
#ifdef FBSD4
|
||||
#define SCNll "qd"
|
||||
#else
|
||||
#define SCNll "lld"
|
||||
#endif
|
||||
# ifdef FBSD4
|
||||
# define SCNll "qd"
|
||||
# else
|
||||
# define SCNll "lld"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
|
101
src/network.c
101
src/network.c
|
@ -32,7 +32,7 @@
|
|||
/* #define WINVER 0x0501 */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -45,24 +45,26 @@
|
|||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_SYS_SOCKET_H) && defined (HAVE_SYS_IOCTL_H)
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/ioctl.h>
|
||||
#elif HAVE_WS2TCPIP_H
|
||||
#include <ws2tcpip.h>
|
||||
# if defined(HAVE_WSPIAPI_H)
|
||||
# include <wspiapi.h>
|
||||
# endif
|
||||
# include <ws2tcpip.h>
|
||||
# if defined(HAVE_WSPIAPI_H)
|
||||
# include <wspiapi.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -88,15 +90,19 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg)
|
|||
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, e,
|
||||
NULL,
|
||||
e,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
// Default language
|
||||
(LPTSTR)&lpMsgBuf,
|
||||
0,
|
||||
NULL)) {
|
||||
NULL))
|
||||
{
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
|
||||
LocalFree(lpMsgBuf);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rig_debug(lvl, "%s: Network error %d\n", msg, e);
|
||||
}
|
||||
|
||||
|
@ -131,44 +137,56 @@ int network_open(hamlib_port_t *rp, int default_port)
|
|||
#ifdef __MINGW32__
|
||||
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, "%s: error creating socket\n", __func__);
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!rp) {
|
||||
if (!rp)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
|
||||
if (rp->type.rig == RIG_PORT_UDP_NETWORK) {
|
||||
if (rp->type.rig == RIG_PORT_UDP_NETWORK)
|
||||
{
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
}
|
||||
|
||||
/* default of all local interfaces */
|
||||
hoststr = NULL;
|
||||
|
||||
if (rp->pathname[0] == ':') {
|
||||
if (rp->pathname[0] == ':')
|
||||
{
|
||||
portstr = rp->pathname + 1;
|
||||
} else {
|
||||
if (strlen(rp->pathname)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen(rp->pathname))
|
||||
{
|
||||
strncpy(hostname, rp->pathname, FILPATHLEN - 1);
|
||||
hoststr = hostname;
|
||||
/* look for IPv6 numeric form [<addr>] */
|
||||
bracketstr1 = strchr(hoststr, '[');
|
||||
bracketstr2 = strrchr(hoststr, ']');
|
||||
|
||||
if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1) {
|
||||
if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1)
|
||||
{
|
||||
hoststr = bracketstr1 + 1;
|
||||
*bracketstr2 = '\0';
|
||||
portstr = bracketstr2 + 1; /* possible port after ]: */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
bracketstr2 = NULL;
|
||||
portstr = hoststr; /* possible port after : */
|
||||
}
|
||||
|
@ -176,12 +194,14 @@ int network_open(hamlib_port_t *rp, int default_port)
|
|||
/* search last ':' */
|
||||
portstr = strrchr(portstr, ':');
|
||||
|
||||
if (portstr) {
|
||||
if (portstr)
|
||||
{
|
||||
*portstr++ = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (!portstr) {
|
||||
if (!portstr)
|
||||
{
|
||||
sprintf(defaultportstr, "%d", default_port);
|
||||
portstr = defaultportstr;
|
||||
}
|
||||
|
@ -189,7 +209,8 @@ int network_open(hamlib_port_t *rp, int default_port)
|
|||
|
||||
status = getaddrinfo(hoststr, portstr, &hints, &res);
|
||||
|
||||
if (status != 0) {
|
||||
if (status != 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: cannot get host \"%s\": %s\n",
|
||||
__func__,
|
||||
|
@ -205,16 +226,19 @@ int network_open(hamlib_port_t *rp, int default_port)
|
|||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
|
||||
if (fd < 0) {
|
||||
if (fd < 0)
|
||||
{
|
||||
handle_error(RIG_DEBUG_ERR, "socket");
|
||||
freeaddrinfo(saved_res);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -225,11 +249,13 @@ int network_open(hamlib_port_t *rp, int default_port)
|
|||
#else
|
||||
close(fd);
|
||||
#endif
|
||||
} while ((res = res->ai_next) != NULL);
|
||||
}
|
||||
while ((res = res->ai_next) != NULL);
|
||||
|
||||
freeaddrinfo(saved_res);
|
||||
|
||||
if (NULL == res) {
|
||||
if (NULL == res)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: failed to connect to %s\n",
|
||||
__func__,
|
||||
|
@ -260,20 +286,24 @@ void network_flush(hamlib_port_t *rp)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
ioctlsocket(rp->fd, FIONREAD, &len);
|
||||
#else
|
||||
ioctl(rp->fd, FIONREAD, &len);
|
||||
#endif
|
||||
|
||||
if (len > 0) {
|
||||
if (len > 0)
|
||||
{
|
||||
len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE);
|
||||
rig_debug(RIG_DEBUG_WARN,
|
||||
"%s: network data cleared: %s\n",
|
||||
__func__,
|
||||
buffer);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +319,8 @@ int network_close(hamlib_port_t *rp)
|
|||
#ifdef __MINGW32__
|
||||
ret = closesocket(rp->fd);
|
||||
|
||||
if (--wsstarted) {
|
||||
if (--wsstarted)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
*/
|
||||
|
||||
/* The status pin functions operate in terms of these bits: */
|
||||
enum ieee1284_status_bits {
|
||||
enum ieee1284_status_bits
|
||||
{
|
||||
S1284_NFAULT = 0x08,
|
||||
S1284_SELECT = 0x10,
|
||||
S1284_PERROR = 0x20,
|
||||
|
@ -39,7 +40,8 @@ enum ieee1284_status_bits {
|
|||
};
|
||||
|
||||
/* The control pin functions operate in terms of these bits: */
|
||||
enum ieee1284_control_bits {
|
||||
enum ieee1284_control_bits
|
||||
{
|
||||
C1284_NSTROBE = 0x01,
|
||||
C1284_NAUTOFD = 0x02,
|
||||
C1284_NINIT = 0x04,
|
||||
|
|
172
src/parallel.c
172
src/parallel.c
|
@ -29,7 +29,7 @@
|
|||
* \file parallel.c
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -41,36 +41,39 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#include "par_nt.h"
|
||||
# include <windows.h>
|
||||
# include "par_nt.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINIOCTL_H
|
||||
#include <winioctl.h>
|
||||
# include <winioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINBASE_H
|
||||
#include <winbase.h>
|
||||
# include <winbase.h>
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
#include "parallel.h"
|
||||
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
#include <linux/ppdev.h>
|
||||
#include <linux/parport.h>
|
||||
# include <linux/ppdev.h>
|
||||
# include <linux/parport.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DEV_PPBUS_PPI_H
|
||||
#include <dev/ppbus/ppi.h>
|
||||
#include <dev/ppbus/ppbconf.h>
|
||||
# include <dev/ppbus/ppi.h>
|
||||
# include <dev/ppbus/ppbconf.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -135,7 +138,8 @@ int par_open(hamlib_port_t *port)
|
|||
HANDLE handle;
|
||||
#endif
|
||||
|
||||
if (!port->pathname[0]) {
|
||||
if (!port->pathname[0])
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -143,7 +147,8 @@ int par_open(hamlib_port_t *port)
|
|||
/* TODO: open with O_NONBLOCK ? */
|
||||
fd = open(port->pathname, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
if (fd < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: opening device \"%s\": %s\n",
|
||||
__func__,
|
||||
|
@ -154,7 +159,8 @@ int par_open(hamlib_port_t *port)
|
|||
|
||||
mode = IEEE1284_MODE_COMPAT;
|
||||
|
||||
if (ioctl(fd, PPSETMODE, &mode) != 0) {
|
||||
if (ioctl(fd, PPSETMODE, &mode) != 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n",
|
||||
__func__,
|
||||
port->pathname,
|
||||
|
@ -167,7 +173,8 @@ int par_open(hamlib_port_t *port)
|
|||
|
||||
fd = open(port->pathname, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
if (fd < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: opening device \"%s\": %s\n",
|
||||
__func__,
|
||||
|
@ -180,17 +187,21 @@ int par_open(hamlib_port_t *port)
|
|||
handle = CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE,
|
||||
0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: opening device \"%s\"\n",
|
||||
__func__,
|
||||
port->pathname);
|
||||
CloseHandle(handle);
|
||||
return -RIG_EIO;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = _open_osfhandle((intptr_t)handle, _O_APPEND | _O_RDONLY);
|
||||
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
return -RIG_EIO;
|
||||
}
|
||||
}
|
||||
|
@ -246,9 +257,11 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
|
|||
|
||||
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_DATA, &data, sizeof(data),
|
||||
NULL, 0, (LPDWORD)&dummy, NULL))) {
|
||||
NULL, 0, (LPDWORD)&dummy, NULL)))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
@ -286,10 +299,21 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
|
|||
|
||||
handle = _get_osfhandle(port->fd);
|
||||
|
||||
if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
|
||||
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret,
|
||||
sizeof(ret), (LPDWORD)&dummy, NULL))) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
|
||||
if (handle != (intptr_t)INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (!(DeviceIoControl((HANDLE)handle,
|
||||
NT_IOCTL_STATUS,
|
||||
NULL,
|
||||
0,
|
||||
&ret,
|
||||
sizeof(ret),
|
||||
(LPDWORD)&dummy,
|
||||
NULL)))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: DeviceIoControl failed!\n",
|
||||
__func__);
|
||||
|
||||
return -RIG_EIO;
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +340,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
|
|||
unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
|
||||
status = ioctl(port->fd, PPWCONTROL, &ctrl);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: ioctl(PPWCONTROL) failed: %s\n",
|
||||
__func__,
|
||||
|
@ -339,10 +364,11 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
|
|||
| C1284_NSELECTIN);
|
||||
intptr_t handle;
|
||||
|
||||
if (ctr & 0x20) {
|
||||
if (ctr & 0x20)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_WARN,
|
||||
"%s: use ieee1284_data_dir to change data line direction!\n",
|
||||
__func__);
|
||||
__func__);
|
||||
}
|
||||
|
||||
/* Deal with inversion issues. */
|
||||
|
@ -351,7 +377,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
|
|||
|
||||
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,
|
||||
|
@ -359,10 +386,11 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
|
|||
&dummyc,
|
||||
sizeof(dummyc),
|
||||
(LPDWORD)&dummy,
|
||||
NULL))) {
|
||||
NULL)))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: frob_control: DeviceIoControl failed!\n",
|
||||
__func__);
|
||||
__func__);
|
||||
return -RIG_EIO;
|
||||
}
|
||||
}
|
||||
|
@ -388,7 +416,8 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
|
|||
unsigned char ctrl;
|
||||
status = ioctl(port->fd, PPRCONTROL, &ctrl);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: ioctl(PPRCONTROL) failed: %s\n",
|
||||
__func__,
|
||||
|
@ -411,10 +440,21 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
|
|||
|
||||
handle = _get_osfhandle(port->fd);
|
||||
|
||||
if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
|
||||
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, NULL, 0, &ret,
|
||||
sizeof(ret), (LPDWORD)&dummy, NULL))) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
|
||||
if (handle != (intptr_t)INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (!(DeviceIoControl((HANDLE)handle,
|
||||
NT_IOCTL_CONTROL,
|
||||
NULL,
|
||||
0,
|
||||
&ret,
|
||||
sizeof(ret),
|
||||
(LPDWORD)&dummy,
|
||||
NULL)))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: DeviceIoControl failed!\n",
|
||||
__func__);
|
||||
|
||||
return -RIG_EIO;
|
||||
}
|
||||
}
|
||||
|
@ -441,15 +481,19 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
|
|||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
int ret;
|
||||
unsigned char sta;
|
||||
|
||||
ret = ioctl(port->fd, PPRSTATUS, &sta);
|
||||
*status = sta ^ SP_ACTIVE_LOW_BITS;
|
||||
return ret == 0 ? RIG_OK : -RIG_EIO;
|
||||
|
||||
#elif defined(HAVE_DEV_PPBUS_PPI_H)
|
||||
int ret;
|
||||
unsigned char sta;
|
||||
|
||||
ret = ioctl(port->fd, PPIGSTATUS, &sta);
|
||||
*status = sta ^ SP_ACTIVE_LOW_BITS;
|
||||
return ret == 0 ? RIG_OK : -RIG_EIO;
|
||||
|
||||
#elif defined(__WIN64__) || defined(__WIN32__)
|
||||
unsigned char ret;
|
||||
unsigned int dummy;
|
||||
|
@ -458,10 +502,21 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
|
|||
|
||||
handle = _get_osfhandle(port->fd);
|
||||
|
||||
if (handle != (intptr_t)INVALID_HANDLE_VALUE) {
|
||||
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret,
|
||||
sizeof(ret), (LPDWORD)&dummy, NULL))) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
|
||||
if (handle != (intptr_t)INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (!(DeviceIoControl((HANDLE)handle,
|
||||
NT_IOCTL_STATUS,
|
||||
NULL,
|
||||
0,
|
||||
&ret,
|
||||
sizeof(ret),
|
||||
(LPDWORD)&dummy,
|
||||
NULL)))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: DeviceIoControl failed!\n",
|
||||
__func__);
|
||||
|
||||
return -RIG_EIO;
|
||||
}
|
||||
}
|
||||
|
@ -486,7 +541,8 @@ int HAMLIB_API par_lock(hamlib_port_t *port)
|
|||
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
|
||||
if (ioctl(port->fd, PPCLAIM) < 0) {
|
||||
if (ioctl(port->fd, PPCLAIM) < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: claiming device \"%s\": %s\n",
|
||||
__func__,
|
||||
|
@ -517,7 +573,8 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
|
|||
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
|
||||
if (ioctl(port->fd, PPRELEASE) < 0) {
|
||||
if (ioctl(port->fd, PPRELEASE) < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: releasing device \"%s\": %s\n",
|
||||
__func__,
|
||||
|
@ -538,10 +595,11 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
|
|||
|
||||
|
||||
#ifndef PARPORT_CONTROL_STROBE
|
||||
#define PARPORT_CONTROL_STROBE 0x1
|
||||
# define PARPORT_CONTROL_STROBE 0x1
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_CONTROL_INIT
|
||||
#define PARPORT_CONTROL_INIT 0x4
|
||||
# define PARPORT_CONTROL_INIT 0x4
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -555,15 +613,18 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
switch (p->type.ptt) {
|
||||
case RIG_PTT_PARALLEL: {
|
||||
switch (p->type.ptt)
|
||||
{
|
||||
case RIG_PTT_PARALLEL:
|
||||
{
|
||||
unsigned char ctl;
|
||||
int status;
|
||||
|
||||
par_lock(p);
|
||||
status = par_read_control(p, &ctl);
|
||||
|
||||
if (status != RIG_OK) {
|
||||
if (status != RIG_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -573,9 +634,12 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
|
|||
/* TODO: kill parm.parallel.pin? */
|
||||
|
||||
/* PTT keying - /INIT bit (pin 16) (inverted) */
|
||||
if (pttx == RIG_PTT_ON) {
|
||||
if (pttx == RIG_PTT_ON)
|
||||
{
|
||||
ctl |= PARPORT_CONTROL_INIT;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ctl &= ~PARPORT_CONTROL_INIT;
|
||||
}
|
||||
|
||||
|
@ -606,8 +670,10 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
switch (p->type.ptt) {
|
||||
case RIG_PTT_PARALLEL: {
|
||||
switch (p->type.ptt)
|
||||
{
|
||||
case RIG_PTT_PARALLEL:
|
||||
{
|
||||
unsigned char ctl;
|
||||
int status;
|
||||
|
||||
|
@ -643,8 +709,10 @@ int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
switch (p->type.dcd) {
|
||||
case RIG_DCD_PARALLEL: {
|
||||
switch (p->type.dcd)
|
||||
{
|
||||
case RIG_DCD_PARALLEL:
|
||||
{
|
||||
unsigned char reg;
|
||||
int status;
|
||||
|
||||
|
|
|
@ -27,36 +27,43 @@
|
|||
#include "iofunc.h"
|
||||
|
||||
#ifdef HAVE_LINUX_PARPORT_H
|
||||
#include <linux/parport.h>
|
||||
# include <linux/parport.h>
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_CONTROL_STROBE
|
||||
#define PARPORT_CONTROL_STROBE 0x1
|
||||
# define PARPORT_CONTROL_STROBE 0x1
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_CONTROL_AUTOFD
|
||||
#define PARPORT_CONTROL_AUTOFD 0x2
|
||||
# define PARPORT_CONTROL_AUTOFD 0x2
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_CONTROL_INIT
|
||||
#define PARPORT_CONTROL_INIT 0x4
|
||||
# define PARPORT_CONTROL_INIT 0x4
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_CONTROL_SELECT
|
||||
#define PARPORT_CONTROL_SELECT 0x8
|
||||
# define PARPORT_CONTROL_SELECT 0x8
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_STATUS_ERROR
|
||||
#define PARPORT_STATUS_ERROR 0x8
|
||||
# define PARPORT_STATUS_ERROR 0x8
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_STATUS_SELECT
|
||||
#define PARPORT_STATUS_SELECT 0x10
|
||||
# define PARPORT_STATUS_SELECT 0x10
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_STATUS_PAPEROUT
|
||||
#define PARPORT_STATUS_PAPEROUT 0x20
|
||||
# define PARPORT_STATUS_PAPEROUT 0x20
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_STATUS_ACK
|
||||
#define PARPORT_STATUS_ACK 0x40
|
||||
# define PARPORT_STATUS_ACK 0x40
|
||||
#endif
|
||||
|
||||
#ifndef PARPORT_STATUS_BUSY
|
||||
#define PARPORT_STATUS_BUSY 0x80
|
||||
# define PARPORT_STATUS_BUSY 0x80
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
|
126
src/register.c
126
src/register.c
|
@ -27,7 +27,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -42,7 +42,7 @@
|
|||
#include <hamlib/rig.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
# define PATH_MAX 1024
|
||||
# define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
#define RIG_BACKEND_MAX 32
|
||||
|
@ -93,19 +93,22 @@ DEFINE_INITRIG_BACKEND(winradio);
|
|||
#endif
|
||||
|
||||
|
||||
/*! \def rig_backend_list
|
||||
/**
|
||||
* \def rig_backend_list
|
||||
* \brief Static list of rig models.
|
||||
*
|
||||
* This is a NULL terminated list of available rig backends. Each entry
|
||||
* in the list consists of two fields: The branch number, which is an integer,
|
||||
* This is a NULL terminated list of available rig backends. Each entry in
|
||||
* the list consists of two fields: The branch number, which is an integer,
|
||||
* and the branch name, which is a character string.
|
||||
*/
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
int be_num;
|
||||
const char *be_name;
|
||||
int (* be_init_all)(void *handle);
|
||||
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_YAESU, RIG_BACKEND_YAESU, RIG_FUNCNAM(yaesu) },
|
||||
{ RIG_KENWOOD, RIG_BACKEND_KENWOOD, RIG_FUNCNAM(kenwood) },
|
||||
|
@ -144,7 +147,8 @@ static struct {
|
|||
* This struct to keep track of known rig models.
|
||||
* It is chained, and used in a hash table, see below.
|
||||
*/
|
||||
struct rig_list {
|
||||
struct rig_list
|
||||
{
|
||||
const struct rig_caps *caps;
|
||||
struct rig_list *next;
|
||||
};
|
||||
|
@ -174,7 +178,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!caps) {
|
||||
if (!caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -185,7 +190,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
|
|||
|
||||
#ifndef DONT_WANT_DUP_CHECK
|
||||
|
||||
if (rig_get_caps(caps->rig_model) != NULL) {
|
||||
if (rig_get_caps(caps->rig_model) != NULL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -193,7 +199,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
|
|||
|
||||
p = (struct rig_list *)malloc(sizeof(struct rig_list));
|
||||
|
||||
if (!p) {
|
||||
if (!p)
|
||||
{
|
||||
return -RIG_ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -211,12 +218,14 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
|
|||
* ie. rig_hash_table lookup
|
||||
*/
|
||||
|
||||
const struct rig_caps *HAMLIB_API rig_get_caps(rig_model_t rig_model)
|
||||
const struct rig_caps * HAMLIB_API rig_get_caps(rig_model_t rig_model)
|
||||
{
|
||||
struct rig_list *p;
|
||||
|
||||
for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next) {
|
||||
if (p->caps->rig_model == rig_model) {
|
||||
for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next)
|
||||
{
|
||||
if (p->caps->rig_model == rig_model)
|
||||
{
|
||||
return p->caps;
|
||||
}
|
||||
}
|
||||
|
@ -233,9 +242,11 @@ static int rig_lookup_backend(rig_model_t rig_model)
|
|||
{
|
||||
int i;
|
||||
|
||||
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) ==
|
||||
rig_backend_list[i].be_num) {
|
||||
rig_backend_list[i].be_num)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +269,8 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model)
|
|||
/* already loaded ? */
|
||||
caps = rig_get_caps(rig_model);
|
||||
|
||||
if (caps) {
|
||||
if (caps)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
@ -267,10 +279,12 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model)
|
|||
/*
|
||||
* Never heard about this backend family!
|
||||
*/
|
||||
if (be_idx == -1) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "rig_check_backend: unsupported "
|
||||
"backend %d for model %d\n",
|
||||
RIG_BACKEND_NUM(rig_model), rig_model);
|
||||
if (be_idx == -1)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE,
|
||||
"rig_check_backend: unsupported backend %d for model %d\n",
|
||||
RIG_BACKEND_NUM(rig_model),
|
||||
rig_model);
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -289,11 +303,16 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model)
|
|||
hval = HASH_FUNC(rig_model);
|
||||
q = NULL;
|
||||
|
||||
for (p = rig_hash_table[hval]; p; p = p->next) {
|
||||
if (p->caps->rig_model == rig_model) {
|
||||
if (q == NULL) {
|
||||
for (p = rig_hash_table[hval]; p; p = p->next)
|
||||
{
|
||||
if (p->caps->rig_model == rig_model)
|
||||
{
|
||||
if (q == NULL)
|
||||
{
|
||||
rig_hash_table[hval] = p->next;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
q->next = p->next;
|
||||
}
|
||||
|
||||
|
@ -312,22 +331,27 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model)
|
|||
* 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)
|
||||
rig_ptr_t),
|
||||
rig_ptr_t data)
|
||||
{
|
||||
struct rig_list *p;
|
||||
int i;
|
||||
|
||||
if (!cfunc) {
|
||||
if (!cfunc)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < RIGLSTHASHSZ; i++) {
|
||||
for (i = 0; i < RIGLSTHASHSZ; i++)
|
||||
{
|
||||
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 */
|
||||
|
||||
if ((*cfunc)(p->caps, data) == 0) {
|
||||
if ((*cfunc)(p->caps, data) == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
}
|
||||
|
@ -336,13 +360,17 @@ int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *,
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
static int dummy_rig_probe(const hamlib_port_t *p, rig_model_t model,
|
||||
|
||||
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);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rig_probe_first
|
||||
* called straight by rig_probe
|
||||
|
@ -352,13 +380,16 @@ rig_model_t rig_probe_first(hamlib_port_t *p)
|
|||
int i;
|
||||
rig_model_t model;
|
||||
|
||||
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
|
||||
if (rig_backend_list[i].be_probe_all) {
|
||||
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++)
|
||||
{
|
||||
if (rig_backend_list[i].be_probe_all)
|
||||
{
|
||||
model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe,
|
||||
(rig_ptr_t)NULL);
|
||||
|
||||
/* stop at first one found */
|
||||
if (model != RIG_MODEL_NONE) {
|
||||
if (model != RIG_MODEL_NONE)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
@ -367,17 +398,21 @@ rig_model_t rig_probe_first(hamlib_port_t *p)
|
|||
return RIG_MODEL_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rig_probe_all_backends
|
||||
* called straight by rig_probe_all
|
||||
*/
|
||||
int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc,
|
||||
int rig_probe_all_backends(hamlib_port_t *p,
|
||||
rig_probe_func_t cfunc,
|
||||
rig_ptr_t data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
|
||||
if (rig_backend_list[i].be_probe_all) {
|
||||
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++)
|
||||
{
|
||||
if (rig_backend_list[i].be_probe_all)
|
||||
{
|
||||
(*rig_backend_list[i].be_probe_all)(p, cfunc, data);
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +425,8 @@ int rig_load_all_backends()
|
|||
{
|
||||
int i;
|
||||
|
||||
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++)
|
||||
{
|
||||
rig_load_backend(rig_backend_list[i].be_name);
|
||||
}
|
||||
|
||||
|
@ -400,6 +436,7 @@ int rig_load_all_backends()
|
|||
|
||||
typedef int (*backend_init_t)(rig_ptr_t);
|
||||
|
||||
|
||||
/*
|
||||
* rig_load_backend
|
||||
*/
|
||||
|
@ -408,13 +445,18 @@ int HAMLIB_API rig_load_backend(const char *be_name)
|
|||
int i;
|
||||
backend_init_t be_init;
|
||||
|
||||
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
|
||||
if (!strcmp(be_name, rig_backend_list[i].be_name)) {
|
||||
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++)
|
||||
{
|
||||
if (!strcmp(be_name, rig_backend_list[i].be_name))
|
||||
{
|
||||
be_init = rig_backend_list[i].be_init_all ;
|
||||
|
||||
if (be_init) {
|
||||
if (be_init)
|
||||
{
|
||||
return (*be_init)(NULL);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
187
src/rot_conf.c
187
src/rot_conf.c
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -48,7 +48,8 @@
|
|||
/*
|
||||
* 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",
|
||||
"Path name to the device file of the rotator",
|
||||
|
@ -98,7 +99,8 @@ static const struct confparams rotfrontend_cfg_params[] = {
|
|||
};
|
||||
|
||||
|
||||
static const struct confparams rotfrontend_serial_cfg_params[] = {
|
||||
static const struct confparams rotfrontend_serial_cfg_params[] =
|
||||
{
|
||||
{
|
||||
TOK_SERIAL_SPEED, "serial_speed", "Serial speed",
|
||||
"Serial port baud rate",
|
||||
|
@ -147,13 +149,15 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
switch (token) {
|
||||
switch (token)
|
||||
{
|
||||
case TOK_PATHNAME:
|
||||
strncpy(rs->rotport.pathname, val, FILPATHLEN - 1);
|
||||
break;
|
||||
|
||||
case TOK_WRITE_DELAY:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -161,7 +165,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_POST_WRITE_DELAY:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -169,7 +174,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_TIMEOUT:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -177,7 +183,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_RETRY:
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -185,11 +192,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_SERIAL_SPEED:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -197,11 +206,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_DATA_BITS:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -209,11 +220,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_STOP_BITS:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (1 != sscanf(val, "%d", &val_i)) {
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -221,38 +234,58 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
break;
|
||||
|
||||
case TOK_PARITY:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(val, "None")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Even")) {
|
||||
}
|
||||
else if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Space")) {
|
||||
}
|
||||
else if (!strcmp(val, "Space"))
|
||||
{
|
||||
rs->rotport.parm.serial.parity = RIG_PARITY_SPACE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TOK_HANDSHAKE:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(val, "None")) {
|
||||
if (!strcmp(val, "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;
|
||||
} else if (!strcmp(val, "Hardware")) {
|
||||
}
|
||||
else if (!strcmp(val, "Hardware"))
|
||||
{
|
||||
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -298,7 +331,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
switch (token) {
|
||||
switch (token)
|
||||
{
|
||||
case TOK_PATHNAME:
|
||||
strcpy(val, rs->rotport.pathname);
|
||||
break;
|
||||
|
@ -320,7 +354,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_SERIAL_SPEED:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -328,7 +363,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_DATA_BITS:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -336,7 +372,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_STOP_BITS:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -344,11 +381,13 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_PARITY:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
switch (rs->rotport.parm.serial.parity) {
|
||||
switch (rs->rotport.parm.serial.parity)
|
||||
{
|
||||
case RIG_PARITY_NONE:
|
||||
s = "None";
|
||||
break;
|
||||
|
@ -377,11 +416,13 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
break;
|
||||
|
||||
case TOK_HANDSHAKE:
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL) {
|
||||
if (rs->rotport.type.rig != RIG_PORT_SERIAL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
switch (rs->rotport.parm.serial.handshake) {
|
||||
switch (rs->rotport.parm.serial.handshake)
|
||||
{
|
||||
case RIG_HANDSHAKE_NONE:
|
||||
s = "None";
|
||||
break;
|
||||
|
@ -434,33 +475,42 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
|
|||
* 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),
|
||||
int (*cfunc)(const struct confparams *,
|
||||
rig_ptr_t),
|
||||
rig_ptr_t data)
|
||||
{
|
||||
const struct confparams *cfp;
|
||||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps || !cfunc) {
|
||||
if (!rot || !rot->caps || !cfunc)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) {
|
||||
if ((*cfunc)(cfp, data) == 0) {
|
||||
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) {
|
||||
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) {
|
||||
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++)
|
||||
{
|
||||
if ((*cfunc)(cfp, data) == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
}
|
||||
|
@ -486,28 +536,36 @@ const struct confparams * HAMLIB_API rot_confparam_lookup(ROT *rot,
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps) {
|
||||
if (!rot || !rot->caps)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 0 returned for invalid format */
|
||||
token = strtol(name, NULL, 0);
|
||||
|
||||
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) {
|
||||
if (!strcmp(cfp->name, name) || token == cfp->token) {
|
||||
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++)
|
||||
{
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -531,7 +589,8 @@ token_t HAMLIB_API rot_token_lookup(ROT *rot, const char *name)
|
|||
|
||||
cfp = rot_confparam_lookup(rot, name);
|
||||
|
||||
if (!cfp) {
|
||||
if (!cfp)
|
||||
{
|
||||
return RIG_CONF_END;
|
||||
}
|
||||
|
||||
|
@ -557,28 +616,33 @@ int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val)
|
|||
{
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps) {
|
||||
if (!rot || !rot->caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig_need_debug(RIG_DEBUG_VERBOSE)) {
|
||||
if (rig_need_debug(RIG_DEBUG_VERBOSE))
|
||||
{
|
||||
const struct confparams *cfp;
|
||||
char tokenstr[12];
|
||||
sprintf(tokenstr, "%ld", token);
|
||||
cfp = rot_confparam_lookup(rot, tokenstr);
|
||||
|
||||
if (!cfp) {
|
||||
if (!cfp)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val);
|
||||
}
|
||||
|
||||
if (IS_TOKEN_FRONTEND(token)) {
|
||||
if (IS_TOKEN_FRONTEND(token))
|
||||
{
|
||||
return frontrot_set_conf(rot, token, val);
|
||||
}
|
||||
|
||||
if (rot->caps->set_conf == NULL) {
|
||||
if (rot->caps->set_conf == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -604,15 +668,18 @@ int HAMLIB_API rot_get_conf(ROT *rot, token_t token, char *val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps || !val) {
|
||||
if (!rot || !rot->caps || !val)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (IS_TOKEN_FRONTEND(token)) {
|
||||
if (IS_TOKEN_FRONTEND(token))
|
||||
{
|
||||
return frontrot_get_conf(rot, token, val);
|
||||
}
|
||||
|
||||
if (rot->caps->get_conf == NULL) {
|
||||
if (rot->caps->get_conf == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -83,21 +83,24 @@ DEFINE_INITROT_BACKEND(cnctrk);
|
|||
DEFINE_INITROT_BACKEND(prosistel);
|
||||
|
||||
|
||||
/*! \def ROT_BACKEND_LIST
|
||||
/**
|
||||
* \def ROT_BACKEND_LIST
|
||||
* \brief Static list of rotator models.
|
||||
*
|
||||
* This is a NULL terminated list of available rotator backends. Each entry
|
||||
* in the list consists of two fields: The branch number, which is an integer,
|
||||
* and the branch name, which is a character string.
|
||||
* An external library, loaded dynamically, could add its own functions pointers
|
||||
* in this array.
|
||||
* An external library, loaded dynamically, could add its own functions
|
||||
* pointers in this array.
|
||||
*/
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
int be_num;
|
||||
const char *be_name;
|
||||
int (*be_init)(void *);
|
||||
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_EASYCOMM, ROT_BACKEND_EASYCOMM, ROT_FUNCNAMA(easycomm) },
|
||||
{ ROT_FODTRACK, ROT_BACKEND_FODTRACK, ROT_FUNCNAMA(fodtrack) },
|
||||
|
@ -131,7 +134,8 @@ static struct {
|
|||
* This struct to keep track of known rot models.
|
||||
* It is chained, and used in a hash table, see below.
|
||||
*/
|
||||
struct rot_list {
|
||||
struct rot_list
|
||||
{
|
||||
const struct rot_caps *caps;
|
||||
struct rot_list *next;
|
||||
};
|
||||
|
@ -159,7 +163,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
|
|||
int hval;
|
||||
struct rot_list *p;
|
||||
|
||||
if (!caps) {
|
||||
if (!caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -167,7 +172,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
|
|||
|
||||
#ifndef DONT_WANT_DUP_CHECK
|
||||
|
||||
if (rot_get_caps(caps->rot_model) != NULL) {
|
||||
if (rot_get_caps(caps->rot_model) != NULL)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -175,7 +181,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
|
|||
|
||||
p = (struct rot_list *)malloc(sizeof(struct rot_list));
|
||||
|
||||
if (!p) {
|
||||
if (!p)
|
||||
{
|
||||
return -RIG_ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -193,12 +200,14 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
|
|||
* Get rot capabilities.
|
||||
* 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;
|
||||
|
||||
for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next) {
|
||||
if (p->caps->rot_model == rot_model) {
|
||||
for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next)
|
||||
{
|
||||
if (p->caps->rot_model == rot_model)
|
||||
{
|
||||
return p->caps;
|
||||
}
|
||||
}
|
||||
|
@ -216,9 +225,11 @@ static int rot_lookup_backend(rot_model_t rot_model)
|
|||
{
|
||||
int i;
|
||||
|
||||
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) ==
|
||||
rot_backend_list[i].be_num) {
|
||||
rot_backend_list[i].be_num)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -242,7 +253,8 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
|
|||
/* already loaded ? */
|
||||
caps = rot_get_caps(rot_model);
|
||||
|
||||
if (caps) {
|
||||
if (caps)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
@ -251,11 +263,13 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
|
|||
/*
|
||||
* Never heard about this backend family!
|
||||
*/
|
||||
if (be_idx == -1) {
|
||||
if (be_idx == -1)
|
||||
{
|
||||
rot_debug(RIG_DEBUG_VERBOSE,
|
||||
"%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;
|
||||
}
|
||||
|
@ -274,11 +288,16 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model)
|
|||
hval = HASH_FUNC(rot_model);
|
||||
q = NULL;
|
||||
|
||||
for (p = rot_hash_table[hval]; p; p = p->next) {
|
||||
if (p->caps->rot_model == rot_model) {
|
||||
if (q == NULL) {
|
||||
for (p = rot_hash_table[hval]; p; p = p->next)
|
||||
{
|
||||
if (p->caps->rot_model == rot_model)
|
||||
{
|
||||
if (q == NULL)
|
||||
{
|
||||
rot_hash_table[hval] = p->next;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
q->next = p->next;
|
||||
}
|
||||
|
||||
|
@ -297,19 +316,23 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model)
|
|||
* rot_list_foreach
|
||||
* 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),
|
||||
int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps *,
|
||||
rig_ptr_t),
|
||||
rig_ptr_t data)
|
||||
{
|
||||
struct rot_list *p;
|
||||
int i;
|
||||
|
||||
if (!cfunc) {
|
||||
if (!cfunc)
|
||||
{
|
||||
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)
|
||||
if ((*cfunc)(p->caps, data) == 0) {
|
||||
if ((*cfunc)(p->caps, data) == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
}
|
||||
|
@ -327,11 +350,14 @@ rot_model_t HAMLIB_API rot_probe_all(hamlib_port_t *p)
|
|||
int i;
|
||||
rot_model_t rot_model;
|
||||
|
||||
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) {
|
||||
if (rot_backend_list[i].be_probe) {
|
||||
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++)
|
||||
{
|
||||
if (rot_backend_list[i].be_probe)
|
||||
{
|
||||
rot_model = (*rot_backend_list[i].be_probe)(p);
|
||||
|
||||
if (rot_model != ROT_MODEL_NONE) {
|
||||
if (rot_model != ROT_MODEL_NONE)
|
||||
{
|
||||
return rot_model;
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +371,8 @@ int rot_load_all_backends()
|
|||
{
|
||||
int i;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -363,11 +390,14 @@ int HAMLIB_API rot_load_backend(const char *be_name)
|
|||
int (*be_init)(rig_ptr_t);
|
||||
int 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)) {
|
||||
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++)
|
||||
{
|
||||
if (!strcmp(be_name, rot_backend_list[i].be_name))
|
||||
{
|
||||
be_init = rot_backend_list[i].be_init;
|
||||
|
||||
if (be_init == NULL) {
|
||||
if (be_init == NULL)
|
||||
{
|
||||
printf("Null\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
187
src/rotator.c
187
src/rotator.c
|
@ -35,14 +35,15 @@
|
|||
*/
|
||||
|
||||
|
||||
/*! \page rot Rotator interface
|
||||
/**
|
||||
* \page rot Rotator interface
|
||||
*
|
||||
* Rotator can be any kind of azimuth or azimuth and elevation controlled
|
||||
* antenna system.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -53,7 +54,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
#include <hamlib/rotator.h>
|
||||
#include "serial.h"
|
||||
#include "parallel.h"
|
||||
|
@ -66,21 +66,21 @@
|
|||
#ifndef DOC_HIDDEN
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
#define DEFAULT_SERIAL_PORT "\\\\.\\COM1"
|
||||
# define DEFAULT_SERIAL_PORT "\\\\.\\COM1"
|
||||
#elif BSD
|
||||
#define DEFAULT_SERIAL_PORT "/dev/cuaa0"
|
||||
# define DEFAULT_SERIAL_PORT "/dev/cuaa0"
|
||||
#elif MACOSX
|
||||
#define DEFAULT_SERIAL_PORT "/dev/cu.usbserial"
|
||||
# define DEFAULT_SERIAL_PORT "/dev/cu.usbserial"
|
||||
#else
|
||||
#define DEFAULT_SERIAL_PORT "/dev/ttyS0"
|
||||
# define DEFAULT_SERIAL_PORT "/dev/ttyS0"
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#define DEFAULT_PARALLEL_PORT "\\\\.\\$VDMLPT1"
|
||||
# define DEFAULT_PARALLEL_PORT "\\\\.\\$VDMLPT1"
|
||||
#elif defined(HAVE_DEV_PPBUS_PPI_H)
|
||||
#define DEFAULT_PARALLEL_PORT "/dev/ppi0"
|
||||
# define DEFAULT_PARALLEL_PORT "/dev/ppi0"
|
||||
#else
|
||||
#define DEFAULT_PARALLEL_PORT "/dev/parport0"
|
||||
# define DEFAULT_PARALLEL_PORT "/dev/parport0"
|
||||
#endif
|
||||
|
||||
#define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
|
||||
|
@ -89,7 +89,8 @@
|
|||
/*
|
||||
* Data structure to track the opened rot (by rot_open)
|
||||
*/
|
||||
struct opened_rot_l {
|
||||
struct opened_rot_l
|
||||
{
|
||||
ROT *rot;
|
||||
struct opened_rot_l *next;
|
||||
};
|
||||
|
@ -105,7 +106,8 @@ static int add_opened_rot(ROT *rot)
|
|||
struct opened_rot_l *p;
|
||||
p = (struct opened_rot_l *)malloc(sizeof(struct opened_rot_l));
|
||||
|
||||
if (!p) {
|
||||
if (!p)
|
||||
{
|
||||
return -RIG_ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -121,11 +123,16 @@ static int remove_opened_rot(ROT *rot)
|
|||
struct opened_rot_l *p, *q;
|
||||
q = NULL;
|
||||
|
||||
for (p = opened_rot_list; p; p = p->next) {
|
||||
if (p->rot == rot) {
|
||||
if (q == NULL) {
|
||||
for (p = opened_rot_list; p; p = p->next)
|
||||
{
|
||||
if (p->rot == rot)
|
||||
{
|
||||
if (q == NULL)
|
||||
{
|
||||
opened_rot_list = opened_rot_list->next;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
q->next = p->next;
|
||||
}
|
||||
|
||||
|
@ -146,15 +153,13 @@ static int remove_opened_rot(ROT *rot)
|
|||
* \param cfunc The function to be executed on each rot
|
||||
* \param data Data pointer to be passed to cfunc()
|
||||
*
|
||||
* Calls cfunc() function for each opened rot.
|
||||
* The contents of the opened rot table
|
||||
* is processed in random order according to a function
|
||||
* pointed to by \a cfunc, whic is called with two arguments,
|
||||
* the first pointing to the #ROT handle, the second
|
||||
* to a data pointer \a data.
|
||||
* If \a data is not needed, then it can be set to NULL.
|
||||
* The processing of the opened rot table is stopped
|
||||
* when cfunc() returns 0.
|
||||
* Calls cfunc() function for each opened rot. The contents of the opened
|
||||
* rot table is processed in random order according to a function pointed to
|
||||
* by \a cfunc, whic is called with two arguments, the first pointing to the
|
||||
* #ROT handle, the second to a data pointer \a data.
|
||||
*
|
||||
* If \a data is not needed, then it can be set to NULL. The processing of
|
||||
* the opened rot table is stopped when cfunc() returns 0.
|
||||
* \internal
|
||||
*
|
||||
* \return always RIG_OK.
|
||||
|
@ -165,8 +170,10 @@ int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
for (p = opened_rot_list; p; p = p->next) {
|
||||
if ((*cfunc)(p->rot, data) == 0) {
|
||||
for (p = opened_rot_list; p; p = p->next)
|
||||
{
|
||||
if ((*cfunc)(p->rot, data) == 0)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +194,7 @@ int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data)
|
|||
*
|
||||
* \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;
|
||||
const struct rot_caps *caps;
|
||||
|
@ -200,7 +207,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
|
|||
|
||||
caps = rot_get_caps(rot_model);
|
||||
|
||||
if (!caps) {
|
||||
if (!caps)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -210,7 +218,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
|
|||
*/
|
||||
rot = calloc(1, sizeof(ROT));
|
||||
|
||||
if (rot == NULL) {
|
||||
if (rot == NULL)
|
||||
{
|
||||
/*
|
||||
* FIXME: how can the caller know it's a memory shortage,
|
||||
* and not "rot not found" ?
|
||||
|
@ -236,7 +245,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
|
|||
rs->rotport.timeout = caps->timeout;
|
||||
rs->rotport.retry = caps->retry;
|
||||
|
||||
switch (caps->port_type) {
|
||||
switch (caps->port_type)
|
||||
{
|
||||
case RIG_PORT_SERIAL:
|
||||
strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1);
|
||||
rs->rotport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
|
||||
|
@ -271,10 +281,12 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
|
|||
* This must be done only once defaults are setup,
|
||||
* so the backend init can override rot_state.
|
||||
*/
|
||||
if (caps->rot_init != NULL) {
|
||||
if (caps->rot_init != NULL)
|
||||
{
|
||||
retcode = caps->rot_init(rot);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
rot_debug(RIG_DEBUG_VERBOSE,
|
||||
"%s: backend_init failed!\n",
|
||||
__func__);
|
||||
|
@ -312,24 +324,28 @@ int HAMLIB_API rot_open(ROT *rot)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps) {
|
||||
if (!rot || !rot->caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
rs = &rot->state;
|
||||
|
||||
if (rs->comm_state) {
|
||||
if (rs->comm_state)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
rs->rotport.fd = -1;
|
||||
|
||||
switch (rs->rotport.type.rig) {
|
||||
switch (rs->rotport.type.rig)
|
||||
{
|
||||
case RIG_PORT_SERIAL:
|
||||
status = serial_open(&rs->rotport);
|
||||
|
||||
if (status != 0) {
|
||||
if (status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -338,7 +354,8 @@ int HAMLIB_API rot_open(ROT *rot)
|
|||
case RIG_PORT_PARALLEL:
|
||||
status = par_open(&rs->rotport);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -347,7 +364,8 @@ int HAMLIB_API rot_open(ROT *rot)
|
|||
case RIG_PORT_DEVICE:
|
||||
status = open(rs->rotport.pathname, O_RDWR, 0);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
|
@ -357,7 +375,8 @@ int HAMLIB_API rot_open(ROT *rot)
|
|||
case RIG_PORT_USB:
|
||||
status = usb_port_open(&rs->rotport);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -372,7 +391,8 @@ int HAMLIB_API rot_open(ROT *rot)
|
|||
/* FIXME: default port */
|
||||
status = network_open(&rs->rotport, 4533);
|
||||
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -391,10 +411,12 @@ int HAMLIB_API rot_open(ROT *rot)
|
|||
* Maybe the backend has something to initialize
|
||||
* In case of failure, just close down and report error code.
|
||||
*/
|
||||
if (caps->rot_open != NULL) {
|
||||
if (caps->rot_open != NULL)
|
||||
{
|
||||
status = caps->rot_open(rot);
|
||||
|
||||
if (status != RIG_OK) {
|
||||
if (status != RIG_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
@ -423,14 +445,16 @@ int HAMLIB_API rot_close(ROT *rot)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps) {
|
||||
if (!rot || !rot->caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
rs = &rot->state;
|
||||
|
||||
if (!rs->comm_state) {
|
||||
if (!rs->comm_state)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -438,13 +462,16 @@ int HAMLIB_API rot_close(ROT *rot)
|
|||
* Let the backend say 73s to the rot.
|
||||
* and ignore the return code.
|
||||
*/
|
||||
if (caps->rot_close) {
|
||||
if (caps->rot_close)
|
||||
{
|
||||
caps->rot_close(rot);
|
||||
}
|
||||
|
||||
|
||||
if (rs->rotport.fd != -1) {
|
||||
switch (rs->rotport.type.rig) {
|
||||
if (rs->rotport.fd != -1)
|
||||
{
|
||||
switch (rs->rotport.type.rig)
|
||||
{
|
||||
case RIG_PORT_SERIAL:
|
||||
ser_close(&rs->rotport);
|
||||
break;
|
||||
|
@ -494,21 +521,24 @@ int HAMLIB_API rot_cleanup(ROT *rot)
|
|||
{
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rot || !rot->caps) {
|
||||
if (!rot || !rot->caps)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* check if they forgot to close the rot
|
||||
*/
|
||||
if (rot->state.comm_state) {
|
||||
if (rot->state.comm_state)
|
||||
{
|
||||
rot_close(rot);
|
||||
}
|
||||
|
||||
/*
|
||||
* basically free up the priv struct
|
||||
*/
|
||||
if (rot->caps->rot_cleanup) {
|
||||
if (rot->caps->rot_cleanup)
|
||||
{
|
||||
rot->caps->rot_cleanup(rot);
|
||||
}
|
||||
|
||||
|
@ -532,7 +562,8 @@ int HAMLIB_API rot_cleanup(ROT *rot)
|
|||
*
|
||||
* \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)
|
||||
{
|
||||
const struct rot_caps *caps;
|
||||
|
@ -540,7 +571,8 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot)) {
|
||||
if (CHECK_ROT_ARG(rot))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -550,11 +582,13 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
|
|||
if (azimuth < rs->min_az
|
||||
|| azimuth > rs->max_az
|
||||
|| elevation < rs->min_el
|
||||
|| elevation > rs->max_el) {
|
||||
return -RIG_EINVAL;
|
||||
|| elevation > rs->max_el)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (caps->set_position == NULL) {
|
||||
if (caps->set_position == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -576,20 +610,23 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
|
|||
*
|
||||
* \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)
|
||||
{
|
||||
const struct rot_caps *caps;
|
||||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot) || !azimuth || !elevation) {
|
||||
if (CHECK_ROT_ARG(rot) || !azimuth || !elevation)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
|
||||
if (caps->get_position == NULL) {
|
||||
if (caps->get_position == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -614,13 +651,15 @@ int HAMLIB_API rot_park(ROT *rot)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot)) {
|
||||
if (CHECK_ROT_ARG(rot))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
|
||||
if (caps->park == NULL) {
|
||||
if (caps->park == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -645,13 +684,15 @@ int HAMLIB_API rot_stop(ROT *rot)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot)) {
|
||||
if (CHECK_ROT_ARG(rot))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
|
||||
if (caps->stop == NULL) {
|
||||
if (caps->stop == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -677,13 +718,15 @@ int HAMLIB_API rot_reset(ROT *rot, rot_reset_t reset)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot)) {
|
||||
if (CHECK_ROT_ARG(rot))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
|
||||
if (caps->reset == NULL) {
|
||||
if (caps->reset == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -706,13 +749,15 @@ int HAMLIB_API rot_move(ROT *rot, int direction, int speed)
|
|||
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot)) {
|
||||
if (CHECK_ROT_ARG(rot))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rot->caps;
|
||||
|
||||
if (caps->move == NULL) {
|
||||
if (caps->move == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -731,15 +776,17 @@ int HAMLIB_API rot_move(ROT *rot, int direction, int speed)
|
|||
* if the operation has been sucessful, otherwise NULL if an error occured
|
||||
* or get_info not part of capabilities.
|
||||
*/
|
||||
const char *HAMLIB_API rot_get_info(ROT *rot)
|
||||
const char * HAMLIB_API rot_get_info(ROT *rot)
|
||||
{
|
||||
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_ROT_ARG(rot)) {
|
||||
if (CHECK_ROT_ARG(rot))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rot->caps->get_info == NULL) {
|
||||
if (rot->caps->get_info == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
126
src/serial.c
126
src/serial.c
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -45,33 +45,34 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h> /* POSIX terminal control definitions */
|
||||
# include <termios.h> /* POSIX terminal control definitions */
|
||||
#else
|
||||
#ifdef HAVE_TERMIO_H
|
||||
#include <termio.h>
|
||||
#else /* sgtty */
|
||||
#ifdef HAVE_SGTTY_H
|
||||
#include <sgtty.h>
|
||||
#endif
|
||||
#endif
|
||||
# ifdef HAVE_TERMIO_H
|
||||
# include <termio.h>
|
||||
# else /* sgtty */
|
||||
# ifdef HAVE_SGTTY_H
|
||||
# include <sgtty.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(HAVE_TERMIOS_H)
|
||||
#include "win32termios.h"
|
||||
#define HAVE_TERMIOS_H 1 /* we have replacement */
|
||||
# include "win32termios.h"
|
||||
# define HAVE_TERMIOS_H 1 /* we have replacement */
|
||||
#else
|
||||
#define OPEN open
|
||||
#define CLOSE close
|
||||
#define IOCTL ioctl
|
||||
# define OPEN open
|
||||
# define CLOSE close
|
||||
# define IOCTL ioctl
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -79,7 +80,7 @@
|
|||
#include "misc.h"
|
||||
|
||||
#ifdef HAVE_SYS_IOCCOM_H
|
||||
#include <sys/ioccom.h>
|
||||
# include <sys/ioccom.h>
|
||||
#endif
|
||||
|
||||
#include "microham.h"
|
||||
|
@ -87,21 +88,27 @@
|
|||
static int uh_ptt_fd = -1;
|
||||
static int uh_radio_fd = -1;
|
||||
|
||||
int is_uh_radio_fd(int fd) {
|
||||
/*
|
||||
* This function simply returns TRUE if the argument
|
||||
* matches uh_radio_fd and is >= 0
|
||||
*
|
||||
* This function is only used in the WIN32 case and implements
|
||||
* access "from outside" to uh_radio_fd.
|
||||
*/
|
||||
if (uh_radio_fd >= 0 && uh_radio_fd == fd) {
|
||||
|
||||
/*
|
||||
* This function simply returns TRUE if the argument matches uh_radio_fd and
|
||||
* is >= 0
|
||||
*
|
||||
* This function is only used in the WIN32 case and implements access "from
|
||||
* outside" to uh_radio_fd.
|
||||
*/
|
||||
int is_uh_radio_fd(int fd)
|
||||
{
|
||||
if (uh_radio_fd >= 0 && uh_radio_fd == fd)
|
||||
{
|
||||
return 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Open serial port using rig.state data
|
||||
* \param rp port data structure (must spec port id eg /dev/ttyS1)
|
||||
|
@ -115,7 +122,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rp) {
|
||||
if (!rp)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -166,7 +174,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp)
|
|||
*/
|
||||
fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
/* Could not open the port. */
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: Unable to open %s - %s\n",
|
||||
|
@ -180,7 +189,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp)
|
|||
|
||||
err = serial_setup(rp);
|
||||
|
||||
if (err != RIG_OK) {
|
||||
if (err != RIG_OK)
|
||||
{
|
||||
CLOSE(fd);
|
||||
return err;
|
||||
}
|
||||
|
@ -206,12 +216,13 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
#elif defined(HAVE_SGTTY_H)
|
||||
struct sgttyb sg;
|
||||
#else
|
||||
#error "No term control supported!"
|
||||
# error "No term control supported!"
|
||||
#endif
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rp) {
|
||||
if (!rp)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -236,7 +247,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
/*
|
||||
* Set the baud rates to requested values
|
||||
*/
|
||||
switch (rp->parm.serial.rate) {
|
||||
switch (rp->parm.serial.rate)
|
||||
{
|
||||
case 150:
|
||||
speed = B150; /* yikes... */
|
||||
break;
|
||||
|
@ -309,7 +321,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
* Set data to requested values.
|
||||
*
|
||||
*/
|
||||
switch (rp->parm.serial.data_bits) {
|
||||
switch (rp->parm.serial.data_bits)
|
||||
{
|
||||
case 7:
|
||||
options.c_cflag &= ~CSIZE;
|
||||
options.c_cflag |= CS7;
|
||||
|
@ -335,7 +348,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
* Set stop bits to requested values.
|
||||
*
|
||||
*/
|
||||
switch (rp->parm.serial.stop_bits) {
|
||||
switch (rp->parm.serial.stop_bits)
|
||||
{
|
||||
case 1:
|
||||
options.c_cflag &= ~CSTOPB;
|
||||
break;
|
||||
|
@ -359,7 +373,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
* Set parity to requested values.
|
||||
*
|
||||
*/
|
||||
switch (rp->parm.serial.parity) {
|
||||
switch (rp->parm.serial.parity)
|
||||
{
|
||||
case RIG_PARITY_NONE:
|
||||
options.c_cflag &= ~PARENB;
|
||||
break;
|
||||
|
@ -403,7 +418,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
* Set flow control to requested mode
|
||||
*
|
||||
*/
|
||||
switch (rp->parm.serial.handshake) {
|
||||
switch (rp->parm.serial.handshake)
|
||||
{
|
||||
case RIG_HANDSHAKE_NONE:
|
||||
options.c_cflag &= ~CRTSCTS;
|
||||
options.c_iflag &= ~IXON;
|
||||
|
@ -461,7 +477,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
*/
|
||||
#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",
|
||||
__func__,
|
||||
|
@ -473,7 +490,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
|
||||
#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",
|
||||
__func__,
|
||||
|
@ -484,8 +502,10 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
}
|
||||
|
||||
#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",
|
||||
__func__,
|
||||
|
@ -629,10 +649,14 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state)
|
|||
#else
|
||||
rc = IOCTL(p->fd, TIOCMGET, &y);
|
||||
|
||||
if (rc >= 0) {
|
||||
if (state) {
|
||||
if (rc >= 0)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
y |= TIOCM_RTS;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
y &= ~TIOCM_RTS;
|
||||
}
|
||||
|
||||
|
@ -641,7 +665,8 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state)
|
|||
|
||||
#endif
|
||||
|
||||
if (rc < 0) {
|
||||
if (rc < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: Cannot change RTS - %s\n",
|
||||
__func__,
|
||||
|
@ -707,10 +732,14 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state)
|
|||
#else
|
||||
rc = IOCTL(p->fd, TIOCMGET, &y);
|
||||
|
||||
if (rc >= 0) {
|
||||
if (state) {
|
||||
if (rc >= 0)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
y |= TIOCM_DTR;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
y &= ~TIOCM_DTR;
|
||||
}
|
||||
|
||||
|
@ -719,7 +748,8 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state)
|
|||
|
||||
#endif
|
||||
|
||||
if (rc < 0) {
|
||||
if (rc < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: Cannot change DTR - %s\n",
|
||||
__func__,
|
||||
|
|
181
src/settings.c
181
src/settings.c
|
@ -34,7 +34,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -51,7 +51,7 @@
|
|||
|
||||
#ifndef DOC_HIDDEN
|
||||
|
||||
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
|
||||
# define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
|
||||
|
||||
#endif /* !DOC_HIDDEN */
|
||||
|
||||
|
@ -81,30 +81,35 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
return caps->set_level(rig, vfo, level, val);
|
||||
|| vfo == rig->state.current_vfo)
|
||||
{
|
||||
return caps->set_level(rig, vfo, level, val);
|
||||
}
|
||||
|
||||
if (!caps->set_vfo) {
|
||||
if (!caps->set_vfo)
|
||||
{
|
||||
return -RIG_ENTARGET;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -146,13 +151,15 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !val) {
|
||||
if (CHECK_RIG_ARG(rig) || !val)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -162,36 +169,41 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
|||
if (level == RIG_LEVEL_STRENGTH
|
||||
&& (caps->has_get_level & RIG_LEVEL_STRENGTH) == 0
|
||||
&& 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) {
|
||||
return retcode;
|
||||
}
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal);
|
||||
return RIG_OK;
|
||||
val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal);
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| vfo == rig->state.current_vfo)
|
||||
{
|
||||
|
||||
return caps->get_level(rig, vfo, level, val);
|
||||
return caps->get_level(rig, vfo, level, val);
|
||||
}
|
||||
|
||||
if (!caps->set_vfo) {
|
||||
if (!caps->set_vfo)
|
||||
{
|
||||
return -RIG_ENTARGET;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -221,11 +233,13 @@ int HAMLIB_API rig_set_parm(RIG *rig, setting_t parm, value_t val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig->caps->set_parm == NULL || !rig_has_set_parm(rig, parm)) {
|
||||
if (rig->caps->set_parm == NULL || !rig_has_set_parm(rig, parm))
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -253,11 +267,13 @@ int HAMLIB_API rig_get_parm(RIG *rig, setting_t parm, value_t *val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !val) {
|
||||
if (CHECK_RIG_ARG(rig) || !val)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig->caps->get_parm == NULL || !rig_has_get_parm(rig, parm)) {
|
||||
if (rig->caps->get_parm == NULL || !rig_has_get_parm(rig, parm))
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -285,7 +301,8 @@ setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -313,7 +330,8 @@ setting_t HAMLIB_API rig_has_set_level(RIG *rig, setting_t level)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -341,7 +359,8 @@ setting_t HAMLIB_API rig_has_get_parm(RIG *rig, setting_t parm)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -369,7 +388,8 @@ setting_t HAMLIB_API rig_has_set_parm(RIG *rig, setting_t parm)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -397,7 +417,8 @@ setting_t HAMLIB_API rig_has_get_func(RIG *rig, setting_t func)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -425,7 +446,8 @@ setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (!rig || !rig->caps) {
|
||||
if (!rig || !rig->caps)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -459,36 +481,42 @@ int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
retcode = caps->set_func(rig, vfo, func, status);
|
||||
caps->set_vfo(rig, curr_vfo);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -520,31 +548,36 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !func) {
|
||||
if (CHECK_RIG_ARG(rig) || !func)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -570,7 +603,9 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
|||
*
|
||||
* \sa rig_get_ext_level()
|
||||
*/
|
||||
int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token,
|
||||
int HAMLIB_API rig_set_ext_level(RIG *rig,
|
||||
vfo_t vfo,
|
||||
token_t token,
|
||||
value_t val)
|
||||
{
|
||||
const struct rig_caps *caps;
|
||||
|
@ -579,31 +614,36 @@ int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token,
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->set_ext_level == NULL) {
|
||||
if (caps->set_ext_level == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -629,7 +669,9 @@ int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token,
|
|||
*
|
||||
* \sa rig_set_ext_level()
|
||||
*/
|
||||
int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token,
|
||||
int HAMLIB_API rig_get_ext_level(RIG *rig,
|
||||
vfo_t vfo,
|
||||
token_t token,
|
||||
value_t *val)
|
||||
{
|
||||
const struct rig_caps *caps;
|
||||
|
@ -638,31 +680,36 @@ int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token,
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !val) {
|
||||
if (CHECK_RIG_ARG(rig) || !val)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->get_ext_level == NULL) {
|
||||
if (caps->get_ext_level == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -691,11 +738,13 @@ int HAMLIB_API rig_set_ext_parm(RIG *rig, token_t token, value_t val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig->caps->set_ext_parm == NULL) {
|
||||
if (rig->caps->set_ext_parm == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -721,11 +770,13 @@ int HAMLIB_API rig_get_ext_parm(RIG *rig, token_t token, value_t *val)
|
|||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !val) {
|
||||
if (CHECK_RIG_ARG(rig) || !val)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
if (rig->caps->get_ext_parm == NULL) {
|
||||
if (rig->caps->get_ext_parm == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
|
@ -748,8 +799,10 @@ int HAMLIB_API rig_setting2idx(setting_t s)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++) {
|
||||
if (s & rig_idx2setting(i)) {
|
||||
for (i = 0; i < RIG_SETTING_MAX; i++)
|
||||
{
|
||||
if (s & rig_idx2setting(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
138
src/tones.c
138
src/tones.c
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -105,31 +105,36 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->set_ctcss_tone == NULL) {
|
||||
if (caps->set_ctcss_tone == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -167,31 +172,36 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !tone) {
|
||||
if (CHECK_RIG_ARG(rig) || !tone)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->get_ctcss_tone == NULL) {
|
||||
if (caps->get_ctcss_tone == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -225,31 +235,36 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->set_dcs_code == NULL) {
|
||||
if (caps->set_dcs_code == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -282,31 +297,36 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !code) {
|
||||
if (CHECK_RIG_ARG(rig) || !code)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->get_dcs_code == NULL) {
|
||||
if (caps->get_dcs_code == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -347,31 +367,36 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->set_ctcss_sql == NULL) {
|
||||
if (caps->set_ctcss_sql == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -409,31 +434,36 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !tone) {
|
||||
if (CHECK_RIG_ARG(rig) || !tone)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->get_ctcss_sql == NULL) {
|
||||
if (caps->get_ctcss_sql == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -466,31 +496,36 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig)) {
|
||||
if (CHECK_RIG_ARG(rig))
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->set_dcs_sql == NULL) {
|
||||
if (caps->set_dcs_sql == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
@ -523,31 +558,36 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code)
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||
|
||||
if (CHECK_RIG_ARG(rig) || !code) {
|
||||
if (CHECK_RIG_ARG(rig) || !code)
|
||||
{
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
||||
caps = rig->caps;
|
||||
|
||||
if (caps->get_dcs_sql == NULL) {
|
||||
if (caps->get_dcs_sql == NULL)
|
||||
{
|
||||
return -RIG_ENAVAIL;
|
||||
}
|
||||
|
||||
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|
||||
|| vfo == RIG_VFO_CURR
|
||||
|| vfo == rig->state.current_vfo) {
|
||||
|| 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;
|
||||
}
|
||||
|
||||
curr_vfo = rig->state.current_vfo;
|
||||
retcode = caps->set_vfo(rig, vfo);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
if (retcode != RIG_OK)
|
||||
{
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
|
12
src/tones.h
12
src/tones.h
|
@ -37,7 +37,8 @@
|
|||
2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \
|
||||
0,
|
||||
|
||||
static const tone_t static_full_ctcss_list[] = {
|
||||
static const tone_t static_full_ctcss_list[] =
|
||||
{
|
||||
FULL_CTCSS_LIST
|
||||
};
|
||||
|
||||
|
@ -57,7 +58,8 @@ static const tone_t static_full_ctcss_list[] = {
|
|||
2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \
|
||||
0,
|
||||
|
||||
static const tone_t static_common_ctcss_list[] = {
|
||||
static const tone_t static_common_ctcss_list[] =
|
||||
{
|
||||
COMMON_CTCSS_LIST
|
||||
};
|
||||
|
||||
|
@ -77,7 +79,8 @@ static const tone_t static_common_ctcss_list[] = {
|
|||
662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \
|
||||
0,
|
||||
|
||||
static const tone_t static_common_dcs_list[] = {
|
||||
static const tone_t static_common_dcs_list[] =
|
||||
{
|
||||
COMMON_DCS_LIST
|
||||
};
|
||||
|
||||
|
@ -97,7 +100,8 @@ static const tone_t static_common_dcs_list[] = {
|
|||
662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \
|
||||
0,
|
||||
|
||||
static const tone_t static_full_dcs_list[] = {
|
||||
static const tone_t static_full_dcs_list[] =
|
||||
{
|
||||
FULL_DCS_LIST
|
||||
};
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <hamlib/rig.h>
|
||||
|
@ -52,9 +52,9 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_LIBUSB_H
|
||||
# include <libusb.h>
|
||||
# include <libusb.h>
|
||||
#elif defined HAVE_LIBUSB_1_0_LIBUSB_H
|
||||
# include <libusb-1.0/libusb.h>
|
||||
# include <libusb-1.0/libusb.h>
|
||||
#endif
|
||||
|
||||
#include "usb_port.h"
|
||||
|
@ -65,7 +65,7 @@
|
|||
* \param port
|
||||
* \return usb_handle
|
||||
*/
|
||||
static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
||||
static libusb_device_handle *find_and_open_device(const hamlib_port_t *port)
|
||||
{
|
||||
libusb_device_handle *udh = NULL;
|
||||
libusb_device *dev, **devs;
|
||||
|
@ -83,7 +83,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
|
||||
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",
|
||||
__func__,
|
||||
|
@ -92,7 +93,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; (dev = devs[i]) != NULL; i++) {
|
||||
for (i = 0; (dev = devs[i]) != NULL; i++)
|
||||
{
|
||||
|
||||
libusb_get_device_descriptor(dev, &desc);
|
||||
|
||||
|
@ -102,12 +104,14 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
desc.idProduct);
|
||||
|
||||
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 */
|
||||
r = libusb_open(dev, &udh);
|
||||
|
||||
if (r < 0) {
|
||||
if (r < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_WARN,
|
||||
"%s: Warning: Cannot open USB device: %s\n",
|
||||
__func__,
|
||||
|
@ -117,7 +121,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
}
|
||||
|
||||
/* now check whether the names match: */
|
||||
if (port->parm.usb.vendor_name) {
|
||||
if (port->parm.usb.vendor_name)
|
||||
{
|
||||
|
||||
string[0] = '\0';
|
||||
r = libusb_get_string_descriptor_ascii(udh,
|
||||
|
@ -125,7 +130,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
(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));
|
||||
|
@ -136,7 +142,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
|
||||
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__);
|
||||
|
@ -146,7 +153,8 @@ 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';
|
||||
r = libusb_get_string_descriptor_ascii(udh,
|
||||
|
@ -154,7 +162,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
(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));
|
||||
|
@ -165,7 +174,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
|
||||
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
|
||||
* match. Updating firmware on FUNcube Dongle to v18f resulted
|
||||
|
@ -175,7 +185,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
|
|||
*/
|
||||
if (strncasecmp(string,
|
||||
port->parm.usb.product,
|
||||
sizeof(port->parm.usb.product - 1)) != 0) {
|
||||
sizeof(port->parm.usb.product - 1)) != 0)
|
||||
{
|
||||
|
||||
rig_debug(RIG_DEBUG_WARN,
|
||||
"%s: Warning: Product string mismatch!\n",
|
||||
|
@ -220,7 +231,8 @@ int usb_port_open(hamlib_port_t *port)
|
|||
/* init defaut libusb-1.0 library contexte, if needed */
|
||||
r = libusb_init(NULL);
|
||||
|
||||
if (r < 0) {
|
||||
if (r < 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: libusb_init failed: %s\n",
|
||||
__func__,
|
||||
|
@ -239,25 +251,29 @@ int usb_port_open(hamlib_port_t *port)
|
|||
p = pathname;
|
||||
q = strchr(p, ':');
|
||||
|
||||
if (q) {
|
||||
if (q)
|
||||
{
|
||||
++q;
|
||||
port->parm.usb.vid = strtol(q, NULL, 16);
|
||||
p = q;
|
||||
q = strchr(p, ':');
|
||||
|
||||
if (q) {
|
||||
if (q)
|
||||
{
|
||||
++q;
|
||||
port->parm.usb.pid = strtol(q, NULL, 16);
|
||||
p = q;
|
||||
q = strchr(p, ':');
|
||||
|
||||
if (q) {
|
||||
if (q)
|
||||
{
|
||||
++q;
|
||||
port->parm.usb.vendor_name = q;
|
||||
p = q;
|
||||
q = strchr(p, ':');
|
||||
|
||||
if (q) {
|
||||
if (q)
|
||||
{
|
||||
*q++ = '\0';
|
||||
port->parm.usb.product = q;
|
||||
}
|
||||
|
@ -267,7 +283,8 @@ int usb_port_open(hamlib_port_t *port)
|
|||
|
||||
udh = find_and_open_device(port);
|
||||
|
||||
if (udh == 0) {
|
||||
if (udh == 0)
|
||||
{
|
||||
libusb_exit(NULL);
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
@ -279,24 +296,26 @@ int usb_port_open(hamlib_port_t *port)
|
|||
*/
|
||||
(void)libusb_set_auto_detach_kernel_driver(udh, port->parm.usb.iface);
|
||||
|
||||
if (port->parm.usb.iface >= 0) {
|
||||
if (port->parm.usb.iface >= 0)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Is it still needed with libusb-1.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_exit(NULL);
|
||||
libusb_close(udh);
|
||||
libusb_exit(NULL);
|
||||
|
||||
return -RIG_EIO;
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -308,7 +327,8 @@ int usb_port_open(hamlib_port_t *port)
|
|||
|
||||
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",
|
||||
__func__,
|
||||
|
@ -325,7 +345,8 @@ int usb_port_open(hamlib_port_t *port)
|
|||
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__,
|
||||
|
|
Ładowanie…
Reference in New Issue