added usb port type support

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2046 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.5
Stéphane Fillod, F8CFE 2005-11-01 23:02:02 +00:00
rodzic 86f5db112d
commit 36c62542ae
5 zmienionych plików z 192 dodań i 9 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - API header
* Copyright (c) 2000-2005 by Stephane Fillod and Frank Singleton
*
* $Id: rig.h,v 1.108 2005-04-20 14:44:01 fillods Exp $
* $Id: rig.h,v 1.109 2005-11-01 23:02:02 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
@ -159,7 +159,8 @@ typedef enum rig_port_e {
RIG_PORT_DTMF, /*!< DTMF protocol bridge via another rig, eg. Kenwood Sky Cmd System */
RIG_PORT_ULTRA, /*!< IrDA Ultra protocol! */
RIG_PORT_RPC, /*!< RPC wrapper */
RIG_PORT_PARALLEL /*!< Parallel port */
RIG_PORT_PARALLEL, /*!< Parallel port */
RIG_PORT_USB /*!< USB port */
} rig_port_t;
/**
@ -1242,9 +1243,7 @@ typedef struct {
dcd_type_t dcd; /*!< DCD port type */
} type;
int fd; /*!< File descriptor */
#if defined(__CYGWIN__) || defined(_WIN32)
void* deprecated_handle; /*!< Place holder for deprecated field */
#endif
void* handle; /*!< handle for USB */
int write_delay; /*!< Delay between each byte sent out, in ms */
int post_write_delay; /*!< Delay between each commands send out, in ms */
@ -1266,6 +1265,13 @@ typedef struct {
struct {
int pin; /*!< Parrallel port pin number */
} parallel; /*!< parallel attributes */
struct {
int vid; /*!< Vendor ID */
int pid; /*!< Product ID */
int conf; /*!< Configuration */
int iface; /*!< interface */
int alt; /*!< alternate */
} usb; /*!< USB attributes */
} parm; /*!< Port parameter union */
} hamlib_port_t;

Wyświetl plik

@ -1,15 +1,15 @@
INCLUDES = @INCLUDES@ @INCLTDL@
RIGSRC = rig.c serial.c misc.c register.c event.c cal.c conf.c tones.c \
rotator.c locator.c rot_reg.c rot_conf.c iofunc.c ext.c \
mem.c settings.c parallel.c debug.c
mem.c settings.c parallel.c usb_port.c debug.c
lib_LTLIBRARIES = libhamlib.la
libhamlib_la_SOURCES = $(RIGSRC)
libhamlib_la_LDFLAGS = $(WINLDFLAGS) -no-undefined -release @VERSION@ -version-info @ABI_VERSION@:4:0
libhamlib_la_CFLAGS = -DIN_HAMLIB $(AM_CFLAGS) -DHAMLIB_MODULE_DIR=\"$(libdir)\"
libhamlib_la_LIBADD = @LIBLTDL@ $(top_builddir)/lib/libmisc.la @MATH_LIBS@
libhamlib_la_LIBADD = @LIBLTDL@ $(top_builddir)/lib/libmisc.la @MATH_LIBS@ $(LIBUSB_LIBS)
noinst_HEADERS = event.h misc.h serial.h iofunc.h cal.h tones.h \
rot_conf.h token.h idx_builtin.h register.h par_nt.h \
parallel.h
parallel.h usb_port.h

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - main file
* Copyright (c) 2000-2005 by Stephane Fillod and Frank Singleton
*
* $Id: rig.c,v 1.90 2005-06-20 21:15:48 fillods Exp $
* $Id: rig.c,v 1.91 2005-11-01 23:02:02 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
@ -59,6 +59,7 @@
#include "hamlib/rig.h"
#include "serial.h"
#include "parallel.h"
#include "usb_port.h"
#include "event.h"
/**
@ -451,6 +452,12 @@ int HAMLIB_API rig_open(RIG *rig)
rs->rigport.fd = status;
break;
case RIG_PORT_USB:
status = usb_port_open(&rs->rigport);
if (status < 0)
return status;
break;
case RIG_PORT_NONE:
case RIG_PORT_RPC:
break; /* ez :) */
@ -632,6 +639,10 @@ int HAMLIB_API rig_close(RIG *rig)
case RIG_PORT_PARALLEL:
par_close(&rs->rigport);
break;
case RIG_PORT_USB:
usb_port_close(&rs->rigport);
break;
default:
close(rs->rigport.fd);
}

