Formatted src/ to final coding guidelines

pull/1/head
Nate Bargmann 2017-10-04 21:32:08 -05:00
rodzic ef3620defb
commit ab3e6bb5a5
28 zmienionych plików z 3750 dodań i 1945 usunięć

Wyświetl plik

@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (cal->size == 0) { if (cal->size == 0)
{
return rawval; return rawval;
} }
for (i = 0; i < cal->size; i++) for (i = 0; i < cal->size; i++)
if (rawval < cal->table[i].raw) { {
if (rawval < cal->table[i].raw)
{
break; break;
} }
}
if (i == 0) { if (i == 0)
{
return cal->table[0].val; return cal->table[0].val;
} }
if (i >= cal->size) { if (i >= cal->size)
{
return cal->table[i - 1].val; return cal->table[i - 1].val;
} }
/* catch divide by 0 error */ /* 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; return cal->table[i].val;
} }

Wyświetl plik

@ -42,6 +42,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
@ -54,9 +55,11 @@
# include <windows.h> # include <windows.h>
# include "par_nt.h" # include "par_nt.h"
#endif #endif
#ifdef HAVE_WINIOCTL_H #ifdef HAVE_WINIOCTL_H
# include <winioctl.h> # include <winioctl.h>
#endif #endif
#ifdef HAVE_WINBASE_H #ifdef HAVE_WINBASE_H
# include <winbase.h> # include <winbase.h>
#endif #endif
@ -80,13 +83,15 @@ int cm108_open(hamlib_port_t *port)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!port->pathname[0]) { if (!port->pathname[0])
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) { if (fd < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n", "%s: opening device \"%s\": %s\n",
__func__, __func__,
@ -119,7 +124,9 @@ int cm108_open(hamlib_port_t *port)
rig_debug(RIG_DEBUG_VERBOSE, rig_debug(RIG_DEBUG_VERBOSE,
"%s: cm108 compatible device detected\n", "%s: cm108 compatible device detected\n",
__func__); __func__);
} else { }
else
{
close(fd); close(fd);
rig_debug(RIG_DEBUG_VERBOSE, rig_debug(RIG_DEBUG_VERBOSE,
"%s: no cm108 (or compatible) device detected\n", "%s: no cm108 (or compatible) device detected\n",
@ -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 // pins are accessible. The SSS1623 chips have a different pinout, so
// we make the GPIO bit number configurable. // we make the GPIO bit number configurable.
switch (p->type.ptt) { switch (p->type.ptt)
case RIG_PTT_CM108: { {
case RIG_PTT_CM108:
{
// Build a packet for CM108 HID to turn GPIO bit on or off. // Build a packet for CM108 HID to turn GPIO bit on or off.
// Packet is 4 bytes, preceded by a 'report number' byte // Packet is 4 bytes, preceded by a 'report number' byte
@ -181,7 +190,8 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
p->parm.cm108.ptt_bitnum, p->parm.cm108.ptt_bitnum,
(pttx == RIG_PTT_ON) ? 1 : 0); (pttx == RIG_PTT_ON) ? 1 : 0);
char out_rep[] = { char out_rep[] =
{
0x00, // report number 0x00, // report number
// HID output report // HID output report
0x00, 0x00,
@ -192,14 +202,16 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx)
ssize_t nw; ssize_t nw;
if (p->fd == -1) { if (p->fd == -1)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
// Send the HID packet // Send the HID packet
nw = write(p->fd, out_rep, sizeof(out_rep)); nw = write(p->fd, out_rep, sizeof(out_rep));
if (nw < 0) { if (nw < 0)
{
return -RIG_EIO; return -RIG_EIO;
} }
@ -228,8 +240,10 @@ int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) { switch (p->type.ptt)
case RIG_PTT_CM108: { {
case RIG_PTT_CM108:
{
int status; int status;
return -RIG_ENIMPL; return -RIG_ENIMPL;
return status; return status;
@ -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 // in HID messages from the CM108 device, but I am not sure how
// to query this state on demand. // to query this state on demand.
switch (p->type.dcd) { switch (p->type.dcd)
case RIG_DCD_CM108: { {
case RIG_DCD_CM108:
{
int status; int status;
return -RIG_ENIMPL; return -RIG_ENIMPL;
return status; return status;

Wyświetl plik

@ -47,7 +47,8 @@
/* /*
* Configuration options available in the rig->state struct. * Configuration options available in the rig->state struct.
*/ */
static const struct confparams frontend_cfg_params[] = { static const struct confparams frontend_cfg_params[] =
{
{ {
TOK_PATHNAME, "rig_pathname", "Rig path name", TOK_PATHNAME, "rig_pathname", "Rig path name",
"Path name to the device file of the rig", "Path name to the device file of the rig",
@ -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", TOK_SERIAL_SPEED, "serial_speed", "Serial speed",
"Serial port baud rate", "Serial port baud rate",
@ -172,13 +174,15 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
caps = rig->caps; caps = rig->caps;
rs = &rig->state; rs = &rig->state;
switch (token) { switch (token)
{
case TOK_PATHNAME: case TOK_PATHNAME:
strncpy(rs->rigport.pathname, val, FILPATHLEN - 1); strncpy(rs->rigport.pathname, val, FILPATHLEN - 1);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -186,7 +190,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -194,7 +199,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -202,7 +208,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_RETRY: case TOK_RETRY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -210,11 +217,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -222,11 +231,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -234,11 +245,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -246,83 +259,121 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (!strcmp(val, "None")) { if (!strcmp(val, "None"))
{
rs->rigport.parm.serial.parity = RIG_PARITY_NONE; rs->rigport.parm.serial.parity = RIG_PARITY_NONE;
} else if (!strcmp(val, "Odd")) { }
else if (!strcmp(val, "Odd"))
{
rs->rigport.parm.serial.parity = RIG_PARITY_ODD; rs->rigport.parm.serial.parity = RIG_PARITY_ODD;
} else if (!strcmp(val, "Even")) { }
else if (!strcmp(val, "Even"))
{
rs->rigport.parm.serial.parity = RIG_PARITY_EVEN; rs->rigport.parm.serial.parity = RIG_PARITY_EVEN;
} else if (!strcmp(val, "Mark")) { }
else if (!strcmp(val, "Mark"))
{
rs->rigport.parm.serial.parity = RIG_PARITY_MARK; rs->rigport.parm.serial.parity = RIG_PARITY_MARK;
} else if (!strcmp(val, "Space")) { }
else if (!strcmp(val, "Space"))
{
rs->rigport.parm.serial.parity = RIG_PARITY_SPACE; rs->rigport.parm.serial.parity = RIG_PARITY_SPACE;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (!strcmp(val, "None")) { if (!strcmp(val, "None"))
{
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
} else if (!strcmp(val, "XONXOFF")) { }
else if (!strcmp(val, "XONXOFF"))
{
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF;
} else if (!strcmp(val, "Hardware")) { }
else if (!strcmp(val, "Hardware"))
{
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
break; break;
case TOK_RTS_STATE: case TOK_RTS_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (!strcmp(val, "Unset")) { if (!strcmp(val, "Unset"))
{
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_UNSET; rs->rigport.parm.serial.rts_state = RIG_SIGNAL_UNSET;
} else if (!strcmp(val, "ON")) { }
else if (!strcmp(val, "ON"))
{
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_ON; rs->rigport.parm.serial.rts_state = RIG_SIGNAL_ON;
} else if (!strcmp(val, "OFF")) { }
else if (!strcmp(val, "OFF"))
{
rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF; rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
break; break;
case TOK_DTR_STATE: case TOK_DTR_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (!strcmp(val, "Unset")) { if (!strcmp(val, "Unset"))
{
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_UNSET; rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_UNSET;
} else if (!strcmp(val, "ON")) { }
else if (!strcmp(val, "ON"))
{
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_ON; rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_ON;
} else if (!strcmp(val, "OFF")) { }
else if (!strcmp(val, "OFF"))
{
rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF; rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
break; break;
case TOK_ITU_REGION: case TOK_ITU_REGION:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
switch (val_i) { switch (val_i)
{
case RIG_ITU_REGION1: case RIG_ITU_REGION1:
rs->itu_region = val_i; rs->itu_region = val_i;
memcpy(rs->tx_range_list, caps->tx_range_list1, 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; break;
case TOK_PTT_TYPE: case TOK_PTT_TYPE:
if (!strcmp(val, "RIG")) { if (!strcmp(val, "RIG"))
{
rs->pttport.type.ptt = RIG_PTT_RIG; rs->pttport.type.ptt = RIG_PTT_RIG;
} else if (!strcmp(val, "RIGMICDATA")) { }
else if (!strcmp(val, "RIGMICDATA"))
{
rs->pttport.type.ptt = RIG_PTT_RIG_MICDATA; rs->pttport.type.ptt = RIG_PTT_RIG_MICDATA;
} else if (!strcmp(val, "DTR")) { }
else if (!strcmp(val, "DTR"))
{
rs->pttport.type.ptt = RIG_PTT_SERIAL_DTR; rs->pttport.type.ptt = RIG_PTT_SERIAL_DTR;
} else if (!strcmp(val, "RTS")) { }
else if (!strcmp(val, "RTS"))
{
rs->pttport.type.ptt = RIG_PTT_SERIAL_RTS; rs->pttport.type.ptt = RIG_PTT_SERIAL_RTS;
} else if (!strcmp(val, "Parallel")) { }
else if (!strcmp(val, "Parallel"))
{
rs->pttport.type.ptt = RIG_PTT_PARALLEL; rs->pttport.type.ptt = RIG_PTT_PARALLEL;
} else if (!strcmp(val, "CM108")) { }
else if (!strcmp(val, "CM108"))
{
rs->pttport.type.ptt = RIG_PTT_CM108; rs->pttport.type.ptt = RIG_PTT_CM108;
} else if (!strcmp(val, "None")) { }
else if (!strcmp(val, "None"))
{
rs->pttport.type.ptt = RIG_PTT_NONE; rs->pttport.type.ptt = RIG_PTT_NONE;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -372,7 +438,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_PTT_BITNUM: case TOK_PTT_BITNUM:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL;//value format error return -RIG_EINVAL;//value format error
} }
@ -380,21 +447,36 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_DCD_TYPE: case TOK_DCD_TYPE:
if (!strcmp(val, "RIG")) { if (!strcmp(val, "RIG"))
{
rs->dcdport.type.dcd = RIG_DCD_RIG; rs->dcdport.type.dcd = RIG_DCD_RIG;
} else if (!strcmp(val, "DSR")) { }
else if (!strcmp(val, "DSR"))
{
rs->dcdport.type.dcd = RIG_DCD_SERIAL_DSR; rs->dcdport.type.dcd = RIG_DCD_SERIAL_DSR;
} else if (!strcmp(val, "CTS")) { }
else if (!strcmp(val, "CTS"))
{
rs->dcdport.type.dcd = RIG_DCD_SERIAL_CTS; rs->dcdport.type.dcd = RIG_DCD_SERIAL_CTS;
} else if (!strcmp(val, "CD")) { }
else if (!strcmp(val, "CD"))
{
rs->dcdport.type.dcd = RIG_DCD_SERIAL_CAR; rs->dcdport.type.dcd = RIG_DCD_SERIAL_CAR;
} else if (!strcmp(val, "Parallel")) { }
else if (!strcmp(val, "Parallel"))
{
rs->dcdport.type.dcd = RIG_DCD_PARALLEL; rs->dcdport.type.dcd = RIG_DCD_PARALLEL;
} else if (!strcmp(val, "CM108")) { }
else if (!strcmp(val, "CM108"))
{
rs->dcdport.type.dcd = RIG_DCD_CM108; rs->dcdport.type.dcd = RIG_DCD_CM108;
} else if (!strcmp(val, "None")) { }
else if (!strcmp(val, "None"))
{
rs->dcdport.type.dcd = RIG_DCD_NONE; rs->dcdport.type.dcd = RIG_DCD_NONE;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -433,7 +515,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
rs = &rig->state; rs = &rig->state;
switch (token) { switch (token)
{
case TOK_PATHNAME: case TOK_PATHNAME:
strcpy(val, rs->rigport.pathname); strcpy(val, rs->rigport.pathname);
break; break;
@ -460,7 +543,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -468,7 +552,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -476,7 +561,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -484,11 +570,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.parity) { switch (rs->rigport.parm.serial.parity)
{
case RIG_PARITY_NONE: case RIG_PARITY_NONE:
s = "None"; s = "None";
break; break;
@ -517,11 +605,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.handshake) { switch (rs->rigport.parm.serial.handshake)
{
case RIG_HANDSHAKE_NONE: case RIG_HANDSHAKE_NONE:
s = "None"; s = "None";
break; break;
@ -542,11 +632,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_RTS_STATE: case TOK_RTS_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.rts_state) { switch (rs->rigport.parm.serial.rts_state)
{
case RIG_SIGNAL_UNSET: case RIG_SIGNAL_UNSET:
s = "Unset"; s = "Unset";
break; break;
@ -567,11 +659,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_DTR_STATE: case TOK_DTR_STATE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) { if (rs->rigport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
switch (rs->rigport.parm.serial.dtr_state) { switch (rs->rigport.parm.serial.dtr_state)
{
case RIG_SIGNAL_UNSET: case RIG_SIGNAL_UNSET:
s = "Unset"; s = "Unset";
break; break;
@ -600,7 +694,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_PTT_TYPE: case TOK_PTT_TYPE:
switch (rs->pttport.type.ptt) { switch (rs->pttport.type.ptt)
{
case RIG_PTT_RIG: case RIG_PTT_RIG:
s = "RIG"; s = "RIG";
break; break;
@ -645,7 +740,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
break; break;
case TOK_DCD_TYPE: case TOK_DCD_TYPE:
switch (rs->dcdport.type.dcd) { switch (rs->dcdport.type.dcd)
{
case RIG_DCD_RIG: case RIG_DCD_RIG:
s = "RIG"; s = "RIG";
break; 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 * \brief call a function against each configuration token of a rig
* \param rig The rig handle * \param rig The rig handle
* \param cfunc The function to perform on each token * \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 * rig_token_foreach starts first with backend conf table, then finish
* with frontend table. * with frontend table.
* *
@ -708,33 +804,45 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
* set appropriately). * set appropriately).
*/ */
int HAMLIB_API rig_token_foreach(RIG *rig, 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) rig_ptr_t data)
{ {
const struct confparams *cfp; const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !cfunc) { if (!rig || !rig->caps || !cfunc)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
for (cfp = frontend_cfg_params; cfp->name; cfp++) for (cfp = frontend_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) { {
if ((*cfunc)(cfp, data) == 0)
{
return RIG_OK; 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++) for (cfp = frontend_serial_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) { {
if ((*cfunc)(cfp, data) == 0)
{
return RIG_OK; return RIG_OK;
} }
} }
}
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) 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;
} }
}
return RIG_OK; return RIG_OK;
} }
@ -757,7 +865,8 @@ const struct confparams *HAMLIB_API rig_confparam_lookup(RIG *rig,
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return NULL; return NULL;
} }
@ -765,21 +874,31 @@ const struct confparams *HAMLIB_API rig_confparam_lookup(RIG *rig,
token = strtol(name, NULL, 0); token = strtol(name, NULL, 0);
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) { {
if (!strcmp(cfp->name, name) || token == cfp->token)
{
return cfp; return cfp;
} }
}
for (cfp = frontend_cfg_params; cfp->name; cfp++) for (cfp = frontend_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) { {
if (!strcmp(cfp->name, name) || token == cfp->token)
{
return cfp; return cfp;
} }
}
if (rig->caps->port_type == RIG_PORT_SERIAL) { if (rig->caps->port_type == RIG_PORT_SERIAL)
{
for (cfp = frontend_serial_cfg_params; cfp->name; cfp++) for (cfp = frontend_serial_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) { {
if (!strcmp(cfp->name, name) || token == cfp->token)
{
return cfp; return cfp;
} }
} }
}
return NULL; return NULL;
} }
@ -802,7 +921,8 @@ token_t HAMLIB_API rig_token_lookup(RIG *rig, const char *name)
cfp = rig_confparam_lookup(rig, name); cfp = rig_confparam_lookup(rig, name);
if (!cfp) { if (!cfp)
{
return RIG_CONF_END; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig_need_debug(RIG_DEBUG_VERBOSE)) { if (rig_need_debug(RIG_DEBUG_VERBOSE))
{
const struct confparams *cfp; const struct confparams *cfp;
char tokenstr[12]; char tokenstr[12];
sprintf(tokenstr, "%ld", token); sprintf(tokenstr, "%ld", token);
cfp = rig_confparam_lookup(rig, tokenstr); cfp = rig_confparam_lookup(rig, tokenstr);
if (!cfp) { if (!cfp)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val);
} }
if (IS_TOKEN_FRONTEND(token)) { if (IS_TOKEN_FRONTEND(token))
{
return frontend_set_conf(rig, token, val); return frontend_set_conf(rig, token, val);
} }
if (rig->caps->set_conf == NULL) { if (rig->caps->set_conf == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !val) { if (!rig || !rig->caps || !val)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (IS_TOKEN_FRONTEND(token)) { if (IS_TOKEN_FRONTEND(token))
{
return frontend_get_conf(rig, token, val); return frontend_get_conf(rig, token, val);
} }
if (rig->caps->get_conf == NULL) { if (rig->caps->get_conf == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }

Wyświetl plik

@ -74,14 +74,17 @@ void dump_hex(const unsigned char ptr[], size_t size)
unsigned char c; unsigned char c;
int i; int i;
if (!rig_need_debug(RIG_DEBUG_TRACE)) { if (!rig_need_debug(RIG_DEBUG_TRACE))
{
return; return;
} }
line[sizeof(line) - 1] = '\0'; line[sizeof(line) - 1] = '\0';
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i)
if (i % DUMP_HEX_WIDTH == 0) { {
if (i % DUMP_HEX_WIDTH == 0)
{
/* new line */ /* new line */
sprintf(line + 0, "%04x", i); sprintf(line + 0, "%04x", i);
memset(line + 4, ' ', sizeof(line) - 4 - 1); memset(line + 4, ' ', sizeof(line) - 4 - 1);
@ -98,7 +101,8 @@ void dump_hex(const unsigned char ptr[], size_t size)
&& c < 0x7f) ? c : '.'; && c < 0x7f) ? c : '.';
/* actually print the line */ /* actually print the line */
if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1)) { if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1))
{
rig_debug(RIG_DEBUG_TRACE, "%s\n", line); rig_debug(RIG_DEBUG_TRACE, "%s\n", line);
} }
} }
@ -135,17 +139,22 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level,
{ {
va_list ap; va_list ap;
if (!rig_need_debug(debug_level)) { if (!rig_need_debug(debug_level))
{
return; return;
} }
va_start(ap, fmt); va_start(ap, fmt);
if (rig_vprintf_cb) { if (rig_vprintf_cb)
{
rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap); rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap);
} else { }
if (!rig_debug_stream) { else
{
if (!rig_debug_stream)
{
rig_debug_stream = stderr; rig_debug_stream = stderr;
} }
@ -158,7 +167,8 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level,
int a; int a;
va_start(ap, fmt); va_start(ap, fmt);
switch (debug_level) { switch (debug_level)
{
// case RIG_DEBUG_NONE: // case RIG_DEBUG_NONE:
case RIG_DEBUG_BUG: case RIG_DEBUG_BUG:
a = ANDROID_LOG_FATAL; a = ANDROID_LOG_FATAL;

Wyświetl plik

@ -40,13 +40,17 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
# include <sys/time.h> # include <sys/time.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
@ -114,7 +118,8 @@ int add_trn_rig(RIG *rig)
status = sigaction(SIGIO, &act, &hamlib_trn_oldact); status = sigaction(SIGIO, &act, &hamlib_trn_oldact);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: sigaction failed: %s\n", "%s: sigaction failed: %s\n",
__func__, __func__,
@ -123,7 +128,8 @@ int add_trn_rig(RIG *rig)
status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid()); status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid());
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETOWN failed: %s\n", "%s: fcntl SETOWN failed: %s\n",
__func__, __func__,
@ -134,7 +140,8 @@ int add_trn_rig(RIG *rig)
#ifdef F_SETSIG #ifdef F_SETSIG
status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO); status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETSIG failed: %s\n", "%s: fcntl SETSIG failed: %s\n",
__func__, __func__,
@ -145,7 +152,8 @@ int add_trn_rig(RIG *rig)
status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC); status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETASYNC failed: %s\n", "%s: fcntl SETASYNC failed: %s\n",
__func__, __func__,
@ -179,7 +187,8 @@ int remove_trn_rig(RIG *rig)
#if defined(HAVE_SIGINFO_T) && defined(O_ASYNC) #if defined(HAVE_SIGINFO_T) && defined(O_ASYNC)
status = fcntl(rig->state.rigport.fd, F_SETFL, 0); status = fcntl(rig->state.rigport.fd, F_SETFL, 0);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: fcntl SETASYNC failed: %s\n", "%s: fcntl SETASYNC failed: %s\n",
__func__, __func__,
@ -190,7 +199,8 @@ int remove_trn_rig(RIG *rig)
status = sigaction(SIGIO, &hamlib_trn_oldact, NULL); status = sigaction(SIGIO, &hamlib_trn_oldact, NULL);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: sigaction failed: %s\n", "%s: sigaction failed: %s\n",
__func__, __func__,
@ -233,7 +243,8 @@ static int add_trn_poll_rig(RIG *rig)
status = sigaction(SIGALRM, &act, &hamlib_trn_poll_oldact); status = sigaction(SIGALRM, &act, &hamlib_trn_poll_oldact);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s sigaction failed: %s\n", "%s sigaction failed: %s\n",
__func__, __func__,
@ -259,7 +270,8 @@ static int remove_trn_poll_rig(RIG *rig)
status = sigaction(SIGALRM, &hamlib_trn_poll_oldact, NULL); status = sigaction(SIGALRM, &hamlib_trn_poll_oldact, NULL);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s sigaction failed: %s\n", "%s sigaction failed: %s\n",
__func__, __func__,
@ -291,7 +303,8 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
* so far, only file oriented ports have event reporting support * so far, only file oriented ports have event reporting support
*/ */
if (rig->state.rigport.type.rig != RIG_PORT_SERIAL if (rig->state.rigport.type.rig != RIG_PORT_SERIAL
|| rig->state.rigport.fd == -1) { || rig->state.rigport.fd == -1)
{
return -1; return -1;
} }
@ -299,7 +312,8 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data)
#if 0&&defined(HAVE_SIGINFO_T) #if 0&&defined(HAVE_SIGINFO_T)
siginfo_t *si = (siginfo_t *)data; siginfo_t *si = (siginfo_t *)data;
if (rig->state.rigport.fd != si->si_fd) { if (rig->state.rigport.fd != si->si_fd)
{
return -1; return -1;
} }
@ -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); retval = select(rig->state.rigport.fd + 1, &rfds, NULL, NULL, &tv);
if (retval < 0) { if (retval < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: select: %s\n", "%s: select: %s\n",
__func__, __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 * Do not disturb, the backend is currently receiving data
*/ */
if (rig->state.hold_decode) { if (rig->state.hold_decode)
{
return -1; return -1;
} }
if (rig->caps->decode_event) { if (rig->caps->decode_event)
{
rig->caps->decode_event(rig); rig->caps->decode_event(rig);
} }
@ -352,26 +369,31 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
struct rig_state *rs = &rig->state; struct rig_state *rs = &rig->state;
int retval; int retval;
if (rig->state.transceive != RIG_TRN_POLL) { if (rig->state.transceive != RIG_TRN_POLL)
{
return -1; return -1;
} }
/* /*
* Do not disturb, the backend is currently receiving data * Do not disturb, the backend is currently receiving data
*/ */
if (rig->state.hold_decode) { if (rig->state.hold_decode)
{
return -1; return -1;
} }
rig->state.hold_decode = 2; rig->state.hold_decode = 2;
if (rig->caps->get_vfo && rig->callbacks.vfo_event) { if (rig->caps->get_vfo && rig->callbacks.vfo_event)
{
vfo_t vfo = RIG_VFO_CURR; vfo_t vfo = RIG_VFO_CURR;
retval = rig->caps->get_vfo(rig, &vfo); retval = rig->caps->get_vfo(rig, &vfo);
if (retval == RIG_OK) { if (retval == RIG_OK)
if (vfo != rs->current_vfo) { {
if (vfo != rs->current_vfo)
{
rig->callbacks.vfo_event(rig, vfo, rig->callbacks.vfo_arg); rig->callbacks.vfo_event(rig, vfo, rig->callbacks.vfo_arg);
} }
@ -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; freq_t freq;
retval = rig->caps->get_freq(rig, RIG_VFO_CURR, &freq); retval = rig->caps->get_freq(rig, RIG_VFO_CURR, &freq);
if (retval == RIG_OK) { if (retval == RIG_OK)
if (freq != rs->current_freq) { {
rig->callbacks.freq_event(rig, RIG_VFO_CURR, if (freq != rs->current_freq)
freq, rig->callbacks.freq_arg); {
rig->callbacks.freq_event(rig,
RIG_VFO_CURR,
freq,
rig->callbacks.freq_arg);
} }
rs->current_freq = freq; rs->current_freq = freq;
} }
} }
if (rig->caps->get_mode && rig->callbacks.mode_event) { if (rig->caps->get_mode && rig->callbacks.mode_event)
{
rmode_t rmode; rmode_t rmode;
pbwidth_t width; pbwidth_t width;
retval = rig->caps->get_mode(rig, RIG_VFO_CURR, &rmode, &width); retval = rig->caps->get_mode(rig, RIG_VFO_CURR, &rmode, &width);
if (retval == RIG_OK) { if (retval == RIG_OK)
if (rmode != rs->current_mode || width != rs->current_width) { {
rig->callbacks.mode_event(rig, RIG_VFO_CURR, if (rmode != rs->current_mode || width != rs->current_width)
rmode, width, rig->callbacks.mode_arg); {
rig->callbacks.mode_event(rig,
RIG_VFO_CURR,
rmode,
width,
rig->callbacks.mode_arg);
} }
rs->current_mode = rmode; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
/* detect whether tranceive is active already */ /* detect whether tranceive is active already */
if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF) { if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF)
if (trn == rig->state.transceive) { {
if (trn == rig->state.transceive)
{
return RIG_OK; return RIG_OK;
} else { }
else
{
/* when going POLL<->RIG, transtition to OFF */ /* when going POLL<->RIG, transtition to OFF */
retcode = rig_set_trn(rig, RIG_TRN_OFF); retcode = rig_set_trn(rig, RIG_TRN_OFF);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
} }
} }
switch (trn) { switch (trn)
{
case RIG_TRN_RIG: case RIG_TRN_RIG:
if (caps->transceive != RIG_TRN_RIG) { if (caps->transceive != RIG_TRN_RIG)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -704,7 +751,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
/* some protocols (e.g. CI-V's) offer no way /* some protocols (e.g. CI-V's) offer no way
* to turn on/off the transceive mode */ * to turn on/off the transceive mode */
if (retcode == RIG_OK && caps->set_trn) { if (retcode == RIG_OK && caps->set_trn)
{
retcode = caps->set_trn(rig, RIG_TRN_RIG); retcode = caps->set_trn(rig, RIG_TRN_RIG);
} }
@ -722,7 +770,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
value.it_interval.tv_usec = rig->state.poll_interval * 1000; value.it_interval.tv_usec = rig->state.poll_interval * 1000;
retcode = setitimer(ITIMER_REAL, &value, NULL); retcode = setitimer(ITIMER_REAL, &value, NULL);
if (retcode == -1) { if (retcode == -1)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: setitimer: %s\n", "%s: setitimer: %s\n",
__func__, __func__,
@ -737,7 +786,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
break; break;
case RIG_TRN_OFF: case RIG_TRN_OFF:
if (rig->state.transceive == RIG_TRN_POLL) { if (rig->state.transceive == RIG_TRN_POLL)
{
#ifdef HAVE_SETITIMER #ifdef HAVE_SETITIMER
retcode = remove_trn_poll_rig(rig); 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); retcode = setitimer(ITIMER_REAL, &value, NULL);
if (retcode == -1) { if (retcode == -1)
{
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n", rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
@ -759,10 +810,13 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
#else #else
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
#endif #endif
} else if (rig->state.transceive == RIG_TRN_RIG) { }
else if (rig->state.transceive == RIG_TRN_RIG)
{
retcode = remove_trn_rig(rig); retcode = remove_trn_rig(rig);
if (caps->set_trn && caps->transceive == RIG_TRN_RIG) { if (caps->set_trn && caps->transceive == RIG_TRN_RIG)
{
retcode = caps->set_trn(rig, RIG_TRN_OFF); retcode = caps->set_trn(rig, RIG_TRN_OFF);
} }
} }
@ -773,7 +827,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (retcode == RIG_OK) { if (retcode == RIG_OK)
{
rig->state.transceive = trn; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !trn) { if (CHECK_RIG_ARG(rig) || !trn)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig->caps->get_trn != NULL) { if (rig->caps->get_trn != NULL)
{
return rig->caps->get_trn(rig, trn); return rig->caps->get_trn(rig, trn);
} }

Wyświetl plik

@ -28,10 +28,10 @@
* \file ext.c * \file ext.c
* \brief Extension request parameter interface * \brief Extension request parameter interface
* *
* An open-ended set of extension parameters and levels are available for each rig, * An open-ended set of extension parameters and levels are available for each
* as provided in the rigcaps extparms and extlevels lists. These provide a way * rig, as provided in the rigcaps extparms and extlevels lists. These
* to work with rig-specific functions that don't fit into the basic "virtual rig" of * provide a way to work with rig-specific functions that don't fit into the
* Hamlib. See icom/ic746.c for an example. * basic "virtual rig" of Hamlib. See icom/ic746.c for an example.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -54,9 +54,11 @@
* \param cfunc callback function of each extlevel * \param cfunc callback function of each extlevel
* \param data cookie to be passed to \a cfunc callback * \param data cookie to be passed to \a cfunc callback
* \brief Executes cfunc on all the elements stored in the extlevels table * \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, * The callback \a cfunc is called until it returns a value which is not
* which will be the return value of rig_ext_level_foreach. * 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 HAMLIB_API rig_ext_level_foreach(RIG *rig,
int (*cfunc)(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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !cfunc) { if (!rig || !rig->caps || !cfunc)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) { for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
{
ret = (*cfunc)(rig, cfp, data); ret = (*cfunc)(rig, cfp, data);
if (ret == 0) { if (ret == 0)
{
return RIG_OK; return RIG_OK;
} }
if (ret < 0) { if (ret < 0)
{
return ret; return ret;
} }
} }
@ -94,9 +100,11 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig,
* \param cfunc callback function of each extparm * \param cfunc callback function of each extparm
* \param data cookie to be passed to \a cfunc callback * \param data cookie to be passed to \a cfunc callback
* \brief Executes cfunc on all the elements stored in the extparms table * \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, * The callback \a cfunc is called until it returns a value which is not
* which will be the return value of rig_ext_parm_foreach. * 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 HAMLIB_API rig_ext_parm_foreach(RIG *rig,
int (*cfunc)(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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps || !cfunc) { if (!rig || !rig->caps || !cfunc)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) { for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
{
ret = (*cfunc)(rig, cfp, data); ret = (*cfunc)(rig, cfp, data);
if (ret == 0) { if (ret == 0)
{
return RIG_OK; return RIG_OK;
} }
if (ret < 0) { if (ret < 0)
{
return ret; return ret;
} }
} }
@ -146,19 +158,26 @@ const struct confparams * HAMLIB_API rig_ext_lookup(RIG *rig, const char *name)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return NULL; return NULL;
} }
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name)) { {
if (!strcmp(cfp->name, name))
{
return cfp; return cfp;
} }
}
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name)) { {
if (!strcmp(cfp->name, name))
{
return cfp; return cfp;
} }
}
return NULL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return NULL; return NULL;
} }
for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++) for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++)
if (cfp->token == token) { {
if (cfp->token == token)
{
return cfp; return cfp;
} }
}
for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++) for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++)
if (cfp->token == token) { {
if (cfp->token == token)
{
return cfp; return cfp;
} }
}
return NULL; 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); cfp = rig_ext_lookup(rig, name);
if (!cfp) { if (!cfp)
{
return RIG_CONF_END; return RIG_CONF_END;
} }

Wyświetl plik

@ -40,7 +40,8 @@ int gpio_open(hamlib_port_t *port, int on_value)
snprintf(pathname, FILPATHLEN, "/sys/class/gpio/export"); snprintf(pathname, FILPATHLEN, "/sys/class/gpio/export");
fexp = fopen(pathname, "w"); fexp = fopen(pathname, "w");
if (!fexp) { if (!fexp)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"Export GPIO%s (using %s): %s\n", "Export GPIO%s (using %s): %s\n",
port->pathname, port->pathname,
@ -58,7 +59,8 @@ int gpio_open(hamlib_port_t *port, int on_value)
port->pathname); port->pathname);
fdir = fopen(pathname, "w"); fdir = fopen(pathname, "w");
if (!fdir) { if (!fdir)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"GPIO%s direction (using %s): %s\n", "GPIO%s direction (using %s): %s\n",
port->pathname, port->pathname,
@ -76,7 +78,8 @@ int gpio_open(hamlib_port_t *port, int on_value)
port->pathname); port->pathname);
fd = open(pathname, O_WRONLY); fd = open(pathname, O_WRONLY);
if (fd < 0) { if (fd < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"GPIO%s opening value file %s: %s\n", "GPIO%s opening value file %s: %s\n",
port->pathname, 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; port->parm.gpio.value = pttx != RIG_PTT_OFF;
if ((port->parm.gpio.value && port->parm.gpio.on_value) if ((port->parm.gpio.value && port->parm.gpio.on_value)
|| (!port->parm.gpio.value && !port->parm.gpio.on_value)) { || (!port->parm.gpio.value && !port->parm.gpio.on_value))
{
val = "1\n"; val = "1\n";
} else { }
else
{
val = "0\n"; val = "0\n";
} }
if (write(port->fd, val, strlen(val)) <= 0) { if (write(port->fd, val, strlen(val)) <= 0)
{
return -RIG_EIO; return -RIG_EIO;
} }
@ -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) int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx)
{ {
if (port->parm.gpio.value) { if (port->parm.gpio.value)
{
return RIG_PTT_ON; return RIG_PTT_ON;
} else { }
else
{
return RIG_PTT_OFF; return RIG_PTT_OFF;
} }
} }

Wyświetl plik

@ -68,32 +68,38 @@ int HAMLIB_API port_open(hamlib_port_t *p)
p->fd = -1; p->fd = -1;
switch (p->type.rig) { switch (p->type.rig)
{
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
status = serial_open(p); status = serial_open(p);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET
&& p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) { && p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE)
{
status = ser_set_rts(p, status = ser_set_rts(p,
p->parm.serial.rts_state == RIG_SIGNAL_ON); p->parm.serial.rts_state == RIG_SIGNAL_ON);
want_state_delay = 1; want_state_delay = 1;
} }
if (status != 0) { if (status != 0)
{
return status; return status;
} }
if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) { if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET)
{
status = ser_set_dtr(p, status = ser_set_dtr(p,
p->parm.serial.dtr_state == RIG_SIGNAL_ON); p->parm.serial.dtr_state == RIG_SIGNAL_ON);
want_state_delay = 1; want_state_delay = 1;
} }
if (status != 0) { if (status != 0)
{
return status; return status;
} }
@ -101,7 +107,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
* Wait whatever electrolytics in the circuit come up to voltage. * Wait whatever electrolytics in the circuit come up to voltage.
* Is 100ms enough? Too much? * Is 100ms enough? Too much?
*/ */
if (want_state_delay) { if (want_state_delay)
{
usleep(100 * 1000); usleep(100 * 1000);
} }
@ -110,7 +117,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
case RIG_PORT_PARALLEL: case RIG_PORT_PARALLEL:
status = par_open(p); status = par_open(p);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -119,7 +127,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
case RIG_PORT_CM108: case RIG_PORT_CM108:
status = cm108_open(p); status = cm108_open(p);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -128,7 +137,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
case RIG_PORT_DEVICE: case RIG_PORT_DEVICE:
status = open(p->pathname, O_RDWR, 0); status = open(p->pathname, O_RDWR, 0);
if (status < 0) { if (status < 0)
{
return -RIG_EIO; return -RIG_EIO;
} }
@ -138,7 +148,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
case RIG_PORT_USB: case RIG_PORT_USB:
status = usb_port_open(p); status = usb_port_open(p);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -153,7 +164,8 @@ int HAMLIB_API port_open(hamlib_port_t *p)
/* FIXME: hardcoded network port */ /* FIXME: hardcoded network port */
status = network_open(p, 4532); status = network_open(p, 4532);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (p->fd != -1) { if (p->fd != -1)
switch (port_type) { {
switch (port_type)
{
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
ret = ser_close(p); ret = ser_close(p);
break; break;
@ -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 * Note that we always have RIG_PORT_SERIAL in the
* microHam case. * microHam case.
*/ */
if (is_uh_radio_fd(p->fd)) { if (is_uh_radio_fd(p->fd))
{
return read(p->fd, buf, count); 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); ret = win32_serial_read(p->fd, buf, count);
if (p->parm.serial.data_bits == 7) { if (p->parm.serial.data_bits == 7)
{
unsigned char *pbuf = buf; unsigned char *pbuf = buf;
/* clear MSB */ /* clear MSB */
for (i = 0; i < ret; i++) { for (i = 0; i < ret; i++)
{
pbuf[i] &= ~0x80; pbuf[i] &= ~0x80;
} }
} }
return ret; return ret;
} else if (p->type.rig == RIG_PORT_NETWORK }
|| p->type.rig == RIG_PORT_UDP_NETWORK) { else if (p->type.rig == RIG_PORT_NETWORK
|| p->type.rig == RIG_PORT_UDP_NETWORK)
{
return recv(p->fd, buf, count, 0); return recv(p->fd, buf, count, 0);
} else { }
else
{
return read(p->fd, buf, count); return read(p->fd, buf, count);
} }
} }
@ -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 * Note that we always have RIG_PORT_SERIAL in the
* microHam case. * microHam case.
*/ */
if (is_uh_radio_fd(p->fd)) { if (is_uh_radio_fd(p->fd))
{
return write(p->fd, buf, count); 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); return win32_serial_write(p->fd, buf, count);
} else if (p->type.rig == RIG_PORT_NETWORK }
|| p->type.rig == RIG_PORT_UDP_NETWORK) { else if (p->type.rig == RIG_PORT_NETWORK
|| p->type.rig == RIG_PORT_UDP_NETWORK)
{
return send(p->fd, buf, count, 0); return send(p->fd, buf, count, 0);
} else { }
else
{
return write(p->fd, buf, count); return write(p->fd, buf, count);
} }
} }
static int port_select(hamlib_port_t *p, int n, fd_set *readfds, static int port_select(hamlib_port_t *p,
fd_set *writefds, fd_set *exceptfds, int n,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
struct timeval *timeout) struct timeval *timeout)
{ {
#if 1 #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 /* select does not work very well with writefds/exceptfds
* So let's pretend there's none of them * So let's pretend there's none of them
*/ */
if (exceptfds) { if (exceptfds)
{
FD_ZERO(exceptfds); FD_ZERO(exceptfds);
} }
if (writefds) { if (writefds)
{
FD_ZERO(writefds); FD_ZERO(writefds);
} }
@ -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 * Note that we always have RIG_PORT_SERIAL in the
* microHam case. * microHam case.
*/ */
if (is_uh_radio_fd(p->fd)) { if (is_uh_radio_fd(p->fd))
{
return select(n, readfds, writefds, exceptfds, timeout); 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); return win32_serial_select(n, readfds, writefds, exceptfds, timeout);
} else { }
else
{
return select(n, readfds, writefds, exceptfds, timeout); return select(n, readfds, writefds, exceptfds, timeout);
} }
} }
@ -335,18 +372,22 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
int i; int i;
ssize_t ret; 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; unsigned char *pbuf = buf;
ret = read(p->fd, buf, count); ret = read(p->fd, buf, count);
/* clear MSB */ /* clear MSB */
for (i = 0; i < ret; i++) { for (i = 0; i < ret; i++)
{
pbuf[i] &= ~0x80; pbuf[i] &= ~0x80;
} }
return ret; return ret;
} else { }
else
{
return read(p->fd, buf, count); return read(p->fd, buf, count);
} }
} }
@ -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 #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
if (p->post_write_date.tv_sec != 0) { if (p->post_write_date.tv_sec != 0)
{
signed int date_delay; /* in us */ signed int date_delay; /* in us */
struct timeval tv; struct timeval tv;
@ -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_sec - p->post_write_date.tv_sec) * 1000000 +
(tv.tv_usec - p->post_write_date.tv_usec)); (tv.tv_usec - p->post_write_date.tv_usec));
if (date_delay > 0) { if (date_delay > 0)
{
/* /*
* optional delay after last write * optional delay after last write
*/ */
@ -415,38 +458,57 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
#endif #endif
if (p->write_delay > 0) { if (p->write_delay > 0)
for (i = 0; i < count; i++) { {
for (i = 0; i < count; i++)
{
ret = port_write(p, txbuffer + i, 1); ret = port_write(p, txbuffer + i, 1);
if (ret != 1) { if (ret != 1)
rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n", {
__func__, __LINE__, ret, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s():%d failed %d - %s\n",
__func__,
__LINE__,
ret,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
usleep(p->write_delay * 1000); usleep(p->write_delay * 1000);
} }
} else { }
else
{
ret = port_write(p, txbuffer, count); ret = port_write(p, txbuffer, count);
if (ret != count) { if (ret != count)
rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n", {
__func__, __LINE__, ret, strerror(errno)); rig_debug(RIG_DEBUG_ERR,
"%s():%d failed %d - %s\n",
__func__,
__LINE__,
ret,
strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
} }
if (p->post_write_delay > 0) { if (p->post_write_delay > 0)
{
#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
#define POST_WRITE_DELAY_TRSHLD 10 #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; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
p->post_write_date.tv_sec = tv.tv_sec; p->post_write_date.tv_sec = tv.tv_sec;
p->post_write_date.tv_usec = tv.tv_usec; p->post_write_date.tv_usec = tv.tv_usec;
} else }
else
#endif #endif
usleep(p->post_write_delay * 1000); /* optional delay after last write */ usleep(p->post_write_delay * 1000); /* optional delay after last write */
@ -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 */ /* Store the time of the read loop start */
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
while (count > 0) { while (count > 0)
{
tv = tv_timeout; /* select may have updated it */ tv = tv_timeout; /* select may have updated it */
FD_ZERO(&rfds); 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); retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv);
if (retval == 0) { if (retval == 0)
{
/* Record timeout time and caculate elapsed time */ /* Record timeout time and caculate elapsed time */
gettimeofday(&end_time, NULL); gettimeofday(&end_time, NULL);
timersub(&end_time, &start_time, &elapsed_time); timersub(&end_time, &start_time, &elapsed_time);
@ -522,7 +586,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
return -RIG_ETIMEOUT; return -RIG_ETIMEOUT;
} }
if (retval < 0) { if (retval < 0)
{
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s(): select() error after %d chars: %s\n", "%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; return -RIG_EIO;
} }
if (FD_ISSET(p->fd, &efds)) { if (FD_ISSET(p->fd, &efds))
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s(): fd error after %d chars\n", "%s(): fd error after %d chars\n",
__func__, __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); rd_count = port_read(p, rxbuffer + total_count, count);
if (rd_count < 0) { if (rd_count < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s(): read() failed - %s\n", "%s(): read() failed - %s\n",
__func__, __func__,
@ -593,7 +660,9 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
* *
* Assumes rxbuffer!=NULL * Assumes rxbuffer!=NULL
*/ */
int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, int HAMLIB_API read_string(hamlib_port_t *p,
char *rxbuffer,
size_t rxmax,
const char *stopset, const char *stopset,
int stopset_len) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!p || !rxbuffer) { if (!p || !rxbuffer)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rxmax < 1) { if (rxmax < 1)
{
return 0; 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 */ /* Store the time of the read loop start */
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
while (total_count < rxmax - 1) { while (total_count < rxmax - 1)
{
tv = tv_timeout; /* select may have updated it */ tv = tv_timeout; /* select may have updated it */
FD_ZERO(&rfds); 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); retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv);
if (retval == 0) { if (retval == 0)
if (0 == total_count) { {
if (0 == total_count)
{
/* Record timeout time and caculate elapsed time */ /* Record timeout time and caculate elapsed time */
gettimeofday(&end_time, NULL); gettimeofday(&end_time, NULL);
timersub(&end_time, &start_time, &elapsed_time); 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 */ break; /* return what we have read */
} }
if (retval < 0) { if (retval < 0)
{
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s(): select() error after %d chars: %s\n", "%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; return -RIG_EIO;
} }
if (FD_ISSET(p->fd, &efds)) { if (FD_ISSET(p->fd, &efds))
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s(): fd error after %d chars\n", "%s(): fd error after %d chars\n",
__func__, __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); rd_count = port_read(p, &rxbuffer[total_count], 1);
if (rd_count < 0) { if (rd_count < 0)
{
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s(): read() failed - %s\n", "%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; ++total_count;
if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len)) { if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len))
{
break; break;
} }
} }
@ -703,6 +781,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax,
"%s(): RX %d characters\n", "%s(): RX %d characters\n",
__func__, __func__,
total_count); total_count);
dump_hex((unsigned char *) rxbuffer, total_count); dump_hex((unsigned char *) rxbuffer, total_count);
return total_count; /* return bytes count read */ return total_count; /* return bytes count read */

Wyświetl plik

@ -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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (degrees < 0) { if (degrees < 0)
{
degrees = abs(degrees); degrees = abs(degrees);
} }
if (minutes < 0) { if (minutes < 0)
{
minutes = abs(minutes); minutes = abs(minutes);
} }
if (seconds < 0) { if (seconds < 0)
{
seconds = fabs(seconds); seconds = fabs(seconds);
} }
st = (double)degrees + (double)minutes / 60. + seconds / 3600.; st = (double)degrees + (double)minutes / 60. + seconds / 3600.;
if (sw == 1) { if (sw == 1)
{
return -st; return -st;
} else { }
else
{
return st; return st;
} }
} }
@ -193,19 +199,24 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (degrees < 0) { if (degrees < 0)
{
degrees = abs(degrees); degrees = abs(degrees);
} }
if (minutes < 0) { if (minutes < 0)
{
minutes = fabs(minutes); minutes = fabs(minutes);
} }
st = (double)degrees + minutes / 60.; st = (double)degrees + minutes / 60.;
if (sw == 1) { if (sw == 1)
{
return -st; return -st;
} else { }
else
{
return st; return st;
} }
} }
@ -238,7 +249,10 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw)
* *
* \sa dms2dec() * \sa dms2dec()
*/ */
int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds, int HAMLIB_API dec2dms(double dec,
int *degrees,
int *minutes,
double *seconds,
int *sw) int *sw)
{ {
int deg, min; int deg, min;
@ -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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!degrees || !minutes || !seconds || !sw) { if (!degrees || !minutes || !seconds || !sw)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -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 * passed 361 st will be set to 1, etc. If passed
* a value > -180 || < 180, value will be unchanged. * a value > -180 || < 180, value will be unchanged.
*/ */
if (dec >= 0.0) { if (dec >= 0.0)
{
st = fmod(dec + 180, 360) - 180; st = fmod(dec + 180, 360) - 180;
} else { }
else
{
st = fmod(dec - 180, 360) + 180; st = fmod(dec - 180, 360) + 180;
} }
@ -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 negative as well except for 180 which we want
* to be positive. * to be positive.
*/ */
if (st < 0.0 && st != -180) { if (st < 0.0 && st != -180)
{
*sw = 1; *sw = 1;
} else { }
else
{
*sw = 0; *sw = 0;
} }
@ -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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!degrees || !minutes || !sw) { if (!degrees || !minutes || !sw)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
r = dec2dms(dec, degrees, &min, &sec, sw); r = dec2dms(dec, degrees, &min, &sec, sw);
if (r != RIG_OK) { if (r != RIG_OK)
{
return r; return r;
} }
@ -370,9 +393,9 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw)
* *
* \sa longlat2locator() * \sa longlat2locator()
*/ */
/* begin dph */ /* begin dph */
int HAMLIB_API locator2longlat(double *longitude, double *latitude, int HAMLIB_API locator2longlat(double *longitude,
double *latitude,
const char *locator) const char *locator)
{ {
int x_or_y, paircount; int x_or_y, paircount;
@ -383,25 +406,31 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude,
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!longitude || !latitude) { if (!longitude || !latitude)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
paircount = strlen(locator) / 2; paircount = strlen(locator) / 2;
/* verify paircount is within limits */ /* verify paircount is within limits */
if (paircount > MAX_LOCATOR_PAIRS) { if (paircount > MAX_LOCATOR_PAIRS)
{
paircount = MAX_LOCATOR_PAIRS; paircount = MAX_LOCATOR_PAIRS;
} else if (paircount < MIN_LOCATOR_PAIRS) { }
else if (paircount < MIN_LOCATOR_PAIRS)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
/* For x(=longitude) and y(=latitude) */ /* For x(=longitude) and y(=latitude) */
for (x_or_y = 0; x_or_y < 2; ++x_or_y) { for (x_or_y = 0; x_or_y < 2; ++x_or_y)
{
ordinate = -90.0; ordinate = -90.0;
divisions = 1; divisions = 1;
for (pair = 0; pair < paircount; ++pair) { for (pair = 0; pair < paircount; ++pair)
{
locvalue = locator[pair * 2 + x_or_y]; locvalue = locator[pair * 2 + x_or_y];
/* Value of digit or letter */ /* Value of digit or letter */
@ -409,7 +438,8 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude,
(isupper(locvalue)) ? 'A' : 'a'; (isupper(locvalue)) ? 'A' : 'a';
/* Check range for non-letter/digit or out of range */ /* Check range for non-letter/digit or out of range */
if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) { if ((locvalue < 0) || (locvalue >= loc_char_range[pair]))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -452,9 +482,10 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude,
* *
* \sa locator2longlat() * \sa locator2longlat()
*/ */
/* begin dph */ /* begin dph */
int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, int HAMLIB_API longlat2locator(double longitude,
double latitude,
char *locator,
int pair_count) int pair_count)
{ {
int x_or_y, pair, locvalue, divisions; int x_or_y, pair, locvalue, divisions;
@ -462,22 +493,26 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!locator) { if (!locator)
{
return -RIG_EINVAL; 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; return -RIG_EINVAL;
} }
for (x_or_y = 0; x_or_y < 2; ++x_or_y) { for (x_or_y = 0; x_or_y < 2; ++x_or_y)
{
ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude;
divisions = 1; divisions = 1;
/* The 1e-6 here guards against floating point rounding errors */ /* The 1e-6 here guards against floating point rounding errors */
ordinate = fmod(ordinate + 270.000001, 180.0); ordinate = fmod(ordinate + 270.000001, 180.0);
for (pair = 0; pair < pair_count; ++pair) { for (pair = 0; pair < pair_count; ++pair)
{
divisions *= loc_char_range[pair]; divisions *= loc_char_range[pair];
square_size = 180.0 / divisions; square_size = 180.0 / divisions;
@ -520,36 +555,49 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator,
* *
* \sa distance_long_path(), azimuth_long_path() * \sa distance_long_path(), azimuth_long_path()
*/ */
int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2, int HAMLIB_API qrb(double lon1,
double *distance, double *azimuth) double lat1,
double lon2,
double lat2,
double *distance,
double *azimuth)
{ {
double delta_long, tmp, arc, az; double delta_long, tmp, arc, az;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* bail if NULL pointers passed */ /* bail if NULL pointers passed */
if (!distance || !azimuth) { if (!distance || !azimuth)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0)) { if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0)) { if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
/* Prevent ACOS() Domain Error */ /* Prevent ACOS() Domain Error */
if (lat1 == 90.0) { if (lat1 == 90.0)
{
lat1 = 89.999999999; lat1 = 89.999999999;
} else if (lat1 == -90.0) { }
else if (lat1 == -90.0)
{
lat1 = -89.999999999; lat1 = -89.999999999;
} }
if (lat2 == 90.0) { if (lat2 == 90.0)
{
lat2 = 89.999999999; lat2 = 89.999999999;
} else if (lat2 == -90.0) { }
else if (lat2 == -90.0)
{
lat2 = -89.999999999; lat2 = -89.999999999;
} }
@ -563,14 +611,16 @@ int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2,
tmp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(delta_long); tmp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(delta_long);
if (tmp > .999999999999999) { if (tmp > .999999999999999)
{
/* Station points coincide, use an Omni! */ /* Station points coincide, use an Omni! */
*distance = 0.0; *distance = 0.0;
*azimuth = 0.0; *azimuth = 0.0;
return RIG_OK; return RIG_OK;
} }
if (tmp < -.999999) { if (tmp < -.999999)
{
/* /*
* points are antipodal, it's straight down. * points are antipodal, it's straight down.
* Station is equal distance in all Azimuths. * 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); az = fmod(360.0 + az, 360.0);
if (az < 0.0) { if (az < 0.0)
{
az += 360.0; az += 360.0;
} else if (az >= 360.0) { }
else if (az >= 360.0)
{
az -= 360.0; az -= 360.0;
} }
@ -645,15 +698,24 @@ double HAMLIB_API azimuth_long_path(double azimuth)
{ {
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); 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; return 180.0;
} else if (azimuth > 0.0 && azimuth < 180.0) { }
else if (azimuth > 0.0 && azimuth < 180.0)
{
return 180.0 + azimuth; return 180.0 + azimuth;
} else if (azimuth == 180.0) { }
else if (azimuth == 180.0)
{
return 0.0; return 0.0;
} else if (azimuth > 180.0 && azimuth < 360.0) { }
else if (azimuth > 180.0 && azimuth < 360.0)
{
return (180.0 - azimuth) * -1.0; return (180.0 - azimuth) * -1.0;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
} }

421
src/mem.c

Plik diff jest za duży Load Diff

Plik diff jest za duży Load Diff

Wyświetl plik

@ -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 // declaration of functions implemented in microham.c
// //
@ -9,4 +30,3 @@ extern void uh_set_ptt(int ptt);
extern int uh_get_ptt(); extern int uh_get_ptt();
extern void uh_close_radio(); extern void uh_close_radio();
extern void uh_close_ptt(); extern void uh_close_ptt();

Wyświetl plik

@ -39,12 +39,15 @@
#include <unistd.h> /* UNIX standard function definitions */ #include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */ #include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */ #include <errno.h> /* Error number definitions */
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
# include <sys/time.h> # include <sys/time.h>
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <hamlib/rig.h> #include <hamlib/rig.h>
@ -70,7 +73,7 @@
* *
* Returns a pointer to (unsigned char *)bcd_data. * 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 char * HAMLIB_API to_bcd(unsigned char bcd_data[],
unsigned long long freq, unsigned long long freq,
@ -84,7 +87,8 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
/* '450'/4-> 5,0;0,4 */ /* '450'/4-> 5,0;0,4 */
/* '450'/3-> 5,0;x,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; a = freq % 10;
freq /= 10; freq /= 10;
a |= (freq % 10) << 4; a |= (freq % 10) << 4;
@ -92,7 +96,8 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
bcd_data[i] = a; bcd_data[i] = a;
} }
if (bcd_len & 1) { if (bcd_len & 1)
{
bcd_data[i] &= 0xf0; bcd_data[i] &= 0xf0;
bcd_data[i] |= freq % 10; /* NB: high nibble is left uncleared */ bcd_data[i] |= freq % 10; /* NB: high nibble is left uncleared */
} }
@ -116,7 +121,7 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[],
* *
* Returns frequency in Hz an unsigned long long integer. * 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 long long HAMLIB_API from_bcd(const unsigned char bcd_data[],
unsigned bcd_len) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (bcd_len & 1) { if (bcd_len & 1)
{
f = bcd_data[bcd_len / 2] & 0x0f; f = bcd_data[bcd_len / 2] & 0x0f;
} }
for (i = (bcd_len / 2) - 1; i >= 0; i--) { for (i = (bcd_len / 2) - 1; i >= 0; i--)
{
f *= 10; f *= 10;
f += bcd_data[i] >> 4; f += bcd_data[i] >> 4;
f *= 10; f *= 10;
@ -151,7 +158,7 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[],
* Same as to_bcd, but in big-endian order * Same as to_bcd, but in big-endian order
* (e.g. byte order 12 34 56 78 90 for 1234567890 Hz) * (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 char * HAMLIB_API to_bcd_be(unsigned char bcd_data[],
unsigned long long freq, unsigned long long freq,
@ -165,14 +172,16 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[],
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (bcd_len & 1) { if (bcd_len & 1)
{
bcd_data[bcd_len / 2] &= 0x0f; bcd_data[bcd_len / 2] &= 0x0f;
bcd_data[bcd_len / 2] |= (freq % 10) << bcd_data[bcd_len / 2] |= (freq % 10) <<
4; /* NB: low nibble is left uncleared */ 4; /* NB: low nibble is left uncleared */
freq /= 10; freq /= 10;
} }
for (i = (bcd_len / 2) - 1; i >= 0; i--) { for (i = (bcd_len / 2) - 1; i >= 0; i--)
{
a = freq % 10; a = freq % 10;
freq /= 10; freq /= 10;
a |= (freq % 10) << 4; 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 * Same as from_bcd, but in big-endian order
* (e.g. byte order 12 34 56 78 90 for 1234567890 Hz) * (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 long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[],
unsigned bcd_len) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0; i < bcd_len / 2; i++) { for (i = 0; i < bcd_len / 2; i++)
{
f *= 10; f *= 10;
f += bcd_data[i] >> 4; f += bcd_data[i] >> 4;
f *= 10; f *= 10;
f += bcd_data[i] & 0x0f; f += bcd_data[i] & 0x0f;
} }
if (bcd_len & 1) { if (bcd_len & 1)
{
f *= 10; f *= 10;
f += bcd_data[bcd_len / 2] >> 4; f += bcd_data[bcd_len / 2] >> 4;
} }
@ -240,16 +251,23 @@ int HAMLIB_API sprintf_freq(char *str, freq_t freq)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (llabs(freq) >= GHz(1)) { if (llabs(freq) >= GHz(1))
{
hz = "GHz"; hz = "GHz";
f = (double)freq / GHz(1); f = (double)freq / GHz(1);
} else if (llabs(freq) >= MHz(1)) { }
else if (llabs(freq) >= MHz(1))
{
hz = "MHz"; hz = "MHz";
f = (double)freq / MHz(1); f = (double)freq / MHz(1);
} else if (llabs(freq) >= kHz(1)) { }
else if (llabs(freq) >= kHz(1))
{
hz = "kHz"; hz = "kHz";
f = (double)freq / kHz(1); f = (double)freq / kHz(1);
} else { }
else
{
hz = "Hz"; hz = "Hz";
f = (double)freq; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (status) { switch (status)
{
case RIG_STATUS_ALPHA: case RIG_STATUS_ALPHA:
return "Alpha"; return "Alpha";
@ -288,10 +307,12 @@ const char * HAMLIB_API rig_strstatus(enum rig_status_e status)
} }
static struct { static struct
{
rmode_t mode; rmode_t mode;
const char *str; const char *str;
} mode_str[] = { } mode_str[] =
{
{ RIG_MODE_AM, "AM" }, { RIG_MODE_AM, "AM" },
{ RIG_MODE_CW, "CW" }, { RIG_MODE_CW, "CW" },
{ RIG_MODE_USB, "USB" }, { 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; mode_str[i].str[0] != '\0'; i++) for (i = 0 ; mode_str[i].str[0] != '\0'; i++)
if (!strcmp(s, mode_str[i].str)) { {
if (!strcmp(s, mode_str[i].str))
{
return mode_str[i].mode; return mode_str[i].mode;
} }
}
return RIG_MODE_NONE; return RIG_MODE_NONE;
} }
@ -351,23 +375,29 @@ const char * HAMLIB_API rig_strrmode(rmode_t mode)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (mode == RIG_MODE_NONE) { if (mode == RIG_MODE_NONE)
{
return ""; return "";
} }
for (i = 0 ; mode_str[i].str[0] != '\0'; i++) for (i = 0 ; mode_str[i].str[0] != '\0'; i++)
if (mode == mode_str[i].mode) { {
if (mode == mode_str[i].mode)
{
return mode_str[i].str; return mode_str[i].str;
} }
}
return ""; return "";
} }
static struct { static struct
{
vfo_t vfo; vfo_t vfo;
const char *str; const char *str;
} vfo_str[] = { } vfo_str[] =
{
{ RIG_VFO_A, "VFOA" }, { RIG_VFO_A, "VFOA" },
{ RIG_VFO_B, "VFOB" }, { RIG_VFO_B, "VFOB" },
{ RIG_VFO_C, "VFOC" }, { 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; vfo_str[i].str[0] != '\0'; i++) for (i = 0 ; vfo_str[i].str[0] != '\0'; i++)
if (!strcmp(s, vfo_str[i].str)) { {
if (!strcmp(s, vfo_str[i].str))
{
return vfo_str[i].vfo; return vfo_str[i].vfo;
} }
}
return RIG_VFO_NONE; return RIG_VFO_NONE;
} }
@ -417,23 +450,29 @@ const char * HAMLIB_API rig_strvfo(vfo_t vfo)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (vfo == RIG_VFO_NONE) { if (vfo == RIG_VFO_NONE)
{
return ""; return "";
} }
for (i = 0 ; vfo_str[i].str[0] != '\0'; i++) for (i = 0 ; vfo_str[i].str[0] != '\0'; i++)
if (vfo == vfo_str[i].vfo) { {
if (vfo == vfo_str[i].vfo)
{
return vfo_str[i].str; return vfo_str[i].str;
} }
}
return ""; return "";
} }
static struct { static struct
{
setting_t func; setting_t func;
const char *str; const char *str;
} func_str[] = { } func_str[] =
{
{ RIG_FUNC_FAGC, "FAGC" }, { RIG_FUNC_FAGC, "FAGC" },
{ RIG_FUNC_NB, "NB" }, { RIG_FUNC_NB, "NB" },
{ RIG_FUNC_COMP, "COMP" }, { RIG_FUNC_COMP, "COMP" },
@ -475,7 +514,7 @@ static struct {
* \param s input alpha string * \param s input alpha string
* \return RIG_FUNC_... * \return RIG_FUNC_...
* *
* \sa rig_func_e * \sa rig_func_e()
*/ */
setting_t HAMLIB_API rig_parse_func(const char *s) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; func_str[i].str[0] != '\0'; i++) for (i = 0 ; func_str[i].str[0] != '\0'; i++)
if (!strcmp(s, func_str[i].str)) { {
if (!strcmp(s, func_str[i].str))
{
return func_str[i].func; return func_str[i].func;
} }
}
return RIG_FUNC_NONE; return RIG_FUNC_NONE;
} }
@ -497,7 +539,7 @@ setting_t HAMLIB_API rig_parse_func(const char *s)
* \param func RIG_FUNC_... * \param func RIG_FUNC_...
* \return alpha string * \return alpha string
* *
* \sa rig_func_e * \sa rig_func_e()
*/ */
const char * HAMLIB_API rig_strfunc(setting_t func) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (func == RIG_FUNC_NONE) { if (func == RIG_FUNC_NONE)
{
return ""; return "";
} }
for (i = 0; func_str[i].str[0] != '\0'; i++) for (i = 0; func_str[i].str[0] != '\0'; i++)
if (func == func_str[i].func) { {
if (func == func_str[i].func)
{
return func_str[i].str; return func_str[i].str;
} }
}
return ""; return "";
} }
static struct { static struct
{
setting_t level; setting_t level;
const char *str; const char *str;
} level_str[] = { } level_str[] =
{
{ RIG_LEVEL_PREAMP, "PREAMP" }, { RIG_LEVEL_PREAMP, "PREAMP" },
{ RIG_LEVEL_ATT, "ATT" }, { RIG_LEVEL_ATT, "ATT" },
{ RIG_LEVEL_VOX, "VOX" }, { RIG_LEVEL_VOX, "VOX" },
@ -562,7 +610,7 @@ static struct {
* \param s input alpha string * \param s input alpha string
* \return RIG_LEVEL_... * \return RIG_LEVEL_...
* *
* \sa rig_level_e * \sa rig_level_e()
*/ */
setting_t HAMLIB_API rig_parse_level(const char *s) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; level_str[i].str[0] != '\0'; i++) for (i = 0 ; level_str[i].str[0] != '\0'; i++)
if (!strcmp(s, level_str[i].str)) { {
if (!strcmp(s, level_str[i].str))
{
return level_str[i].level; return level_str[i].level;
} }
}
return RIG_LEVEL_NONE; return RIG_LEVEL_NONE;
} }
@ -584,7 +635,7 @@ setting_t HAMLIB_API rig_parse_level(const char *s)
* \param level RIG_LEVEL_... * \param level RIG_LEVEL_...
* \return alpha string * \return alpha string
* *
* \sa rig_level_e * \sa rig_level_e()
*/ */
const char * HAMLIB_API rig_strlevel(setting_t level) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (level == RIG_LEVEL_NONE) { if (level == RIG_LEVEL_NONE)
{
return ""; return "";
} }
for (i = 0; level_str[i].str[0] != '\0'; i++) for (i = 0; level_str[i].str[0] != '\0'; i++)
if (level == level_str[i].level) { {
if (level == level_str[i].level)
{
return level_str[i].str; return level_str[i].str;
} }
}
return ""; return "";
} }
static struct { static struct
{
setting_t parm; setting_t parm;
const char *str; const char *str;
} parm_str[] = { } parm_str[] =
{
{ RIG_PARM_ANN, "ANN" }, { RIG_PARM_ANN, "ANN" },
{ RIG_PARM_APO, "APO" }, { RIG_PARM_APO, "APO" },
{ RIG_PARM_BACKLIGHT, "BACKLIGHT" }, { RIG_PARM_BACKLIGHT, "BACKLIGHT" },
@ -625,7 +682,7 @@ static struct {
* \param s input alpha string * \param s input alpha string
* \return RIG_PARM_... * \return RIG_PARM_...
* *
* \sa rig_parm_e * \sa rig_parm_e()
*/ */
setting_t HAMLIB_API rig_parse_parm(const char *s) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; parm_str[i].str[0] != '\0'; i++) for (i = 0 ; parm_str[i].str[0] != '\0'; i++)
if (!strcmp(s, parm_str[i].str)) { {
if (!strcmp(s, parm_str[i].str))
{
return parm_str[i].parm; return parm_str[i].parm;
} }
}
return RIG_PARM_NONE; return RIG_PARM_NONE;
} }
@ -647,7 +707,7 @@ setting_t HAMLIB_API rig_parse_parm(const char *s)
* \param parm RIG_PARM_... * \param parm RIG_PARM_...
* \return alpha string * \return alpha string
* *
* \sa rig_parm_e * \sa rig_parm_e()
*/ */
const char * HAMLIB_API rig_strparm(setting_t parm) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (parm == RIG_PARM_NONE) { if (parm == RIG_PARM_NONE)
{
return ""; return "";
} }
for (i = 0; parm_str[i].str[0] != '\0'; i++) for (i = 0; parm_str[i].str[0] != '\0'; i++)
if (parm == parm_str[i].parm) { {
if (parm == parm_str[i].parm)
{
return parm_str[i].str; return parm_str[i].str;
} }
}
return ""; return "";
} }
static struct { static struct
{
vfo_op_t vfo_op; vfo_op_t vfo_op;
const char *str; const char *str;
} vfo_op_str[] = { } vfo_op_str[] =
{
{ RIG_OP_CPY, "CPY" }, { RIG_OP_CPY, "CPY" },
{ RIG_OP_XCHG, "XCHG" }, { RIG_OP_XCHG, "XCHG" },
{ RIG_OP_FROM_VFO, "FROM_VFO" }, { RIG_OP_FROM_VFO, "FROM_VFO" },
@ -694,7 +760,7 @@ static struct {
* \param s alpha string * \param s alpha string
* \return RIG_OP_... * \return RIG_OP_...
* *
* \sa vfo_op_t * \sa vfo_op_t()
*/ */
vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; vfo_op_str[i].str[0] != '\0'; i++) for (i = 0 ; vfo_op_str[i].str[0] != '\0'; i++)
if (!strcmp(s, vfo_op_str[i].str)) { {
if (!strcmp(s, vfo_op_str[i].str))
{
return vfo_op_str[i].vfo_op; return vfo_op_str[i].vfo_op;
} }
}
return RIG_OP_NONE; return RIG_OP_NONE;
} }
@ -716,7 +785,7 @@ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s)
* \param op RIG_OP_... * \param op RIG_OP_...
* \return alpha string * \return alpha string
* *
* \sa vfo_op_t * \sa vfo_op_t()
*/ */
const char * HAMLIB_API rig_strvfop(vfo_op_t op) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (op == RIG_OP_NONE) { if (op == RIG_OP_NONE)
{
return ""; return "";
} }
for (i = 0; vfo_op_str[i].str[0] != '\0'; i++) for (i = 0; vfo_op_str[i].str[0] != '\0'; i++)
if (op == vfo_op_str[i].vfo_op) { { if (op == vfo_op_str[i].vfo_op)
{
return vfo_op_str[i].str; return vfo_op_str[i].str;
} }
}
return ""; return "";
} }
static struct { static struct
{
scan_t rscan; scan_t rscan;
const char *str; const char *str;
} scan_str[] = { } scan_str[] =
{
{ RIG_SCAN_STOP, "STOP" }, { RIG_SCAN_STOP, "STOP" },
{ RIG_SCAN_MEM, "MEM" }, { RIG_SCAN_MEM, "MEM" },
{ RIG_SCAN_SLCT, "SLCT" }, { RIG_SCAN_SLCT, "SLCT" },
@ -759,7 +833,7 @@ static struct {
* \param s alpha string * \param s alpha string
* \return RIG_SCAN_... * \return RIG_SCAN_...
* *
* \sa scan_t * \sa scan_t()
*/ */
scan_t HAMLIB_API rig_parse_scan(const char *s) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; scan_str[i].str[0] != '\0'; i++) { for (i = 0 ; scan_str[i].str[0] != '\0'; i++)
if (strcmp(s, scan_str[i].str) == 0) { {
if (strcmp(s, scan_str[i].str) == 0)
{
return scan_str[i].rscan; return scan_str[i].rscan;
} }
} }
@ -782,7 +858,7 @@ scan_t HAMLIB_API rig_parse_scan(const char *s)
* \param rscan RIG_SCAN_... * \param rscan RIG_SCAN_...
* \return alpha string * \return alpha string
* *
* \sa scan_t * \sa scan_t()
*/ */
const char * HAMLIB_API rig_strscan(scan_t rscan) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (rscan == RIG_SCAN_NONE) { if (rscan == RIG_SCAN_NONE)
{
return ""; return "";
} }
for (i = 0; scan_str[i].str[0] != '\0'; i++) 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 scan_str[i].str;
} }
}
return ""; return "";
} }
@ -812,7 +891,8 @@ const char * HAMLIB_API rig_strptrshift(rptr_shift_t shift)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (shift) { switch (shift)
{
case RIG_RPT_SHIFT_MINUS: case RIG_RPT_SHIFT_MINUS:
return "-"; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (strcmp(s, "+") == 0) { if (strcmp(s, "+") == 0)
{
return RIG_RPT_SHIFT_PLUS; return RIG_RPT_SHIFT_PLUS;
} else if (strcmp(s, "-") == 0) { }
else if (strcmp(s, "-") == 0)
{
return RIG_RPT_SHIFT_MINUS; return RIG_RPT_SHIFT_MINUS;
} else { }
else
{
return RIG_RPT_SHIFT_NONE; return RIG_RPT_SHIFT_NONE;
} }
} }
static struct { static struct
{
chan_type_t mtype; chan_type_t mtype;
const char *str; const char *str;
} mtype_str[] = { } mtype_str[] =
{
{ RIG_MTYPE_MEM, "MEM" }, { RIG_MTYPE_MEM, "MEM" },
{ RIG_MTYPE_EDGE, "EDGE" }, { RIG_MTYPE_EDGE, "EDGE" },
{ RIG_MTYPE_CALL, "CALL" }, { RIG_MTYPE_CALL, "CALL" },
@ -866,7 +953,7 @@ static struct {
* \param s alpha string * \param s alpha string
* \return RIG_MTYPE_... * \return RIG_MTYPE_...
* *
* \sa chan_type_t * \sa chan_type_t()
*/ */
chan_type_t HAMLIB_API rig_parse_mtype(const char *s) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; mtype_str[i].str[0] != '\0'; i++) { for (i = 0 ; mtype_str[i].str[0] != '\0'; i++)
if (strcmp(s, mtype_str[i].str) == 0) { {
if (strcmp(s, mtype_str[i].str) == 0)
{
return mtype_str[i].mtype; return mtype_str[i].mtype;
} }
} }
@ -889,7 +978,7 @@ chan_type_t HAMLIB_API rig_parse_mtype(const char *s)
* \param mtype RIG_MTYPE_... * \param mtype RIG_MTYPE_...
* \return alpha string * \return alpha string
* *
* \sa chan_type_t * \sa chan_type_t()
*/ */
const char * HAMLIB_API rig_strmtype(chan_type_t mtype) 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (mtype == RIG_MTYPE_NONE) { if (mtype == RIG_MTYPE_NONE)
{
return ""; return "";
} }
for (i = 0; mtype_str[i].str[0] != '\0'; i++) for (i = 0; mtype_str[i].str[0] != '\0'; i++)
if (mtype == mtype_str[i].mtype) { {
if (mtype == mtype_str[i].mtype)
{
return mtype_str[i].str; return mtype_str[i].str;
} }
}
return ""; return "";
} }
@ -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__); 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, rig_debug(RIG_DEBUG_VERBOSE,
"%s: forced cache timeout\n", "%s: forced cache timeout\n",
__func__); __func__);
@ -945,13 +1039,16 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
t = timediff(&curr, tv); t = timediff(&curr, tv);
if (t < timeout) { if (t < timeout)
{
rig_debug(RIG_DEBUG_VERBOSE, rig_debug(RIG_DEBUG_VERBOSE,
"%s: using cache (%ld ms)\n", "%s: using cache (%ld ms)\n",
__func__, __func__,
t); t);
return 0; return 0;
} else { }
else
{
rig_debug(RIG_DEBUG_VERBOSE, rig_debug(RIG_DEBUG_VERBOSE,
"%s: cache timed out (%ld ms)\n", "%s: cache timed out (%ld ms)\n",
__func__, __func__,

Wyświetl plik

@ -57,7 +57,8 @@ extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[],
unsigned long long freq, unsigned long long freq,
unsigned bcd_len); 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); unsigned bcd_len);
/* /*
@ -67,7 +68,8 @@ extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[],
unsigned long long freq, unsigned long long freq,
unsigned bcd_len); 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); unsigned bcd_len);
extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t); extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
@ -84,6 +86,7 @@ extern int no_restore_ai;
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
# include <inttypes.h> # include <inttypes.h>
#endif #endif
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
# include <sys/time.h> # include <sys/time.h>
#endif #endif

Wyświetl plik

@ -45,16 +45,18 @@
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
#ifdef HAVE_NETINET_IN_H #ifdef HAVE_NETINET_IN_H
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#if HAVE_NETDB_H #if HAVE_NETDB_H
# include <netdb.h> # include <netdb.h>
#endif #endif
#ifdef HAVE_ARPA_INET_H #ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif
#if defined (HAVE_SYS_SOCKET_H) && defined (HAVE_SYS_IOCTL_H) #if defined (HAVE_SYS_SOCKET_H) && defined (HAVE_SYS_IOCTL_H)
# include <sys/socket.h> # include <sys/socket.h>
# include <sys/ioctl.h> # include <sys/ioctl.h>
@ -88,15 +90,19 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg)
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS, | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, e, NULL,
e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language // Default language
(LPTSTR)&lpMsgBuf, (LPTSTR)&lpMsgBuf,
0, 0,
NULL)) { NULL))
{
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
} else { }
else
{
rig_debug(lvl, "%s: Network error %d\n", msg, e); rig_debug(lvl, "%s: Network error %d\n", msg, e);
} }
@ -131,44 +137,56 @@ int network_open(hamlib_port_t *rp, int default_port)
#ifdef __MINGW32__ #ifdef __MINGW32__
WSADATA wsadata; WSADATA wsadata;
if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR)
{
rig_debug(RIG_DEBUG_ERR, "%s: error creating socket\n", __func__); rig_debug(RIG_DEBUG_ERR, "%s: error creating socket\n", __func__);
return -RIG_EIO; return -RIG_EIO;
} }
#endif #endif
if (!rp) { if (!rp)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC; hints.ai_family = PF_UNSPEC;
if (rp->type.rig == RIG_PORT_UDP_NETWORK) { if (rp->type.rig == RIG_PORT_UDP_NETWORK)
{
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
} else { }
else
{
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
} }
/* default of all local interfaces */ /* default of all local interfaces */
hoststr = NULL; hoststr = NULL;
if (rp->pathname[0] == ':') { if (rp->pathname[0] == ':')
{
portstr = rp->pathname + 1; portstr = rp->pathname + 1;
} else { }
if (strlen(rp->pathname)) { else
{
if (strlen(rp->pathname))
{
strncpy(hostname, rp->pathname, FILPATHLEN - 1); strncpy(hostname, rp->pathname, FILPATHLEN - 1);
hoststr = hostname; hoststr = hostname;
/* look for IPv6 numeric form [<addr>] */ /* look for IPv6 numeric form [<addr>] */
bracketstr1 = strchr(hoststr, '['); bracketstr1 = strchr(hoststr, '[');
bracketstr2 = strrchr(hoststr, ']'); bracketstr2 = strrchr(hoststr, ']');
if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1) { if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1)
{
hoststr = bracketstr1 + 1; hoststr = bracketstr1 + 1;
*bracketstr2 = '\0'; *bracketstr2 = '\0';
portstr = bracketstr2 + 1; /* possible port after ]: */ portstr = bracketstr2 + 1; /* possible port after ]: */
} else { }
else
{
bracketstr2 = NULL; bracketstr2 = NULL;
portstr = hoststr; /* possible port after : */ portstr = hoststr; /* possible port after : */
} }
@ -176,12 +194,14 @@ int network_open(hamlib_port_t *rp, int default_port)
/* search last ':' */ /* search last ':' */
portstr = strrchr(portstr, ':'); portstr = strrchr(portstr, ':');
if (portstr) { if (portstr)
{
*portstr++ = '\0'; *portstr++ = '\0';
} }
} }
if (!portstr) { if (!portstr)
{
sprintf(defaultportstr, "%d", default_port); sprintf(defaultportstr, "%d", default_port);
portstr = defaultportstr; portstr = defaultportstr;
} }
@ -189,7 +209,8 @@ int network_open(hamlib_port_t *rp, int default_port)
status = getaddrinfo(hoststr, portstr, &hints, &res); status = getaddrinfo(hoststr, portstr, &hints, &res);
if (status != 0) { if (status != 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: cannot get host \"%s\": %s\n", "%s: cannot get host \"%s\": %s\n",
__func__, __func__,
@ -205,16 +226,19 @@ int network_open(hamlib_port_t *rp, int default_port)
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif #endif
do { do
{
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (fd < 0) { if (fd < 0)
{
handle_error(RIG_DEBUG_ERR, "socket"); handle_error(RIG_DEBUG_ERR, "socket");
freeaddrinfo(saved_res); freeaddrinfo(saved_res);
return -RIG_EIO; return -RIG_EIO;
} }
if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0) { if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0)
{
break; break;
} }
@ -225,11 +249,13 @@ int network_open(hamlib_port_t *rp, int default_port)
#else #else
close(fd); close(fd);
#endif #endif
} while ((res = res->ai_next) != NULL); }
while ((res = res->ai_next) != NULL);
freeaddrinfo(saved_res); freeaddrinfo(saved_res);
if (NULL == res) { if (NULL == res)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: failed to connect to %s\n", "%s: failed to connect to %s\n",
__func__, __func__,
@ -260,20 +286,24 @@ void network_flush(hamlib_port_t *rp)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (;;) { for (;;)
{
#ifdef __MINGW32__ #ifdef __MINGW32__
ioctlsocket(rp->fd, FIONREAD, &len); ioctlsocket(rp->fd, FIONREAD, &len);
#else #else
ioctl(rp->fd, FIONREAD, &len); ioctl(rp->fd, FIONREAD, &len);
#endif #endif
if (len > 0) { if (len > 0)
{
len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE); len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE);
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_WARN,
"%s: network data cleared: %s\n", "%s: network data cleared: %s\n",
__func__, __func__,
buffer); buffer);
} else { }
else
{
break; break;
} }
} }
@ -289,7 +319,8 @@ int network_close(hamlib_port_t *rp)
#ifdef __MINGW32__ #ifdef __MINGW32__
ret = closesocket(rp->fd); ret = closesocket(rp->fd);
if (--wsstarted) { if (--wsstarted)
{
WSACleanup(); WSACleanup();
} }

Wyświetl plik

@ -28,7 +28,8 @@
*/ */
/* The status pin functions operate in terms of these bits: */ /* The status pin functions operate in terms of these bits: */
enum ieee1284_status_bits { enum ieee1284_status_bits
{
S1284_NFAULT = 0x08, S1284_NFAULT = 0x08,
S1284_SELECT = 0x10, S1284_SELECT = 0x10,
S1284_PERROR = 0x20, S1284_PERROR = 0x20,
@ -39,7 +40,8 @@ enum ieee1284_status_bits {
}; };
/* The control pin functions operate in terms of these bits: */ /* The control pin functions operate in terms of these bits: */
enum ieee1284_control_bits { enum ieee1284_control_bits
{
C1284_NSTROBE = 0x01, C1284_NSTROBE = 0x01,
C1284_NAUTOFD = 0x02, C1284_NAUTOFD = 0x02,
C1284_NINIT = 0x04, C1284_NINIT = 0x04,

Wyświetl plik

@ -41,6 +41,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
@ -53,9 +54,11 @@
# include <windows.h> # include <windows.h>
# include "par_nt.h" # include "par_nt.h"
#endif #endif
#ifdef HAVE_WINIOCTL_H #ifdef HAVE_WINIOCTL_H
# include <winioctl.h> # include <winioctl.h>
#endif #endif
#ifdef HAVE_WINBASE_H #ifdef HAVE_WINBASE_H
# include <winbase.h> # include <winbase.h>
#endif #endif
@ -135,7 +138,8 @@ int par_open(hamlib_port_t *port)
HANDLE handle; HANDLE handle;
#endif #endif
if (!port->pathname[0]) { if (!port->pathname[0])
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -143,7 +147,8 @@ int par_open(hamlib_port_t *port)
/* TODO: open with O_NONBLOCK ? */ /* TODO: open with O_NONBLOCK ? */
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) { if (fd < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n", "%s: opening device \"%s\": %s\n",
__func__, __func__,
@ -154,7 +159,8 @@ int par_open(hamlib_port_t *port)
mode = IEEE1284_MODE_COMPAT; mode = IEEE1284_MODE_COMPAT;
if (ioctl(fd, PPSETMODE, &mode) != 0) { if (ioctl(fd, PPSETMODE, &mode) != 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n", rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n",
__func__, __func__,
port->pathname, port->pathname,
@ -167,7 +173,8 @@ int par_open(hamlib_port_t *port)
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) { if (fd < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n", "%s: opening device \"%s\": %s\n",
__func__, __func__,
@ -180,17 +187,21 @@ int par_open(hamlib_port_t *port)
handle = CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE, handle = CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL); 0, NULL, OPEN_EXISTING, 0, NULL);
if (handle == INVALID_HANDLE_VALUE) { if (handle == INVALID_HANDLE_VALUE)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\"\n", "%s: opening device \"%s\"\n",
__func__, __func__,
port->pathname); port->pathname);
CloseHandle(handle); CloseHandle(handle);
return -RIG_EIO; return -RIG_EIO;
} else { }
else
{
fd = _open_osfhandle((intptr_t)handle, _O_APPEND | _O_RDONLY); fd = _open_osfhandle((intptr_t)handle, _O_APPEND | _O_RDONLY);
if (fd == -1) { if (fd == -1)
{
return -RIG_EIO; return -RIG_EIO;
} }
} }
@ -246,9 +257,11 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
handle = _get_osfhandle(port->fd); handle = _get_osfhandle(port->fd);
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE)
{
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_DATA, &data, sizeof(data), if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_DATA, &data, sizeof(data),
NULL, 0, (LPDWORD)&dummy, NULL))) { NULL, 0, (LPDWORD)&dummy, NULL)))
{
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
return -RIG_EIO; 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); 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_STATUS, NULL, 0, &ret, {
sizeof(ret), (LPDWORD)&dummy, NULL))) { if (!(DeviceIoControl((HANDLE)handle,
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); NT_IOCTL_STATUS,
NULL,
0,
&ret,
sizeof(ret),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; 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; unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
status = ioctl(port->fd, PPWCONTROL, &ctrl); status = ioctl(port->fd, PPWCONTROL, &ctrl);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(PPWCONTROL) failed: %s\n", "%s: ioctl(PPWCONTROL) failed: %s\n",
__func__, __func__,
@ -339,7 +364,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
| C1284_NSELECTIN); | C1284_NSELECTIN);
intptr_t handle; intptr_t handle;
if (ctr & 0x20) { if (ctr & 0x20)
{
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_WARN,
"%s: use ieee1284_data_dir to change data line direction!\n", "%s: use ieee1284_data_dir to change data line direction!\n",
__func__); __func__);
@ -351,7 +377,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
handle = _get_osfhandle(port->fd); handle = _get_osfhandle(port->fd);
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE)
{
if (!(DeviceIoControl((HANDLE)handle, if (!(DeviceIoControl((HANDLE)handle,
NT_IOCTL_CONTROL, NT_IOCTL_CONTROL,
&ctr, &ctr,
@ -359,7 +386,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
&dummyc, &dummyc,
sizeof(dummyc), sizeof(dummyc),
(LPDWORD)&dummy, (LPDWORD)&dummy,
NULL))) { NULL)))
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: frob_control: DeviceIoControl failed!\n", "%s: frob_control: DeviceIoControl failed!\n",
__func__); __func__);
@ -388,7 +416,8 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
unsigned char ctrl; unsigned char ctrl;
status = ioctl(port->fd, PPRCONTROL, &ctrl); status = ioctl(port->fd, PPRCONTROL, &ctrl);
if (status < 0) { if (status < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(PPRCONTROL) failed: %s\n", "%s: ioctl(PPRCONTROL) failed: %s\n",
__func__, __func__,
@ -411,10 +440,21 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
handle = _get_osfhandle(port->fd); handle = _get_osfhandle(port->fd);
if (handle != (intptr_t)INVALID_HANDLE_VALUE) { if (handle != (intptr_t)INVALID_HANDLE_VALUE)
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, NULL, 0, &ret, {
sizeof(ret), (LPDWORD)&dummy, NULL))) { if (!(DeviceIoControl((HANDLE)handle,
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); NT_IOCTL_CONTROL,
NULL,
0,
&ret,
sizeof(ret),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; 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 #ifdef HAVE_LINUX_PPDEV_H
int ret; int ret;
unsigned char sta; unsigned char sta;
ret = ioctl(port->fd, PPRSTATUS, &sta); ret = ioctl(port->fd, PPRSTATUS, &sta);
*status = sta ^ SP_ACTIVE_LOW_BITS; *status = sta ^ SP_ACTIVE_LOW_BITS;
return ret == 0 ? RIG_OK : -RIG_EIO; return ret == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
int ret; int ret;
unsigned char sta; unsigned char sta;
ret = ioctl(port->fd, PPIGSTATUS, &sta); ret = ioctl(port->fd, PPIGSTATUS, &sta);
*status = sta ^ SP_ACTIVE_LOW_BITS; *status = sta ^ SP_ACTIVE_LOW_BITS;
return ret == 0 ? RIG_OK : -RIG_EIO; return ret == 0 ? RIG_OK : -RIG_EIO;
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
unsigned char ret; unsigned char ret;
unsigned int dummy; 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); 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_STATUS, NULL, 0, &ret, {
sizeof(ret), (LPDWORD)&dummy, NULL))) { if (!(DeviceIoControl((HANDLE)handle,
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); NT_IOCTL_STATUS,
NULL,
0,
&ret,
sizeof(ret),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; return -RIG_EIO;
} }
} }
@ -486,7 +541,8 @@ int HAMLIB_API par_lock(hamlib_port_t *port)
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPCLAIM) < 0) { if (ioctl(port->fd, PPCLAIM) < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: claiming device \"%s\": %s\n", "%s: claiming device \"%s\": %s\n",
__func__, __func__,
@ -517,7 +573,8 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPRELEASE) < 0) { if (ioctl(port->fd, PPRELEASE) < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: releasing device \"%s\": %s\n", "%s: releasing device \"%s\": %s\n",
__func__, __func__,
@ -540,6 +597,7 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
#ifndef PARPORT_CONTROL_STROBE #ifndef PARPORT_CONTROL_STROBE
# define PARPORT_CONTROL_STROBE 0x1 # define PARPORT_CONTROL_STROBE 0x1
#endif #endif
#ifndef PARPORT_CONTROL_INIT #ifndef PARPORT_CONTROL_INIT
# define PARPORT_CONTROL_INIT 0x4 # define PARPORT_CONTROL_INIT 0x4
#endif #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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) { switch (p->type.ptt)
case RIG_PTT_PARALLEL: { {
case RIG_PTT_PARALLEL:
{
unsigned char ctl; unsigned char ctl;
int status; int status;
par_lock(p); par_lock(p);
status = par_read_control(p, &ctl); status = par_read_control(p, &ctl);
if (status != RIG_OK) { if (status != RIG_OK)
{
return status; return status;
} }
@ -573,9 +634,12 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
/* TODO: kill parm.parallel.pin? */ /* TODO: kill parm.parallel.pin? */
/* PTT keying - /INIT bit (pin 16) (inverted) */ /* PTT keying - /INIT bit (pin 16) (inverted) */
if (pttx == RIG_PTT_ON) { if (pttx == RIG_PTT_ON)
{
ctl |= PARPORT_CONTROL_INIT; ctl |= PARPORT_CONTROL_INIT;
} else { }
else
{
ctl &= ~PARPORT_CONTROL_INIT; ctl &= ~PARPORT_CONTROL_INIT;
} }
@ -606,8 +670,10 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) { switch (p->type.ptt)
case RIG_PTT_PARALLEL: { {
case RIG_PTT_PARALLEL:
{
unsigned char ctl; unsigned char ctl;
int status; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.dcd) { switch (p->type.dcd)
case RIG_DCD_PARALLEL: { {
case RIG_DCD_PARALLEL:
{
unsigned char reg; unsigned char reg;
int status; int status;

Wyświetl plik

@ -33,12 +33,15 @@
#ifndef PARPORT_CONTROL_STROBE #ifndef PARPORT_CONTROL_STROBE
# define PARPORT_CONTROL_STROBE 0x1 # define PARPORT_CONTROL_STROBE 0x1
#endif #endif
#ifndef PARPORT_CONTROL_AUTOFD #ifndef PARPORT_CONTROL_AUTOFD
# define PARPORT_CONTROL_AUTOFD 0x2 # define PARPORT_CONTROL_AUTOFD 0x2
#endif #endif
#ifndef PARPORT_CONTROL_INIT #ifndef PARPORT_CONTROL_INIT
# define PARPORT_CONTROL_INIT 0x4 # define PARPORT_CONTROL_INIT 0x4
#endif #endif
#ifndef PARPORT_CONTROL_SELECT #ifndef PARPORT_CONTROL_SELECT
# define PARPORT_CONTROL_SELECT 0x8 # define PARPORT_CONTROL_SELECT 0x8
#endif #endif
@ -46,15 +49,19 @@
#ifndef PARPORT_STATUS_ERROR #ifndef PARPORT_STATUS_ERROR
# define PARPORT_STATUS_ERROR 0x8 # define PARPORT_STATUS_ERROR 0x8
#endif #endif
#ifndef PARPORT_STATUS_SELECT #ifndef PARPORT_STATUS_SELECT
# define PARPORT_STATUS_SELECT 0x10 # define PARPORT_STATUS_SELECT 0x10
#endif #endif
#ifndef PARPORT_STATUS_PAPEROUT #ifndef PARPORT_STATUS_PAPEROUT
# define PARPORT_STATUS_PAPEROUT 0x20 # define PARPORT_STATUS_PAPEROUT 0x20
#endif #endif
#ifndef PARPORT_STATUS_ACK #ifndef PARPORT_STATUS_ACK
# define PARPORT_STATUS_ACK 0x40 # define PARPORT_STATUS_ACK 0x40
#endif #endif
#ifndef PARPORT_STATUS_BUSY #ifndef PARPORT_STATUS_BUSY
# define PARPORT_STATUS_BUSY 0x80 # define PARPORT_STATUS_BUSY 0x80
#endif #endif

Wyświetl plik

@ -93,19 +93,22 @@ DEFINE_INITRIG_BACKEND(winradio);
#endif #endif
/*! \def rig_backend_list /**
* \def rig_backend_list
* \brief Static list of rig models. * \brief Static list of rig models.
* *
* This is a NULL terminated list of available rig backends. Each entry * This is a NULL terminated list of available rig backends. Each entry in
* in the list consists of two fields: The branch number, which is an integer, * the list consists of two fields: The branch number, which is an integer,
* and the branch name, which is a character string. * and the branch name, which is a character string.
*/ */
static struct { static struct
{
int be_num; int be_num;
const char *be_name; const char *be_name;
int (* be_init_all)(void *handle); int (* be_init_all)(void *handle);
rig_model_t (* be_probe_all)(hamlib_port_t *, rig_probe_func_t, rig_ptr_t); rig_model_t (* be_probe_all)(hamlib_port_t *, rig_probe_func_t, rig_ptr_t);
} rig_backend_list[RIG_BACKEND_MAX] = { } rig_backend_list[RIG_BACKEND_MAX] =
{
{ RIG_DUMMY, RIG_BACKEND_DUMMY, RIG_FUNCNAMA(dummy) }, { RIG_DUMMY, RIG_BACKEND_DUMMY, RIG_FUNCNAMA(dummy) },
{ RIG_YAESU, RIG_BACKEND_YAESU, RIG_FUNCNAM(yaesu) }, { RIG_YAESU, RIG_BACKEND_YAESU, RIG_FUNCNAM(yaesu) },
{ RIG_KENWOOD, RIG_BACKEND_KENWOOD, RIG_FUNCNAM(kenwood) }, { RIG_KENWOOD, RIG_BACKEND_KENWOOD, RIG_FUNCNAM(kenwood) },
@ -144,7 +147,8 @@ static struct {
* This struct to keep track of known rig models. * This struct to keep track of known rig models.
* It is chained, and used in a hash table, see below. * It is chained, and used in a hash table, see below.
*/ */
struct rig_list { struct rig_list
{
const struct rig_caps *caps; const struct rig_caps *caps;
struct rig_list *next; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!caps) { if (!caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -185,7 +190,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
#ifndef DONT_WANT_DUP_CHECK #ifndef DONT_WANT_DUP_CHECK
if (rig_get_caps(caps->rig_model) != NULL) { if (rig_get_caps(caps->rig_model) != NULL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -193,7 +199,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps)
p = (struct rig_list *)malloc(sizeof(struct rig_list)); p = (struct rig_list *)malloc(sizeof(struct rig_list));
if (!p) { if (!p)
{
return -RIG_ENOMEM; return -RIG_ENOMEM;
} }
@ -215,8 +222,10 @@ const struct rig_caps *HAMLIB_API rig_get_caps(rig_model_t rig_model)
{ {
struct rig_list *p; struct rig_list *p;
for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next) { for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next)
if (p->caps->rig_model == rig_model) { {
if (p->caps->rig_model == rig_model)
{
return p->caps; return p->caps;
} }
} }
@ -233,9 +242,11 @@ static int rig_lookup_backend(rig_model_t rig_model)
{ {
int i; 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) == if (RIG_BACKEND_NUM(rig_model) ==
rig_backend_list[i].be_num) { rig_backend_list[i].be_num)
{
return i; return i;
} }
} }
@ -258,7 +269,8 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model)
/* already loaded ? */ /* already loaded ? */
caps = rig_get_caps(rig_model); caps = rig_get_caps(rig_model);
if (caps) { if (caps)
{
return RIG_OK; return RIG_OK;
} }
@ -267,10 +279,12 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model)
/* /*
* Never heard about this backend family! * Never heard about this backend family!
*/ */
if (be_idx == -1) { if (be_idx == -1)
rig_debug(RIG_DEBUG_VERBOSE, "rig_check_backend: unsupported " {
"backend %d for model %d\n", rig_debug(RIG_DEBUG_VERBOSE,
RIG_BACKEND_NUM(rig_model), rig_model); "rig_check_backend: unsupported backend %d for model %d\n",
RIG_BACKEND_NUM(rig_model),
rig_model);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -289,11 +303,16 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model)
hval = HASH_FUNC(rig_model); hval = HASH_FUNC(rig_model);
q = NULL; q = NULL;
for (p = rig_hash_table[hval]; p; p = p->next) { for (p = rig_hash_table[hval]; p; p = p->next)
if (p->caps->rig_model == rig_model) { {
if (q == NULL) { if (p->caps->rig_model == rig_model)
{
if (q == NULL)
{
rig_hash_table[hval] = p->next; rig_hash_table[hval] = p->next;
} else { }
else
{
q->next = p->next; q->next = p->next;
} }
@ -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 * executes cfunc on all the elements stored in the rig hash list
*/ */
int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *, 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; struct rig_list *p;
int i; int i;
if (!cfunc) { if (!cfunc)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
for (i = 0; i < RIGLSTHASHSZ; i++) { for (i = 0; i < RIGLSTHASHSZ; i++)
{
struct rig_list *next = NULL; struct rig_list *next = NULL;
for (p = rig_hash_table[i]; p; p = next) { for (p = rig_hash_table[i]; p; p = next)
{
next = p->next; /* read before call in case it is unregistered */ next = p->next; /* read before call in case it is unregistered */
if ((*cfunc)(p->caps, data) == 0) { if ((*cfunc)(p->caps, data) == 0)
{
return RIG_OK; return RIG_OK;
} }
} }
@ -336,13 +360,17 @@ int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *,
return RIG_OK; 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_ptr_t data)
{ {
rig_debug(RIG_DEBUG_TRACE, "Found rig, model %d\n", model); rig_debug(RIG_DEBUG_TRACE, "Found rig, model %d\n", model);
return RIG_OK; return RIG_OK;
} }
/* /*
* rig_probe_first * rig_probe_first
* called straight by rig_probe * called straight by rig_probe
@ -352,13 +380,16 @@ rig_model_t rig_probe_first(hamlib_port_t *p)
int i; int i;
rig_model_t model; rig_model_t model;
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++)
if (rig_backend_list[i].be_probe_all) { {
if (rig_backend_list[i].be_probe_all)
{
model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe, model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe,
(rig_ptr_t)NULL); (rig_ptr_t)NULL);
/* stop at first one found */ /* stop at first one found */
if (model != RIG_MODEL_NONE) { if (model != RIG_MODEL_NONE)
{
return model; return model;
} }
} }
@ -367,17 +398,21 @@ rig_model_t rig_probe_first(hamlib_port_t *p)
return RIG_MODEL_NONE; return RIG_MODEL_NONE;
} }
/* /*
* rig_probe_all_backends * rig_probe_all_backends
* called straight by rig_probe_all * called straight by rig_probe_all
*/ */
int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc, int rig_probe_all_backends(hamlib_port_t *p,
rig_probe_func_t cfunc,
rig_ptr_t data) rig_ptr_t data)
{ {
int i; 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_list[i].be_probe_all) { {
if (rig_backend_list[i].be_probe_all)
{
(*rig_backend_list[i].be_probe_all)(p, cfunc, data); (*rig_backend_list[i].be_probe_all)(p, cfunc, data);
} }
} }
@ -390,7 +425,8 @@ int rig_load_all_backends()
{ {
int i; 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); 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); typedef int (*backend_init_t)(rig_ptr_t);
/* /*
* rig_load_backend * rig_load_backend
*/ */
@ -408,13 +445,18 @@ int HAMLIB_API rig_load_backend(const char *be_name)
int i; int i;
backend_init_t be_init; backend_init_t be_init;
for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++)
if (!strcmp(be_name, rig_backend_list[i].be_name)) { {
if (!strcmp(be_name, rig_backend_list[i].be_name))
{
be_init = rig_backend_list[i].be_init_all ; be_init = rig_backend_list[i].be_init_all ;
if (be_init) { if (be_init)
{
return (*be_init)(NULL); return (*be_init)(NULL);
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
} }

1208
src/rig.c

Plik diff jest za duży Load Diff

Wyświetl plik

@ -48,7 +48,8 @@
/* /*
* Configuration options available in the rot->state struct. * Configuration options available in the rot->state struct.
*/ */
static const struct confparams rotfrontend_cfg_params[] = { static const struct confparams rotfrontend_cfg_params[] =
{
{ {
TOK_PATHNAME, "rot_pathname", "Rig path name", TOK_PATHNAME, "rot_pathname", "Rig path name",
"Path name to the device file of the rotator", "Path name to the device file of the rotator",
@ -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", TOK_SERIAL_SPEED, "serial_speed", "Serial speed",
"Serial port baud rate", "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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (token) { switch (token)
{
case TOK_PATHNAME: case TOK_PATHNAME:
strncpy(rs->rotport.pathname, val, FILPATHLEN - 1); strncpy(rs->rotport.pathname, val, FILPATHLEN - 1);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -161,7 +165,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -169,7 +174,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -177,7 +183,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_RETRY: case TOK_RETRY:
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -185,11 +192,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -197,11 +206,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -209,11 +220,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (1 != sscanf(val, "%d", &val_i)) { if (1 != sscanf(val, "%d", &val_i))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -221,38 +234,58 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val)
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (!strcmp(val, "None")) { if (!strcmp(val, "None"))
{
rs->rotport.parm.serial.parity = RIG_PARITY_NONE; rs->rotport.parm.serial.parity = RIG_PARITY_NONE;
} else if (!strcmp(val, "Odd")) { }
else if (!strcmp(val, "Odd"))
{
rs->rotport.parm.serial.parity = RIG_PARITY_ODD; rs->rotport.parm.serial.parity = RIG_PARITY_ODD;
} else if (!strcmp(val, "Even")) { }
else if (!strcmp(val, "Even"))
{
rs->rotport.parm.serial.parity = RIG_PARITY_EVEN; rs->rotport.parm.serial.parity = RIG_PARITY_EVEN;
} else if (!strcmp(val, "Mark")) { }
else if (!strcmp(val, "Mark"))
{
rs->rotport.parm.serial.parity = RIG_PARITY_MARK; rs->rotport.parm.serial.parity = RIG_PARITY_MARK;
} else if (!strcmp(val, "Space")) { }
else if (!strcmp(val, "Space"))
{
rs->rotport.parm.serial.parity = RIG_PARITY_SPACE; rs->rotport.parm.serial.parity = RIG_PARITY_SPACE;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (!strcmp(val, "None")) { if (!strcmp(val, "None"))
{
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_NONE; rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
} else if (!strcmp(val, "XONXOFF")) { }
else if (!strcmp(val, "XONXOFF"))
{
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF;
} else if (!strcmp(val, "Hardware")) { }
else if (!strcmp(val, "Hardware"))
{
rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
} else { }
else
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -298,7 +331,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (token) { switch (token)
{
case TOK_PATHNAME: case TOK_PATHNAME:
strcpy(val, rs->rotport.pathname); strcpy(val, rs->rotport.pathname);
break; break;
@ -320,7 +354,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -328,7 +363,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -336,7 +372,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -344,11 +381,13 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
switch (rs->rotport.parm.serial.parity) { switch (rs->rotport.parm.serial.parity)
{
case RIG_PARITY_NONE: case RIG_PARITY_NONE:
s = "None"; s = "None";
break; break;
@ -377,11 +416,13 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val)
break; break;
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rotport.type.rig != RIG_PORT_SERIAL) { if (rs->rotport.type.rig != RIG_PORT_SERIAL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
switch (rs->rotport.parm.serial.handshake) { switch (rs->rotport.parm.serial.handshake)
{
case RIG_HANDSHAKE_NONE: case RIG_HANDSHAKE_NONE:
s = "None"; s = "None";
break; 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 * start first with backend conf table, then finish with frontend table
*/ */
int HAMLIB_API rot_token_foreach(ROT *rot, 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) rig_ptr_t data)
{ {
const struct confparams *cfp; const struct confparams *cfp;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !cfunc) { if (!rot || !rot->caps || !cfunc)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) { for (cfp = rotfrontend_cfg_params; cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) { {
if ((*cfunc)(cfp, data) == 0)
{
return RIG_OK; return RIG_OK;
} }
} }
if (rot->caps->port_type == RIG_PORT_SERIAL) { if (rot->caps->port_type == RIG_PORT_SERIAL)
for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) { {
if ((*cfunc)(cfp, data) == 0) { for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++)
{
if ((*cfunc)(cfp, data) == 0)
{
return RIG_OK; return RIG_OK;
} }
} }
} }
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) { for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++)
if ((*cfunc)(cfp, data) == 0) { {
if ((*cfunc)(cfp, data) == 0)
{
return RIG_OK; 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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) { if (!rot || !rot->caps)
{
return NULL; return NULL;
} }
/* 0 returned for invalid format */ /* 0 returned for invalid format */
token = strtol(name, NULL, 0); token = strtol(name, NULL, 0);
for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) { for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) { {
if (!strcmp(cfp->name, name) || token == cfp->token)
{
return cfp; return cfp;
} }
} }
for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) { for (cfp = rotfrontend_cfg_params; cfp->name; cfp++)
if (!strcmp(cfp->name, name) || token == cfp->token) { {
if (!strcmp(cfp->name, name) || token == cfp->token)
{
return cfp; return cfp;
} }
} }
if (rot->caps->port_type == RIG_PORT_SERIAL) { 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) { for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++)
{
if (!strcmp(cfp->name, name) || token == cfp->token)
{
return cfp; return cfp;
} }
} }
@ -531,7 +589,8 @@ token_t HAMLIB_API rot_token_lookup(ROT *rot, const char *name)
cfp = rot_confparam_lookup(rot, name); cfp = rot_confparam_lookup(rot, name);
if (!cfp) { if (!cfp)
{
return RIG_CONF_END; 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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) { if (!rot || !rot->caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig_need_debug(RIG_DEBUG_VERBOSE)) { if (rig_need_debug(RIG_DEBUG_VERBOSE))
{
const struct confparams *cfp; const struct confparams *cfp;
char tokenstr[12]; char tokenstr[12];
sprintf(tokenstr, "%ld", token); sprintf(tokenstr, "%ld", token);
cfp = rot_confparam_lookup(rot, tokenstr); cfp = rot_confparam_lookup(rot, tokenstr);
if (!cfp) { if (!cfp)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
rot_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); 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); return frontrot_set_conf(rot, token, val);
} }
if (rot->caps->set_conf == NULL) { if (rot->caps->set_conf == NULL)
{
return -RIG_ENAVAIL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !val) { if (!rot || !rot->caps || !val)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (IS_TOKEN_FRONTEND(token)) { if (IS_TOKEN_FRONTEND(token))
{
return frontrot_get_conf(rot, token, val); return frontrot_get_conf(rot, token, val);
} }
if (rot->caps->get_conf == NULL) { if (rot->caps->get_conf == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }

Wyświetl plik

@ -83,21 +83,24 @@ DEFINE_INITROT_BACKEND(cnctrk);
DEFINE_INITROT_BACKEND(prosistel); DEFINE_INITROT_BACKEND(prosistel);
/*! \def ROT_BACKEND_LIST /**
* \def ROT_BACKEND_LIST
* \brief Static list of rotator models. * \brief Static list of rotator models.
* *
* This is a NULL terminated list of available rotator backends. Each entry * 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, * in the list consists of two fields: The branch number, which is an integer,
* and the branch name, which is a character string. * and the branch name, which is a character string.
* An external library, loaded dynamically, could add its own functions pointers * An external library, loaded dynamically, could add its own functions
* in this array. * pointers in this array.
*/ */
static struct { static struct
{
int be_num; int be_num;
const char *be_name; const char *be_name;
int (*be_init)(void *); int (*be_init)(void *);
rot_model_t (*be_probe)(hamlib_port_t *); rot_model_t (*be_probe)(hamlib_port_t *);
} rot_backend_list[ROT_BACKEND_MAX] = { } rot_backend_list[ROT_BACKEND_MAX] =
{
{ ROT_DUMMY, ROT_BACKEND_DUMMY, ROT_FUNCNAMA(dummy) }, { ROT_DUMMY, ROT_BACKEND_DUMMY, ROT_FUNCNAMA(dummy) },
{ ROT_EASYCOMM, ROT_BACKEND_EASYCOMM, ROT_FUNCNAMA(easycomm) }, { ROT_EASYCOMM, ROT_BACKEND_EASYCOMM, ROT_FUNCNAMA(easycomm) },
{ ROT_FODTRACK, ROT_BACKEND_FODTRACK, ROT_FUNCNAMA(fodtrack) }, { ROT_FODTRACK, ROT_BACKEND_FODTRACK, ROT_FUNCNAMA(fodtrack) },
@ -131,7 +134,8 @@ static struct {
* This struct to keep track of known rot models. * This struct to keep track of known rot models.
* It is chained, and used in a hash table, see below. * It is chained, and used in a hash table, see below.
*/ */
struct rot_list { struct rot_list
{
const struct rot_caps *caps; const struct rot_caps *caps;
struct rot_list *next; struct rot_list *next;
}; };
@ -159,7 +163,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
int hval; int hval;
struct rot_list *p; struct rot_list *p;
if (!caps) { if (!caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -167,7 +172,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
#ifndef DONT_WANT_DUP_CHECK #ifndef DONT_WANT_DUP_CHECK
if (rot_get_caps(caps->rot_model) != NULL) { if (rot_get_caps(caps->rot_model) != NULL)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -175,7 +181,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps)
p = (struct rot_list *)malloc(sizeof(struct rot_list)); p = (struct rot_list *)malloc(sizeof(struct rot_list));
if (!p) { if (!p)
{
return -RIG_ENOMEM; return -RIG_ENOMEM;
} }
@ -197,8 +204,10 @@ const struct rot_caps * HAMLIB_API rot_get_caps(rot_model_t rot_model)
{ {
struct rot_list *p; struct rot_list *p;
for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next) { for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next)
if (p->caps->rot_model == rot_model) { {
if (p->caps->rot_model == rot_model)
{
return p->caps; return p->caps;
} }
} }
@ -216,9 +225,11 @@ static int rot_lookup_backend(rot_model_t rot_model)
{ {
int i; 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) == if (ROT_BACKEND_NUM(rot_model) ==
rot_backend_list[i].be_num) { rot_backend_list[i].be_num)
{
return i; return i;
} }
} }
@ -242,7 +253,8 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
/* already loaded ? */ /* already loaded ? */
caps = rot_get_caps(rot_model); caps = rot_get_caps(rot_model);
if (caps) { if (caps)
{
return RIG_OK; return RIG_OK;
} }
@ -251,11 +263,13 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model)
/* /*
* Never heard about this backend family! * Never heard about this backend family!
*/ */
if (be_idx == -1) { if (be_idx == -1)
{
rot_debug(RIG_DEBUG_VERBOSE, rot_debug(RIG_DEBUG_VERBOSE,
"%s: unsupported backend %d for model %d\n", "%s: unsupported backend %d for model %d\n",
__func__, __func__,
ROT_BACKEND_NUM(rot_model), rot_model); ROT_BACKEND_NUM(rot_model),
rot_model);
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -274,11 +288,16 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model)
hval = HASH_FUNC(rot_model); hval = HASH_FUNC(rot_model);
q = NULL; q = NULL;
for (p = rot_hash_table[hval]; p; p = p->next) { for (p = rot_hash_table[hval]; p; p = p->next)
if (p->caps->rot_model == rot_model) { {
if (q == NULL) { if (p->caps->rot_model == rot_model)
{
if (q == NULL)
{
rot_hash_table[hval] = p->next; rot_hash_table[hval] = p->next;
} else { }
else
{
q->next = p->next; q->next = p->next;
} }
@ -297,19 +316,23 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model)
* rot_list_foreach * rot_list_foreach
* executes cfunc on all the elements stored in the rot hash list * executes cfunc on all the elements stored in the rot hash list
*/ */
int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps *, rig_ptr_t), int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps *,
rig_ptr_t),
rig_ptr_t data) rig_ptr_t data)
{ {
struct rot_list *p; struct rot_list *p;
int i; int i;
if (!cfunc) { if (!cfunc)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
for (i = 0; i < ROTLSTHASHSZ; i++) { for (i = 0; i < ROTLSTHASHSZ; i++)
{
for (p = rot_hash_table[i]; p; p = p->next) for (p = rot_hash_table[i]; p; p = p->next)
if ((*cfunc)(p->caps, data) == 0) { if ((*cfunc)(p->caps, data) == 0)
{
return RIG_OK; return RIG_OK;
} }
} }
@ -327,11 +350,14 @@ rot_model_t HAMLIB_API rot_probe_all(hamlib_port_t *p)
int i; int i;
rot_model_t rot_model; rot_model_t rot_model;
for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++)
if (rot_backend_list[i].be_probe) { {
if (rot_backend_list[i].be_probe)
{
rot_model = (*rot_backend_list[i].be_probe)(p); rot_model = (*rot_backend_list[i].be_probe)(p);
if (rot_model != ROT_MODEL_NONE) { if (rot_model != ROT_MODEL_NONE)
{
return rot_model; return rot_model;
} }
} }
@ -345,7 +371,8 @@ int rot_load_all_backends()
{ {
int i; 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); 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 (*be_init)(rig_ptr_t);
int i; 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 (!strcmp(be_name, rot_backend_list[i].be_name)) { {
if (!strcmp(be_name, rot_backend_list[i].be_name))
{
be_init = rot_backend_list[i].be_init; be_init = rot_backend_list[i].be_init;
if (be_init == NULL) { if (be_init == NULL)
{
printf("Null\n"); printf("Null\n");
return -EINVAL; return -EINVAL;
} }

Wyświetl plik

@ -35,7 +35,8 @@
*/ */
/*! \page rot Rotator interface /**
* \page rot Rotator interface
* *
* Rotator can be any kind of azimuth or azimuth and elevation controlled * Rotator can be any kind of azimuth or azimuth and elevation controlled
* antenna system. * antenna system.
@ -53,7 +54,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <hamlib/rotator.h> #include <hamlib/rotator.h>
#include "serial.h" #include "serial.h"
#include "parallel.h" #include "parallel.h"
@ -89,7 +89,8 @@
/* /*
* Data structure to track the opened rot (by rot_open) * Data structure to track the opened rot (by rot_open)
*/ */
struct opened_rot_l { struct opened_rot_l
{
ROT *rot; ROT *rot;
struct opened_rot_l *next; struct opened_rot_l *next;
}; };
@ -105,7 +106,8 @@ static int add_opened_rot(ROT *rot)
struct opened_rot_l *p; struct opened_rot_l *p;
p = (struct opened_rot_l *)malloc(sizeof(struct opened_rot_l)); p = (struct opened_rot_l *)malloc(sizeof(struct opened_rot_l));
if (!p) { if (!p)
{
return -RIG_ENOMEM; return -RIG_ENOMEM;
} }
@ -121,11 +123,16 @@ static int remove_opened_rot(ROT *rot)
struct opened_rot_l *p, *q; struct opened_rot_l *p, *q;
q = NULL; q = NULL;
for (p = opened_rot_list; p; p = p->next) { for (p = opened_rot_list; p; p = p->next)
if (p->rot == rot) { {
if (q == NULL) { if (p->rot == rot)
{
if (q == NULL)
{
opened_rot_list = opened_rot_list->next; opened_rot_list = opened_rot_list->next;
} else { }
else
{
q->next = p->next; 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 cfunc The function to be executed on each rot
* \param data Data pointer to be passed to cfunc() * \param data Data pointer to be passed to cfunc()
* *
* Calls cfunc() function for each opened rot. * Calls cfunc() function for each opened rot. The contents of the opened
* The contents of the opened rot table * rot table is processed in random order according to a function pointed to
* is processed in random order according to a function * by \a cfunc, whic is called with two arguments, the first pointing to the
* pointed to by \a cfunc, whic is called with two arguments, * #ROT handle, the second to a data pointer \a data.
* 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
* If \a data is not needed, then it can be set to NULL. * the opened rot table is stopped when cfunc() returns 0.
* The processing of the opened rot table is stopped
* when cfunc() returns 0.
* \internal * \internal
* *
* \return always RIG_OK. * \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__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (p = opened_rot_list; p; p = p->next) { for (p = opened_rot_list; p; p = p->next)
if ((*cfunc)(p->rot, data) == 0) { {
if ((*cfunc)(p->rot, data) == 0)
{
return RIG_OK; return RIG_OK;
} }
} }
@ -200,7 +207,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
caps = rot_get_caps(rot_model); caps = rot_get_caps(rot_model);
if (!caps) { if (!caps)
{
return NULL; return NULL;
} }
@ -210,7 +218,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
*/ */
rot = calloc(1, sizeof(ROT)); rot = calloc(1, sizeof(ROT));
if (rot == NULL) { if (rot == NULL)
{
/* /*
* FIXME: how can the caller know it's a memory shortage, * FIXME: how can the caller know it's a memory shortage,
* and not "rot not found" ? * 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.timeout = caps->timeout;
rs->rotport.retry = caps->retry; rs->rotport.retry = caps->retry;
switch (caps->port_type) { switch (caps->port_type)
{
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1); strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1);
rs->rotport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */ 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, * This must be done only once defaults are setup,
* so the backend init can override rot_state. * so the backend init can override rot_state.
*/ */
if (caps->rot_init != NULL) { if (caps->rot_init != NULL)
{
retcode = caps->rot_init(rot); retcode = caps->rot_init(rot);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
rot_debug(RIG_DEBUG_VERBOSE, rot_debug(RIG_DEBUG_VERBOSE,
"%s: backend_init failed!\n", "%s: backend_init failed!\n",
__func__); __func__);
@ -312,24 +324,28 @@ int HAMLIB_API rot_open(ROT *rot)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) { if (!rot || !rot->caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
rs = &rot->state; rs = &rot->state;
if (rs->comm_state) { if (rs->comm_state)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
rs->rotport.fd = -1; rs->rotport.fd = -1;
switch (rs->rotport.type.rig) { switch (rs->rotport.type.rig)
{
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
status = serial_open(&rs->rotport); status = serial_open(&rs->rotport);
if (status != 0) { if (status != 0)
{
return status; return status;
} }
@ -338,7 +354,8 @@ int HAMLIB_API rot_open(ROT *rot)
case RIG_PORT_PARALLEL: case RIG_PORT_PARALLEL:
status = par_open(&rs->rotport); status = par_open(&rs->rotport);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -347,7 +364,8 @@ int HAMLIB_API rot_open(ROT *rot)
case RIG_PORT_DEVICE: case RIG_PORT_DEVICE:
status = open(rs->rotport.pathname, O_RDWR, 0); status = open(rs->rotport.pathname, O_RDWR, 0);
if (status < 0) { if (status < 0)
{
return -RIG_EIO; return -RIG_EIO;
} }
@ -357,7 +375,8 @@ int HAMLIB_API rot_open(ROT *rot)
case RIG_PORT_USB: case RIG_PORT_USB:
status = usb_port_open(&rs->rotport); status = usb_port_open(&rs->rotport);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -372,7 +391,8 @@ int HAMLIB_API rot_open(ROT *rot)
/* FIXME: default port */ /* FIXME: default port */
status = network_open(&rs->rotport, 4533); status = network_open(&rs->rotport, 4533);
if (status < 0) { if (status < 0)
{
return status; return status;
} }
@ -391,10 +411,12 @@ int HAMLIB_API rot_open(ROT *rot)
* Maybe the backend has something to initialize * Maybe the backend has something to initialize
* In case of failure, just close down and report error code. * 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); status = caps->rot_open(rot);
if (status != RIG_OK) { if (status != RIG_OK)
{
return status; return status;
} }
} }
@ -423,14 +445,16 @@ int HAMLIB_API rot_close(ROT *rot)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) { if (!rot || !rot->caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
rs = &rot->state; rs = &rot->state;
if (!rs->comm_state) { if (!rs->comm_state)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -438,13 +462,16 @@ int HAMLIB_API rot_close(ROT *rot)
* Let the backend say 73s to the rot. * Let the backend say 73s to the rot.
* and ignore the return code. * and ignore the return code.
*/ */
if (caps->rot_close) { if (caps->rot_close)
{
caps->rot_close(rot); caps->rot_close(rot);
} }
if (rs->rotport.fd != -1) { if (rs->rotport.fd != -1)
switch (rs->rotport.type.rig) { {
switch (rs->rotport.type.rig)
{
case RIG_PORT_SERIAL: case RIG_PORT_SERIAL:
ser_close(&rs->rotport); ser_close(&rs->rotport);
break; break;
@ -494,21 +521,24 @@ int HAMLIB_API rot_cleanup(ROT *rot)
{ {
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps) { if (!rot || !rot->caps)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
/* /*
* check if they forgot to close the rot * check if they forgot to close the rot
*/ */
if (rot->state.comm_state) { if (rot->state.comm_state)
{
rot_close(rot); rot_close(rot);
} }
/* /*
* basically free up the priv struct * basically free up the priv struct
*/ */
if (rot->caps->rot_cleanup) { if (rot->caps->rot_cleanup)
{
rot->caps->rot_cleanup(rot); rot->caps->rot_cleanup(rot);
} }
@ -532,7 +562,8 @@ int HAMLIB_API rot_cleanup(ROT *rot)
* *
* \sa rot_get_position() * \sa rot_get_position()
*/ */
int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth, int HAMLIB_API rot_set_position(ROT *rot,
azimuth_t azimuth,
elevation_t elevation) elevation_t elevation)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
@ -540,7 +571,8 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) { if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -550,11 +582,13 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
if (azimuth < rs->min_az if (azimuth < rs->min_az
|| azimuth > rs->max_az || azimuth > rs->max_az
|| elevation < rs->min_el || elevation < rs->min_el
|| elevation > rs->max_el) { || elevation > rs->max_el)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (caps->set_position == NULL) { if (caps->set_position == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -576,20 +610,23 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth,
* *
* \sa rot_set_position() * \sa rot_set_position()
*/ */
int HAMLIB_API rot_get_position(ROT *rot, azimuth_t *azimuth, int HAMLIB_API rot_get_position(ROT *rot,
azimuth_t *azimuth,
elevation_t *elevation) elevation_t *elevation)
{ {
const struct rot_caps *caps; const struct rot_caps *caps;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); 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; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
if (caps->get_position == NULL) { if (caps->get_position == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -614,13 +651,15 @@ int HAMLIB_API rot_park(ROT *rot)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) { if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
if (caps->park == NULL) { if (caps->park == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -645,13 +684,15 @@ int HAMLIB_API rot_stop(ROT *rot)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) { if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
if (caps->stop == NULL) { if (caps->stop == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -677,13 +718,15 @@ int HAMLIB_API rot_reset(ROT *rot, rot_reset_t reset)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) { if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
if (caps->reset == NULL) { if (caps->reset == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -706,13 +749,15 @@ int HAMLIB_API rot_move(ROT *rot, int direction, int speed)
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) { if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rot->caps; caps = rot->caps;
if (caps->move == NULL) { if (caps->move == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -735,11 +780,13 @@ const char *HAMLIB_API rot_get_info(ROT *rot)
{ {
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot)) { if (CHECK_ROT_ARG(rot))
{
return NULL; return NULL;
} }
if (rot->caps->get_info == NULL) { if (rot->caps->get_info == NULL)
{
return NULL; return NULL;
} }

Wyświetl plik

@ -45,6 +45,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
@ -87,21 +88,27 @@
static int uh_ptt_fd = -1; static int uh_ptt_fd = -1;
static int uh_radio_fd = -1; static int uh_radio_fd = -1;
int is_uh_radio_fd(int fd) {
/* /*
* This function simply returns TRUE if the argument * This function simply returns TRUE if the argument matches uh_radio_fd and
* matches uh_radio_fd and is >= 0 * is >= 0
* *
* This function is only used in the WIN32 case and implements * This function is only used in the WIN32 case and implements access "from
* access "from outside" to uh_radio_fd. * outside" to uh_radio_fd.
*/ */
if (uh_radio_fd >= 0 && uh_radio_fd == fd) { int is_uh_radio_fd(int fd)
{
if (uh_radio_fd >= 0 && uh_radio_fd == fd)
{
return 1; return 1;
} else { }
else
{
return 0; return 0;
} }
} }
/** /**
* \brief Open serial port using rig.state data * \brief Open serial port using rig.state data
* \param rp port data structure (must spec port id eg /dev/ttyS1) * \param rp port data structure (must spec port id eg /dev/ttyS1)
@ -115,7 +122,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rp) { if (!rp)
{
return -RIG_EINVAL; 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); fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) { if (fd == -1)
{
/* Could not open the port. */ /* Could not open the port. */
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: Unable to open %s - %s\n", "%s: Unable to open %s - %s\n",
@ -180,7 +189,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp)
err = serial_setup(rp); err = serial_setup(rp);
if (err != RIG_OK) { if (err != RIG_OK)
{
CLOSE(fd); CLOSE(fd);
return err; return err;
} }
@ -211,7 +221,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rp) { if (!rp)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
@ -236,7 +247,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
/* /*
* Set the baud rates to requested values * Set the baud rates to requested values
*/ */
switch (rp->parm.serial.rate) { switch (rp->parm.serial.rate)
{
case 150: case 150:
speed = B150; /* yikes... */ speed = B150; /* yikes... */
break; break;
@ -309,7 +321,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set data to requested values. * Set data to requested values.
* *
*/ */
switch (rp->parm.serial.data_bits) { switch (rp->parm.serial.data_bits)
{
case 7: case 7:
options.c_cflag &= ~CSIZE; options.c_cflag &= ~CSIZE;
options.c_cflag |= CS7; options.c_cflag |= CS7;
@ -335,7 +348,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set stop bits to requested values. * Set stop bits to requested values.
* *
*/ */
switch (rp->parm.serial.stop_bits) { switch (rp->parm.serial.stop_bits)
{
case 1: case 1:
options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSTOPB;
break; break;
@ -359,7 +373,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set parity to requested values. * Set parity to requested values.
* *
*/ */
switch (rp->parm.serial.parity) { switch (rp->parm.serial.parity)
{
case RIG_PARITY_NONE: case RIG_PARITY_NONE:
options.c_cflag &= ~PARENB; options.c_cflag &= ~PARENB;
break; break;
@ -403,7 +418,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
* Set flow control to requested mode * Set flow control to requested mode
* *
*/ */
switch (rp->parm.serial.handshake) { switch (rp->parm.serial.handshake)
{
case RIG_HANDSHAKE_NONE: case RIG_HANDSHAKE_NONE:
options.c_cflag &= ~CRTSCTS; options.c_cflag &= ~CRTSCTS;
options.c_iflag &= ~IXON; options.c_iflag &= ~IXON;
@ -461,7 +477,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
*/ */
#if defined(HAVE_TERMIOS_H) #if defined(HAVE_TERMIOS_H)
if (tcsetattr(fd, TCSANOW, &options) == -1) { if (tcsetattr(fd, TCSANOW, &options) == -1)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: tcsetattr failed: %s\n", "%s: tcsetattr failed: %s\n",
__func__, __func__,
@ -473,7 +490,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
#elif defined(HAVE_TERMIO_H) #elif defined(HAVE_TERMIO_H)
if (IOCTL(fd, TCSETA, &options) == -1) { if (IOCTL(fd, TCSETA, &options) == -1)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(TCSETA) failed: %s\n", "%s: ioctl(TCSETA) failed: %s\n",
__func__, __func__,
@ -484,8 +502,10 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
} }
#else #else
/* sgtty */ /* sgtty */
if (IOCTL(fd, TIOCSETP, &sg) == -1) { if (IOCTL(fd, TIOCSETP, &sg) == -1)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(TIOCSETP) failed: %s\n", "%s: ioctl(TIOCSETP) failed: %s\n",
__func__, __func__,
@ -629,10 +649,14 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state)
#else #else
rc = IOCTL(p->fd, TIOCMGET, &y); rc = IOCTL(p->fd, TIOCMGET, &y);
if (rc >= 0) { if (rc >= 0)
if (state) { {
if (state)
{
y |= TIOCM_RTS; y |= TIOCM_RTS;
} else { }
else
{
y &= ~TIOCM_RTS; y &= ~TIOCM_RTS;
} }
@ -641,7 +665,8 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state)
#endif #endif
if (rc < 0) { if (rc < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: Cannot change RTS - %s\n", "%s: Cannot change RTS - %s\n",
__func__, __func__,
@ -707,10 +732,14 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state)
#else #else
rc = IOCTL(p->fd, TIOCMGET, &y); rc = IOCTL(p->fd, TIOCMGET, &y);
if (rc >= 0) { if (rc >= 0)
if (state) { {
if (state)
{
y |= TIOCM_DTR; y |= TIOCM_DTR;
} else { }
else
{
y &= ~TIOCM_DTR; y &= ~TIOCM_DTR;
} }
@ -719,7 +748,8 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state)
#endif #endif
if (rc < 0) { if (rc < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: Cannot change DTR - %s\n", "%s: Cannot change DTR - %s\n",
__func__, __func__,

Wyświetl plik

@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_level == NULL || !rig_has_set_level(rig, level)) { if (caps->set_level == NULL || !rig_has_set_level(rig, level))
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|| vfo == RIG_VFO_CURR || vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo) { || vfo == rig->state.current_vfo)
{
return caps->set_level(rig, vfo, level, val); return caps->set_level(rig, vfo, level, val);
} }
if (!caps->set_vfo) { if (!caps->set_vfo)
{
return -RIG_ENTARGET; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !val) { if (CHECK_RIG_ARG(rig) || !val)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_level == NULL || !rig_has_get_level(rig, level)) { if (caps->get_level == NULL || !rig_has_get_level(rig, level))
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -162,13 +169,15 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if (level == RIG_LEVEL_STRENGTH if (level == RIG_LEVEL_STRENGTH
&& (caps->has_get_level & RIG_LEVEL_STRENGTH) == 0 && (caps->has_get_level & RIG_LEVEL_STRENGTH) == 0
&& rig_has_get_level(rig, RIG_LEVEL_RAWSTR) && rig_has_get_level(rig, RIG_LEVEL_RAWSTR)
&& rig->state.str_cal.size) { && rig->state.str_cal.size)
{
value_t rawstr; value_t rawstr;
retcode = rig_get_level(rig, vfo, RIG_LEVEL_RAWSTR, &rawstr); retcode = rig_get_level(rig, vfo, RIG_LEVEL_RAWSTR, &rawstr);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -179,19 +188,22 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; 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; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !val) { if (CHECK_RIG_ARG(rig) || !val)
{
return -RIG_EINVAL; 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; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return 0; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return 0; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return 0; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return 0; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return 0; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rig || !rig->caps) { if (!rig || !rig->caps)
{
return 0; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_func == NULL || !rig_has_set_func(rig, func)) { if (caps->set_func == NULL || !rig_has_set_func(rig, func))
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC) if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
retcode = caps->set_func(rig, vfo, func, status); retcode = caps->set_func(rig, vfo, func, status);
caps->set_vfo(rig, curr_vfo); caps->set_vfo(rig, curr_vfo);
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !func) { if (CHECK_RIG_ARG(rig) || !func)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_func == NULL || !rig_has_get_func(rig, func)) { if (caps->get_func == NULL || !rig_has_get_func(rig, func))
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC) if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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() * \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) value_t val)
{ {
const struct rig_caps *caps; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_ext_level == NULL) { if (caps->set_ext_level == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -629,7 +669,9 @@ int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token,
* *
* \sa rig_set_ext_level() * \sa rig_set_ext_level()
*/ */
int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token, int HAMLIB_API rig_get_ext_level(RIG *rig,
vfo_t vfo,
token_t token,
value_t *val) value_t *val)
{ {
const struct rig_caps *caps; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !val) { if (CHECK_RIG_ARG(rig) || !val)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_ext_level == NULL) { if (caps->get_ext_level == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) if ((caps->targetable_vfo & RIG_TARGETABLE_PURE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig->caps->set_ext_parm == NULL) { if (rig->caps->set_ext_parm == NULL)
{
return -RIG_ENAVAIL; 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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !val) { if (CHECK_RIG_ARG(rig) || !val)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig->caps->get_ext_parm == NULL) { if (rig->caps->get_ext_parm == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
@ -748,8 +799,10 @@ int HAMLIB_API rig_setting2idx(setting_t s)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0; i < RIG_SETTING_MAX; i++) { for (i = 0; i < RIG_SETTING_MAX; i++)
if (s & rig_idx2setting(i)) { {
if (s & rig_idx2setting(i))
{
return i; return i;
} }
} }

Wyświetl plik

@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_ctcss_tone == NULL) { if (caps->set_ctcss_tone == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !tone) { if (CHECK_RIG_ARG(rig) || !tone)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_ctcss_tone == NULL) { if (caps->get_ctcss_tone == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_dcs_code == NULL) { if (caps->set_dcs_code == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !code) { if (CHECK_RIG_ARG(rig) || !code)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_dcs_code == NULL) { if (caps->get_dcs_code == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_ctcss_sql == NULL) { if (caps->set_ctcss_sql == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !tone) { if (CHECK_RIG_ARG(rig) || !tone)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_ctcss_sql == NULL) { if (caps->get_ctcss_sql == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig)) { if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->set_dcs_sql == NULL) { if (caps->set_dcs_sql == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }
@ -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__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !code) { if (CHECK_RIG_ARG(rig) || !code)
{
return -RIG_EINVAL; return -RIG_EINVAL;
} }
caps = rig->caps; caps = rig->caps;
if (caps->get_dcs_sql == NULL) { if (caps->get_dcs_sql == NULL)
{
return -RIG_ENAVAIL; return -RIG_ENAVAIL;
} }
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR || 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; return -RIG_ENTARGET;
} }
curr_vfo = rig->state.current_vfo; curr_vfo = rig->state.current_vfo;
retcode = caps->set_vfo(rig, vfo); retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK) { if (retcode != RIG_OK)
{
return retcode; return retcode;
} }

Wyświetl plik

@ -37,7 +37,8 @@
2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \ 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \
0, 0,
static const tone_t static_full_ctcss_list[] = { static const tone_t static_full_ctcss_list[] =
{
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, \ 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \
0, 0,
static const tone_t static_common_ctcss_list[] = { static const tone_t static_common_ctcss_list[] =
{
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, \ 662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \
0, 0,
static const tone_t static_common_dcs_list[] = { static const tone_t static_common_dcs_list[] =
{
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, \ 662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \
0, 0,
static const tone_t static_full_dcs_list[] = { static const tone_t static_full_dcs_list[] =
{
FULL_DCS_LIST FULL_DCS_LIST
}; };

Wyświetl plik

@ -83,7 +83,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
r = libusb_get_device_list(NULL, &devs); r = libusb_get_device_list(NULL, &devs);
if (r < 0) { if (r < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: failed getting usb device list: %s", "%s: failed getting usb device list: %s",
__func__, __func__,
@ -92,7 +93,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
return NULL; return NULL;
} }
for (i = 0; (dev = devs[i]) != NULL; i++) { for (i = 0; (dev = devs[i]) != NULL; i++)
{
libusb_get_device_descriptor(dev, &desc); 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); desc.idProduct);
if (desc.idVendor == port->parm.usb.vid if (desc.idVendor == port->parm.usb.vid
&& desc.idProduct == port->parm.usb.pid) { && desc.idProduct == port->parm.usb.pid)
{
/* we need to open the device in order to query strings */ /* we need to open the device in order to query strings */
r = libusb_open(dev, &udh); r = libusb_open(dev, &udh);
if (r < 0) { if (r < 0)
{
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_WARN,
"%s: Warning: Cannot open USB device: %s\n", "%s: Warning: Cannot open USB device: %s\n",
__func__, __func__,
@ -117,7 +121,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
} }
/* now check whether the names match: */ /* now check whether the names match: */
if (port->parm.usb.vendor_name) { if (port->parm.usb.vendor_name)
{
string[0] = '\0'; string[0] = '\0';
r = libusb_get_string_descriptor_ascii(udh, 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, (unsigned char *)string,
sizeof(string)); sizeof(string));
if (r < 0) { if (r < 0)
{
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_WARN,
"Warning: cannot query manufacturer for USB device: %s\n", "Warning: cannot query manufacturer for USB device: %s\n",
libusb_error_name(r)); 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); 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, rig_debug(RIG_DEBUG_WARN,
"%s: Warning: Vendor name string mismatch!\n", "%s: Warning: Vendor name string mismatch!\n",
__func__); __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'; string[0] = '\0';
r = libusb_get_string_descriptor_ascii(udh, 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, (unsigned char *)string,
sizeof(string)); sizeof(string));
if (r < 0) { if (r < 0)
{
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_WARN,
"Warning: cannot query product for USB device: %s\n", "Warning: cannot query product for USB device: %s\n",
libusb_error_name(r)); 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); rig_debug(RIG_DEBUG_VERBOSE, " product >%s<", string);
if (strcmp(string, port->parm.usb.product) != 0) { if (strcmp(string, port->parm.usb.product) != 0)
{
/* Now testing with strncasecmp() for case insensitive /* Now testing with strncasecmp() for case insensitive
* match. Updating firmware on FUNcube Dongle to v18f resulted * match. Updating firmware on FUNcube Dongle to v18f resulted
@ -175,7 +185,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port)
*/ */
if (strncasecmp(string, if (strncasecmp(string,
port->parm.usb.product, port->parm.usb.product,
sizeof(port->parm.usb.product - 1)) != 0) { sizeof(port->parm.usb.product - 1)) != 0)
{
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_WARN,
"%s: Warning: Product string mismatch!\n", "%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 */ /* init defaut libusb-1.0 library contexte, if needed */
r = libusb_init(NULL); r = libusb_init(NULL);
if (r < 0) { if (r < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: libusb_init failed: %s\n", "%s: libusb_init failed: %s\n",
__func__, __func__,
@ -239,25 +251,29 @@ int usb_port_open(hamlib_port_t *port)
p = pathname; p = pathname;
q = strchr(p, ':'); q = strchr(p, ':');
if (q) { if (q)
{
++q; ++q;
port->parm.usb.vid = strtol(q, NULL, 16); port->parm.usb.vid = strtol(q, NULL, 16);
p = q; p = q;
q = strchr(p, ':'); q = strchr(p, ':');
if (q) { if (q)
{
++q; ++q;
port->parm.usb.pid = strtol(q, NULL, 16); port->parm.usb.pid = strtol(q, NULL, 16);
p = q; p = q;
q = strchr(p, ':'); q = strchr(p, ':');
if (q) { if (q)
{
++q; ++q;
port->parm.usb.vendor_name = q; port->parm.usb.vendor_name = q;
p = q; p = q;
q = strchr(p, ':'); q = strchr(p, ':');
if (q) { if (q)
{
*q++ = '\0'; *q++ = '\0';
port->parm.usb.product = q; port->parm.usb.product = q;
} }
@ -267,7 +283,8 @@ int usb_port_open(hamlib_port_t *port)
udh = find_and_open_device(port); udh = find_and_open_device(port);
if (udh == 0) { if (udh == 0)
{
libusb_exit(NULL); libusb_exit(NULL);
return -RIG_EIO; return -RIG_EIO;
} }
@ -279,13 +296,15 @@ int usb_port_open(hamlib_port_t *port)
*/ */
(void)libusb_set_auto_detach_kernel_driver(udh, port->parm.usb.iface); (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 #ifdef _WIN32
/* Is it still needed with libusb-1.0 ? */ /* Is it still needed with libusb-1.0 ? */
if (port->parm.usb.conf >= 0 if (port->parm.usb.conf >= 0
&& (r = libusb_set_configuration(udh, port->parm.usb.conf)) < 0) { && (r = libusb_set_configuration(udh, port->parm.usb.conf)) < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: libusb_set_configuration: failed conf %d: %s\n", "%s: libusb_set_configuration: failed conf %d: %s\n",
@ -308,7 +327,8 @@ int usb_port_open(hamlib_port_t *port)
r = libusb_claim_interface(udh, port->parm.usb.iface); r = libusb_claim_interface(udh, port->parm.usb.iface);
if (r < 0) { if (r < 0)
{
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s:libusb_claim_interface: failed interface %d: %s\n", "%s:libusb_claim_interface: failed interface %d: %s\n",
__func__, __func__,
@ -325,7 +345,8 @@ int usb_port_open(hamlib_port_t *port)
r = libusb_set_interface_alt_setting(udh, port->parm.usb.iface, r = libusb_set_interface_alt_setting(udh, port->parm.usb.iface,
port->parm.usb.alt); port->parm.usb.alt);
if (r < 0) { if (r < 0)
{
fprintf(stderr, fprintf(stderr,
"%s:usb_set_alt_interface: failed: %s\n", "%s:usb_set_alt_interface: failed: %s\n",
__func__, __func__,