aca-device-modules 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f068e2f8fc138bd97e542fd11651670607e3c552
4
- data.tar.gz: cf23a437d8f1f777527920342a759a301bc3c6aa
3
+ metadata.gz: 1b69086f2a1f7cedc0f6ee28a9dba6f771233396
4
+ data.tar.gz: 6080121ffbf65e399205c885be16959f7b7603d7
5
5
  SHA512:
6
- metadata.gz: b24a834e0ed6db515937608d39d21c276d66d644f39acb47281480f96bc2730f9f23f29ba066ff532ca356f72dfffafe250a372d28bad0e31a131d83a13acd1c
7
- data.tar.gz: fde92eeed5925c426fa2ced3d3c8fab4cbf3fe5ddf222f71f1cfdbc5caa739687c5f8e7cca74b50adcb05a6f3e42f6480ce0f062772726ea2f4a39b6d89dedb5
6
+ metadata.gz: 38add061a9db39ec6ed34d2cfb9bba11c2d7c395f0498c1f74a2089c3a606cfafc4b0e4df7f9e62b460567dbb03108cc66507b4d573fcf8cbdd654c5b10d00ee
7
+ data.tar.gz: 7a5c4ecc2012e09c552bb0a48f6af767d33a1e61c47a7a850463653c4d972695e2de8ba2f7e7a6fde05d59a87d65d4094684e0a0f0b02c1ab335e841987e08a9
@@ -1,3 +1,3 @@
1
1
  module AcaDeviceModules
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -51,38 +51,59 @@ class Biamp::Nexia
51
51
  #
52
52
  do_send('RECALL', 0, 'PRESET', number)
53
53
  end
54
+
55
+ # {1 => [2,3,5], 2 => [2,3,6]}, true
56
+ # Supports Matrix and Automixers
57
+ def mixer(id, inouts, mute = false)
58
+ value = is_affirmative?(mute) ?
59
+
60
+ if inouts.is_a? Hash
61
+ inouts.each_key do |input|
62
+ outputs = inouts[input]
63
+ outs = outputs.is_a?(Array) ? outputs : [outputs]
64
+
65
+ outs.each do |output|
66
+ do_send('SETD', self[:device_id], 'MMMUTEXP', id, input, output, value)
67
+ end
68
+ end
69
+ else # assume array (auto-mixer)
70
+ inouts.each do |input|
71
+ do_send('SETD', self[:device_id], 'AMMUTEXP', id, input, value)
72
+ end
73
+ end
74
+ end
54
75
 
55
- def fader(fader_id, level)
76
+ def fader(fader_id, level, index = 1)
56
77
  # value range: -100 ~ 12
57
- do_send('SETD', self[:device_id], 'FDRLVL', fader_id, 1, level)
78
+ do_send('SETD', self[:device_id], 'FDRLVL', fader_id, index, level)
58
79
  end
59
80
 
60
- def mute(fader_id, val = true)
81
+ def mute(fader_id, val = true, index = 1)
61
82
  actual = val ? 1 : 0
62
- do_send('SETD', self[:device_id], 'FDRMUTE', fader_id, 1, actual)
83
+ do_send('SETD', self[:device_id], 'FDRMUTE', fader_id, index, actual)
63
84
  end
64
85
 
65
- def unmute(fader_id)
66
- do_send('SETD', self[:device_id], 'FDRMUTE', fader_id, 1, 0)
86
+ def unmute(fader_id, index = 1)
87
+ mute(fader_id, false, index)
67
88
  end
68
89
 
69
- def query_fader(fader_id)
70
- send("GET #{self[:device_id]} FDRLVL #{fader_id} 1 \n") do |data|
71
- if data == "-ERR"
90
+ def query_fader(fader_id, index = 1)
91
+ send("GET #{self[:device_id]} FDRLVL #{fader_id} #{index} \n") do |data|
92
+ if data.start_with?('-ERR')
72
93
  :abort
73
94
  else
74
- self[:"fader_#{fader_id}"] = data.to_i
95
+ self[:"fader#{fader_id}_#{index}"] = data.to_i
75
96
  :success
