Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux? |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
12-19-2006, 04:53 PM
|
#1
|
LQ Newbie
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14
Rep:
|
driver help with libusb
I can't believe that a usb controlled rocket launcher hasn't fallen into the hands of a programmer before. So I'm determined to make this work. I have a usb data sniffer and got a bunch of data for each of the rocket launcher's movements, but don't know how to translate that into libusb calls.
I see the usb_control_msg function in libusb and I think I can work that out, but I don't know what the "Class-Specific Request" stuff is... and it looks important. Can someone help me interpret these?
Here is the data I gathered for moving the launcher arm up. Under the "Class-specific request" section where the 8 bytes of data have a 1 for the first byte signify the up movement. down is 2, right is 4 and left is 8.
138321: Class-Specific Request (DOWN), 17.12.2006 22:15:36.6081536 +0.0
Destination: Inrterface, Index 0
Reserved Bits: 34
Request: 0x9
Value: 0x200
Send 0x8 bytes to the device
00 00 00 00 00 00 00 00 ........
138322: Control Transfer (UP), 17.12.2006 22:15:36.6081536 +0.0
Pipe Handle: 0xff8e65c8
00 00 00 00 00 00 00 00 ........
Setup Packet
21 09 00 02 00 00 08 00 !.......
Recipient: Inrterface
Request Type: Class
Direction: Host->Device
Request: 0x9 (Unknown)
Value: 0x200
Index: 0x0
Length: 0x8
138323: Class-Specific Request (DOWN), 17.12.2006 22:15:36.6081536 +0.0
Destination: Inrterface, Index 0
Reserved Bits: 34
Request: 0x9
Value: 0x200
Send 0x8 bytes to the device
01 00 00 00 00 00 00 00 ........
138324: Control Transfer (UP), 17.12.2006 22:15:36.6081536 +0.0
Pipe Handle: 0xff8e65c8
01 00 00 00 00 00 00 00 ........
Setup Packet
21 09 00 02 00 00 08 00 !.......
Recipient: Inrterface
Request Type: Class
Direction: Host->Device
Request: 0x9 (Unknown)
Value: 0x200
Index: 0x0
Length: 0x8
138329: Class-Specific Request (DOWN), 17.12.2006 22:15:36.6482112 +0.0100144
Destination: Inrterface, Index 0
Reserved Bits: 34
Request: 0x9
Value: 0x200
Send 0x8 bytes to the device
00 00 00 00 00 00 00 00 ........
138330: Control Transfer (UP), 17.12.2006 22:15:36.6482112 +0.0
Pipe Handle: 0xff8e65c8
00 00 00 00 00 00 00 00 ........
Setup Packet
21 09 00 02 00 00 08 00 !.......
Recipient: Inrterface
Request Type: Class
Direction: Host->Device
Request: 0x9 (Unknown)
Value: 0x200
Index: 0x0
Length: 0x8
Thanks so much,
Jim
|
|
|
12-21-2006, 06:04 AM
|
#2
|
Member
Registered: Nov 2003
Location: North of the Border
Distribution: Gentoo & Debian
Posts: 155
Rep:
|
Have you considered this for getting more help on this subject
|
|
|
01-03-2007, 07:37 PM
|
#3
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
allowing links
|
|
|
01-03-2007, 07:40 PM
|
#4
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
okay...now that i can use links in my post
http://www.beyondlogic.org/usbnutshell/usb1.htm
the above link has an overview of the USB standard which may be of use to you. I have been working on the same project for a few hours and am finding that my only block at the moment is that the documentation for libusb is so terrible that it seems as though randomly hitting buttons until something works would be almost as effective.
|
|
|
01-03-2007, 11:08 PM
|
#5
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
okay...i can control the thing now. let me know if you want the code.
|
|
|
01-04-2007, 07:40 AM
|
#6
|
LQ Newbie
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14
Original Poster
Rep:
|
I'm sure that would help. What device are you trying to make work?
I thought about scraping the libusb program and going for a device driver and noticed that the kernel functions were pretty much the same. I was able to find several documents on creating usb device drivers. This also lets me keep track of the device so I don't have to reset it before every use to put it in a "known" state and position... We are talking about nerf-like rockets... I need precision.
If I had the libusb program, I'm sure I could convert it to a driver.
Thanks for your help. Let me know how I can peek at the code.
Jim
|
|
|
01-04-2007, 12:01 PM
|
#7
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
I'll post the source code and an explanation this afternoon. Look for it at
http://www.amctrl.com/rocketlauncher.html
|
|
|
01-04-2007, 12:47 PM
|
#8
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
and by afternoon i mean before lunch. its up now
|
|
|
01-04-2007, 10:04 PM
|
#9
|
LQ Newbie
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14
Original Poster
Rep:
|
Wouldn't you know I didn't bring my rocket launcher home... I have to wait until tomorrow to try it out. I'll be shooting my co-workers yet!
I think my problem might have been a bad vendor ID. I read it 3 times from that stupid sniffer, but it might have been pointed at a device between us. I also had the index value wrong for the first and third packet. Otherwise I think the rest looks pretty much the same. Well, I won't be getting my work done tomorrow.
Thanks for your help.
Jim
|
|
|
01-05-2007, 12:12 PM
|
#10
|
LQ Newbie
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14
Original Poster
Rep:
|
ok, it doesn't work for me. It fails when trying to claim the interface. Do you have any ideas? Do I need to release the device from a driver? I tried the libusb call to usb_detach_kernel_driver_np but it fails as well.
I also noticed that my vendor id was a hex 1941 which is the same as your decimal 6465... so the only difference was the index value. That and I can't claim the interface.
|
|
|
01-05-2007, 01:01 PM
|
#11
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
Do you have the device on a USB hub?
I have read numerous reports that the device does not like to work unless it is physically plugged into the ports on the back of the machine. Even ports on the front tend to be problematic. There doesnt seem to be a solution to that problem.
If not, then I have no idea. My understanding of USB is poor at best and the first time I tried to claim the interface I had no issues so I moved onto other things. I'll look into it bit more.
On a final note, I have always been running the program as root. This shouldn't affect anything, though, as the whole point of libusb is to allow non-root users tha ability to use usb devices.
-edit-> what error do you get when claiming the interface?
|
|
|
01-05-2007, 02:16 PM
|
#12
|
LQ Newbie
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14
Original Poster
Rep:
|
ok, I have success... sort of. It does work as root when plugged into the machine itself. As a regular user I get a -1 returned from the call to claim the interface. I'm still trying to figure out where the "-EBUSY" and "-ENOMEM" that libusb's api talk about are defined.
I guess if I'm just going to turn around and do a kernel driver for this, it might just be a moot issue. This is cool though.
Jim
|
|
|
01-05-2007, 03:05 PM
|
#13
|
LQ Newbie
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10
Rep:
|
well...the root hub thing seems to be a manufacturing flaw, so there isnt really anything to about that.
My research (e.g. running strerror() on +1) indicaties that a return of -1 means that there is a permissions error. I don't know which devices are USB, but I would look there and make sure that non-root users have usb read and write permissions.
-ADDENDUM-
if you have usbfs enabled in your kernel, you can set permissions in /proc/bus/usb/
Last edited by shatteredllama; 01-05-2007 at 03:20 PM.
|
|
|
01-06-2007, 12:50 PM
|
#14
|
LQ Newbie
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14
Original Poster
Rep:
|
I noticed (at least on Fedora Core 6) that when I plug in the rocket launcher the kernel assigns a driver to it. I have to release the kernel driver with the usb_detach_kernel_driver_np function.
Regardless for whatever reason it assigns the user/group for usb devices to root/root with a mode of 644 and have not had the chance to research how to make it respect my authority. I assume this is the reason root needs to be the one to claim the interface. I hate it when my computer tries to think for me. This is why I don't like Windows.
I got my program working, mostly. I was just going for movement first and will work on firing (charging seperate from firing) and a reset function to put it into a known position. Then I'll play more with a kernel driver.
I noticed that the control messages with the index of 1 and the all-0 message is not needed and actually errors, so I changed mine to send nothing to the device until you tell it to and then sends all 0 message, the command, then all 0 message all with an index of 0.
Very cool, thanks again for your help.
Jim
|
|
|
02-02-2007, 10:31 AM
|
#15
|
LQ Newbie
Registered: Feb 2007
Posts: 1
Rep:
|
can not claim the usb device
hi there!
i'm stucked too with the claiming of the device - i receive -16 as return code - any ideas?
it's the same with user or root permissions.
many thanks!
-> update: was able to implement the detach-thingy and was finally able to claim the device as root. but now, the movements & everything is not working...
Last edited by maniaq; 02-02-2007 at 10:46 AM.
|
|
|
All times are GMT -5. The time now is 08:59 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|