usbutils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Berksfile +5 -0
- data/Berksfile.lock +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/Vagrantfile +162 -0
- data/bin/usb-devices +172 -0
- data/bin/usbutils +5 -0
- data/lib/usbutils.rb +60 -0
- data/lib/usbutils/cli.rb +33 -0
- data/lib/usbutils/version.rb +3 -0
- data/usbutils.gemspec +26 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44280c8cb845604e93470fc9b0ee9c012d281c5c
|
4
|
+
data.tar.gz: f8c12da7e5fd1ebb1cf568fcdaa91201b5b3a7d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9a42ebc0646e43ea12e4ffca7987725e707f9f8969bf47f5bd1c474a264ba2a807267c8c074e4eea5f457b8e0851f6ac47307c56ea3115ed3219b2ee5f67a35
|
7
|
+
data.tar.gz: b5b6a9657b63de970880b70c2d0ed6df9c631ba2116f6ca55da743d099b9488e8fac741e8ac2634942917927de5011bf2c9697907f025181d21e419b3b6c2bb2
|
data/.gitignore
ADDED
data/Berksfile
ADDED
data/Berksfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
{
|
2
|
+
"sources": {
|
3
|
+
"android-sdk": {
|
4
|
+
"locked_version": "0.0.0"
|
5
|
+
},
|
6
|
+
"rbenv": {
|
7
|
+
"locked_version": "1.7.1"
|
8
|
+
},
|
9
|
+
"ruby_build": {
|
10
|
+
"locked_version": "0.8.0"
|
11
|
+
},
|
12
|
+
"java": {
|
13
|
+
"locked_version": "1.21.2"
|
14
|
+
},
|
15
|
+
"ark": {
|
16
|
+
"locked_version": "0.6.0"
|
17
|
+
},
|
18
|
+
"git": {
|
19
|
+
"locked_version": "3.1.0"
|
20
|
+
},
|
21
|
+
"dmg": {
|
22
|
+
"locked_version": "2.2.0"
|
23
|
+
},
|
24
|
+
"build-essential": {
|
25
|
+
"locked_version": "2.0.0"
|
26
|
+
},
|
27
|
+
"windows": {
|
28
|
+
"locked_version": "1.30.0"
|
29
|
+
},
|
30
|
+
"chef_handler": {
|
31
|
+
"locked_version": "1.1.5"
|
32
|
+
},
|
33
|
+
"runit": {
|
34
|
+
"locked_version": "1.5.10"
|
35
|
+
},
|
36
|
+
"yum": {
|
37
|
+
"locked_version": "3.1.4"
|
38
|
+
},
|
39
|
+
"yum-epel": {
|
40
|
+
"locked_version": "0.3.4"
|
41
|
+
},
|
42
|
+
"apt": {
|
43
|
+
"locked_version": "2.3.8"
|
44
|
+
},
|
45
|
+
"ohai": {
|
46
|
+
"locked_version": "2.0.0"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 k-yamada
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# USBUtils
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'usbutils'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install usbutils
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/usbutils/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Vagrantfile
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = "2"
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
# All Vagrant configuration is done here. The most common configuration
|
9
|
+
# options are documented and commented below. For a complete reference,
|
10
|
+
# please see the online documentation at vagrantup.com.
|
11
|
+
|
12
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
13
|
+
config.vm.box = "precise64"
|
14
|
+
|
15
|
+
# The url from where the 'config.vm.box' box will be fetched if it
|
16
|
+
# doesn't already exist on the user's system.
|
17
|
+
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
18
|
+
|
19
|
+
config.omnibus.chef_version = :latest
|
20
|
+
config.berkshelf.enabled = true
|
21
|
+
|
22
|
+
config.vm.provision :chef_solo do |chef|
|
23
|
+
chef.run_list = [
|
24
|
+
"ruby_build",
|
25
|
+
"rbenv::user",
|
26
|
+
"rbenv::vagrant",
|
27
|
+
"android-sdk::default"
|
28
|
+
]
|
29
|
+
|
30
|
+
chef.json = {
|
31
|
+
"android-sdk" => {
|
32
|
+
"components" => [
|
33
|
+
"platform-tools",
|
34
|
+
"android-18", "sysimg-18",
|
35
|
+
"android-17", "sysimg-17",
|
36
|
+
"android-16", "sysimg-16",
|
37
|
+
"extra-android-support",
|
38
|
+
"extra-google-google_play_services",
|
39
|
+
"extra-google-m2repository",
|
40
|
+
"extra-android-m2repository"
|
41
|
+
]
|
42
|
+
},
|
43
|
+
"rbenv" => {
|
44
|
+
"user_installs" => [
|
45
|
+
{
|
46
|
+
"user" => "vagrant",
|
47
|
+
"rubies" => [
|
48
|
+
"2.0.0-p247"
|
49
|
+
],
|
50
|
+
"global" => "2.0.0-p247",
|
51
|
+
"gems" => {
|
52
|
+
"2.0.0-p247" => [{"name" => "bundler"}]
|
53
|
+
}
|
54
|
+
}
|
55
|
+
]
|
56
|
+
},
|
57
|
+
"ruby_build" => {
|
58
|
+
"upgrade" => "true"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create a forwarded port mapping which allows access to a specific port
|
64
|
+
# within the machine from a port on the host machine. In the example below,
|
65
|
+
# accessing "localhost:8080" will access port 80 on the guest machine.
|
66
|
+
# config.vm.network :forwarded_port, guest: 80, host: 8080
|
67
|
+
|
68
|
+
# Create a private network, which allows host-only access to the machine
|
69
|
+
# using a specific IP.
|
70
|
+
# config.vm.network :private_network, ip: "192.168.33.10"
|
71
|
+
|
72
|
+
# Create a public network, which generally matched to bridged network.
|
73
|
+
# Bridged networks make the machine appear as another physical device on
|
74
|
+
# your network.
|
75
|
+
# config.vm.network :public_network
|
76
|
+
|
77
|
+
# If true, then any SSH connections made will enable agent forwarding.
|
78
|
+
# Default value: false
|
79
|
+
# config.ssh.forward_agent = true
|
80
|
+
|
81
|
+
# Share an additional folder to the guest VM. The first argument is
|
82
|
+
# the path on the host to the actual folder. The second argument is
|
83
|
+
# the path on the guest to mount the folder. And the optional third
|
84
|
+
# argument is a set of non-required options.
|
85
|
+
# config.vm.synced_folder "../data", "/vagrant_data"
|
86
|
+
|
87
|
+
# Provider-specific configuration so you can fine-tune various
|
88
|
+
# backing providers for Vagrant. These expose provider-specific options.
|
89
|
+
# Example for VirtualBox:
|
90
|
+
#
|
91
|
+
# config.vm.provider :virtualbox do |vb|
|
92
|
+
# # Don't boot with headless mode
|
93
|
+
# vb.gui = true
|
94
|
+
#
|
95
|
+
# # Use VBoxManage to customize the VM. For example to change memory:
|
96
|
+
# vb.customize ["modifyvm", :id, "--memory", "1024"]
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# View the documentation for the provider you're using for more
|
100
|
+
# information on available options.
|
101
|
+
|
102
|
+
# Enable provisioning with Puppet stand alone. Puppet manifests
|
103
|
+
# are contained in a directory path relative to this Vagrantfile.
|
104
|
+
# You will need to create the manifests directory and a manifest in
|
105
|
+
# the file precise64.pp in the manifests_path directory.
|
106
|
+
#
|
107
|
+
# An example Puppet manifest to provision the message of the day:
|
108
|
+
#
|
109
|
+
# # group { "puppet":
|
110
|
+
# # ensure => "present",
|
111
|
+
# # }
|
112
|
+
# #
|
113
|
+
# # File { owner => 0, group => 0, mode => 0644 }
|
114
|
+
# #
|
115
|
+
# # file { '/etc/motd':
|
116
|
+
# # content => "Welcome to your Vagrant-built virtual machine!
|
117
|
+
# # Managed by Puppet.\n"
|
118
|
+
# # }
|
119
|
+
#
|
120
|
+
# config.vm.provision :puppet do |puppet|
|
121
|
+
# puppet.manifests_path = "manifests"
|
122
|
+
# puppet.manifest_file = "site.pp"
|
123
|
+
# end
|
124
|
+
|
125
|
+
# Enable provisioning with chef solo, specifying a cookbooks path, roles
|
126
|
+
# path, and data_bags path (all relative to this Vagrantfile), and adding
|
127
|
+
# some recipes and/or roles.
|
128
|
+
#
|
129
|
+
# config.vm.provision :chef_solo do |chef|
|
130
|
+
# chef.cookbooks_path = "../my-recipes/cookbooks"
|
131
|
+
# chef.roles_path = "../my-recipes/roles"
|
132
|
+
# chef.data_bags_path = "../my-recipes/data_bags"
|
133
|
+
# chef.add_recipe "mysql"
|
134
|
+
# chef.add_role "web"
|
135
|
+
#
|
136
|
+
# # You may also specify custom JSON attributes:
|
137
|
+
# chef.json = { :mysql_password => "foo" }
|
138
|
+
# end
|
139
|
+
|
140
|
+
# Enable provisioning with chef server, specifying the chef server URL,
|
141
|
+
# and the path to the validation key (relative to this Vagrantfile).
|
142
|
+
#
|
143
|
+
# The Opscode Platform uses HTTPS. Substitute your organization for
|
144
|
+
# ORGNAME in the URL and validation key.
|
145
|
+
#
|
146
|
+
# If you have your own Chef Server, use the appropriate URL, which may be
|
147
|
+
# HTTP instead of HTTPS depending on your configuration. Also change the
|
148
|
+
# validation key to validation.pem.
|
149
|
+
#
|
150
|
+
# config.vm.provision :chef_client do |chef|
|
151
|
+
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
|
152
|
+
# chef.validation_key_path = "ORGNAME-validator.pem"
|
153
|
+
# end
|
154
|
+
#
|
155
|
+
# If you're using the Opscode platform, your validator client is
|
156
|
+
# ORGNAME-validator, replacing ORGNAME with your organization name.
|
157
|
+
#
|
158
|
+
# If you have your own Chef Server, the default validation client name is
|
159
|
+
# chef-validator, unless you changed the configuration.
|
160
|
+
#
|
161
|
+
# chef.validation_client_name = "ORGNAME-validator"
|
162
|
+
end
|
data/bin/usb-devices
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Copyright: 2009 Greg Kroah-Hartman <greg@kroah.com>
|
4
|
+
# 2009 Randy Dunlap <rdunlap@xenotime.net>
|
5
|
+
# 2009 Frans Pop <elendil@planet.nl>
|
6
|
+
#
|
7
|
+
# This software may be used and distributed according to the terms of
|
8
|
+
# the GNU General Public License (GPL), version 2, or at your option
|
9
|
+
# any later version.
|
10
|
+
|
11
|
+
print_string() {
|
12
|
+
file=$1
|
13
|
+
name=$2
|
14
|
+
if [ -f $file ]; then
|
15
|
+
echo "S: $name=`cat $file`"
|
16
|
+
fi
|
17
|
+
}
|
18
|
+
|
19
|
+
class_decode() {
|
20
|
+
local class=$1 # v4: in hex
|
21
|
+
|
22
|
+
case $class in
|
23
|
+
"00") echo ">ifc " ;;
|
24
|
+
"01") echo "audio" ;;
|
25
|
+
"02") echo "commc" ;;
|
26
|
+
"03") echo "HID " ;;
|
27
|
+
"05") echo "PID " ;;
|
28
|
+
"06") echo "still" ;;
|
29
|
+
"07") echo "print" ;;
|
30
|
+
"08") echo "stor." ;;
|
31
|
+
"09") echo "hub " ;;
|
32
|
+
"0a") echo "data " ;;
|
33
|
+
"0b") echo "scard" ;;
|
34
|
+
"0d") echo "c-sec" ;;
|
35
|
+
"0e") echo "video" ;;
|
36
|
+
"0f") echo "perhc" ;;
|
37
|
+
"dc") echo "diagd" ;;
|
38
|
+
"e0") echo "wlcon" ;;
|
39
|
+
"ef") echo "misc " ;;
|
40
|
+
"fe") echo "app. " ;;
|
41
|
+
"ff") echo "vend." ;;
|
42
|
+
"*") echo "unk. " ;;
|
43
|
+
esac
|
44
|
+
}
|
45
|
+
|
46
|
+
print_endpoint() {
|
47
|
+
local eppath=$1
|
48
|
+
|
49
|
+
addr=`cat $eppath/bEndpointAddress`
|
50
|
+
attr=`cat $eppath/bmAttributes`
|
51
|
+
dir=`cat $eppath/direction`
|
52
|
+
eptype=`cat $eppath/type`
|
53
|
+
maxps_hex="0x`cat $eppath/wMaxPacketSize`"
|
54
|
+
# Extract MaxPS size (bits 0-10) and multiplicity values (bits 11-12)
|
55
|
+
maxps=`printf "%4i*%s\n" $(($maxps_hex & 0x7ff)) \
|
56
|
+
$((1 + (($maxps_hex >> 11) & 0x3)))`
|
57
|
+
interval=`cat $eppath/interval`
|
58
|
+
|
59
|
+
printf "E: Ad=%s(%s) Atr=%s(%s) MxPS=%s Ivl=%s\n" \
|
60
|
+
$addr $dir $attr $eptype "$maxps" $interval
|
61
|
+
}
|
62
|
+
|
63
|
+
print_interface() {
|
64
|
+
local ifpath=$1
|
65
|
+
|
66
|
+
ifnum=`cat $ifpath/bInterfaceNumber`
|
67
|
+
altset=`cat $ifpath/bAlternateSetting`
|
68
|
+
numeps=`cat $ifpath/bNumEndpoints`
|
69
|
+
class=`cat $ifpath/bInterfaceClass`
|
70
|
+
subclass=`cat $ifpath/bInterfaceSubClass`
|
71
|
+
protocol=`cat $ifpath/bInterfaceProtocol`
|
72
|
+
if [ -L $ifpath/driver ]; then # v4: allow for no driver
|
73
|
+
driver=`readlink $ifpath/driver`
|
74
|
+
driver=`basename $driver`
|
75
|
+
else
|
76
|
+
driver="(none)"
|
77
|
+
fi
|
78
|
+
classname=`class_decode $class`
|
79
|
+
printf "I: If#=%2i Alt=%2i #EPs=%2i Cls=%s(%s) Sub=%s Prot=%s Driver=%s\n" \
|
80
|
+
$ifnum $altset $numeps $class "$classname" $subclass \
|
81
|
+
$protocol $driver
|
82
|
+
|
83
|
+
for endpoint in $ifpath/ep_??
|
84
|
+
do
|
85
|
+
if [ -L $endpoint ]; then # v4: verify endpoint exists
|
86
|
+
print_endpoint $endpoint
|
87
|
+
fi
|
88
|
+
done
|
89
|
+
}
|
90
|
+
|
91
|
+
print_device() {
|
92
|
+
local devpath=$1
|
93
|
+
local parent=$2
|
94
|
+
local level=$3
|
95
|
+
local count=$4
|
96
|
+
|
97
|
+
[ -d $devpath ] || return
|
98
|
+
cd $devpath
|
99
|
+
|
100
|
+
local busnum=`cat busnum`
|
101
|
+
local devnum=`cat devnum`
|
102
|
+
|
103
|
+
if [ $level -gt 0 ]; then
|
104
|
+
port=$((${devpath##*[-.]} - 1))
|
105
|
+
else
|
106
|
+
port=0
|
107
|
+
fi
|
108
|
+
speed=`cat speed`
|
109
|
+
maxchild=`cat maxchild`
|
110
|
+
printf "\nT: Bus=%02i Lev=%02i Prnt=%02i Port=%02i Cnt=%02i Dev#=%3i Spd=%-3s MxCh=%2i\n" \
|
111
|
+
$busnum $level $parent $port $count $devnum $speed $maxchild
|
112
|
+
|
113
|
+
ver=`cat version`
|
114
|
+
devclass=`cat bDeviceClass`
|
115
|
+
devsubclass=`cat bDeviceSubClass`
|
116
|
+
devprotocol=`cat bDeviceProtocol`
|
117
|
+
maxps0=`cat bMaxPacketSize0`
|
118
|
+
numconfigs=`cat bNumConfigurations`
|
119
|
+
classname=`class_decode $devclass`
|
120
|
+
printf "D: Ver=%5s Cls=%s(%s) Sub=%s Prot=%s MxPS=%2i #Cfgs=%3i\n" \
|
121
|
+
$ver $devclass "$classname" $devsubclass $devprotocol \
|
122
|
+
$maxps0 $numconfigs
|
123
|
+
|
124
|
+
vendid=`cat idVendor`
|
125
|
+
prodid=`cat idProduct`
|
126
|
+
revmajor=`cat bcdDevice | cut -c 1-2`
|
127
|
+
revminor=`cat bcdDevice | cut -c 3-4`
|
128
|
+
printf "P: Vendor=%s ProdID=%s Rev=%s.%s\n" \
|
129
|
+
$vendid $prodid $revmajor $revminor
|
130
|
+
|
131
|
+
print_string manufacturer "Manufacturer"
|
132
|
+
print_string product Product
|
133
|
+
print_string serial SerialNumber
|
134
|
+
|
135
|
+
numifs=`cat bNumInterfaces`
|
136
|
+
cfgnum=`cat bConfigurationValue`
|
137
|
+
attr=`cat bmAttributes`
|
138
|
+
maxpower=`cat bMaxPower`
|
139
|
+
printf "C: #Ifs=%2i Cfg#=%2i Atr=%s MxPwr=%s\n" \
|
140
|
+
$numifs $cfgnum $attr $maxpower
|
141
|
+
|
142
|
+
# There's not really any useful info in endpoint 00
|
143
|
+
#print_endpoint $devpath/ep_00
|
144
|
+
|
145
|
+
for interface in $busnum-*:?.*
|
146
|
+
do
|
147
|
+
print_interface $devpath/$interface
|
148
|
+
done
|
149
|
+
|
150
|
+
local devcount=0
|
151
|
+
for subdev in $busnum-*
|
152
|
+
do
|
153
|
+
echo "$subdev" | grep -Eq "^$busnum-[0-9]+(\.[0-9]+)*$" \
|
154
|
+
|| continue
|
155
|
+
|
156
|
+
devcount=$(($devcount + 1))
|
157
|
+
if [ -d $devpath/$subdev ]; then
|
158
|
+
print_device $devpath/$subdev \
|
159
|
+
$devnum $(($level +1)) $devcount
|
160
|
+
fi
|
161
|
+
done
|
162
|
+
}
|
163
|
+
|
164
|
+
if [ ! -d /sys/bus ]; then
|
165
|
+
echo "Error: directory /sys/bus does not exist; is sysfs mounted?" >&2
|
166
|
+
exit 1
|
167
|
+
fi
|
168
|
+
|
169
|
+
for device in /sys/bus/usb/devices/usb*
|
170
|
+
do
|
171
|
+
print_device $device 0 0 0
|
172
|
+
done
|
data/bin/usbutils
ADDED
data/lib/usbutils.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "libusb"
|
2
|
+
require "pp"
|
3
|
+
|
4
|
+
require "usbutils/version"
|
5
|
+
require "usbutils/cli"
|
6
|
+
|
7
|
+
module USBUtils
|
8
|
+
class << self
|
9
|
+
def reset(serial)
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_by(by, value)
|
13
|
+
devices.each do |device|
|
14
|
+
return device if device[by.to_sym] == value
|
15
|
+
end
|
16
|
+
raise "device not found: #{by}:#{value}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def devices
|
20
|
+
devices = []
|
21
|
+
Dir.glob("/sys/bus/usb/devices/usb*") do |device|
|
22
|
+
set_device(devices, device, 0, 0)
|
23
|
+
end
|
24
|
+
devices
|
25
|
+
|
26
|
+
usb = LIBUSB::Context.new
|
27
|
+
usb.devices.each do |usbdev|
|
28
|
+
idvendor = format("%04x", usbdev.idVendor)
|
29
|
+
idproduct = format("%04x", usbdev.idProduct)
|
30
|
+
device = devices.select {|item| item[:idvendor] == idvendor && item[:idproduct] == idproduct}.first
|
31
|
+
device[:usbdev] = usbdev
|
32
|
+
end
|
33
|
+
devices
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_device(devices, devpath, parent, level)
|
37
|
+
return unless FileTest::directory?(devpath)
|
38
|
+
Dir.chdir(devpath) do
|
39
|
+
next unless File.exists? "#{devpath}/serial"
|
40
|
+
busnum = `cat busnum`.chomp
|
41
|
+
devnum = `cat devnum`.chomp
|
42
|
+
idvendor = `cat idVendor`.chomp
|
43
|
+
idproduct = `cat idProduct`.chomp
|
44
|
+
manufacturer = `cat manufacturer`.chomp
|
45
|
+
product = `cat product`.chomp
|
46
|
+
serial = `cat serial`.chomp
|
47
|
+
devices << {
|
48
|
+
:serial => serial,
|
49
|
+
:idvendor => idvendor,
|
50
|
+
:idproduct => idproduct,
|
51
|
+
:manufacturer => manufacturer,
|
52
|
+
:product => product,
|
53
|
+
}
|
54
|
+
Dir.glob("#{busnum}-*") do |subdev|
|
55
|
+
set_device devices, "#{devpath}/#{subdev}", devnum, level + 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/usbutils/cli.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'usbutils'
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module USBUtils
|
6
|
+
class CLI < Thor
|
7
|
+
desc "find_by <by> <value>", "find device"
|
8
|
+
def find_by(by, value)
|
9
|
+
pp USBUtils.find_by(by, value)
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "reset_by <by> <value>", "reset device"
|
13
|
+
def reset_by(by, value)
|
14
|
+
device = USBUtils.find_by(by, value)
|
15
|
+
device[:usbdev].open.reset_device
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "reset <serial no>", "reset device"
|
19
|
+
def reset(serial)
|
20
|
+
device = USBUtils.find_by(:serial, serial)
|
21
|
+
p device[:usbdev]
|
22
|
+
p device[:usbdev].open
|
23
|
+
#device[:usbdev].open.reset_device
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "devices", "list all usb devices"
|
27
|
+
def devices
|
28
|
+
USBUtils.devices.each do |device|
|
29
|
+
pp device
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/usbutils.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'usbutils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "usbutils"
|
8
|
+
spec.version = USBUtils::VERSION
|
9
|
+
spec.authors = ["k-yamada"]
|
10
|
+
spec.email = ["yamadakazu45@gmail.com"]
|
11
|
+
spec.summary = %q{usb utils}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "libusb"
|
25
|
+
spec.add_dependency "thor"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: usbutils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- k-yamada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: libusb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- yamadakazu45@gmail.com
|
72
|
+
executables:
|
73
|
+
- usb-devices
|
74
|
+
- usbutils
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Berksfile
|
80
|
+
- Berksfile.lock
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- Vagrantfile
|
86
|
+
- bin/usb-devices
|
87
|
+
- bin/usbutils
|
88
|
+
- lib/usbutils.rb
|
89
|
+
- lib/usbutils/cli.rb
|
90
|
+
- lib/usbutils/version.rb
|
91
|
+
- usbutils.gemspec
|
92
|
+
homepage: ''
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.0.3
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: usb utils
|
116
|
+
test_files: []
|
117
|
+
has_rdoc:
|