76
97
  end
77
98
  end
78
99
  end
79
100
 
80
- def query_mute(fader_id)
81
- send("GET #{self[:device_id]} FDRMUTE #{fader_id} 1 \n") do |data|
82
- if data == "-ERR"
101
+ def query_mute(fader_id, index = 1)
102
+ send("GET #{self[:device_id]} FDRMUTE #{fader_id} #{index} \n") do |data|
103
+ if data.start_with?('-ERR')
83
104
  :abort
84
105
  else
85
- self[:"fader_#{fader_id}_mute"] = data.to_i == 1
106
+ self[:"fader#{fader_id}_#{index}_mute"] = data.to_i == 1
86
107
  :success
87
108
  end
88
109
  end
@@ -90,23 +111,21 @@ class Biamp::Nexia
90
111
 
91
112
 
92
113
  def received(data, resolve, command)
93
- data = data.split(' ')
94
-
95
- if data.length == 1
96
- if data[-1] == "-ERR"
97
- logger.debug "Nexia Invalid Command sent #{command[:data]}" if !!command
98
- return :abort
99
- end
100
- return :success # data[-1] == "+OK" || data == "" # Echo off
114
+ if data.start_with?('-ERR')
115
+ logger.debug "Nexia returned #{data} for #{command[:data]}" if command
116
+ return :abort
101
117
  end
102
118
 
119
+ #--> "#SETD 0 FDRLVL 29 1 0.000000 +OK"
120
+ data = data.split(' ')
103
121
  unless data[2].nil?
104
122
  case data[2].to_sym
105
- when :FDRLVL
106
- self[:"fader_#{data[3]}"] = data[-2].to_i
123
+ when :FDRLVL, :VL
124
+ self[:"fader#{data[3]}_#{data[4]}"] = data[5].to_i
107
125
  when :FDRMUTE
108
- self[:"fader_#{data[3]}_mute"] = data[-2] == "1"
126
+ self[:"fader#{data[3]}_#{data[4]}_mute"] = data[5] == "1"
109
127
  when :DEVID
128
+ # "#GETD 0 DEVID 1 "
110
129
  self[:device_id] = data[-2].to_i
111
130
  end
112
131
  end
@@ -120,7 +139,7 @@ class Biamp::Nexia
120
139
 
121
140
 
122
141
  def do_send(*args)
123
- send("#{args.join(' ')}\n")
142
+ send("#{args.join(' ')} \n")
124
143
  end
125
144
  end
126
145
 
@@ -15,12 +15,15 @@ class Bss::Blu100
15
15
  delimiter: "\x03",
16
16
  indicator: "\x02"
17
17
  })
18
+
19
+ on_update
18
20
  end
19
21
 
20
22
  def on_unload
21
23
  end
22
24
 
23
25
  def on_update
26
+ @type_lookup ||= {}
24
27
  end
25
28
 
26
29
  def connected
@@ -64,69 +67,82 @@ class Bss::Blu100
64
67
  #
65
68
  # Level controls
66
69
  #
67
- def fader(fader, percent)
70
+ def fader(fader, percent, index = 0)
71
+ index_data = id_to_array(index, :gain)
72
+
68
73
  percent = percent.to_i
69
74
  percent = 6553600 if percent > 6553600
70
75
  percent = 0 if percent < 0
71
76
 
72
77
  percent = number_to_data(percent)
73
78
 
74
- do_send([OPERATION_CODE[:set_percent]] + NODE + VIRTUAL + number_to_object(fader.to_i) + CONTROLS[:gain] + percent)
79
+ do_send([OPERATION_CODE[:set_percent]] + NODE + VIRTUAL + number_to_object(fader.to_i) + index_data + percent)
75
80
  subscribe_percent(fader)
76
81
  end
77
82
 
