From 20efdcce8dc71af74c48944c2c1dbde516dfafb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Sun, 22 Jun 2003 19:50:36 +0000 Subject: [PATCH] new pp_write data/control helpers git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1485 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- src/serial.c | 62 ++++++++++++++++++++++++++++++++++++++++++---------- src/serial.h | 7 +++++- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/serial.c b/src/serial.c index 20e687026..e8f6b3862 100644 --- a/src/serial.c +++ b/src/serial.c @@ -4,7 +4,7 @@ * Parts of the PTT handling are derived from soundmodem, an excellent * ham packet softmodem written by Thomas Sailer, HB9JNX. * - * $Id: serial.c,v 1.31 2003-04-19 11:49:43 fillods Exp $ + * $Id: serial.c,v 1.32 2003-06-22 19:50:36 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -581,24 +581,68 @@ int par_close(port_t *p) return close(p->fd); } +int par_write_data(port_t *p, unsigned char data) +{ + int status; +#ifdef HAVE_LINUX_PPDEV_H + status = ioctl(p->fd, PPWDATA, &data); + return status == 0 ? RIG_OK : -RIG_EIO; +#endif + return -RIG_ENIMPL; +} + +int par_read_data(port_t *p, unsigned char *data) +{ + int status; +#ifdef HAVE_LINUX_PPDEV_H + status = ioctl(p->fd, PPRDATA, data); + return status == 0 ? RIG_OK : -RIG_EIO; +#endif + return -RIG_ENIMPL; +} + + +int par_write_control(port_t *p, unsigned char control) +{ + int status; +#ifdef HAVE_LINUX_PPDEV_H + status = ioctl(p->fd, PPWCONTROL, &control); + return status == 0 ? RIG_OK : -RIG_EIO; +#endif + return -RIG_ENIMPL; +} + +int par_read_control(port_t *p, unsigned char *control) +{ + int status; +#ifdef HAVE_LINUX_PPDEV_H + status = ioctl(p->fd, PPRCONTROL, control); + return status == 0 ? RIG_OK : -RIG_EIO; +#endif + return -RIG_ENIMPL; +} + + + + int par_ptt_set(port_t *p, ptt_t pttx) { switch(p->type.ptt) { -#ifdef HAVE_LINUX_PPDEV_H case RIG_PTT_PARALLEL: { unsigned char reg; int status; - status = ioctl(p->fd, PPRDATA, ®); + status = par_read_data(p, ®); + if (status != RIG_OK) + return status; if (pttx == RIG_PTT_ON) reg |= 1 << p->parm.parallel.pin; else reg &= ~(1 << p->parm.parallel.pin); - return ioctl(p->fd, PPWDATA, ®); + return par_write_data(p, reg); } -#endif default: rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n", p->type.ptt); @@ -613,18 +657,16 @@ int par_ptt_set(port_t *p, ptt_t pttx) int par_ptt_get(port_t *p, ptt_t *pttx) { switch(p->type.ptt) { -#ifdef HAVE_LINUX_PPDEV_H case RIG_PTT_PARALLEL: { unsigned char reg; int status; - status = ioctl(p->fd, PPRDATA, ®); + status = par_read_data(p, ®); *pttx = reg & (1<parm.parallel.pin) ? RIG_PTT_ON:RIG_PTT_OFF; return status; } -#endif default: rig_debug(RIG_DEBUG_ERR,"Unsupported PTT type %d\n", p->type.ptt); @@ -639,18 +681,16 @@ int par_ptt_get(port_t *p, ptt_t *pttx) int par_dcd_get(port_t *p, dcd_t *dcdx) { switch(p->type.dcd) { -#ifdef HAVE_LINUX_PPDEV_H case RIG_DCD_PARALLEL: { unsigned char reg; int status; - status = ioctl(p->fd, PPRDATA, ®); + status = par_read_data(p, ®); *dcdx = reg & (1<parm.parallel.pin) ? RIG_DCD_ON:RIG_DCD_OFF; return status; } -#endif default: rig_debug(RIG_DEBUG_ERR,"Unsupported DCD type %d\n", p->type.dcd); diff --git a/src/serial.h b/src/serial.h index 6366c3fd8..15529cccf 100644 --- a/src/serial.h +++ b/src/serial.h @@ -2,7 +2,7 @@ * Hamlib Interface - serial communication header * Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton * - * $Id: serial.h,v 1.18 2003-02-23 22:36:30 fillods Exp $ + * $Id: serial.h,v 1.19 2003-06-22 19:50:36 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -45,5 +45,10 @@ int par_ptt_set(port_t *p, ptt_t pttx); int par_ptt_get(port_t *p, ptt_t *pttx); int par_dcd_get(port_t *p, dcd_t *dcdx); +extern HAMLIB_EXPORT(int) par_write_data(port_t *p, unsigned char data); +extern HAMLIB_EXPORT(int) par_write_control(port_t *p, unsigned char control); +extern HAMLIB_EXPORT(int) par_read_data(port_t *p, unsigned char *data); +extern HAMLIB_EXPORT(int) par_read_control(port_t *p, unsigned char *control); + #endif /* _SERIAL_H */