Universelles USB Commandline Tool HidCom für FritzBox

rundekugel

Neuer User
Mitglied seit
21 Dez 2007
Beiträge
16
Punkte für Reaktionen
0
Punkte
1
Hi,
kann mir jemand das HidCom für die FritzBox compilieren? Ist sowas wie NetCat für USB. Damit kann man mit HID Geräten einfach über commandline kommunizieren. Damit spart man sich viele spezifischen Treiber und kann viele Geräte an der Fritzbox zum laufen bringen.(für die ganzen Hardwarebaster) z.B. das Arcaze-USB ich hab' so n Ding, viele I/O-Pins + 6 ADC. An der Fritzbox wäre das mein Trauminterface.

HidCom habe ich nach langer sucher hier gefunden nachdem ich schon angefangen hatte es selbst zu programmieren.
Source zusätzlich hier:
Anhang anzeigen HidCom.tar.gz

Wäre nett, wenn sich einer meiner erbarmt das zu compilieren. Ich bin leider mit dem Versuch des Crosscompilens mehrfach gescheitert.

Suche auch ständig nach einfachen, preiswerten Lösungen zur Kommunikation der FB mit der Aussenwelt. Ein Prolific2303 mit µC arbeitet auch ganz nett an der FB. Sowie das AVR-NetIo von Pollin.
 
kann mir jemand das HidCom für die FritzBox compilieren?
Mit einem Linux als Build-System, dem trunk aus Freetz ( www.freetz.org ) und dem untenstehenden Patch, kannst Du das _statisch_ gelinkte binary kompilieren und im binär-Modus auf deine Box übertragen. Nach dem Patchen ist evtl. eine Formatierung (Linux/Unix-Editor!) erforderlich.
Code:
diff -Naur '--exclude=.*' make/hidcom.orig/Config.in make/hidcom/Config.in
--- make/hidcom.orig/Config.in	1970-01-01 01:00:00.000000000 +0100
+++ make/hidcom/Config.in	2012-07-21 21:57:28.000000000 +0200
@@ -0,0 +1,6 @@
+config FREETZ_PACKAGE_HIDCOM
+	bool "hidcom 0.1 (binary only)"
+	default n
+	help
+		WWW: http://openprog.altervista.org/USB_firm_eng.html
+		IPPF: http://www.ip-phone-forum.de/showthread.php?t=250494
diff -Naur '--exclude=.*' make/hidcom.orig/hidcom.mk make/hidcom/hidcom.mk
--- make/hidcom.orig/hidcom.mk	1970-01-01 01:00:00.000000000 +0100
+++ make/hidcom/hidcom.mk	2012-07-21 21:58:30.000000000 +0200
@@ -0,0 +1,25 @@
+$(call PKG_INIT_BIN, 0.1)
+$(PKG)_BINARY:=$($(PKG)_DIR)/$(pkg)
+$(PKG)_TARGET_BINARY:=$($(PKG)_DEST_DIR)/usr/bin/$(pkg)
+
+$(PKG_LOCALSOURCE_PACKAGE)
+$(PKG_CONFIGURED_NOP)
+
+$($(PKG)_BINARY): $($(PKG)_DIR)/.configured
+	$(SUBMAKE) -C $(HIDCOM_DIR) \
+		CC="$(TARGET_CC)" \
+		CFLAGS="$(TARGET_CFLAGS)"
+
+$($(PKG)_TARGET_BINARY): $($(PKG)_BINARY)
+	$(INSTALL_BINARY_STRIP)
+
+$(pkg)-precompiled: $($(PKG)_TARGET_BINARY)
+
+$(pkg)-clean:
+	-$(SUBMAKE) -C $(HIDCOM_DIR) clean
+	 $(RM) $(HIDCOM_DIR)/.configured
+
+$(pkg)-uninstall:
+	$(RM) $(HIDCOM_TARGET_BINARY)
+
+$(PKG_FINISH)
diff -Naur '--exclude=.*' make/hidcom.orig/src/HidCom.c make/hidcom/src/HidCom.c
--- make/hidcom.orig/src/HidCom.c	1970-01-01 01:00:00.000000000 +0100
+++ make/hidcom/src/HidCom.c	2010-01-23 15:23:16.000000000 +0100
@@ -0,0 +1,216 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <asm/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/hiddev.h>
+#include <linux/input.h>
+#include <time.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <string.h>
+
+
+int main (int argc, char **argv) {
+	int n=64,d=0,info=0,increment=0,p=0,vid=0,pid=0,q=0,f=0,ctrl=0,r=1,c,i,j;
+	char path[256],buf[256];
+	path[0]=0;
+	for(i=0;i<256;i++) buf[i]=0;
+	opterr = 0;
+	int option_index = 0;
+	struct option long_options[] =
+	{
+		{"control", no_argument,      &ctrl,1},
+		{"c",       no_argument,      &ctrl,1},
+		{"delay",   required_argument, 0, 'd'},
+		{"d",       required_argument, 0, 'd'},
+		{"feature", no_argument,         &f,1},
+		{"f",       no_argument,         &f,1},
+		{"help",    no_argument,       0, 'h'},
+		{"i",       no_argument,      &info,1},
+		{"info",    no_argument,      &info,1},
+		{"increment",no_argument,&increment,1},
+		{"I",       no_argument, &increment,1},
+		{"path",    required_argument, 0, 'P'},
+		{"pid",     required_argument, 0, 'p'},
+		{"quiet",   no_argument,        &q, 1},
+		{"q",       no_argument,        &q, 1},
+		{"repeat",  required_argument, 0, 'r'},
+		{"size",    required_argument, 0, 's'},
+		{"vid",     required_argument, 0, 'v'},
+		{0, 0, 0, 0}
+	};
+	while ((c = getopt_long (argc, argv, "cd:fhiIp:qv:r:s:",long_options,&option_index)) != -1)
+     switch (c)
+		{
+		case 'h':
+		printf("hid_test [options] [data]\
+		\noptions:\
+		\n-h, --help       help\
+		\n-c, --control    use control transfer [no]\
+		\n-d, --delay      read delay (ms) [0]\
+		\n-f, --feature    use feature report [no]\
+		\n-i, --info       device info [no]\
+		\n-I, --increment  increment byte 6 every transfer [no]\
+		\n--path           device path [/dev/usb/hiddev0]\
+		\n-p, --pid        Product ID [0x1FF]\
+		\n-q, --quiet      print response only [no]\
+		\n-r, --repeat     repeat N times [1]\
+		\n-s, --size       report size [64]\
+		\n-v, --vid        Vendor ID [0x4D8]\
+		\n example:  HidCom -i 1 2 3 4\n");
+		exit(1);
+		break;
+		case 'c':	//control endpoint
+			 ctrl=1;
+             break;
+		case 'd':	//delay
+			d = atoi(optarg);
+			break;
+		case 'f':	//feature report
+			f=1;
+			break;
+		case 'i':	//info
+			info=1;
+			break;
+		case 'I':	//increment
+			increment=1;
+			break;
+		case 'p':	//pid
+			sscanf(optarg, "%x", &pid);
+			break;
+		case 'P':	//path
+			strncpy(path,optarg,256);
+			break;
+		case 'q':	//quiet
+			q=1;
+			break;
+		case 'r':	//repeat
+			r = atoi(optarg);
+			break;
+		case 's':	//report size
+			n = atoi(optarg);	//No always add report index
+			break;
+		case 'v':	//vid
+			sscanf(optarg, "%x", &vid);
+			break;
+		case '?':
+			fprintf (stderr, "Unknown option character 0x%02x (%c)\n",optopt,optopt);
+			return 1;
+		default:
+		 //abort ();
+		break;
+		}
+
+	for (j=0,i = optind; i < argc&&i<128; i++,j++) sscanf(argv[i], "%x", &buf[j]);
+	int fd = -1;
+	struct hiddev_devinfo device_info;		
+	if(pid&&vid){
+		for(i=0;i<20;i++){
+			sprintf(path,"/dev/usb/hiddev%d",i);
+			if ((fd = open(path, O_RDONLY )) >= 0){
+				ioctl(fd, HIDIOCGDEVINFO, &device_info);
+				if(device_info.vendor==vid&&device_info.product==pid) i=29;
+			}
+		}
+		if(i==20){
+			printf("Can't find device");
+			exit(1);
+		}
+	}
+	else{ 
+		if(!path[0]) sprintf(path,"/dev/usb/hiddev0");
+		if ((fd = open(path, O_RDONLY )) < 0) {	//O_RDWR
+			perror("hiddev open");
+			exit(1);
+		}		
+	}	
+	if(info){
+		struct hiddev_string_descriptor Hstring1,Hstring2;
+		Hstring1.index=1;
+		Hstring1.value[0]=0;
+		Hstring2.index=2;
+		Hstring2.value[0]=0;
+		ioctl(fd, HIDIOCGDEVINFO, &device_info);
+		printf("VID: 0x%04hX  PID: 0x%04hX  version: 0x%04hX\n",
+			device_info.vendor, device_info.product, device_info.version);
+		printf("Applications: %i\n", device_info.num_applications);
+		printf("Bus: %d Devnum: %d Ifnum: %d\n",
+			device_info.busnum, device_info.devnum, device_info.ifnum);
+		ioctl(fd, HIDIOCGSTRING, &Hstring1);
+		ioctl(fd, HIDIOCGSTRING, &Hstring2);
+		printf("Path: %s\nManufacturer: %s\nProduct: %s\n",path,Hstring1.value,Hstring2.value);
+	}
+	struct hiddev_report_info rep_info_i,rep_info_u;	
+	struct hiddev_usage_ref_multi ref_multi_i,ref_multi_u;
+	rep_info_u.report_type=HID_REPORT_TYPE_OUTPUT;
+	rep_info_i.report_type=HID_REPORT_TYPE_INPUT;
+	rep_info_u.report_id=rep_info_i.report_id=HID_REPORT_ID_FIRST;
+	rep_info_u.num_fields=rep_info_i.num_fields=1;
+	ref_multi_u.uref.report_type=HID_REPORT_TYPE_OUTPUT;
+	ref_multi_i.uref.report_type=HID_REPORT_TYPE_INPUT;
+	ref_multi_u.uref.report_id=ref_multi_i.uref.report_id=HID_REPORT_ID_FIRST;
+	ref_multi_u.uref.field_index=ref_multi_i.uref.field_index=0;
+	ref_multi_u.uref.usage_index=ref_multi_i.uref.usage_index=0;
+	ref_multi_u.num_values=ref_multi_i.num_values=n;
+	for(i=0;i<n;i++) ref_multi_u.values[i]=buf[i];
+	int res;
+	if(f){				//use feature report
+			rep_info_u.report_type=rep_info_i.report_type=HID_REPORT_TYPE_FEATURE;
+			ref_multi_u.uref.report_type=ref_multi_i.uref.report_type=HID_REPORT_TYPE_FEATURE;
+	}
+	for(j=0;j<r;j++){
+		if(!q){ 
+			printf("-> ");
+			for(i=0;i<n;i++) printf("%02X ",(unsigned char)ref_multi_u.values[i]);
+			printf("\n");
+		}
+		if(f){				//use feature report
+			ioctl(fd,HIDIOCSUSAGES, &ref_multi_u);
+			ioctl(fd,HIDIOCSREPORT, &rep_info_u);
+			usleep(d*1000);
+			ioctl(fd,HIDIOCGREPORT, &rep_info_i);
+			ioctl(fd,HIDIOCGUSAGES, &ref_multi_i);
+		}
+		else if(ctrl){		//use control endpoint, at least for reading
+			ioctl(fd,HIDIOCSUSAGES, &ref_multi_u);
+			ioctl(fd,HIDIOCSREPORT, &rep_info_u);
+			usleep(d*1000);
+			ioctl(fd,HIDIOCGREPORT, &rep_info_i);
+			ioctl(fd,HIDIOCGUSAGES, &ref_multi_i);
+		}
+		else{				//use interrupt endpoint
+			ioctl(fd,HIDIOCSUSAGES, &ref_multi_u); 
+			ioctl(fd,HIDIOCSREPORT, &rep_info_u);
+			usleep(d*1000);
+			ioctl(fd,HIDIOCGUSAGES, &ref_multi_i); 
+			ioctl(fd,HIDIOCGREPORT, &rep_info_i);
+		}
+		if(!q) printf("<- ");
+		for(i=0;i<n;i++) printf("%02X ",ref_multi_i.values[i]);
+		printf("\n");
+		if(increment) ref_multi_u.values[5]++; 
+	}
+	close(fd);
+	exit(0);
+}
diff -Naur '--exclude=.*' make/hidcom.orig/src/Makefile make/hidcom/src/Makefile
--- make/hidcom.orig/src/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ make/hidcom/src/Makefile	2012-07-21 21:52:08.000000000 +0200
@@ -0,0 +1,7 @@
+CC=
+CFLAGS=
+
+all: hidcom
+
+hidcom: HidCom.c
+	${CC} ${CFLAGS} -o hidcom HidCom.c -static
diff -Naur '--exclude=.*' make/hidcom.orig/src/readme make/hidcom/src/readme
--- make/hidcom.orig/src/readme	1970-01-01 01:00:00.000000000 +0100
+++ make/hidcom/src/readme	2012-07-21 22:05:13.000000000 +0200
@@ -0,0 +1,9 @@
+HidCom, an example of communication between a PC and an HID device.
+For more information see http://openprog.altervista.org/
+These sources are given free of charge under the GNU General Public License version 2 
+
+How to compile:
+gcc HidCOm.cpp -o HidCom
+
+Example:
+HidCOm --pid 4D8 --vid 1FF --info 0 1 2 3 12 15 1a 1c 1f 4
Code:
... /freetz-devel> file packages/target-mipsel_uClibc-0.9.32.1/hidcom-0.1/root/usr/bin/hidcom
packages/target-mipsel_uClibc-0.9.32.1/hidcom-0.1/root/usr/bin/hidcom: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, stripped
Code:
root@fritz:/var/media/ftp/uStor02/archiv# ./hidcom -h
hid_test [options] [data]               
options:                
-h, --help       help           
-c, --control    use control transfer [no]              
-d, --delay      read delay (ms) [0]            
-f, --feature    use feature report [no]                
-i, --info       device info [no]               
-I, --increment  increment byte 6 every transfer [no]           
--path           device path [/dev/usb/hiddev0]         
-p, --pid        Product ID [0x1FF]             
-q, --quiet      print response only [no]               
-r, --repeat     repeat N times [1]             
-s, --size       report size [64]               
-v, --vid        Vendor ID [0x4D8]              
 example:  HidCom -i 1 2 3 4
 
@sf3978:
Besser spät als nie:

Danke!

Hab immer noch nicht die Zeit gefunden, das zum Laufen zu bringen. Aber trotzdem danke für die ausführliche Anleitung!
 
Holen Sie sich 3CX - völlig kostenlos!
Verbinden Sie Ihr Team und Ihre Kunden Telefonie Livechat Videokonferenzen

Gehostet oder selbst-verwaltet. Für bis zu 10 Nutzer dauerhaft kostenlos. Keine Kreditkartendetails erforderlich. Ohne Risiko testen.

3CX
Für diese E-Mail-Adresse besteht bereits ein 3CX-Konto. Sie werden zum Kundenportal weitergeleitet, wo Sie sich anmelden oder Ihr Passwort zurücksetzen können, falls Sie dieses vergessen haben.