Fix for linux & libusb version, added library to Linux makefile
authorpavel <pavel@aaa>
Sat, 28 Mar 2015 00:58:04 +0000 (03:58 +0300)
committerpavel <pavel@aaa>
Sat, 28 Mar 2015 00:58:04 +0000 (03:58 +0300)
commandline/hiddata.h
commandline/hiddata_libusb01.c
commandline/makemake/Makefile
lib/usb_relay_device.h
lib/usb_relay_lib.c

index ca8cfa58312cd4872557e6439ef98f756c2ea3c2..ed0144c5c8664349b5ad83874e4d985495e251f1 100644 (file)
@@ -40,7 +40,7 @@ Libraries to link are:
  */
 struct usbDevice;
 typedef struct usbDevice    usbDevice_t;
-typedef struct usbDevice    *USBDEVHANDLE;
+typedef usbDevice_t         *USBDEVHANDLE;
 
 
 /* ------------------------------------------------------------------------ */
@@ -95,7 +95,7 @@ int usbhidGetReport(USBDEVHANDLE usbh, int reportID, char *buffer, int *len);
  * Return description of error code
  * TODO? return error descr. of underlying libusb or hid layer too?
  */
-int usbhidStrerror_r( int err, char *buf, int len);
+int usbhidStrerror_r(int err, char *buf, int len);
 
 /* ------------------------------------------------------------------------ */
 
index 1cc8b733e1f2eb3cb0721d1842e7e719e56e71f3..b21aa80042eefcf313875ed1e2edc486ebdb2672 100644 (file)
@@ -14,9 +14,9 @@
 #include <usb.h>
 
 #if 0 //ifdef DEBUG
-#define DEBUG_PRINT(arg)    printf arg
+#define DEBUG_PRINT(fmt, ...)    do {} while(0)
 #else
-#define DEBUG_PRINT(arg)
+#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
 #endif
 
 
@@ -70,7 +70,7 @@ int usbhidEnumDevices(int vendor, int product,
                 handle = usb_open(dev); /* we need to open the device in order to query strings */
                 if ( !handle ) {
                     errorCode = USBHID_ERR_ACCESS;
-                    fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror());
+                    DEBUG_PRINT("Warning: cannot open USB device: %s\n", usb_strerror());
                     continue;
                 }
 
