svi 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/bin/dfu +176 -0
- data/bin/gettime +153 -0
- data/bin/led_set +158 -0
- data/bin/lun_format_ao +153 -0
- data/bin/lun_get_count +149 -0
- data/bin/lun_get_table +176 -0
- data/bin/lun_save_table +149 -0
- data/bin/lun_set_count +150 -0
- data/bin/lun_set_mode +161 -0
- data/bin/lun_set_table +154 -0
- data/bin/random +152 -0
- data/bin/settime +156 -0
- data/bin/svi +4 -0
- data/bin/svirb +21 -0
- data/bin/system_reset +149 -0
- data/bin/usb_reconnect +149 -0
- data/lib/svi/api.generated.rb +31 -0
- data/lib/svi/api.rb +111 -0
- data/lib/svi/svi.rb +135 -0
- metadata +98 -0
data/bin/system_reset
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/ruby19
|
2
|
+
|
3
|
+
require 'svi/svi'
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'optparse/time'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
USAGE = "Usage: system_reset [options]"
|
10
|
+
ARGS_NUM = 0
|
11
|
+
|
12
|
+
def parse_options(args)
|
13
|
+
options = OpenStruct.new
|
14
|
+
|
15
|
+
opt_parser = OptionParser.new do |opts|
|
16
|
+
opts.banner = USAGE
|
17
|
+
options.vid = 0x3241
|
18
|
+
options.pid = 0x9372
|
19
|
+
options.svi_if = 2
|
20
|
+
options.sbi_if = 3
|
21
|
+
options.sbi_if_ep_out = 0x3
|
22
|
+
options.sbi_if_ep_in = 0x3
|
23
|
+
options.svi_if_ep_out = 0x4
|
24
|
+
options.svi_if_ep_in = 0x4
|
25
|
+
options.timeout = 1000
|
26
|
+
options.devnum = 0
|
27
|
+
options.devnum_mod = nil
|
28
|
+
options.verbose = false
|
29
|
+
|
30
|
+
opts.separator ""
|
31
|
+
opts.separator "Common options:"
|
32
|
+
|
33
|
+
opts.on("-D", "--device vid:pid", String, "Use appropriate VID/PID") do |vidpid|
|
34
|
+
vidpid = vidpid.split ':'
|
35
|
+
options.vid = vidpid[0].hex
|
36
|
+
options.pid = vidpid[1].hex
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-N", "--device-number N", Integer, "Use device number N (see device list by --list option)") do |devnum|
|
40
|
+
options.devnum = devnum
|
41
|
+
options.devnum_mod = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-T", "--timeout milliseconds", Integer, "Timeout for transfers on both interfaces") do |timeout|
|
45
|
+
options.timeout = timeout
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("--svi-if ifnum:epout:epin", String, "Define interface for SVI") do |args|
|
49
|
+
args = args.split ':'
|
50
|
+
options.svi_if = args[0].hex
|
51
|
+
options.svi_if_ep_out = args[1].hex
|
52
|
+
options.svi_if_ep_in = args[2].hex
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("--verbose", "Print maximum information") do
|
56
|
+
options.verbose = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("--sbi-if ifnum:epout:epin", String, "Define interface for SBI") do |args|
|
60
|
+
args = args.split ':'
|
61
|
+
options.sbi_if = args[0].hex
|
62
|
+
options.sbi_if_ep_out = args[1].hex
|
63
|
+
options.sbi_if_ep_in = args[2].hex
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on_tail("-l", "--list", "Show devices list only") do
|
67
|
+
USB.new(options.vid, options.pid).svi_devices.each_with_index { |dev, i|
|
68
|
+
puts "#%d %s %s" % [i, dev.manufacturer, dev.product]
|
69
|
+
}
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
74
|
+
puts opts
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on_tail("--version", "Show version") do
|
79
|
+
puts SVI_VERSION
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
opt_parser.parse!(args)
|
85
|
+
[options, opt_parser]
|
86
|
+
end
|
87
|
+
|
88
|
+
res = parse_options(ARGV)
|
89
|
+
options = res[0]
|
90
|
+
opt_parser = res[1]
|
91
|
+
|
92
|
+
if ARGV.count != ARGS_NUM
|
93
|
+
p opt_parser
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
devs = USB.new(options.vid, options.pid).svi_devices
|
98
|
+
|
99
|
+
if devs.count == 0
|
100
|
+
puts 'Device not found'
|
101
|
+
exit 1
|
102
|
+
end
|
103
|
+
|
104
|
+
if devs.count > 1 and options.devnum_mod.nil?
|
105
|
+
puts 'There are more than one devices, using device #%d.' % options.devnum
|
106
|
+
puts 'Use option -N to define necessary device.'
|
107
|
+
puts "To view list of devices use -l option.\n\n"
|
108
|
+
end
|
109
|
+
|
110
|
+
dev = devs[options.devnum]
|
111
|
+
|
112
|
+
dev.svi_if = options.svi_if
|
113
|
+
dev.svi_if_ep_out = options.svi_if_ep_out
|
114
|
+
dev.svi_if_ep_in = options.svi_if_ep_in
|
115
|
+
|
116
|
+
dev.sbi_if = options.sbi_if
|
117
|
+
dev.sbi_if_ep_out = options.sbi_if_ep_out
|
118
|
+
dev.sbi_if_ep_in = options.sbi_if_ep_in
|
119
|
+
|
120
|
+
dev.svi_timeout = options.timeout
|
121
|
+
dev.sbi_timeout = options.timeout
|
122
|
+
|
123
|
+
if options.verbose
|
124
|
+
puts "Configuration:"
|
125
|
+
puts "Device # = %d" % options.devnum
|
126
|
+
puts "idVendor = 0x%04x" % options.vid
|
127
|
+
puts "idProduct = 0x%04x" % options.pid
|
128
|
+
puts "Interface number SVI = %d" % options.svi_if
|
129
|
+
puts "OUT endpoint for SVI = 0x%02x" % options.svi_if_ep_out
|
130
|
+
puts "IN endpoint for SVI = 0x%02x" % (options.svi_if_ep_in | 0x80)
|
131
|
+
puts "Interface number SBI = %d" % options.sbi_if
|
132
|
+
puts "OUT endpoint for SBI = 0x%02x" % options.sbi_if_ep_out
|
133
|
+
puts "IN endpoint for SBI = 0x%02x" % (options.sbi_if_ep_in | 0x80)
|
134
|
+
puts "Timeout for IN operations = %d msec" % options.timeout
|
135
|
+
puts "\n\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
if options.verbose
|
139
|
+
end
|
140
|
+
|
141
|
+
res = dev.system_reset
|
142
|
+
|
143
|
+
if options.verbose
|
144
|
+
end
|
145
|
+
|
146
|
+
p res[0].to_i
|
147
|
+
|
148
|
+
# vim: sw=2 sts=2 ts=8:
|
149
|
+
|
data/bin/usb_reconnect
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/ruby19
|
2
|
+
|
3
|
+
require 'svi/svi'
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'optparse/time'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
USAGE = "Usage: usb_reconnect [options]"
|
10
|
+
ARGS_NUM = 0
|
11
|
+
|
12
|
+
def parse_options(args)
|
13
|
+
options = OpenStruct.new
|
14
|
+
|
15
|
+
opt_parser = OptionParser.new do |opts|
|
16
|
+
opts.banner = USAGE
|
17
|
+
options.vid = 0x3241
|
18
|
+
options.pid = 0x9372
|
19
|
+
options.svi_if = 2
|
20
|
+
options.sbi_if = 3
|
21
|
+
options.sbi_if_ep_out = 0x3
|
22
|
+
options.sbi_if_ep_in = 0x3
|
23
|
+
options.svi_if_ep_out = 0x4
|
24
|
+
options.svi_if_ep_in = 0x4
|
25
|
+
options.timeout = 1000
|
26
|
+
options.devnum = 0
|
27
|
+
options.devnum_mod = nil
|
28
|
+
options.verbose = false
|
29
|
+
|
30
|
+
opts.separator ""
|
31
|
+
opts.separator "Common options:"
|
32
|
+
|
33
|
+
opts.on("-D", "--device vid:pid", String, "Use appropriate VID/PID") do |vidpid|
|
34
|
+
vidpid = vidpid.split ':'
|
35
|
+
options.vid = vidpid[0].hex
|
36
|
+
options.pid = vidpid[1].hex
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-N", "--device-number N", Integer, "Use device number N (see device list by --list option)") do |devnum|
|
40
|
+
options.devnum = devnum
|
41
|
+
options.devnum_mod = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-T", "--timeout milliseconds", Integer, "Timeout for transfers on both interfaces") do |timeout|
|
45
|
+
options.timeout = timeout
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("--svi-if ifnum:epout:epin", String, "Define interface for SVI") do |args|
|
49
|
+
args = args.split ':'
|
50
|
+
options.svi_if = args[0].hex
|
51
|
+
options.svi_if_ep_out = args[1].hex
|
52
|
+
options.svi_if_ep_in = args[2].hex
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("--verbose", "Print maximum information") do
|
56
|
+
options.verbose = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("--sbi-if ifnum:epout:epin", String, "Define interface for SBI") do |args|
|
60
|
+
args = args.split ':'
|
61
|
+
options.sbi_if = args[0].hex
|
62
|
+
options.sbi_if_ep_out = args[1].hex
|
63
|
+
options.sbi_if_ep_in = args[2].hex
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on_tail("-l", "--list", "Show devices list only") do
|
67
|
+
USB.new(options.vid, options.pid).svi_devices.each_with_index { |dev, i|
|
68
|
+
puts "#%d %s %s" % [i, dev.manufacturer, dev.product]
|
69
|
+
}
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
74
|
+
puts opts
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on_tail("--version", "Show version") do
|
79
|
+
puts SVI_VERSION
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
opt_parser.parse!(args)
|
85
|
+
[options, opt_parser]
|
86
|
+
end
|
87
|
+
|
88
|
+
res = parse_options(ARGV)
|
89
|
+
options = res[0]
|
90
|
+
opt_parser = res[1]
|
91
|
+
|
92
|
+
if ARGV.count != ARGS_NUM
|
93
|
+
p opt_parser
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
devs = USB.new(options.vid, options.pid).svi_devices
|
98
|
+
|
99
|
+
if devs.count == 0
|
100
|
+
puts 'Device not found'
|
101
|
+
exit 1
|
102
|
+
end
|
103
|
+
|
104
|
+
if devs.count > 1 and options.devnum_mod.nil?
|
105
|
+
puts 'There are more than one devices, using device #%d.' % options.devnum
|
106
|
+
puts 'Use option -N to define necessary device.'
|
107
|
+
puts "To view list of devices use -l option.\n\n"
|
108
|
+
end
|
109
|
+
|
110
|
+
dev = devs[options.devnum]
|
111
|
+
|
112
|
+
dev.svi_if = options.svi_if
|
113
|
+
dev.svi_if_ep_out = options.svi_if_ep_out
|
114
|
+
dev.svi_if_ep_in = options.svi_if_ep_in
|
115
|
+
|
116
|
+
dev.sbi_if = options.sbi_if
|
117
|
+
dev.sbi_if_ep_out = options.sbi_if_ep_out
|
118
|
+
dev.sbi_if_ep_in = options.sbi_if_ep_in
|
119
|
+
|
120
|
+
dev.svi_timeout = options.timeout
|
121
|
+
dev.sbi_timeout = options.timeout
|
122
|
+
|
123
|
+
if options.verbose
|
124
|
+
puts "Configuration:"
|
125
|
+
puts "Device # = %d" % options.devnum
|
126
|
+
puts "idVendor = 0x%04x" % options.vid
|
127
|
+
puts "idProduct = 0x%04x" % options.pid
|
128
|
+
puts "Interface number SVI = %d" % options.svi_if
|
129
|
+
puts "OUT endpoint for SVI = 0x%02x" % options.svi_if_ep_out
|
130
|
+
puts "IN endpoint for SVI = 0x%02x" % (options.svi_if_ep_in | 0x80)
|
131
|
+
puts "Interface number SBI = %d" % options.sbi_if
|
132
|
+
puts "OUT endpoint for SBI = 0x%02x" % options.sbi_if_ep_out
|
133
|
+
puts "IN endpoint for SBI = 0x%02x" % (options.sbi_if_ep_in | 0x80)
|
134
|
+
puts "Timeout for IN operations = %d msec" % options.timeout
|
135
|
+
puts "\n\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
if options.verbose
|
139
|
+
end
|
140
|
+
|
141
|
+
res = dev.usb_reconnect
|
142
|
+
|
143
|
+
if options.verbose
|
144
|
+
end
|
145
|
+
|
146
|
+
p res[0].to_i
|
147
|
+
|
148
|
+
# vim: sw=2 sts=2 ts=8:
|
149
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$svi_api_desc = {
|
2
|
+
:lun_get_seccount => { :response => [Integer], :args => [] },
|
3
|
+
:lun_get_count => { :response => [Integer], :args => [] },
|
4
|
+
:lun_set_count => { :response => [Integer], :args => [Integer] },
|
5
|
+
:lun_set_table => { :response => [Integer], :args => [LUNDesc] },
|
6
|
+
:lun_get_table => { :response => [Integer, LUNDesc], :args => [Integer] },
|
7
|
+
:lun_set_mode => { :response => [Integer], :args => [Integer, Integer] },
|
8
|
+
:lun_format_ao => { :response => [Integer], :args => [Integer, Integer] },
|
9
|
+
:lun_save_table => { :response => [Integer], :args => [] },
|
10
|
+
:firmware_program => { :response => [Integer], :args => [Integer, Integer] },
|
11
|
+
:nvm_write => { :response => [Integer], :args => [Integer, Integer, String] },
|
12
|
+
:nvm_read => { :response => [String, Integer], :args => [Integer, Integer, Integer] },
|
13
|
+
:nvm_open => { :response => [Integer], :args => [Integer] },
|
14
|
+
:nvm_close => { :response => [Integer], :args => [Integer] },
|
15
|
+
:led_set => { :response => [], :args => [Integer, Integer] },
|
16
|
+
:usb_reconnect => { :response => [], :args => [] },
|
17
|
+
:system_reset => { :response => [], :args => [] },
|
18
|
+
:system_get_serial => { :response => [String], :args => [String] },
|
19
|
+
:system_get_sysver => { :response => [String], :args => [String] },
|
20
|
+
:firmware_get_ver => { :response => [String, String, String, String, String], :args => [] },
|
21
|
+
:system_get_appver => { :response => [String], :args => [String] },
|
22
|
+
:random => { :response => [Integer], :args => [] },
|
23
|
+
:gettime => { :response => [Integer], :args => [] },
|
24
|
+
:settime => { :response => [Integer], :args => [Integer] },
|
25
|
+
:app_exist => { :response => [Integer], :args => [] },
|
26
|
+
:app_length => { :response => [Integer], :args => [] },
|
27
|
+
:app_checksum => { :response => [Integer], :args => [] },
|
28
|
+
:app_start => { :response => [Integer], :args => [] },
|
29
|
+
:app_stop => { :response => [Integer], :args => [] },
|
30
|
+
:app_state => { :response => [Integer], :args => [] },
|
31
|
+
}
|
data/lib/svi/api.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
class Integer
|
4
|
+
def self.scan_from_svipack buf
|
5
|
+
[ buf[0..3].unpack('L')[0], buf[4..-1] ]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.put_to_svipack val
|
9
|
+
[val].pack('L')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class String
|
14
|
+
def self.scan_from_svipack buf
|
15
|
+
len, buf = Integer.scan_from_svipack buf
|
16
|
+
|
17
|
+
[ buf[0..len-1], buf[len..-1] ]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.put_to_svipack val
|
21
|
+
res = ''
|
22
|
+
res << Integer.put_to_svipack(val.length)
|
23
|
+
res << val
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module SelfString
|
28
|
+
@len
|
29
|
+
|
30
|
+
def scan_from_svipack buf
|
31
|
+
raise UndefinedError, self unless @len
|
32
|
+
|
33
|
+
[ buf[0..@len-1], buf[@len..-1] ]
|
34
|
+
end
|
35
|
+
|
36
|
+
def len= length
|
37
|
+
raise ArgumentError unless length.kind_of? Integer
|
38
|
+
|
39
|
+
@len = length
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class LUNDesc < Array
|
44
|
+
def self.scan_from_svipack buf
|
45
|
+
count, buf = Integer.scan_from_svipack buf
|
46
|
+
|
47
|
+
luns = []
|
48
|
+
|
49
|
+
# TODO: Kill Constant «8»
|
50
|
+
raise ArgumentError, "LUNDesc: error count #{count}" unless count <= 8 and count > 0
|
51
|
+
|
52
|
+
count.times do
|
53
|
+
start, buf = Integer.scan_from_svipack buf
|
54
|
+
len, buf = Integer.scan_from_svipack buf
|
55
|
+
mode, buf = Integer.scan_from_svipack buf
|
56
|
+
flags, buf = Integer.scan_from_svipack buf
|
57
|
+
|
58
|
+
luns << start << len << mode << flags
|
59
|
+
end
|
60
|
+
|
61
|
+
[ luns, buf ]
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.put_to_svipack val
|
65
|
+
raise "LUNDesc elements array.count%4 shall be 0" unless val.count%4 == 0
|
66
|
+
res = ''
|
67
|
+
|
68
|
+
res << Integer.put_to_svipack(val.count/4)
|
69
|
+
|
70
|
+
val.each do |elem|
|
71
|
+
res << Integer.put_to_svipack(elem)
|
72
|
+
end
|
73
|
+
|
74
|
+
res
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module SVISubsystemNVM
|
79
|
+
def nvm_load_file bank, offset, path
|
80
|
+
raise ArgumentError, 'file (%s) is not readable' % path.to_s unless Pathname.new(path).readable_real?
|
81
|
+
|
82
|
+
data = IO.binread(path).unpack 'C*'
|
83
|
+
data = data + [0]*(data.length % 1024 > 0 ? (1024 - data.length%1024) : 0)
|
84
|
+
data = data.each_slice(1024).to_a
|
85
|
+
|
86
|
+
data.each_with_index do |packet, i|
|
87
|
+
nvm_write bank, offset + i*1024, packet.pack('C*')
|
88
|
+
end
|
89
|
+
|
90
|
+
[0]
|
91
|
+
end
|
92
|
+
|
93
|
+
def nvm_verify_file bank, offset, path
|
94
|
+
raise ArgumentError, 'file (%s) is not readable' % path.to_s unless Pathname.new(path).readable_real?
|
95
|
+
|
96
|
+
data = IO.binread(path).unpack 'C*'
|
97
|
+
data = data + [0]*(data.length % 1024 > 0 ? (1024 - data.length%1024) : 0)
|
98
|
+
data = data.each_slice(1024).to_a
|
99
|
+
|
100
|
+
data.each_with_index do |packet, i|
|
101
|
+
res = nvm_read(bank, offset + i*1024, 1024)[0]
|
102
|
+
|
103
|
+
return [1, res, packet.pack('C*')] if res != packet.pack('C*')
|
104
|
+
end
|
105
|
+
|
106
|
+
[0]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# vim: sw=2 sts=2 ts=8:
|
111
|
+
|
data/lib/svi/svi.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'libusb'
|
2
|
+
|
3
|
+
require 'svi/api'
|
4
|
+
require 'svi/api.generated'
|
5
|
+
|
6
|
+
|
7
|
+
class USB < LIBUSB::Context
|
8
|
+
@vidpids
|
9
|
+
|
10
|
+
def initialize(vid, pid)
|
11
|
+
@vidpids = [
|
12
|
+
{:idVendor => vid, :idProduct => pid}
|
13
|
+
]
|
14
|
+
|
15
|
+
super()
|
16
|
+
end
|
17
|
+
|
18
|
+
def svi_devices
|
19
|
+
devs = []
|
20
|
+
@vidpids.each { |vidpid|
|
21
|
+
devs = devs + devices(vidpid)
|
22
|
+
}
|
23
|
+
|
24
|
+
devs.each { |dev| dev.extend SVIDevice }
|
25
|
+
|
26
|
+
devs
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module SVICall
|
31
|
+
SVI_PACKET_SIZE = 2048
|
32
|
+
|
33
|
+
def call(*_args)
|
34
|
+
args = _args.reverse
|
35
|
+
noreturn = false
|
36
|
+
resp = nil
|
37
|
+
packet = ""
|
38
|
+
|
39
|
+
raise ArgumentError, 'Wrong arguments count' if args.count == 0
|
40
|
+
|
41
|
+
if args[-1] == :noreturn
|
42
|
+
noreturn = true
|
43
|
+
args.pop
|
44
|
+
end
|
45
|
+
|
46
|
+
name = args.pop
|
47
|
+
|
48
|
+
raise ArgumentError, "Invalid syscall name #{name}" unless $svi_api_desc.has_key? name
|
49
|
+
raise ArgumentError, 'SVI is not configured' unless svi_configured?
|
50
|
+
|
51
|
+
packet << name.to_s << "\0"
|
52
|
+
|
53
|
+
args.reverse!
|
54
|
+
|
55
|
+
$svi_api_desc[name][:args].each_with_index do |arg, i|
|
56
|
+
packet << arg.put_to_svipack(args[i])
|
57
|
+
end
|
58
|
+
|
59
|
+
raise ArgumentError, 'Too long svc call' if packet.length > SVI_PACKET_SIZE
|
60
|
+
|
61
|
+
packet << ([0]*(SVI_PACKET_SIZE-packet.length)).pack('C*')
|
62
|
+
|
63
|
+
res = nil
|
64
|
+
|
65
|
+
open_interface(svi_if) do |handle|
|
66
|
+
res = handle.bulk_transfer(:endpoint => svi_if_ep_out, :dataOut => packet)
|
67
|
+
|
68
|
+
raise IOError, 'Sending failed' unless res == SVI_PACKET_SIZE
|
69
|
+
|
70
|
+
resp = []
|
71
|
+
|
72
|
+
res = handle.bulk_transfer(:endpoint => svi_if_ep_in | 0x80, :dataIn => SVI_PACKET_SIZE, :timeout => @svi_timeout) unless $svi_api_desc[name][:response].empty? || noreturn
|
73
|
+
end
|
74
|
+
|
75
|
+
unless $svi_api_desc[name][:response].empty? || noreturn
|
76
|
+
$svi_api_desc[name][:response].each do |resptype|
|
77
|
+
resp_token, res = resptype.scan_from_svipack res
|
78
|
+
resp << resp_token
|
79
|
+
end
|
80
|
+
else
|
81
|
+
resp << 0
|
82
|
+
end
|
83
|
+
|
84
|
+
resp
|
85
|
+
end
|
86
|
+
|
87
|
+
def method_missing *args
|
88
|
+
call *args
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
module SBITxRx
|
93
|
+
attr_accessor :sbi_if
|
94
|
+
attr_accessor :sbi_if_ep_out
|
95
|
+
attr_accessor :sbi_if_ep_in
|
96
|
+
attr_accessor :sbi_timeout
|
97
|
+
|
98
|
+
def sbi_configured?
|
99
|
+
!(@sbi_if.nil? or @sbi_if_ep_out.nil? or @sbi_if_ep_in.nil?)
|
100
|
+
end
|
101
|
+
|
102
|
+
def sbi_send data
|
103
|
+
raise ArgumentError unless sbi_configured?
|
104
|
+
|
105
|
+
open_interface(sbi_if) { |handle|
|
106
|
+
res = handle.bulk_transfer(:endpoint => sbi_if_ep_out, :dataOut => data)
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def sbi_receive length
|
111
|
+
raise ArgumentError if @sbi_if.nil? or @sbi_if_ep_out.nil? or @sbi_if_ep_in.nil?
|
112
|
+
|
113
|
+
open_interface(sbi_if) { |handle|
|
114
|
+
res = handle.bulk_transfer(:endpoint => sbi_if_ep_in | 0x80, :dataIn => length, :timeout => @sbi_timeout)
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
module SVIDevice
|
120
|
+
attr_accessor :svi_if
|
121
|
+
attr_accessor :svi_if_ep_out
|
122
|
+
attr_accessor :svi_if_ep_in
|
123
|
+
attr_accessor :svi_timeout
|
124
|
+
|
125
|
+
include SVICall
|
126
|
+
include SBITxRx
|
127
|
+
include SVISubsystemNVM
|
128
|
+
|
129
|
+
def svi_configured?
|
130
|
+
!(@svi_if.nil? or @svi_if_ep_out.nil? or @svi_if_ep_in.nil? or @svi_timeout.nil?)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# vim: sw=2 sts=2 ts=8:
|
135
|
+
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Levenkov Artem
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: libusb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.4'
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.1
|
33
|
+
description: Service Interface
|
34
|
+
email: alev@mcs51.ru
|
35
|
+
executables:
|
36
|
+
- usb_reconnect
|
37
|
+
- lun_set_mode
|
38
|
+
- random
|
39
|
+
- system_reset
|
40
|
+
- lun_get_count
|
41
|
+
- lun_set_count
|
42
|
+
- lun_set_table
|
43
|
+
- svi
|
44
|
+
- svirb
|
45
|
+
- lun_save_table
|
46
|
+
- settime
|
47
|
+
- dfu
|
48
|
+
- lun_format_ao
|
49
|
+
- gettime
|
50
|
+
- led_set
|
51
|
+
- lun_get_table
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- bin/dfu
|
56
|
+
- bin/gettime
|
57
|
+
- bin/led_set
|
58
|
+
- bin/lun_format_ao
|
59
|
+
- bin/lun_get_count
|
60
|
+
- bin/lun_get_table
|
61
|
+
- bin/lun_save_table
|
62
|
+
- bin/lun_set_count
|
63
|
+
- bin/lun_set_mode
|
64
|
+
- bin/lun_set_table
|
65
|
+
- bin/random
|
66
|
+
- bin/settime
|
67
|
+
- bin/svi
|
68
|
+
- bin/svirb
|
69
|
+
- bin/system_reset
|
70
|
+
- bin/usb_reconnect
|
71
|
+
- lib/svi/api.generated.rb
|
72
|
+
- lib/svi/api.rb
|
73
|
+
- lib/svi/svi.rb
|
74
|
+
homepage: http://www.mcs51.ru/svi-utils
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Service Interface for MCS51
|
98
|
+
test_files: []
|