onkyo_eiscp_ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/onkyo-server.rb +7 -0
- data/lib/eiscp/eiscp.rb +12 -0
- data/lib/eiscp/eiscp_packet.rb +13 -0
- data/lib/eiscp/eiscp_server.rb +21 -0
- data/lib/eiscp.rb +3 -2
- data/onkyo_eiscp_ruby.gemspec +1 -0
- metadata +5 -3
- data/lib/server.rb +0 -15
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/onkyo-server.rb
ADDED
data/lib/eiscp/eiscp.rb
CHANGED
@@ -6,10 +6,13 @@ class EISCP
|
|
6
6
|
ONKYO_PORT = 60128
|
7
7
|
ONKYO_MAGIC = EISCPPacket.new("ECN", "QSTN", "x").to_s
|
8
8
|
|
9
|
+
# Create a new EISCP object to communicate with a receiver.
|
10
|
+
|
9
11
|
def initialize(host)
|
10
12
|
@host = host
|
11
13
|
end
|
12
14
|
|
15
|
+
# Internal method for receiving data with a timeout
|
13
16
|
|
14
17
|
def self.recv(sock, timeout = 0.5)
|
15
18
|
data = []
|
@@ -34,6 +37,9 @@ class EISCP
|
|
34
37
|
|
35
38
|
end
|
36
39
|
end
|
40
|
+
|
41
|
+
# Returns an array of arrays consisting of a discovery response packet string
|
42
|
+
# and the source ip address of the reciever.
|
37
43
|
|
38
44
|
def self.discover
|
39
45
|
sock = UDPSocket.new
|
@@ -62,6 +68,8 @@ class EISCP
|
|
62
68
|
|
63
69
|
end
|
64
70
|
end
|
71
|
+
|
72
|
+
# Sends a packet string on the network
|
65
73
|
|
66
74
|
def send(eiscp_packet)
|
67
75
|
sock = TCPSocket.new @host, ONKYO_PORT
|
@@ -69,12 +77,16 @@ class EISCP
|
|
69
77
|
sock.close
|
70
78
|
end
|
71
79
|
|
80
|
+
# Send a packet string and return recieved data string.
|
81
|
+
|
72
82
|
def send_recv(eiscp_packet)
|
73
83
|
sock = TCPSocket.new @host, ONKYO_PORT
|
74
84
|
sock.puts eiscp_packet
|
75
85
|
puts EISCP.recv(sock, 0.5)
|
76
86
|
end
|
77
87
|
|
88
|
+
# Open a TCP connection to the host and print all received messages until
|
89
|
+
# killed.
|
78
90
|
|
79
91
|
def connect(&block)
|
80
92
|
sock = TCPSocket.new @host, ONKYO_PORT
|
data/lib/eiscp/eiscp_packet.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'eiscp/iscp_message'
|
2
2
|
|
3
|
+
# Public: Encapsulates ISCP Messages in eISCP packets to send on the network.
|
4
|
+
# You can alsoe use the class method 'parse' to create objects from strings
|
5
|
+
# captured from the network using the EISCP class.
|
6
|
+
|
3
7
|
class EISCPPacket
|
4
8
|
|
5
9
|
MAGIC = "ISCP"
|
@@ -10,15 +14,24 @@ class EISCPPacket
|
|
10
14
|
attr_accessor :header
|
11
15
|
attr_reader :iscp_message
|
12
16
|
|
17
|
+
# Create a new EISCPPacket object with a given command and parameter
|
18
|
+
# -+command+ - an ISCP command like "PWR" for "system-power"
|
19
|
+
# -+parameter+ - an ISCP command parameter like "01" for "on" for
|
20
|
+
# "system-power"
|
21
|
+
|
13
22
|
def initialize(command, parameter, unit_type = "1", start = "!")
|
14
23
|
@iscp_message = ISCPMessage.new(command, parameter, unit_type, start)
|
15
24
|
@header = { :magic => MAGIC, :header_size => HEADER_SIZE, :data_size => @iscp_message.to_s.length, :version => VERSION, :reserved => RESERVED }
|
16
25
|
end
|
17
26
|
|
27
|
+
# Returns a raw packet string for sending on the network using EISCP object.
|
28
|
+
|
18
29
|
def to_s
|
19
30
|
return [ @header[:magic], @header[:header_size], @header[:data_size], @header[:version], @header[:reserved], @iscp_message.to_s ].pack("A4NNAa3A*")
|
20
31
|
end
|
21
32
|
|
33
|
+
# Returns an EISCPPacket from a raw packet string
|
34
|
+
|
22
35
|
def self.parse(eiscp_message_string)
|
23
36
|
array = eiscp_message_string.unpack("A4NNAa3A*")
|
24
37
|
iscp_message = ISCPMessage.parse(array[5])
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'eiscp/eiscp_packet'
|
3
|
+
require 'eiscp/eiscp'
|
4
|
+
|
5
|
+
# Mock server that only responds to ECNQSTN.
|
6
|
+
|
7
|
+
class EISCPServer
|
8
|
+
|
9
|
+
ONKYO_DISCOVERY_RESPONSE = EISCPPacket.new("ECN", "TX-NR609/60128/DX/001122334455")
|
10
|
+
|
11
|
+
# Create/start the server object.
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
Socket.udp_server_loop("255.255.255.255", EISCP::ONKYO_PORT) do |msg, msg_src|
|
15
|
+
msg_src.reply ONKYO_DISCOVERY_RESPONSE.to_s
|
16
|
+
puts msg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
data/lib/eiscp.rb
CHANGED
data/onkyo_eiscp_ruby.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onkyo_eiscp_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,26 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "\n Use the provided binary script or require the library for use
|
15
15
|
in your scripts.\n "
|
16
16
|
email: mikebrodrigues@gmail.com
|
17
17
|
executables:
|
18
18
|
- onkyo.rb
|
19
|
+
- onkyo-server.rb
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files:
|
21
22
|
- README.md
|
22
23
|
files:
|
24
|
+
- bin/onkyo-server.rb
|
23
25
|
- bin/onkyo.rb
|
26
|
+
- lib/eiscp/eiscp_server.rb
|
24
27
|
- lib/eiscp/eiscp.rb
|
25
28
|
- lib/eiscp/eiscp_packet.rb
|
26
29
|
- lib/eiscp/command.rb
|
27
30
|
- lib/eiscp/iscp_message.rb
|
28
31
|
- lib/eiscp.rb
|
29
|
-
- lib/server.rb
|
30
32
|
- test/tc_command.rb
|
31
33
|
- test/tc_iscp_message.rb
|
32
34
|
- test/tc_eiscp.rb
|
data/lib/server.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
|
3
|
-
class EISCPServer
|
4
|
-
|
5
|
-
ONKYO_DISCOVERY_RESPONSE = "ISCP\u0000\u0000\u0000\u0010\u0000\u0000\u0000&\u0001\u0000\u0000\u0000!1ECNTX-MR909/60128/DX/0009B0C727FE\u0019\r\n\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
|
6
|
-
def initialize
|
7
|
-
Socket.udp_server_loop("255.255.255.255", 60128) do |msg, msg_src|
|
8
|
-
msg_src.reply ONKYO_DISCOVERY_RESPONSE
|
9
|
-
puts msg
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
EISCPServer.new
|
15
|
-
|