@@ -78,8 +78,8 @@ int usbhidEnumDevices(int vendor, int product,
 
 //  printf("Probing: [%s] nc=%u %p\n", dev->filename, dev->num_children, dev->children);
                 // Assume our devices are leaf, so we can use dev->children to store the handle
-                if ( dev->children ) {
-                    fprintf(stderr, "ERROR: assertion failed for usb dev %p\n", dev);
+                if ( dev->num_children != 0 ) {
+                    DEBUG_PRINT("ERROR: assertion failed for usb dev %p\n", dev);
                     usb_close(handle);
                     handle = NULL;
                     continue;
@@ -118,9 +118,9 @@ static int usbhidGetStringAscii(struct usb_dev_handle *dev, int index, char *buf
     if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */
         return rval;
     if (errno == EPERM)
-      fprintf(stderr, "usbhid: Access denied to USB device. Run as root or adjust device permissions.\n");
+      DEBUG_PRINT("usbhid: Access denied to USB device. Run as root or adjust device permissions.\n");
     else
-      fprintf(stderr, "usbhid: %s error %s\n", __FUNCTION__, usb_strerror());
+      DEBUG_PRINT("usbhid: %s error %s\n", __FUNCTION__, usb_strerror());
     return -1;
 }
 
@@ -128,7 +128,7 @@ int usbhidGetVendorString(USBDEVHANDLE usbh, char *buffer, int len)
 {
     int len2 = usbhidGetStringAscii(usbDevHandle(usbh), usbDevStruct(usbh)->descriptor.iManufacturer, buffer, len);
     if (len2 < 0) {
-        fprintf(stderr, "Warning: cannot query vendor for device\n");
+        DEBUG_PRINT("Warning: cannot query vendor for device\n");
         return USBHID_ERR_IO;
     }
     return 0;
@@ -138,7 +138,7 @@ int usbhidGetProductString(USBDEVHANDLE usbh, char *buffer, int len)
 {
     int len2 = usbhidGetStringAscii(usbDevHandle(usbh), usbDevStruct(usbh)->descriptor.iProduct, buffer, len);
     if (len2 < 0) {
-        fprintf(stderr, "Warning: cannot query product for device\n");
+        DEBUG_PRINT("Warning: cannot query product for device\n");
         return USBHID_ERR_IO;
     }
     return 0;
@@ -160,7 +160,7 @@ int usbhidSetReport(USBDEVHANDLE usbh, char *buffer, int len)
             0, buffer, len, A_REPORT_REQUEST_TIMEOUT);
     if (bytesSent != len) {
         if (bytesSent < 0)
-            fprintf(stderr, "Error sending message: %s\n", usb_strerror());
+            DEBUG_PRINT("Error sending message: %s\n", usb_strerror());
         return USBHID_ERR_IO;
     }
     return 0;
@@ -180,7 +180,7 @@ int bytesReceived, maxLen = *len;
             USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | reportNumber,
             0, buffer, maxLen, A_REPORT_REQUEST_TIMEOUT);
     if(bytesReceived < 0){
-        fprintf(stderr, "Error sending message: %s\n", usb_strerror());
+        DEBUG_PRINT("Error sending message: %s\n", usb_strerror());
         return USBHID_ERR_IO;
     }
     *len = bytesReceived;
index cc3b0f14eb758150380c1e477c120e1d17f3a273..71af1147d2c4623477d3709a6d3b8c039b39359a 100644 (file)
@@ -1,21 +1,22 @@
-# Makefile for HID USB relay utility, hidusbrelay-cmd
-# pa03 24-jan-2015
-#
+# Makefile for HID USB relay utility, hidusbrelay-cmd and library
+# for Linux
+# (Quick'n'dirty - no .h dependencies, etc.)
+# Assume make is run in this dir
+# pa04 24-jan-2015
+
 # prototype:
 # Author: Christian Starkjohann
 # Creation Date: 2008-04-11
-# Tabsize: 4
 # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
-# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
 
 SRCDIR=..
 VPATH = $(SRCDIR)
 
-CMD_UTILITY=hidusb-relay-cmd
+CMD_UTILITY := hidusb-relay-cmd
+SHRLIB      := usb_relay_device.so
 
-# For Linux
-# Using old simple version 0.1 of libusb
-HIDDATA=hiddata_libusb01
+# For Linux: Using old simple version 0.1 of libusb
+HIDDATA  := hiddata_libusb01
 USBFLAGS := $(shell libusb-config --cflags)
 USBLIBS  := $(shell libusb-config --libs)
 EXE_SUFFIX=
@@ -49,7 +50,19 @@ strip: $(PROGRAM)
        strip $(PROGRAM)
 
 clean:
-       rm -f $(OBJ) $(PROGRAM)
+       rm -f *.o $(PROGRAM) $(SHRLIB)
 
 %.c.o:
        $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o
+
+#
+# Shared library
+# The main lib source is in lib/ and hiddata src with the cmd utility - reorg!
+#
+SRCS_LIB = $(HIDDATA) usb_relay_lib
+CFLAGS += -I../../lib
+VPATH =../../lib:..
+
+$(SHRLIB):     $(addsuffix .o, $(SRCS_LIB))
+       $(CC) -shared -Wl,-shared $(addsuffix .o, $(SRCS_LIB)) $(LIBS) -o $(SHRLIB)
+
index 05f88d18f87a7da39a1d1c2f0a6ab88c0169d040..19a62df018f30b16dcb9cd10d2baeabf165cd9e5 100644 (file)
@@ -18,6 +18,9 @@
 #  define USBRL_CALL
 #  define USBRL_API USBRL_CALL
 #endif /* Windows & Not Microsoft's compiler */
+#else /* non-Windows */
+  /* do not include this always for compat with VC++ < 2010 */
+#include <stdint.h>
 #endif /* WIN32 */
 
 #ifndef USBRL_CALL
index 9b9c5683b40e5ad17193a0f089a5c1e2ed62a9d6..c7aadc2f2d34e13aa72e5cb605a9e23cbfc38331 100644 (file)
 #include <string.h>
 #include <stdlib.h>
 
-//#define dbgprintf(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
-//#define dbgprintf(fmt, ...) printf(fmt, __VA_ARGS__)
-#define dbgprintf(fmt, ...) __noop(fmt, __VA_ARGS__)
-//#define printerr(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
-//#define printerr(fmt, ...) printf(fmt, __VA_ARGS__)
-#define printerr(fmt, ...) __noop(fmt, __VA_ARGS__)
+//#define dbgprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
+//#define dbgprintf(fmt, ...) printf(fmt, ## __VA_ARGS__)
+#define dbgprintf(fmt, ...)  //__noop(fmt, __VA_ARGS__)
+//#define printerr(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
+//#define printerr(fmt, ...) printf(fmt, ## __VA_ARGS__)
+#define printerr(fmt, ...) // __noop(fmt, __VA_ARGS__)
 
 #ifdef __cplusplus
 extern "C" {