LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
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

Reply
 
Search this Thread
Old 12-19-2006, 03:53 PM   #1
halfwit
LQ Newbie
 
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14

Rep: Reputation: 0
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
 
Old 12-21-2006, 05:04 AM   #2
diilbert
Member
 
Registered: Nov 2003
Location: North of the Border
Distribution: Gentoo & Debian
Posts: 155

Rep: Reputation: 30
Have you considered this for getting more help on this subject
 
Old 01-03-2007, 06:37 PM   #3
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
allowing links
 
Old 01-03-2007, 06:40 PM   #4
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
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.
 
Old 01-03-2007, 10:08 PM   #5
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
okay...i can control the thing now. let me know if you want the code.
 
Old 01-04-2007, 06:40 AM   #6
halfwit
LQ Newbie
 
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 01-04-2007, 11:01 AM   #7
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
I'll post the source code and an explanation this afternoon. Look for it at

http://www.amctrl.com/rocketlauncher.html
 
Old 01-04-2007, 11:47 AM   #8
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
and by afternoon i mean before lunch. its up now
 
Old 01-04-2007, 09:04 PM   #9
halfwit
LQ Newbie
 
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 01-05-2007, 11:12 AM   #10
halfwit
LQ Newbie
 
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14

Original Poster
Rep: Reputation: 0
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.
 
Old 01-05-2007, 12:01 PM   #11
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
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?
 
Old 01-05-2007, 01:16 PM   #12
halfwit
LQ Newbie
 
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 01-05-2007, 02:05 PM   #13
shatteredllama
LQ Newbie
 
Registered: Jan 2007
Location: Its hard to tell
Distribution: Gentoo & Slackware
Posts: 10

Rep: Reputation: 0
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 02:20 PM.
 
Old 01-06-2007, 11:50 AM   #14
halfwit
LQ Newbie
 
Registered: Mar 2006
Location: Texas
Distribution: Fedora Core x
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 02-02-2007, 09:31 AM   #15
maniaq
LQ Newbie
 
Registered: Feb 2007
Posts: 1

Rep: Reputation: 0
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 09:46 AM.
 
  


Reply

Tags
driver, libusb, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
libusb compile error gabyx Programming 10 03-24-2010 04:38 AM
Help getting libusb 0.1.12 installed... 003 Suse/Novell 7 07-15-2006 02:45 PM
libusb compiler error, Help!!! Librason Programming 1 03-10-2006 09:46 PM
help me --- interrupt_read() in libusb shiva_teknic Programming 0 09-27-2005 08:17 AM
libUSB install Dutch3 Linux - Newbie 1 04-30-2002 07:15 AM


All times are GMT -5. The time now is 05:28 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration