astyle parallel.c

pull/104/head
Michael Black 2019-05-21 12:45:09 -05:00
rodzic 151a7059c5
commit 37f87c9b62
1 zmienionych plików z 358 dodań i 353 usunięć

Wyświetl plik

@ -126,91 +126,91 @@
*/ */
int par_open(hamlib_port_t *port) int par_open(hamlib_port_t *port)
{ {
int fd; int fd;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int mode; int mode;
#endif #endif
#if defined (__WIN64__) || defined(__WIN32__) #if defined (__WIN64__) || defined(__WIN32__)
HANDLE handle; HANDLE handle;
#endif #endif
if (!port->pathname[0]) if (!port->pathname[0])
{ {
return -RIG_EINVAL; return -RIG_EINVAL;
} }
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
/* TODO: open with O_NONBLOCK ? */ /* TODO: open with O_NONBLOCK ? */
fd = open(port->pathname, O_RDWR); fd = open(port->pathname, O_RDWR);
if (fd < 0) if (fd < 0)
{ {
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: opening device \"%s\": %s\n", "%s: opening device \"%s\": %s\n",
__func__, __func__,
port->pathname, port->pathname,
strerror(errno)); strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
mode = IEEE1284_MODE_COMPAT; mode = IEEE1284_MODE_COMPAT;
if (ioctl(fd, PPSETMODE, &mode) != 0) if (ioctl(fd, PPSETMODE, &mode) != 0)
{ {
rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n", rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n",
__func__, __func__,
port->pathname, port->pathname,
strerror(errno)); strerror(errno));
close(fd); close(fd);
return -RIG_EIO; return -RIG_EIO;
} }
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
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__,
port->pathname, port->pathname,
strerror(errno)); strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
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;
}
} }
}
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
port->fd = fd; port->fd = fd;
return fd; return fd;
} }
@ -220,16 +220,16 @@ int par_open(hamlib_port_t *port)
*/ */
int par_close(hamlib_port_t *port) int par_close(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
_close(port->fd); _close(port->fd);
return RIG_OK; return RIG_OK;
#endif #endif
return close(port->fd); return close(port->fd);
} }
@ -240,36 +240,36 @@ int par_close(hamlib_port_t *port)
*/ */
int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data) int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
status = ioctl(port->fd, PPWDATA, &data); status = ioctl(port->fd, PPWDATA, &data);
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
int status; int status;
status = ioctl(port->fd, PPISDATA, &data); status = ioctl(port->fd, PPISDATA, &data);
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
unsigned int dummy; unsigned int dummy;
intptr_t handle; intptr_t handle;
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),
NULL, 0, (LPDWORD)&dummy, NULL)))
{ {
if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_DATA, &data, sizeof(data), rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
NULL, 0, (LPDWORD)&dummy, NULL))) return -RIG_EIO;
{
rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__);
return -RIG_EIO;
}
} }
}
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -281,47 +281,47 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
*/ */
int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
status = ioctl(port->fd, PPRDATA, data); status = ioctl(port->fd, PPRDATA, data);
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
int status; int status;
status = ioctl(port->fd, PPIGDATA, &data); status = ioctl(port->fd, PPIGDATA, &data);
return status == 0 ? RIG_OK : -RIG_EIO; return status == 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;
intptr_t handle; intptr_t handle;
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,
NT_IOCTL_STATUS, "%s: DeviceIoControl failed!\n",
NULL, __func__);
0,
&ret,
sizeof(ret),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; return -RIG_EIO;
}
} }
}
*data = ret ^ S1284_INVERTED; *data = ret ^ S1284_INVERTED;
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -333,71 +333,71 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data)
*/ */
int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS; unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
status = ioctl(port->fd, PPWCONTROL, &ctrl); status = ioctl(port->fd, PPWCONTROL, &ctrl);
if (status < 0) if (status < 0)
{ {
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(PPWCONTROL) failed: %s\n", "%s: ioctl(PPWCONTROL) failed: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
} }
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
int status; int status;
unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS; unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
status = ioctl(port->fd, PPISCTRL, &ctrl); status = ioctl(port->fd, PPISCTRL, &ctrl);
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
unsigned char ctr = control; unsigned char ctr = control;
unsigned char dummyc; unsigned char dummyc;
unsigned int dummy; unsigned int dummy;
const unsigned char wm = (C1284_NSTROBE const unsigned char wm = (C1284_NSTROBE
| C1284_NAUTOFD | C1284_NAUTOFD
| C1284_NINIT | C1284_NINIT
| C1284_NSELECTIN); | C1284_NSELECTIN);
intptr_t handle; intptr_t handle;
if (ctr & 0x20) if (ctr & 0x20)
{
rig_debug(RIG_DEBUG_WARN,
"%s: use ieee1284_data_dir to change data line direction!\n",
__func__);
}
/* Deal with inversion issues. */
ctr ^= wm & C1284_INVERTED;
ctr = (ctr & ~wm) ^ (ctr & wm);
handle = _get_osfhandle(port->fd);
if (handle != (intptr_t)INVALID_HANDLE_VALUE)
{
if (!(DeviceIoControl((HANDLE)handle,
NT_IOCTL_CONTROL,
&ctr,
sizeof(ctr),
&dummyc,
sizeof(dummyc),
(LPDWORD)&dummy,
NULL)))
{ {
rig_debug(RIG_DEBUG_WARN, rig_debug(RIG_DEBUG_ERR,
"%s: use ieee1284_data_dir to change data line direction!\n", "%s: frob_control: DeviceIoControl failed!\n",
__func__); __func__);
return -RIG_EIO;
} }
}
/* Deal with inversion issues. */ return RIG_OK;
ctr ^= wm & C1284_INVERTED;
ctr = (ctr & ~wm) ^ (ctr & wm);
handle = _get_osfhandle(port->fd);
if (handle != (intptr_t)INVALID_HANDLE_VALUE)
{
if (!(DeviceIoControl((HANDLE)handle,
NT_IOCTL_CONTROL,
&ctr,
sizeof(ctr),
&dummyc,
sizeof(dummyc),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: frob_control: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO;
}
}
return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -409,61 +409,61 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
*/ */
int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int status; int status;
unsigned char ctrl; unsigned char ctrl;
status = ioctl(port->fd, PPRCONTROL, &ctrl); status = ioctl(port->fd, PPRCONTROL, &ctrl);
if (status < 0) if (status < 0)
{ {
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: ioctl(PPRCONTROL) failed: %s\n", "%s: ioctl(PPRCONTROL) failed: %s\n",
__func__, __func__,
strerror(errno)); strerror(errno));
} }
*control = ctrl ^ CP_ACTIVE_LOW_BITS; *control = ctrl ^ CP_ACTIVE_LOW_BITS;
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
int status; int status;
unsigned char ctrl; unsigned char ctrl;
status = ioctl(port->fd, PPIGCTRL, &ctrl); status = ioctl(port->fd, PPIGCTRL, &ctrl);
*control = ctrl ^ CP_ACTIVE_LOW_BITS; *control = ctrl ^ CP_ACTIVE_LOW_BITS;
return status == 0 ? RIG_OK : -RIG_EIO; return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
unsigned char ret; unsigned char ret;
unsigned int dummy; unsigned int dummy;
intptr_t handle; intptr_t handle;
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,
NT_IOCTL_CONTROL, "%s: DeviceIoControl failed!\n",
NULL, __func__);
0,
&ret,
sizeof(ret),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; return -RIG_EIO;
}
} }
}
*control = ret ^ S1284_INVERTED; *control = ret ^ S1284_INVERTED;
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -476,56 +476,56 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
*/ */
int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
int ret; int ret;
unsigned char sta; unsigned char sta;
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;
intptr_t handle; intptr_t handle;
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,
NT_IOCTL_STATUS, "%s: DeviceIoControl failed!\n",
NULL, __func__);
0,
&ret,
sizeof(ret),
(LPDWORD)&dummy,
NULL)))
{
rig_debug(RIG_DEBUG_ERR,
"%s: DeviceIoControl failed!\n",
__func__);
return -RIG_EIO; return -RIG_EIO;
}
} }
}
*status = ret ^ S1284_INVERTED; *status = ret ^ S1284_INVERTED;
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -537,27 +537,27 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
*/ */
int HAMLIB_API par_lock(hamlib_port_t *port) int HAMLIB_API par_lock(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPCLAIM) < 0) if (ioctl(port->fd, PPCLAIM) < 0)
{ {
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: claiming device \"%s\": %s\n", "%s: claiming device \"%s\": %s\n",
__func__, __func__,
port->pathname, port->pathname,
strerror(errno)); strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
return RIG_OK; return RIG_OK;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
return RIG_OK; return RIG_OK;
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -569,27 +569,27 @@ int HAMLIB_API par_lock(hamlib_port_t *port)
*/ */
int HAMLIB_API par_unlock(hamlib_port_t *port) int HAMLIB_API par_unlock(hamlib_port_t *port)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef HAVE_LINUX_PPDEV_H #ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPRELEASE) < 0) if (ioctl(port->fd, PPRELEASE) < 0)
{ {
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"%s: releasing device \"%s\": %s\n", "%s: releasing device \"%s\": %s\n",
__func__, __func__,
port->pathname, port->pathname,
strerror(errno)); strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
return RIG_OK; return RIG_OK;
#elif defined(HAVE_DEV_PPBUS_PPI_H) #elif defined(HAVE_DEV_PPBUS_PPI_H)
return RIG_OK; return RIG_OK;
#elif defined(__WIN64__) || defined(__WIN32__) #elif defined(__WIN64__) || defined(__WIN32__)
return RIG_OK; return RIG_OK;
#else #else
return -RIG_ENIMPL; return -RIG_ENIMPL;
#endif #endif
} }
@ -611,52 +611,52 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
*/ */
int par_ptt_set(hamlib_port_t *p, ptt_t pttx) int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) switch (p->type.ptt)
{
case RIG_PTT_PARALLEL:
{
unsigned char ctl;
int status;
par_lock(p);
status = par_read_control(p, &ctl);
if (status != RIG_OK)
{ {
case RIG_PTT_PARALLEL: return status;
{
unsigned char ctl;
int status;
par_lock(p);
status = par_read_control(p, &ctl);
if (status != RIG_OK)
{
return status;
}
/* Enable CW & PTT - /STROBE bit (pin 1) */
ctl &= ~PARPORT_CONTROL_STROBE;
/* TODO: kill parm.parallel.pin? */
/* PTT keying - /INIT bit (pin 16) (inverted) */
if (pttx == RIG_PTT_ON)
{
ctl |= PARPORT_CONTROL_INIT;
}
else
{
ctl &= ~PARPORT_CONTROL_INIT;
}
status = par_write_control(p, ctl);
par_unlock(p);
return status;
} }
default: /* Enable CW & PTT - /STROBE bit (pin 1) */
rig_debug(RIG_DEBUG_ERR, ctl &= ~PARPORT_CONTROL_STROBE;
"%s: unsupported PTT type %d\n",
__func__, /* TODO: kill parm.parallel.pin? */
p->type.ptt);
return -RIG_EINVAL; /* PTT keying - /INIT bit (pin 16) (inverted) */
if (pttx == RIG_PTT_ON)
{
ctl |= PARPORT_CONTROL_INIT;
}
else
{
ctl &= ~PARPORT_CONTROL_INIT;
} }
return RIG_OK; status = par_write_control(p, ctl);
par_unlock(p);
return status;
}
default:
rig_debug(RIG_DEBUG_ERR,
"%s: unsupported PTT type %d\n",
__func__,
p->type.ptt);
return -RIG_EINVAL;
}
return RIG_OK;
} }
@ -668,36 +668,38 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
*/ */
int par_ptt_get(hamlib_port_t *p, ptt_t *pttx) int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
switch (p->type.ptt) switch (p->type.ptt)
{
case RIG_PTT_PARALLEL:
{
unsigned char ctl;
int status;
par_lock(p);
status = par_read_control(p, &ctl);
par_unlock(p);
if (status == RIG_OK)
{ {
case RIG_PTT_PARALLEL: *pttx = (ctl & PARPORT_CONTROL_INIT) &&
{ !(ctl & PARPORT_CONTROL_STROBE) ?
unsigned char ctl; RIG_PTT_ON : RIG_PTT_OFF;
int status;
par_lock(p);
status = par_read_control(p, &ctl);
par_unlock(p);
if (status == RIG_OK) {
*pttx = (ctl & PARPORT_CONTROL_INIT) &&
!(ctl & PARPORT_CONTROL_STROBE) ?
RIG_PTT_ON : RIG_PTT_OFF;
}
return status;
} }
default: return status;
rig_debug(RIG_DEBUG_ERR, }
"Unsupported PTT type %d\n",
__func__,
p->type.ptt);
return -RIG_ENAVAIL;
}
return RIG_OK; default:
rig_debug(RIG_DEBUG_ERR,
"Unsupported PTT type %d\n",
__func__,
p->type.ptt);
return -RIG_ENAVAIL;
}
return RIG_OK;
} }
@ -709,32 +711,35 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
*/ */
int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx) int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); 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;
status = par_read_data(p, &reg); status = par_read_data(p, &reg);
if (status == RIG_OK) {
*dcdx = reg & (1 << p->parm.parallel.pin) ? if (status == RIG_OK)
RIG_DCD_ON : RIG_DCD_OFF; {
} *dcdx = reg & (1 << p->parm.parallel.pin) ?
return status; RIG_DCD_ON : RIG_DCD_OFF;
} }
default: return status;
rig_debug(RIG_DEBUG_ERR, }
"%s: unsupported DCD type %d\n",
__func__,
p->type.dcd);
return -RIG_ENAVAIL;
}
return RIG_OK; default:
rig_debug(RIG_DEBUG_ERR,
"%s: unsupported DCD type %d\n",
__func__,
p->type.dcd);
return -RIG_ENAVAIL;
}
return RIG_OK;
} }
/** @} */ /** @} */