78
- def mute(fader)
79
- do_send([OPERATION_CODE[:set_state]] + NODE + VIRTUAL + number_to_object(fader.to_i) + CONTROLS[:mute] + number_to_data(1))
83
+ def mute(fader, val = true, index = 1)
84
+ actual = val ? 1 : 0
85
+
86
+ index_data = id_to_array(index, :mute)
87
+
88
+ do_send([OPERATION_CODE[:set_state]] + NODE + VIRTUAL + number_to_object(fader.to_i) + index_data + number_to_data(actual))
80
89
  subscribe_state(fader)
81
90
  end
82
91
 
83
- def unmute(fader)
84
- do_send([OPERATION_CODE[:set_state]] + NODE + VIRTUAL + number_to_object(fader.to_i) + CONTROLS[:mute] + number_to_data(0))
85
- subscribe_state(fader)
92
+ def unmute(fader, index = 1)
93
+ mute(fader, false, index)
86
94
  end
87
95
 
88
96
 
89
- def query_fader(fader_id)
90
- subscribe_percent(fader_id)
97
+ def query_fader(fader_id, index = 0)
98
+ subscribe_percent(fader_id, index)
91
99
  end
92
100
 
93
- def query_mute(fader_id)
94
- subscribe_state(fader_id)
101
+ def query_mute(fader_id, index = 1)
102
+ subscribe_state(fader_id, index)
95
103
  end
96
104
 
97
105
 
98
106
  #
99
107
  # Percent controls for relative values
100
108
  #
101
- def subscribe_percent(fader, rate = 0, control = CONTROLS[:gain]) # rate must be 0 for non meter controls
109
+ def subscribe_percent(fader, index = 0, rate = 0) # rate must be 0 for non meter controls
110
+ index_data = id_to_array(index, :gain)
111
+
102
112
  fader = number_to_object(fader.to_i)
103
113
  rate = number_to_data(rate.to_i)
104
114
 
105
- do_send([OPERATION_CODE[:subscribe_percent]] + NODE + VIRTUAL + fader + control + rate)
115
+ do_send([OPERATION_CODE[:subscribe_percent]] + NODE + VIRTUAL + fader + index_data + rate)
106
116
  end
107
117
 
108
- def unsubscribe_percent(fader, control = CONTROLS[:gain]) # rate must be 0 for non meter controls
118
+ def unsubscribe_percent(fader, index = 0) # rate must be 0 for non meter controls
119
+ index_data = id_to_array(index, :gain)
120
+
109
121
  fader = number_to_object(fader.to_i)
110
122
  rate = number_to_data(0)
111
123
 
112
- do_send([OPERATION_CODE[:unsubscribe_percent]] + NODE + VIRTUAL + fader + control + rate)
124
+ do_send([OPERATION_CODE[:unsubscribe_percent]] + NODE + VIRTUAL + fader + index_data + rate)
113
125
  end
114
126
 
115
127
  #
116
128
  # State controls are for discrete values
117
129
  #
118
- def subscribe_state(fader, rate = 0, control = CONTROLS[:mute]) # 1000 == every second
130
+ def subscribe_state(fader, index = 1, rate = 0) # 1000 == every second
131
+ index_data = id_to_array(index, :mute)
132
+
119
133
  fader = number_to_object(fader.to_i)
120
134
  rate = number_to_data(rate.to_i)
121
135
 
122
- do_send([OPERATION_CODE[:subscribe_state]] + NODE + VIRTUAL + fader + control + rate)
136
+ do_send([OPERATION_CODE[:subscribe_state]] + NODE + VIRTUAL + fader + index_data + rate)
123
137
  end
124
138
 
125
- def unsubscribe_state(fader, control = CONTROLS[:mute]) # 1000 == every second
139
+ def unsubscribe_state(fader, index = 1) # 1000 == every second
140
+ index_data = id_to_array(index, :mute)
141
+
126
142
  fader = number_to_object(fader.to_i)
127
143
  rate = number_to_data(0)
128
144
 
129
- do_send([OPERATION_CODE[:unsubscribe_state]] + NODE + VIRTUAL + fader + control + rate)
145
+ do_send([OPERATION_CODE[:unsubscribe_state]] + NODE + VIRTUAL + fader + index_data + rate)
130
146
  end
131
147
 
132
148
 
@@ -170,10 +186,11 @@ class Bss::Blu100
170
186
  case OPERATION_CODE[type]
171
187
  when :set_state # This is the mute response
172
188
  obj = byte_to_hex(array_to_str(obj)).to_i(16)
173
- if CONTROLS[cntrl] == :mute
174
- self[:"fader_#{obj}_mute"] = data == 1
189
+ index = byte_to_hex(array_to_str(cntrl)).to_i(16)
190
+ if @type_lookup[cntrl] == :mute
191
+ self[:"fader#{obj}_#{index}_mute"] = data == 1
175
192
  else
176
- self[:"fader_#{obj}"] = data
193
+ self[:"fader#{obj}_#{index}"] = data
177
194
  end
178
195
  when :subscribe_state
179
196
  when :unsubscribe_state
@@ -181,7 +198,8 @@ class Bss::Blu100
181
198
  when :param_preset
182
199
  when :set_percent # This is the fader response
183
200
  obj = byte_to_hex(array_to_str(obj)).to_i(16)
184
- self[:"fader_#{obj}"] = data
201
+ index = byte_to_hex(array_to_str(cntrl)).to_i(16)
202
+ self[:"fader#{obj}_#{index}"] = data
185
203
  when :subscribe_percent
186
204
  when :unsubscribe_percent
187
205
  when :set_relative_percent
@@ -198,12 +216,18 @@ class Bss::Blu100
198
216
  protected
199
217
 
200
218
 
219
+ def id_to_array(id, type)
220
+ data = str_to_array(hex_to_byte(id.to_s(16).rjust(4, '0')))
221
+ @type_lookup[data] = type
222
+ data
223
+ end
224
+
201
225
  def number_to_data(num)
202
- str_to_array(hex_to_byte(num.to_s(16).upcase.rjust(8, '0')))
226
+ str_to_array(hex_to_byte(num.to_s(16).rjust(8, '0')))
203
227
  end
204
228
 
205
229
  def number_to_object(num)
206
- str_to_array(hex_to_byte(num.to_s(16).upcase.rjust(6, '0')))
230
+ str_to_array(hex_to_byte(num.to_s(16).rjust(6, '0')))
207
231
  end
208
232
 
209
233
 
@@ -211,12 +235,6 @@ class Bss::Blu100
211
235
  NODE = [0,0] # node we are connected to
212
236
  VIRTUAL = [3] # virtual device is always 3 for audio devices
213
237
 
214
- CONTROLS = {
215
- :gain => [0,0],
216
- :mute => [0,1]
217
- }
218
- CONTROLS.merge!(CONTROLS.invert)
219
-
220
238
 
221
239
  def check_checksum(data)
222
240
  #
