onkyo_eiscp_ruby 0.0.2 → 2.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a4b06cd590c97b2221cbb2aea133003a16d59c0ad917c48e3cba7ee0758e9c88
4
+ data.tar.gz: a0eae4abe4ec00ea74db045b4218b6e7adc86f4aefa839e9faa53eee0d135598
5
+ SHA512:
6
+ metadata.gz: 7b2274ea6e68eb2405c32aa4db290621a49bddfdb4b8550d76da52013981691c783b9b03088e6fde4f845ab18a5d858a3bf145cf4a7d60e2ae4531bb4fcecfa4
7
+ data.tar.gz: bd9fa98a349f0eee2dfb80f7c46c8f8ae5ba0a624f6563bd43983cc2d9cf531f0a57095f2db0eb5d7b68232b97bdbda25f1585930b858c4177af0c5a3d2a96f0
data/README.md CHANGED
@@ -1,41 +1,225 @@
1
1
  onkyo_eiscp_ruby
2
2
  ================
3
+ [![Gem Version](https://badge.fury.io/rb/onkyo_eiscp_ruby.png)](http://badge.fury.io/rb/onkyo_eiscp_ruby)
4
+ [![GitHub version](https://badge.fury.io/gh/mikerodrigues%2Fonkyo_eiscp_ruby.png)](http://badge.fury.io/gh/mikerodrigues%2Fonkyo_eiscp_ruby)
3
5
 
4
- A Ruby implementation of eISCP for controlling Onkyo receivers.
6
+ *A Ruby implementation of eISCP for controlling Onkyo receivers.*
5
7
 
6
- **This code is still under heavy development and using it might make you sick.**
7
- * Create ISCP messages and eISCP packets
8
- * Automatically discover receiver's in the broadcast domain
9
- * Send/Recieve eISCP messages
10
- * Open a TCP socket to send commands and receive solicited and non-solicited status updates.
11
- * Mock reciever (currently only responds to discovery)
8
+ **This code is not really still under development and using it might still make you sick.**
9
+
10
+ **The python version linked below sees much more activity.**
11
+
12
+ Automatically discover receivers in the broadcast domain
13
+
14
+ Send commands to receivers and parse returned messages
15
+
16
+ Open a TCP socket to receive solicited and non-solicited status updates.
17
+
18
+ Mock reciever (currently only responds to discovery)
19
+
20
+ Human-readable commands
12
21
 
13
22
  **Inspired by https://github.com/miracle2k/onkyo-eiscp
14
23
 
15
- Usage
16
- ________________
24
+ **Protocol information from http://michael.elsdoerfer.name/onkyo/ISCP-V1.21_2011.xls
17
25
 
18
- # require the library
26
+ What's missing?
27
+ ---------------
28
+ * Command validation
19
29
 
20
- require 'eiscp'
30
+ * Parsing of all human readable commands (run the tests to see some commands that aren't parsable in human readable form yet.
21
31
 
32
+ * Reasonable variants for human-readable commands (ex. `main-volume` or`volume
33
+ ` as opposed to `master-volume`)
34
+
35
+ * Model compatability checking
36
+
37
+ * Logging
38
+
39
+ * Exhaustive testing and documentation
40
+
41
+ Using the Library
42
+ -----------------
43
+ * require the library
44
+
45
+ require 'eiscp'
46
+
47
+ * You might want to `include EISCP` if you know you won't pollute your namespace
48
+ with Constants under `EISCP` (`Dictionary`, `Message`, `Parser`, `Receiver`,
49
+ `VERSION`)
50
+
51
+ * You can do most everything through the `Receiver` and `Message` objects. If you
52
+ want to accept user input you will probably want to use the Parser module. Be
53
+ sure to check out the RDocs or dig through the source code. I try to keep it
54
+ well commented/documented, and there's more functionality to the library than
55
+ is shown here:
56
+
57
+ * The `Message` object is pretty self explanatory. `Message.new` is mostly used
58
+ internally, but you're better off using `Parser.parse` to create them. You
59
+ probably will want to interact with `Message` objects to get information:
60
+
61
+ ```ruby
62
+ msg = EISCP::Message.new(command: 'PWR', value: '01')
63
+ msg.zone => 'main'
64
+ msg.command => "PWR"
65
+ msg.value => "01"
66
+ msg.command_name => "system-power"
67
+ msg.command_description => "System Power Command"
68
+ msg.value_name => "on"
69
+ msg.value_description => "sets System On"
70
+ ```
71
+
72
+ * Discover local receivers (returns an `Array` of `Receiver` objects)
73
+
74
+ ```ruby
75
+ EISCP::Receiver.discover
76
+ ```
77
+
78
+ * Create `Receiver` object from first discovered Receiver on the LAN
79
+
80
+ ```ruby
81
+ receiver = EISCP::Receiver.new
82
+ ```
83
+
84
+ * Or create one manually by IP address or hostname
85
+
86
+ ```ruby
87
+ receiver = EISCP::Receiver.new('10.0.0.132')
88
+ ```
89
+
90
+ * When you create a `Receiver` object with a callback block it will
91
+ connect and call your block on each message received.:
92
+
93
+ ```ruby
94
+ receiver = EISCP::Receiver.new do |msg|
95
+ puts msg.command
96
+ puts msg.value
97
+ end
98
+ ```
99
+
100
+ * Receivers created without a block will not connect automatically. You can use
101
+ the `connect` method to create a socket and connect to the receiver.
102
+
103
+ ```ruby
104
+ receiver.connect
105
+ ```
106
+
107
+ * You can also set or change the callback block later. This will kill the
108
+ existing callback thread, recreate the socket if necessary and start
109
+ a new callback thread using the provided block:
110
+
111
+ ```ruby
112
+ receiver.connect do |msg|
113
+ puts "Received: #{msg.command_name}:#{msg.value_name}"
114
+ end
115
+ ```
116
+
117
+ * You can also disconnect, which will close the socket and kill the connection
118
+ thread:
119
+
120
+ ```ruby
121
+ receiver.disconnect
122
+ ```
123
+
124
+ * Get information about the Receiver:
22
125
 
23
- # Discover local receivers
24
- EISCP.discover
25
-
26
-
27
- # Open a TCP connection to monitor solicited updates
28
- eiscp = EISCP.new('10.0.0.1')
29
- eiscp.connect
30
-
31
- # You can also pass a block and operate on received packet strings:
32
- eiscp.connect do |data|
33
- puts EISCPPacket.parse(data).iscp_message
34
- end
35
-
36
- # Turn on the receiver
37
- iscp_message = ISCPMessage.new("PWR", "01")
38
- eiscp_packet = EISCPPacket.new(iscp_message.message)
39
- eiscp.send(eiscp_packet.to_s)
40
-
126
+ ```ruby
127
+ receiver.model => "TX-NR609"
128
+ receiver.host => "10.0.0.111"
129
+ receiver.port => 60128
130
+ receiver.mac_address => "001122334455"
131
+ receiver.area => "DX"
132
+ ```
133
+
134
+ * Receivers now have a `@state` hash that contains a mapping of commands and
135
+ values received. You can use this see the Receiver's last known state without
136
+ querying. Use the `#update_state` method to run every 'QSTN' command in the
137
+ Dictionary and update the state hash, but do note that it will take a few
138
+ seconds to finish:
139
+
140
+ ```ruby
141
+ receiver.update_state
142
+ receiver.state["MVL"] => "22"
143
+ receiver.human_readable_state["master-volume"] => 34
144
+ ```
145
+
146
+
147
+ * You can use `CommandMethods` to easily send a message and return the reply as
148
+ a Message object. Once `Receiver#connect`is called, a method is defined for each command listed in the
149
+ `Dictionary` using the `@command_name` attribute which is 'human readable'.
150
+ You can check the included yaml file or look at the output of
151
+ `EISCP::Dictionary.commands`. Here a few examples:
152
+
153
+ ```ruby
154
+ # Turn on receiver
155
+ receiver.system_power "on"
156
+
157
+ # Query current input source
158
+ receiver.input_selector "query"
159
+
160
+ # Turn the master volume up one level
161
+ receiver.master_volume "level-up"
162
+
163
+ # Set the master volume to 45
164
+ receiver.master_volume "45"
165
+ ```
166
+
167
+ * Parse ISCP and human readable strings:
168
+
169
+ ```ruby
170
+ # Parse various ISCP strings
171
+ iscp_message = EISCP::Parser.parse "PWR01"
172
+ iscp_message = EISCP::Parser.parse "PWR 01"
173
+ iscp_message = EISCP::Parser.parse "!1PWR01"
174
+ iscp_message = EISCP::Parser.parse "!1PWR 01"
175
+
176
+ # Parse human readable,
177
+ EISCP::Parser.parse("main-volume 34")
178
+ ```
179
+
180
+ * `Parser.parse` is also used internally by `Receiver` to parse raw eISCP socket
181
+ data.
182
+
183
+
184
+ Using the Binaries
185
+ ------------------
186
+
187
+ * Discover local receivers
188
+
189
+ `$ onkyo.rb -d`
190
+
191
+ * Send a human-readable command
192
+
193
+ `$ onkyo.rb system-power on # uses Parser.parse`
194
+
195
+ * Or send a raw command
196
+
197
+ `$ onkyo.rb PWRQSTN # Also tries to use Parser.parse`
198
+
199
+ * Monitor the first discovered receiver to see status updates
200
+
201
+ `$ onkyo.rb -m`
202
+
203
+ * Start the mock server (only responds to 'ECNQSTN')
204
+
205
+ `$ onkyo-server.rb`
206
+
207
+ * Turn off the first receiver discovered:
208
+
209
+ `$ onkyo.rb system-power off`
210
+
211
+ * List all known commands and values:
212
+
213
+ `$ onkyo.rb -L`
214
+
215
+ * List all known commands known to work with discovered models:
216
+
217
+ `$ onkyo.rb -l`
218
+
219
+ Contributing
220
+ ------------
41
221
 
222
+ * Open an issue describing bug or feature
223
+ * Fork repo
224
+ * Create a branch
225
+ * Send pull request
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 2.1.1
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'socket'
4
+ require_relative './receiver'
5
+ require_relative './message'
6
+
7
+ # Mock server that only responds to ECNQSTN.
8
+
9
+ module EISCP
10
+ # This class acts as an Onkyo Stereo. It can be used for testing
11
+ #
12
+ class MockReceiver
13
+ DISCOVERY_IP = '255.255.255.255'
14
+ ONKYO_DISCOVERY_RESPONSE = Message.new('ECN', "TX-NR609/60128/DX/14DAE9E967C8\x19\r\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
15
+
16
+ # Create/start the server object.
17
+
18
+ def initialize
19
+ Socket.udp_server_loop(DISCOVERY_IP, Receiver::ONKYO_PORT) do |msg, src|
20
+ src.reply "ISCP\x00\x00\x00\x10\x00\x00\x00&\x01\x00\x00\x00!1ECNTX-NR609/60128/DX/14DAE9E967C8\x19\r\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
21
+ puts msg
22
+ end
23
+ end
24
+ end
25
+ end
data/bin/onkyo.rb CHANGED
@@ -1,18 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'eiscp'
4
5
  require 'optparse'
5
6
  require 'ostruct'
6
7
 
8
+ # This object parses ARGV and returns an @option hash
9
+ #
7
10
  class Options
8
- DEFAULT_OPTIONS = { verbose: true, all: false }
11
+ DEFAULT_OPTIONS = { verbose: true, all: false }.freeze
9
12
  USAGE = ' Usage: onkyo_rb [options]'
10
13
 
11
14
  def self.parse(args)
12
15
  @options = OpenStruct.new
13
16
 
14
17
  options = OptionParser.new do |opts|
15
-
16
18
  opts.banner = USAGE
17
19
 
18
20
  opts.on '-d', '--discover', 'Find Onkyo Receivers on the local broadcast domain' do |d|
@@ -35,33 +37,91 @@ class Options
35
37
  @options.list_all = l
36
38
  end
37
39
 
38
- opts.on '-c', '--connect', 'Connect to the first discovered reciever and show updates' do |c|
39
- @options.connect = c
40
+ opts.on '-m', '--monitor', 'Connect to the first discovered reciever and monitor updates' do |m|
41
+ @options.monitor = m
40
42
  end
41
-
42
43
  end
43
44
 
44
45
  options.parse!(args)
45
46
 
46
- if @options == nil && ARGV == []
47
- puts options
48
- end
47
+ puts options if @options.nil? && ARGV == []
49
48
 
50
49
  if @options.discover
51
- EISCP.discover.each do |receiver|
52
- puts EISCPPacket.parse(receiver[0]).to_s
53
- end
50
+ EISCP::Receiver.discover.each { |rec| puts "#{rec.host}:#{rec.port} - #{rec.model} - #{rec.mac_address}" }
54
51
  exit 0
55
52
  end
56
53
 
57
54
  if @options.help
58
55
  puts options
59
- exit 0
56
+ exit 0
60
57
  end
61
58
 
62
- if @options.connect
63
- eiscp = EISCP.new(EISCP.discover[0][1])
64
- eiscp.connect
59
+ if @options.monitor
60
+ begin
61
+ rec = EISCP::Receiver.new do |reply|
62
+ puts "#{Time.now} #{rec.host} "\
63
+ "#{reply.zone}: "\
64
+ "#{reply.command_description || reply.command} "\
65
+ "-> #{reply.value_description || reply.value}"
66
+ end
67
+ rec.thread.join
68
+ rescue Interrupt
69
+ raise 'Exiting...'
70
+ rescue Exception => e
71
+ puts 'bummer...'
72
+ puts e
73
+ end
74
+ end
75
+
76
+ if @options.list
77
+ models = []
78
+ modelsets = []
79
+ EISCP::Receiver.discover.each do |rec|
80
+ models << rec.model
81
+ end
82
+ models.each do |model|
83
+ EISCP::Dictionary.modelsets.each do |modelset, list|
84
+ modelsets << modelset unless list.select { |x| x.match model }.empty?
85
+ end
86
+ end
87
+ EISCP::Dictionary.zones.each do |zone|
88
+ EISCP::Dictionary.commands[zone].each do |command, command_hash|
89
+ puts 'Command - Description'
90
+ puts "\n"
91
+ puts " '#{Dictionary.command_to_name(command)}' - "\
92
+ "#{Dictionary.description_from_command(command)}"
93
+ puts "\n"
94
+ puts ' Value - Description>'
95
+ puts "\n"
96
+ command_hash[:values].each do |_value, attr_hash|
97
+ if modelsets.include? attr_hash[:models]
98
+ puts " '#{attr_hash[:name]}' - "\
99
+ " #{attr_hash[:description]}"
100
+ end
101
+ end
102
+ puts "\n"
103
+ end
104
+ end
105
+ end
106
+
107
+ if @options.list_all
108
+ EISCP::Dictionary.zones.each do |zone|
109
+ EISCP::Dictionary.commands[zone].each do |command, command_hash|
110
+ puts 'Command - Description'
111
+ puts "\n"
112
+ puts " '#{Dictionary.command_to_name(command)}' - "\
113
+ "#{Dictionary.description_from_command(command)}"
114
+ puts "\n"
115
+ puts ' Value - Description>'
116
+ puts "\n"
117
+ command_hash[:values].each do |_value, attr_hash|
118
+ puts " '#{attr_hash[:name]}' - "\
119
+ " #{attr_hash[:description]}"
120
+ end
121
+ puts "\n"
122
+ end
123
+ end
124
+ exit 0
65
125
  end
66
126
 
67
127
  if ARGV == []
@@ -69,16 +129,18 @@ class Options
69
129
  exit 0
70
130
  end
71
131
  end
72
-
73
132
  end
74
133
 
134
+ include EISCP
75
135
 
76
136
  @options = Options.parse(ARGV)
77
137
 
78
-
79
- eiscp = EISCP.new(EISCP.discover[0][1])
80
- eiscp.send_recv(EISCPPacket.new(ISCPMessage.new(ARGV[0], ARGV[1]).message).to_s)
81
-
82
-
83
-
84
-
138
+ receiver = EISCP::Receiver.discover[0]
139
+ receiver.connect
140
+ begin
141
+ command = EISCP::Parser.parse(ARGV.join(' '))
142
+ rescue StandardError
143
+ raise "Couldn't parse command"
144
+ end
145
+ reply = receiver.send_recv(command)
146
+ puts "#{Time.now}: Response from #{receiver.host}: #{reply.zone.capitalize} #{reply.command_description || reply.command} -> #{reply.value_description || reply.value}"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'eiscp/mock_receiver'
5
+
6
+ puts 'Starting server on 60128...'
7
+
8
+ EISCP::MockReceiver.new