libusb 0.6.0-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +17 -0
  4. data/.yardopts +6 -0
  5. data/COPYING +165 -0
  6. data/Gemfile +11 -0
  7. data/History.md +124 -0
  8. data/README.md +159 -0
  9. data/Rakefile +145 -0
  10. data/appveyor.yml +23 -0
  11. data/lib/libusb.rb +58 -0
  12. data/lib/libusb/bos.rb +306 -0
  13. data/lib/libusb/call.rb +446 -0
  14. data/lib/libusb/compat.rb +376 -0
  15. data/lib/libusb/configuration.rb +155 -0
  16. data/lib/libusb/constants.rb +160 -0
  17. data/lib/libusb/context.rb +426 -0
  18. data/lib/libusb/dependencies.rb +7 -0
  19. data/lib/libusb/dev_handle.rb +564 -0
  20. data/lib/libusb/device.rb +365 -0
  21. data/lib/libusb/endpoint.rb +194 -0
  22. data/lib/libusb/eventmachine.rb +183 -0
  23. data/lib/libusb/interface.rb +60 -0
  24. data/lib/libusb/setting.rb +132 -0
  25. data/lib/libusb/ss_companion.rb +69 -0
  26. data/lib/libusb/stdio.rb +25 -0
  27. data/lib/libusb/transfer.rb +377 -0
  28. data/lib/libusb/version_gem.rb +19 -0
  29. data/lib/libusb/version_struct.rb +63 -0
  30. data/libusb.gemspec +30 -0
  31. data/test/test_libusb_bos.rb +118 -0
  32. data/test/test_libusb_bulk_stream_transfer.rb +50 -0
  33. data/test/test_libusb_capability.rb +23 -0
  34. data/test/test_libusb_compat.rb +78 -0
  35. data/test/test_libusb_compat_mass_storage.rb +81 -0
  36. data/test/test_libusb_descriptors.rb +212 -0
  37. data/test/test_libusb_event_machine.rb +118 -0
  38. data/test/test_libusb_gc.rb +37 -0
  39. data/test/test_libusb_hotplug.rb +127 -0
  40. data/test/test_libusb_iso_transfer.rb +50 -0
  41. data/test/test_libusb_mass_storage.rb +268 -0
  42. data/test/test_libusb_mass_storage2.rb +96 -0
  43. data/test/test_libusb_structs.rb +58 -0
  44. data/test/test_libusb_threads.rb +89 -0
  45. data/test/test_libusb_version.rb +40 -0
  46. data/wireshark-usb-sniffer.png +0 -0
  47. metadata +150 -0
@@ -0,0 +1,96 @@
1
+ # This file is part of Libusb for Ruby.
2
+ #
3
+ # Libusb for Ruby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # Libusb for Ruby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Libusb for Ruby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ require "minitest/autorun"
18
+ require "libusb"
19
+
20
+ class TestLibusbMassStorage2 < Minitest::Test
21
+ include LIBUSB
22
+
23
+ attr_accessor :usb
24
+ attr_accessor :device
25
+ attr_accessor :interface
26
+
27
+ def setup
28
+ @usb = Context.new
29
+ @usb.debug = 3
30
+ @device = usb.devices( bClass: CLASS_MASS_STORAGE, bSubClass: [0x06,0x01], bProtocol: 0x50 ).last
31
+ skip "no mass storage device found" unless @device
32
+
33
+ @interface = device.interfaces.first
34
+
35
+ # Ensure kernel driver is detached
36
+ device.open do |dev|
37
+ if RUBY_PLATFORM=~/linux/i && dev.kernel_driver_active?(interface)
38
+ dev.detach_kernel_driver(interface)
39
+ end
40
+ end
41
+ end
42
+
43
+ def teardown
44
+ end
45
+
46
+ def test_open_with_block
47
+ device.open do |dev|
48
+ assert_kind_of DevHandle, dev
49
+ assert_kind_of String, dev.string_descriptor_ascii(1)
50
+ end
51
+ end
52
+
53
+ def test_claim_interface_with_block
54
+ res = device.open do |dev|
55
+ dev.claim_interface(interface) do |dev2|
56
+ assert_kind_of DevHandle, dev2
57
+ assert_kind_of String, dev2.string_descriptor_ascii(1)
58
+ 12345
59
+ end
60
+ end
61
+ assert_equal 12345, res, "Block versions should pass through the result"
62
+ end
63
+
64
+ def test_open_interface
65
+ res = device.open_interface(interface) do |dev|
66
+ assert_kind_of DevHandle, dev
67
+ assert_kind_of String, dev.string_descriptor_ascii(1)
68
+ 12345
69
+ end
70
+ assert_equal 12345, res, "Block versions should pass through the result"
71
+ end
72
+
73
+ def test_attach_kernel_driver
74
+ # Should work with both Fixnum and Interface parameter
75
+ [0, interface].each do |i|
76
+ device.open do |dev|
77
+ dev.attach_kernel_driver(i)
78
+ assert dev.kernel_driver_active?(i), "kernel driver should be active again"
79
+ dev.detach_kernel_driver(i)
80
+ refute dev.kernel_driver_active?(i), "kernel driver should be detached"
81
+ end
82
+ end
83
+ end
84
+
85
+ def test_auto_detach_kernel_driver
86
+ assert LIBUSB.has_capability?(:CAP_SUPPORTS_DETACH_KERNEL_DRIVER), "libusb should have CAP_SUPPORTS_DETACH_KERNEL_DRIVER"
87
+
88
+ device.open do |dev|
89
+ dev.attach_kernel_driver 0
90
+ assert dev.kernel_driver_active?(0), "kernel driver should attached, now"
91
+ dev.auto_detach_kernel_driver = true
92
+ dev.claim_interface(0)
93
+ refute dev.kernel_driver_active?(0), "kernel driver should get detached automatically"
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,58 @@
1
+ # This file is part of Libusb for Ruby.
2
+ #
3
+ # Libusb for Ruby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # Libusb for Ruby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Libusb for Ruby. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require "minitest/autorun"
17
+ require "libusb"
18
+
19
+ class TestLibusbStructs < Minitest::Test
20
+ def test_struct_Timeval
21
+ s = LIBUSB::Call::Timeval.new
22
+ assert_equal 0, s.in_ms
23
+ s.in_ms = 12345678
24
+ assert_equal 12345, s[:tv_sec]
25
+ assert_equal 678000, s[:tv_usec]
26
+ assert_equal 12345678, s.in_ms
27
+
28
+ s.in_s = 1234.5678
29
+ assert_equal 1234, s[:tv_sec]
30
+ assert_equal 567800, s[:tv_usec]
31
+ assert_equal 1234.5678, s.in_s
32
+ end
33
+
34
+ def test_struct_CompletionFlag
35
+ s = LIBUSB::Context::CompletionFlag.new
36
+ assert_equal 0, s[:completed]
37
+ assert_equal false, s.completed?
38
+ s.completed = true
39
+ assert_equal 1, s[:completed]
40
+ assert_equal true, s.completed?
41
+ s.completed = false
42
+ assert_equal false, s.completed?
43
+ assert_equal 0, s[:completed]
44
+ end
45
+
46
+ def test_Transfer
47
+ t = LIBUSB::InterruptTransfer.new allow_device_memory: true
48
+ assert_equal :TRANSFER_COMPLETED, t.status
49
+ assert_equal true, t.allow_device_memory
50
+ assert_equal nil, t.memory_type
51
+
52
+ t.alloc_buffer(10)
53
+ assert_equal :user_space, t.memory_type, "no device assigned -> should use memory from user space"
54
+
55
+ t.free_buffer
56
+ assert_equal nil, t.memory_type
57
+ end
58
+ end
@@ -0,0 +1,89 @@
1
+ # This file is part of Libusb for Ruby.
2
+ #
3
+ # Libusb for Ruby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # Libusb for Ruby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Libusb for Ruby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ # This test requires two connected, but not mounted mass storage device with
17
+ # read/write access allowed.
18
+
19
+ require "minitest/autorun"
20
+ require "libusb"
21
+
22
+ class TestLibusbThreads < Minitest::Test
23
+ include LIBUSB
24
+
25
+ BOMS_GET_MAX_LUN = 0xFE
26
+
27
+ attr_accessor :usb
28
+ attr_accessor :devices
29
+ attr_accessor :devs
30
+ attr_accessor :endpoints_in
31
+ attr_accessor :endpoints_out
32
+
33
+ def setup
34
+ @usb = Context.new
35
+ @usb.debug = 3
36
+
37
+ @devices = usb.devices( bClass: CLASS_MASS_STORAGE, bSubClass: [0x06,0x01], bProtocol: 0x50 )
38
+ skip "less than two mass storage devices found" unless @devices.length >= 2
39
+
40
+ @devs = @devices.map do |device|
41
+ dev = device.open
42
+ if RUBY_PLATFORM=~/linux/i && dev.kernel_driver_active?(0)
43
+ dev.detach_kernel_driver(0)
44
+ end
45
+ dev.claim_interface(0)
46
+ dev
47
+ end
48
+
49
+ @endpoints_in = {}
50
+ @endpoints_out = {}
51
+
52
+ @devs.each do |dev|
53
+ @endpoints_in[dev] = dev.device.endpoints.find{|ep| ep.bEndpointAddress&ENDPOINT_IN != 0 }
54
+ @endpoints_out[dev] = dev.device.endpoints.find{|ep| ep.bEndpointAddress&ENDPOINT_IN == 0 }
55
+ end
56
+
57
+ Thread.abort_on_exception = true
58
+ end
59
+
60
+ def teardown
61
+ if devs
62
+ devs.each do |dev|
63
+ dev.release_interface(0)
64
+ dev.close
65
+ end
66
+ end
67
+ end
68
+
69
+ def thread_worker(dev)
70
+ endpoint = endpoints_in[dev]
71
+ 1.times do
72
+ st = Time.now
73
+ assert_raises LIBUSB::ERROR_TIMEOUT do
74
+ dev.bulk_transfer(endpoint: endpoint, dataIn: 123, timeout: 100)
75
+ end
76
+ assert_operator Time.now-st, :<, 5
77
+ dev.clear_halt(endpoint)
78
+ end
79
+ end
80
+
81
+ def test_sync_api
82
+ threads = devs.map do |dev|
83
+ Thread.new do
84
+ thread_worker(dev)
85
+ end
86
+ end
87
+ threads.map(&:join)
88
+ end
89
+ end
@@ -0,0 +1,40 @@
1
+ # This file is part of Libusb for Ruby.
2
+ #
3
+ # Libusb for Ruby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # Libusb for Ruby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Libusb for Ruby. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require "minitest/autorun"
17
+ require "libusb"
18
+
19
+ class TestLibusbVersion < Minitest::Test
20
+ def setup
21
+ @v = LIBUSB.version
22
+ end
23
+
24
+ def test_version_parts
25
+ assert_operator @v.major, :>=, 0
26
+ assert_operator @v.minor, :>=, 0
27
+ assert_operator @v.micro, :>=, 0
28
+ assert_operator @v.nano, :>=, 0
29
+ assert_kind_of String, @v.rc
30
+ end
31
+
32
+ def test_version_string
33
+ assert_match(/^\d+\.\d+\.\d+/, @v.to_s)
34
+ assert_match(/^#<LIBUSB::Version \d+\.\d+\.\d+/, @v.inspect)
35
+ end
36
+
37
+ def test_gem_version_string
38
+ assert_match(/^\d+\.\d+\.\d+/, LIBUSB::VERSION)
39
+ end
40
+ end
Binary file
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libusb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: x86-linux
6
+ authors:
7
+ - Lars Kanis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler-dock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary
70
+ USB devices
71
+ email:
72
+ - lars@greiz-reinsdorf.de
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - ".yardopts"
80
+ - COPYING
81
+ - Gemfile
82
+ - History.md
83
+ - README.md
84
+ - Rakefile
85
+ - appveyor.yml
86
+ - lib/libusb-1.0.so
87
+ - lib/libusb.rb
88
+ - lib/libusb/bos.rb
89
+ - lib/libusb/call.rb
90
+ - lib/libusb/compat.rb
91
+ - lib/libusb/configuration.rb
92
+ - lib/libusb/constants.rb
93
+ - lib/libusb/context.rb
94
+ - lib/libusb/dependencies.rb
95
+ - lib/libusb/dev_handle.rb
96
+ - lib/libusb/device.rb
97
+ - lib/libusb/endpoint.rb
98
+ - lib/libusb/eventmachine.rb
99
+ - lib/libusb/interface.rb
100
+ - lib/libusb/setting.rb
101
+ - lib/libusb/ss_companion.rb
102
+ - lib/libusb/stdio.rb
103
+ - lib/libusb/transfer.rb
104
+ - lib/libusb/version_gem.rb
105
+ - lib/libusb/version_struct.rb
106
+ - libusb.gemspec
107
+ - test/test_libusb_bos.rb
108
+ - test/test_libusb_bulk_stream_transfer.rb
109
+ - test/test_libusb_capability.rb
110
+ - test/test_libusb_compat.rb
111
+ - test/test_libusb_compat_mass_storage.rb
112
+ - test/test_libusb_descriptors.rb
113
+ - test/test_libusb_event_machine.rb
114
+ - test/test_libusb_gc.rb
115
+ - test/test_libusb_hotplug.rb
116
+ - test/test_libusb_iso_transfer.rb
117
+ - test/test_libusb_mass_storage.rb
118
+ - test/test_libusb_mass_storage2.rb
119
+ - test/test_libusb_structs.rb
120
+ - test/test_libusb_threads.rb
121
+ - test/test_libusb_version.rb
122
+ - wireshark-usb-sniffer.png
123
+ homepage: http://github.com/larskanis/libusb
124
+ licenses:
125
+ - LGPL-3.0
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options:
129
+ - "--main"
130
+ - README.md
131
+ - "--charset=UTF-8"
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.9.3
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.5.2
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Access USB devices from Ruby via libusb-1.0
150
+ test_files: []