kopia lustrzana https://github.com/Hamlib/Hamlib
* reworked parallel port access: invert logic to make it more natural
* explicit ppdev locking * support for inclusion by C++ code git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1543 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.0
rodzic
52d15c1aaa
commit
f9478f5e97
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Rotator backend - Fodtrack parallel port
|
||||
* Copyright (c) 2001-2003 by Stephane Fillod
|
||||
*
|
||||
* $Id: fodtrack.c,v 1.5 2003-08-25 22:26:42 fillods Exp $
|
||||
* $Id: fodtrack.c,v 1.6 2003-09-28 15:34:44 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
|
||||
|
@ -49,6 +49,10 @@
|
|||
#define PARPORT_CONTROL_STROBE 0x1
|
||||
#endif
|
||||
|
||||
#ifndef CP_ACTIVE_LOW_BITS
|
||||
#define CP_ACTIVE_LOW_BITS 0x0B
|
||||
#endif
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
||||
/** outputs an direction to the interface */
|
||||
|
@ -56,6 +60,8 @@ static int setDirection(port_t *port, unsigned char outputvalue, int direction)
|
|||
{
|
||||
unsigned char outputstatus;
|
||||
|
||||
par_lock (port);
|
||||
|
||||
// set the data bits
|
||||
par_write_data(port, outputvalue);
|
||||
|
||||
|
@ -64,7 +70,7 @@ static int setDirection(port_t *port, unsigned char outputvalue, int direction)
|
|||
outputstatus = PARPORT_CONTROL_AUTOFD;
|
||||
else
|
||||
outputstatus=0;
|
||||
par_write_control(port, outputstatus);
|
||||
par_write_control(port, outputstatus^CP_ACTIVE_LOW_BITS);
|
||||
// and now the strobe impulse
|
||||
usleep(1);
|
||||
|
||||
|
@ -72,14 +78,16 @@ static int setDirection(port_t *port, unsigned char outputvalue, int direction)
|
|||
outputstatus = PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE;
|
||||
else
|
||||
outputstatus = PARPORT_CONTROL_STROBE;
|
||||
par_write_control(port, outputstatus);
|
||||
par_write_control(port, outputstatus^CP_ACTIVE_LOW_BITS);
|
||||
usleep(1);
|
||||
|
||||
if (direction)
|
||||
outputstatus= PARPORT_CONTROL_AUTOFD;
|
||||
else
|
||||
outputstatus=0;
|
||||
par_write_control(port, outputstatus);
|
||||
par_write_control(port, outputstatus^CP_ACTIVE_LOW_BITS);
|
||||
|
||||
par_unlock (port);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -118,9 +126,9 @@ const struct rot_caps fodtrack_rot_caps = {
|
|||
.rot_model = ROT_MODEL_FODTRACK,
|
||||
.model_name = "Fodtrack",
|
||||
.mfg_name = "XQ2FOD",
|
||||
.version = "0.1",
|
||||
.version = "0.2",
|
||||
.copyright = "LGPL",
|
||||
.status = RIG_STATUS_NEW,
|
||||
.status = RIG_STATUS_STABLE,
|
||||
.rot_type = ROT_TYPE_OTHER,
|
||||
.port_type = RIG_PORT_PARALLEL,
|
||||
.write_delay = 0,
|
||||
|
|
73
src/serial.c
73
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.36 2003-08-25 22:35:55 fillods Exp $
|
||||
* $Id: serial.c,v 1.37 2003-09-28 15:34:44 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
|
||||
|
@ -84,6 +84,22 @@
|
|||
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
#include <linux/ppdev.h>
|
||||
#include <linux/parport.h>
|
||||
|
||||
/*
|
||||
* These control port bits are active low.
|
||||
* We toggle them so that this weirdness doesn't get get propagated
|
||||
* through our interface.
|
||||
*/
|
||||
#define CP_ACTIVE_LOW_BITS 0x0B
|
||||
|
||||
/*
|
||||
* These status port bits are active low.
|
||||
* We toggle them so that this weirdness doesn't get get propagated
|
||||
* through our interface.
|
||||
*/
|
||||
#define SP_ACTIVE_LOW_BITS 0x80
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -620,6 +636,7 @@ int ser_dcd_get(port_t *p, dcd_t *dcdx)
|
|||
int par_open(port_t *port)
|
||||
{
|
||||
int fd;
|
||||
int mode;
|
||||
|
||||
if (!port->pathname)
|
||||
return -RIG_EINVAL;
|
||||
|
@ -627,14 +644,16 @@ int par_open(port_t *port)
|
|||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
fd = open(port->pathname, O_RDWR);
|
||||
if (fd < 0) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Opening device \"%s\": %s\n", port->pathname, strerror(errno));
|
||||
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno));
|
||||
return -RIG_EIO;
|
||||
}
|
||||
if (ioctl(fd, PPCLAIM) < 0) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Claiming device \"%s\": %s\n", port->pathname, strerror(errno));
|
||||
mode = IEEE1284_MODE_COMPAT;
|
||||
if (ioctl (fd, PPSETMODE, &mode) != 0) {
|
||||
rig_debug(RIG_DEBUG_ERR, "PPSETMODE \"%s\": %s\n", port->pathname, strerror(errno));
|
||||
close(fd);
|
||||
return -RIG_EIO;
|
||||
}
|
||||
|
||||
#elif defined(WIN32)
|
||||
fd = (int)CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE,
|
||||
0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
@ -653,12 +672,11 @@ int par_open(port_t *port)
|
|||
int par_close(port_t *port)
|
||||
{
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
ioctl(port->fd, PPRELEASE);
|
||||
#elif defined(WIN32)
|
||||
CloseHandle((HANDLE)(port->fd));
|
||||
return RIG_OK;
|
||||
CloseHandle((HANDLE)(port->fd));
|
||||
return RIG_OK;
|
||||
#endif
|
||||
return close(port->fd);
|
||||
return close(port->fd);
|
||||
}
|
||||
|
||||
int par_write_data(port_t *port, unsigned char data)
|
||||
|
@ -703,7 +721,8 @@ int par_write_control(port_t *port, unsigned char control)
|
|||
{
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
int status;
|
||||
status = ioctl(port->fd, PPWCONTROL, &control);
|
||||
unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
|
||||
status = ioctl(port->fd, PPWCONTROL, &ctrl);
|
||||
return status == 0 ? RIG_OK : -RIG_EIO;
|
||||
#elif defined(WIN32)
|
||||
unsigned char ctr = control;
|
||||
|
@ -735,7 +754,9 @@ int par_read_control(port_t *port, unsigned char *control)
|
|||
{
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
int status;
|
||||
status = ioctl(port->fd, PPRCONTROL, control);
|
||||
unsigned char ctrl;
|
||||
status = ioctl(port->fd, PPRCONTROL, &ctrl);
|
||||
*control = ctrl ^ CP_ACTIVE_LOW_BITS;
|
||||
return status == 0 ? RIG_OK : -RIG_EIO;
|
||||
#elif defined(WIN32)
|
||||
char ret;
|
||||
|
@ -756,7 +777,9 @@ int par_read_status(port_t *port, unsigned char *status)
|
|||
{
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
int ret;
|
||||
ret = ioctl(port->fd, PPRSTATUS, status);
|
||||
unsigned char sta;
|
||||
ret = ioctl(port->fd, PPRSTATUS, &sta);
|
||||
*status = sta ^ SP_ACTIVE_LOW_BITS;
|
||||
return ret == 0 ? RIG_OK : -RIG_EIO;
|
||||
#elif defined(WIN32)
|
||||
unsigned char ret;
|
||||
|
@ -773,6 +796,34 @@ int par_read_status(port_t *port, unsigned char *status)
|
|||
}
|
||||
|
||||
|
||||
int par_lock(port_t *port)
|
||||
{
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
if (ioctl(port->fd, PPCLAIM) < 0) {
|
||||
rig_debug(RIG_DEBUG_ERR, "Claiming device \"%s\": %s\n", port->pathname, strerror(errno));
|
||||
return -RIG_EIO;
|
||||
}
|
||||
return RIG_OK;
|
||||
#elif defined(WIN32)
|
||||
return RIG_OK;
|
||||
#endif
|
||||
return -RIG_ENIMPL;
|
||||
}
|
||||
|
||||
int par_unlock(port_t *port)
|
||||
{
|
||||
#ifdef HAVE_LINUX_PPDEV_H
|
||||
if (ioctl(port->fd, PPRELEASE) < 0) {
|
||||
rig_debug(RIG_DEBUG_ERR, "Releasing device \"%s\": %s\n", port->pathname, strerror(errno));
|
||||
return -RIG_EIO;
|
||||
}
|
||||
return RIG_OK;
|
||||
#elif defined(WIN32)
|
||||
return RIG_OK;
|
||||
#endif
|
||||
return -RIG_ENIMPL;
|
||||
}
|
||||
|
||||
|
||||
int par_ptt_set(port_t *p, ptt_t pttx)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Interface - serial communication header
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton
|
||||
*
|
||||
* $Id: serial.h,v 1.21 2003-08-25 22:35:55 fillods Exp $
|
||||
* $Id: serial.h,v 1.22 2003-09-28 15:34:44 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
|
||||
|
@ -26,6 +26,7 @@
|
|||
#include <hamlib/rig.h>
|
||||
#include "iofunc.h"
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern HAMLIB_EXPORT(int) serial_open(port_t *rs);
|
||||
extern HAMLIB_EXPORT(int) serial_setup(port_t *rs);
|
||||
|
@ -53,6 +54,9 @@ 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);
|
||||
extern HAMLIB_EXPORT(int) par_read_status(port_t *p, unsigned char *status);
|
||||
extern HAMLIB_EXPORT(int) par_lock(port_t *p);
|
||||
extern HAMLIB_EXPORT(int) par_unlock(port_t *p);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _SERIAL_H */
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue