aca-device-modules 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,218 +32,218 @@ module Extron::Switcher; end
32
32
 
33
33
 
34
34
  class Extron::Switcher::Dxp
35
- include ::Orchestrator::Constants
35
+ include ::Orchestrator::Constants
36
36
  include ::Orchestrator::Transcoder
37
37
 
38
38
 
39
- def on_load
40
- #
41
- # Setup constants
42
- #
43
- defaults({
44
- :wait => false
45
- })
46
- config({
47
- :clear_queue_on_disconnect => true # Clear the queue as we may need to send login
48
- })
49
- end
50
-
51
- def connected
52
- @polling_timer = schedule.every('2m') do
53
- logger.debug "-- Extron Maintaining Connection"
54
- send('Q', :priority => 0) # Low priority poll to maintain connection
55
- end
56
- end
57
-
58
- def disconnected
59
- #
60
- # Disconnected may be called without calling connected
61
- # Hence the check if timer is nil here
62
- #
63
- @polling_timer.cancel unless @polling_timer.nil?
64
- @polling_timer = nil
65
- end
66
-
67
-
68
- def direct(string)
69
- send(string, :wait => false)
70
- end
71
-
72
-
73
- #
74
- # No need to wait as commands can be chained
75
- #
76
- def switch(map)
77
- map.each do |input, outputs|
78
- input = input.to_s if input.is_a?(Symbol)
79
- input = input.to_i if input.is_a?(String)
80
-
81
- outputs = [outputs] unless outputs.is_a?(Array)
82
- command = ''
83
- outputs.each do |output|
84
- command += "#{input}*#{output}!"
85
- end
86
- send(command)
87
- end
88
- end
89
-
90
- def switch_video(map)
91
- map.each do |input, outputs|
92
- input = input.to_s if input.is_a?(Symbol)
93
- input = input.to_i if input.is_a?(String)
94
-
95
-
96
- outputs = [outputs] unless outputs.is_a?(Array)
97
- command = ''
98
- outputs.each do |output|
99
- command += "#{input}*#{output}%"
100
- end
101
- send(command)
102
- end
103
- end
104
-
105
- def switch_audio(map)
106
- map.each do |input, outputs|
107
- input = input.to_s if input.is_a?(Symbol)
108
- input = input.to_i if input.is_a?(String)
109
-
110
- outputs = [outputs] unless outputs.is_a?(Array)
111
- command = ''
112
- outputs.each do |output|
113
- command += "#{input}*#{output}$"
114
- end
115
- send(command)
116
- end
117
- end
118
-
119
- def mute_video(outputs)
120
- outputs = [outputs] unless outputs.is_a?(Array)
121
- command = ''
122
- outputs.each do |output|
123
- command += "#{output}*1B"
124
- end
125
- send(command)
126
- end
127
-
128
- def unmute_video(outputs)
129
- outputs = [outputs] unless outputs.is_a?(Array)
130
- command = ''
131
- outputs.each do |output|
132
- command += "#{output}*0B"
133
- end
134
- send(command)
135
- end
136
-
137
- def mute_audio(outputs)
138
- outputs = [outputs] unless outputs.is_a?(Array)
139
- command = ''
140
- outputs.each do |output|
141
- command += "#{output}*1Z"
142
- end
143
- send(command)
144
- end
145
-
146
- def unmute_audio(outputs)
147
- outputs = [outputs] unless outputs.is_a?(Array)
148
- command = ''
149
- outputs.each do |output|
150
- command += "#{output}*0Z"
151
- end
152
- send(command)
153
- end
154
-
155
- def set_preset(number)
156
- send("#{number},")
157
- end
158
-
159
- def recall_preset(number)
160
- send("#{number}.")
161
- end
162
-
163
-
164
- #def response_delimiter
165
- # [0x0D, 0x0A] # Used to interpret the end of a message
166
- #end
167
-
168
-
169
- #
170
- # Sends copyright information
171
- # Then sends password prompt
172
- #
173
- def received(data, resolve, command)
174
- logger.debug "Extron Matrix sent #{data}"
175
-
176
- if command.nil? && data =~ /Copyright/i
177
- pass = setting(:password)
178
- if pass.nil?
179
- device_ready
180
- else
181
- do_send(pass) # Password set
182
- end
183
- elsif data =~ /Login/i
184
- device_ready
185
- elsif command.present? && command[:command] == :information
186
- data = data.split(' ')
187
- video = data[0][1..-1].split('X')
188
- self[:video_inputs] = video[0].to_i
189
- self[:video_outputs] = video[1].to_i
190
-
191
- audio = data[1][1..-1].split('X')
192
- self[:audio_inputs] = audio[0].to_i
193
- self[:audio_outputs] = audio[1].to_i
194
- else
195
- case data[0..1].to_sym
196
- when :Am # Audio mute
197
- data = data[3..-1].split('*')
198
- self["audio#{data[0].to_i}_muted"] = data[1] == '1'
199
- when :Vm # Video mute
200
- data = data[3..-1].split('*')
201
- self["video#{data[0].to_i}_muted"] = data[1] == '1'
202
- when :In # Input to all outputs
203
- data = data[2..-1].split(' ')
204
- input = data[0].to_i
205
- if data[1] =~ /(All|RGB|Vid)/
206
- for i in 1..self[:video_outputs]
207
- self["video#{i}"] = input
208
- end
209
- end
210
- if data[1] =~ /(All|Aud)/
211
- for i in 1..self[:audio_outputs]
212
- self["audio#{i}"] = input
213
- end
214
- end
215
- when :Ou # Output x to input y
216
- data = data[3..-1].split(' ')
217
- output = data[0].to_i
218
- input = data[1][2..-1].to_i
219
- if data[2] =~ /(All|RGB|Vid)/
220
- self["video#{output}"] = input
221
- end
222
- if data[2] =~ /(All|Aud)/
223
- self["audio#{output}"] = input
224
- end
225
- else
226
- if data == 'E22' # Busy! We should retry this one
227
- command[:delay_on_receive] = 1 unless command.nil?
228
- return :failed
229
- end
230
- end
231
- end
232
-
233
- return :success
234
- end
235
-
236
-
237
- private
238
-
239
-
240
- def device_ready
241
- send("I", :wait => true, :command => :information)
242
- do_send("\e3CV", :wait => true) # Verbose mode and tagged responses
243
- end
244
-
245
- def do_send(data, options = {})
246
- send(data << 0x0D, options)
247
- end
39
+ def on_load
40
+ #
41
+ # Setup constants
42
+ #
43
+ defaults({
44
+ :wait => false
45
+ })
46
+ config({
47
+ :clear_queue_on_disconnect => true # Clear the queue as we may need to send login
48
+ })
49
+ end
50
+
51
+ def connected
52
+ @polling_timer = schedule.every('2m') do
53
+ logger.debug "-- Extron Maintaining Connection"
54
+ send('Q', :priority => 0) # Low priority poll to maintain connection
55
+ end
56
+ end
57
+
58
+ def disconnected
59
+ #
60
+ # Disconnected may be called without calling connected
61
+ # Hence the check if timer is nil here
62
+ #
63
+ @polling_timer.cancel unless @polling_timer.nil?
64
+ @polling_timer = nil
65
+ end
66
+
67
+
68
+ def direct(string)
69
+ send(string, :wait => false)
70
+ end
71
+
72
+
73
+ #
74
+ # No need to wait as commands can be chained
75
+ #
76
+ def switch(map)
77
+ map.each do |input, outputs|
78
+ input = input.to_s if input.is_a?(Symbol)
79
+ input = input.to_i if input.is_a?(String)
80
+
81
+ outputs = [outputs] unless outputs.is_a?(Array)
82
+ command = ''
83
+ outputs.each do |output|
84
+ command += "#{input}*#{output}!"
85
+ end
86
+ send(command)
87
+ end
88
+ end
89
+
90
+ def switch_video(map)
91
+ map.each do |input, outputs|
92
+ input = input.to_s if input.is_a?(Symbol)
93
+ input = input.to_i if input.is_a?(String)
94
+
95
+
96
+ outputs = [outputs] unless outputs.is_a?(Array)
97
+ command = ''
98
+ outputs.each do |output|
99
+ command += "#{input}*#{output}%"
100
+ end
101
+ send(command)
102
+ end
103
+ end
104
+
105
+ def switch_audio(map)
106
+ map.each do |input, outputs|
107
+ input = input.to_s if input.is_a?(Symbol)
108
+ input = input.to_i if input.is_a?(String)
109
+
110
+ outputs = [outputs] unless outputs.is_a?(Array)
111
+ command = ''
112
+ outputs.each do |output|
113
+ command += "#{input}*#{output}$"
114
+ end
115
+ send(command)
116
+ end
117
+ end
118
+
119
+ def mute_video(outputs)
120
+ outputs = [outputs] unless outputs.is_a?(Array)
121
+ command = ''
122
+ outputs.each do |output|
123
+ command += "#{output}*1B"
124
+ end
125
+ send(command)
126
+ end
127
+
128
+ def unmute_video(outputs)
129
+ outputs = [outputs] unless outputs.is_a?(Array)
130
+ command = ''
131
+ outputs.each do |output|
132
+ command += "#{output}*0B"
133
+ end
134
+ send(command)
135
+ end
136
+
137
+ def mute_audio(outputs)
138
+ outputs = [outputs] unless outputs.is_a?(Array)
139
+ command = ''
140
+ outputs.each do |output|
141
+ command += "#{output}*1Z"
142
+ end
143
+ send(command)
144
+ end
145
+
146
+ def unmute_audio(outputs)
147
+ outputs = [outputs] unless outputs.is_a?(Array)
148
+ command = ''
149
+ outputs.each do |output|
150
+ command += "#{output}*0Z"
151
+ end
152
+ send(command)
153
+ end
154
+
155
+ def set_preset(number)
156
+ send("#{number},")
157
+ end
158
+
159
+ def recall_preset(number)
160
+ send("#{number}.")
161
+ end
162
+
163
+
164
+ #def response_delimiter
165
+ # [0x0D, 0x0A] # Used to interpret the end of a message
166
+ #end
167
+
168
+
169
+ #
170
+ # Sends copyright information
171
+ # Then sends password prompt
172
+ #
173
+ def received(data, resolve, command)
174
+ logger.debug "Extron Matrix sent #{data}"
175
+
176
+ if command.nil? && data =~ /Copyright/i
177
+ pass = setting(:password)
178
+ if pass.nil?
179
+ device_ready
180
+ else
181
+ do_send(pass) # Password set
182
+ end
183
+ elsif data =~ /Login/i
184
+ device_ready
185
+ elsif command.present? && command[:command] == :information
186
+ data = data.split(' ')
187
+ video = data[0][1..-1].split('X')
188
+ self[:video_inputs] = video[0].to_i
189
+ self[:video_outputs] = video[1].to_i
190
+
191
+ audio = data[1][1..-1].split('X')
192
+ self[:audio_inputs] = audio[0].to_i
193
+ self[:audio_outputs] = audio[1].to_i
194
+ else
195
+ case data[0..1].to_sym
196
+ when :Am # Audio mute
197
+ data = data[3..-1].split('*')
198
+ self["audio#{data[0].to_i}_muted"] = data[1] == '1'
199
+ when :Vm # Video mute
200
+ data = data[3..-1].split('*')
201
+ self["video#{data[0].to_i}_muted"] = data[1] == '1'
202
+ when :In # Input to all outputs
203
+ data = data[2..-1].split(' ')
204
+ input = data[0].to_i
205
+ if data[1] =~ /(All|RGB|Vid)/
206
+ for i in 1..self[:video_outputs]
207
+ self["video#{i}"] = input
208
+ end
209
+ end
210
+ if data[1] =~ /(All|Aud)/
211
+ for i in 1..self[:audio_outputs]
212
+ self["audio#{i}"] = input
213
+ end
214
+ end
215
+ when :Ou # Output x to input y
216
+ data = data[3..-1].split(' ')
217
+ output = data[0].to_i
218
+ input = data[1][2..-1].to_i
219
+ if data[2] =~ /(All|RGB|Vid)/
220
+ self["video#{output}"] = input
221
+ end
222
+ if data[2] =~ /(All|Aud)/
223
+ self["audio#{output}"] = input
224
+ end
225
+ else
226
+ if data == 'E22' # Busy! We should retry this one
227
+ command[:delay_on_receive] = 1 unless command.nil?
228
+ return :failed
229
+ end
230
+ end
231
+ end
232
+
233
+ return :success
234
+ end
235
+
236
+
237
+ private
238
+
239
+
240
+ def device_ready
241
+ send("I", :wait => true, :command => :information)
242
+ do_send("\e3CV", :wait => true) # Verbose mode and tagged responses
243
+ end
244
+
245
+ def do_send(data, options = {})
246
+ send(data << 0x0D, options)
247
+ end
248
248
  end
249
249
 
@@ -63,7 +63,9 @@ class GlobalCache::Gc100
63
63
  def relay_status?(index, &block)
64
64
  if index < self[:num_relays]
65
65
  connector = self[:config][:relay][index]
66
- do_send("getstate,#{connector}", {:emit => {"relay#{index}".to_sym => block}})
66
+ options = {}
67
+ options[:emit] = block if block_given?
68
+ do_send("getstate,#{connector}", options)
67
69
  else
68
70
  logger.warn "Attempted to check IO on GlobalCache that does not exist: #{index}"
69
71
  end
@@ -72,7 +74,9 @@ class GlobalCache::Gc100
72
74
  def io_status?(index, &block)
73
75
  if index < self[:num_ir]
74
76
  connector = self[:config][:ir][index]
75
- do_send("getstate,#{connector}", {:emit => {"ir#{index}".to_sym => block}})
77
+ options = {}
78
+ options[:emit] = block if block_given?
79
+ do_send("getstate,#{connector}", options)
76
80
  else
77
81
  logger.warn "Attempted to check IO on GlobalCache that does not exist: #{index}"
78
82
  end
@@ -24,220 +24,220 @@ module Kramer::Switcher; end
24
24
  #
25
25
 
26
26
  class Kramer::Switcher::Protocol3000
27
- include ::Orchestrator::Constants
27
+ include ::Orchestrator::Constants
28
28
  include ::Orchestrator::Transcoder
29
-
30
- def on_load
31
- config({
29
+
30
+ def on_load
31
+ config({
32
32
  tokenize: true,
33
33
  delimiter: "\x0D\x0A",
34
34
  encoding: "ASCII-8BIT"
35
35
  })
36
36
 
37
37
  on_update
38
- end
39
-
40
- def on_update
41
- @device_id = setting(:kramer_id)
42
- @destination = "#{@device_id}@" if @device_id
43
-
44
- @login_level = setting(:kramer_login)
45
- @password = setting(:kramer_password) if @login_level
46
- end
47
-
48
- def connected
49
- #
50
- # Get current state of the switcher
51
- #
52
- protocol_handshake
53
- login
54
- get_machine_info
55
-
56
- @polling_timer = schedule.every('2m') do
57
- logger.debug "-- Kramer Maintaining Connection"
58
- do_send('MODEL?', {:priority => 0}) # Low priority poll to maintain connection
59
- end
60
- end
61
-
62
- def disconnected
63
- @polling_timer.cancel unless @polling_timer.nil?
64
- @polling_timer = nil
65
- end
66
-
67
-
68
- #
69
- # Starting at input 1, input 0 == disconnect
70
- #
71
- def switch(map, out = nil)
72
- map = {map => out} if out
73
- do_send(CMDS[:switch], build_switch_data(map))
74
- end
75
-
76
-
77
- def switch_video(map, out = nil)
78
- map = {map => out} if out
79
- do_send(CMDS[:switch_video], build_switch_data(map))
80
- end
81
-
82
-
83
- def switch_audio(map, out = nil)
84
- map = {map => out} if out
85
- do_send(CMDS[:switch_audio], build_switch_data(map))
86
- end
87
-
88
-
89
- def mute_video(out, state = true)
90
- data = is_affirmative?(state) ? 1 : 0
91
- do_send(CMDS[:video_mute], out, data)
92
- end
93
-
94
- def mute_audio(out, state = true)
95
- data = is_affirmative?(state) ? 1 : 0
96
- do_send(CMDS[:audio_mute], out, data)
97
- end
98
-
99
- def unmute_video(out)
100
- mute_video out, false
101
- end
102
-
103
- def unmute_audio(out)
104
- mute_audio out, false
105
- end
106
-
107
-
108
- def received(data, resolve, command)
109
- logger.debug "Kramer sent #{data}"
110
-
111
- # Extract and check the machine number if we've defined it
112
- components = data.split('@')
113
- if components.length > 1
114
- machine = components[0]
115
- if @device_id && machine != @device_id
116
- return :ignore
117
- end
118
- end
119
-
120
- data = components[-1].strip
121
- components = data.split(/\s+|,/)
122
-
123
- cmd = components[0]
124
- args = components[1..-1]
125
-
126
- if cmd == 'OK'
127
- return :success
128
- elsif cmd[0..2] == 'ERR' || args[0][0..2] == 'ERR'
129
- if cmd[0..2] == 'ERR'
130
- error = cmd[3..-1]
131
- errfor = nil
132
- else
133
- error = args[0][3..-1]
134
- errfor = " on #{cmd}"
135
- end
136
- logger.error "Kramer command error #{error}#{errfor}"
137
- self[:last_error] = error
138
- return :abort
139
- end
140
-
141
- case CMDS[cmd.to_sym]
142
- when :info
143
- self[:video_inputs] = args[1].to_i
144
- self[:video_outputs] = args[3].to_i
145
- when :route
146
- inout = args[0].split(',')
147
- layer = inout[0].to_i
148
- dest = inout[1].to_i
149
- src = inout[2].to_i
150
- self[:"#{LAYERS[layer]}#{dest}"] = src
151
- when :switch, :switch_audio, :switch_video
152
- # return string like "in>out,in>out,in>out"
153
-
154
- type = :av
155
- type = :audio if CMDS[cmd] == :switch_audio
156
- type = :video if CMDS[cmd] == :switch_video
157
-
158
- mappings = args[0].split(',')
159
- mappings.each do |map|
160
- inout = map.split('>')
161
- self[:"#{type}#{inout[1]}"] = inout[0].to_i
162
- end
163
- when :audio_mute
164
- output, mute = args[0].split(',')
165
- self[:"audio#{output}_muted"] = mute == '1'
166
- when :video_mute
167
- output, mute = args[0].split(',')
168
- self[:"video#{output}_muted"] = mute == '1'
169
- end
170
-
171
- return :success
172
- end
173
-
174
-
175
- CMDS = {
176
- info: :"INFO-IO?",
177
- login: :"LOGIN",
178
- route: :"ROUTE",
179
- switch: :"AV",
180
- switch_audio: :"AUD",
181
- switch_video: :"VID",
182
- audio_mute: :"MUTE",
183
- video_mute: :"VMUTE"
184
- }
185
- CMDS.merge!(CMDS.invert)
186
-
187
- LAYERS = {
188
- 1 => :video,
189
- 2 => :audio,
190
- 2 => :data
191
- }
192
-
193
-
194
- private
195
-
196
-
197
- def build_switch_data(map)
198
- data = ''
199
-
200
- map.each do |input, outputs|
201
- outputs = [outputs] unless outputs.class == Array
202
- input = input.to_s if input.class == Symbol
203
- input = input.to_i if input.class == String
204
- outputs.each do |output|
205
- data << "#{input}>#{output},"
206
- end
207
- end
208
-
209
- data.chop
210
- end
211
-
212
-
213
- def protocol_handshake
214
- do_send('', {priority: 99})
215
- end
216
-
217
- def login
218
- if @login_level
219
- do_send(CMDS[:login], @password, {priority: 99})
220
- end
221
- end
222
-
223
- def get_machine_info
224
- do_send(CMDS[:info], {priority: 99})
225
- end
226
-
227
-
228
- def do_send(command, *args)
229
- options = {}
230
- if args[-1].is_a? Hash
231
- options = args.pop
232
- end
233
-
234
- cmd = "##{@destination}#{command}"
235
-
236
- if args.length > 0
237
- cmd << " #{args.join(',')}"
238
- end
239
- cmd << "\r"
240
-
241
- send(cmd, options)
242
- end
38
+ end
39
+
40
+ def on_update
41
+ @device_id = setting(:kramer_id)
42
+ @destination = "#{@device_id}@" if @device_id
43
+
44
+ @login_level = setting(:kramer_login)
45
+ @password = setting(:kramer_password) if @login_level
46
+ end
47
+
48
+ def connected
49
+ #
50
+ # Get current state of the switcher
51
+ #
52
+ protocol_handshake
53
+ login
54
+ get_machine_info
55
+
56
+ @polling_timer = schedule.every('2m') do
57
+ logger.debug "-- Kramer Maintaining Connection"
58
+ do_send('MODEL?', {:priority => 0}) # Low priority poll to maintain connection
59
+ end
60
+ end
61
+
62
+ def disconnected
63
+ @polling_timer.cancel unless @polling_timer.nil?
64
+ @polling_timer = nil
65
+ end
66
+
67
+
68
+ #
69
+ # Starting at input 1, input 0 == disconnect
70
+ #
71
+ def switch(map, out = nil)
72
+ map = {map => out} if out
73
+ do_send(CMDS[:switch], build_switch_data(map))
74
+ end
75
+
76
+
77
+ def switch_video(map, out = nil)
78
+ map = {map => out} if out
79
+ do_send(CMDS[:switch_video], build_switch_data(map))
80
+ end
81
+
82
+
83
+ def switch_audio(map, out = nil)
84
+ map = {map => out} if out
85
+ do_send(CMDS[:switch_audio], build_switch_data(map))
86
+ end
87
+
88
+
89
+ def mute_video(out, state = true)
90
+ data = is_affirmative?(state) ? 1 : 0
91
+ do_send(CMDS[:video_mute], out, data)
92
+ end
93
+
94
+ def mute_audio(out, state = true)
95
+ data = is_affirmative?(state) ? 1 : 0
96
+ do_send(CMDS[:audio_mute], out, data)
97
+ end
98
+
99
+ def unmute_video(out)
100
+ mute_video out, false
101
+ end
102
+
103
+ def unmute_audio(out)
104
+ mute_audio out, false
105
+ end
106
+
107
+
108
+ def received(data, resolve, command)
109
+ logger.debug "Kramer sent #{data}"
110
+
111
+ # Extract and check the machine number if we've defined it
112
+ components = data.split('@')
113
+ if components.length > 1
114
+ machine = components[0]
115
+ if @device_id && machine != @device_id
116
+ return :ignore
117
+ end
118
+ end
119
+
120
+ data = components[-1].strip
121
+ components = data.split(/\s+|,/)
122
+
123
+ cmd = components[0]
124
+ args = components[1..-1]
125
+
126
+ if cmd == 'OK'
127
+ return :success
128
+ elsif cmd[0..2] == 'ERR' || args[0][0..2] == 'ERR'
129
+ if cmd[0..2] == 'ERR'
130
+ error = cmd[3..-1]
131
+ errfor = nil
132
+ else
133
+ error = args[0][3..-1]
134
+ errfor = " on #{cmd}"
135
+ end
136
+ logger.error "Kramer command error #{error}#{errfor}"
137
+ self[:last_error] = error
138
+ return :abort
139
+ end
140
+
141
+ case CMDS[cmd.to_sym]
142
+ when :info
143
+ self[:video_inputs] = args[1].to_i
144
+ self[:video_outputs] = args[3].to_i
145
+ when :route
146
+ inout = args[0].split(',')
147
+ layer = inout[0].to_i
148
+ dest = inout[1].to_i
149
+ src = inout[2].to_i
150
+ self[:"#{LAYERS[layer]}#{dest}"] = src
151
+ when :switch, :switch_audio, :switch_video
152
+ # return string like "in>out,in>out,in>out"
153
+
154
+ type = :av
155
+ type = :audio if CMDS[cmd] == :switch_audio
156
+ type = :video if CMDS[cmd] == :switch_video
157
+
158
+ mappings = args[0].split(',')
159
+ mappings.each do |map|
160
+ inout = map.split('>')
161
+ self[:"#{type}#{inout[1]}"] = inout[0].to_i
162
+ end
163
+ when :audio_mute
164
+ output, mute = args[0].split(',')
165
+ self[:"audio#{output}_muted"] = mute == '1'
166
+ when :video_mute
167
+ output, mute = args[0].split(',')
168
+ self[:"video#{output}_muted"] = mute == '1'
169
+ end
170
+
171
+ return :success
172
+ end
173
+
174
+
175
+ CMDS = {
176
+ info: :"INFO-IO?",
177
+ login: :"LOGIN",
178
+ route: :"ROUTE",
179
+ switch: :"AV",
180
+ switch_audio: :"AUD",
181
+ switch_video: :"VID",
182
+ audio_mute: :"MUTE",
183
+ video_mute: :"VMUTE"
184
+ }
185
+ CMDS.merge!(CMDS.invert)
186
+
187
+ LAYERS = {
188
+ 1 => :video,
189
+ 2 => :audio,
190
+ 2 => :data
191
+ }
192
+
193
+
194
+ private
195
+
196
+
197
+ def build_switch_data(map)
198
+ data = ''
199
+
200
+ map.each do |input, outputs|
201
+ outputs = [outputs] unless outputs.class == Array
202
+ input = input.to_s if input.class == Symbol
203
+ input = input.to_i if input.class == String
204
+ outputs.each do |output|
205
+ data << "#{input}>#{output},"
206
+ end
207
+ end
208
+
209
+ data.chop
210
+ end
211
+
212
+
213
+ def protocol_handshake
214
+ do_send('', {priority: 99})
215
+ end
216
+
217
+ def login
218
+ if @login_level
219
+ do_send(CMDS[:login], @password, {priority: 99})
220
+ end
221
+ end
222
+
223
+ def get_machine_info
224
+ do_send(CMDS[:info], {priority: 99})
225
+ end
226
+
227
+
228
+ def do_send(command, *args)
229
+ options = {}
230
+ if args[-1].is_a? Hash
231
+ options = args.pop
232
+ end
233
+
234
+ cmd = "##{@destination}#{command}"
235
+
236
+ if args.length > 0
237
+ cmd << " #{args.join(',')}"
238
+ end
239
+ cmd << "\r"
240
+
241
+ send(cmd, options)
242
+ end
243
243
  end