diff -u --recursive --new-file --exclude=CVS libgpio.orig/.cvsignore libgpio/.cvsignore --- libgpio.orig/.cvsignore Fri Jul 21 20:56:24 2000 +++ libgpio/.cvsignore Fri Aug 4 23:48:21 2000 @@ -13,15 +13,8 @@ Makefile Makefile.in gpio-config -gpio.h .deps .libs gpio_test -gpio.lo -gpio-serial.lo -gpio-parallel.lo -gpio-network.lo -gpio-ieee1394.lo -gpio-usb.lo gpioConf.sh libgpio.la diff -u --recursive --new-file --exclude=CVS libgpio.orig/ieee1394/.cvsignore libgpio/ieee1394/.cvsignore --- libgpio.orig/ieee1394/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/ieee1394/.cvsignore Fri Aug 4 23:45:05 2000 @@ -0,0 +1,5 @@ +*.lo +Makefile +Makefile.in +.deps +.libs diff -u --recursive --new-file --exclude=CVS libgpio.orig/include/.cvsignore libgpio/include/.cvsignore --- libgpio.orig/include/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/include/.cvsignore Fri Aug 4 23:48:21 2000 @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff -u --recursive --new-file --exclude=CVS libgpio.orig/include/Makefile.am libgpio/include/Makefile.am --- libgpio.orig/include/Makefile.am Tue Aug 1 01:41:26 2000 +++ libgpio/include/Makefile.am Tue Aug 22 13:59:24 2000 @@ -1,5 +1,6 @@ gpioincdir = $(includedir)/gpio gpioinc_HEADERS = gpio.h \ + gpio-port.h \ gpio-serial.h \ gpio-parallel.h \ gpio-usb.h \ diff -u --recursive --new-file --exclude=CVS libgpio.orig/include/gpio-port.h libgpio/include/gpio-port.h --- libgpio.orig/include/gpio-port.h Thu Jan 1 01:00:00 1970 +++ libgpio/include/gpio-port.h Thu Sep 14 19:48:05 2000 @@ -0,0 +1,83 @@ + +/* Windows Portability + ------------------------------------------------------------------ */ + +#ifdef WIN32 + +#include +#include +#include +#include +#include +#include + +#define IOLIBS "." +#define strcasecmp _stricmp +#define snprintf _snprintf + +/* Work-around for readdir() */ +typedef struct { + HANDLE handle; + int got_first; + WIN32_FIND_DATA search; + char dir[1024]; + char drive[32][2]; + int drive_count; + int drive_index; +} GPIOWINDIR; + +/* Sleep functionality */ +#define GPIO_SLEEP(_ms) Sleep(_ms) + +/* Dynamic library functions */ +#define GPIO_DLOPEN(_filename) LoadLibrary(_filename) +#define GPIO_DLSYM(_handle, _funcname) GetProcAddress(_handle, _funcname) +#define GPIO_DLCLOSE(_handle) FreeLibrary(_handle) +#define GPIO_DLERROR() "Windows Error" + +/* Directory-oriented functions */ +#define GPIO_DIR GPIOWINDIR * +#define GPIO_DIRENT WIN32_FIND_DATA * +#define GPIO_DIR_DELIM '\\' + + +#else + +/* POSIX Portability + ------------------------------------------------------------------ */ + +/* yummy. :) */ + +#include +#include +#include +#include +#include + +/* Sleep functionality */ +#define GPIO_SLEEP(_ms) usleep(_ms*1000) + +/* Dynamic library functions */ +#define GPIO_DLOPEN(_filename) dlopen(_filename, RTLD_LAZY) +#define GPIO_DLSYM(_handle, _funcname) dlsym(_handle, _funcname) +#define GPIO_DLCLOSE(_handle) dlclose(_handle) +#define GPIO_DLERROR() dlerror() + +/* Directory-oriented functions */ +#define GPIO_DIR DIR * +#define GPIO_DIRENT struct dirent * +#ifdef OS2 +#define GPIO_DIR_DELIM '\\' +#else +#define GPIO_DIR_DELIM '/' +#endif /* OS2 */ + +#endif /* else */ + +int GPIO_MKDIR (char *dirname); +GPIO_DIR GPIO_OPENDIR (char *dirname); +GPIO_DIRENT GPIO_READDIR (GPIO_DIR d); +char* GPIO_FILENAME (GPIO_DIRENT de); +int GPIO_CLOSEDIR (GPIO_DIR dir); +int GPIO_IS_FILE (char *filename); +int GPIO_IS_DIR (char *dirname); diff -u --recursive --new-file --exclude=CVS libgpio.orig/include/gpio-serial.h libgpio/include/gpio-serial.h --- libgpio.orig/include/gpio-serial.h Tue Aug 1 01:41:26 2000 +++ libgpio/include/gpio-serial.h Tue Aug 22 13:59:28 2000 @@ -7,14 +7,15 @@ /* Linux */ #ifdef linux -#define GPIO_SERIAL_PREFIX "/dev/ttyS%i" +/* devfs is accounted for in the implementation */ +#define GPIO_SERIAL_PREFIX "/dev/ttyS%i" #define GPIO_SERIAL_RANGE_LOW 0 #define GPIO_SERIAL_RANGE_HIGH 32 #endif /* BSD */ #if defined(__FreeBSD__) || defined(__NetBSD__) -#define GPIO_SERIAL_PREFIX "/dev/tty0%i" +#define GPIO_SERIAL_PREFIX "/dev/tty0%i" #define GPIO_SERIAL_RANGE_LOW 0 #define GPIO_SERIAL_RANGE_HIGH 32 #endif @@ -35,14 +36,14 @@ #endif /* Windows */ -#ifdef WIN -#define GPIO_SERIAL_PREFIX "COM%i:" -#define GPIO_SERIAL_RANGE_LOW 0 -#define GPIO_SERIAL_RANGE_HIGH 32 +#ifdef WIN32 +#define GPIO_SERIAL_PREFIX "COM%i:" +#define GPIO_SERIAL_RANGE_LOW 1 +#define GPIO_SERIAL_RANGE_HIGH 4 #endif #ifdef OS2 -#define GPIO_SERIAL_PREFIX "COM%i" +#define GPIO_SERIAL_PREFIX "COM%i" #define GPIO_SERIAL_RANGE_LOW 1 #define GPIO_SERIAL_RANGE_HIGH 4 #endif @@ -51,8 +52,7 @@ /* Default */ #ifndef GPIO_SERIAL_PREFIX -#warning GPIO_SERIAL_PREFIX not defined. Enumeration will fail -#define GPIO_SERIAL_PREFIX NULL +#define GPIO_SERIAL_PREFIX "/dev/cua%i" #define GPIO_SERIAL_RANGE_LOW 0 #define GPIO_SERIAL_RANGE_HIGH 0 #endif @@ -74,7 +74,5 @@ #define PIN_DSR 3 #define PIN_CD 4 #define PIN_RING 5 - - #endif /* _GPIO_SERIAL_H_ */ diff -u --recursive --new-file --exclude=CVS libgpio.orig/include/gpio.h libgpio/include/gpio.h --- libgpio.orig/include/gpio.h Tue Aug 1 01:41:26 2000 +++ libgpio/include/gpio.h Mon Sep 4 14:06:44 2000 @@ -6,6 +6,10 @@ #include #endif +/* Include the portability layer */ +#include "gpio-port.h" + +/* Include serial by default */ #include "gpio-serial.h" #ifdef GPIO_PARALLEL @@ -40,10 +44,17 @@ #define GPIO_MAX_BUF_LEN 4096 /* max length of receive buffer */ +/* Return values (errors are negative) */ #define GPIO_OK 0 #define GPIO_ERROR -1 /* IO return codes */ #define GPIO_TIMEOUT -2 +/* Debugging definitions for gpio_init */ +#define GPIO_DEBUG_NONE 0 +#define GPIO_DEBUG_LOW 1 +#define GPIO_DEBUG_MEDIUM 2 +#define GPIO_DEBUG_HIGH 3 + /* Specify the types of devices */ typedef enum { GPIO_DEVICE_SERIAL, @@ -102,8 +113,9 @@ int (*update) (gpio_device *); /* for serial and parallel devices */ - int (*get_pin) (gpio_device *, int); - int (*set_pin) (gpio_device *, int, int); + int (*get_pin) (gpio_device *, int); + int (*set_pin) (gpio_device *, int, int); + int (*send_break)(gpio_device *, int); #ifdef GPIO_USB /* for USB devices */ @@ -113,6 +125,7 @@ int (*msg_read) (gpio_device * dev, int value, char *bytes, int size); #endif }; + typedef struct gpio_operations gpio_operations; /* Function pointers for the dynamic libraries */ @@ -134,7 +147,11 @@ gpio_device_settings settings_saved; int device_fd; +#ifdef WIN32 + HANDLE device_handle; +#else void *device_handle; +#endif int timeout; /* in milli seconds */ void *library_handle; @@ -143,15 +160,16 @@ struct usb_device *usb_device; #endif + int debug_level; }; /* gpio Core functions -------------------------------------------------------------- */ - void gpio_debug_printf (char *format, ...); + void gpio_debug_printf (int target_debug_level, int debug_level, char *format, ...); /* issues debugging messages */ - int gpio_init (); + int gpio_init (int debug_level); /* Initializes the library. return values: successful: GPIO_OK @@ -186,6 +204,10 @@ unsuccessful: GPIO_ERROR */ + int gpio_set_debug (gpio_device *dev, int debug_level); + /* + Set the debugging level specific to a device + */ int gpio_open (gpio_device *dev); /* Open the device for reading and writing @@ -266,6 +288,9 @@ successful: status unsuccessful: GPIO_ERROR */ + + int gpio_send_break (gpio_device *dev, int duration); + /* send a break (duration is in seconds) */ /* USB specific functions -------------------------------------------------------------- */ diff -u --recursive --new-file --exclude=CVS libgpio.orig/libgpio/.cvsignore libgpio/libgpio/.cvsignore --- libgpio.orig/libgpio/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/libgpio/.cvsignore Fri Aug 4 23:49:37 2000 @@ -0,0 +1,6 @@ +*.lo +Makefile +Makefile.in +.deps +.libs +*.la diff -u --recursive --new-file --exclude=CVS libgpio.orig/libgpio/Makefile.am libgpio/libgpio/Makefile.am --- libgpio.orig/libgpio/Makefile.am Tue Aug 1 01:41:27 2000 +++ libgpio/libgpio/Makefile.am Tue Aug 22 13:59:29 2000 @@ -4,10 +4,11 @@ CFLAGS = @IOLIB_CFLAGS@ \ -DIOLIBS=\"$(prefix)/lib/gpio\" \ -g -LDFLAGS = @LDFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g -ldl ## Compile the IO library into a shared library lib_LTLIBRARIES = libgpio.la libgpio_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ libgpio_la_SOURCES = gpio.c \ - library.c library.h + library.c library.h \ + port.c diff -u --recursive --new-file --exclude=CVS libgpio.orig/libgpio/gpio.c libgpio/libgpio/gpio.c --- libgpio.orig/libgpio/gpio.c Fri Aug 4 16:37:47 2000 +++ libgpio/libgpio/gpio.c Mon Sep 4 14:06:45 2000 @@ -29,22 +25,23 @@ #include #include #include "gpio.h" +#include "library.h" gpio_device_info device_list[256]; -int device_count; +int device_count; /* Toggle to turn on/off debugging */ -int device_debug=0; - -void gpio_debug_printf (char *format, ...) { +int glob_debug_level=0; - va_list pvar; +void gpio_debug_printf (int target_debug_level, int debug_level, char *format, ...) +{ + va_list arg; - if (device_debug) { + if ((debug_level > 0)&&(debug_level >= target_debug_level)) { fprintf(stderr, "gpio: "); - va_start(pvar, format); - vfprintf(stderr, format, pvar); - va_end(pvar); + va_start(arg, format); + vfprintf(stderr, format, arg); + va_end(arg); fprintf(stderr, "\n"); } } @@ -54,178 +51,266 @@ ---------------------------------------------------------------- */ -int gpio_init() +int gpio_init(int debug) { - gpio_operations *ops; - /* Enumerate all the available devices */ - device_count = 0; - - return (gpio_library_list(device_list, &device_count)); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Initializing..."); + /* Enumerate all the available devices */ + device_count = 0; + glob_debug_level = debug; + return (gpio_library_list(device_list, &device_count)); } int gpio_get_device_count(void) { - return device_count; + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Device count: %i", device_count); + return device_count; } int gpio_get_device_info(int device_number, gpio_device_info *info) { - memcpy(info, &device_list[device_number], sizeof(device_list[device_number])); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Getting device info..."); - return GPIO_OK; + memcpy(info, &device_list[device_number], sizeof(device_list[device_number])); + + return GPIO_OK; } gpio_device *gpio_new(gpio_device_type type) - /* Create a new IO device */ + /* Create a new IO device */ { - gpio_device *dev; - gpio_device_settings settings; - char buf[1024]; - - dev = (gpio_device *) malloc(sizeof(gpio_device)); - if (!dev) { - fprintf(stderr, "unable to allocate memory for gpio device\n"); - return NULL; - } + gpio_device *dev; + gpio_device_settings settings; + char buf[1024]; + + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Creating new device... "); + + dev = (gpio_device *) malloc(sizeof(gpio_device)); + if (!dev) { + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Can not allocate device!"); + return NULL; + } + memset(dev, 0, sizeof(gpio_device)); - if (gpio_library_load(dev, type)) { - /* whoops! that type of device isn't supported */ - free(dev); - return NULL; - } + if (gpio_library_load(dev, type)) { + /* whoops! that type of device isn't supported */ + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Device type not supported! (%i)", type); + free(dev); + return NULL; + } - dev->type = type; - dev->device_fd = 0; + dev->debug_level = glob_debug_level; + + dev->type = type; + dev->device_fd = 0; + dev->ops->init(dev); - switch (dev->type) { - case GPIO_DEVICE_SERIAL: - sprintf(buf, GPIO_SERIAL_PREFIX, GPIO_SERIAL_RANGE_LOW); - strcpy(settings.serial.port, buf); - /* set some defaults */ - settings.serial.speed = 9600; - settings.serial.bits = 8; - settings.serial.parity = 0; - settings.serial.stopbits = 1; - gpio_set_settings(dev, settings); - gpio_set_timeout(dev, 5000); - break; - case GPIO_DEVICE_PARALLEL: + switch (dev->type) { + case GPIO_DEVICE_SERIAL: + sprintf(buf, GPIO_SERIAL_PREFIX, GPIO_SERIAL_RANGE_LOW); + strcpy(settings.serial.port, buf); + /* set some defaults */ + settings.serial.speed = 9600; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + gpio_set_settings(dev, settings); + gpio_set_timeout(dev, 500); + break; + case GPIO_DEVICE_PARALLEL: #ifdef GPIO_PARALLEL - sprintf(buf, GPIO_SERIAL_PREFIX, GPIO_SERIAL_RANGE_LOW); - strcpy(settings.parallel.port, buf); + sprintf(buf, GPIO_SERIAL_PREFIX, GPIO_SERIAL_RANGE_LOW); + strcpy(settings.parallel.port, buf); #endif - break; - case GPIO_DEVICE_NETWORK: + break; + case GPIO_DEVICE_NETWORK: #ifdef GPIO_NETWORK - gpio_set_timeout(dev, 50000); + gpio_set_timeout(dev, 50000); #endif - break; - case GPIO_DEVICE_USB: + break; + case GPIO_DEVICE_USB: #ifdef GPIO_USB - gpio_set_timeout(dev, 5000); + gpio_set_timeout(dev, 5000); #endif - break; - case GPIO_DEVICE_IEEE1394: + break; + case GPIO_DEVICE_IEEE1394: #ifdef GPIO_IEEE1394 - /* blah ? */ + /* blah ? */ #endif - break; - default: - /* ERROR! */ - break; - } + break; + default: + /* ERROR! */ + break; + } - dev->ops->init(dev); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "Created device successfully..."); - return (dev); + return (dev); +} + +int gpio_set_debug (gpio_device *dev, int debug_level) +{ + dev->debug_level = debug_level; + + return (GPIO_OK); } int gpio_open(gpio_device *dev) - /* Open a device for reading/writing */ + /* Open a device for reading/writing */ { - int retval = 0; + int retval = 0; - /* Try to open device */ - retval = dev->ops->open(dev); - if (retval == GPIO_OK) { - /* Now update the settings */ - retval = dev->ops->update(dev); - if (retval != GPIO_OK) { - dev->device_fd = 0; - return GPIO_ERROR; - } - return GPIO_OK; - } - return GPIO_ERROR; + /* Try to open device */ + retval = dev->ops->open(dev); + if (retval == GPIO_OK) { + /* Now update the settings */ + retval = dev->ops->update(dev); + if (retval != GPIO_OK) { + dev->device_fd = 0; + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_open: update error"); + return GPIO_ERROR; + } + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_open: OK"); + return GPIO_OK; + } + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_open: open error"); + return GPIO_ERROR; } int gpio_close(gpio_device *dev) - /* Close the device to prevent reading/writing */ + /* Close the device to prevent reading/writing */ { - int retval = 0; + int retval = 0; - if (!dev) - return GPIO_ERROR; - if (dev->type == GPIO_DEVICE_SERIAL && dev->device_fd == 0) - return GPIO_OK; - - retval = dev->ops->close(dev); - dev->device_fd = 0; + if (!dev) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_close: bad device"); + return GPIO_ERROR; + } + if (dev->type == GPIO_DEVICE_SERIAL && dev->device_fd == 0) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_close: OK"); + return GPIO_OK; + } - return retval; + retval = dev->ops->close(dev); + dev->device_fd = 0; + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_close: close %s", retval == GPIO_OK? "ok":"error"); + return retval; } int gpio_free(gpio_device *dev) - /* Frees a device struct */ + /* Frees a device struct */ { - int retval = dev->ops->exit(dev); + int retval = dev->ops->exit(dev); - gpio_library_close(dev); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_free: exit %s", retval < 0? "error":"ok"); - free(dev); + gpio_library_close(dev); + free(dev); - return GPIO_OK; + return GPIO_OK; } int gpio_write(gpio_device *dev, char *bytes, int size) - /* Called to write "bytes" to the IO device */ + /* Called to write "bytes" to the IO device */ { - return dev->ops->write(dev, bytes, size); + int x, retval; + char t[8]; + char *buf; + + if (glob_debug_level == GPIO_DEBUG_HIGH) { + buf = (char *)malloc(sizeof(char)*(4*size+64)); + buf[0] = 0; + for (x=0; xdebug_level, + "gpio_write: (size=%05i) DATA: %s", size, buf); + free(buf); + } + retval = dev->ops->write(dev, bytes, size); + + if (retval == GPIO_TIMEOUT) + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_write: write timeout"); + if (retval == GPIO_ERROR) + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_write: write error"); + + return (retval); } int gpio_read(gpio_device *dev, char *bytes, int size) - /* Reads data from the device into the "bytes" buffer. - "bytes" should be large enough to hold all the data. - */ -{ - return dev->ops->read(dev, bytes, size); + /* Reads data from the device into the "bytes" buffer. + "bytes" should be large enough to hold all the data. + */ +{ + int x, retval; + char t[8]; + char *buf; + + retval = dev->ops->read(dev, bytes, size); + + if ((retval > 0)&&(glob_debug_level == GPIO_DEBUG_HIGH)) { + buf = (char *)malloc(sizeof(char)*(4*retval+64)); + buf[0] = 0; + for (x=0; xdebug_level, + "gpio_read: (size=%05i) DATA: %s", retval, buf); + free(buf); + } + + if (retval == GPIO_TIMEOUT) + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_read: read timeout"); + if (retval == GPIO_ERROR) + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_read: read error"); + + return (retval); } int gpio_set_timeout(gpio_device *dev, int millisec_timeout) { - dev->timeout = millisec_timeout; - return GPIO_OK; + dev->timeout = millisec_timeout; + + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_set_timeout: value=%ims", millisec_timeout); + + return GPIO_OK; } int gpio_get_timeout(gpio_device *dev, int *millisec_timeout) { - *millisec_timeout = dev->timeout; - return GPIO_OK; + *millisec_timeout = dev->timeout; + + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_get_timeout: value=%ims", *millisec_timeout); + + return GPIO_OK; } int gpio_set_settings(gpio_device *dev, gpio_device_settings settings) { - /* need to memcpy() settings to dev->settings */ - memcpy(&dev->settings_pending, &settings, sizeof(dev->settings_pending)); + int retval; + + /* need to memcpy() settings to dev->settings */ + memcpy(&dev->settings_pending, &settings, sizeof(dev->settings_pending)); - return dev->ops->update(dev); + retval = dev->ops->update(dev); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_set_settings: update %s", retval < 0? "error":"ok"); + return (retval); } int gpio_get_settings(gpio_device *dev, gpio_device_settings * settings) { - memcpy(settings, &dev->settings, sizeof(gpio_device_settings)); - return GPIO_OK; + memcpy(settings, &dev->settings, sizeof(gpio_device_settings)); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_get_settings: ok"); + + return GPIO_OK; } /* Serial and Parallel-specific functions */ @@ -233,20 +318,48 @@ int gpio_get_pin(gpio_device *dev, int pin) { - if (!dev->ops->get_pin) - return (GPIO_ERROR); + int retval; + + if (!dev->ops->get_pin) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_get_pin: get_pin NULL"); + return (GPIO_ERROR); + } - return (dev->ops->get_pin(dev, pin)); + retval = dev->ops->get_pin(dev, pin); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_get_pin: get_pin %s", retval < 0? "error":"ok"); + return (retval); } int gpio_set_pin(gpio_device *dev, int pin, int level) { - if (!dev->ops->get_pin) - return (GPIO_ERROR); + int retval; - return (dev->ops->set_pin(dev, pin, level)); + if (!dev->ops->get_pin) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_set_pin: set_pin NULL"); + return (GPIO_ERROR); + } + + retval = dev->ops->set_pin(dev, pin, level); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_set_pin: set_pin %s", retval < 0? "error":"ok"); + return (retval); } +int gpio_send_break (gpio_device *dev, int duration) +{ + int retval; + + if (!dev->ops->send_break) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, "gpio_break: gpio_break NULL"); + return (GPIO_ERROR); + } + + retval = dev->ops->send_break(dev, duration); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_send_break: send_break %s", retval < 0? "error":"ok"); + return (retval); +} /* USB-specific functions */ /* ------------------------------------------------------------------ */ @@ -255,32 +368,65 @@ int gpio_usb_find_device (gpio_device * dev, int idvendor, int idproduct) { - if (!dev->ops->find_device) - return (GPIO_ERROR); + int retval; - return (dev->ops->find_device(dev, idvendor, idproduct)); + if (!dev->ops->find_device) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_find_device: find_device NULL"); + return (GPIO_ERROR); + } + + retval = dev->ops->find_device(dev, idvendor, idproduct); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_find_device: find_device (0x%04x 0x%04x) %s", + idvendor, idproduct, retval < 0? "error":"ok"); + return (retval); } int gpio_usb_clear_halt (gpio_device * dev) { - if (!dev->ops->clear_halt) - return (GPIO_ERROR); + int retval; + + if (!dev->ops->clear_halt) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_clear_halt: clear_halt NULL"); + return (GPIO_ERROR); + } - return (dev->ops->clear_halt(dev)); + retval = dev->ops->clear_halt(dev); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_clear_halt: clear_halt %s", retval < 0? "error":"ok"); + return (retval); } int gpio_usb_msg_write (gpio_device * dev, int value, char *bytes, int size) { - if (!dev->ops->msg_write) - return (GPIO_ERROR); + int retval; - return (dev->ops->msg_write(dev, value, bytes, size)); + if (!dev->ops->msg_write) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_msg_write: msg_write NULL"); + return (GPIO_ERROR); + } + + retval = dev->ops->msg_write(dev, value, bytes, size); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_msg_write: msg_write %s", retval < 0? "error":"ok"); + return (retval); } int gpio_usb_msg_read (gpio_device * dev, int value, char *bytes, int size) { - if (!dev->ops->msg_read) - return (GPIO_ERROR); + int retval; + + if (!dev->ops->msg_read) { + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_msg_read: msg_read NULL"); + return (GPIO_ERROR); + } - return (dev->ops->msg_read(dev, value, bytes, size)); + retval = dev->ops->msg_read(dev, value, bytes, size); + gpio_debug_printf(GPIO_DEBUG_LOW, dev->debug_level, + "gpio_usb_msg_read: msg_read %s", retval < 0? "error":"ok"); + return (retval); } #endif diff -u --recursive --new-file --exclude=CVS libgpio.orig/libgpio/library.c libgpio/libgpio/library.c --- libgpio.orig/libgpio/library.c Tue Aug 1 02:20:11 2000 +++ libgpio/libgpio/library.c Fri Sep 15 12:28:53 2000 @@ -1,75 +1,85 @@ -#include +#include #include #include "gpio.h" #include "library.h" extern int device_count; +extern int glob_debug_level; extern gpio_device_info device_list[]; void *device_lh; int gpio_library_is_valid (char *filename) { - void *lh; + void *lh; - if ((lh = dlopen(filename, RTLD_LAZY))==NULL) { - gpio_debug_printf("%s is not a library (%s) ", filename, dlerror()); - return (GPIO_ERROR); + if ((lh = GPIO_DLOPEN(filename))==NULL) { + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "%s is not a library (%s) ", filename, GPIO_DLERROR()); + return (GPIO_ERROR); } - gpio_debug_printf("%s is a library ", filename); - dlclose(lh); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, "%s is a library ", filename); + GPIO_DLCLOSE(lh); - return (GPIO_OK); + return (GPIO_OK); } int gpio_library_list_load(char *filename, int loaded[], gpio_device_info *list, int *count) { - void *lh; + void *lh; int type, x; - gpio_ptr_list lib_list; gpio_ptr_type lib_type; + gpio_ptr_list lib_list; int old_count = *count; - if ((lh = dlopen(filename, RTLD_LAZY))==NULL) - return (GPIO_ERROR); - + if ((lh = GPIO_DLOPEN(filename))==NULL) + return (GPIO_ERROR); - lib_type = dlsym(lh, "gpio_library_type"); - lib_list = dlsym(lh, "gpio_library_list"); + lib_type = (gpio_ptr_type)GPIO_DLSYM(lh, "gpio_library_type"); + lib_list = (gpio_ptr_list)GPIO_DLSYM(lh, "gpio_library_list"); if ((!list) || (!lib_type)) { - gpio_debug_printf("%s ", dlerror()); - dlclose(lh); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "could not find type/list symbols: %s ", GPIO_DLERROR()); + GPIO_DLCLOSE(lh); return (GPIO_ERROR); } type = lib_type(); if (loaded[type] == 1) { - gpio_debug_printf("%s (%i) already loaded ", filename, type); - dlclose(lh); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "%s (%i) already loaded ", filename, type); + GPIO_DLCLOSE(lh); return (GPIO_ERROR); } else { loaded[type] = 1; } if (lib_list(list, count)==GPIO_ERROR) - gpio_debug_printf("%s could not list devices ", filename); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "%s could not list devices ", filename); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "Loaded these devices from %s:", filename); /* copy in the library path */ - for (x=old_count; x<(*count); x++) + for (x=old_count; x<(*count); x++) { + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "\t%s path=\"%s\"", list[x].name, list[x].path); strcpy(list[x].library_filename, filename); + } - dlclose(lh); + GPIO_DLCLOSE(lh); return (GPIO_OK); } int gpio_library_list (gpio_device_info *list, int *count) { - DIR *d; - int loaded[256], x; - struct dirent *de; + GPIO_DIR d; + GPIO_DIRENT de; + int loaded[256]; + int x; char buf[1024]; *count = 0; @@ -77,26 +87,29 @@ for (x=0;x<256; x++) loaded[x]=0; - /* Look for available camera libraries */ - d = opendir(IOLIBS); - if (!d) { - gpio_debug_printf("couldn't open %s ", IOLIBS); - return GPIO_ERROR; - } - - do { - /* Read each entry */ - de = readdir(d); - if (de) { -#if defined(OS2) || defined(WINDOWS) - sprintf(buf, "%s\\%s", IOLIBS, de->d_name); + /* Look for available camera libraries */ + d = GPIO_OPENDIR(IOLIBS); + if (!d) { + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "couldn't open %s ", IOLIBS); + return GPIO_ERROR; + } + + do { + /* Read each entry */ + de = GPIO_READDIR(d); + if (de) { +#if defined(OS2) || defined(WIN32) + sprintf(buf, "%s\\%s", IOLIBS, GPIO_FILENAME(de)); #else - sprintf(buf, "%s/%s", IOLIBS, de->d_name); + sprintf(buf, "%s/%s", IOLIBS, GPIO_FILENAME(de)); #endif - if (gpio_library_is_valid(buf) == GPIO_OK) + if (gpio_library_is_valid(buf) == GPIO_OK) gpio_library_list_load(buf, loaded, list, count); - } - } while (de); + } + } while (de); + + GPIO_CLOSEDIR(d); return (GPIO_OK); } @@ -104,25 +117,26 @@ int gpio_library_load (gpio_device *device, gpio_device_type type) { int x=0; - gpio_ptr_operations ops_func; + gpio_ptr_operations ops_func; for (x=0; xlibrary_handle = - dlopen(device_list[x].library_filename, RTLD_LAZY); + device->library_handle = GPIO_DLOPEN(device_list[x].library_filename); if (!device->library_handle) { - gpio_debug_printf (" %s %s ", device_list[x].library_filename, - dlerror()); - return (GPIO_ERROR); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "bad handle: %s %s ", + device_list[x].library_filename, GPIO_DLERROR()); + return (GPIO_ERROR); } /* Load the operations */ - ops_func = dlsym(device->library_handle, "gpio_library_operations"); + ops_func = (gpio_ptr_operations)GPIO_DLSYM(device->library_handle, "gpio_library_operations"); if (!ops_func) { - gpio_debug_printf (" %s %s ", device_list[x].library_filename, - dlerror()); - dlclose(device->library_handle); + gpio_debug_printf(GPIO_DEBUG_LOW, glob_debug_level, + "can't load ops: %s %s ", + device_list[x].library_filename, GPIO_DLERROR()); + GPIO_DLCLOSE(device->library_handle); return (GPIO_ERROR); } device->ops = ops_func(); @@ -134,5 +148,7 @@ int gpio_library_close (gpio_device *device) { - dlclose(device->library_handle); + GPIO_DLCLOSE(device->library_handle); + + return (GPIO_OK); } diff -u --recursive --new-file --exclude=CVS libgpio.orig/libgpio/port.c libgpio/libgpio/port.c --- libgpio.orig/libgpio/port.c Thu Jan 1 01:00:00 1970 +++ libgpio/libgpio/port.c Fri Sep 15 12:28:53 2000 @@ -0,0 +1,172 @@ +#include +#include + +/* Windows Portability + ------------------------------------------------------------------ */ +#ifdef WIN32 + +void gpio_win_convert_path (char *path) { + + int x; + + if (strchr(path, '\\')) + /* already converted */ + return; + + if (path[0] != '.') { + path[0] = path[1]; + path[1] = ':'; + path[2] = '\\'; + } + + for (x=0; xhandle = INVALID_HANDLE_VALUE; + d->got_first = 0; + strcpy(d->dir, dirname); + d->drive_count = 0; + d->drive_index = 0; + + dr = GetLogicalDrives(); + + for (x=0; x<32; x++) { + if ((dr >> x) & 0x0001) { + sprintf(d->drive[d->drive_count], "%c", 'A' + x); + d->drive_count += 1; + } + } + + return (d); +} + +GPIO_DIRENT GPIO_READDIR (GPIO_DIR d) { + + char dirn[1024]; + + if (strcmp(d->dir, "/")==0) { + if (d->drive_index == d->drive_count) + return (NULL); + strcpy(d->search.cFileName, d->drive[d->drive_index]); + d->drive_index += 1; + return (&(d->search)); + } + + + /* Append the wildcard */ + + strcpy(dirn, d->dir); + gpio_win_convert_path(dirn); + + if (dirn[strlen(dirn)-1] != '\\') + strcat(dirn, "\\"); + strcat(dirn, "*"); + + + if (d->handle == INVALID_HANDLE_VALUE) { + d->handle = FindFirstFile(dirn, &(d->search)); + if (d->handle == INVALID_HANDLE_VALUE) + return NULL; + } else { + if (!FindNextFile(d->handle, &(d->search))) + return NULL; + } + + return (&(d->search)); +} + +char *GPIO_FILENAME (GPIO_DIRENT de) { + + return (de->cFileName); +} + +int GPIO_CLOSEDIR (GPIO_DIR d) { + FindClose(d->handle); + free(d); + return (1); +} + +int GPIO_IS_FILE (char *filename) { + + struct stat st; + + gpio_win_convert_path(filename); + + if (stat(filename, &st)!=0) + return 0; + return (st.st_mode & _S_IFREG); +} + +int GPIO_IS_DIR (char *dirname) { + + struct stat st; + + if (strlen(dirname) <= 3) + return 1; + + gpio_win_convert_path(dirname); + + if (stat(dirname, &st)!=0) + return 0; + return (st.st_mode & _S_IFDIR); +} + + +#else + +int GPIO_MKDIR (char *dirname) { + + if (mkdir(dirname, 0700)<0) + return (GPIO_ERROR); + return (GPIO_OK); +} + +GPIO_DIR GPIO_OPENDIR (char *dirname) { + return (opendir(dirname)); +} + +GPIO_DIRENT GPIO_READDIR (GPIO_DIR d) { + return (readdir(d)); +} + +char *GPIO_FILENAME (GPIO_DIRENT de) { + return (de->d_name); +} + +int GPIO_CLOSEDIR (GPIO_DIR dir) { + closedir(dir); + return (GPIO_OK); +} + +int GPIO_IS_FILE (char *filename) { + struct stat st; + + if (stat(filename, &st)!=0) + return 0; + return (!S_ISDIR(st.st_mode)); +} + +int GPIO_IS_DIR (char *dirname) { + struct stat st; + + if (stat(dirname, &st)!=0) + return 0; + return (S_ISDIR(st.st_mode)); +} +#endif diff -u --recursive --new-file --exclude=CVS libgpio.orig/network/.cvsignore libgpio/network/.cvsignore --- libgpio.orig/network/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/network/.cvsignore Fri Aug 4 23:45:05 2000 @@ -0,0 +1,5 @@ +*.lo +Makefile +Makefile.in +.deps +.libs diff -u --recursive --new-file --exclude=CVS libgpio.orig/parallel/.cvsignore libgpio/parallel/.cvsignore --- libgpio.orig/parallel/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/parallel/.cvsignore Fri Aug 4 23:45:05 2000 @@ -0,0 +1,5 @@ +*.lo +Makefile +Makefile.in +.deps +.libs diff -u --recursive --new-file --exclude=CVS libgpio.orig/parallel/parallel.df libgpio/parallel/parallel.df --- libgpio.orig/parallel/parallel.df Thu Jan 1 01:00:00 1970 +++ libgpio/parallel/parallel.df Fri Aug 11 11:42:40 2000 @@ -0,0 +1,2 @@ +LIBRARY GIPARALL +EXPORTS diff -u --recursive --new-file --exclude=CVS libgpio.orig/serial/.cvsignore libgpio/serial/.cvsignore --- libgpio.orig/serial/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/serial/.cvsignore Fri Aug 4 23:49:37 2000 @@ -0,0 +1,6 @@ +*.lo +Makefile +Makefile.in +.deps +.libs +*.la diff -u --recursive --new-file --exclude=CVS libgpio.orig/serial/Makefile.am libgpio/serial/Makefile.am --- libgpio.orig/serial/Makefile.am Sun Aug 13 14:48:00 2000 +++ libgpio/serial/Makefile.am Tue Aug 1 01:41:28 2000 @@ -8,5 +8,4 @@ iolibdir = $(prefix)/lib/gpio iolib_LTLIBRARIES = libgpio_serial.la libgpio_serial_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ -DHAVE_TERMIOS_H -libgpio_serial_la_SOURCES = unix.c - +libgpio_serial_la_SOURCES = unix.c gpio-serial.h diff -u --recursive --new-file --exclude=CVS libgpio.orig/serial/serial.df libgpio/serial/serial.df --- libgpio.orig/serial/serial.df Thu Jan 1 01:00:00 1970 +++ libgpio/serial/serial.df Fri Aug 11 11:42:41 2000 @@ -0,0 +1,2 @@ +LIBRARY GISERIAL +EXPORTS diff -u --recursive --new-file --exclude=CVS libgpio.orig/serial/unix.c libgpio/serial/unix.c --- libgpio.orig/serial/unix.c Fri Aug 4 16:37:48 2000 +++ libgpio/serial/unix.c Mon Sep 4 14:06:45 2000 @@ -67,10 +67,13 @@ int gpio_serial_read(gpio_device *dev, char *bytes, int size); int gpio_serial_write(gpio_device *dev, char *bytes, int size); +int gpio_serial_update (gpio_device *dev); + +/* Specific */ int gpio_serial_get_pin(gpio_device *dev, int pin); int gpio_serial_set_pin(gpio_device *dev, int pin, int level); +int gpio_serial_send_break (gpio_device *dev, int duration); -int gpio_serial_update (gpio_device *dev); /* private */ int gpio_serial_set_baudrate(gpio_device *dev); @@ -100,6 +103,7 @@ ops->update = gpio_serial_update; ops->get_pin = gpio_serial_get_pin; ops->set_pin = gpio_serial_set_pin; + ops->send_break = gpio_serial_send_break; return (ops); } @@ -128,13 +132,10 @@ for (x=GPIO_SERIAL_RANGE_LOW; x<=GPIO_SERIAL_RANGE_HIGH; x++) { sprintf(buf, prefix, x); #ifdef OS2 - rc = DosOpen(buf,&fh,&option,0,0,1,OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYREADWRITE,0); - DosClose(fh); - if(rc==0) - { + rc = DosOpen(buf,&fh,&option,0,0,1,OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYREADWRITE,0); + DosClose(fh); + if(rc==0) { #endif - - fd = open (buf, O_RDONLY | O_NDELAY); if (fd != -1) { close(fd); @@ -146,10 +147,8 @@ *count += 1; } #ifdef OS2 - } + } #endif - - } return (GPIO_OK); @@ -191,6 +190,7 @@ perror(dev->settings.serial.port); return GPIO_ERROR; } + /* if (ioctl (dev->device_fd, TIOCMBIC, &RTS) <0) { perror("ioctl(TIOCMBIC)"); return GPIO_ERROR; @@ -509,4 +509,17 @@ return ret; #undef BAUDCASE +} + +int gpio_serial_send_break (gpio_device *dev, int duration) { + + /* Duration is in seconds */ + +#if HAVE_TERMIOS_H + tcsendbreak(dev->device_fd, duration / 3); + tcdrain(dev->device_fd); +#else + /* ioctl */ +#endif + } diff -u --recursive --new-file --exclude=CVS libgpio.orig/usb/.cvsignore libgpio/usb/.cvsignore --- libgpio.orig/usb/.cvsignore Thu Jan 1 01:00:00 1970 +++ libgpio/usb/.cvsignore Fri Aug 4 23:49:37 2000 @@ -0,0 +1,6 @@ +*.lo +Makefile +Makefile.in +.deps +.libs +*.la diff -u --recursive --new-file --exclude=CVS libgpio.orig/usb/Makefile.am libgpio/usb/Makefile.am --- libgpio.orig/usb/Makefile.am Sun Aug 13 14:48:01 2000 +++ libgpio/usb/Makefile.am Tue Aug 1 01:41:29 2000 @@ -8,5 +8,4 @@ iolibdir = $(prefix)/lib/gpio iolib_LTLIBRARIES = libgpio_usb.la libgpio_usb_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ -libgpio_usb_la_SOURCES = libusb.c - +libgpio_usb_la_SOURCES = libusb.c gpio-usb.h diff -u --recursive --new-file --exclude=CVS libgpio.orig/usb/libusb.c libgpio/usb/libusb.c --- libgpio.orig/usb/libusb.c Fri Aug 4 16:37:49 2000 +++ libgpio/usb/libusb.c Wed Aug 9 20:28:17 2000 @@ -31,7 +31,7 @@ #include #include "gpio.h" -#undef GPIO_USB_DEBUG +#define GPIO_USB_DEBUG int gpio_usb_list(gpio_device_info *list, int *count); int gpio_usb_init(gpio_device *dev); @@ -81,9 +81,6 @@ int gpio_library_list(gpio_device_info *list, int *count) { - usb_init(); - usb_find_busses(); - usb_find_devices(); list[*count].type = GPIO_DEVICE_USB; strcpy(list[*count].name, "Universal Serial Bus"); @@ -96,10 +93,15 @@ int gpio_usb_init(gpio_device *dev) { + usb_init(); + usb_find_busses(); + usb_find_devices(); + return (GPIO_OK); } int gpio_usb_exit(gpio_device *dev) { + return (GPIO_OK); } int gpio_usb_open(gpio_device *dev) @@ -230,9 +232,10 @@ { struct usb_bus *bus; struct usb_device *dev; - +printf("here\n"); for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { +printf("vendor=%x product=%x\n", dev->descriptor.idVendor, dev->descriptor.idProduct); if ((dev->descriptor.idVendor == idvendor) && (dev->descriptor.idProduct == idproduct)) { d->usb_device = dev;