@@ -0,0 +1,183 @@
1
+ module Chiyu; end
2
+
3
+
4
+ # Normal state for inputs == open
5
+ # IO Operations mode TCP server
6
+ # Periodically every second
7
+
8
+
9
+ # Default port: 50001
10
+ class Chiyu::Cyt
11
+ include ::Orchestrator::Constants
12
+ include ::Orchestrator::Transcoder
13
+
14
+
15
+ def on_load
16
+ @outputs = Array.new(32, 1)
17
+
18
+ config({
19
+ tokenize: true,
20
+ delimiter: "\xF0\xF0",
21
+ min_length: 2, # this will ignore the CRC check byte
22
+ encoding: "ASCII-8BIT"
23
+ })
24
+
25
+ defaults({
26
+ delay_on_receive: 500
27
+ })
28
+ end
29
+
30
+ def on_update
31
+ end
32
+
33
+ # No keep alive required as the device polls us
34
+ def connected
35
+ do_send(:state)
36
+ do_send(:auto_report)
37
+ end
38
+
39
+ def disconnected
40
+ end
41
+
42
+
43
+
44
+ COMMANDS = {
45
+ state: [0x00, 0x01],
46
+ trigger: [0x00, 0x03],
47
+ auto_report: [0x00, 0x05],
48
+ ack_keepalive: [0x00, 0x08]
49
+ }
50
+
51
+ RESPONSES = {
52
+ [0x00, 0x02] => :state,
53
+ [0x00, 0x04] => :trigger,
54
+ [0x00, 0x06] => :emailed,
55
+ [0x00, 0x10] => :report,
56
+ [0x00, 0x07] => :keepalive,
57
+ [0x00, 0x08] => :keepalive
58
+ }
59
+
60
+ ERRORS = {
61
+ 0xFC => 'Flag error, incorrect Start Flag or End Flag'.freeze,
62
+ 0xFD => 'Length error, the length of command packet is invalid'.freeze,
63
+ 0xFE => 'CRC error, incorrect CRC value'.freeze,
64
+ 0xFF => 'Command error, no such command'.freeze
65
+ }
66
+
67
+
68
+
69
+ def relay(index, state, time = nil)
70
+ index = index - 1
71
+ return if index >= 30 || index < 0
72
+
73
+ @outputs[index] = is_affirmative?(state) ? 0 : 1
74
+ opts = {
75
+ data1: @outputs
76
+ }
77
+
78
+ if time
79
+ time = time.to_i
80
+ times = Array.new(32, 0)
81
+ times[index] = time
82
+ opts[:data2] = times
83
+ opts[:delay_on_receive] = time * 1000 + 1200
84
+ end
85
+
86
+ do_send(:trigger, opts)
87
+ self[:"relay#{index + 1}"] = true
88
+ end
89
+
90
+
91
+
92
+ def received(data_str, resolve, command)
93
+ data = str_to_array(data_str)
94
+ logger.debug "Chiyu sent #{data}"
95
+
96
+ cmd = data[0..1]
97
+ data1 = data[2..33]
98
+ data2 = data[34..65]
99
+
100
+ if cmd[0] != 0xFF
101
+ case RESPONSES[cmd]
102
+ when :state, :report
103
+ data1.each_index do |index|
104
+ next if index >= 30
105
+ byte = data1[index]
106
+ if byte < 2
107
+ self[:"sensor#{index + 1}"] = byte == 1
108
+ end
109
+ end
110
+
111
+ @outputs = data2
112
+ data2.each_index do |index|
113
+ next if index >= 30
114
+ byte = data2[index]
115
+ if byte < 2
116
+ self[:"relay#{index + 1}"] = byte == 0
117
+ end
118
+ end
119
+ when :keepalive
120
+ do_send(:ack_keepalive)
121
+ end
122
+
123
+ :success
124
+ else
125
+ # Error
126
+ error = ERRORS[cmd[1]]
127
+ self[:last_error] = error
128
+ logger.debug "Chiyu error #{error}"
129
+ :abort
130
+ end
131
+ end
132
+
133
+
134
+
135
+ # Pulse Lifter Logic
136
+ #
137
+ # Automatically creates a callable function for each command
138
+ # http://blog.jayfields.com/2007/10/ruby-defining-class-methods.html
139
+ # http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html
140
+ #
141
+ [:up, :down, :left, :right].each do |helper|
142
+ define_method helper do |*args|
143
+ index = args[0] || setting(helper) || 1
144
+ index = index.to_i
145
+
146
+ relay(index, true, 2)
147
+ relay(index, true, 2)
148
+ end
149
+ end
150
+
151
+
152
+
153
+ protected
154
+
155
+
156
+ def checksum!(command)
157
+ check = 0
158
+ command.each do |byte|
159
+ check = check + byte
160
+ end
161
+ check = (0 - check) & 0xFF
162
+ command << check
163
+ end
164
+
165
+
166
+ FLAG = [0xF0, 0xF0]
167
+ EMPTY = Array.new(32, 0)
168
+
169
+
170
+ def do_send(command, options = {})
171
+ cmd = FLAG + COMMANDS[command]
172
+ cmd += options.delete(:data1) || EMPTY
173
+ cmd += options.delete(:data2) || EMPTY
174
+ cmd += FLAG
175
+ checksum!(cmd)
176
+
177
+ options[:name] = command unless options[:name]
178
+
179
+ send(cmd, options)
180
+ logger.debug "-- CYT, sending: #{command}"
181
+ end
182
+ end
183
+