129
src/usb_port.c 100644
Wyświetl plik

@ -0,0 +1,129 @@
/*
* Hamlib Interface - parallel communication low-level support
* Copyright (c) 2000-2005 by Stephane Fillod
*
* $Id: usb_port.c,v 1.1 2005-11-01 23:02:02 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
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/*
* Compile only this model if libusb is available
*/
#ifdef HAVE_USB_H
#include <stdlib.h>
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <usb.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <usb.h>
#include "usb_port.h"
struct usb_device * find_device(const hamlib_port_t *port)
{
struct usb_bus *p;
struct usb_device *q;
p = usb_get_busses();
while (p != NULL){
q = p->devices;
while (q != NULL){
if (q->descriptor.idVendor == port->parm.usb.vid &&
q->descriptor.idProduct == port->parm.usb.pid) {
return q;
}
q = q->next;
}
p = p->next;
}
return NULL; /* not found */
}
int usb_port_open(hamlib_port_t *port)
{
struct usb_dev_handle *udh;
struct usb_device *dev;
if (!port->pathname)
return -RIG_EINVAL;
usb_init (); /* usb library init */
usb_find_busses ();
dev = find_device(port);
if (dev == 0)
return -RIG_EIO;
udh = usb_open (dev);
if (udh == 0)
return -RIG_EIO;
if (dev != usb_device (udh)){
rig_debug(RIG_DEBUG_ERR, "%s:%d: internal error!\n", __FILE__, __LINE__);
return -RIG_EINTERNAL;
}
if (usb_set_configuration (udh, port->parm.usb.conf) < 0){
rig_debug(RIG_DEBUG_ERR, "%s: usb_claim_interface: failed conf %d: %s\n",
__FUNCTION__,port->parm.usb.conf, usb_strerror());
usb_close (udh);
return 0;
}
if (usb_claim_interface (udh, port->parm.usb.iface) < 0){
rig_debug(RIG_DEBUG_ERR, "%s:usb_claim_interface: failed interface %d: %s\n",
__FUNCTION__,port->parm.usb.iface, usb_strerror());
usb_close (udh);
return 0;
}
if (usb_set_altinterface (udh, port->parm.usb.alt) < 0){
fprintf (stderr, "%s:usb_set_alt_interface: failed: %s\n", __FUNCTION__,
usb_strerror());
usb_release_interface (udh, port->parm.usb.iface);
usb_close (udh);
return 0;
}
port->handle = (void*) udh;
return RIG_OK;
}
int usb_port_close(hamlib_port_t *port)
{
struct usb_dev_handle *udh = port->handle;
/* we're assuming that closing an interface automatically releases it. */
return usb_close (udh) == 0 ? RIG_OK : -RIG_EIO;
}
#endif /* HAVE_LIBUSB */

37
src/usb_port.h 100644
Wyświetl plik

@ -0,0 +1,37 @@
/*
* Hamlib Interface - USB communication header
* Copyright (c) 2005 by Stephane Fillod
*
* $Id: usb_port.h,v 1.1 2005-11-01 23:02:02 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
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef _USB_PORT_H
#define _USB_PORT_H 1
#include <hamlib/rig.h>
#include "iofunc.h"
__BEGIN_DECLS
/* Hamlib internal use, see rig.c */
int usb_port_open(hamlib_port_t *p);
int usb_port_close(hamlib_port_t *p);
__END_DECLS
#endif /* _USB_PORT_H */